Mesa (master): nir/lower_fragcolor: Take max cbufs as argument

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 23 17:50:09 UTC 2021


Module: Mesa
Branch: master
Commit: c84804f167d240e47e843502425379c80437deb6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c84804f167d240e47e843502425379c80437deb6

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Thu Apr 22 11:28:42 2021 -0400

nir/lower_fragcolor: Take max cbufs as argument

One step closer to generalizing this pass to more drivers.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10411>

---

 src/compiler/nir/nir.h                   |  2 +-
 src/compiler/nir/nir_lower_fragcolor.c   | 11 +++++------
 src/gallium/drivers/zink/zink_compiler.c |  3 ++-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index cbe5ab94f3b..d71dc4d72c3 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4628,7 +4628,7 @@ bool nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
 bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
 bool nir_vectorize_tess_levels(nir_shader *shader);
 
-bool nir_lower_fragcolor(nir_shader *shader);
+bool nir_lower_fragcolor(nir_shader *shader, unsigned max_cbufs);
 bool nir_lower_fragcoord_wtrans(nir_shader *shader);
 void nir_lower_viewport_transform(nir_shader *shader);
 bool nir_lower_uniforms_to_ubo(nir_shader *shader, bool dword_packed, bool load_vec4);
diff --git a/src/compiler/nir/nir_lower_fragcolor.c b/src/compiler/nir/nir_lower_fragcolor.c
index 70ade5cacf7..15480361764 100644
--- a/src/compiler/nir/nir_lower_fragcolor.c
+++ b/src/compiler/nir/nir_lower_fragcolor.c
@@ -48,14 +48,13 @@
  */
 
 static bool
-lower_fragcolor_instr(nir_builder *b, nir_instr *intr, UNUSED void *data)
+lower_fragcolor_instr(nir_builder *b, nir_instr *intr, void *data)
 {
    if (intr->type != nir_instr_type_intrinsic)
       return false;
 
    nir_intrinsic_instr *instr = nir_instr_as_intrinsic(intr);
-   const unsigned max_draw_buffers =
-      b->shader->info.fs.color_is_dual_source ? 1 : 8;
+   unsigned *max_draw_buffers = data;
 
    nir_variable *out;
    if (instr->intrinsic != nir_intrinsic_store_deref)
@@ -82,7 +81,7 @@ lower_fragcolor_instr(nir_builder *b, nir_instr *intr, UNUSED void *data)
    b->shader->info.outputs_written &= ~BITFIELD64_BIT(FRAG_RESULT_COLOR);
    b->shader->info.outputs_written |= BITFIELD64_BIT(FRAG_RESULT_DATA0);
 
-   for (unsigned i = 1; i < max_draw_buffers; i++) {
+   for (unsigned i = 1; i < *max_draw_buffers; i++) {
       char name[28];
       snprintf(name, sizeof(name), name_tmpl, i);
       nir_variable *out_color = nir_variable_create(b->shader, nir_var_shader_out,
@@ -97,11 +96,11 @@ lower_fragcolor_instr(nir_builder *b, nir_instr *intr, UNUSED void *data)
 }
 
 bool
-nir_lower_fragcolor(nir_shader *shader)
+nir_lower_fragcolor(nir_shader *shader, unsigned max_draw_buffers)
 {
    if (shader->info.stage != MESA_SHADER_FRAGMENT)
       return false;
 
    return nir_shader_instructions_pass(shader, lower_fragcolor_instr,
-         nir_metadata_block_index | nir_metadata_dominance, NULL);
+         nir_metadata_block_index | nir_metadata_dominance, &max_draw_buffers);
 }
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index a2edecb9806..e006058910b 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -823,7 +823,8 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
    optimize_nir(nir);
    NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp, NULL);
    NIR_PASS_V(nir, lower_discard_if);
-   NIR_PASS_V(nir, nir_lower_fragcolor);
+   NIR_PASS_V(nir, nir_lower_fragcolor,
+         nir->info.fs.color_is_dual_source ? 1 : 8);
    NIR_PASS_V(nir, lower_64bit_vertex_attribs);
    NIR_PASS_V(nir, unbreak_bos);
 



More information about the mesa-commit mailing list