24 return allocation_ != VK_NULL_HANDLE;
35 return VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
40 return VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
45 return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
50 return is_host_visible ? VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT : 0;
55 VkBufferUsageFlags buffer_usage,
56 const bool is_host_visible)
72 VkBufferCreateInfo create_info = {};
73 create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
74 create_info.flags = 0;
80 create_info.usage = buffer_usage;
83 create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
84 create_info.queueFamilyIndexCount = 1;
86 create_info.pQueueFamilyIndices = queue_family_indices;
88 VmaAllocationCreateInfo vma_create_info = {};
90 vma_create_info.priority = 1.0f;
93 vma_create_info.usage = VMA_MEMORY_USAGE_AUTO;
95 VkResult result = vmaCreateBuffer(
96 allocator, &create_info, &vma_create_info, &vk_buffer_, &allocation_,
nullptr);
97 if (result != VK_SUCCESS) {
103 if (is_host_visible) {
112 memcpy(mapped_memory_, data, size_in_bytes_);
118 BLI_assert(size_in_bytes_ <= 65536 && size_in_bytes_ % 4 == 0);
121 update_buffer.
data_size = size_in_bytes_;
123 context.render_graph.add_node(update_buffer);
137 fill_buffer.
data = clear_value;
138 fill_buffer.
size = size_in_bytes_;
139 context.render_graph.add_node(fill_buffer);
145 context.rendering_end();
146 context.descriptor_set_get().upload_descriptor_sets();
147 context.render_graph.submit_buffer_for_read(vk_buffer_);
148 memcpy(data, mapped_memory_, size_in_bytes_);
154 return mapped_memory_;
159 return mapped_memory_ !=
nullptr;
167 VkResult result = vmaMapMemory(allocator, allocation_, &mapped_memory_);
168 return result == VK_SUCCESS;
171void VKBuffer::unmap()
176 vmaUnmapMemory(allocator, allocation_);
177 mapped_memory_ =
nullptr;
189 allocation_ = VK_NULL_HANDLE;
190 vk_buffer_ = VK_NULL_HANDLE;
204 allocation_ = VK_NULL_HANDLE;
205 vk_buffer_ = VK_NULL_HANDLE;
#define BLI_assert_msg(a, msg)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
void update_immediately(const void *data) const
bool is_allocated() const
bool create(size_t size, GPUUsageType usage, VkBufferUsageFlags buffer_usage, bool is_host_visible=true)
void read(VKContext &context, void *data) const
void free_immediately(VKDevice &device)
void clear(VKContext &context, uint32_t clear_value)
void update_render_graph(VKContext &context, void *data) const
void * mapped_memory_get() const
int64_t size_in_bytes() const
render_graph::VKResourceStateTracker resources
VmaAllocator mem_allocator_get() const
const uint32_t queue_family_get() const
VKDiscardPool & discard_pool_for_current_thread()
void discard_buffer(VkBuffer vk_buffer, VmaAllocation vma_allocation)
void remove_buffer(VkBuffer vk_buffer)
void add_buffer(VkBuffer vk_buffer, const char *name=nullptr)
MINLINE unsigned long long max_ulul(unsigned long long a, unsigned long long b)
static VmaAllocationCreateFlags vma_allocation_flags(GPUUsageType usage)
static VkMemoryPropertyFlags vma_required_flags(const bool is_host_visible)
static VkMemoryPropertyFlags vma_preferred_flags()