Mesa (master): spirv: Refactor the base case of offset_pointer_dereference

Jason Ekstrand jekstrand at kemper.freedesktop.org
Wed Dec 6 06:02:44 UTC 2017


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

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Wed Oct 18 16:40:39 2017 -0700

spirv: Refactor the base case of offset_pointer_dereference

This makes us key off of !offset instead of !block_index.  It also puts
the guts inside a switch statement so that we can handle more than just
UBOs and SSBOs.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>

---

 src/compiler/spirv/vtn_variables.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 49d9d39962..c5a13c3bd3 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -161,24 +161,32 @@ vtn_ssa_offset_pointer_dereference(struct vtn_builder *b,
       idx++;
    }
 
-   if (!block_index) {
+   if (!offset) {
+      /* This is the first access chain so we don't have a block index */
+      vtn_assert(!block_index);
+
       vtn_assert(base->var);
-      if (glsl_type_is_array(type->type)) {
-         /* We need at least one element in the chain */
-         vtn_assert(deref_chain->length >= 1);
+      switch (base->mode) {
+      case vtn_variable_mode_ubo:
+      case vtn_variable_mode_ssbo:
+         if (glsl_type_is_array(type->type)) {
+            /* We need at least one element in the chain */
+            vtn_assert(deref_chain->length >= 1);
+
+            nir_ssa_def *desc_arr_idx =
+               vtn_access_link_as_ssa(b, deref_chain->link[0], 1);
+            block_index = vtn_variable_resource_index(b, base->var, desc_arr_idx);
+            type = type->array_element;
+            idx++;
+         } else {
+            block_index = vtn_variable_resource_index(b, base->var, NULL);
+         }
+         offset = nir_imm_int(&b->nb, 0);
+         break;
 
-         nir_ssa_def *desc_arr_idx =
-            vtn_access_link_as_ssa(b, deref_chain->link[0], 1);
-         block_index = vtn_variable_resource_index(b, base->var, desc_arr_idx);
-         type = type->array_element;
-         idx++;
-      } else {
-         block_index = vtn_variable_resource_index(b, base->var, NULL);
+      default:
+         vtn_fail("Invalid offset pointer mode");
       }
-
-      /* This is the first access chain so we also need an offset */
-      vtn_assert(!offset);
-      offset = nir_imm_int(&b->nb, 0);
    }
    vtn_assert(offset);
 




More information about the mesa-commit mailing list