asahi: Run nir_lower_fragcolor during preprocessing
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Tue, 29 Nov 2022 03:37:31 +0000 (22:37 -0500)
committerMarge Bot <emma+marge@anholt.net>
Fri, 3 Feb 2023 15:03:06 +0000 (15:03 +0000)
This pass needs to run early (because it depends on early I/O), but it doesn't
actually need the shader key. Why not? If we overestimate the number of render
targets, extra store_output intrinsics will be generated, but they will be
deleted by AGX tilebuffer lowering later.

Note we'll probably want something smarter than this for fragment epilogues in
the future to avoid piles of unnecessary moves.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21065>

src/asahi/compiler/agx_compile.c
src/gallium/drivers/asahi/agx_state.c

index cd7724c..d75e6ae 100644 (file)
@@ -1882,8 +1882,15 @@ agx_preprocess_nir(nir_shader *nir)
 {
    NIR_PASS_V(nir, nir_lower_vars_to_ssa);
 
-   if (nir->info.stage == MESA_SHADER_VERTEX)
+   if (nir->info.stage == MESA_SHADER_VERTEX) {
       NIR_PASS_V(nir, nir_lower_point_size, 1.0, 0.0);
+   } else if (nir->info.stage == MESA_SHADER_FRAGMENT) {
+      /* Lower to maximum colour buffers, the excess stores will get cleaned up
+       * by tilebuffer lowering so they won't become real shader code. However,
+       * that depends on the shader key which we don't have at this point.
+       */
+      NIR_PASS_V(nir, nir_lower_fragcolor, 8);
+   }
 
    /* Lower large arrays to scratch and small arrays to csel */
    NIR_PASS_V(nir, nir_lower_vars_to_scratch, nir_var_function_temp, 16,
index 474a93e..f47747b 100644 (file)
@@ -1265,8 +1265,6 @@ agx_compile_variant(struct agx_device *dev, struct agx_uncompiled_shader *so,
       memcpy(opts.rt, key->blend.rt, sizeof(opts.rt));
       NIR_PASS_V(nir, nir_lower_blend, &opts);
 
-      NIR_PASS_V(nir, nir_lower_fragcolor, key->nr_cbufs);
-
       if (key->sprite_coord_enable) {
          NIR_PASS_V(nir, nir_lower_texcoord_replace, key->sprite_coord_enable,
                     false /* point coord is sysval */, false /* Y-invert */);