Debian Codegraph @

src/panfrost/compiler/pan_nir_lower_texel_buffer_index.c

raw
1 /*
2 * Copyright (C) 2025 Arm, Ltd.
3 *
4 * Derived from pan_nir_lower_image_index.c which is:
5 * Copyright (C) 2024 Collabora, Ltd.
6 *
7 * SPDX-License-Identifier: MIT
8 */
9
10 #include "compiler/nir/nir_builder.h"
11 #include "pan_nir.h"
12
13 static bool
14 lower_texel_buffer_fetch_intr(struct nir_builder *b, nir_tex_instr *tex,
15 void *data)
16 {
17 if (tex->op != nir_texop_txf || tex->sampler_dim != GLSL_SAMPLER_DIM_BUF)
18 return false;
19
20 b->cursor = nir_before_instr(&tex->instr);
21
22 nir_def *index = NULL;
23 unsigned index_src;
24 for (index_src = 0; index_src < tex->num_srcs; ++index_src) {
25 switch (tex->src[index_src].src_type) {
26 case nir_tex_src_texture_offset:
27 /* This should always be 0 as lower_index_to_offset is expected to be
28 * set */
29 assert(tex->texture_index == 0);
30 index = tex->src[index_src].src.ssa;
31 break;
32 default:
33 continue;
34 }
35 }
36
37 unsigned attr_offset = *(unsigned *)data;
38 if (!index)
39 tex->texture_index += attr_offset;
40 else {
41 b->cursor = nir_before_instr(&tex->instr);
42 index = nir_iadd_imm(b, index, attr_offset);
43 nir_src_rewrite(&tex->src[index_src].src, index);
44 }
45 return true;
46 }
47
48 bool
49 pan_nir_lower_texel_buffer_fetch_index(nir_shader *shader,
50 unsigned attrib_offset)
51 {
52 return nir_shader_tex_pass(shader, lower_texel_buffer_fetch_intr,
53 nir_metadata_control_flow, &attrib_offset);
54 }