summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2018-11-01 22:12:11 +0100
committerErik Faye-Lund <[email protected]>2019-10-28 08:51:43 +0000
commitacdd12dae3479b88d49e4a449e2c82c6fe45ef57 (patch)
tree203d93eb15e943440b1d4cecfd58eab3f7e976b4 /src/gallium/drivers
parent11ad9bfc35cd0c300fcf7be6133a04beba409895 (diff)
zink/spirv: implement discard
Acked-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c14
-rw-r--r--src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c7
-rw-r--r--src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h2
3 files changed, 23 insertions, 0 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 9fc7aa94cd2..c4c8da2efa1 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
@@ -1022,6 +1022,16 @@ emit_store_output(struct ntv_context *ctx, nir_intrinsic_instr *intr)
}
static void
+emit_discard(struct ntv_context *ctx, nir_intrinsic_instr *intr)
+{
+ assert(ctx->block_started);
+ spirv_builder_emit_kill(&ctx->builder);
+ /* discard is weird in NIR, so let's just create an unreachable block after
+ it and hope that the vulkan driver will DCE any instructinos in it. */
+ spirv_builder_label(&ctx->builder, spirv_builder_new_id(&ctx->builder));
+}
+
+static void
emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr)
{
switch (intr->intrinsic) {
@@ -1037,6 +1047,10 @@ emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr)
emit_store_output(ctx, intr);
break;
+ case nir_intrinsic_discard:
+ emit_discard(ctx, intr);
+ break;
+
default:
fprintf(stderr, "emit_intrinsic: not implemented (%s)\n",
nir_intrinsic_infos[intr->intrinsic].name);
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 1a02ab0fe09..8fce21bbc35 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c
@@ -487,6 +487,13 @@ spirv_builder_set_phi_operand(struct spirv_builder *b, size_t position,
b->instructions.words[position + index * 2 + 1] = parent;
}
+void
+spirv_builder_emit_kill(struct spirv_builder *b)
+{
+ spirv_buffer_prepare(&b->instructions, 1);
+ spirv_buffer_emit_word(&b->instructions, SpvOpKill | (1 << 16));
+}
+
SpvId
spirv_builder_emit_image_sample_implicit_lod(struct spirv_builder *b,
SpvId result_type,
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 2fecaf445f2..3cf3d5d3565 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
+++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
@@ -194,6 +194,8 @@ void
spirv_builder_set_phi_operand(struct spirv_builder *b, size_t position,
size_t index, SpvId variable, SpvId parent);
+void
+spirv_builder_emit_kill(struct spirv_builder *b);
SpvId
spirv_builder_emit_image_sample_implicit_lod(struct spirv_builder *b,