Mesa (master): spirv: Do implicit conversions of uint to bool in OpStore

Jason Ekstrand jekstrand at kemper.freedesktop.org
Mon Jan 8 23:16:06 UTC 2018


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

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Wed Jan  3 09:26:18 2018 -0800

spirv: Do implicit conversions of uint to bool in OpStore

Technically, the GLSLang bug related to this can also affect SSBO writes
where the bool -> uint conversion is missing.  However, the only known
shipping application with an old enough version of GLSLang to cause
issues with this is the new DOOM game so we keep the workaround as small
as possible.

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

---

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

diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 41125f689a..eb306d0c4a 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -2041,6 +2041,25 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
       vtn_fail_if(dest->type->type == NULL,
                   "Invalid destination type for OpStore");
 
+      if (glsl_get_base_type(dest->type->type) == GLSL_TYPE_BOOL &&
+          glsl_get_base_type(src_val->type->type) == GLSL_TYPE_UINT) {
+         /* Early versions of GLSLang would use uint types for UBOs/SSBOs but
+          * would then store them to a local variable as bool.  Work around
+          * the issue by doing an implicit conversion.
+          *
+          * https://github.com/KhronosGroup/glslang/issues/170
+          * https://bugs.freedesktop.org/show_bug.cgi?id=104424
+          */
+         vtn_warn("OpStore of value of type OpTypeInt to a pointer to type "
+                  "OpTypeBool.  Doing an implicit conversion to work around "
+                  "the problem.");
+         struct vtn_ssa_value *bool_ssa =
+            vtn_create_ssa_value(b, dest->type->type);
+         bool_ssa->def = nir_i2b(&b->nb, vtn_ssa_value(b, w[2])->def);
+         vtn_variable_store(b, bool_ssa, dest);
+         break;
+      }
+
       vtn_assert_types_equal(b, opcode, dest_val->type->deref, src_val->type);
 
       if (glsl_type_is_sampler(dest->type->type)) {




More information about the mesa-commit mailing list