Fix persistent buffer mapping balance and prevent double map#87
Merged
Mrkol merged 3 commits intoMay 4, 2026
Merged
Conversation
| // make map() optional if allocationCreate has VMA_ALLOCATION_CREATE_MAPPED_BIT | ||
| mapped = reinterpret_cast<std::byte*>(allocInfo.pMappedData); | ||
| // make map() forbidden for the user if allocationCreate has VMA_ALLOCATION_CREATE_MAPPED_BIT | ||
| if (info.allocationCreate & VMA_ALLOCATION_CREATE_MAPPED_BIT) |
There was a problem hiding this comment.
warning: implicit conversion 'VmaAllocationCreateFlags' (aka 'unsigned int') -> 'bool' [readability-implicit-bool-conversion]
Suggested change
| if (info.allocationCreate & VMA_ALLOCATION_CREATE_MAPPED_BIT) | |
| if ((info.allocationCreate & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0u) |
kzubatov
added a commit
to kzubatov/etna
that referenced
this pull request
May 11, 2026
Mrkol
pushed a commit
that referenced
this pull request
May 13, 2026
* Revert "Fix persistent buffer mapping balance and prevent double map (#87)" This reverts commit e498aab. * buffer: do not call unmap in reset if VMA_ALLOCATION_CREATE_MAPPED_BIT is set, the buffer is always mapped and unmap should not be called in reset, see https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/group__group__alloc.html#ggad9889c10c798b040d59c92f257cae597a11da372cc3a82931c5e5d6146cd9dd1f:~:text=It%20is%20also%20safe,to%20VMA%5FALLOCATION%5FCREATE%5FMAPPED%5FBIT%20flag If map is called explicitly, instead of creating the buffer using VMA_ALLOCATION_CREATE_MAPPED_BIT, unmap must also be called explicitly Removed map/unmap calls in helper functions, since buffers are created with VMA_ALLOCATION_CREATE_MAPPED_BIT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Buffers created with
VMA_ALLOCATION_CREATE_MAPPED_BITreceive apersistently mapped pointer without an explicit
vmaMapMemorycall.The destructor's
unmap()then triggers a VMA assertion because thereis no matching explicit
vmaMapMemory.Solution
Explicitly call
map()in the constructor when the persistent flagis set, pairing with the
unmap()inreset().Forbid further
map()calls viaETNA_VERIFY(mapped == nullptr).If the user were allowed to call
map()/unmap()manually, a singleunmap()would setmapped = nullptr, breaking the pairing with thedestructor's
unmap()— the constructor'smap()would remainunmatched forever.