diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index 59a724c..7307e71 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -1539,6 +1539,10 @@ typedef struct VulkanCommandBuffer VulkanComputePipeline *currentComputePipeline; VulkanGraphicsPipeline *currentGraphicsPipeline; + uint32_t vertexUniformOffset; + uint32_t fragmentUniformOffset; + uint32_t computeUniformOffset; + VulkanTexture *renderPassColorTargetTextures[MAX_COLOR_TARGET_BINDINGS]; uint32_t renderPassColorTargetCount; VulkanTexture *renderPassDepthTexture; /* can be NULL */ @@ -5203,9 +5207,7 @@ static void VULKAN_DrawInstancedPrimitives( uint32_t baseVertex, uint32_t startIndex, uint32_t primitiveCount, - uint32_t instanceCount, - uint32_t vertexParamOffset, - uint32_t fragmentParamOffset + uint32_t instanceCount ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; @@ -5218,8 +5220,8 @@ static void VULKAN_DrawInstancedPrimitives( descriptorSets[2] = renderer->vertexUniformBufferObject->descriptorSet; descriptorSets[3] = renderer->fragmentUniformBufferObject->descriptorSet; - dynamicOffsets[0] = vertexParamOffset; - dynamicOffsets[1] = fragmentParamOffset; + dynamicOffsets[0] = vulkanCommandBuffer->vertexUniformOffset; + dynamicOffsets[1] = vulkanCommandBuffer->fragmentUniformOffset; renderer->vkCmdBindDescriptorSets( vulkanCommandBuffer->commandBuffer, @@ -5250,9 +5252,7 @@ static void VULKAN_DrawIndexedPrimitives( Refresh_CommandBuffer *commandBuffer, uint32_t baseVertex, uint32_t startIndex, - uint32_t primitiveCount, - uint32_t vertexParamOffset, - uint32_t fragmentParamOffset + uint32_t primitiveCount ) { VULKAN_DrawInstancedPrimitives( driverData, @@ -5260,9 +5260,7 @@ static void VULKAN_DrawIndexedPrimitives( baseVertex, startIndex, primitiveCount, - 1, - vertexParamOffset, - fragmentParamOffset + 1 ); } @@ -5270,9 +5268,7 @@ static void VULKAN_DrawPrimitives( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, uint32_t vertexStart, - uint32_t primitiveCount, - uint32_t vertexParamOffset, - uint32_t fragmentParamOffset + uint32_t primitiveCount ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; @@ -5285,8 +5281,8 @@ static void VULKAN_DrawPrimitives( descriptorSets[2] = renderer->vertexUniformBufferObject->descriptorSet; descriptorSets[3] = renderer->fragmentUniformBufferObject->descriptorSet; - dynamicOffsets[0] = vertexParamOffset; - dynamicOffsets[1] = fragmentParamOffset; + dynamicOffsets[0] = vulkanCommandBuffer->vertexUniformOffset; + dynamicOffsets[1] = vulkanCommandBuffer->fragmentUniformOffset; renderer->vkCmdBindDescriptorSets( vulkanCommandBuffer->commandBuffer, @@ -5317,9 +5313,7 @@ static void VULKAN_DrawPrimitivesIndirect( Refresh_GpuBuffer *buffer, uint32_t offsetInBytes, uint32_t drawCount, - uint32_t stride, - uint32_t vertexParamOffset, - uint32_t fragmentParamOffset + uint32_t stride ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; @@ -5332,8 +5326,8 @@ static void VULKAN_DrawPrimitivesIndirect( descriptorSets[2] = renderer->vertexUniformBufferObject->descriptorSet; descriptorSets[3] = renderer->fragmentUniformBufferObject->descriptorSet; - dynamicOffsets[0] = vertexParamOffset; - dynamicOffsets[1] = fragmentParamOffset; + dynamicOffsets[0] = vulkanCommandBuffer->vertexUniformOffset; + dynamicOffsets[1] = vulkanCommandBuffer->fragmentUniformOffset; renderer->vkCmdBindDescriptorSets( vulkanCommandBuffer->commandBuffer, @@ -6828,7 +6822,7 @@ static void VULKAN_INTERNAL_SetUniformBufferData( ); } -static uint32_t VULKAN_PushVertexShaderUniforms( +static void VULKAN_PushVertexShaderUniforms( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, void *data, @@ -6837,22 +6831,15 @@ static uint32_t VULKAN_PushVertexShaderUniforms( VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer* vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanGraphicsPipeline* graphicsPipeline = vulkanCommandBuffer->currentGraphicsPipeline; - uint32_t offset; - - if (graphicsPipeline->vertexUniformBlockSize == 0) - { - Refresh_LogError("Bound pipeline's vertex stage does not declare uniforms!"); - return 0; - } SDL_LockMutex(renderer->vertexUniformBufferObject->lock); - if (renderer->vertexUniformBufferObject->currentOffset + dataLengthInBytes + UBO_SECTION_SIZE >= UBO_BUFFER_SIZE) + if (renderer->vertexUniformBufferObject->currentOffset + graphicsPipeline->vertexUniformBlockSize + UBO_SECTION_SIZE >= UBO_BUFFER_SIZE) { renderer->vertexUniformBufferObject->currentOffset = 0; } - offset = renderer->vertexUniformBufferObject->currentOffset; + vulkanCommandBuffer->vertexUniformOffset = renderer->vertexUniformBufferObject->currentOffset; VULKAN_INTERNAL_SetUniformBufferData( renderer->vertexUniformBufferObject, @@ -6863,11 +6850,9 @@ static uint32_t VULKAN_PushVertexShaderUniforms( renderer->vertexUniformBufferObject->currentOffset += graphicsPipeline->vertexUniformBlockSize; SDL_UnlockMutex(renderer->vertexUniformBufferObject->lock); - - return offset; } -static uint32_t VULKAN_PushFragmentShaderUniforms( +static void VULKAN_PushFragmentShaderUniforms( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, void *data, @@ -6876,22 +6861,15 @@ static uint32_t VULKAN_PushFragmentShaderUniforms( VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer* vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanGraphicsPipeline* graphicsPipeline = vulkanCommandBuffer->currentGraphicsPipeline; - uint32_t offset; - - if (graphicsPipeline->fragmentUniformBlockSize == 0) - { - Refresh_LogError("Bound pipeline's fragment stage does not declare uniforms!"); - return 0; - } SDL_LockMutex(renderer->fragmentUniformBufferObject->lock); - if (renderer->fragmentUniformBufferObject->currentOffset + dataLengthInBytes + UBO_SECTION_SIZE >= UBO_BUFFER_SIZE) + if (renderer->fragmentUniformBufferObject->currentOffset + graphicsPipeline->fragmentUniformBlockSize + UBO_SECTION_SIZE >= UBO_BUFFER_SIZE) { renderer->fragmentUniformBufferObject->currentOffset = 0; } - offset = renderer->fragmentUniformBufferObject->currentOffset; + vulkanCommandBuffer->fragmentUniformOffset = renderer->fragmentUniformBufferObject->currentOffset; VULKAN_INTERNAL_SetUniformBufferData( renderer->fragmentUniformBufferObject, @@ -6902,11 +6880,9 @@ static uint32_t VULKAN_PushFragmentShaderUniforms( renderer->fragmentUniformBufferObject->currentOffset += graphicsPipeline->fragmentUniformBlockSize; SDL_UnlockMutex(renderer->fragmentUniformBufferObject->lock); - - return offset; } -static uint32_t VULKAN_PushComputeShaderUniforms( +static void VULKAN_PushComputeShaderUniforms( Refresh_Renderer *driverData, Refresh_CommandBuffer *commandBuffer, void *data, @@ -6915,22 +6891,15 @@ static uint32_t VULKAN_PushComputeShaderUniforms( VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer* vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; VulkanComputePipeline* computePipeline = vulkanCommandBuffer->currentComputePipeline; - uint32_t offset; - - if (computePipeline->uniformBlockSize == 0) - { - Refresh_LogError("Bound pipeline's compute stage does not declare uniforms!"); - return 0; - } SDL_LockMutex(renderer->computeUniformBufferObject->lock); - if (renderer->computeUniformBufferObject->currentOffset + dataLengthInBytes + UBO_SECTION_SIZE >= UBO_BUFFER_SIZE) + if (renderer->computeUniformBufferObject->currentOffset + computePipeline->uniformBlockSize + UBO_SECTION_SIZE >= UBO_BUFFER_SIZE) { renderer->computeUniformBufferObject->currentOffset = 0; } - offset = renderer->computeUniformBufferObject->currentOffset; + vulkanCommandBuffer->computeUniformOffset = renderer->computeUniformBufferObject->currentOffset; VULKAN_INTERNAL_SetUniformBufferData( renderer->computeUniformBufferObject, @@ -6941,8 +6910,6 @@ static uint32_t VULKAN_PushComputeShaderUniforms( renderer->computeUniformBufferObject->currentOffset += computePipeline->uniformBlockSize; SDL_UnlockMutex(renderer->computeUniformBufferObject->lock); - - return offset; } /* If fetching an image descriptor, descriptorImageInfos must not be NULL. @@ -8239,8 +8206,7 @@ static void VULKAN_DispatchCompute( Refresh_CommandBuffer *commandBuffer, uint32_t groupCountX, uint32_t groupCountY, - uint32_t groupCountZ, - uint32_t computeParamOffset + uint32_t groupCountZ ) { VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer; @@ -8259,7 +8225,7 @@ static void VULKAN_DispatchCompute( 3, descriptorSets, 1, - &computeParamOffset + &vulkanCommandBuffer->computeUniformOffset ); renderer->vkCmdDispatch( @@ -9280,6 +9246,10 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer( commandBuffer->currentComputePipeline = NULL; commandBuffer->currentGraphicsPipeline = NULL; + commandBuffer->vertexUniformOffset = 0; + commandBuffer->fragmentUniformOffset = 0; + commandBuffer->computeUniformOffset = 0; + commandBuffer->renderPassColorTargetCount = 0; commandBuffer->autoReleaseFence = 1;