Commit 3cd449c1 authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

First try at alpha test lowering

parent 56787591
......@@ -414,6 +414,9 @@ typedef struct compiler_context {
/* Count of instructions emitted from NIR overall, across all blocks */
int instruction_count;
/* Alpha ref value passed in */
float alpha_ref;
} compiler_context;
/* Append instruction to end of current block */
......@@ -1381,6 +1384,18 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
break;
case nir_intrinsic_load_alpha_ref_float:
assert(instr->dest.is_ssa);
float ref_value = ctx->alpha_ref;
printf("Ref %f\n", ref_value);
float *v = ralloc_array(NULL, float, 4);
memcpy(v, &ref_value, sizeof(float));
_mesa_hash_table_u64_insert(ctx->ssa_constants, instr->dest.ssa.index + 1, v);
break;
default:
printf ("Unhandled intrinsic\n");
assert(0);
......@@ -3267,6 +3282,8 @@ midgard_compile_shader_nir(nir_shader *nir, midgard_program *program, bool is_bl
.is_blend = is_blend,
.blend_constant_offset = -1,
.alpha_ref = program->alpha_ref
};
compiler_context *ctx = &ictx;
......
......@@ -45,6 +45,9 @@ typedef struct {
* negative, there's no constant. */
int blend_patch_offset;
/* IN: For a fragment shader with a lowered alpha test, the ref value */
float alpha_ref;
} midgard_program;
int
......
......@@ -54,9 +54,20 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *m
s->info.stage = type == JOB_TYPE_VERTEX ? MESA_SHADER_VERTEX : MESA_SHADER_FRAGMENT;
if (s->info.stage == MESA_SHADER_FRAGMENT) {
/* Inject the alpha test now if we need to */
if (state->alpha_state.enabled) {
NIR_PASS_V(s, nir_lower_alpha_test, state->alpha_state.func, false);
}
}
/* Call out to Midgard compiler given the above NIR */
midgard_program program;
midgard_program program = {
.alpha_ref = state->alpha_state.ref_value
};
midgard_compile_shader_nir(s, &program, false);
/* Prepare the compiled binary for upload */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment