31 if (async_read_buffer_) {
32 MEM_delete(async_read_buffer_);
33 async_read_buffer_ =
nullptr;
41 if (!buffer_.is_allocated()) {
43 "Unable to upload data to storage buffer as the storage buffer could not be "
66 "Unable to upload data to storage buffer via a staging buffer as the staging buffer "
67 "could not be allocated. Storage buffer will be filled with on zeros to reduce "
68 "drawing artifacts due to read from uninitialized memory.");
69 buffer_.clear(context, 0u);
75 if (!buffer_.is_allocated()) {
80void VKStorageBuffer::allocate()
82 const VkBufferUsageFlags buffer_usage_flags = VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT |
83 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
84 VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
85 VK_BUFFER_USAGE_TRANSFER_DST_BIT;
88 VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
89 VmaAllocationCreateFlags(0),
98 context.state_manager_get().storage_buffer_bind(
106 context->state_manager_get().storage_buffer_unbind(
this);
114 buffer_.clear(context, clear_value);
122 src_vertex_buffer.
upload();
127 copy_buffer.
region.srcOffset = src_offset;
128 copy_buffer.
region.dstOffset = dst_offset;
129 copy_buffer.
region.size = copy_size;
132 context.render_graph().add_node(copy_buffer);
137 if (async_read_buffer_ !=
nullptr) {
143 async_read_buffer_ = MEM_new<VKStagingBuffer>(
145 async_read_buffer_->copy_from_device(context);
146 async_read_buffer_->host_buffer_get().async_flush_to_host(context);
151 if (async_read_buffer_ ==
nullptr) {
156 async_read_buffer_->host_buffer_get().read_async(context,
data);
157 MEM_delete(async_read_buffer_);
158 async_read_buffer_ =
nullptr;
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
StorageBuf(size_t size, const char *name)
size_t usage_size_in_bytes_
char name_[DEBUG_NAME_LEN]
void update_immediately(const void *data) const
bool is_allocated() 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 VkPhysicalDeviceProperties & physical_device_properties_get() const
VKBuffer & host_buffer_get()
void copy_to_device(VKContext &context)
const VKResourceWithHandle< VkBuffer > & resource() const
void update(const void *data) override
void async_flush_to_host() override
void clear(uint32_t clear_value) override
void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override
void read(void *data) override
VKStorageBuffer(size_t size, GPUUsageType usage, const char *name)
void bind(int slot) override
VkDeviceSize update(VKContext &context, const void *data, size_t data_size)
const VKResourceWithHandle< VkBuffer > & resource() const
VKCopyBufferData CreateInfo
BLI_INLINE MTLTexture * unwrap(Texture *tex)
BMesh const char void * data
VKResourceWithHandle< VkBuffer > dst_buffer
VKResourceWithHandle< VkBuffer > src_buffer