From 903192cb4c886920186f078bc1638a6a0d1e8c88 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 11 Jan 2023 02:41:30 +0000 Subject: [PATCH] Descriptor validation fix (#32) The validator layer was complaining about us updating bound descriptor sets, this is technically a bug in the validator layer but resetting the command buffer in Cleanup makes more sense anyway. Also changed the wait for timeout call to a fence status query to make it easier to understand. Reviewed-on: https://gitea.moonside.games/MoonsideGames/Refresh/pulls/32 --- src/Refresh_Driver_Vulkan.c | 55 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index e94b93e..77eb353 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -9227,27 +9227,6 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer( commandBuffer->renderPassInProgress = 0; commandBuffer->renderPassColorTargetCount = 0; - result = renderer->vkResetCommandBuffer( - commandBuffer->commandBuffer, - VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT - ); - - if (result != VK_SUCCESS) - { - LogVulkanResultAsError("vkResetCommandBuffer", result); - } - - result = renderer->vkResetFences( - renderer->logicalDevice, - 1, - &commandBuffer->inFlightFence - ); - - if (result != VK_SUCCESS) - { - LogVulkanResultAsError("vkResetFences", result); - } - VULKAN_INTERNAL_BeginCommandBuffer(renderer, commandBuffer); return (Refresh_CommandBuffer*) commandBuffer; @@ -9651,6 +9630,7 @@ static void VULKAN_INTERNAL_CleanCommandBuffer( uint32_t i; VulkanUniformBuffer *uniformBuffer; DescriptorSetData *descriptorSetData; + VkResult result; /* Bound uniform buffers are now available */ @@ -9780,12 +9760,35 @@ static void VULKAN_INTERNAL_CleanCommandBuffer( SDL_UnlockMutex(renderer->acquireCommandBufferLock); - /* Resent presentation data */ + /* Reset presentation data */ commandBuffer->presentDataCount = 0; commandBuffer->waitSemaphoreCount = 0; commandBuffer->signalSemaphoreCount = 0; + /* Reset Vulkan state */ + + result = renderer->vkResetCommandBuffer( + commandBuffer->commandBuffer, + VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT + ); + + if (result != VK_SUCCESS) + { + LogVulkanResultAsError("vkResetCommandBuffer", result); + } + + result = renderer->vkResetFences( + renderer->logicalDevice, + 1, + &commandBuffer->inFlightFence + ); + + if (result != VK_SUCCESS) + { + LogVulkanResultAsError("vkResetFences", result); + } + /* Remove this command buffer from the submitted list */ for (i = 0; i < renderer->submittedCommandBufferCount; i += 1) { @@ -9955,13 +9958,9 @@ static void VULKAN_Submit( for (i = renderer->submittedCommandBufferCount - 1; i >= 0; i -= 1) { - /* If we set a timeout of 0, we can query the command buffer state */ - vulkanResult = renderer->vkWaitForFences( + vulkanResult = renderer->vkGetFenceStatus( renderer->logicalDevice, - 1, - &renderer->submittedCommandBuffers[i]->inFlightFence, - VK_TRUE, - 0 + renderer->submittedCommandBuffers[i]->inFlightFence ); if (vulkanResult == VK_SUCCESS)