zink: support offset-variants of texturing
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 2 Jan 2020 10:26:38 +0000 (11:26 +0100)
committerMarge Bot <eric+marge@anholt.net>
Sat, 18 Jan 2020 10:45:38 +0000 (10:45 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3275>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h

index 35c2fc4..5ed0d0b 100644 (file)
@@ -1372,7 +1372,8 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
           nir_alu_type_get_base_type(tex->dest_type) == nir_type_float);
    assert(tex->texture_index == tex->sampler_index);
 
-   SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0, dx = 0, dy = 0;
+   SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0, dx = 0, dy = 0,
+         offset = 0;
    unsigned coord_components = 0;
    for (unsigned i = 0; i < tex->num_srcs; i++) {
       switch (tex->src[i].src_type) {
@@ -1390,6 +1391,10 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
          assert(proj != 0);
          break;
 
+      case nir_tex_src_offset:
+         offset = get_src_int(ctx, &tex->src[i].src);
+         break;
+
       case nir_tex_src_bias:
          assert(tex->op == nir_texop_txb);
          bias = get_src_float(ctx, &tex->src[i].src);
@@ -1494,7 +1499,8 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
                                                actual_dest_type, load,
                                                coord,
                                                proj != 0,
-                                               lod, bias, dref, dx, dy);
+                                               lod, bias, dref, dx, dy,
+                                               offset);
    }
 
    spirv_builder_emit_decoration(&ctx->builder, result,
index bae23c9..bdb8b8a 100644 (file)
@@ -515,7 +515,8 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
                                 SpvId bias,
                                 SpvId dref,
                                 SpvId dx,
-                                SpvId dy)
+                                SpvId dy,
+                                SpvId offset)
 {
    SpvId result = spirv_builder_new_id(b);
 
@@ -531,7 +532,7 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
    }
 
    SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
-   SpvId extra_operands[4];
+   SpvId extra_operands[5];
    int num_extra_operands = 0;
    if (bias) {
       extra_operands[++num_extra_operands] = bias;
@@ -545,6 +546,10 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
       extra_operands[++num_extra_operands] = dy;
       operand_mask |= SpvImageOperandsGradMask;
    }
+   if (offset) {
+      extra_operands[++num_extra_operands] = offset;
+      operand_mask |= SpvImageOperandsOffsetMask;
+   }
 
    /* finalize num_extra_operands / extra_operands */
    if (num_extra_operands > 0) {
index 56db0a1..bd19e74 100644 (file)
@@ -215,7 +215,8 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
                                 SpvId bias,
                                 SpvId dref,
                                 SpvId dx,
-                                SpvId dy);
+                                SpvId dy,
+                                SpvId offset);
 
 SpvId
 spirv_builder_emit_image(struct spirv_builder *b, SpvId result_type,