50 if (vk_buffer_view_ != VK_NULL_HANDLE) {
54 VkBufferViewCreateInfo buffer_view_info = {};
55 buffer_view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
56 buffer_view_info.buffer = buffer_.vk_handle();
58 buffer_view_info.range = buffer_.size_in_bytes();
61 vkCreateBufferView(device.
vk_handle(), &buffer_view_info,
nullptr, &vk_buffer_view_);
72 if (!buffer_.is_allocated()) {
76 if (buffer_.is_mapped()) {
77 buffer_.update_sub_immediately(start_offset, data_size_in_bytes,
data);
91 if (buffer_.is_mapped()) {
92 buffer_.read(context,
data);
97 if (buffer_.is_allocated()) {
107 "Unable to read data from vertex buffer via a staging buffer as the staging buffer "
108 "could not be allocated. ");
136 if (vk_buffer_view_ != VK_NULL_HANDLE) {
138 vk_buffer_view_ = VK_NULL_HANDLE;
144void VKVertexBuffer::upload_data_direct(
const VKBuffer &host_buffer)
149void VKVertexBuffer::upload_data_via_staging_buffer(VKContext &context)
152 VKBuffer &buffer = staging_buffer.host_buffer_get();
153 if (buffer.is_allocated()) {
154 upload_data_direct(buffer);
155 staging_buffer.copy_to_device(context);
159 "Unable to upload data to vertex buffer via a staging buffer as the staging buffer "
160 "could not be allocated. Vertex buffer will be filled with on zeros to reduce "
161 "drawing artifacts due to read from uninitialized memory.");
162 buffer_.
clear(context, 0u);
168 if (!buffer_.is_allocated()) {
171 if (!buffer_.is_allocated()) {
172 CLOG_ERROR(&
LOG,
"Unable to allocate vertex buffer. Most likely an out of memory issue.");
182 if (buffer_.is_mapped() && !data_uploaded_) {
183 upload_data_direct(buffer_);
187 upload_data_via_staging_buffer(context);
192 data_uploaded_ =
true;
199void VKVertexBuffer::allocate()
201 VkBufferUsageFlags vk_buffer_usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
202 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
203 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
204 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
205 VK_BUFFER_USAGE_TRANSFER_DST_BIT;
210 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
211 VmaAllocationCreateFlags(0),
#define CLOG_ERROR(clg_ref,...)
@ GPU_VERTBUF_DATA_UPLOADED
Read Guarded memory(de)allocation.
unsigned long long int uint64_t
void update_immediately(const void *data) const
bool create(size_t size, VkBufferUsageFlags buffer_usage, VkMemoryPropertyFlags required_flags, VkMemoryPropertyFlags preferred_flags, VmaAllocationCreateFlags vma_allocation_flags, float priority, bool export_memory=false)
void read(VKContext &context, void *data) const
VkBuffer vk_handle() const
void clear(VKContext &context, uint32_t clear_value)
void * mapped_memory_get() const
VkDevice vk_handle() const
void discard_buffer_view(VkBufferView vk_buffer_view)
static VKDiscardPool & discard_pool_get()
void copy_from_device(VKContext &context)
VKBuffer & host_buffer_get()
void copy_to_device(VKContext &context)
void texel_buffer_bind(VKVertexBuffer &vertex_buffer, int slot)
void storage_buffer_bind(BindSpaceStorageBuffers::Type resource_type, void *resource, int binding)
void release_data() override
void acquire_data() override
void update_sub(uint start, uint len, const void *data) override
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 read(void *data) const override
void resize_data() override
size_t size_alloc_get() const
#define MEM_reallocN(vmemh, len)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void object_label(GLenum type, GLuint object, const char *name)
#define NOT_YET_IMPLEMENTED