From 445fb40081c870c0a9b1c1c3cf27b20fdd36a531 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 24 Oct 2023 21:24:40 +0200 Subject: rhi: d3d12: Do not waste time on sorting the binding list Nothing is relying on the binding list being sorted based on the binding number. In many ways the D3D12 backend is very similar to the OpenGL one: the srb merely holds some flags derived from the binding list and that's it really, no native resources or other content are owned directly by the binding set objects. Change-Id: I35d652c9738308bff691095e43aea9706031dd90 Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhid3d12.cpp | 23 +++++------------------ src/gui/rhi/qrhid3d12_p.h | 4 +++- 2 files changed, 8 insertions(+), 19 deletions(-) (limited to 'src/gui/rhi') diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 47c0a228b1..502a9bc911 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -951,8 +951,8 @@ void QRhiD3D12::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind QD3D12ShaderResourceBindings *srbD = QRHI_RES(QD3D12ShaderResourceBindings, srb); - for (int i = 0, ie = srbD->sortedBindings.size(); i != ie; ++i) { - const QRhiShaderResourceBinding::Data *b = shaderResourceBindingData(srbD->sortedBindings[i]); + for (int i = 0, ie = srbD->m_bindings.size(); i != ie; ++i) { + const QRhiShaderResourceBinding::Data *b = shaderResourceBindingData(srbD->m_bindings[i]); switch (b->type) { case QRhiShaderResourceBinding::UniformBuffer: { @@ -2546,8 +2546,8 @@ static inline QPair mapBinding(int binding, const QShader::NativeResou void QD3D12ShaderResourceVisitor::visit() { - for (int bindingIdx = 0, bindingCount = srb->sortedBindings.count(); bindingIdx != bindingCount; ++bindingIdx) { - const QRhiShaderResourceBinding &b(srb->sortedBindings[bindingIdx]); + for (int bindingIdx = 0, bindingCount = srb->m_bindings.count(); bindingIdx != bindingCount; ++bindingIdx) { + const QRhiShaderResourceBinding &b(srb->m_bindings[bindingIdx]); const QRhiShaderResourceBinding::Data *bd = QRhiImplementation::shaderResourceBindingData(b); for (int stageIdx = 0; stageIdx < stageCount; ++stageIdx) { @@ -4767,8 +4767,6 @@ QD3D12ShaderResourceBindings::~QD3D12ShaderResourceBindings() void QD3D12ShaderResourceBindings::destroy() { - sortedBindings.clear(); - QRHI_RES_RHI(QRhiD3D12); if (rhiD) rhiD->unregisterResource(this); @@ -4776,20 +4774,14 @@ void QD3D12ShaderResourceBindings::destroy() bool QD3D12ShaderResourceBindings::create() { - if (!sortedBindings.isEmpty()) - destroy(); - QRHI_RES_RHI(QRhiD3D12); if (!rhiD->sanityCheckShaderResourceBindings(this)) return false; rhiD->updateLayoutDesc(this); - std::copy(m_bindings.cbegin(), m_bindings.cend(), std::back_inserter(sortedBindings)); - std::sort(sortedBindings.begin(), sortedBindings.end(), QRhiImplementation::sortedBindingLessThan); - hasDynamicOffset = false; - for (const QRhiShaderResourceBinding &b : sortedBindings) { + for (const QRhiShaderResourceBinding &b : std::as_const(m_bindings)) { const QRhiShaderResourceBinding::Data *bd = QRhiImplementation::shaderResourceBindingData(b); if (bd->type == QRhiShaderResourceBinding::UniformBuffer && bd->u.ubuf.hasDynamicOffset) { hasDynamicOffset = true; @@ -4812,11 +4804,6 @@ bool QD3D12ShaderResourceBindings::create() void QD3D12ShaderResourceBindings::updateResources(UpdateFlags flags) { - sortedBindings.clear(); - std::copy(m_bindings.cbegin(), m_bindings.cend(), std::back_inserter(sortedBindings)); - if (!flags.testFlag(BindingsAreSorted)) - std::sort(sortedBindings.begin(), sortedBindings.end(), QRhiImplementation::sortedBindingLessThan); - generation += 1; } diff --git a/src/gui/rhi/qrhid3d12_p.h b/src/gui/rhi/qrhid3d12_p.h index 2f8e00f130..e4bf9a1fde 100644 --- a/src/gui/rhi/qrhid3d12_p.h +++ b/src/gui/rhi/qrhid3d12_p.h @@ -867,9 +867,11 @@ struct QD3D12ShaderResourceBindings : public QRhiShaderResourceBindings QD3D12ShaderResourceVisitor::StorageOp op, int shaderRegister); - QVarLengthArray sortedBindings; bool hasDynamicOffset = false; uint generation = 0; + + friend class QRhiD3D12; + friend struct QD3D12ShaderResourceVisitor; }; struct QD3D12GraphicsPipeline : public QRhiGraphicsPipeline -- cgit v1.2.3