2 * Copyright (c) 2020 Intel Corporation
3 * Copyright (c) 2020 Collabora Ltd
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 * Lower scoped barriers embedding a control barrier (execusion_scope != NONE)
27 * to scoped_barriers-without-control-barrier + control_barrier.
31 #include "compiler/nir/nir_builder.h"
34 lower_impl(nir_function_impl
*impl
)
37 nir_builder_init(&b
, impl
);
38 bool progress
= false;
40 nir_foreach_block(block
, impl
) {
41 nir_foreach_instr_safe(instr
, block
) {
42 if (instr
->type
!= nir_instr_type_intrinsic
)
45 nir_intrinsic_instr
*intr
= nir_instr_as_intrinsic(instr
);
47 if (intr
->intrinsic
!= nir_intrinsic_scoped_barrier
||
48 nir_intrinsic_execution_scope(intr
) == NIR_SCOPE_NONE
)
51 if (nir_intrinsic_execution_scope(intr
) == NIR_SCOPE_WORKGROUP
) {
52 b
.cursor
= nir_after_instr(&intr
->instr
);
53 nir_intrinsic_instr
*cbarrier
=
54 nir_intrinsic_instr_create(b
.shader
,
55 nir_intrinsic_control_barrier
);
56 nir_builder_instr_insert(&b
, &cbarrier
->instr
);
59 nir_intrinsic_set_execution_scope(intr
, NIR_SCOPE_NONE
);
65 nir_metadata_preserve(impl
, nir_metadata_block_index
|
66 nir_metadata_dominance
);
68 nir_metadata_preserve(impl
, nir_metadata_all
);
75 brw_nir_lower_scoped_barriers(nir_shader
*nir
)
77 bool progress
= false;
79 nir_foreach_function(function
, nir
) {
81 progress
|= lower_impl(function
->impl
);