From d70f814dc7d1a1ce94604166a926915ed9159408 Mon Sep 17 00:00:00 2001 From: kzubatov Date: Mon, 8 Dec 2025 22:45:39 +0300 Subject: [PATCH] Buffer: auto map for buffers with VMA_ALLOCATION_CREATE_MAPPED_BIT --- etna/source/Buffer.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/etna/source/Buffer.cpp b/etna/source/Buffer.cpp index baef3d2..fbce335 100644 --- a/etna/source/Buffer.cpp +++ b/etna/source/Buffer.cpp @@ -16,7 +16,7 @@ Buffer::Buffer(VmaAllocator alloc, CreateInfo info) .sharingMode = vk::SharingMode::eExclusive, }; - VmaAllocationCreateInfo allocInfo{ + VmaAllocationCreateInfo allocCreateInfo{ .flags = info.allocationCreate, .usage = info.memoryUsage, .requiredFlags = 0, @@ -27,14 +27,16 @@ Buffer::Buffer(VmaAllocator alloc, CreateInfo info) .priority = 0.f, }; + VmaAllocationInfo allocInfo; + VkBuffer buf; auto retcode = vmaCreateBuffer( allocator, &static_cast(bufInfo), - &allocInfo, + &allocCreateInfo, &buf, &allocation, - nullptr); + &allocInfo); // Note that usually vulkan.hpp handles doing the assertion // and a pretty message, but VMA cannot do that. ETNA_VERIFYF( @@ -42,6 +44,11 @@ Buffer::Buffer(VmaAllocator alloc, CreateInfo info) "Error {} occurred while trying to allocate an etna::Buffer!", vk::to_string(static_cast(retcode))); buffer = vk::Buffer(buf); + + // make map() optional if allocationCreate has VMA_ALLOCATION_CREATE_MAPPED_BIT + mapped = reinterpret_cast(allocInfo.pMappedData); + ETNA_VERIFY(mapped == nullptr || info.allocationCreate & VMA_ALLOCATION_CREATE_MAPPED_BIT); + etna::set_debug_name(buffer, info.name.data()); }