zink: support shadow-samplers
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Tue, 16 Jul 2019 15:52:36 +0000 (17:52 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 28 Oct 2019 08:51:47 +0000 (08:51 +0000)
Acked-by: Jordan Justen <jordan.l.justen@intel.com>
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 4168513e6815f509a1297400aff68a19451dee03..11eb56e9d7bed8eeba1869cb3acb5eb20514da8d 100644 (file)
@@ -1111,7 +1111,7 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
    assert(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;
+   SpvId coord = 0, proj = 0, bias = 0, lod = 0, dref = 0;
    unsigned coord_components;
    for (unsigned i = 0; i < tex->num_srcs; i++) {
       switch (tex->src[i].src_type) {
@@ -1138,6 +1138,12 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
          assert(lod != 0);
          break;
 
+      case nir_tex_src_comparator:
+         assert(nir_src_num_components(tex->src[i].src) == 1);
+         dref = get_src_float(ctx, &tex->src[i].src);
+         assert(dref != 0);
+         break;
+
       default:
          fprintf(stderr, "texture source: %d\n", tex->src[i].src_type);
          unreachable("unknown texture source");
@@ -1187,14 +1193,26 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
                                                             coord_components);
    }
 
+   SpvId actual_dest_type = dest_type;
+   if (dref)
+      actual_dest_type = float_type;
+
    SpvId result = spirv_builder_emit_image_sample(&ctx->builder,
-                                                  dest_type, load,
+                                                  actual_dest_type, load,
                                                   coord,
                                                   proj != 0,
-                                                  lod, bias);
+                                                  lod, bias, dref);
    spirv_builder_emit_decoration(&ctx->builder, result,
                                  SpvDecorationRelaxedPrecision);
 
+   if (dref) {
+      SpvId components[4] = { result, result, result, result };
+      result = spirv_builder_emit_composite_construct(&ctx->builder,
+                                                      dest_type,
+                                                      components,
+                                                      4);
+   }
+
    store_dest(ctx, &tex->dest, result, tex->dest_type);
 }
 
index 1b3718307f9563c4ea3c33081630277f1681585c..99b9e5833bc5bb0cccba275397237ea05ef0f852 100644 (file)
@@ -512,15 +512,21 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
                                 SpvId coordinate,
                                 bool proj,
                                 SpvId lod,
-                                SpvId bias)
+                                SpvId bias,
+                                SpvId dref)
 {
    SpvId result = spirv_builder_new_id(b);
 
    int opcode = SpvOpImageSampleImplicitLod;
+   int operands = 5;
    if (proj)
       opcode += SpvOpImageSampleProjImplicitLod - SpvOpImageSampleImplicitLod;
    if (lod)
       opcode += SpvOpImageSampleExplicitLod - SpvOpImageSampleImplicitLod;
+   if (dref) {
+      opcode += SpvOpImageSampleDrefImplicitLod - SpvOpImageSampleImplicitLod;
+      operands++;
+   }
 
    SpvImageOperandsMask operand_mask = 0;
    SpvId extra_operands[3];
@@ -540,12 +546,14 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
       num_extra_operands++;
    }
 
-   spirv_buffer_prepare(&b->instructions, 5 + num_extra_operands);
-   spirv_buffer_emit_word(&b->instructions, opcode | ((5 + num_extra_operands) << 16));
+   spirv_buffer_prepare(&b->instructions, operands + num_extra_operands);
+   spirv_buffer_emit_word(&b->instructions, opcode | ((operands + 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, sampled_image);
    spirv_buffer_emit_word(&b->instructions, coordinate);
+   if (dref)
+      spirv_buffer_emit_word(&b->instructions, dref);
    for (int i = 0; i < num_extra_operands; ++i)
       spirv_buffer_emit_word(&b->instructions, extra_operands[i]);
    return result;
index 0bb16b16dd3400aaef4fec38756beb74af50b5dd..612e6ec03736de7c2e08376b83aa70314af68d3b 100644 (file)
@@ -212,7 +212,8 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
                                 SpvId coordinate,
                                 bool proj,
                                 SpvId lod,
-                                SpvId bias);
+                                SpvId bias,
+                                SpvId dref);
 
 SpvId
 spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,