asahi: use tex builders

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36050>
This commit is contained in:
Alyssa Rosenzweig 2025-07-10 10:14:37 -04:00 committed by Marge Bot
parent d1f5953965
commit a85219f89f
3 changed files with 25 additions and 51 deletions

View file

@ -398,24 +398,16 @@ static nir_def *
txs_for_image(nir_builder *b, nir_intrinsic_instr *intr,
unsigned num_components, unsigned bit_size, bool query_samples)
{
nir_tex_instr *tex = nir_tex_instr_create(b->shader, query_samples ? 1 : 2);
tex->op = query_samples ? nir_texop_texture_samples : nir_texop_txs;
tex->is_array = nir_intrinsic_image_array(intr);
tex->dest_type = nir_type_uint32;
tex->sampler_dim = nir_intrinsic_image_dim(intr);
enum glsl_sampler_dim dim = nir_intrinsic_image_dim(intr);
nir_def *lod = query_samples ? NULL : intr->src[1].ssa;
nir_texop op = query_samples ? nir_texop_texture_samples : nir_texop_txs;
tex->src[0] =
nir_tex_src_for_ssa(nir_tex_src_texture_handle, intr->src[0].ssa);
if (!query_samples)
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_lod, intr->src[1].ssa);
nir_def_init(&tex->instr, &tex->def, num_components, bit_size);
nir_builder_instr_insert(b, &tex->instr);
nir_def *res = &tex->def;
nir_def *res =
nir_build_tex(b, op, .texture_handle = intr->src[0].ssa, .lod = lod,
.dim = dim, .is_array = nir_intrinsic_image_array(intr));
/* Cube images are implemented as 2D arrays, so we need to divide here. */
if (tex->sampler_dim == GLSL_SAMPLER_DIM_CUBE && res->num_components > 2 &&
if (dim == GLSL_SAMPLER_DIM_CUBE && res->num_components > 2 &&
!query_samples) {
nir_def *divided = nir_udiv_imm(b, nir_channel(b, res, 2), 6);
res = nir_vector_insert_imm(b, res, divided, 2);

View file

@ -74,33 +74,24 @@ build_background_op(nir_builder *b, enum agx_bg_eot_op op, unsigned rt,
nir_load_layer_id(b));
}
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 2);
/* The type doesn't matter as long as it matches the store */
tex->dest_type = nir_type_uint32;
tex->sampler_dim = msaa ? GLSL_SAMPLER_DIM_MS : GLSL_SAMPLER_DIM_2D;
tex->is_array = layered;
tex->op = msaa ? nir_texop_txf_ms : nir_texop_txf;
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_coord, coord);
b->shader->info.fs.uses_sample_shading |= msaa;
/* Layer is necessarily already in-bounds so we do not want the compiler
* to clamp it, which would require reading the descriptor
*/
tex->backend_flags = AGX_TEXTURE_FLAG_NO_CLAMP;
nir_def *tex = nir_build_tex(
b, msaa ? nir_texop_txf_ms : nir_texop_txf, coord,
.ms_index = msaa ? nir_load_sample_id(b) : NULL,
.texture_index = rt * 2,
.dim = msaa ? GLSL_SAMPLER_DIM_MS : GLSL_SAMPLER_DIM_2D,
.is_array = layered,
if (msaa) {
tex->src[1] =
nir_tex_src_for_ssa(nir_tex_src_ms_index, nir_load_sample_id(b));
b->shader->info.fs.uses_sample_shading = true;
} else {
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_lod, nir_imm_int(b, 0));
}
/* The type doesn't matter as long as it matches the store */
.dest_type = nir_type_uint32,
tex->coord_components = layered ? 3 : 2;
tex->texture_index = rt * 2;
nir_def_init(&tex->instr, &tex->def, 4, 32);
nir_builder_instr_insert(b, &tex->instr);
/* Layer is necessarily already in-bounds so we do not want the
* compiler to clamp it, which would require reading the descriptor
*/
.backend_flags = AGX_TEXTURE_FLAG_NO_CLAMP);
return nir_trim_vector(b, &tex->def, nr);
return nir_trim_vector(b, tex, nr);
} else {
assert(op == AGX_BG_CLEAR);

View file

@ -124,19 +124,10 @@ asahi_blit_compute_shader(struct pipe_context *ctx, struct asahi_blit_key *key)
b, nir_pad_vector(b, coords_el_nd, 3), nir_u2f32(b, layer), 2);
}
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 1);
tex->dest_type = nir_type_uint32; /* irrelevant */
tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
tex->is_array = key->array;
tex->op = nir_texop_tex;
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_coord, coords_el_nd);
tex->backend_flags = AGX_TEXTURE_FLAG_NO_CLAMP;
tex->coord_components = coords_el_nd->num_components;
tex->texture_index = 0;
tex->sampler_index = 0;
nir_def_init(&tex->instr, &tex->def, 4, 32);
nir_builder_instr_insert(b, &tex->instr);
colour0 = &tex->def;
colour0 = nir_tex(b, coords_el_nd, .texture_index = 0, .sampler_index = 0,
.backend_flags = AGX_TEXTURE_FLAG_NO_CLAMP,
.dim = GLSL_SAMPLER_DIM_2D, .is_array = key->array,
.dest_type = nir_type_uint32);
}
nir_push_else(b, NULL);
{