agx: fix early-z + discard together

don't trigger tests twice.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26963>
This commit is contained in:
Alyssa Rosenzweig 2023-12-09 23:13:18 -04:00
parent eab145e223
commit 210c6931ff
2 changed files with 46 additions and 43 deletions

View file

@ -64,18 +64,14 @@ agx_nir_lower_frag_sidefx(nir_shader *s)
s->info.outputs_written &
(BITFIELD64_BIT(FRAG_RESULT_STENCIL) | BITFIELD64_BIT(FRAG_RESULT_DEPTH));
/* If the shader wants early fragment tests, trigger an early test at the
* beginning of the shader. This lets us use a Passthrough punch type,
* instead of Opaque which may result in the shader getting skipped
* incorrectly and then the side effects not kicking in.
/* If the shader wants early fragment tests, the sample mask lowering pass
* will trigger an early test at the beginning of the shader. This lets us
* use a Passthrough punch type, instead of Opaque which may result in the
* shader getting skipped incorrectly and then the side effects not kicking
* in. But this happens there to avoid it happening twice with a discard.
*/
if (s->info.fs.early_fragment_tests) {
nir_function_impl *impl = nir_shader_get_entrypoint(s);
nir_builder b = nir_builder_at(nir_before_impl(impl));
nir_sample_mask_agx(&b, nir_imm_intN_t(&b, ALL_SAMPLES, 16),
nir_imm_intN_t(&b, ALL_SAMPLES, 16));
return true;
}
if (s->info.fs.early_fragment_tests)
return false;
/* If depth/stencil feedback is already used, we're done */
if (writes_zs)

View file

@ -192,44 +192,51 @@ run_tests_after_last_discard(nir_builder *b)
}
}
static void
run_tests_at_start(nir_shader *shader)
{
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_builder b = nir_builder_at(nir_before_impl(impl));
nir_sample_mask_agx(&b, nir_imm_intN_t(&b, ALL_SAMPLES, 16),
nir_imm_intN_t(&b, ALL_SAMPLES, 16));
}
bool
agx_nir_lower_sample_mask(nir_shader *shader, unsigned nr_samples)
{
if (!shader->info.fs.uses_discard)
return false;
/* sample_mask can't be used with zs_emit, so lower sample_mask to zs_emit.
* We ignore depth/stencil writes with early fragment testing though.
*/
if (shader->info.outputs_written & (BITFIELD64_BIT(FRAG_RESULT_DEPTH) |
BITFIELD64_BIT(FRAG_RESULT_STENCIL)) &&
!shader->info.fs.early_fragment_tests) {
bool progress = nir_shader_intrinsics_pass(
shader, lower_sample_mask_to_zs,
nir_metadata_block_index | nir_metadata_dominance, NULL);
/* The lowering requires an unconditional depth write. We mark this after
* lowering so the lowering knows whether there was already a depth write
*/
assert(progress && "must have lowered something,given the outputs");
shader->info.outputs_written |= BITFIELD64_BIT(FRAG_RESULT_DEPTH);
return true;
}
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_builder b = nir_builder_create(impl);
/* If we force early fragment testing forced, run tests at the beginning of
* the shader. Otherwise, run after last discard.
*/
if (shader->info.fs.early_fragment_tests) {
b.cursor = nir_before_impl(impl);
/* run tests early */
run_tests_at_start(shader);
} else if (shader->info.fs.uses_discard) {
/* sample_mask can't be used with zs_emit, so lower sample_mask to zs_emit.
* We ignore depth/stencil writes with early fragment testing though.
*/
if (shader->info.outputs_written &
(BITFIELD64_BIT(FRAG_RESULT_DEPTH) |
BITFIELD64_BIT(FRAG_RESULT_STENCIL))) {
bool progress = nir_shader_intrinsics_pass(
shader, lower_sample_mask_to_zs,
nir_metadata_block_index | nir_metadata_dominance, NULL);
nir_def *all_samples = nir_imm_intN_t(&b, ALL_SAMPLES, 16);
nir_sample_mask_agx(&b, all_samples, all_samples);
} else {
/* The lowering requires an unconditional depth write. We mark this
* after lowering so the lowering knows whether there was already a
* depth write
*/
assert(progress && "must have lowered something,given the outputs");
shader->info.outputs_written |= BITFIELD64_BIT(FRAG_RESULT_DEPTH);
return true;
}
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_builder b = nir_builder_create(impl);
/* run tests late */
run_tests_after_last_discard(&b);
} else {
/* regular shaders that don't use discard have nothing to lower */
return false;
}
nir_shader_intrinsics_pass(shader, lower_discard_to_sample_mask_0,