From b9b71bcae685dba5da066a769e5ea0ab53110f3c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 25 May 2023 13:22:50 -0400 Subject: [PATCH] asahi,agx: Call lower_discard_zs_emit in the driver The driver needs to lower MSAA (because only it knows the sample count). MSAA lowering depends on discards getting lowered (in order to get sample masks on the discards for sample shading to work properly). Discard lowering depends on all discards emitted. But the driver needs to lower clip planes which generates discards. To break the circular dependency, we have the driver call the discard lowering pass itself (in between lowering clip planes and lowering MSAA). Technically, this is probably a layering violation but it's the least gross solution I see. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 5 ----- src/asahi/compiler/agx_compile.h | 2 ++ src/asahi/compiler/agx_compiler.h | 1 - src/gallium/drivers/asahi/agx_state.c | 14 ++++++++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index f10deeb530b..7309035e8b5 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -2375,11 +2375,6 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, out->nr_bindful_textures = BITSET_LAST_BIT(nir->info.textures_used); - /* Late clip plane lowering created discards */ - if (nir->info.stage == MESA_SHADER_FRAGMENT) { - NIR_PASS_V(nir, agx_nir_lower_discard_zs_emit); - } - /* Late sysval lowering creates large loads. Load lowering creates unpacks */ NIR_PASS_V(nir, nir_lower_mem_access_bit_sizes, nir_var_mem_ssbo | nir_var_mem_constant | diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index e218cdc6fa5..7f9b2300e7a 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -173,6 +173,8 @@ struct agx_shader_key { void agx_preprocess_nir(nir_shader *nir, bool support_lod_bias); +bool agx_nir_lower_discard_zs_emit(nir_shader *s); + void agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, struct util_debug_callback *debug, struct util_dynarray *binary, diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index 35bb1a5f846..a69b54a9a3d 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -793,7 +793,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_discard_zs_emit(nir_shader *s); bool agx_nir_lower_sample_mask(nir_shader *s, unsigned nr_samples); bool agx_nir_lower_texture(nir_shader *s, bool support_lod_bias); bool agx_nir_opt_preamble(nir_shader *s, unsigned *preamble_size); diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 771ebd11154..9da8ac1576a 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1401,6 +1401,16 @@ agx_compile_variant(struct agx_device *dev, struct agx_uncompiled_shader *so, } } + /* Clip plane lowering creates discard instructions, so run that before + * lowering discards. + */ + if (key->clip_plane_enable) { + NIR_PASS_V(nir, nir_lower_clip_fs, key->clip_plane_enable, false); + } + + /* Discards must be lowering before lowering MSAA to handle discards */ + NIR_PASS_V(nir, agx_nir_lower_discard_zs_emit); + NIR_PASS_V(nir, nir_lower_blend, &opts); NIR_PASS_V(nir, agx_nir_lower_tilebuffer, &tib, colormasks, &force_translucent); @@ -1410,10 +1420,6 @@ agx_compile_variant(struct agx_device *dev, struct agx_uncompiled_shader *so, key->sprite_coord_enable, false /* point coord is sysval */); } - - if (key->clip_plane_enable) { - NIR_PASS_V(nir, nir_lower_clip_fs, key->clip_plane_enable, false); - } } struct agx_shader_key base_key = {0};