Mesa (master): zink: handle textureGather with Shadow-type samplers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 4 16:00:01 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri Jul 24 09:48:36 2020 -0400

zink: handle textureGather with Shadow-type samplers

these have to go through OpImageDrefGather without composite construction
on the result

Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8151>

---

 src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c  |  4 ++--
 src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c | 13 ++++++++++---
 src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h |  3 ++-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
index 3cd68252cbf..19121289c29 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
@@ -2276,7 +2276,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
       if (tex->op == nir_texop_tg4)
          result = spirv_builder_emit_image_gather(&ctx->builder, dest_type,
                                                  load, coord, emit_uint_const(ctx, 32, tex->component),
-                                                 lod, sample, offset);
+                                                 lod, sample, offset, dref);
       else
          result = spirv_builder_emit_image_fetch(&ctx->builder, dest_type,
                                                  image, coord, lod, sample, offset);
@@ -2292,7 +2292,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
    spirv_builder_emit_decoration(&ctx->builder, result,
                                  SpvDecorationRelaxedPrecision);
 
-   if (dref && nir_dest_num_components(tex->dest) > 1) {
+   if (dref && nir_dest_num_components(tex->dest) > 1 && tex->op != nir_texop_tg4) {
       SpvId components[4] = { result, result, result, result };
       result = spirv_builder_emit_composite_construct(&ctx->builder,
                                                       dest_type,
diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
index 5d09b0d7dc0..5aee0b6b44a 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
@@ -718,9 +718,11 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
                                SpvId component,
                                SpvId lod,
                                SpvId sample,
-                               SpvId offset)
+                               SpvId offset,
+                               SpvId dref)
 {
    SpvId result = spirv_builder_new_id(b);
+   SpvId op = SpvOpImageGather;
 
    SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
    SpvId extra_operands[4];
@@ -737,6 +739,8 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
       extra_operands[++num_extra_operands] = offset;
       operand_mask |= SpvImageOperandsOffsetMask;
    }
+   if (dref)
+      op = SpvOpImageDrefGather;
    /* finalize num_extra_operands / extra_operands */
    if (num_extra_operands > 0) {
       extra_operands[0] = operand_mask;
@@ -744,13 +748,16 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
    }
 
    spirv_buffer_prepare(&b->instructions, b->mem_ctx, 6 + num_extra_operands);
-   spirv_buffer_emit_word(&b->instructions, SpvOpImageGather |
+   spirv_buffer_emit_word(&b->instructions, op |
                           ((6 + num_extra_operands) << 16));
    spirv_buffer_emit_word(&b->instructions, result_type);
    spirv_buffer_emit_word(&b->instructions, result);
    spirv_buffer_emit_word(&b->instructions, image);
    spirv_buffer_emit_word(&b->instructions, coordinate);
-   spirv_buffer_emit_word(&b->instructions, component);
+   if (dref)
+      spirv_buffer_emit_word(&b->instructions, dref);
+   else
+      spirv_buffer_emit_word(&b->instructions, component);
    for (int i = 0; i < num_extra_operands; ++i)
       spirv_buffer_emit_word(&b->instructions, extra_operands[i]);
    return result;
diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
index 622adb61463..d819a6d29db 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
@@ -273,7 +273,8 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
                                SpvId component,
                                SpvId lod,
                                SpvId sample,
-                               SpvId offset);
+                               SpvId offset,
+                               SpvId dref);
 
 SpvId
 spirv_builder_emit_image_query_size(struct spirv_builder *b,



More information about the mesa-commit mailing list