Fix heap iteration (#22)

Fixes an issue where certain memory heaps could potentially be overlooked.

Reviewed-on: MoonsideGames/Refresh#22
anisotropy
cosmonaut 2022-09-13 20:54:24 +00:00
parent f49c0ab190
commit 5568ce4949
1 changed files with 52 additions and 34 deletions

View File

@ -2156,22 +2156,22 @@ static uint8_t VULKAN_INTERNAL_FindMemoryType(
uint32_t typeFilter, uint32_t typeFilter,
VkMemoryPropertyFlags requiredProperties, VkMemoryPropertyFlags requiredProperties,
VkMemoryPropertyFlags ignoredProperties, VkMemoryPropertyFlags ignoredProperties,
uint32_t *result uint32_t *memoryTypeIndex
) { ) {
uint32_t i; uint32_t i;
for (i = 0; i < renderer->memoryProperties.memoryTypeCount; i += 1) for (i = *memoryTypeIndex; i < renderer->memoryProperties.memoryTypeCount; i += 1)
{ {
if ( (typeFilter & (1 << i)) && if ( (typeFilter & (1 << i)) &&
(renderer->memoryProperties.memoryTypes[i].propertyFlags & requiredProperties) == requiredProperties && (renderer->memoryProperties.memoryTypes[i].propertyFlags & requiredProperties) == requiredProperties &&
(renderer->memoryProperties.memoryTypes[i].propertyFlags & ignoredProperties) == 0 ) (renderer->memoryProperties.memoryTypes[i].propertyFlags & ignoredProperties) == 0 )
{ {
*result = i; *memoryTypeIndex = i;
return 1; return 1;
} }
} }
Refresh_LogError("Failed to find memory properties %X, required %X, ignored %X", requiredProperties, ignoredProperties, typeFilter); Refresh_LogError("Failed to find memory properties %X, required %X, ignored %X", typeFilter, requiredProperties, ignoredProperties);
return 0; return 0;
} }
@ -2513,7 +2513,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableBufferMemory(
VkDeviceSize *pOffset, VkDeviceSize *pOffset,
VkDeviceSize *pSize VkDeviceSize *pSize
) { ) {
uint32_t memoryTypeIndex; uint32_t memoryTypeIndex = 0;
VkMemoryDedicatedRequirementsKHR dedicatedRequirements = VkMemoryDedicatedRequirementsKHR dedicatedRequirements =
{ {
VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR,
@ -2524,18 +2524,15 @@ static uint8_t VULKAN_INTERNAL_FindAvailableBufferMemory(
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
&dedicatedRequirements &dedicatedRequirements
}; };
uint8_t findResult = 0;
if (!VULKAN_INTERNAL_FindBufferMemoryRequirements( while (VULKAN_INTERNAL_FindBufferMemoryRequirements(
renderer, renderer,
buffer, buffer,
&memoryRequirements, &memoryRequirements,
&memoryTypeIndex &memoryTypeIndex
)) { )) {
Refresh_LogError("Failed to acquire buffer memory requirements!"); findResult = VULKAN_INTERNAL_FindAvailableMemory(
return 0;
}
return VULKAN_INTERNAL_FindAvailableMemory(
renderer, renderer,
memoryTypeIndex, memoryTypeIndex,
&memoryRequirements, &memoryRequirements,
@ -2546,6 +2543,18 @@ static uint8_t VULKAN_INTERNAL_FindAvailableBufferMemory(
pOffset, pOffset,
pSize pSize
); );
if (findResult == 1)
{
break;
}
else
{
memoryTypeIndex += 1;
}
}
return findResult;
} }
static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory( static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
@ -2556,7 +2565,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
VkDeviceSize *pOffset, VkDeviceSize *pOffset,
VkDeviceSize *pSize VkDeviceSize *pSize
) { ) {
uint32_t memoryTypeIndex; uint32_t memoryTypeIndex = 0;
VkMemoryPropertyFlags requiredMemoryPropertyFlags; VkMemoryPropertyFlags requiredMemoryPropertyFlags;
VkMemoryPropertyFlags ignoredMemoryPropertyFlags; VkMemoryPropertyFlags ignoredMemoryPropertyFlags;
VkMemoryDedicatedRequirementsKHR dedicatedRequirements = VkMemoryDedicatedRequirementsKHR dedicatedRequirements =
@ -2569,6 +2578,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
&dedicatedRequirements &dedicatedRequirements
}; };
uint8_t findResult = 0;
if (cpuAllocation) if (cpuAllocation)
{ {
@ -2581,7 +2591,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
ignoredMemoryPropertyFlags = 0; ignoredMemoryPropertyFlags = 0;
} }
if (!VULKAN_INTERNAL_FindImageMemoryRequirements( while (VULKAN_INTERNAL_FindImageMemoryRequirements(
renderer, renderer,
image, image,
requiredMemoryPropertyFlags, requiredMemoryPropertyFlags,
@ -2589,11 +2599,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
&memoryRequirements, &memoryRequirements,
&memoryTypeIndex &memoryTypeIndex
)) { )) {
Refresh_LogError("Failed to acquire image memory requirements!"); findResult = VULKAN_INTERNAL_FindAvailableMemory(
return 0;
}
return VULKAN_INTERNAL_FindAvailableMemory(
renderer, renderer,
memoryTypeIndex, memoryTypeIndex,
&memoryRequirements, &memoryRequirements,
@ -2604,6 +2610,18 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
pOffset, pOffset,
pSize pSize
); );
if (findResult == 1)
{
break;
}
else
{
memoryTypeIndex += 1;
}
}
return findResult;
} }
/* Memory Barriers */ /* Memory Barriers */