summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2017-02-22 16:53:18 -0800
committerEric Anholt <[email protected]>2017-10-10 11:42:04 -0700
commitc34295b1a3e2bd6ddf8a79bbe391aae1e98cd976 (patch)
tree1f66b4d477702e7c913c18352833138c2e73cb61 /src/gallium/drivers
parente37b32f80c8ed95a3c3f49ba20d6155820c8bba8 (diff)
nir: Move vc4's alpha test lowering to core NIR.
I've been doing this inside of vc4, but vc5 wants it as well and it may be useful for other drivers (Intel has a related path for pre-gen6 with MRT, and freedreno had a TGSI path for it at one point). This required defining a common enum for the standard comparison functions, but other lowering passes are likely to also want that enum. v2: Add to meson.build as well. Acked-by: Rob Clark <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/vc4/vc4_nir_lower_blend.c50
-rw-r--r--src/gallium/drivers/vc4/vc4_program.c15
-rw-r--r--src/gallium/drivers/vc4/vc4_qir.h1
3 files changed, 11 insertions, 55 deletions
diff --git a/src/gallium/drivers/vc4/vc4_nir_lower_blend.c b/src/gallium/drivers/vc4/vc4_nir_lower_blend.c
index a28ebb5bb7c..60eccb4fc00 100644
--- a/src/gallium/drivers/vc4/vc4_nir_lower_blend.c
+++ b/src/gallium/drivers/vc4/vc4_nir_lower_blend.c
@@ -450,54 +450,6 @@ vc4_logicop(nir_builder *b, int logicop_func,
}
static nir_ssa_def *
-vc4_nir_pipe_compare_func(nir_builder *b, int func,
- nir_ssa_def *src0, nir_ssa_def *src1)
-{
- switch (func) {
- default:
- fprintf(stderr, "Unknown compare func %d\n", func);
- /* FALLTHROUGH */
- case PIPE_FUNC_NEVER:
- return nir_imm_int(b, 0);
- case PIPE_FUNC_ALWAYS:
- return nir_imm_int(b, ~0);
- case PIPE_FUNC_EQUAL:
- return nir_feq(b, src0, src1);
- case PIPE_FUNC_NOTEQUAL:
- return nir_fne(b, src0, src1);
- case PIPE_FUNC_GREATER:
- return nir_flt(b, src1, src0);
- case PIPE_FUNC_GEQUAL:
- return nir_fge(b, src0, src1);
- case PIPE_FUNC_LESS:
- return nir_flt(b, src0, src1);
- case PIPE_FUNC_LEQUAL:
- return nir_fge(b, src1, src0);
- }
-}
-
-static void
-vc4_nir_emit_alpha_test_discard(struct vc4_compile *c, nir_builder *b,
- nir_ssa_def *alpha)
-{
- if (!c->fs_key->alpha_test)
- return;
-
- nir_ssa_def *condition =
- vc4_nir_pipe_compare_func(b, c->fs_key->alpha_test_func,
- alpha,
- nir_load_alpha_ref_float(b));
-
- nir_intrinsic_instr *discard =
- nir_intrinsic_instr_create(b->shader,
- nir_intrinsic_discard_if);
- discard->num_components = 1;
- discard->src[0] = nir_src_for_ssa(nir_inot(b, condition));
- nir_builder_instr_insert(b, &discard->instr);
- c->s->info.fs.uses_discard = true;
-}
-
-static nir_ssa_def *
vc4_nir_swizzle_and_pack(struct vc4_compile *c, nir_builder *b,
nir_ssa_def **colors)
{
@@ -537,8 +489,6 @@ vc4_nir_blend_pipeline(struct vc4_compile *c, nir_builder *b, nir_ssa_def *src,
if (c->fs_key->sample_alpha_to_one && c->fs_key->msaa)
src_color[3] = nir_imm_float(b, 1.0);
- vc4_nir_emit_alpha_test_discard(c, b, src_color[3]);
-
nir_ssa_def *packed_color;
if (srgb) {
/* Unswizzle the destination color. */
diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index e93333d35e7..bf7424bf28a 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -2250,8 +2250,15 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage,
c->s = nir_shader_clone(c, key->shader_state->base.ir.nir);
- if (stage == QSTAGE_FRAG)
+ if (stage == QSTAGE_FRAG) {
+ if (c->fs_key->alpha_test_func != COMPARE_FUNC_ALWAYS) {
+ NIR_PASS_V(c->s, nir_lower_alpha_test,
+ c->fs_key->alpha_test_func,
+ c->fs_key->sample_alpha_to_one &&
+ c->fs_key->msaa);
+ }
NIR_PASS_V(c->s, vc4_nir_lower_blend, c);
+ }
struct nir_lower_tex_options tex_options = {
/* We would need to implement txs, but we don't want the
@@ -2748,10 +2755,10 @@ vc4_update_compiled_fs(struct vc4_context *vc4, uint8_t prim_mode)
key->stencil_full_writemasks = vc4->zsa->stencil_uniforms[2] != 0;
key->depth_enabled = (vc4->zsa->base.depth.enabled ||
key->stencil_enabled);
- if (vc4->zsa->base.alpha.enabled) {
- key->alpha_test = true;
+ if (vc4->zsa->base.alpha.enabled)
key->alpha_test_func = vc4->zsa->base.alpha.func;
- }
+ else
+ key->alpha_test_func = COMPARE_FUNC_ALWAYS;
if (key->is_points) {
key->point_sprite_mask =
diff --git a/src/gallium/drivers/vc4/vc4_qir.h b/src/gallium/drivers/vc4/vc4_qir.h
index 6469e51b051..90acaef2898 100644
--- a/src/gallium/drivers/vc4/vc4_qir.h
+++ b/src/gallium/drivers/vc4/vc4_qir.h
@@ -354,7 +354,6 @@ struct vc4_fs_key {
bool stencil_full_writemasks;
bool is_points;
bool is_lines;
- bool alpha_test;
bool point_coord_upper_left;
bool light_twoside;
bool msaa;