mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-02 18:48:28 +02:00
treewide: use nir_shader_tex_pass
Adapted the Coccinelle rules from the nir_shader_intrinsics_pass commit a while
ago, which was buggy then and buggy now, so then I fixed stuff up manually
(including formatting).
Via Coccinelle patch:
@def@
typedef bool;
typedef nir_builder;
typedef nir_instr;
typedef nir_def;
identifier fn, instr, intr, x, builder, data;
@@
static fn(nir_builder* builder,
-nir_instr *instr,
+nir_tex_instr *intr,
...)
{
(
- if (instr->type != nir_instr_type_tex)
- return false;
- nir_tex_instr *intr = nir_instr_as_tex(instr);
|
- nir_tex_instr *intr = nir_instr_as_tex(instr);
- if (instr->type != nir_instr_type_tex)
- return false;
)
<...
(
-instr->x
+intr->instr.x
|
-instr
+&intr->instr
)
...>
}
@pass depends on def@
identifier def.fn;
expression shader, progress;
@@
(
-nir_shader_instructions_pass(shader, fn,
+nir_shader_tex_pass(shader, fn,
...)
|
-NIR_PASS_V(shader, nir_shader_instructions_pass, fn,
+NIR_PASS_V(shader, nir_shader_tex_pass, fn,
...)
|
-NIR_PASS(progress, shader, nir_shader_instructions_pass, fn,
+NIR_PASS(progress, shader, nir_shader_tex_pass, fn,
...)
)
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> [v3d]
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33672>
This commit is contained in:
parent
940e87f225
commit
2504e7951b
9 changed files with 46 additions and 98 deletions
|
|
@ -462,12 +462,8 @@ has_custom_border(nir_builder *b, nir_tex_instr *tex)
|
|||
}
|
||||
|
||||
static bool
|
||||
lower(nir_builder *b, nir_instr *instr, UNUSED void *_data)
|
||||
lower(nir_builder *b, nir_tex_instr *tex, UNUSED void *_data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
if (!nir_tex_instr_need_sampler(tex) || nir_tex_instr_is_query(tex))
|
||||
return false;
|
||||
|
||||
|
|
@ -533,7 +529,7 @@ lower(nir_builder *b, nir_instr *instr, UNUSED void *_data)
|
|||
static bool
|
||||
agx_nir_lower_custom_border(nir_shader *nir)
|
||||
{
|
||||
return nir_shader_instructions_pass(nir, lower, nir_metadata_none, NULL);
|
||||
return nir_shader_tex_pass(nir, lower, nir_metadata_none, NULL);
|
||||
}
|
||||
|
||||
static nir_def *
|
||||
|
|
@ -545,12 +541,8 @@ query_min_lod(nir_builder *b, nir_tex_instr *tex, bool int_coords)
|
|||
}
|
||||
|
||||
static bool
|
||||
lower_min_lod(nir_builder *b, nir_instr *instr, UNUSED void *_data)
|
||||
lower_min_lod(nir_builder *b, nir_tex_instr *tex, UNUSED void *_data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
if (nir_tex_instr_is_query(tex))
|
||||
return false;
|
||||
|
||||
|
|
@ -608,8 +600,7 @@ lower_min_lod(nir_builder *b, nir_instr *instr, UNUSED void *_data)
|
|||
static bool
|
||||
agx_nir_lower_image_view_min_lod(nir_shader *nir)
|
||||
{
|
||||
return nir_shader_instructions_pass(nir, lower_min_lod, nir_metadata_none,
|
||||
NULL);
|
||||
return nir_shader_tex_pass(nir, lower_min_lod, nir_metadata_none, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -639,12 +630,8 @@ lower_viewport_fs(nir_builder *b, nir_intrinsic_instr *intr, UNUSED void *data)
|
|||
}
|
||||
|
||||
static bool
|
||||
lower_subpass_dim(nir_builder *b, nir_instr *instr, UNUSED void *_data)
|
||||
lower_subpass_dim(nir_builder *b, nir_tex_instr *tex, UNUSED void *_data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
if (tex->sampler_dim == GLSL_SAMPLER_DIM_SUBPASS)
|
||||
tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
|
||||
else if (tex->sampler_dim == GLSL_SAMPLER_DIM_SUBPASS_MS)
|
||||
|
|
@ -689,8 +676,8 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir,
|
|||
.use_view_id_for_layer = is_multiview,
|
||||
});
|
||||
|
||||
NIR_PASS(_, nir, nir_shader_instructions_pass, lower_subpass_dim,
|
||||
nir_metadata_all, NULL);
|
||||
NIR_PASS(_, nir, nir_shader_tex_pass, lower_subpass_dim, nir_metadata_all,
|
||||
NULL);
|
||||
NIR_PASS(_, nir, nir_lower_wpos_center);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,23 +29,18 @@
|
|||
* magnitude component is -1.0 or 1.0.
|
||||
*/
|
||||
static bool
|
||||
normalize_cubemap_coords(nir_builder *b, nir_instr *instr, void *data)
|
||||
normalize_cubemap_coords(nir_builder *b, nir_tex_instr *tex, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
if (tex->sampler_dim != GLSL_SAMPLER_DIM_CUBE)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
|
||||
int idx = nir_tex_instr_src_index(tex, nir_tex_src_coord);
|
||||
if (idx < 0)
|
||||
return false;
|
||||
|
||||
nir_def *orig_coord =
|
||||
tex->src[idx].src.ssa;
|
||||
nir_def *orig_coord = tex->src[idx].src.ssa;
|
||||
assert(orig_coord->num_components >= 3);
|
||||
|
||||
nir_def *orig_xyz = nir_trim_vector(b, orig_coord, 3);
|
||||
|
|
@ -67,7 +62,6 @@ normalize_cubemap_coords(nir_builder *b, nir_instr *instr, void *data)
|
|||
bool
|
||||
nir_normalize_cubemap_coords(nir_shader *shader)
|
||||
{
|
||||
return nir_shader_instructions_pass(shader, normalize_cubemap_coords,
|
||||
nir_metadata_control_flow,
|
||||
NULL);
|
||||
return nir_shader_tex_pass(shader, normalize_cubemap_coords,
|
||||
nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3622,17 +3622,12 @@ nir_to_tgsi_lower_tex_instr_arg(nir_builder *b,
|
|||
* manage it on our own, and may lead to more vectorization.
|
||||
*/
|
||||
static bool
|
||||
nir_to_tgsi_lower_tex_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
nir_to_tgsi_lower_tex_instr(nir_builder *b, nir_tex_instr *tex, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
|
||||
if (nir_tex_instr_src_index(tex, nir_tex_src_coord) < 0)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
|
||||
struct ntt_lower_tex_state s = {0};
|
||||
|
||||
|
|
@ -3676,10 +3671,8 @@ nir_to_tgsi_lower_tex_instr(nir_builder *b, nir_instr *instr, void *data)
|
|||
static bool
|
||||
nir_to_tgsi_lower_tex(nir_shader *s)
|
||||
{
|
||||
return nir_shader_instructions_pass(s,
|
||||
nir_to_tgsi_lower_tex_instr,
|
||||
nir_metadata_control_flow,
|
||||
NULL);
|
||||
return nir_shader_tex_pass(s, nir_to_tgsi_lower_tex_instr,
|
||||
nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -1850,17 +1850,12 @@ nir_to_rc_lower_tex_instr_arg(nir_builder *b, nir_tex_instr *instr, nir_tex_src_
|
|||
* manage it on our own, and may lead to more vectorization.
|
||||
*/
|
||||
static bool
|
||||
nir_to_rc_lower_tex_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
nir_to_rc_lower_tex_instr(nir_builder *b, nir_tex_instr *tex, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
|
||||
if (nir_tex_instr_src_index(tex, nir_tex_src_coord) < 0)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
|
||||
struct ntr_lower_tex_state s = {0};
|
||||
|
||||
|
|
@ -1902,8 +1897,8 @@ nir_to_rc_lower_tex_instr(nir_builder *b, nir_instr *instr, void *data)
|
|||
static bool
|
||||
nir_to_rc_lower_tex(nir_shader *s)
|
||||
{
|
||||
return nir_shader_instructions_pass(s, nir_to_rc_lower_tex_instr, nir_metadata_control_flow,
|
||||
NULL);
|
||||
return nir_shader_tex_pass(s, nir_to_rc_lower_tex_instr,
|
||||
nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
||||
/* Lowers texture projectors if we can't do them as TGSI_OPCODE_TXP. */
|
||||
|
|
|
|||
|
|
@ -120,12 +120,8 @@ store_instr_depends_on_tex(nir_builder *b, nir_intrinsic_instr *intrin,
|
|||
|
||||
|
||||
static bool
|
||||
replace_tex_by_imm(nir_builder *b, nir_instr *instr, void *state)
|
||||
replace_tex_by_imm(nir_builder *b, nir_tex_instr *tex, void *state)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
struct replace_param *p = (struct replace_param*) state;
|
||||
|
||||
if (get_tex_unit(tex) != *(p->texunit))
|
||||
|
|
@ -161,8 +157,8 @@ si_nir_is_output_const_if_tex_is_const(nir_shader *shader, float *in, float *out
|
|||
assert(*p.texunit != -1);
|
||||
|
||||
/* Replace nir_tex_instr using texunit by vec4(v) */
|
||||
nir_shader_instructions_pass(shader, replace_tex_by_imm,
|
||||
nir_metadata_control_flow, &p);
|
||||
nir_shader_tex_pass(shader, replace_tex_by_imm,
|
||||
nir_metadata_control_flow, &p);
|
||||
|
||||
/* Optimize the cloned shader */
|
||||
bool progress;
|
||||
|
|
|
|||
|
|
@ -2132,16 +2132,13 @@ bool si_should_clear_lds(struct si_screen *sscreen, const struct nir_shader *sha
|
|||
shader->info.shared_size > 0 && sscreen->options.clear_lds;
|
||||
}
|
||||
|
||||
static bool clamp_shadow_comparison_value(nir_builder *b, nir_instr *instr, void *state)
|
||||
static bool clamp_shadow_comparison_value(nir_builder *b, nir_tex_instr *tex,
|
||||
void *state)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
if (!tex->is_shadow)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
|
||||
int samp_index = nir_tex_instr_src_index(tex, nir_tex_src_sampler_handle);
|
||||
int comp_index = nir_tex_instr_src_index(tex, nir_tex_src_comparator);
|
||||
|
|
@ -2176,9 +2173,8 @@ static bool si_nir_clamp_shadow_comparison_value(nir_shader *nir)
|
|||
* Z24 anymore. Do it manually here for GFX8-9; GFX10 has
|
||||
* an explicitly clamped 32-bit float format.
|
||||
*/
|
||||
return nir_shader_instructions_pass(nir, clamp_shadow_comparison_value,
|
||||
nir_metadata_control_flow,
|
||||
NULL);
|
||||
return nir_shader_tex_pass(nir, clamp_shadow_comparison_value,
|
||||
nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -307,12 +307,8 @@ lower_uniform_offset_to_bytes_cb(nir_builder *b, nir_intrinsic_instr *intr,
|
|||
}
|
||||
|
||||
static bool
|
||||
lower_textures_cb(nir_builder *b, nir_instr *instr, void *_state)
|
||||
lower_textures_cb(nir_builder *b, nir_tex_instr *tex, void *_state)
|
||||
{
|
||||
if (instr->type != nir_instr_type_tex)
|
||||
return false;
|
||||
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
if (nir_tex_instr_need_sampler(tex))
|
||||
return false;
|
||||
|
||||
|
|
@ -334,8 +330,8 @@ v3d_nir_lower_uniform_offset_to_bytes(nir_shader *s)
|
|||
static bool
|
||||
v3d_nir_lower_textures(nir_shader *s)
|
||||
{
|
||||
return nir_shader_instructions_pass(s, lower_textures_cb,
|
||||
nir_metadata_control_flow, NULL);
|
||||
return nir_shader_tex_pass(s, lower_textures_cb,
|
||||
nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
|
|
|||
|
|
@ -1666,15 +1666,12 @@ lower_fbfetch(nir_shader *shader, nir_variable **fbfetch, bool ms)
|
|||
* - res = (0, 0, 0, 1)
|
||||
*/
|
||||
static bool
|
||||
lower_txf_lod_robustness_instr(nir_builder *b, nir_instr *in, void *data)
|
||||
lower_txf_lod_robustness_instr(nir_builder *b, nir_tex_instr *txf, void *data)
|
||||
{
|
||||
if (in->type != nir_instr_type_tex)
|
||||
return false;
|
||||
nir_tex_instr *txf = nir_instr_as_tex(in);
|
||||
if (txf->op != nir_texop_txf)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(in);
|
||||
b->cursor = nir_before_instr(&txf->instr);
|
||||
int lod_idx = nir_tex_instr_src_index(txf, nir_tex_src_lod);
|
||||
assert(lod_idx >= 0);
|
||||
nir_src lod_src = txf->src[lod_idx].src;
|
||||
|
|
@ -1708,7 +1705,7 @@ lower_txf_lod_robustness_instr(nir_builder *b, nir_instr *in, void *data)
|
|||
nir_builder_instr_insert(b, &levels->instr);
|
||||
|
||||
nir_if *lod_oob_if = nir_push_if(b, nir_ilt(b, lod, &levels->def));
|
||||
nir_tex_instr *new_txf = nir_instr_as_tex(nir_instr_clone(b->shader, in));
|
||||
nir_tex_instr *new_txf = nir_instr_as_tex(nir_instr_clone(b->shader, &txf->instr));
|
||||
nir_builder_instr_insert(b, &new_txf->instr);
|
||||
|
||||
nir_if *lod_oob_else = nir_push_else(b, lod_oob_if);
|
||||
|
|
@ -1722,7 +1719,7 @@ lower_txf_lod_robustness_instr(nir_builder *b, nir_instr *in, void *data)
|
|||
nir_def *robust_txf = nir_if_phi(b, &new_txf->def, oob_val);
|
||||
|
||||
nir_def_rewrite_uses(&txf->def, robust_txf);
|
||||
nir_instr_remove_v(in);
|
||||
nir_instr_remove_v(&txf->instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1732,7 +1729,8 @@ lower_txf_lod_robustness_instr(nir_builder *b, nir_instr *in, void *data)
|
|||
static bool
|
||||
lower_txf_lod_robustness(nir_shader *shader)
|
||||
{
|
||||
return nir_shader_instructions_pass(shader, lower_txf_lod_robustness_instr, nir_metadata_none, NULL);
|
||||
return nir_shader_tex_pass(shader, lower_txf_lod_robustness_instr,
|
||||
nir_metadata_none, NULL);
|
||||
}
|
||||
|
||||
/* check for a genuine gl_PointSize output vs one from nir_lower_point_size_mov */
|
||||
|
|
@ -4784,11 +4782,9 @@ scan_nir(struct zink_screen *screen, nir_shader *shader, struct zink_shader *zs)
|
|||
}
|
||||
|
||||
static bool
|
||||
match_tex_dests_instr(nir_builder *b, nir_instr *in, void *data, bool pre)
|
||||
match_tex_dests_instr(nir_builder *b, nir_tex_instr *tex, void *data,
|
||||
bool pre)
|
||||
{
|
||||
if (in->type != nir_instr_type_tex)
|
||||
return false;
|
||||
nir_tex_instr *tex = nir_instr_as_tex(in);
|
||||
if (tex->op == nir_texop_txs || tex->op == nir_texop_lod)
|
||||
return false;
|
||||
int handle = nir_tex_instr_src_index(tex, nir_tex_src_texture_handle);
|
||||
|
|
@ -4808,13 +4804,13 @@ match_tex_dests_instr(nir_builder *b, nir_instr *in, void *data, bool pre)
|
|||
}
|
||||
|
||||
static bool
|
||||
match_tex_dests_instr_pre(nir_builder *b, nir_instr *in, void *data)
|
||||
match_tex_dests_instr_pre(nir_builder *b, nir_tex_instr *in, void *data)
|
||||
{
|
||||
return match_tex_dests_instr(b, in, data, true);
|
||||
}
|
||||
|
||||
static bool
|
||||
match_tex_dests_instr_post(nir_builder *b, nir_instr *in, void *data)
|
||||
match_tex_dests_instr_post(nir_builder *b, nir_tex_instr *in, void *data)
|
||||
{
|
||||
return match_tex_dests_instr(b, in, data, false);
|
||||
}
|
||||
|
|
@ -4822,7 +4818,7 @@ match_tex_dests_instr_post(nir_builder *b, nir_instr *in, void *data)
|
|||
static bool
|
||||
match_tex_dests(nir_shader *shader, struct zink_shader *zs, bool pre_mangle)
|
||||
{
|
||||
return nir_shader_instructions_pass(shader, pre_mangle ? match_tex_dests_instr_pre : match_tex_dests_instr_post, nir_metadata_dominance, zs);
|
||||
return nir_shader_tex_pass(shader, pre_mangle ? match_tex_dests_instr_pre : match_tex_dests_instr_post, nir_metadata_dominance, zs);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
|||
|
|
@ -33,13 +33,9 @@ bool midgard_nir_lod_errata(nir_shader *shader);
|
|||
*/
|
||||
|
||||
static bool
|
||||
nir_lod_errata_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
nir_lod_errata_instr(nir_builder *b, nir_tex_instr *tex, 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);
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
|
||||
/* The errata only applies to textureLod ("TEXGRD") */
|
||||
if (tex->op != nir_texop_txl)
|
||||
|
|
@ -75,7 +71,6 @@ nir_lod_errata_instr(nir_builder *b, nir_instr *instr, void *data)
|
|||
bool
|
||||
midgard_nir_lod_errata(nir_shader *shader)
|
||||
{
|
||||
return nir_shader_instructions_pass(
|
||||
shader, nir_lod_errata_instr,
|
||||
nir_metadata_control_flow, NULL);
|
||||
return nir_shader_tex_pass(shader, nir_lod_errata_instr,
|
||||
nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue