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)
- GpuMemDumpVis.py using unsupported call on modern Python + PIL install HOT 1
- Use of signed char may not be correct in JsonWriter. HOT 1
- Offer option to use aliased named string with VMA HOT 4
- vmaFreeString missing from ~VmaPool_T() HOT 1
- All uses of %llu gen warnings in clang, replace with PRIu64 HOT 1
- Split out stats for dedicated blockCount and bytes. HOT 2
- GpuDumpMemVis.py docs should indicate it doesn't handle aliasing HOT 1
- Added a Perfetto python dump HOT 6
- How to query if an allocation is dedicated? HOT 7
- vulkanApiVersion in doc refers to instance-api version and not device-api version HOT 1
- Switch leaks from VMA_ASSERT to VMA_ASSERT_LEAK. HOT 7
- vmafindMemoryTypeIndexForImageInfo not working when selecting Vulkan 1.2 HOT 2
- Example for External Memory support HOT 4
- Make a new version HOT 1
- vmaCreatePool failing at startup on some Nvidia gpu + driver combos HOT 5
- 3.0.1 doesn't build on armeabi-v7a HOT 1
- Validation error (VkMemoryRequirements::alignment) in v2.3.0 HOT 2
- Support using parts of VMA without vulkan [virtual allocation & defragmentation] HOT 1
- VMA crashing at startup on Android 14 devices HOT 9
- 3.0.2 release for gcc-13 fix? HOT 1
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.