diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2020-08-27 15:03:53 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2020-09-13 21:50:21 +0200 |
commit | 959f3a35a089f5380ce9a84408dd8ecd090c633f (patch) | |
tree | 4b85dde05ab1b2de25b1e36b35b7d16e32192c65 | |
parent | 040866a8efa52d1a879233edf917f3c9347b93d0 (diff) |
rhi: RenderCommand resolve m_rhiShader at submission time
Resolving the rhiShader while updating the RenderCommand which happens
prior to submission time can lead to creating pipelines referencing outdated
rhi shaders.
This is what used to happen:
-> Shader with id shaderId is dirty
// Jobs
-> Resolve (outdated) m_rhiShader for command based on shaderId
-> Rebuild new shader code for shader with id shaderId
// Submission
-> Create new RHIShader for dirty shader and shaderId
(command still references the old one)
-> Build pipeline using outdated m_rhiShader
This is what would now happen:
-> Shader with id shaderId is dirty
// Jobs
-> Rebuild new shader code for shader with id shaderId
// Submission
-> Create new RHIShader for dirty shader and shaderId
-> Resolve (up to date) m_rhiShader for command based on shaderId
-> Build pipeline using correct m_rhiShader
Change-Id: Icb0b93228da409d1b3945f5f32480a344295e60f
Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r-- | src/plugins/renderers/rhi/renderer/renderer.cpp | 3 | ||||
-rw-r--r-- | src/plugins/renderers/rhi/renderer/renderview.cpp | 7 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index ccf2a0584..81d1194f3 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -1360,6 +1360,7 @@ Renderer::prepareCommandsSubmission(const std::vector<RenderView *> &renderViews rhiPassesInfo.push_back(bucket); } + RHIShaderManager *rhiShaderManager = m_RHIResourceManagers->rhiShaderManager(); // Assign a Graphics Pipeline to each RenderCommand for (size_t i = 0; i < renderViewCount; ++i) { RenderView *rv = renderViews[i]; @@ -1376,6 +1377,8 @@ Renderer::prepareCommandsSubmission(const std::vector<RenderView *> &renderViews GeometryRenderer *rGeometryRenderer = m_nodesManager->data<GeometryRenderer, GeometryRendererManager>( command.m_geometryRenderer); + + command.m_rhiShader = rhiShaderManager->lookupResource(command.m_shaderId); // By this time shaders should have been loaded RHIShader *shader = command.m_rhiShader; if (!shader) diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp index b37f57c45..c750373da 100644 --- a/src/plugins/renderers/rhi/renderer/renderview.cpp +++ b/src/plugins/renderers/rhi/renderer/renderview.cpp @@ -819,7 +819,6 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const Entity **entit int offset, int count) const { EntityRenderCommandData commands; - RHIShaderManager *rhiShaderManager = m_renderer->rhiResourceManagers()->rhiShaderManager(); commands.reserve(count); @@ -869,11 +868,9 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const Entity **entit m_renderer->defaultRenderState()->changeCost(command.m_stateSet.data()); } command.m_shaderId = pass->shaderProgram(); - command.m_rhiShader = rhiShaderManager->lookupResource(command.m_shaderId); - - // It takes two frames to have a valid command as we can only - // reference a glShader at frame n if it has been loaded at frame n - 1 + // At submission time, shaderId is used to retrieve a RHIShader + // No point in continuing if shaderId is null if (!command.m_shaderId) continue; |