Mesa (master): nir/spirv: Rename some things from access_chain to pointer

Jason Ekstrand jekstrand at kemper.freedesktop.org
Wed Jul 5 22:27:10 UTC 2017


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

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Thu Jun 29 10:33:27 2017 -0700

nir/spirv: Rename some things from access_chain to pointer

We're about to add a vtn_pointer data structure and this will prevent
some rename churn in the next commit.

Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>

---

 src/compiler/spirv/spirv_to_nir.c  | 65 +++++++++++++++++---------------------
 src/compiler/spirv/vtn_cfg.c       |  9 +++---
 src/compiler/spirv/vtn_private.h   | 18 +++++------
 src/compiler/spirv/vtn_variables.c | 63 ++++++++++++++++++------------------
 4 files changed, 73 insertions(+), 82 deletions(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 78ccd65903..02b42f2f1f 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -185,9 +185,9 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
    case vtn_value_type_ssa:
       return val->ssa;
 
-   case vtn_value_type_access_chain:
+   case vtn_value_type_pointer:
       /* This is needed for function parameters */
-      return vtn_variable_load(b, val->access_chain);
+      return vtn_variable_load(b, val->pointer);
 
    default:
       unreachable("Invalid type for an SSA value");
@@ -1345,8 +1345,8 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
    for (unsigned i = 0; i < call->num_params; i++) {
       unsigned arg_id = w[4 + i];
       struct vtn_value *arg = vtn_untyped_value(b, arg_id);
-      if (arg->value_type == vtn_value_type_access_chain) {
-         nir_deref_var *d = vtn_access_chain_to_deref(b, arg->access_chain);
+      if (arg->value_type == vtn_value_type_pointer) {
+         nir_deref_var *d = vtn_pointer_to_deref(b, arg->pointer);
          call->params[i] = nir_deref_var_clone(d, call);
       } else {
          struct vtn_ssa_value *arg_ssa = vtn_ssa_value(b, arg_id);
@@ -1434,19 +1434,18 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
          vtn_push_value(b, w[2], vtn_value_type_sampled_image);
       val->sampled_image = ralloc(b, struct vtn_sampled_image);
       val->sampled_image->image =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+         vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       val->sampled_image->sampler =
-         vtn_value(b, w[4], vtn_value_type_access_chain)->access_chain;
+         vtn_value(b, w[4], vtn_value_type_pointer)->pointer;
       return;
    } else if (opcode == SpvOpImage) {
-      struct vtn_value *val =
-         vtn_push_value(b, w[2], vtn_value_type_access_chain);
+      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
       struct vtn_value *src_val = vtn_untyped_value(b, w[3]);
       if (src_val->value_type == vtn_value_type_sampled_image) {
-         val->access_chain = src_val->sampled_image->image;
+         val->pointer = src_val->sampled_image->image;
       } else {
-         assert(src_val->value_type == vtn_value_type_access_chain);
-         val->access_chain = src_val->access_chain;
+         assert(src_val->value_type == vtn_value_type_pointer);
+         val->pointer = src_val->pointer;
       }
       return;
    }
@@ -1459,9 +1458,9 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    if (sampled_val->value_type == vtn_value_type_sampled_image) {
       sampled = *sampled_val->sampled_image;
    } else {
-      assert(sampled_val->value_type == vtn_value_type_access_chain);
+      assert(sampled_val->value_type == vtn_value_type_pointer);
       sampled.image = NULL;
-      sampled.sampler = sampled_val->access_chain;
+      sampled.sampler = sampled_val->pointer;
    }
 
    const struct glsl_type *image_type;
@@ -1685,10 +1684,10 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
       unreachable("Invalid base type for sampler result");
    }
 
-   nir_deref_var *sampler = vtn_access_chain_to_deref(b, sampled.sampler);
+   nir_deref_var *sampler = vtn_pointer_to_deref(b, sampled.sampler);
    nir_deref_var *texture;
    if (sampled.image) {
-      nir_deref_var *image = vtn_access_chain_to_deref(b, sampled.image);
+      nir_deref_var *image = vtn_pointer_to_deref(b, sampled.image);
       texture = image;
    } else {
       texture = sampler;
@@ -1850,8 +1849,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
          vtn_push_value(b, w[2], vtn_value_type_image_pointer);
       val->image = ralloc(b, struct vtn_image_pointer);
 
-      val->image->image =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+      val->image->image = vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       val->image->coord = get_image_coord(b, w[4]);
       val->image->sample = vtn_ssa_value(b, w[5])->def;
       return;
@@ -1883,15 +1881,13 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpImageQuerySize:
-      image.image =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+      image.image = vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       image.coord = NULL;
       image.sample = NULL;
       break;
 
    case SpvOpImageRead:
-      image.image =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+      image.image = vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       image.coord = get_image_coord(b, w[4]);
 
       if (count > 5 && (w[5] & SpvImageOperandsSampleMask)) {
@@ -1903,8 +1899,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpImageWrite:
-      image.image =
-         vtn_value(b, w[1], vtn_value_type_access_chain)->access_chain;
+      image.image = vtn_value(b, w[1], vtn_value_type_pointer)->pointer;
       image.coord = get_image_coord(b, w[2]);
 
       /* texel = w[3] */
@@ -1949,7 +1944,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
 
    nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op);
 
-   nir_deref_var *image_deref = vtn_access_chain_to_deref(b, image.image);
+   nir_deref_var *image_deref = vtn_pointer_to_deref(b, image.image);
    intrin->variables[0] = nir_deref_var_clone(image_deref, intrin);
 
    /* ImageQuerySize doesn't take any extra parameters */
@@ -2074,7 +2069,7 @@ static void
 vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
                                  const uint32_t *w, unsigned count)
 {
-   struct vtn_access_chain *chain;
+   struct vtn_access_chain *ptr;
    nir_intrinsic_instr *atomic;
 
    switch (opcode) {
@@ -2093,13 +2088,11 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
    case SpvOpAtomicAnd:
    case SpvOpAtomicOr:
    case SpvOpAtomicXor:
-      chain =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+      ptr = vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       break;
 
    case SpvOpAtomicStore:
-      chain =
-         vtn_value(b, w[1], vtn_value_type_access_chain)->access_chain;
+      ptr = vtn_value(b, w[1], vtn_value_type_pointer)->pointer;
       break;
 
    default:
@@ -2111,8 +2104,8 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
    SpvMemorySemanticsMask semantics = w[5];
    */
 
-   if (chain->var->mode == vtn_variable_mode_workgroup) {
-      nir_deref_var *deref = vtn_access_chain_to_deref(b, chain);
+   if (ptr->var->mode == vtn_variable_mode_workgroup) {
+      nir_deref_var *deref = vtn_pointer_to_deref(b, ptr);
       const struct glsl_type *deref_type = nir_deref_tail(&deref->deref)->type;
       nir_intrinsic_op op = get_shared_nir_atomic_op(opcode);
       atomic = nir_intrinsic_instr_create(b->nb.shader, op);
@@ -2151,10 +2144,10 @@ vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
 
       }
    } else {
-      assert(chain->var->mode == vtn_variable_mode_ssbo);
+      assert(ptr->var->mode == vtn_variable_mode_ssbo);
       struct vtn_type *type;
       nir_ssa_def *offset, *index;
-      offset = vtn_access_chain_to_offset(b, chain, &index, &type, NULL, false);
+      offset = vtn_pointer_to_offset(b, ptr, &index, &type, NULL, false);
 
       nir_intrinsic_op op = get_ssbo_nir_atomic_op(opcode);
 
@@ -3071,7 +3064,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
 
    case SpvOpImageQuerySize: {
       struct vtn_access_chain *image =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+         vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       if (glsl_type_is_image(image->var->var->interface_type)) {
          vtn_handle_image(b, opcode, w, count);
       } else {
@@ -3099,7 +3092,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
       if (pointer->value_type == vtn_value_type_image_pointer) {
          vtn_handle_image(b, opcode, w, count);
       } else {
-         assert(pointer->value_type == vtn_value_type_access_chain);
+         assert(pointer->value_type == vtn_value_type_pointer);
          vtn_handle_ssbo_or_shared_atomic(b, opcode, w, count);
       }
       break;
@@ -3110,7 +3103,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
       if (pointer->value_type == vtn_value_type_image_pointer) {
          vtn_handle_image(b, opcode, w, count);
       } else {
-         assert(pointer->value_type == vtn_value_type_access_chain);
+         assert(pointer->value_type == vtn_value_type_pointer);
          vtn_handle_ssbo_or_shared_atomic(b, opcode, w, count);
       }
       break;
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 50ef767dea..123a8c6820 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -84,8 +84,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpFunctionParameter: {
-      struct vtn_value *val =
-         vtn_push_value(b, w[2], vtn_value_type_access_chain);
+      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
 
       struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
 
@@ -100,8 +99,8 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
       struct vtn_variable *vtn_var = rzalloc(b, struct vtn_variable);
       vtn_var->type = type;
       vtn_var->var = param;
-      vtn_var->chain.var = vtn_var;
-      vtn_var->chain.length = 0;
+      vtn_var->ptr.var = vtn_var;
+      vtn_var->ptr.length = 0;
 
       struct vtn_type *without_array = type;
       while(glsl_type_is_array(without_array->type))
@@ -117,7 +116,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
          vtn_var->mode = vtn_variable_mode_param;
       }
 
-      val->access_chain = &vtn_var->chain;
+      val->pointer = &vtn_var->ptr;
       break;
    }
 
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index a377c90144..a7f86ae104 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -44,7 +44,7 @@ enum vtn_value_type {
    vtn_value_type_decoration_group,
    vtn_value_type_type,
    vtn_value_type_constant,
-   vtn_value_type_access_chain,
+   vtn_value_type_pointer,
    vtn_value_type_function,
    vtn_value_type_block,
    vtn_value_type_ssa,
@@ -302,7 +302,7 @@ struct vtn_variable {
     */
    struct vtn_access_chain *copy_prop_sampler;
 
-   struct vtn_access_chain chain;
+   struct vtn_access_chain ptr;
 };
 
 struct vtn_image_pointer {
@@ -328,7 +328,7 @@ struct vtn_value {
          nir_constant *constant;
          const struct glsl_type *const_type;
       };
-      struct vtn_access_chain *access_chain;
+      struct vtn_access_chain *pointer;
       struct vtn_image_pointer *image;
       struct vtn_sampled_image *sampled_image;
       struct vtn_function *func;
@@ -459,13 +459,13 @@ nir_ssa_def *vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
 
 nir_deref_var *vtn_nir_deref(struct vtn_builder *b, uint32_t id);
 
-nir_deref_var *vtn_access_chain_to_deref(struct vtn_builder *b,
-                                         struct vtn_access_chain *chain);
+nir_deref_var *vtn_pointer_to_deref(struct vtn_builder *b,
+                                    struct vtn_access_chain *ptr);
 nir_ssa_def *
-vtn_access_chain_to_offset(struct vtn_builder *b,
-                           struct vtn_access_chain *chain,
-                           nir_ssa_def **index_out, struct vtn_type **type_out,
-                           unsigned *end_idx_out, bool stop_at_matrix);
+vtn_pointer_to_offset(struct vtn_builder *b,
+                      struct vtn_access_chain *ptr,
+                      nir_ssa_def **index_out, struct vtn_type **type_out,
+                      unsigned *end_idx_out, bool stop_at_matrix);
 
 struct vtn_ssa_value *vtn_local_load(struct vtn_builder *b, nir_deref_var *src);
 
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 754320afff..5e4e772b2f 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -94,11 +94,11 @@ rewrite_deref_types(nir_deref *deref, const struct glsl_type *type)
 }
 
 nir_deref_var *
-vtn_access_chain_to_deref(struct vtn_builder *b, struct vtn_access_chain *chain)
+vtn_pointer_to_deref(struct vtn_builder *b, struct vtn_access_chain *chain)
 {
    /* Do on-the-fly copy propagation for samplers. */
    if (chain->var->copy_prop_sampler)
-      return vtn_access_chain_to_deref(b, chain->var->copy_prop_sampler);
+      return vtn_pointer_to_deref(b, chain->var->copy_prop_sampler);
 
    nir_deref_var *deref_var;
    if (chain->var->var) {
@@ -237,9 +237,9 @@ nir_deref_var *
 vtn_nir_deref(struct vtn_builder *b, uint32_t id)
 {
    struct vtn_access_chain *chain =
-      vtn_value(b, id, vtn_value_type_access_chain)->access_chain;
+      vtn_value(b, id, vtn_value_type_pointer)->pointer;
 
-   return vtn_access_chain_to_deref(b, chain);
+   return vtn_pointer_to_deref(b, chain);
 }
 
 /*
@@ -338,10 +338,10 @@ get_vulkan_resource_index(struct vtn_builder *b, struct vtn_access_chain *chain,
 }
 
 nir_ssa_def *
-vtn_access_chain_to_offset(struct vtn_builder *b,
-                           struct vtn_access_chain *chain,
-                           nir_ssa_def **index_out, struct vtn_type **type_out,
-                           unsigned *end_idx_out, bool stop_at_matrix)
+vtn_pointer_to_offset(struct vtn_builder *b,
+                      struct vtn_access_chain *chain,
+                      nir_ssa_def **index_out, struct vtn_type **type_out,
+                      unsigned *end_idx_out, bool stop_at_matrix)
 {
    unsigned idx = 0;
    struct vtn_type *type;
@@ -712,7 +712,7 @@ vtn_block_load(struct vtn_builder *b, struct vtn_access_chain *src)
    nir_ssa_def *offset, *index = NULL;
    struct vtn_type *type;
    unsigned chain_idx;
-   offset = vtn_access_chain_to_offset(b, src, &index, &type, &chain_idx, true);
+   offset = vtn_pointer_to_offset(b, src, &index, &type, &chain_idx, true);
 
    struct vtn_ssa_value *value = NULL;
    _vtn_block_load_store(b, op, true, index, offset,
@@ -728,7 +728,7 @@ vtn_block_store(struct vtn_builder *b, struct vtn_ssa_value *src,
    nir_ssa_def *offset, *index = NULL;
    struct vtn_type *type;
    unsigned chain_idx;
-   offset = vtn_access_chain_to_offset(b, dst, &index, &type, &chain_idx, true);
+   offset = vtn_pointer_to_offset(b, dst, &index, &type, &chain_idx, true);
 
    _vtn_block_load_store(b, nir_intrinsic_store_ssbo, false, index, offset,
                          0, 0, dst, chain_idx, type, &src);
@@ -764,9 +764,9 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load,
        * are storred row-major in a UBO.
        */
       if (load) {
-         *inout = vtn_local_load(b, vtn_access_chain_to_deref(b, chain));
+         *inout = vtn_local_load(b, vtn_pointer_to_deref(b, chain));
       } else {
-         vtn_local_store(b, *inout, vtn_access_chain_to_deref(b, chain));
+         vtn_local_store(b, *inout, vtn_pointer_to_deref(b, chain));
       }
       return;
 
@@ -1215,9 +1215,9 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
       break;
    }
 
-   if (val->value_type == vtn_value_type_access_chain) {
-      assert(val->access_chain->length == 0);
-      assert(val->access_chain->var == void_var);
+   if (val->value_type == vtn_value_type_pointer) {
+      assert(val->pointer->length == 0);
+      assert(val->pointer->var == void_var);
       assert(member == -1);
    } else {
       assert(val->value_type == vtn_value_type_type);
@@ -1389,12 +1389,11 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
       struct vtn_variable *var = rzalloc(b, struct vtn_variable);
       var->type = vtn_value(b, w[1], vtn_value_type_type)->type;
 
-      var->chain.var = var;
-      var->chain.length = 0;
+      var->ptr.var = var;
+      var->ptr.length = 0;
 
-      struct vtn_value *val =
-         vtn_push_value(b, w[2], vtn_value_type_access_chain);
-      val->access_chain = &var->chain;
+      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
+      val->pointer = &var->ptr;
 
       struct vtn_type *without_array = var->type;
       while(glsl_type_is_array(without_array->type))
@@ -1595,8 +1594,8 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
           */
          base = base_val->sampled_image->image;
       } else {
-         assert(base_val->value_type == vtn_value_type_access_chain);
-         base = base_val->access_chain;
+         assert(base_val->value_type == vtn_value_type_pointer);
+         base = base_val->pointer;
       }
 
       chain = vtn_access_chain_extend(b, base, count - 4);
@@ -1622,27 +1621,27 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
          val->sampled_image->sampler = base_val->sampled_image->sampler;
       } else {
          struct vtn_value *val =
-            vtn_push_value(b, w[2], vtn_value_type_access_chain);
-         val->access_chain = chain;
+            vtn_push_value(b, w[2], vtn_value_type_pointer);
+         val->pointer = chain;
       }
       break;
    }
 
    case SpvOpCopyMemory: {
-      struct vtn_value *dest = vtn_value(b, w[1], vtn_value_type_access_chain);
-      struct vtn_value *src = vtn_value(b, w[2], vtn_value_type_access_chain);
+      struct vtn_value *dest = vtn_value(b, w[1], vtn_value_type_pointer);
+      struct vtn_value *src = vtn_value(b, w[2], vtn_value_type_pointer);
 
-      vtn_variable_copy(b, dest->access_chain, src->access_chain);
+      vtn_variable_copy(b, dest->pointer, src->pointer);
       break;
    }
 
    case SpvOpLoad: {
       struct vtn_access_chain *src =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+         vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
 
       if (src->var->mode == vtn_variable_mode_image ||
           src->var->mode == vtn_variable_mode_sampler) {
-         vtn_push_value(b, w[2], vtn_value_type_access_chain)->access_chain = src;
+         vtn_push_value(b, w[2], vtn_value_type_pointer)->pointer = src;
          return;
       }
 
@@ -1653,14 +1652,14 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
 
    case SpvOpStore: {
       struct vtn_access_chain *dest =
-         vtn_value(b, w[1], vtn_value_type_access_chain)->access_chain;
+         vtn_value(b, w[1], vtn_value_type_pointer)->pointer;
 
       if (glsl_type_is_sampler(dest->var->type->type)) {
          vtn_warn("OpStore of a sampler detected.  Doing on-the-fly copy "
                   "propagation to workaround the problem.");
          assert(dest->var->copy_prop_sampler == NULL);
          dest->var->copy_prop_sampler =
-            vtn_value(b, w[2], vtn_value_type_access_chain)->access_chain;
+            vtn_value(b, w[2], vtn_value_type_pointer)->pointer;
          break;
       }
 
@@ -1671,7 +1670,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
 
    case SpvOpArrayLength: {
       struct vtn_access_chain *chain =
-         vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+         vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
 
       const uint32_t offset = chain->var->type->offsets[w[4]];
       const uint32_t stride = chain->var->type->members[w[4]]->stride;




More information about the mesa-commit mailing list