Mesa (staging/20.3): nir/opt_shrink_vectors: add option to skip shrinking image stores

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 17 19:57:08 UTC 2021


Module: Mesa
Branch: staging/20.3
Commit: fc46f3b88206e2a69f9859f5dbc236e1c6be9749
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fc46f3b88206e2a69f9859f5dbc236e1c6be9749

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Tue Feb 23 19:31:48 2021 +0000

nir/opt_shrink_vectors: add option to skip shrinking image stores

Some games declare the wrong format, so we might want to disable this
optimization in that case.

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Fixes: e4d75c22 ("nir/opt_shrink_vectors: shrink image stores using the format")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9557>

---

 src/amd/vulkan/radv_pipeline.c                     |  4 ++--
 src/amd/vulkan/radv_shader.c                       |  2 +-
 src/compiler/nir/nir.h                             |  2 +-
 src/compiler/nir/nir_opt_shrink_vectors.c          | 12 ++++++------
 src/gallium/auxiliary/nir/nir_to_tgsi.c            |  2 +-
 src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c |  2 +-
 src/intel/compiler/brw_nir.c                       |  2 +-
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index 44c1dd9e0f9..a0b4a3ba764 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -2275,7 +2275,7 @@ radv_link_shaders(struct radv_pipeline *pipeline, nir_shader **shaders,
 			if (nir_lower_io_to_scalar_early(ordered_shaders[i], mask)) {
 				/* Optimize the new vector code and then remove dead vars */
 				nir_copy_prop(ordered_shaders[i]);
-				nir_opt_shrink_vectors(ordered_shaders[i]);
+				nir_opt_shrink_vectors(ordered_shaders[i], true);
 
 		                if (ordered_shaders[i]->info.stage != last) {
 					/* Optimize swizzled movs of load_const for
@@ -3196,7 +3196,7 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
 
 			radv_lower_io(device, nir[i]);
 
-			lower_to_scalar |= nir_opt_shrink_vectors(nir[i]);
+			lower_to_scalar |= nir_opt_shrink_vectors(nir[i], true);
 
 			if (lower_to_scalar)
 				nir_lower_alu_to_scalar(nir[i], NULL, NULL);
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index d942fd14773..95a2f729dd9 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -238,7 +238,7 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively,
                 }
 
                 NIR_PASS(progress, shader, nir_opt_undef);
-                NIR_PASS(progress, shader, nir_opt_shrink_vectors);
+                NIR_PASS(progress, shader, nir_opt_shrink_vectors, true);
                 if (shader->options->max_unroll_iterations) {
                         NIR_PASS(progress, shader, nir_opt_loop_unroll, 0);
                 }
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 118fb5d1252..e2a94bfb11d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -5107,7 +5107,7 @@ bool nir_opt_rematerialize_compares(nir_shader *shader);
 bool nir_opt_remove_phis(nir_shader *shader);
 bool nir_opt_remove_phis_block(nir_block *block);
 
-bool nir_opt_shrink_vectors(nir_shader *shader);
+bool nir_opt_shrink_vectors(nir_shader *shader, bool shrink_image_store);
 
 bool nir_opt_trivial_continues(nir_shader *shader);
 
diff --git a/src/compiler/nir/nir_opt_shrink_vectors.c b/src/compiler/nir/nir_opt_shrink_vectors.c
index 05365986150..6192dbadeb1 100644
--- a/src/compiler/nir/nir_opt_shrink_vectors.c
+++ b/src/compiler/nir/nir_opt_shrink_vectors.c
@@ -134,7 +134,7 @@ opt_shrink_vectors_image_store(nir_builder *b, nir_intrinsic_instr *instr)
 }
 
 static bool
-opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr)
+opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, bool shrink_image_store)
 {
    switch (instr->intrinsic) {
    case nir_intrinsic_load_uniform:
@@ -160,7 +160,7 @@ opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr)
    case nir_intrinsic_bindless_image_store:
    case nir_intrinsic_image_deref_store:
    case nir_intrinsic_image_store:
-      return opt_shrink_vectors_image_store(b, instr);
+      return shrink_image_store && opt_shrink_vectors_image_store(b, instr);
    default:
       return false;
    }
@@ -209,7 +209,7 @@ opt_shrink_vectors_ssa_undef(nir_ssa_undef_instr *instr)
 }
 
 static bool
-opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr)
+opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr, bool shrink_image_store)
 {
    b->cursor = nir_before_instr(instr);
 
@@ -218,7 +218,7 @@ opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr)
       return opt_shrink_vectors_alu(b, nir_instr_as_alu(instr));
 
    case nir_instr_type_intrinsic:
-      return opt_shrink_vectors_intrinsic(b, nir_instr_as_intrinsic(instr));
+      return opt_shrink_vectors_intrinsic(b, nir_instr_as_intrinsic(instr), shrink_image_store);
 
    case nir_instr_type_load_const:
       return opt_shrink_vectors_load_const(nir_instr_as_load_const(instr));
@@ -234,7 +234,7 @@ opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr)
 }
 
 bool
-nir_opt_shrink_vectors(nir_shader *shader)
+nir_opt_shrink_vectors(nir_shader *shader, bool shrink_image_store)
 {
    bool progress = false;
 
@@ -247,7 +247,7 @@ nir_opt_shrink_vectors(nir_shader *shader)
 
       nir_foreach_block(block, function->impl) {
          nir_foreach_instr(instr, block) {
-            progress |= opt_shrink_vectors_instr(&b, instr);
+            progress |= opt_shrink_vectors_instr(&b, instr, shrink_image_store);
          }
       }
 
diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c
index 7ee27b4ced0..4cb7e7d6de7 100644
--- a/src/gallium/auxiliary/nir/nir_to_tgsi.c
+++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c
@@ -2299,7 +2299,7 @@ ntt_optimize_nir(struct nir_shader *s, struct pipe_screen *screen)
       NIR_PASS(progress, s, nir_opt_constant_folding);
       NIR_PASS(progress, s, nir_opt_load_store_vectorize, nir_var_mem_ubo,
                ntt_should_vectorize_io, 0);
-      NIR_PASS(progress, s, nir_opt_shrink_vectors);
+      NIR_PASS(progress, s, nir_opt_shrink_vectors, true);
       NIR_PASS(progress, s, nir_opt_trivial_continues);
       NIR_PASS(progress, s, nir_opt_vectorize, ntt_should_vectorize_instr, NULL);
       NIR_PASS(progress, s, nir_opt_undef);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
index 2ce32458da2..0647bb648cc 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
@@ -145,7 +145,7 @@ etna_optimize_loop(nir_shader *s)
 
       NIR_PASS_V(s, nir_lower_vars_to_ssa);
       progress |= OPT(s, nir_opt_copy_prop_vars);
-      progress |= OPT(s, nir_opt_shrink_vectors);
+      progress |= OPT(s, nir_opt_shrink_vectors, true);
       progress |= OPT(s, nir_copy_prop);
       progress |= OPT(s, nir_opt_dce);
       progress |= OPT(s, nir_opt_cse);
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index a36ffa1506d..9f7601ebcf2 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -550,7 +550,7 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
       if (is_scalar) {
          OPT(nir_lower_alu_to_scalar, NULL, NULL);
       } else {
-         OPT(nir_opt_shrink_vectors);
+         OPT(nir_opt_shrink_vectors, true);
       }
 
       OPT(nir_copy_prop);



More information about the mesa-commit mailing list