aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/zink/nir_to_spirv
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2019-07-16 17:52:36 +0200
committerErik Faye-Lund <[email protected]>2019-10-28 08:51:47 +0000
commitb525348729aa26fb048a8556be3f250157abac43 (patch)
treeecb6786c11c62983bb691281e7d6293eda8dfd81 /src/gallium/drivers/zink/nir_to_spirv
parentd9c068cba186a6cc3dca9d05f54842676ef303ed (diff)
zink: support shadow-samplers
Acked-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/gallium/drivers/zink/nir_to_spirv')
-rw-r--r--src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c24
-rw-r--r--src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c14
-rw-r--r--src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h3
3 files changed, 34 insertions, 7 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 4168513e681..11eb56e9d7b 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
@@ -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);
}
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 1b3718307f9..99b9e5833bc 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
@@ -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;
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 0bb16b16dd3..612e6ec0373 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
@@ -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,