Mesa (master): spirv: Whack sampler/image pointers to uniform

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Jan 12 23:56:26 UTC 2019


Module: Mesa
Branch: master
Commit: b57c1ec4219f01bfdb98bcab8fca4c44e87bd1a4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b57c1ec4219f01bfdb98bcab8fca4c44e87bd1a4

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Fri Jan 11 14:17:24 2019 -0600

spirv: Whack sampler/image pointers to uniform

A long time in a galaxy far far away, there was a GLSLang bug with how
it handled samplers passed in as function parameters.  (The bug can be
found here: https://github.com/KhronosGroup/glslang/issues/179.)
Unfortunately, that version was shipped in several apps and has been
causing heartburn for our SPIR-V parser ever since.

Recent changes to NIR uncovered a moderately old bug in how we work
around this issue.  In particular, we ended up with a deref_cast from
uniform to local which is not a no-op cast so nir_opt_deref wasn't
getting rid of the cast.  The only reason why it worked before was
because someone just happened to call nir_fixup_deref_modes which
"fixed" the cast (that shouldn't be happening) and then a later round of
copy-prop would get rid of it.  The fact that the deref_cast survived
that long without causing trouble for other parts of NIR is a bit
surprising.

Just whacking the mode of the pointer seems to fix it fairly
unobtrusively.  Currently, only apps with this bug will have a local
variable containing an image or sampler.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109304
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>

---

 src/compiler/spirv/vtn_variables.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 50cd1b42c6..6036295e61 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -1800,6 +1800,18 @@ vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
    ptr->type = ptr_type->deref;
    ptr->ptr_type = ptr_type;
 
+   /* To work around https://github.com/KhronosGroup/glslang/issues/179 we
+    * need to whack the mode because it creates a function parameter with the
+    * Function storage class even though it's a pointer to a sampler.  If we
+    * don't do this, then NIR won't get rid of the deref_cast for us.
+    */
+   if (ptr->mode == vtn_variable_mode_function &&
+       (ptr->type->base_type == vtn_base_type_sampler ||
+        ptr->type->base_type == vtn_base_type_sampled_image)) {
+      ptr->mode = vtn_variable_mode_uniform;
+      nir_mode = nir_var_uniform;
+   }
+
    if (vtn_pointer_uses_ssa_offset(b, ptr)) {
       /* This pointer type needs to have actual storage */
       vtn_assert(ptr_type->type);




More information about the mesa-commit mailing list