Vulkan: Inline more trivial methods

These functions are trivial and shouldn't add the cost of a call.
They appeared in profiles, which they shouldn't since they mostly
just return access to member variables. Inlining them reduces
the backend's overhead when sculpting.

Also reserve a Vector before repeated appending.

Pull Request: https://projects.blender.org/blender/blender/pulls/138349
This commit is contained in:
Hans Goudey
2025-05-06 14:27:43 +02:00
committed by Hans Goudey
parent 01fb09b240
commit d094812709
9 changed files with 51 additions and 52 deletions

View File

@@ -94,6 +94,7 @@ void vk_vertex_buffer_bindings_build_links(VKResourceStateTracker &resources,
VKRenderGraphNodeLinks &node_links,
const VKVertexBufferBindings &vertex_buffers)
{
node_links.inputs.reserve(node_links.inputs.size() + vertex_buffers.buffer_count);
for (const VkBuffer vk_buffer :
Span<VkBuffer>(vertex_buffers.buffer, vertex_buffers.buffer_count))
{

View File

@@ -142,19 +142,4 @@ void VKBatch::multi_draw_indirect(const VkBuffer indirect_buffer,
}
}
VKVertexBuffer *VKBatch::vertex_buffer_get(int index)
{
return unwrap(verts_(index));
}
VKVertexBuffer *VKBatch::instance_buffer_get(int index)
{
return unwrap(inst_(index));
}
VKIndexBuffer *VKBatch::index_buffer_get()
{
return unwrap(unwrap(elem));
}
} // namespace blender::gpu

View File

@@ -8,14 +8,12 @@
#pragma once
#include "vk_common.hh"
#include "vk_index_buffer.hh"
#include "vk_vertex_buffer.hh"
#include "GPU_batch.hh"
namespace blender::gpu {
class VKVertexBuffer;
class VKIndexBuffer;
class VKBatch : public Batch {
public:
void draw(int vertex_first, int vertex_count, int instance_first, int instance_count) override;
@@ -36,4 +34,19 @@ inline VKBatch *unwrap(Batch *batch)
return static_cast<VKBatch *>(batch);
}
inline VKVertexBuffer *VKBatch::vertex_buffer_get(int index)
{
return unwrap(verts_(index));
}
inline VKVertexBuffer *VKBatch::instance_buffer_get(int index)
{
return unwrap(inst_(index));
}
inline VKIndexBuffer *VKBatch::index_buffer_get()
{
return unwrap(unwrap(elem));
}
} // namespace blender::gpu

View File

@@ -20,11 +20,6 @@ VKBuffer::~VKBuffer()
}
}
bool VKBuffer::is_allocated() const
{
return allocation_ != VK_NULL_HANDLE;
}
bool VKBuffer::create(size_t size_in_bytes,
VkBufferUsageFlags buffer_usage,
VkMemoryPropertyFlags required_flags,
@@ -166,17 +161,6 @@ void VKBuffer::read(VKContext &context, void *data) const
memcpy(data, mapped_memory_, size_in_bytes_);
}
void *VKBuffer::mapped_memory_get() const
{
BLI_assert_msg(is_mapped(), "Cannot access a non-mapped buffer.");
return mapped_memory_;
}
bool VKBuffer::is_mapped() const
{
return mapped_memory_ != nullptr;
}
bool VKBuffer::map()
{
BLI_assert(!is_mapped());

View File

@@ -122,6 +122,22 @@ class VKBuffer : public NonCopyable {
void unmap();
};
inline void *VKBuffer::mapped_memory_get() const
{
BLI_assert_msg(this->is_mapped(), "Cannot access a non-mapped buffer.");
return mapped_memory_;
}
inline bool VKBuffer::is_mapped() const
{
return mapped_memory_ != nullptr;
}
inline bool VKBuffer::is_allocated() const
{
return allocation_ != VK_NULL_HANDLE;
}
/**
* Helper struct to enable buffers to be bound with an offset.
*

View File

@@ -1290,18 +1290,6 @@ void VertexFormatConverter::init(const GPUVertFormat *vertex_format,
}
}
const GPUVertFormat &VertexFormatConverter::device_format_get() const
{
BLI_assert(is_initialized());
return *device_format_;
}
bool VertexFormatConverter::needs_conversion() const
{
BLI_assert(is_initialized());
return needs_conversion_;
}
void VertexFormatConverter::update_conversion_flags(const GPUVertFormat &vertex_format,
const VKWorkarounds &workarounds)
{

View File

@@ -194,6 +194,18 @@ struct VertexFormatConverter {
const GPUVertAttr &source_attribute) const;
};
inline const GPUVertFormat &VertexFormatConverter::device_format_get() const
{
BLI_assert(this->is_initialized());
return *device_format_;
}
inline bool VertexFormatConverter::needs_conversion() const
{
BLI_assert(is_initialized());
return needs_conversion_;
}
inline bool VertexFormatConverter::is_initialized() const
{
return device_format_ != nullptr;

View File

@@ -189,11 +189,6 @@ void VKVertexBuffer::device_format_ensure()
}
}
const GPUVertFormat &VKVertexBuffer::device_format_get() const
{
return vertex_format_converter.device_format_get();
}
void VKVertexBuffer::allocate()
{
VkBufferUsageFlags vk_buffer_usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT |

View File

@@ -66,6 +66,11 @@ class VKVertexBuffer : public VertBuf {
friend class VKTexture;
};
inline const GPUVertFormat &VKVertexBuffer::device_format_get() const
{
return vertex_format_converter.device_format_get();
}
BLI_INLINE VKVertexBuffer *unwrap(VertBuf *vertex_buffer)
{
return static_cast<VKVertexBuffer *>(vertex_buffer);