From 27ddcea2b3929a503c08ae8137b0377570f546e5 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 6 Feb 2024 21:44:21 -0400 Subject: [PATCH] agx: call agx_nir_lower_sample_mask earlier A given sample needs depth testing to happen before writing its colour, which requires shuffling pass order. To do so, merge agx_nir_opt_ixor_bcsel into regular late alg pass now that we can, which is actually a small shader-db win. Closes https://gitlab.freedesktop.org/asahi/mesa/-/issues/30 Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 19 ------------------- src/asahi/compiler/agx_compile.h | 1 + src/asahi/compiler/agx_compiler.h | 1 - src/asahi/compiler/agx_nir_algebraic.py | 3 ++- src/asahi/lib/agx_nir_lower_msaa.c | 3 +++ 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index 072e9ddc2ad..1687002bedf 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -3154,25 +3154,6 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, out->push_count = key->reserved_preamble; agx_optimize_nir(nir, &out->push_count); - /* Create sample_mask instructions late, since NIR's scheduling is not aware - * of the ordering requirements between sample_mask and pixel stores. - * - * Note: when epilogs are used, special handling is required since the sample - * count is dynamic when the main fragment shader is compiled. - */ - if (nir->info.stage == MESA_SHADER_FRAGMENT && key->fs.nr_samples) { - if (agx_nir_lower_sample_mask(nir)) { - /* Clean up ixor(bcsel) patterns created from sample mask lowering. - * Also constant fold to get the benefit. We need to rescalarize after - * folding constants. - */ - NIR_PASS(_, nir, agx_nir_opt_ixor_bcsel); - NIR_PASS(_, nir, nir_opt_constant_folding); - NIR_PASS(_, nir, nir_lower_load_const_to_scalar); - NIR_PASS(_, nir, nir_opt_dce); - } - } - /* Must be last since NIR passes can remap driver_location freely */ if (nir->info.stage == MESA_SHADER_VERTEX) agx_remap_varyings_vs(nir, &out->varyings.vs, key); diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index 6a7bdeef19c..41e34a25b30 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -256,6 +256,7 @@ void agx_preprocess_nir(nir_shader *nir, const nir_shader *libagx, struct agx_uncompiled_shader_info *out); bool agx_nir_lower_discard_zs_emit(nir_shader *s); +bool agx_nir_lower_sample_mask(nir_shader *s); bool agx_nir_lower_cull_distance_fs(struct nir_shader *s, unsigned nr_distances); diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index 66296f45513..333c5720fed 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -926,7 +926,6 @@ void agx_emit_parallel_copies(agx_builder *b, struct agx_copy *copies, void agx_compute_liveness(agx_context *ctx); void agx_liveness_ins_update(BITSET_WORD *live, agx_instr *I); -bool agx_nir_lower_sample_mask(nir_shader *s); bool agx_nir_lower_texture(nir_shader *s); bool agx_nir_opt_preamble(nir_shader *s, unsigned *preamble_size); bool agx_nir_lower_load_mask(nir_shader *shader); diff --git a/src/asahi/compiler/agx_nir_algebraic.py b/src/asahi/compiler/agx_nir_algebraic.py index ca3dc49f4a0..1987477e980 100644 --- a/src/asahi/compiler/agx_nir_algebraic.py +++ b/src/asahi/compiler/agx_nir_algebraic.py @@ -193,7 +193,8 @@ def run(): lower_sm5_shift + lower_pack + lower_selects).render()) print(nir_algebraic.AlgebraicPass("agx_nir_fuse_algebraic_late", - fuse_extr + fuse_ubfe + fuse_imad).render()) + fuse_extr + fuse_ubfe + fuse_imad + + ixor_bcsel).render()) print(nir_algebraic.AlgebraicPass("agx_nir_opt_ixor_bcsel", ixor_bcsel).render()) diff --git a/src/asahi/lib/agx_nir_lower_msaa.c b/src/asahi/lib/agx_nir_lower_msaa.c index 43da2bea14f..943617f8289 100644 --- a/src/asahi/lib/agx_nir_lower_msaa.c +++ b/src/asahi/lib/agx_nir_lower_msaa.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT */ +#include "agx_compile.h" #include "agx_tilebuffer.h" #include "nir.h" #include "nir_builder.h" @@ -187,6 +188,8 @@ agx_nir_lower_monolithic_msaa(nir_shader *shader, struct agx_msaa_state *state) nir_metadata_block_index | nir_metadata_dominance, &state->nr_samples); + agx_nir_lower_sample_mask(shader); + /* In single sampled programs, interpolateAtSample needs to return the * center pixel. TODO: Generalize for dynamic sample count. */