nir: add is_gather_implicit_lod
authorRhys Perry <pendingchaos02@gmail.com>
Thu, 13 Apr 2023 13:13:35 +0000 (14:13 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 18 Apr 2023 10:42:07 +0000 (10:42 +0000)
Needed for SPV_AMD_texture_gather_bias_lod.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22315>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_tex.c
src/compiler/nir/nir_print.c
src/compiler/nir/nir_serialize.c
src/compiler/nir/nir_validate.c

index 4c3fa21..b2a3b4e 100644 (file)
@@ -2321,6 +2321,9 @@ typedef struct {
    /** Validation needs to know this for gradient component count */
    unsigned array_is_lowered_cube : 1;
 
+   /** True if this tg4 instruction has an implicit LOD or LOD bias, instead of using level 0 */
+   unsigned is_gather_implicit_lod : 1;
+
    /** Gather offsets */
    int8_t tg4_offsets[4][2];
 
index 64ab92c..639d8a2 100644 (file)
@@ -1160,6 +1160,7 @@ lower_tg4_offsets(nir_builder *b, nir_tex_instr *tex)
       tex_copy->is_shadow = tex->is_shadow;
       tex_copy->is_new_style_shadow = tex->is_new_style_shadow;
       tex_copy->is_sparse = tex->is_sparse;
+      tex_copy->is_gather_implicit_lod = tex->is_gather_implicit_lod;
       tex_copy->component = tex->component;
       tex_copy->dest_type = tex->dest_type;
 
index 6073e41..05ad3f3 100644 (file)
@@ -1401,6 +1401,9 @@ print_tex_instr(nir_tex_instr *instr, print_state *state)
       }
    }
 
+   if (instr->is_gather_implicit_lod)
+      fprintf(fp, ", implicit lod");
+
    if (instr->op == nir_texop_tg4) {
       fprintf(fp, ", %u (gather_component)", instr->component);
    }
index e105b2d..b94665a 100644 (file)
@@ -1502,7 +1502,8 @@ union packed_tex_data {
       unsigned texture_non_uniform:1;
       unsigned sampler_non_uniform:1;
       unsigned array_is_lowered_cube:1;
-      unsigned unused:6; /* Mark unused for valgrind. */
+      unsigned is_gather_implicit_lod:1;
+      unsigned unused:5; /* Mark unused for valgrind. */
    } u;
 };
 
@@ -1539,6 +1540,7 @@ write_tex(write_ctx *ctx, const nir_tex_instr *tex)
       .u.texture_non_uniform = tex->texture_non_uniform,
       .u.sampler_non_uniform = tex->sampler_non_uniform,
       .u.array_is_lowered_cube = tex->array_is_lowered_cube,
+      .u.is_gather_implicit_lod = tex->is_gather_implicit_lod,
    };
    blob_write_uint32(ctx->blob, packed.u32);
 
@@ -1576,6 +1578,7 @@ read_tex(read_ctx *ctx, union packed_instr header)
    tex->texture_non_uniform = packed.u.texture_non_uniform;
    tex->sampler_non_uniform = packed.u.sampler_non_uniform;
    tex->array_is_lowered_cube = packed.u.array_is_lowered_cube;
+   tex->is_gather_implicit_lod = packed.u.is_gather_implicit_lod;
 
    for (unsigned i = 0; i < tex->num_srcs; i++) {
       union packed_src src = read_src(ctx, &tex->src[i].src);
index d343021..1ce0eab 100644 (file)
@@ -981,6 +981,9 @@ validate_tex_instr(nir_tex_instr *instr, validate_state *state)
       validate_assert(state, !src_type_seen[nir_tex_src_offset]);
    }
 
+   if (instr->is_gather_implicit_lod)
+      validate_assert(state, instr->op == nir_texop_tg4);
+
    validate_dest(&instr->dest, state, 0, nir_tex_instr_dest_size(instr));
 
    unsigned bit_size = nir_alu_type_get_type_size(instr->dest_type);