nir: use nir_shader_instructions_pass in nir_lower_interpolation
Changes: - nir_metadata_preserve(..., nir_metadata_block_index | nir_metadata_dominance) is called only when pass makes progress - nir_metadata_preserve(..., nir_metadata_all) is called when pass doesn't make progress Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12282>
This commit is contained in:

committed by
Marge Bot

parent
6e0bcc1c4d
commit
865d959090
@@ -35,19 +35,18 @@
|
|||||||
#include "nir_builder.h"
|
#include "nir_builder.h"
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
nir_lower_interpolation_block(nir_block *block, nir_builder *b,
|
nir_lower_interpolation_instr(nir_builder *b, nir_instr *instr, void *cb_data)
|
||||||
nir_lower_interpolation_options options)
|
|
||||||
{
|
{
|
||||||
bool progress = false;
|
nir_lower_interpolation_options options =
|
||||||
|
*(nir_lower_interpolation_options *)cb_data;
|
||||||
|
|
||||||
nir_foreach_instr_safe(instr, block) {
|
|
||||||
if (instr->type != nir_instr_type_intrinsic)
|
if (instr->type != nir_instr_type_intrinsic)
|
||||||
continue;
|
return false;
|
||||||
|
|
||||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||||
|
|
||||||
if (intr->intrinsic != nir_intrinsic_load_interpolated_input)
|
if (intr->intrinsic != nir_intrinsic_load_interpolated_input)
|
||||||
continue;
|
return false;
|
||||||
|
|
||||||
assert(intr->dest.is_ssa);
|
assert(intr->dest.is_ssa);
|
||||||
assert(intr->src[0].is_ssa);
|
assert(intr->src[0].is_ssa);
|
||||||
@@ -58,7 +57,7 @@ nir_lower_interpolation_block(nir_block *block, nir_builder *b,
|
|||||||
|
|
||||||
/* Leave VARYING_SLOT_POS alone */
|
/* Leave VARYING_SLOT_POS alone */
|
||||||
if (nir_intrinsic_base(intr) == VARYING_SLOT_POS)
|
if (nir_intrinsic_base(intr) == VARYING_SLOT_POS)
|
||||||
continue;
|
return false;
|
||||||
|
|
||||||
const enum glsl_interp_mode interp_mode =
|
const enum glsl_interp_mode interp_mode =
|
||||||
nir_intrinsic_interp_mode(bary_intrinsic);
|
nir_intrinsic_interp_mode(bary_intrinsic);
|
||||||
@@ -69,7 +68,7 @@ nir_lower_interpolation_block(nir_block *block, nir_builder *b,
|
|||||||
/* Only lower for inputs that need interpolation */
|
/* Only lower for inputs that need interpolation */
|
||||||
if (interp_mode != INTERP_MODE_SMOOTH &&
|
if (interp_mode != INTERP_MODE_SMOOTH &&
|
||||||
interp_mode != INTERP_MODE_NOPERSPECTIVE)
|
interp_mode != INTERP_MODE_NOPERSPECTIVE)
|
||||||
continue;
|
return false;
|
||||||
|
|
||||||
nir_intrinsic_op op = bary_intrinsic->intrinsic;
|
nir_intrinsic_op op = bary_intrinsic->intrinsic;
|
||||||
|
|
||||||
@@ -77,25 +76,25 @@ nir_lower_interpolation_block(nir_block *block, nir_builder *b,
|
|||||||
case nir_intrinsic_load_barycentric_at_sample:
|
case nir_intrinsic_load_barycentric_at_sample:
|
||||||
if (options & nir_lower_interpolation_at_sample)
|
if (options & nir_lower_interpolation_at_sample)
|
||||||
break;
|
break;
|
||||||
continue;
|
return false;
|
||||||
case nir_intrinsic_load_barycentric_at_offset:
|
case nir_intrinsic_load_barycentric_at_offset:
|
||||||
if (options & nir_lower_interpolation_at_offset)
|
if (options & nir_lower_interpolation_at_offset)
|
||||||
break;
|
break;
|
||||||
continue;
|
return false;
|
||||||
case nir_intrinsic_load_barycentric_centroid:
|
case nir_intrinsic_load_barycentric_centroid:
|
||||||
if (options & nir_lower_interpolation_centroid)
|
if (options & nir_lower_interpolation_centroid)
|
||||||
break;
|
break;
|
||||||
continue;
|
return false;
|
||||||
case nir_intrinsic_load_barycentric_pixel:
|
case nir_intrinsic_load_barycentric_pixel:
|
||||||
if (options & nir_lower_interpolation_pixel)
|
if (options & nir_lower_interpolation_pixel)
|
||||||
break;
|
break;
|
||||||
continue;
|
return false;
|
||||||
case nir_intrinsic_load_barycentric_sample:
|
case nir_intrinsic_load_barycentric_sample:
|
||||||
if (options & nir_lower_interpolation_sample)
|
if (options & nir_lower_interpolation_sample)
|
||||||
break;
|
break;
|
||||||
continue;
|
return false;
|
||||||
default:
|
default:
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
b->cursor = nir_before_instr(instr);
|
b->cursor = nir_before_instr(instr);
|
||||||
@@ -123,38 +122,14 @@ nir_lower_interpolation_block(nir_block *block, nir_builder *b,
|
|||||||
nir_ssa_def *vec = nir_vec(b, comps, intr->num_components);
|
nir_ssa_def *vec = nir_vec(b, comps, intr->num_components);
|
||||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, vec);
|
nir_ssa_def_rewrite_uses(&intr->dest.ssa, vec);
|
||||||
|
|
||||||
progress = true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
nir_lower_interpolation_impl(nir_function_impl *impl,
|
|
||||||
nir_lower_interpolation_options options)
|
|
||||||
{
|
|
||||||
bool progress = false;
|
|
||||||
nir_builder builder;
|
|
||||||
nir_builder_init(&builder, impl);
|
|
||||||
|
|
||||||
nir_foreach_block(block, impl) {
|
|
||||||
progress |= nir_lower_interpolation_block(block, &builder, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
nir_metadata_preserve(impl, nir_metadata_block_index |
|
|
||||||
nir_metadata_dominance);
|
|
||||||
return progress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nir_lower_interpolation(nir_shader *shader, nir_lower_interpolation_options options)
|
nir_lower_interpolation(nir_shader *shader, nir_lower_interpolation_options options)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
return nir_shader_instructions_pass(shader, nir_lower_interpolation_instr,
|
||||||
|
nir_metadata_block_index |
|
||||||
nir_foreach_function(function, shader) {
|
nir_metadata_dominance,
|
||||||
if (function->impl)
|
&options);
|
||||||
progress |= nir_lower_interpolation_impl(function->impl, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return progress;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user