require CpuBuffers to be host-local

pull/50/head
cosmonaut 2024-02-16 18:43:02 -08:00
parent f5e25979f4
commit a0414d0a4f
1 changed files with 30 additions and 4 deletions

View File

@ -709,6 +709,7 @@ struct VulkanBuffer
uint8_t requireHostVisible; uint8_t requireHostVisible;
uint8_t preferDeviceLocal; uint8_t preferDeviceLocal;
uint8_t requireHostLocal;
SDL_atomic_t referenceCount; /* Tracks command buffer usage */ SDL_atomic_t referenceCount; /* Tracks command buffer usage */
@ -2350,6 +2351,7 @@ static uint8_t VULKAN_INTERNAL_FindMemoryType(
VulkanRenderer *renderer, VulkanRenderer *renderer,
uint32_t typeFilter, uint32_t typeFilter,
VkMemoryPropertyFlags requiredProperties, VkMemoryPropertyFlags requiredProperties,
VkMemoryPropertyFlags ignoredProperties,
uint32_t *memoryTypeIndex uint32_t *memoryTypeIndex
) { ) {
uint32_t i; uint32_t i;
@ -2357,7 +2359,8 @@ static uint8_t VULKAN_INTERNAL_FindMemoryType(
for (i = *memoryTypeIndex; 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 )
{ {
*memoryTypeIndex = i; *memoryTypeIndex = i;
return 1; return 1;
@ -2371,6 +2374,7 @@ static uint8_t VULKAN_INTERNAL_FindBufferMemoryRequirements(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VkBuffer buffer, VkBuffer buffer,
VkMemoryPropertyFlags requiredMemoryProperties, VkMemoryPropertyFlags requiredMemoryProperties,
VkMemoryPropertyFlags ignoredMemoryProperties,
VkMemoryRequirements2KHR *pMemoryRequirements, VkMemoryRequirements2KHR *pMemoryRequirements,
uint32_t *pMemoryTypeIndex uint32_t *pMemoryTypeIndex
) { ) {
@ -2390,6 +2394,7 @@ static uint8_t VULKAN_INTERNAL_FindBufferMemoryRequirements(
renderer, renderer,
pMemoryRequirements->memoryRequirements.memoryTypeBits, pMemoryRequirements->memoryRequirements.memoryTypeBits,
requiredMemoryProperties, requiredMemoryProperties,
ignoredMemoryProperties,
pMemoryTypeIndex pMemoryTypeIndex
); );
} }
@ -2417,6 +2422,7 @@ static uint8_t VULKAN_INTERNAL_FindImageMemoryRequirements(
renderer, renderer,
pMemoryRequirements->memoryRequirements.memoryTypeBits, pMemoryRequirements->memoryRequirements.memoryTypeBits,
requiredMemoryPropertyFlags, requiredMemoryPropertyFlags,
0,
pMemoryTypeIndex pMemoryTypeIndex
); );
} }
@ -2925,6 +2931,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
VkBuffer buffer, VkBuffer buffer,
VkDeviceSize size, VkDeviceSize size,
uint8_t requireHostVisible, uint8_t requireHostVisible,
uint8_t requireHostLocal,
uint8_t preferDeviceLocal, uint8_t preferDeviceLocal,
uint8_t dedicatedAllocation, uint8_t dedicatedAllocation,
VulkanMemoryUsedRegion** usedRegion VulkanMemoryUsedRegion** usedRegion
@ -2932,6 +2939,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
uint8_t bindResult = 0; uint8_t bindResult = 0;
uint32_t memoryTypeIndex = 0; uint32_t memoryTypeIndex = 0;
VkMemoryPropertyFlags requiredMemoryPropertyFlags = 0; VkMemoryPropertyFlags requiredMemoryPropertyFlags = 0;
VkMemoryPropertyFlags ignoredMemoryPropertyFlags = 0;
VkMemoryRequirements2KHR memoryRequirements = VkMemoryRequirements2KHR memoryRequirements =
{ {
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
@ -2945,7 +2953,11 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
} }
if (preferDeviceLocal) if (requireHostLocal)
{
ignoredMemoryPropertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
else if (preferDeviceLocal)
{ {
requiredMemoryPropertyFlags |= requiredMemoryPropertyFlags |=
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
@ -2955,6 +2967,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
renderer, renderer,
buffer, buffer,
requiredMemoryPropertyFlags, requiredMemoryPropertyFlags,
ignoredMemoryPropertyFlags,
&memoryRequirements, &memoryRequirements,
&memoryTypeIndex &memoryTypeIndex
)) { )) {
@ -2979,7 +2992,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
} }
} }
/* Bind failed, try again without preferred flags */ /* Bind failed, try again with fallback flags */
if (bindResult != 1) if (bindResult != 1)
{ {
memoryTypeIndex = 0; memoryTypeIndex = 0;
@ -2992,6 +3005,11 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
} }
if (requireHostLocal)
{
ignoredMemoryPropertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
/* Follow-up for the warning logged by FindMemoryType */ /* Follow-up for the warning logged by FindMemoryType */
if (!renderer->unifiedMemoryWarning) if (!renderer->unifiedMemoryWarning)
{ {
@ -3003,6 +3021,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
renderer, renderer,
buffer, buffer,
requiredMemoryPropertyFlags, requiredMemoryPropertyFlags,
ignoredMemoryPropertyFlags,
&memoryRequirements, &memoryRequirements,
&memoryTypeIndex &memoryTypeIndex
)) { )) {
@ -4106,6 +4125,7 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
VulkanResourceAccessType resourceAccessType, VulkanResourceAccessType resourceAccessType,
VkBufferUsageFlags usage, VkBufferUsageFlags usage,
uint8_t requireHostVisible, uint8_t requireHostVisible,
uint8_t requireHostLocal,
uint8_t preferDeviceLocal, uint8_t preferDeviceLocal,
uint8_t dedicatedAllocation uint8_t dedicatedAllocation
) { ) {
@ -4120,6 +4140,7 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
buffer->resourceAccessType = resourceAccessType; buffer->resourceAccessType = resourceAccessType;
buffer->usage = usage; buffer->usage = usage;
buffer->requireHostVisible = requireHostVisible; buffer->requireHostVisible = requireHostVisible;
buffer->requireHostLocal = requireHostLocal;
buffer->preferDeviceLocal = preferDeviceLocal; buffer->preferDeviceLocal = preferDeviceLocal;
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@ -4144,6 +4165,7 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
buffer->buffer, buffer->buffer,
buffer->size, buffer->size,
buffer->requireHostVisible, buffer->requireHostVisible,
buffer->requireHostLocal,
buffer->preferDeviceLocal, buffer->preferDeviceLocal,
dedicatedAllocation, dedicatedAllocation,
&buffer->usedRegion &buffer->usedRegion
@ -4235,6 +4257,7 @@ static VulkanUniformBufferObject* VULKAN_INTERNAL_CreateUniformBufferObject(
resourceAccessType, resourceAccessType,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
1, 1,
0,
1, 1,
1 1
); );
@ -4290,7 +4313,7 @@ static VulkanUniformBufferObject* VULKAN_INTERNAL_CreateUniformBufferObject(
return uniformBufferObject; return uniformBufferObject;
} }
/* Buffer indirection so we can cleanly defrag */ /* Buffer indirection so we can cleanly defrag GpuBuffers */
static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer( static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
VulkanRenderer *renderer, VulkanRenderer *renderer,
uint32_t sizeInBytes, uint32_t sizeInBytes,
@ -4309,6 +4332,7 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
resourceAccessType, resourceAccessType,
usageFlags, usageFlags,
0, 0,
0,
1, 1,
0 0
); );
@ -6803,6 +6827,7 @@ static Refresh_CpuBuffer* VULKAN_CreateCpuBuffer(
RESOURCE_ACCESS_NONE, RESOURCE_ACCESS_NONE,
vulkanUsageFlags, vulkanUsageFlags,
1, 1,
1,
0, 0,
1 1
); );
@ -10134,6 +10159,7 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory(
RESOURCE_ACCESS_NONE, RESOURCE_ACCESS_NONE,
currentRegion->vulkanBuffer->usage, currentRegion->vulkanBuffer->usage,
currentRegion->vulkanBuffer->requireHostVisible, currentRegion->vulkanBuffer->requireHostVisible,
currentRegion->vulkanBuffer->requireHostLocal,
currentRegion->vulkanBuffer->preferDeviceLocal, currentRegion->vulkanBuffer->preferDeviceLocal,
0 0
); );