nir/opt_barrier: Generalize to control barriers
For GLSL, we want to optimize code like memoryBarrierBuffer(); controlBarrier(); into a single scoped_barrier intrinsic for the backend to consume. Now that backends can get scoped_barriers everywhere, what's left is enabling backends to combine these barriers together. We already have an Intel-specific pass for combining memory barriers; it just needs a teensy bit of generalization to allow combining all sorts of barriers together. This avoids code quality regression on Asahi when switching to purely scoped barriers. It's probably useful for other backends too. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21661>
This commit is contained in:

committed by
Marge Bot

parent
83fd7a5ed1
commit
952bd63d6d
@@ -5720,12 +5720,12 @@ bool nir_opt_constant_folding(nir_shader *shader);
|
|||||||
* which will result in b being removed by the pass. Return false if
|
* which will result in b being removed by the pass. Return false if
|
||||||
* combination wasn't possible.
|
* combination wasn't possible.
|
||||||
*/
|
*/
|
||||||
typedef bool (*nir_combine_memory_barrier_cb)(
|
typedef bool (*nir_combine_barrier_cb)(
|
||||||
nir_intrinsic_instr *a, nir_intrinsic_instr *b, void *data);
|
nir_intrinsic_instr *a, nir_intrinsic_instr *b, void *data);
|
||||||
|
|
||||||
bool nir_opt_combine_memory_barriers(nir_shader *shader,
|
bool nir_opt_combine_barriers(nir_shader *shader,
|
||||||
nir_combine_memory_barrier_cb combine_cb,
|
nir_combine_barrier_cb combine_cb,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
bool nir_opt_combine_stores(nir_shader *shader, nir_variable_mode modes);
|
bool nir_opt_combine_stores(nir_shader *shader, nir_variable_mode modes);
|
||||||
|
|
||||||
|
@@ -24,8 +24,8 @@
|
|||||||
#include "nir.h"
|
#include "nir.h"
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
nir_opt_combine_memory_barriers_impl(
|
nir_opt_combine_barriers_impl(
|
||||||
nir_function_impl *impl, nir_combine_memory_barrier_cb combine_cb, void *data)
|
nir_function_impl *impl, nir_combine_barrier_cb combine_cb, void *data)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
bool progress = false;
|
||||||
|
|
||||||
@@ -39,8 +39,7 @@ nir_opt_combine_memory_barriers_impl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
nir_intrinsic_instr *current = nir_instr_as_intrinsic(instr);
|
nir_intrinsic_instr *current = nir_instr_as_intrinsic(instr);
|
||||||
if (current->intrinsic != nir_intrinsic_scoped_barrier ||
|
if (current->intrinsic != nir_intrinsic_scoped_barrier) {
|
||||||
nir_intrinsic_execution_scope(current) != NIR_SCOPE_NONE) {
|
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -65,10 +64,10 @@ nir_opt_combine_memory_barriers_impl(
|
|||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Combine adjacent scoped memory barriers. */
|
/* Combine adjacent scoped barriers. */
|
||||||
bool
|
bool
|
||||||
nir_opt_combine_memory_barriers(
|
nir_opt_combine_barriers(
|
||||||
nir_shader *shader, nir_combine_memory_barrier_cb combine_cb, void *data)
|
nir_shader *shader, nir_combine_barrier_cb combine_cb, void *data)
|
||||||
{
|
{
|
||||||
assert(combine_cb);
|
assert(combine_cb);
|
||||||
|
|
||||||
@@ -76,7 +75,7 @@ nir_opt_combine_memory_barriers(
|
|||||||
|
|
||||||
nir_foreach_function(function, shader) {
|
nir_foreach_function(function, shader) {
|
||||||
if (function->impl &&
|
if (function->impl &&
|
||||||
nir_opt_combine_memory_barriers_impl(function->impl, combine_cb, data)) {
|
nir_opt_combine_barriers_impl(function->impl, combine_cb, data)) {
|
||||||
progress = true;
|
progress = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1243,10 +1243,15 @@ brw_nir_should_vectorize_mem(unsigned align_mul, unsigned align_offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
bool combine_all_barriers(nir_intrinsic_instr *a,
|
bool combine_all_memory_barriers(nir_intrinsic_instr *a,
|
||||||
nir_intrinsic_instr *b,
|
nir_intrinsic_instr *b,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
|
/* Only combine pure memory barriers */
|
||||||
|
if ((nir_intrinsic_execution_scope(a) != NIR_SCOPE_NONE) ||
|
||||||
|
(nir_intrinsic_execution_scope(b) != NIR_SCOPE_NONE))
|
||||||
|
return false;
|
||||||
|
|
||||||
/* Translation to backend IR will get rid of modes we don't care about, so
|
/* Translation to backend IR will get rid of modes we don't care about, so
|
||||||
* no harm in always combining them.
|
* no harm in always combining them.
|
||||||
*
|
*
|
||||||
@@ -1418,7 +1423,7 @@ brw_postprocess_nir(nir_shader *nir, const struct brw_compiler *compiler,
|
|||||||
OPT(nir_lower_bit_size, lower_bit_size_callback, (void *)compiler);
|
OPT(nir_lower_bit_size, lower_bit_size_callback, (void *)compiler);
|
||||||
|
|
||||||
OPT(brw_nir_lower_scoped_barriers);
|
OPT(brw_nir_lower_scoped_barriers);
|
||||||
OPT(nir_opt_combine_memory_barriers, combine_all_barriers, NULL);
|
OPT(nir_opt_combine_barriers, combine_all_memory_barriers, NULL);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
progress = false;
|
progress = false;
|
||||||
|
Reference in New Issue
Block a user