nir: Use nir_shader_intrinsic_pass() a few places
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24760>
This commit is contained in:

committed by
Marge Bot

parent
831085afa3
commit
1198816f50
@@ -500,14 +500,10 @@ nir_blend_replace_rt(const nir_lower_blend_rt *rt)
|
||||
}
|
||||
|
||||
static bool
|
||||
nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
nir_lower_blend_instr(nir_builder *b, nir_intrinsic_instr *store, void *data)
|
||||
{
|
||||
struct ctx *ctx = data;
|
||||
const nir_lower_blend_options *options = ctx->options;
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *store = nir_instr_as_intrinsic(instr);
|
||||
if (store->intrinsic != nir_intrinsic_store_output)
|
||||
return false;
|
||||
|
||||
@@ -519,21 +515,21 @@ nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
return false;
|
||||
|
||||
/* Only process stores once. Pass flags are cleared by consume_dual_stores */
|
||||
if (instr->pass_flags)
|
||||
if (store->instr.pass_flags)
|
||||
return false;
|
||||
|
||||
instr->pass_flags = 1;
|
||||
store->instr.pass_flags = 1;
|
||||
|
||||
/* Store are sunk to the bottom of the block to ensure that the dual
|
||||
* source colour is already written.
|
||||
*/
|
||||
b->cursor = nir_after_block(instr->block);
|
||||
b->cursor = nir_after_block(store->instr.block);
|
||||
|
||||
/* Don't bother copying the destination to the source for disabled RTs */
|
||||
if (options->rt[rt].colormask == 0 ||
|
||||
(options->logicop_enable && options->logicop_func == PIPE_LOGICOP_NOOP)) {
|
||||
|
||||
nir_instr_remove(instr);
|
||||
nir_instr_remove(&store->instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -600,8 +596,8 @@ nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
nir_src_rewrite(&store->src[0], blended);
|
||||
|
||||
/* Sink to bottom */
|
||||
nir_instr_remove(instr);
|
||||
nir_builder_instr_insert(b, instr);
|
||||
nir_instr_remove(&store->instr);
|
||||
nir_builder_instr_insert(b, &store->instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -611,20 +607,16 @@ nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
* backend doesn't have to deal with them, collecting the sources for blending.
|
||||
*/
|
||||
static bool
|
||||
consume_dual_stores(nir_builder *b, nir_instr *instr, void *data)
|
||||
consume_dual_stores(nir_builder *b, nir_intrinsic_instr *store, void *data)
|
||||
{
|
||||
nir_def **outputs = data;
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *store = nir_instr_as_intrinsic(instr);
|
||||
if (store->intrinsic != nir_intrinsic_store_output)
|
||||
return false;
|
||||
|
||||
/* While we're here, clear the pass flags for store_outputs, since we'll set
|
||||
* them later.
|
||||
*/
|
||||
instr->pass_flags = 0;
|
||||
store->instr.pass_flags = 0;
|
||||
|
||||
nir_io_semantics sem = nir_intrinsic_io_semantics(store);
|
||||
if (sem.dual_source_blend_index == 0)
|
||||
@@ -634,7 +626,7 @@ consume_dual_stores(nir_builder *b, nir_instr *instr, void *data)
|
||||
assert(rt >= 0 && rt < 8 && "bounds for dual-source blending");
|
||||
|
||||
outputs[rt] = store->src[0].ssa;
|
||||
nir_instr_remove(instr);
|
||||
nir_instr_remove(&store->instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -649,13 +641,13 @@ nir_lower_blend(nir_shader *shader, const nir_lower_blend_options *options)
|
||||
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
||||
|
||||
struct ctx ctx = { .options = options };
|
||||
nir_shader_instructions_pass(shader, consume_dual_stores,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
ctx.src1);
|
||||
nir_shader_intrinsics_pass(shader, consume_dual_stores,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
ctx.src1);
|
||||
|
||||
nir_shader_instructions_pass(shader, nir_lower_blend_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&ctx);
|
||||
nir_shader_intrinsics_pass(shader, nir_lower_blend_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&ctx);
|
||||
}
|
||||
|
@@ -25,15 +25,10 @@
|
||||
#include "nir.h"
|
||||
|
||||
static bool
|
||||
lower_discard_if_instr(nir_builder *b, nir_instr *instr_, void *cb_data)
|
||||
lower_discard_if(nir_builder *b, nir_intrinsic_instr *instr, void *cb_data)
|
||||
{
|
||||
nir_lower_discard_if_options options = *(nir_lower_discard_if_options *)cb_data;
|
||||
|
||||
if (instr_->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *instr = nir_instr_as_intrinsic(instr_);
|
||||
|
||||
switch (instr->intrinsic) {
|
||||
case nir_intrinsic_discard_if:
|
||||
if (!(options & nir_lower_discard_if_to_cf))
|
||||
@@ -122,8 +117,8 @@ lower_discard_if_instr(nir_builder *b, nir_instr *instr_, void *cb_data)
|
||||
bool
|
||||
nir_lower_discard_if(nir_shader *shader, nir_lower_discard_if_options options)
|
||||
{
|
||||
return nir_shader_instructions_pass(shader,
|
||||
lower_discard_if_instr,
|
||||
nir_metadata_none,
|
||||
&options);
|
||||
return nir_shader_intrinsics_pass(shader,
|
||||
lower_discard_if,
|
||||
nir_metadata_none,
|
||||
&options);
|
||||
}
|
||||
|
@@ -26,12 +26,8 @@
|
||||
#include "nir_builder.h"
|
||||
|
||||
static bool
|
||||
nir_lower_discard_to_demote_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
lower_discard_to_demote(nir_builder *b, nir_intrinsic_instr *intrin, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||
switch (intrin->intrinsic) {
|
||||
case nir_intrinsic_discard:
|
||||
intrin->intrinsic = nir_intrinsic_demote;
|
||||
@@ -48,12 +44,8 @@ nir_lower_discard_to_demote_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
}
|
||||
|
||||
static bool
|
||||
nir_lower_demote_to_discard_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
lower_demote_to_discard(nir_builder *b, nir_intrinsic_instr *intrin, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||
switch (intrin->intrinsic) {
|
||||
case nir_intrinsic_demote:
|
||||
intrin->intrinsic = nir_intrinsic_discard;
|
||||
@@ -65,10 +57,10 @@ nir_lower_demote_to_discard_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
case nir_intrinsic_load_helper_invocation: {
|
||||
/* If the shader doesn't need helper invocations,
|
||||
* we can assume there are none */
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&intrin->instr);
|
||||
nir_def *zero = nir_imm_false(b);
|
||||
nir_def_rewrite_uses(&intrin->def, zero);
|
||||
nir_instr_remove_v(instr);
|
||||
nir_instr_remove(&intrin->instr);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@@ -93,19 +85,16 @@ insert_is_helper(nir_builder *b, nir_instr *instr)
|
||||
}
|
||||
|
||||
static bool
|
||||
nir_lower_load_helper_to_is_helper(nir_builder *b, nir_instr *instr, void *data)
|
||||
lower_load_helper_to_is_helper(nir_builder *b,
|
||||
nir_intrinsic_instr *intrin, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||
nir_def *is_helper = *(nir_def **)data;
|
||||
switch (intrin->intrinsic) {
|
||||
case nir_intrinsic_demote:
|
||||
case nir_intrinsic_demote_if:
|
||||
/* insert is_helper at last top level occasion */
|
||||
if (is_helper == NULL) {
|
||||
is_helper = insert_is_helper(b, instr);
|
||||
is_helper = insert_is_helper(b, &intrin->instr);
|
||||
*(nir_def **)data = is_helper;
|
||||
return true;
|
||||
} else {
|
||||
@@ -116,9 +105,9 @@ nir_lower_load_helper_to_is_helper(nir_builder *b, nir_instr *instr, void *data)
|
||||
* we can insert new is_helper() intrinsics. These are placed at
|
||||
* top-level blocks to ensure correct behavior w.r.t. loops */
|
||||
if (is_helper == NULL)
|
||||
is_helper = insert_is_helper(b, instr);
|
||||
is_helper = insert_is_helper(b, &intrin->instr);
|
||||
nir_def_rewrite_uses(&intrin->def, is_helper);
|
||||
nir_instr_remove_v(instr);
|
||||
nir_instr_remove(&intrin->instr);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -161,23 +150,21 @@ nir_lower_discard_or_demote(nir_shader *shader,
|
||||
/* If we need correct derivatives, convert discard to demote only when
|
||||
* derivatives are actually used.
|
||||
*/
|
||||
progress = nir_shader_instructions_pass(shader,
|
||||
nir_lower_discard_to_demote_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance |
|
||||
nir_metadata_live_defs |
|
||||
nir_metadata_instr_index,
|
||||
NULL);
|
||||
progress = nir_shader_intrinsics_pass(shader, lower_discard_to_demote,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance |
|
||||
nir_metadata_live_defs |
|
||||
nir_metadata_instr_index,
|
||||
NULL);
|
||||
shader->info.fs.uses_demote = true;
|
||||
} else if (!shader->info.fs.needs_quad_helper_invocations &&
|
||||
!shader->info.fs.needs_all_helper_invocations &&
|
||||
shader->info.fs.uses_demote) {
|
||||
/* If we don't need any helper invocations, convert demote to discard. */
|
||||
progress = nir_shader_instructions_pass(shader,
|
||||
nir_lower_demote_to_discard_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
NULL);
|
||||
progress = nir_shader_intrinsics_pass(shader, lower_demote_to_discard,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
NULL);
|
||||
shader->info.fs.uses_demote = false;
|
||||
} else if (shader->info.fs.uses_demote &&
|
||||
BITSET_TEST(shader->info.system_values_read,
|
||||
@@ -185,11 +172,11 @@ nir_lower_discard_or_demote(nir_shader *shader,
|
||||
/* load_helper needs to preserve the value (whether an invocation is
|
||||
* a helper lane) from the beginning of the shader. */
|
||||
nir_def *is_helper = NULL;
|
||||
progress = nir_shader_instructions_pass(shader,
|
||||
nir_lower_load_helper_to_is_helper,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&is_helper);
|
||||
progress = nir_shader_intrinsics_pass(shader,
|
||||
lower_load_helper_to_is_helper,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&is_helper);
|
||||
BITSET_CLEAR(shader->info.system_values_read,
|
||||
nir_system_value_from_intrinsic(nir_intrinsic_load_helper_invocation));
|
||||
}
|
||||
|
@@ -48,12 +48,8 @@
|
||||
*/
|
||||
|
||||
static bool
|
||||
lower_fragcolor_instr(nir_builder *b, nir_instr *intr, void *data)
|
||||
lower_fragcolor_intrin(nir_builder *b, nir_intrinsic_instr *instr, void *data)
|
||||
{
|
||||
if (intr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *instr = nir_instr_as_intrinsic(intr);
|
||||
unsigned *max_draw_buffers = data;
|
||||
|
||||
nir_variable *out;
|
||||
@@ -99,6 +95,8 @@ nir_lower_fragcolor(nir_shader *shader, unsigned max_draw_buffers)
|
||||
if (shader->info.stage != MESA_SHADER_FRAGMENT)
|
||||
return false;
|
||||
|
||||
return nir_shader_instructions_pass(shader, lower_fragcolor_instr,
|
||||
nir_metadata_block_index | nir_metadata_dominance, &max_draw_buffers);
|
||||
return nir_shader_intrinsics_pass(shader, lower_fragcolor_intrin,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&max_draw_buffers);
|
||||
}
|
||||
|
@@ -160,13 +160,9 @@ lower_image_samples_identical_to_fragment_mask_load(nir_builder *b, nir_intrinsi
|
||||
}
|
||||
|
||||
static bool
|
||||
lower_image_instr(nir_builder *b, nir_instr *instr, void *state)
|
||||
lower_image_intrin(nir_builder *b, nir_intrinsic_instr *intrin, void *state)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
const nir_lower_image_options *options = state;
|
||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||
|
||||
switch (intrin->intrinsic) {
|
||||
case nir_intrinsic_image_size:
|
||||
@@ -220,8 +216,8 @@ lower_image_instr(nir_builder *b, nir_instr *instr, void *state)
|
||||
bool
|
||||
nir_lower_image(nir_shader *nir, const nir_lower_image_options *options)
|
||||
{
|
||||
return nir_shader_instructions_pass(nir, lower_image_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
(void *)options);
|
||||
return nir_shader_intrinsics_pass(nir, lower_image_intrin,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
(void *)options);
|
||||
}
|
||||
|
@@ -15,12 +15,8 @@
|
||||
*/
|
||||
|
||||
static bool
|
||||
lower(nir_builder *b, nir_instr *instr, UNUSED void *_)
|
||||
lower(nir_builder *b, nir_intrinsic_instr *intr, UNUSED void *_)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
nir_intrinsic_op address_op;
|
||||
bool swap;
|
||||
|
||||
@@ -40,7 +36,7 @@ lower(nir_builder *b, nir_instr *instr, UNUSED void *_)
|
||||
}
|
||||
#undef CASE
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
nir_atomic_op atomic_op = nir_intrinsic_atomic_op(intr);
|
||||
enum pipe_format format = nir_intrinsic_format(intr);
|
||||
unsigned bit_size = intr->def.bit_size;
|
||||
@@ -94,15 +90,15 @@ lower(nir_builder *b, nir_instr *instr, UNUSED void *_)
|
||||
* explicitly because it has side effects so is not DCE'd.
|
||||
*/
|
||||
nir_def_rewrite_uses(&intr->def, global);
|
||||
nir_instr_remove(instr);
|
||||
nir_instr_remove(&intr->instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nir_lower_image_atomics_to_global(nir_shader *shader)
|
||||
{
|
||||
return nir_shader_instructions_pass(shader, lower,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
NULL);
|
||||
return nir_shader_intrinsics_pass(shader, lower,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
NULL);
|
||||
}
|
||||
|
@@ -40,32 +40,29 @@
|
||||
*/
|
||||
|
||||
static bool
|
||||
nir_lower_load_and_store_is_helper(nir_builder *b, nir_instr *instr, void *data)
|
||||
lower_load_and_store_is_helper(nir_builder *b,
|
||||
nir_intrinsic_instr *intrin, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||
nir_deref_instr *is_helper_deref = (nir_deref_instr *)data;
|
||||
|
||||
switch (intrin->intrinsic) {
|
||||
case nir_intrinsic_demote: {
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&intrin->instr);
|
||||
nir_store_deref(b, is_helper_deref, nir_imm_true(b), 1);
|
||||
return true;
|
||||
}
|
||||
case nir_intrinsic_demote_if: {
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&intrin->instr);
|
||||
nir_def *current_is_helper = nir_load_deref(b, is_helper_deref);
|
||||
nir_def *updated_is_helper = nir_ior(b, current_is_helper, intrin->src[0].ssa);
|
||||
nir_store_deref(b, is_helper_deref, updated_is_helper, 1);
|
||||
return true;
|
||||
}
|
||||
case nir_intrinsic_is_helper_invocation: {
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&intrin->instr);
|
||||
nir_def *is_helper = nir_load_deref(b, is_helper_deref);
|
||||
nir_def_rewrite_uses(&intrin->def, is_helper);
|
||||
nir_instr_remove_v(instr);
|
||||
nir_instr_remove(&intrin->instr);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
@@ -114,9 +111,8 @@ nir_lower_is_helper_invocation(nir_shader *shader)
|
||||
nir_deref_instr *is_helper_deref = nir_build_deref_var(&b, is_helper);
|
||||
nir_store_deref(&b, is_helper_deref, started_as_helper, 1);
|
||||
|
||||
return nir_shader_instructions_pass(shader,
|
||||
nir_lower_load_and_store_is_helper,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
is_helper_deref);
|
||||
return nir_shader_intrinsics_pass(shader, lower_load_and_store_is_helper,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
is_helper_deref);
|
||||
}
|
||||
|
@@ -33,14 +33,10 @@
|
||||
* valid range.
|
||||
*/
|
||||
static bool
|
||||
lower_point_size_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
lower_point_size_intrin(nir_builder *b, nir_intrinsic_instr *intr, void *data)
|
||||
{
|
||||
float *minmax = (float *)data;
|
||||
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic != nir_intrinsic_store_deref)
|
||||
return false;
|
||||
|
||||
@@ -49,7 +45,7 @@ lower_point_size_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
if (var->data.location != VARYING_SLOT_PSIZ)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
|
||||
assert(intr->src[1].ssa->num_components == 1);
|
||||
nir_def *psiz = intr->src[1].ssa;
|
||||
@@ -79,8 +75,8 @@ nir_lower_point_size(nir_shader *s, float min, float max)
|
||||
assert(min <= 0.0f || max <= 0.0f || min <= max);
|
||||
|
||||
float minmax[] = { min, max };
|
||||
return nir_shader_instructions_pass(s, lower_point_size_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
minmax);
|
||||
return nir_shader_intrinsics_pass(s, lower_point_size_intrin,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
minmax);
|
||||
}
|
||||
|
@@ -28,13 +28,9 @@
|
||||
#include "util/u_math.h"
|
||||
|
||||
static bool
|
||||
lower_printf_instr(nir_builder *b, nir_instr *instr, void *_options)
|
||||
lower_printf_intrin(nir_builder *b, nir_intrinsic_instr *prntf, void *_options)
|
||||
{
|
||||
const nir_lower_printf_options *options = _options;
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *prntf = nir_instr_as_intrinsic(instr);
|
||||
if (prntf->intrinsic != nir_intrinsic_printf)
|
||||
return false;
|
||||
|
||||
@@ -136,7 +132,7 @@ lower_printf_instr(nir_builder *b, nir_instr *instr, void *_options)
|
||||
bool
|
||||
nir_lower_printf(nir_shader *nir, const nir_lower_printf_options *options)
|
||||
{
|
||||
return nir_shader_instructions_pass(nir, lower_printf_instr,
|
||||
nir_metadata_none,
|
||||
(void *)options);
|
||||
return nir_shader_intrinsics_pass(nir, lower_printf_intrin,
|
||||
nir_metadata_none,
|
||||
(void *)options);
|
||||
}
|
||||
|
Reference in New Issue
Block a user