iterate over multiple heaps to find memory

pull/22/head
cosmonaut 2022-08-26 11:15:56 -07:00
parent f49c0ab190
commit 223a9d6593
1 changed files with 51 additions and 34 deletions

View File

@ -2156,22 +2156,22 @@ static uint8_t VULKAN_INTERNAL_FindMemoryType(
uint32_t typeFilter,
VkMemoryPropertyFlags requiredProperties,
VkMemoryPropertyFlags ignoredProperties,
uint32_t *result
uint32_t *memoryTypeIndex
) {
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)) &&
(renderer->memoryProperties.memoryTypes[i].propertyFlags & requiredProperties) == requiredProperties &&
(renderer->memoryProperties.memoryTypes[i].propertyFlags & ignoredProperties) == 0 )
{
*result = i;
*memoryTypeIndex = i;
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;
}
@ -2513,7 +2513,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableBufferMemory(
VkDeviceSize *pOffset,
VkDeviceSize *pSize
) {
uint32_t memoryTypeIndex;
uint32_t memoryTypeIndex = 0;
VkMemoryDedicatedRequirementsKHR dedicatedRequirements =
{
VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR,
@ -2524,18 +2524,15 @@ static uint8_t VULKAN_INTERNAL_FindAvailableBufferMemory(
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
&dedicatedRequirements
};
uint8_t findResult;
if (!VULKAN_INTERNAL_FindBufferMemoryRequirements(
while (VULKAN_INTERNAL_FindBufferMemoryRequirements(
renderer,
buffer,
&memoryRequirements,
&memoryTypeIndex
)) {
Refresh_LogError("Failed to acquire buffer memory requirements!");
return 0;
}
return VULKAN_INTERNAL_FindAvailableMemory(
findResult = VULKAN_INTERNAL_FindAvailableMemory(
renderer,
memoryTypeIndex,
&memoryRequirements,
@ -2546,6 +2543,17 @@ static uint8_t VULKAN_INTERNAL_FindAvailableBufferMemory(
pOffset,
pSize
);
if (findResult == 1)
{
break;
}
else
{
memoryTypeIndex += 1;
}
}
return findResult;
}
static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
@ -2556,7 +2564,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
VkDeviceSize *pOffset,
VkDeviceSize *pSize
) {
uint32_t memoryTypeIndex;
uint32_t memoryTypeIndex = 0;
VkMemoryPropertyFlags requiredMemoryPropertyFlags;
VkMemoryPropertyFlags ignoredMemoryPropertyFlags;
VkMemoryDedicatedRequirementsKHR dedicatedRequirements =
@ -2569,6 +2577,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
&dedicatedRequirements
};
uint8_t findResult = 0;
if (cpuAllocation)
{
@ -2581,7 +2590,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
ignoredMemoryPropertyFlags = 0;
}
if (!VULKAN_INTERNAL_FindImageMemoryRequirements(
while (VULKAN_INTERNAL_FindImageMemoryRequirements(
renderer,
image,
requiredMemoryPropertyFlags,
@ -2589,11 +2598,7 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
&memoryRequirements,
&memoryTypeIndex
)) {
Refresh_LogError("Failed to acquire image memory requirements!");
return 0;
}
return VULKAN_INTERNAL_FindAvailableMemory(
findResult = VULKAN_INTERNAL_FindAvailableMemory(
renderer,
memoryTypeIndex,
&memoryRequirements,
@ -2604,6 +2609,18 @@ static uint8_t VULKAN_INTERNAL_FindAvailableTextureMemory(
pOffset,
pSize
);
if (findResult == 1)
{
break;
}
else
{
memoryTypeIndex += 1;
}
}
return findResult;
}
/* Memory Barriers */