nir: Add alignment information to cast derefs
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 24 Aug 2020 14:51:04 +0000 (09:51 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 3 Sep 2020 18:02:50 +0000 (18:02 +0000)
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6472>

src/compiler/nir/nir.h
src/compiler/nir/nir_clone.c
src/compiler/nir/nir_instr_set.c
src/compiler/nir/nir_serialize.c
src/compiler/nir/nir_validate.c

index f6f667bcdcb74cb7d6068670b8835dc35901f13b..16733fd5e5067a9264f5dcf292fb2f340c5efed1 100644 (file)
@@ -1462,6 +1462,8 @@ typedef struct {
 
       struct {
          unsigned ptr_stride;
+         unsigned align_mul;
+         unsigned align_offset;
       } cast;
    };
 
index 05689b097a86b3223ef5e9e3ff018e797280370c..d090a7cf160475b24b3dbfc309b81ae0ef427537 100644 (file)
@@ -339,6 +339,8 @@ clone_deref_instr(clone_state *state, const nir_deref_instr *deref)
 
    case nir_deref_type_cast:
       nderef->cast.ptr_stride = deref->cast.ptr_stride;
+      nderef->cast.align_mul = deref->cast.align_mul;
+      nderef->cast.align_offset = deref->cast.align_offset;
       break;
 
    default:
index 5e280a1e3e0cef01366086dfcb438835ca207f67..63f01872d728a9695d11f9f932b728606d2b90f8 100644 (file)
@@ -172,6 +172,8 @@ hash_deref(uint32_t hash, const nir_deref_instr *instr)
 
    case nir_deref_type_cast:
       hash = HASH(hash, instr->cast.ptr_stride);
+      hash = HASH(hash, instr->cast.align_mul);
+      hash = HASH(hash, instr->cast.align_offset);
       break;
 
    case nir_deref_type_var:
@@ -619,7 +621,9 @@ nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2)
          break;
 
       case nir_deref_type_cast:
-         if (deref1->cast.ptr_stride != deref2->cast.ptr_stride)
+         if (deref1->cast.ptr_stride != deref2->cast.ptr_stride ||
+             deref1->cast.align_mul != deref2->cast.align_mul ||
+             deref1->cast.align_offset != deref2->cast.align_offset)
             return false;
          break;
 
index 2a0e51807873e5cb96bfa6ecff578d10fec4a805..64319886cd9c9fd502eb007cdbe696871a99f20f 100644 (file)
@@ -1037,6 +1037,8 @@ write_deref(write_ctx *ctx, const nir_deref_instr *deref)
    case nir_deref_type_cast:
       write_src(ctx, &deref->parent);
       blob_write_uint32(ctx->blob, deref->cast.ptr_stride);
+      blob_write_uint32(ctx->blob, deref->cast.align_mul);
+      blob_write_uint32(ctx->blob, deref->cast.align_offset);
       if (!header.deref.cast_type_same_as_last) {
          encode_type_to_blob(ctx->blob, deref->type);
          ctx->last_type = deref->type;
@@ -1101,6 +1103,8 @@ read_deref(read_ctx *ctx, union packed_instr header)
    case nir_deref_type_cast:
       read_src(ctx, &deref->parent, &deref->instr);
       deref->cast.ptr_stride = blob_read_uint32(ctx->blob);
+      deref->cast.align_mul = blob_read_uint32(ctx->blob);
+      deref->cast.align_offset = blob_read_uint32(ctx->blob);
       if (header.deref.cast_type_same_as_last) {
          deref->type = ctx->last_type;
       } else {
index 11e9841e1784222d30d918245fc88b60290cce76..b7622cd06a98e7a0f2d3f7a9f1bce75090d5e067 100644 (file)
@@ -418,6 +418,12 @@ validate_deref_instr(nir_deref_instr *instr, validate_state *state)
       /* We just validate that the type and mode are there */
       validate_assert(state, instr->mode);
       validate_assert(state, instr->type);
+      if (instr->cast.align_mul > 0) {
+         validate_assert(state, util_is_power_of_two_nonzero(instr->cast.align_mul));
+         validate_assert(state, instr->cast.align_offset < instr->cast.align_mul);
+      } else {
+         validate_assert(state, instr->cast.align_offset == 0);
+      }
    } else {
       /* We require the parent to be SSA.  This may be lifted in the future */
       validate_assert(state, instr->parent.is_ssa);