From 3411f202fdfd6e3c69421ae143013920a65704ee Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 27 Jul 2020 12:21:45 +0200 Subject: rhi: Update PipelineUBOSet::resourceLayout to not allocate UBOs This is possible since the merge of https://codereview.qt-project.org/c/qt/qtbase/+/307472 When we build pipelines, we only need to know about the layout of the resource, allocating UBO is only required when we want to use the pipeline for draw calls, later. Change-Id: If0ee9238fb13aea04d473c01a7bac3df2ffb02e0 Reviewed-by: Mike Krus --- .../renderers/rhi/renderer/pipelineuboset.cpp | 33 ++++++---------------- .../renderers/rhi/renderer/pipelineuboset_p.h | 2 +- src/plugins/renderers/rhi/renderer/renderer.cpp | 9 +----- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp index 26165c074..82da03196 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp @@ -190,14 +190,12 @@ std::vector PipelineUBOSet::offsets(const Rend // Resources in that function which means that one will be about providing the // Pipeline resourceLayout only and resourceBindings will be about providing // the actual resources for a RenderCommand -std::vector PipelineUBOSet::resourceLayout(const RenderCommand &command) +std::vector PipelineUBOSet::resourceLayout(const RHIShader *shader) { - RHITextureManager *textureManager = m_resourceManagers->rhiTextureManager(); - RHIShader *shader = command.m_rhiShader; const QRhiShaderResourceBinding::StageFlags stages = QRhiShaderResourceBinding::VertexStage|QRhiShaderResourceBinding::FragmentStage; std::vector bindings = { - QRhiShaderResourceBinding::uniformBuffer(0, stages, m_rvUBO.buffer->rhiBuffer()), - QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(1, stages, m_commandsUBO.buffer->rhiBuffer(), m_commandsUBO.buffer->size()) + QRhiShaderResourceBinding::uniformBuffer(0, stages, nullptr), + QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(1, stages, nullptr, sizeof(CommandUBO)) }; // TO DO: Handle Parameters that directly define a UBO or SSBO @@ -206,29 +204,16 @@ std::vector PipelineUBOSet::resourceLayout(const Rend // Create additional empty UBO Buffer for UBO with binding point > 1 (since // we assume 0 and 1 and for Qt3D standard values) - // TO DO: Only bind buffer if we haven't already bound a user defined UBO to - // the binding point for (const UBOBufferWithBindingAndBlockSize &ubo : m_materialsUBOs) bindings.push_back( QRhiShaderResourceBinding::uniformBufferWithDynamicOffset( - ubo.binding, stages, ubo.buffer->rhiBuffer(), ubo.buffer->size())); + ubo.binding, stages, nullptr, ubo.blockSize)); // Samplers - for (const ShaderParameterPack::NamedResource &textureParameter : command.m_parameterPack.textures()) { - const HRHITexture &handle = textureManager->getOrAcquireHandle(textureParameter.nodeId); - const RHITexture *textureData = handle.data(); - - for (const ShaderAttribute &samplerAttribute : shader->samplers()) { - if (samplerAttribute.m_nameId == textureParameter.glslNameId) { - const auto rhiTexture = textureData->getRhiTexture(); - const auto rhiSampler = textureData->getRhiSampler(); - if (rhiTexture && rhiSampler) { - bindings.push_back(QRhiShaderResourceBinding::sampledTexture( - samplerAttribute.m_location, - stages, rhiTexture, rhiSampler)); - } - } - } + for (const ShaderAttribute &samplerAttribute : shader->samplers()) { + bindings.push_back(QRhiShaderResourceBinding::sampledTexture( + samplerAttribute.m_location, + stages, nullptr, nullptr)); } return bindings; @@ -250,8 +235,6 @@ std::vector PipelineUBOSet::resourceBindings(const Re // Create additional empty UBO Buffer for UBO with binding point > 1 (since // we assume 0 and 1 and for Qt3D standard values) - // TO DO: Only bind buffer if we haven't already bound a user defined UBO to - // the binding point for (const UBOBufferWithBindingAndBlockSize &ubo : m_materialsUBOs) bindings.push_back( QRhiShaderResourceBinding::uniformBufferWithDynamicOffset( diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h index 6eae0ccaf..699ff0602 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h @@ -88,7 +88,7 @@ public: size_t distanceToCommand(const RenderCommand &command) const; std::vector offsets(const RenderCommand &command) const; - std::vector resourceLayout(const RenderCommand &command); + std::vector resourceLayout(const RHIShader *shader); std::vector resourceBindings(const RenderCommand &command); bool allocateUBOs(SubmissionContext *ctx); diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index 8e0af1701..f33626b8f 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -951,15 +951,8 @@ void Renderer::buildGraphicsPipelines(RHIGraphicsPipeline *graphicsPipeline, return onFailure(); } - // TO DO: Remove once https://codereview.qt-project.org/c/qt/qtbase/+/307472 lands - // Allocate UBOs - // Note: we have to do this even though we might not use the UBOs simply - // because RHI needs actual UBO/Texture to recreate the ResourceBindings - if (!uboSet->allocateUBOs(m_submissionContext.data())) - return onFailure(); - // Set Resource Bindings - const std::vector resourceBindings = uboSet->resourceLayout(cmd); + const std::vector resourceBindings = uboSet->resourceLayout(shader); QRhiShaderResourceBindings *shaderResourceBindings = m_submissionContext->rhi()->newShaderResourceBindings(); graphicsPipeline->setShaderResourceBindings(shaderResourceBindings); -- cgit v1.2.3