zink: move shared intrinsic offset adjustments to compiler passes
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 20 Oct 2021 14:19:26 +0000 (10:19 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 27 Oct 2021 17:13:26 +0000 (17:13 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13484>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
src/gallium/drivers/zink/zink_compiler.c

index 6a615bd..3b6eb9f 100644 (file)
@@ -2179,7 +2179,7 @@ emit_load_shared(struct ntv_context *ctx, nir_intrinsic_instr *intr)
    SpvId ptr_type = spirv_builder_type_pointer(&ctx->builder,
                                                SpvStorageClassWorkgroup,
                                                uint_type);
-   SpvId offset = emit_binop(ctx, SpvOpUDiv, uint_type, get_src(ctx, &intr->src[0]), emit_uint_const(ctx, 32, 4));
+   SpvId offset = get_src(ctx, &intr->src[0]);
    SpvId constituents[NIR_MAX_VEC_COMPONENTS];
    /* need to convert array -> vec */
    for (unsigned i = 0; i < num_components; i++) {
@@ -2209,7 +2209,7 @@ emit_store_shared(struct ntv_context *ctx, nir_intrinsic_instr *intr)
    SpvId ptr_type = spirv_builder_type_pointer(&ctx->builder,
                                                SpvStorageClassWorkgroup,
                                                uint_type);
-   SpvId offset = emit_binop(ctx, SpvOpUDiv, uint_type, get_src(ctx, &intr->src[1]), emit_uint_const(ctx, 32, 4));
+   SpvId offset = get_src(ctx, &intr->src[1]);
 
    for (unsigned i = 0; num_writes; i++) {
       if ((wrmask >> i) & 1) {
index 6f5d4f8..1847e34 100644 (file)
@@ -675,6 +675,8 @@ rewrite_bo_access_instr(nir_builder *b, nir_instr *instr, void *data)
       return true;
    }
    case nir_intrinsic_load_shared:
+      b->cursor = nir_before_instr(instr);
+      nir_instr_rewrite_src_ssa(instr, &intr->src[0], nir_udiv_imm(b, intr->src[0].ssa, nir_dest_bit_size(intr->dest) / 8));
       /* if 64bit isn't supported, 64bit loads definitely aren't supported, so rewrite as 2x32 with cast and pray */
       if (nir_dest_bit_size(intr->dest) == 64 && !has_int64) {
          /* this is always scalarized */
@@ -692,6 +694,10 @@ rewrite_bo_access_instr(nir_builder *b, nir_instr *instr, void *data)
       b->cursor = nir_before_instr(instr);
       nir_instr_rewrite_src_ssa(instr, &intr->src[2], nir_udiv_imm(b, intr->src[2].ssa, MIN2(nir_src_bit_size(intr->src[0]), 32) / 8));
       return true;
+   case nir_intrinsic_store_shared:
+      b->cursor = nir_before_instr(instr);
+      nir_instr_rewrite_src_ssa(instr, &intr->src[1], nir_udiv_imm(b, intr->src[1].ssa, MIN2(nir_src_bit_size(intr->src[0]), 32) / 8));
+      return true;
    default:
       break;
    }