summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhigles2.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-03-08 14:25:57 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2021-03-09 12:00:48 +0100
commit80029e0ca65d4bf4575f7a08d186c781ec6c2f0e (patch)
tree876115cce65a0a9e9db63b2dc94bcbaf3e8e241c /src/gui/rhi/qrhigles2.cpp
parent2f9a3352b25417845375c47382f6e5fe931c157a (diff)
rhi: gl: Fix missing uniform data with certain command lists
Following patterns from the other backends is insufficient with OpenGL because we do not use real uniform buffers. There is currently a possibility that a shader program will be bound without following it with setting uniforms. Correct this by having a second level of tracking of the associated srb object in the pipelines. Pick-to: 6.0 6.1 Fixes: QTBUG-91630 Change-Id: I74a012daade826dd22c436bde06381c1233bad11 Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhigles2.cpp')
-rw-r--r--src/gui/rhi/qrhigles2.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index cd1e4ec944..1556e45fbf 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -1331,7 +1331,29 @@ void QRhiGles2::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind
}
}
- const bool srbChanged = gfxPsD ? (cbD->currentGraphicsSrb != srb) : (cbD->currentComputeSrb != srb);
+ bool srbChanged = gfxPsD ? (cbD->currentGraphicsSrb != srb) : (cbD->currentComputeSrb != srb);
+
+ // The Command::BindShaderResources command generated below is what will
+ // cause uniforms to be set (glUniformNxx). This needs some special
+ // handling here in this backend without real uniform buffers, because,
+ // like in other backends, we optimize out the setShaderResources when the
+ // srb that was set before is attempted to be set again on the command
+ // buffer, but that is incorrect if the same srb is now used with another
+ // pipeline. (because that could mean a glUseProgram not followed by
+ // up-to-date glUniform calls, i.e. with GL we have a strong dependency
+ // between the pipeline (== program) and the srb, unlike other APIs) This
+ // is the reason there is a second level of srb(+generation) tracking in
+ // the pipeline objects.
+ if (gfxPsD && (gfxPsD->currentSrb != srb || gfxPsD->currentSrbGeneration != srbD->generation)) {
+ srbChanged = true;
+ gfxPsD->currentSrb = srb;
+ gfxPsD->currentSrbGeneration = srbD->generation;
+ } else if (compPsD && (compPsD->currentSrb != srb || compPsD->currentSrbGeneration != srbD->generation)) {
+ srbChanged = true;
+ compPsD->currentSrb = srb;
+ compPsD->currentSrbGeneration = srbD->generation;
+ }
+
if (srbChanged || cbD->currentSrbGeneration != srbD->generation || srbD->hasDynamicOffset) {
if (gfxPsD) {
cbD->currentGraphicsSrb = srb;
@@ -4876,6 +4898,9 @@ bool QGles2GraphicsPipeline::create()
memset(uniformState, 0, sizeof(uniformState));
+ currentSrb = nullptr;
+ currentSrbGeneration = 0;
+
generation += 1;
rhiD->registerResource(this);
return true;
@@ -4964,6 +4989,9 @@ bool QGles2ComputePipeline::create()
memset(uniformState, 0, sizeof(uniformState));
+ currentSrb = nullptr;
+ currentSrbGeneration = 0;
+
generation += 1;
rhiD->registerResource(this);
return true;