diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-09 20:12:34 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-11 10:58:50 +0200 |
commit | 8c9dfd7914472585f4fd0519f6f2a278225c3658 (patch) | |
tree | b2f19b304a9e6854e8d7f34ae2a4bc407d3aa0a4 /src/gui/rhi/qrhivulkan.cpp | |
parent | b540c783557808f778f8afd332b33aa81f7e5ec6 (diff) |
rhi: gl: vk: Pre-calculate the flags for dyn.offset
...instead of doing a loop in setShaderResources() just for this.
Change-Id: Iac8d4517783967c6b8bca4926cceca918f7dcdec
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhivulkan.cpp')
-rw-r--r-- | src/gui/rhi/qrhivulkan.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index d0e98fb751..ccb2c002b3 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -4283,24 +4283,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin } QVkShaderResourceBindings *srbD = QRHI_RES(QVkShaderResourceBindings, srb); - bool hasSlottedResourceInSrb = false; - bool hasDynamicOffsetInSrb = false; - - for (const QRhiShaderResourceBinding &binding : qAsConst(srbD->sortedBindings)) { - const QRhiShaderResourceBinding::Data *b = binding.data(); - switch (b->type) { - case QRhiShaderResourceBinding::UniformBuffer: - if (QRHI_RES(QVkBuffer, b->u.ubuf.buf)->m_type == QRhiBuffer::Dynamic) - hasSlottedResourceInSrb = true; - if (b->u.ubuf.hasDynamicOffset) - hasDynamicOffsetInSrb = true; - break; - default: - break; - } - } - - const int descSetIdx = hasSlottedResourceInSrb ? currentFrameSlot : 0; + const int descSetIdx = srbD->hasSlottedResource ? currentFrameSlot : 0; bool rewriteDescSet = false; // Do host writes and mark referenced shader resources as in-use. @@ -4429,13 +4412,13 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin // make sure the descriptors for the correct slot will get bound. // also, dynamic offsets always need a bind. - const bool forceRebind = (hasSlottedResourceInSrb && cbD->currentDescSetSlot != descSetIdx) || hasDynamicOffsetInSrb; + const bool forceRebind = (srbD->hasSlottedResource && cbD->currentDescSetSlot != descSetIdx) || srbD->hasDynamicOffset; const bool srbChanged = gfxPsD ? (cbD->currentGraphicsSrb != srb) : (cbD->currentComputeSrb != srb); if (forceRebind || rewriteDescSet || srbChanged || cbD->currentSrbGeneration != srbD->generation) { QVarLengthArray<uint32_t, 4> dynOfs; - if (hasDynamicOffsetInSrb) { + if (srbD->hasDynamicOffset) { // Filling out dynOfs based on the sorted bindings is important // because dynOfs has to be ordered based on the binding numbers, // and neither srb nor dynamicOffsets has any such ordering @@ -6249,6 +6232,18 @@ bool QVkShaderResourceBindings::create() return a.data()->binding < b.data()->binding; }); + hasSlottedResource = false; + hasDynamicOffset = false; + for (const QRhiShaderResourceBinding &binding : qAsConst(sortedBindings)) { + const QRhiShaderResourceBinding::Data *b = binding.data(); + if (b->type == QRhiShaderResourceBinding::UniformBuffer && b->u.ubuf.buf) { + if (QRHI_RES(QVkBuffer, b->u.ubuf.buf)->type() == QRhiBuffer::Dynamic) + hasSlottedResource = true; + if (b->u.ubuf.hasDynamicOffset) + hasDynamicOffset = true; + } + } + QVarLengthArray<VkDescriptorSetLayoutBinding, 4> vkbindings; for (const QRhiShaderResourceBinding &binding : qAsConst(sortedBindings)) { const QRhiShaderResourceBinding::Data *b = binding.data(); |