• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2023 Igalia S.L.
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "etnaviv_nir.h"
7 
8 static bool
lower_txs(nir_builder * b,nir_instr * instr,UNUSED void * data)9 lower_txs(nir_builder *b, nir_instr *instr, UNUSED void *data)
10 {
11    if (instr->type != nir_instr_type_tex)
12       return false;
13 
14    nir_tex_instr *tex = nir_instr_as_tex(instr);
15 
16    if (tex->op != nir_texop_txs)
17       return false;
18 
19    b->cursor = nir_instr_remove(instr);
20 
21    nir_def *idx = nir_imm_int(b, tex->texture_index);
22    nir_def *sizes = nir_load_texture_size_etna(b, 32, idx);
23 
24    nir_def_rewrite_uses(&tex->def, sizes);
25 
26    return true;
27 }
28 
29 bool
etna_nir_lower_texture(nir_shader * s,struct etna_shader_key * key)30 etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key)
31 {
32    bool progress = false;
33 
34    nir_lower_tex_options lower_tex_options = {
35       .lower_txp = ~0u,
36       .lower_txs_lod = true,
37       .lower_invalid_implicit_lod = true,
38    };
39 
40    NIR_PASS(progress, s, nir_lower_tex, &lower_tex_options);
41 
42    if (key->has_sample_tex_compare)
43       NIR_PASS(progress, s, nir_lower_tex_shadow, key->num_texture_states,
44                                                   key->tex_compare_func,
45                                                   key->tex_swizzle,
46                                                   true);
47 
48    NIR_PASS(progress, s, nir_shader_instructions_pass, lower_txs,
49          nir_metadata_control_flow, NULL);
50 
51    return progress;
52 }
53