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

Author: Gert Wollny <[email protected]>
Date:   Wed Jan 13 10:28:59 2021 +0100

nir: Add flag to tex instruction to indicate lowering cube to array

E.g. r600 a cube texture lookup uses a specific cube instruction
to evaluate the sample coordinates and the face ID, so that the cube
texture lookup can be lowered to a array texture lookup, thereby sharing
the code with the 2D array texture lopkup.
However, for TXD the given gradients still need to be three-component
vectors, so add a flag that the NIR validation knows that we deal with
cube texture that was lowered to an array and can validate accordingly.

v2: Handle new flag in serialization (Marek)
v3: Rebase so that the change does not require the patch to deduct the
    number of offset and grad components from sampler type

Signed-off-by: Gert Wollny <[email protected]>
Reviewed-by: Marek Olšák <[email protected]> (v2)
Acked-by: Eric Anholt <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9200>

---

 src/compiler/nir/nir.h           | 6 +++++-
 src/compiler/nir/nir_clone.c     | 1 +
 src/compiler/nir/nir_serialize.c | 5 ++++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index fd35676bf3b..5a88bef0a81 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2049,6 +2049,9 @@ typedef struct {
    /* gather component selector */
    unsigned component : 2;
 
+   /* Validation needs to know this for gradient component count */
+   unsigned array_is_lowered_cube : 1;
+
    /* gather offsets */
    int8_t tg4_offsets[4][2];
 
@@ -2268,7 +2271,8 @@ nir_tex_instr_src_size(const nir_tex_instr *instr, 
unsigned src)
 
    if (instr->src[src].src_type == nir_tex_src_ddx ||
        instr->src[src].src_type == nir_tex_src_ddy) {
-      if (instr->is_array)
+
+      if (instr->is_array && !instr->array_is_lowered_cube)
          return instr->coord_components - 1;
       else
          return instr->coord_components;
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index ab3ca607969..b5cffe7eb7e 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -411,6 +411,7 @@ clone_tex(clone_state *state, const nir_tex_instr *tex)
    }
    ntex->coord_components = tex->coord_components;
    ntex->is_array = tex->is_array;
+   ntex->array_is_lowered_cube = tex->array_is_lowered_cube;
    ntex->is_shadow = tex->is_shadow;
    ntex->is_new_style_shadow = tex->is_new_style_shadow;
    ntex->is_sparse = tex->is_sparse;
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 35f3ba222f8..08bb8e89442 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -1460,7 +1460,8 @@ union packed_tex_data {
       unsigned component:2;
       unsigned texture_non_uniform:1;
       unsigned sampler_non_uniform:1;
-      unsigned unused:7; /* Mark unused for valgrind. */
+      unsigned array_is_lowered_cube:1;
+      unsigned unused:6; /* Mark unused for valgrind. */
    } u;
 };
 
@@ -1496,6 +1497,7 @@ write_tex(write_ctx *ctx, const nir_tex_instr *tex)
       .u.component = tex->component,
       .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,
    };
    blob_write_uint32(ctx->blob, packed.u32);
 
@@ -1532,6 +1534,7 @@ read_tex(read_ctx *ctx, union packed_instr header)
    tex->component = packed.u.component;
    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;
 
    for (unsigned i = 0; i < tex->num_srcs; i++) {
       union packed_src src = read_src(ctx, &tex->src[i].src, &tex->instr);

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to