Module: Mesa
Branch: main
Commit: 2da3a6e1b9644e4452388f83f3c5f64fc1da9bbe
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=2da3a6e1b9644e4452388f83f3c5f64fc1da9bbe

Author: Alyssa Rosenzweig <[email protected]>
Date:   Tue May 23 14:12:19 2023 -0400

nir/opt_barriers: Add a default callback

Absent any knowledge about the hardware, if the backend wants to combine
barriers we should try to combine all barriers.

Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Caio Oliveira <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23181>

---

 src/compiler/nir/nir_opt_barriers.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_opt_barriers.c 
b/src/compiler/nir/nir_opt_barriers.c
index 61dcdbdf3ef..3a6fc2d162b 100644
--- a/src/compiler/nir/nir_opt_barriers.c
+++ b/src/compiler/nir/nir_opt_barriers.c
@@ -23,6 +23,20 @@
 
 #include "nir.h"
 
+static bool
+combine_all_barriers(nir_intrinsic_instr *a, nir_intrinsic_instr *b, void *_)
+{
+   nir_intrinsic_set_memory_modes(
+      a, nir_intrinsic_memory_modes(a) | nir_intrinsic_memory_modes(b));
+   nir_intrinsic_set_memory_semantics(
+      a, nir_intrinsic_memory_semantics(a) | 
nir_intrinsic_memory_semantics(b));
+   nir_intrinsic_set_memory_scope(
+      a, MAX2(nir_intrinsic_memory_scope(a), nir_intrinsic_memory_scope(b)));
+   nir_intrinsic_set_execution_scope(
+      a, MAX2(nir_intrinsic_execution_scope(a), 
nir_intrinsic_execution_scope(b)));
+   return true;
+}
+
 static bool
 nir_opt_combine_barriers_impl(
    nir_function_impl *impl, nir_combine_barrier_cb combine_cb, void *data)
@@ -69,7 +83,9 @@ bool
 nir_opt_combine_barriers(
    nir_shader *shader, nir_combine_barrier_cb combine_cb, void *data)
 {
-   assert(combine_cb);
+   /* Default to combining everything. Only some backends can do better. */
+   if (!combine_cb)
+      combine_cb = combine_all_barriers;
 
    bool progress = false;
 

Reply via email to