From 4460f6d85730cb630dda4be2ebe47fcf13478d58 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Thu, 4 Mar 2021 20:48:29 +0100 Subject: Attempt at synchronizing memory write --- src/vk-api.cpp | 57 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/vk-api.cpp') diff --git a/src/vk-api.cpp b/src/vk-api.cpp index f051025..3ff6cb8 100644 --- a/src/vk-api.cpp +++ b/src/vk-api.cpp @@ -46,24 +46,20 @@ vkapi::~vkapi() { } -Buffer vkapi::create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage mem_usage, void* ptr) { +Buffer vkapi::create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage mem_usage) { Buffer buffer = {}; - if (ptr) { - buffer.mapped_ptr = ptr; - } - - VkBufferCreateInfo buffer_info = { }; + VkBufferCreateInfo buffer_info = {}; buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; buffer_info.size = data_size; buffer_info.usage = buffer_usage; VmaAllocationCreateInfo alloc_create_info = {}; alloc_create_info.usage = mem_usage; + alloc_create_info.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT; + alloc_create_info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - VKRESULT(vmaCreateBuffer(context.allocator, &buffer_info, &alloc_create_info, &buffer.handle, &buffer.alloc, nullptr)) - - vmaMapMemory(context.allocator, buffer.alloc, (void**) &buffer.mapped_ptr); + VKRESULT(vmaCreateBuffer(context.allocator, &buffer_info, &alloc_create_info, &buffer.handle, &buffer.alloc, &buffer.alloc_info)) return std::move(buffer); } @@ -74,13 +70,9 @@ void vkapi::destroy_buffer(Buffer& buffer) { } -Image vkapi::create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags usages, void* ptr) { +Image vkapi::create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags usages) { Image image; - if (ptr) { - image.mapped_ptr = ptr; - } - image.size = size; image.subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -108,8 +100,9 @@ Image vkapi::create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags us VmaAllocationCreateInfo alloc_create_info = {}; alloc_create_info.usage = VMA_MEMORY_USAGE_GPU_ONLY; + alloc_create_info.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT; - VKRESULT(vmaCreateImage(context.allocator, &img_create_info, &alloc_create_info, &image.handle, &image.alloc, nullptr)) + VKRESULT(vmaCreateImage(context.allocator, &img_create_info, &alloc_create_info, &image.handle, &image.alloc, &image.alloc_info)) VkImageViewCreateInfo image_view_create_info = {}; image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; @@ -139,7 +132,7 @@ std::vector vkapi::create_images(VkExtent3D size, VkFormat format, VkImag std::vector images { image_count }; for (size_t image_index = 0; image_index < image_count; image_index++) { - images[image_index] = create_image(size, format, usages, nullptr); + images[image_index] = create_image(size, format, usages); } return std::move(images); @@ -252,8 +245,8 @@ VkRenderPass vkapi::create_render_pass(std::vector& color_attachments_ attachment_description.storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachment_description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment_description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachment_description.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; // TODO: Change this - attachment_description.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + attachment_description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // TODO: Change this + attachment_description.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; attachments_description.push_back(attachment_description); @@ -480,12 +473,12 @@ Pipeline vkapi::create_graphics_pipeline(const char* shader_name, std::vector