Optimize compute shader pipeline binding on D3D12 and Vulkan when unchanged

This commit is contained in:
Wojtek Figat
2025-08-09 23:58:15 +02:00
parent b5a431d2f5
commit 1915e1e7f4
3 changed files with 29 additions and 11 deletions

View File

@@ -746,6 +746,7 @@ void GPUContextVulkan::FrameBegin()
_stencilRef = 0;
_renderPass = nullptr;
_currentState = nullptr;
_currentCompute = nullptr;
_vertexLayout = nullptr;
_rtDepth = nullptr;
Platform::MemoryClear(_rtHandles, sizeof(_rtHandles));
@@ -1157,8 +1158,12 @@ void GPUContextVulkan::Dispatch(GPUShaderProgramCS* shader, uint32 threadGroupCo
FlushBarriers();
// Bind pipeline
vkCmdBindPipeline(cmdBuffer->GetHandle(), VK_PIPELINE_BIND_POINT_COMPUTE, pipelineState->GetHandle());
RENDER_STAT_PS_STATE_CHANGE();
if (_currentCompute != shaderVulkan)
{
_currentCompute = shaderVulkan;
vkCmdBindPipeline(cmdBuffer->GetHandle(), VK_PIPELINE_BIND_POINT_COMPUTE, pipelineState->GetHandle());
RENDER_STAT_PS_STATE_CHANGE();
}
// Bind descriptors sets to the compute pipeline
pipelineState->Bind(cmdBuffer);
@@ -1193,8 +1198,12 @@ void GPUContextVulkan::DispatchIndirect(GPUShaderProgramCS* shader, GPUBuffer* b
FlushBarriers();
// Bind pipeline
vkCmdBindPipeline(cmdBuffer->GetHandle(), VK_PIPELINE_BIND_POINT_COMPUTE, pipelineState->GetHandle());
RENDER_STAT_PS_STATE_CHANGE();
if (_currentCompute != shaderVulkan)
{
_currentCompute = shaderVulkan;
vkCmdBindPipeline(cmdBuffer->GetHandle(), VK_PIPELINE_BIND_POINT_COMPUTE, pipelineState->GetHandle());
RENDER_STAT_PS_STATE_CHANGE();
}
// Bind descriptors sets to the compute pipeline
pipelineState->Bind(cmdBuffer);
@@ -1346,6 +1355,7 @@ void GPUContextVulkan::Flush()
// Flush remaining and buffered commands
FlushState();
_currentState = nullptr;
_currentCompute = nullptr;
// Execute commands
_cmdBufferManager->SubmitActiveCmdBuffer();

View File

@@ -16,6 +16,7 @@ class GPUTextureViewVulkan;
class GPUBufferVulkan;
class GPUVertexLayoutVulkan;
class GPUPipelineStateVulkan;
class GPUShaderProgramCSVulkan;
class ComputePipelineStateVulkan;
class GPUConstantBufferVulkan;
class DescriptorPoolVulkan;
@@ -84,6 +85,7 @@ private:
RenderPassVulkan* _renderPass;
GPUPipelineStateVulkan* _currentState;
GPUShaderProgramCSVulkan* _currentCompute;
GPUVertexLayoutVulkan* _vertexLayout;
GPUTextureViewVulkan* _rtDepth;
GPUTextureViewVulkan* _rtHandles[GPU_MAX_RT_BINDED];