我在标题中说明了一个错误和更一般的相关问题。
首先提出问题:vkGetPhysicalDeviceMemoryProperties提供一组堆和内存信息。在我的具体情况下,有两种堆和11种类型的内存。从那些,仅存在4种不同的掩模和堆组合。因此,有7种冗余内存类型。 为什么同一个堆上有多个具有相同属性标记的内存?
在规范的同一部分中,示例代码显示了如何使用vkGetImageMemoryRequirements
查找资源的内存。我使用了相同的代码,它给了我两个索引来检查,在我的11个记忆中。由于两者都不满足要求,因此分配失败。但是,如果我手动设置其中一个(正确堆上的那个)并忽略属性,则分配顺利运行。对我而言,这似乎是一个驱动程序¹,vkGetImageMemoryRequirements
和vkGetPhysicalDeviceMemoryProperties
的结果不匹配。如果vkGetImageMemoryRequirements
要求使用不同的索引,一切都会毫无问题地运行。
¹带有驱动程序版本382.33的GTX 980
编辑:根据要求,这里有代码片段和结果:
我系统上从memoryTypes
返回的vkGetPhysicalDeviceMemoryProperties
是:
[0] {propertyFlags = 0, heapIndex = 1},
[1] {propertyFlags = 0, heapIndex = 1},
[2] {propertyFlags = 0, heapIndex = 1},
[3] {propertyFlags = 0, heapIndex = 1},
[4] {propertyFlags = 0, heapIndex = 1},
[5] {propertyFlags = 0, heapIndex = 1},
[6] {propertyFlags = 0, heapIndex = 1},
[7] {propertyFlags = 1, heapIndex = 0},
[8] {propertyFlags = 1, heapIndex = 0},
[9] {propertyFlags = 6, heapIndex = 1},
[10] {propertyFlags = 14, heapIndex = 1},
vkGetImageMemoryRequirements
的调用为memoryTypeBits
返回130(即位数为2 ^ 1和2 ^ 7 - >数组索引1和7的行由下面的算法检查。)
最后,我们有代码(来自规范)使用允许的类型搜索内存索引(唯一的修改是名称)。
uint32_t getMemoryTypeIndex(uint32_t _memoryTypeBits, vk::MemoryPropertyFlags _desiredProperties)
{
for(uint32_t i = 0; i < m_memProps.memoryTypeCount; i++)
{
if(_memoryTypeBits & (1 << i))
{
if((m_memProps.memoryTypes[i].propertyFlags & _desiredProperties) == _desiredProperties)
return i;
}
}
return ~0;
}
我的desiredProperties
内存标志是VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT == 2.这仅适用于内存9和10,它们不在vkGetImageMemoryRequirements
的返回结果中,而是与内存1在同一堆上。