From a43141f3b5411180b0ca3df55d004e72ae1626c2 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 6 Jun 2023 18:58:40 -0400 Subject: [PATCH] agx: Extract coords_for_buffer_texture helper The mapping of 1D -> 2D coordinates for indexing into buffer textures (lowered to fixed-width 2D images) will be shared between both texture load and image store code paths, so pull it out. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_nir_lower_texture.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/asahi/compiler/agx_nir_lower_texture.c b/src/asahi/compiler/agx_nir_lower_texture.c index 3dacd6d5efe..9420c35f239 100644 --- a/src/asahi/compiler/agx_nir_lower_texture.c +++ b/src/asahi/compiler/agx_nir_lower_texture.c @@ -209,6 +209,17 @@ load_rgb32(nir_builder *b, nir_tex_instr *tex, nir_ssa_def *coordinate) return nir_vec(b, swizzled, nir_tex_instr_dest_size(tex)); } +/* + * Given a 1D buffer texture coordinate, calculate the 2D coordinate vector that + * will be used to access the linear 2D texture bound to the buffer. + */ +static nir_ssa_def * +coords_for_buffer_texture(nir_builder *b, nir_ssa_def *coord) +{ + return nir_vec2(b, nir_iand_imm(b, coord, BITFIELD_MASK(10)), + nir_ushr_imm(b, coord, 10)); +} + /* * Buffer textures are lowered to 2D (1024xN) textures in the driver to access * more storage. When lowering, we need to fix up the coordinate accordingly. @@ -246,8 +257,8 @@ lower_buffer_texture(nir_builder *b, nir_tex_instr *tex) /* Otherwise, lower the texture instruction to read from 2D */ assert(coord->num_components == 1 && "buffer textures are 1D"); tex->sampler_dim = GLSL_SAMPLER_DIM_2D; - nir_ssa_def *coord2d = nir_vec2(b, nir_iand_imm(b, coord, BITFIELD_MASK(10)), - nir_ushr_imm(b, coord, 10)); + + nir_ssa_def *coord2d = coords_for_buffer_texture(b, coord); nir_instr_remove(&tex->instr); nir_builder_instr_insert(b, &tex->instr); nir_tex_instr_add_src(tex, nir_tex_src_backend1, nir_src_for_ssa(coord2d));