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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23480>
This commit is contained in:
Alyssa Rosenzweig
2023-05-25 13:22:50 -04:00
committed by Marge Bot
parent 398851ca53
commit b9b71bcae6
4 changed files with 12 additions and 10 deletions

View File

@@ -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); 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 */ /* Late sysval lowering creates large loads. Load lowering creates unpacks */
NIR_PASS_V(nir, nir_lower_mem_access_bit_sizes, NIR_PASS_V(nir, nir_lower_mem_access_bit_sizes,
nir_var_mem_ssbo | nir_var_mem_constant | nir_var_mem_ssbo | nir_var_mem_constant |

View File

@@ -173,6 +173,8 @@ struct agx_shader_key {
void agx_preprocess_nir(nir_shader *nir, bool support_lod_bias); 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, void agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key,
struct util_debug_callback *debug, struct util_debug_callback *debug,
struct util_dynarray *binary, struct util_dynarray *binary,

View File

@@ -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_compute_liveness(agx_context *ctx);
void agx_liveness_ins_update(BITSET_WORD *live, agx_instr *I); 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_sample_mask(nir_shader *s, unsigned nr_samples);
bool agx_nir_lower_texture(nir_shader *s, bool support_lod_bias); bool agx_nir_lower_texture(nir_shader *s, bool support_lod_bias);
bool agx_nir_opt_preamble(nir_shader *s, unsigned *preamble_size); bool agx_nir_opt_preamble(nir_shader *s, unsigned *preamble_size);

View File

@@ -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, nir_lower_blend, &opts);
NIR_PASS_V(nir, agx_nir_lower_tilebuffer, &tib, colormasks, NIR_PASS_V(nir, agx_nir_lower_tilebuffer, &tib, colormasks,
&force_translucent); &force_translucent);
@@ -1410,10 +1420,6 @@ agx_compile_variant(struct agx_device *dev, struct agx_uncompiled_shader *so,
key->sprite_coord_enable, key->sprite_coord_enable,
false /* point coord is sysval */); 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}; struct agx_shader_key base_key = {0};