• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 Rob Clark <robclark@freedesktop.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Rob Clark <robclark@freedesktop.org>
25  */
26 
27 #ifndef IR3_NIR_H_
28 #define IR3_NIR_H_
29 
30 #include "compiler/nir/nir.h"
31 #include "compiler/nir/nir_builder.h"
32 #include "compiler/shader_enums.h"
33 
34 #include "ir3_shader.h"
35 
36 BEGINC;
37 
38 bool ir3_nir_apply_trig_workarounds(nir_shader *shader);
39 bool ir3_nir_lower_imul(nir_shader *shader);
40 bool ir3_nir_lower_io_offsets(nir_shader *shader);
41 bool ir3_nir_lower_load_barycentric_at_sample(nir_shader *shader);
42 bool ir3_nir_lower_load_barycentric_at_offset(nir_shader *shader);
43 bool ir3_nir_lower_push_consts_to_preamble(nir_shader *nir,
44                                            struct ir3_shader_variant *v);
45 bool ir3_nir_lower_driver_params_to_ubo(nir_shader *nir,
46                                         struct ir3_shader_variant *v);
47 bool ir3_nir_move_varying_inputs(nir_shader *shader);
48 int ir3_nir_coord_offset(nir_def *ssa);
49 bool ir3_nir_lower_tex_prefetch(nir_shader *shader);
50 bool ir3_nir_lower_wide_load_store(nir_shader *shader);
51 bool ir3_nir_lower_layer_id(nir_shader *shader);
52 
53 void ir3_nir_lower_to_explicit_output(nir_shader *shader,
54                                       struct ir3_shader_variant *v,
55                                       unsigned topology);
56 void ir3_nir_lower_to_explicit_input(nir_shader *shader,
57                                      struct ir3_shader_variant *v);
58 void ir3_nir_lower_tess_ctrl(nir_shader *shader, struct ir3_shader_variant *v,
59                              unsigned topology);
60 void ir3_nir_lower_tess_eval(nir_shader *shader, struct ir3_shader_variant *v,
61                              unsigned topology);
62 void ir3_nir_lower_gs(nir_shader *shader);
63 
64 /*
65  * 64b related lowering:
66  */
67 bool ir3_nir_lower_64b_intrinsics(nir_shader *shader);
68 bool ir3_nir_lower_64b_undef(nir_shader *shader);
69 bool ir3_nir_lower_64b_global(nir_shader *shader);
70 bool ir3_nir_lower_64b_regs(nir_shader *shader);
71 
72 void ir3_optimize_loop(struct ir3_compiler *compiler, nir_shader *s);
73 void ir3_nir_lower_io_to_temporaries(nir_shader *s);
74 void ir3_finalize_nir(struct ir3_compiler *compiler, nir_shader *s);
75 void ir3_nir_post_finalize(struct ir3_shader *shader);
76 void ir3_nir_lower_variant(struct ir3_shader_variant *so, nir_shader *s);
77 
78 void ir3_setup_const_state(nir_shader *nir, struct ir3_shader_variant *v,
79                            struct ir3_const_state *const_state);
80 bool ir3_nir_lower_load_constant(nir_shader *nir, struct ir3_shader_variant *v);
81 void ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader_variant *v);
82 bool ir3_nir_lower_ubo_loads(nir_shader *nir, struct ir3_shader_variant *v);
83 bool ir3_nir_lower_const_global_loads(nir_shader *nir, struct ir3_shader_variant *v);
84 bool ir3_nir_fixup_load_uniform(nir_shader *nir);
85 bool ir3_nir_opt_preamble(nir_shader *nir, struct ir3_shader_variant *v);
86 bool ir3_nir_lower_preamble(nir_shader *nir, struct ir3_shader_variant *v);
87 
88 nir_def *ir3_nir_try_propagate_bit_shift(nir_builder *b,
89                                              nir_def *offset,
90                                              int32_t shift);
91 
92 bool ir3_nir_opt_subgroups(nir_shader *nir, struct ir3_shader_variant *v);
93 
94 nir_def *ir3_get_driver_ubo(nir_builder *b, struct ir3_driver_ubo *ubo);
95 nir_def *ir3_load_driver_ubo(nir_builder *b, unsigned components,
96                              struct ir3_driver_ubo *ubo,
97                              unsigned offset);
98 nir_def *ir3_load_driver_ubo_indirect(nir_builder *b, unsigned components,
99                                       struct ir3_driver_ubo *ubo,
100                                       unsigned base, nir_def *offset,
101                                       unsigned range);
102 
103 struct driver_param_info {
104    uint32_t offset;
105 };
106 
107 bool ir3_get_driver_param_info(const nir_shader *shader,
108                                nir_intrinsic_instr *intr,
109                                struct driver_param_info *param_info);
110 
111 static inline nir_intrinsic_instr *
ir3_bindless_resource(nir_src src)112 ir3_bindless_resource(nir_src src)
113 {
114    if (src.ssa->parent_instr->type != nir_instr_type_intrinsic)
115       return NULL;
116 
117    nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(src.ssa->parent_instr);
118    if (intrin->intrinsic != nir_intrinsic_bindless_resource_ir3)
119       return NULL;
120 
121    return intrin;
122 }
123 
124 static inline bool
is_intrinsic_store(nir_intrinsic_op op)125 is_intrinsic_store(nir_intrinsic_op op)
126 {
127    switch (op) {
128    case nir_intrinsic_store_output:
129    case nir_intrinsic_store_scratch:
130    case nir_intrinsic_store_ssbo:
131    case nir_intrinsic_store_shared:
132    case nir_intrinsic_store_global:
133    case nir_intrinsic_store_global_ir3:
134       return true;
135    default:
136       return false;
137    }
138 }
139 
140 static inline bool
is_intrinsic_load(nir_intrinsic_op op)141 is_intrinsic_load(nir_intrinsic_op op)
142 {
143    switch (op) {
144    case nir_intrinsic_load_input:
145    case nir_intrinsic_load_scratch:
146    case nir_intrinsic_load_uniform:
147    case nir_intrinsic_load_ssbo:
148    case nir_intrinsic_load_ubo:
149    case nir_intrinsic_load_shared:
150    case nir_intrinsic_load_global:
151    case nir_intrinsic_load_global_ir3:
152       return true;
153    default:
154       return false;
155    }
156 }
157 
158 ENDC;
159 
160 #endif /* IR3_NIR_H_ */
161