55 if (vk_buffer_view_ != VK_NULL_HANDLE) {
59 VkBufferViewCreateInfo buffer_view_info = {};
60 buffer_view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
61 buffer_view_info.buffer = buffer_.vk_handle();
63 buffer_view_info.range = buffer_.size_in_bytes();
67 device.
vk_handle(), &buffer_view_info,
nullptr, &vk_buffer_view_);
70 BLI_assert(buffer_.resource().resource_handle != 0);
81 if (!buffer_.is_allocated()) {
85 BLI_assert_msg(start_offset + data_size_in_bytes <= buffer_.size_in_bytes(),
86 "Out of bound write to vertex buffer");
87 if (buffer_.is_mapped()) {
88 buffer_.update_sub_immediately(start_offset, data_size_in_bytes,
data);
100 uint source_first_vertex,
101 uint dest_first_vertex,
106 "Copy source range exceeds the source vertex buffer bounds");
108 "Copy destination range exceeds the vertex buffer bounds");
110 BLI_assert_msg(buffer_.is_allocated(),
"GPU_vertbuf_use() not called on this buffer");
112 "GPU_vertbuf_use() not called on the source buffer");
114 if (!buffer_.is_allocated() || !source_vertex_buffer.buffer_.
is_allocated()) {
118 if (copy_size == 0) {
126 copy_buffer.
region.srcOffset = VkDeviceSize(source_first_vertex) *
129 copy_buffer.
region.size = copy_size;
130 context.render_graph().add_node(copy_buffer);
136 if (buffer_.is_mapped()) {
137 buffer_.read(context,
data);
142 if (buffer_.is_allocated()) {
152 "Unable to read data from vertex buffer via a staging buffer as the staging buffer "
153 "could not be allocated. ");
166 MEM_SAFE_DELETE(
data_);
182 MEM_SAFE_DELETE(
data_);
185void VKVertexBuffer::upload_data_direct(
const VKBuffer &host_buffer)
190void VKVertexBuffer::upload_data_via_staging_buffer(
VKContext &context)
194 VKBuffer &buffer = staging_buffer.host_buffer_get();
196 upload_data_direct(buffer);
197 staging_buffer.copy_to_device(context);
201 "Unable to upload data to vertex buffer via a staging buffer as the staging buffer "
202 "could not be allocated. Vertex buffer will be filled with on zeros to reduce "
203 "drawing artifacts due to read from uninitialized memory.");
204 buffer_.
clear(context, 0u);
210 if (!buffer_.is_allocated()) {
213 if (!buffer_.is_allocated()) {
214 CLOG_ERROR(&
LOG,
"Unable to allocate vertex buffer. Most likely an out of memory issue.");
224 if (buffer_.is_mapped() && !data_uploaded_) {
225 upload_data_direct(buffer_);
229 upload_data_via_staging_buffer(context);
232 MEM_SAFE_DELETE(
data_);
234 data_uploaded_ =
true;
241void VKVertexBuffer::allocate()
243 VkBufferUsageFlags vk_buffer_usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
244 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
245 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
246 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
247 VK_BUFFER_USAGE_TRANSFER_DST_BIT;
249 vk_buffer_usage |= VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR |
250 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
255 VMA_MEMORY_USAGE_AUTO,
256 VmaAllocationCreateFlags(0),
#define CLOG_ERROR(clg_ref,...)
Read Blender memory allocation and freeing.
#define BLI_assert_msg(a, msg)
#define MEM_realloc_uninitialized(vmemh, len)
void update_immediately(const void *data) const
bool is_allocated() const
void read(VKContext &context, void *data) const
bool create(size_t size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage vma_memory_usage, VmaAllocationCreateFlags vma_allocation_flags, float priority, bool export_memory=false, const char *debug_name="VKBuffer", size_t alignment=0)
const VKResourceWithHandle< VkBuffer > & resource() const
void clear(VKContext &context, uint32_t clear_value)
void * mapped_memory_get() const
render_graph::VKResourceStateTracker resources
VkDevice vk_handle() const
VolkDeviceTable functions
void copy_from_device(VKContext &context)
VKBuffer & host_buffer_get()
void copy_to_device(VKContext &context)
void texel_buffer_bind(VKVertexBuffer &vertex_buffer, int binding)
void storage_buffer_bind(BindSpaceStorageBuffers::Type resource_type, void *resource, int binding)
void release_data() override
void acquire_data() override
void copy_sub(VertBuf &source_buf, uint source_first_vertex, uint dest_first_vertex, uint vertex_len) override
Copy from part of source vertex buffer into the vertex buffer.
void upload_data() override
void wrap_handle(uint64_t handle) override
void bind_as_ssbo(uint binding) override
void ensure_buffer_view()
void bind_as_texture(uint binding) override
void update_sub(uint start_offset, uint data_size_in_bytes, const void *data) override
void read(void *data) const override
void resize_data() override
size_t size_used_get() const
size_t size_alloc_get() const
VKCopyBufferData CreateInfo
void register_view(ResourceHandle resource_handle, VkView vk_view)
void object_label(GLenum type, GLuint object, const char *name)
BLI_INLINE MTLTexture * unwrap(Texture *tex)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
@ GPU_VERTBUF_DATA_UPLOADED
VKResourceWithHandle< VkBuffer > dst_buffer
VKResourceWithHandle< VkBuffer > src_buffer
#define NOT_YET_IMPLEMENTED