Mesa (staging/21.3): spirv: run nir_copy_prop before nir_rematerialize_derefs_in_use_blocks_impl

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Nov 28 20:53:53 UTC 2021


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

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Tue Nov 23 13:27:14 2021 +0000

spirv: run nir_copy_prop before nir_rematerialize_derefs_in_use_blocks_impl

spirv_to_nir sometimes wraps derefs in vec2 or mov instructions as part of
its texture handling. These get in the way of
nir_rematerialize_derefs_in_use_blocks_impl. Running copy propagation
should get rid of the extra move instructions and get us back to intact
deref chains for everything except variable pointer use-cases.

fossil-db (Sienna Cichlid):
Totals from 6 (0.00% of 134572) affected shaders:
CodeSize: 92656 -> 93088 (+0.47%)
Instrs: 17060 -> 17138 (+0.46%)
Latency: 224408 -> 227539 (+1.40%)
InvThroughput: 37402 -> 37924 (+1.40%)
VClause: 408 -> 402 (-1.47%)
Copies: 1065 -> 1107 (+3.94%)

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5668
Fixes: 14a12b771d0 ("spirv: Rework our handling of images and samplers")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13924>
(cherry picked from commit b4251007810bc2a02d44580b04ad34ec381f891b)

---

 .pick_status.json                         | 2 +-
 src/compiler/nir/nir.h                    | 1 +
 src/compiler/nir/nir_opt_copy_propagate.c | 2 +-
 src/compiler/spirv/vtn_cfg.c              | 2 ++
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index b94c20d9393..a0257d4f825 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -652,7 +652,7 @@
         "description": "spirv: run nir_copy_prop before nir_rematerialize_derefs_in_use_blocks_impl",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "14a12b771d0a380defacafe5825362af77ff21bd"
     },
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 2bc17548d4a..aff1289892c 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -5532,6 +5532,7 @@ bool nir_opt_combine_memory_barriers(nir_shader *shader,
 
 bool nir_opt_combine_stores(nir_shader *shader, nir_variable_mode modes);
 
+bool nir_copy_prop_impl(nir_function_impl *impl);
 bool nir_copy_prop(nir_shader *shader);
 
 bool nir_opt_copy_prop_vars(nir_shader *shader);
diff --git a/src/compiler/nir/nir_opt_copy_propagate.c b/src/compiler/nir/nir_opt_copy_propagate.c
index 386587fa6c8..8b88779956a 100644
--- a/src/compiler/nir/nir_opt_copy_propagate.c
+++ b/src/compiler/nir/nir_opt_copy_propagate.c
@@ -162,7 +162,7 @@ copy_prop_instr(nir_function_impl *impl, nir_instr *instr)
    return progress;
 }
 
-static bool
+bool
 nir_copy_prop_impl(nir_function_impl *impl)
 {
    bool progress = false;
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 9a8a88ae9a8..2bf698629c1 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -1387,6 +1387,8 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
    vtn_foreach_instruction(b, func->start_block->label, func->end,
                            vtn_handle_phi_second_pass);
 
+   if (func->nir_func->impl->structured)
+      nir_copy_prop_impl(impl);
    nir_rematerialize_derefs_in_use_blocks_impl(impl);
 
    /*



More information about the mesa-commit mailing list