spirv: set variables to restrict by default
authorRhys Perry <pendingchaos02@gmail.com>
Thu, 21 May 2020 19:08:37 +0000 (20:08 +0100)
committerMarge Bot <eric+marge@anholt.net>
Wed, 24 Jun 2020 10:52:27 +0000 (10:52 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5207>

src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_private.h
src/compiler/spirv/vtn_variables.c

index 7565590fbd83088b174ebc5dc86cb0a024c534b4..2e351cc21ed077c7f6c652dfa7a850a1e4e43517 100644 (file)
@@ -4171,6 +4171,7 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
          break;
       }
 
+      b->mem_model = w[2];
       switch (w[2]) {
       case SpvMemoryModelSimple:
       case SpvMemoryModelGLSL450:
index 484ab853a821064b338e40b80b21c6db732ec815..059c94494a1ee201ac01c36fc5a8131dc3213e52 100644 (file)
@@ -685,6 +685,9 @@ struct vtn_builder {
 
    /* when a physical memory model is choosen */
    bool physical_ptrs;
+
+   /* memory model specified by OpMemoryModel */
+   unsigned mem_model;
 };
 
 nir_ssa_def *
index aad07d7556ddee3cf3ebdc734f8d576f8478f23d..51b40801091e27a2f613bbf7e9319413d6209e71 100644 (file)
@@ -1595,6 +1595,9 @@ apply_var_decoration(struct vtn_builder *b,
    case SpvDecorationRestrict:
       var_data->access |= ACCESS_RESTRICT;
       break;
+   case SpvDecorationAliased:
+      var_data->access &= ~ACCESS_RESTRICT;
+      break;
    case SpvDecorationVolatile:
       var_data->access |= ACCESS_VOLATILE;
       break;
@@ -1635,7 +1638,6 @@ apply_var_decoration(struct vtn_builder *b,
    case SpvDecorationRowMajor:
    case SpvDecorationColMajor:
    case SpvDecorationMatrixStride:
-   case SpvDecorationAliased:
    case SpvDecorationUniform:
    case SpvDecorationUniformId:
    case SpvDecorationLinkageAttributes:
@@ -2425,6 +2427,12 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
    if (var_initializer)
       var->var->pointer_initializer = var_initializer;
 
+   if (var->mode == vtn_variable_mode_uniform ||
+       var->mode == vtn_variable_mode_ssbo) {
+      /* SSBOs and images are assumed to not alias in the Simple, GLSL and Vulkan memory models */
+      var->var->data.access |= b->mem_model != SpvMemoryModelOpenCL ? ACCESS_RESTRICT : 0;
+   }
+
    vtn_foreach_decoration(b, val, var_decoration_cb, var);
    vtn_foreach_decoration(b, val, ptr_decoration_cb, val->pointer);