pan/mdg: Use nir_shader_instructions_pass for nir_lod_errata
Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6718>
This commit is contained in:
@@ -32,12 +32,18 @@ bool midgard_nir_lod_errata(nir_shader *shader);
|
||||
* constants in as system values and perform the bias/clamp in the shader.
|
||||
*/
|
||||
|
||||
static void
|
||||
mir_lod_errata_body(nir_builder *b, nir_tex_instr *tex)
|
||||
static bool
|
||||
nir_lod_errata_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
b->cursor = nir_before_instr(instr);
|
||||
|
||||
/* The errata only applies to textureLod ("TEXGRD") */
|
||||
if (tex->op != nir_texop_txl)
|
||||
return;
|
||||
return false;
|
||||
|
||||
/* Let's grab the sampler parameters */
|
||||
nir_intrinsic_instr *l = nir_intrinsic_instr_create(b->shader,
|
||||
@@ -56,7 +62,7 @@ mir_lod_errata_body(nir_builder *b, nir_tex_instr *tex)
|
||||
nir_ssa_def *min_lod = nir_channel(b, params, 0);
|
||||
nir_ssa_def *max_lod = nir_channel(b, params, 1);
|
||||
nir_ssa_def *lod_bias = nir_channel(b, params, 2);
|
||||
|
||||
|
||||
/* Rewrite the LOD with bias/clamps. Order sensitive. */
|
||||
for (unsigned i = 0; i < tex->num_srcs; i++) {
|
||||
if (tex->src[i].src_type != nir_tex_src_lod)
|
||||
@@ -71,29 +77,15 @@ mir_lod_errata_body(nir_builder *b, nir_tex_instr *tex)
|
||||
nir_instr_rewrite_src(&tex->instr, &tex->src[i].src,
|
||||
nir_src_for_ssa(clamped));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
midgard_nir_lod_errata(nir_shader *shader)
|
||||
{
|
||||
nir_foreach_function(function, shader) {
|
||||
if (!function->impl) continue;
|
||||
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, function->impl);
|
||||
|
||||
nir_foreach_block(block, function->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type != nir_instr_type_tex) continue;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
b.cursor = nir_before_instr(instr);
|
||||
mir_lod_errata_body(&b, tex);
|
||||
}
|
||||
}
|
||||
|
||||
nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance);
|
||||
|
||||
}
|
||||
return true;
|
||||
return nir_shader_instructions_pass(shader,
|
||||
nir_lod_errata_instr,
|
||||
nir_metadata_block_index | nir_metadata_dominance,
|
||||
NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user