Skip to content

Commit 8ea1712

Browse files
committed
prefer CACHED bit on buffer allocation
1 parent 275cfdb commit 8ea1712

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/FNA3D_Driver_Vulkan.c

+45-1
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,8 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
28612861

28622862
requiredMemoryPropertyFlags =
28632863
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
2864-
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
2864+
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
2865+
VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
28652866

28662867
while (VULKAN_INTERNAL_FindBufferMemoryRequirements(
28672868
renderer,
@@ -2897,6 +2898,49 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
28972898
}
28982899
}
28992900

2901+
/* Bind failed, try again without CACHED */
2902+
if (bindResult != 1)
2903+
{
2904+
memoryTypeIndex = 0;
2905+
requiredMemoryPropertyFlags =
2906+
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
2907+
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
2908+
2909+
while (VULKAN_INTERNAL_FindBufferMemoryRequirements(
2910+
renderer,
2911+
buffer,
2912+
requiredMemoryPropertyFlags,
2913+
&memoryRequirements,
2914+
&memoryTypeIndex
2915+
)) {
2916+
bindResult = FNA3D_Memory_BindResource(
2917+
renderer->allocator,
2918+
memoryTypeIndex,
2919+
memoryRequirements.size,
2920+
memoryRequirements.alignment,
2921+
(renderer->memoryProperties.memoryTypes[memoryTypeIndex].propertyFlags &
2922+
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0,
2923+
(renderer->memoryProperties.memoryTypes[memoryTypeIndex].propertyFlags &
2924+
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0,
2925+
isTransferBuffer,
2926+
size,
2927+
0,
2928+
(FNA3D_MemoryPlatformHandle) (size_t) buffer,
2929+
bufferHandle,
2930+
usedRegion
2931+
);
2932+
2933+
if (bindResult == 1)
2934+
{
2935+
break;
2936+
}
2937+
else /* Bind failed, try the next heap */
2938+
{
2939+
memoryTypeIndex += 1;
2940+
}
2941+
}
2942+
}
2943+
29002944
return bindResult;
29012945
}
29022946

0 commit comments

Comments
 (0)