radeonsi: move sparse intrinsic lowering to a separate file, call it later

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38802>
This commit is contained in:
Marek Olšák 2025-11-21 23:17:03 -05:00 committed by Marge Bot
parent 2dc16ccb8f
commit 041cde6aa1
5 changed files with 40 additions and 32 deletions

View file

@ -51,6 +51,7 @@ files_libradeonsi = files(
'si_nir_kill_outputs.c',
'si_nir_lower_abi.c',
'si_nir_lower_color_inputs_to_sysvals.c',
'si_nir_lower_intrinsics_early.c',
'si_nir_lower_polygon_stipple.c',
'si_nir_lower_ps_color_inputs.c',
'si_nir_lower_resource.c',

View file

@ -0,0 +1,36 @@
/* Copyright 2025 Advanced Micro Devices, Inc.
* SPDX-License-Identifier: MIT
*/
#include "si_shader_internal.h"
#include "nir_builder.h"
static bool
lower_intrinsic_filter(const nir_instr *instr, const void *dummy)
{
return instr->type == nir_instr_type_intrinsic;
}
static nir_def *
lower_intrinsic_instr(nir_builder *b, nir_instr *instr, void *dummy)
{
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
case nir_intrinsic_is_sparse_texels_resident:
/* code==0 means sparse texels are resident */
return nir_ieq_imm(b, intrin->src[0].ssa, 0);
case nir_intrinsic_sparse_residency_code_and:
return nir_ior(b, intrin->src[0].ssa, intrin->src[1].ssa);
default:
return NULL;
}
}
bool si_nir_lower_intrinsics_early(nir_shader *nir)
{
return nir_shader_lower_instructions(nir,
lower_intrinsic_filter,
lower_intrinsic_instr,
NULL);
}

View file

@ -647,6 +647,8 @@ static void si_preprocess_nir(struct si_nir_shader_ctx *ctx)
NIR_PASS(progress, nir, ac_nir_lower_mesh_inputs_to_mem);
}
NIR_PASS(progress, nir, si_nir_lower_intrinsics_early);
if (mesa_shader_stage_is_compute(nir->info.stage)) {
/* gl_LocalInvocationIndex must be derived from gl_LocalInvocationID.xyz to make it correct
* with quad derivatives. Using gl_SubgroupID for that (which is what we do by default) is

View file

@ -125,6 +125,7 @@ nir_def *si_nir_load_internal_binding(struct si_screen *sscreen, nir_builder *b,
unsigned num_components);
bool si_nir_lower_abi(nir_shader *nir, struct si_shader *shader, struct si_shader_args *args);
bool si_nir_lower_color_inputs_to_sysvals(nir_shader *nir);
bool si_nir_lower_intrinsics_early(nir_shader *nir);
bool si_nir_lower_polygon_stipple(nir_shader *nir);
bool si_nir_lower_ps_color_inputs(nir_shader *nir, const union si_shader_key *key,
const struct si_shader_info *info);

View file

@ -107,36 +107,6 @@ void si_nir_late_opts(nir_shader *nir)
}
}
static bool
lower_intrinsic_filter(const nir_instr *instr, const void *dummy)
{
return instr->type == nir_instr_type_intrinsic;
}
static nir_def *
lower_intrinsic_instr(nir_builder *b, nir_instr *instr, void *dummy)
{
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
case nir_intrinsic_is_sparse_texels_resident:
/* code==0 means sparse texels are resident */
return nir_ieq_imm(b, intrin->src[0].ssa, 0);
case nir_intrinsic_sparse_residency_code_and:
return nir_ior(b, intrin->src[0].ssa, intrin->src[1].ssa);
default:
return NULL;
}
}
static bool si_lower_intrinsics(nir_shader *nir)
{
return nir_shader_lower_instructions(nir,
lower_intrinsic_filter,
lower_intrinsic_instr,
NULL);
}
/**
* Perform "lowering" operations on the NIR that are run once when the shader
* selector is created.
@ -169,8 +139,6 @@ static void si_lower_nir(struct si_screen *sscreen, struct nir_shader *nir)
};
NIR_PASS(_, nir, nir_lower_image, &lower_image_options);
NIR_PASS(_, nir, si_lower_intrinsics);
NIR_PASS(_, nir, ac_nir_lower_sin_cos);
/* Lower load constants to scalar and then clean up the mess */