Comments (9)
Unfortunately I don't have a Mac environment to test the code.
First of all, I can see you are not using VkSubresourceLayout::offset
returned by vkGetImageSubresourceLayout
, which you should do when accessing mapped data of a linear image.
If that doesn't help, you may check if adding VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
flag to allocation created for that image helps. That would be a valuable information.
Please also check if Vulkan validation layers are really enabled and if they don't report any warnings or errors.
How does the corruption (invalid image data) looks like? Maybe something can be concluded from this data.
What memory heaps and types are available on this platform? Can you please show output of vulkaninfo
command?
from vulkanmemoryallocator.
Thanks for letting me know about VkSubresourceLayout::offset. I implemented it but it unfortunately it didn't make a difference in this example because the offset was 0.
Adding the VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT flag does fix the problem. I can use that if that's how you expect persistently mapped data to be created, but it seems unusual because the problem occurs regardless the size of the persistently mapped data. In the example its only 1 byte. Also I don't believe I'm mapping any data simultaneously.
I also tried using VMA_ALLOCATION_CREATE_MAPPED_BIT flag but that didn't help and sounds relatively identical to calling vmaMapMemory after creation.
The validation layers are working. I've used them quite extensively. There are no reported warnings or errors in the example.
The corruption has always appeared as if the image was just a solid color. In this example it is black. So if I change the screen clear color to something other than black then you can see a black rectangle where the image should be. In another example the image just became solid blue. I'm not sure what determines the color.
I attached the vulkan info output.
from vulkanmemoryallocator.
I'm not sure if this is related but I'm getting a validation warning with this updated code. It's nearly identical to the previously attached main.cpp. At the beginning of the createTextureImage function I create two images. I transition one to VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL and map the second. In the call to vmaMapMemory on stagingImageMemory2 I get the validation warning, "Mapping an image with layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used." This seems unusual because I never transitioned the second image. I get this validation warning regardless if any data is persistently mapped.
from vulkanmemoryallocator.
Thank you very much for this test. Indeed this is a very strange bug. I think it is possible that it's a bug in MoltenVK and not in VMA.
Please make sure you use latest version of Vulkan SDK (or whatever is the MacOS equivalent).
One thing you may try is a debug session where you could compare the pointer returned by vmaMapMemory
with VmaAllocation
's (char*)m_BlockAllocation.m_Block->m_pMappedData + m_BlockAllocation.m_Offset
to check if it's offseted correctly.
You could also try to allocate your images in similar way but without using VMA and see if that works:
- Allocate one big block of
VkDeviceMemory
, like 256 MB. - Bind your images to different non-zero offsets of this block, respecting their
VkMemoryRequirements
(especially offset).
from vulkanmemoryallocator.
Yes, that's possible. I can bring this to the attention of the MoltenVK devs.
The pointer returned by vmaMapMemory
is correctly offset from that m_pMappedData
. I noticed that these two image allocations share the same m_BlockAllocation.m_Block
, and when I follow the vmaMapMemory
function it goes into VmaAllocator_T::Map
and then VmaDeviceMemoryBlock::Map
, and inside there it calls
VkResult result = (*hAllocator->GetVulkanFunctions().vkMapMemory)(
hAllocator->m_hDevice,
m_hMemory,
0, // offset
VK_WHOLE_SIZE,
0, // flags
&m_pMappedData);
I could be missing something simple, but that looks like to me it maps the entire block. After returning from vmaMapMemory
both vmaAllocation
's have the same m_pMappedData
and the second has a nonzero m_Offset
.
Are you saying that I should be able to map the whole memory block and I shouldn't be getting the validation warning for another reason?
from vulkanmemoryallocator.
You are right. The way VMA implements mapping is that it always maps entire block, as described in documentation chapter "Memory mapping" → "Mapping functions".
The warning from Vulkan validation layers you experience is expected in that case. I'm sorry I forgot to mention that before. It's described in documentation chapter "General considerations" → "Validation layer warnings" → point 2.
Still I believe it should work correctly. If it's not, then my best guess is that it's the fact that some of the images is bound to a non-zero offset that is causing the problem. Question is: which one and where is the bug with offset not respected: in MoltenVK, VMA, or in your code.
from vulkanmemoryallocator.
Hey, any update on this? :)
from vulkanmemoryallocator.
I had not gotten around to doing the more testing that this needed until now. I determined that it is not a VMA bug and is in fact a limitation with MoltenVK as referenced here:
KhronosGroup/MoltenVK#175
I wish I had found that sooner.
Sorry for the trouble. Thanks for your help!
from vulkanmemoryallocator.
Thank you for finding this out. If you use memory type that has HOST_COHERENT
flag and you still need to Flush or worse Unmap then surely it's a bug in Vulkan implementation.
from vulkanmemoryallocator.
Related Issues (20)
- missing VMA_LEN_IF_NOT_NULL in vmaCopyMemoryToAllocation/vmaCopyAllocationToMemory HOT 1
- Buggy mapping hysteresis optimization HOT 2
- Asserts on Android 9 wth vkGetPhysicalDeviceMemoryProperties2KHR HOT 2
- no support for `VkBufferUsageFlags2CreateInfoKHR` HOT 2
- Specify in documentation that individual pools can be individually used w/o external synchronization HOT 1
- Compatibility issue with Vulkan 1.2.198 on OSX HOT 3
- Can I batch all allocations in one function call to VMA if I know my memory requirements upfront? HOT 2
- Building VulkanMemoryAllocator for C HOT 2
- Changes to PFN_vmaAllocateDeviceMemoryFunction HOT 1
- do not create a dummy buffer and destroy when call vmaFindMemoryTypeIndexForBufferInfo HOT 2
- Validation layer error in sample application HOT 5
- Problem when running tests of sample application on NVIDIA RTX 3090 HOT 5
- Use vkSetDebugUtilsObjectNameEXT to make debugging easier
- Question about 'Advanced data uploading' in the docs HOT 5
- C++20 module HOT 1
- VmaAllocator_T::Map illegal use of [[fallthough]] HOT 1
- Remove unused BasicTestBuddyAllocator()? HOT 3
- Write a new test which covers 'advanced data uploading' from docs HOT 5
- Clarify docs and improve pool API thread-safety guarantees if possible HOT 2
- Introduce a CMake option which allows VMA_DEBUG_LOG to be enabled easily HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vulkanmemoryallocator.