summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-07-27 12:21:45 +0200
committerPaul Lemire <paul.lemire@kdab.com>2020-07-29 10:23:49 +0200
commit3411f202fdfd6e3c69421ae143013920a65704ee (patch)
treec43a2313002411d325cfb6916ff14baec4c2a081 /src
parent6fc896c28370577f7065961391d8a8d2794b55cf (diff)
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 <mike.krus@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/renderers/rhi/renderer/pipelineuboset.cpp33
-rw-r--r--src/plugins/renderers/rhi/renderer/pipelineuboset_p.h2
-rw-r--r--src/plugins/renderers/rhi/renderer/renderer.cpp9
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<QRhiCommandBuffer::DynamicOffset> 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<QRhiShaderResourceBinding> PipelineUBOSet::resourceLayout(const RenderCommand &command)
+std::vector<QRhiShaderResourceBinding> 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<QRhiShaderResourceBinding> 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<QRhiShaderResourceBinding> 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<QRhiShaderResourceBinding> 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<QRhiCommandBuffer::DynamicOffset> offsets(const RenderCommand &command) const;
- std::vector<QRhiShaderResourceBinding> resourceLayout(const RenderCommand &command);
+ std::vector<QRhiShaderResourceBinding> resourceLayout(const RHIShader *shader);
std::vector<QRhiShaderResourceBinding> 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<QRhiShaderResourceBinding> resourceBindings = uboSet->resourceLayout(cmd);
+ const std::vector<QRhiShaderResourceBinding> resourceBindings = uboSet->resourceLayout(shader);
QRhiShaderResourceBindings *shaderResourceBindings =
m_submissionContext->rhi()->newShaderResourceBindings();
graphicsPipeline->setShaderResourceBindings(shaderResourceBindings);