1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Copyright © 2014 Connor Abbott
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker *
11*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker * Software.
14*61046927SAndroid Build Coastguard Worker *
15*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*61046927SAndroid Build Coastguard Worker * IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker *
23*61046927SAndroid Build Coastguard Worker * Authors:
24*61046927SAndroid Build Coastguard Worker * Connor Abbott ([email protected])
25*61046927SAndroid Build Coastguard Worker *
26*61046927SAndroid Build Coastguard Worker */
27*61046927SAndroid Build Coastguard Worker
28*61046927SAndroid Build Coastguard Worker #ifndef NIR_H
29*61046927SAndroid Build Coastguard Worker #define NIR_H
30*61046927SAndroid Build Coastguard Worker
31*61046927SAndroid Build Coastguard Worker #include <stdint.h>
32*61046927SAndroid Build Coastguard Worker #include "compiler/glsl_types.h"
33*61046927SAndroid Build Coastguard Worker #include "compiler/glsl/list.h"
34*61046927SAndroid Build Coastguard Worker #include "compiler/shader_enums.h"
35*61046927SAndroid Build Coastguard Worker #include "compiler/shader_info.h"
36*61046927SAndroid Build Coastguard Worker #include "util/bitscan.h"
37*61046927SAndroid Build Coastguard Worker #include "util/bitset.h"
38*61046927SAndroid Build Coastguard Worker #include "util/compiler.h"
39*61046927SAndroid Build Coastguard Worker #include "util/enum_operators.h"
40*61046927SAndroid Build Coastguard Worker #include "util/format/u_format.h"
41*61046927SAndroid Build Coastguard Worker #include "util/hash_table.h"
42*61046927SAndroid Build Coastguard Worker #include "util/list.h"
43*61046927SAndroid Build Coastguard Worker #include "util/log.h"
44*61046927SAndroid Build Coastguard Worker #include "util/macros.h"
45*61046927SAndroid Build Coastguard Worker #include "util/ralloc.h"
46*61046927SAndroid Build Coastguard Worker #include "util/set.h"
47*61046927SAndroid Build Coastguard Worker #include "util/u_printf.h"
48*61046927SAndroid Build Coastguard Worker #define XXH_INLINE_ALL
49*61046927SAndroid Build Coastguard Worker #include <stdio.h>
50*61046927SAndroid Build Coastguard Worker #include "util/xxhash.h"
51*61046927SAndroid Build Coastguard Worker
52*61046927SAndroid Build Coastguard Worker #ifndef NDEBUG
53*61046927SAndroid Build Coastguard Worker #include "util/u_debug.h"
54*61046927SAndroid Build Coastguard Worker #endif /* NDEBUG */
55*61046927SAndroid Build Coastguard Worker
56*61046927SAndroid Build Coastguard Worker #include "nir_opcodes.h"
57*61046927SAndroid Build Coastguard Worker
58*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
59*61046927SAndroid Build Coastguard Worker extern "C" {
60*61046927SAndroid Build Coastguard Worker #endif
61*61046927SAndroid Build Coastguard Worker
62*61046927SAndroid Build Coastguard Worker extern uint32_t nir_debug;
63*61046927SAndroid Build Coastguard Worker extern bool nir_debug_print_shader[MESA_SHADER_KERNEL + 1];
64*61046927SAndroid Build Coastguard Worker
65*61046927SAndroid Build Coastguard Worker #ifndef NDEBUG
66*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG(flag) unlikely(nir_debug &(NIR_DEBUG_##flag))
67*61046927SAndroid Build Coastguard Worker #else
68*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG(flag) false
69*61046927SAndroid Build Coastguard Worker #endif
70*61046927SAndroid Build Coastguard Worker
71*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_CLONE (1u << 0)
72*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_SERIALIZE (1u << 1)
73*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_NOVALIDATE (1u << 2)
74*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_VALIDATE_SSA_DOMINANCE (1u << 3)
75*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_TGSI (1u << 4)
76*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_VS (1u << 5)
77*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_TCS (1u << 6)
78*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_TES (1u << 7)
79*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_GS (1u << 8)
80*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_FS (1u << 9)
81*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_CS (1u << 10)
82*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_TS (1u << 11)
83*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_MS (1u << 12)
84*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_RGS (1u << 13)
85*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_AHS (1u << 14)
86*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_CHS (1u << 15)
87*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_MHS (1u << 16)
88*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_IS (1u << 17)
89*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_CBS (1u << 18)
90*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_KS (1u << 19)
91*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_NO_INLINE_CONSTS (1u << 20)
92*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_INTERNAL (1u << 21)
93*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT_PASS_FLAGS (1u << 22)
94*61046927SAndroid Build Coastguard Worker
95*61046927SAndroid Build Coastguard Worker #define NIR_DEBUG_PRINT (NIR_DEBUG_PRINT_VS | \
96*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_TCS | \
97*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_TES | \
98*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_GS | \
99*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_FS | \
100*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_CS | \
101*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_TS | \
102*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_MS | \
103*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_RGS | \
104*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_AHS | \
105*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_CHS | \
106*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_MHS | \
107*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_IS | \
108*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_CBS | \
109*61046927SAndroid Build Coastguard Worker NIR_DEBUG_PRINT_KS)
110*61046927SAndroid Build Coastguard Worker
111*61046927SAndroid Build Coastguard Worker #define NIR_FALSE 0u
112*61046927SAndroid Build Coastguard Worker #define NIR_TRUE (~0u)
113*61046927SAndroid Build Coastguard Worker #define NIR_MAX_VEC_COMPONENTS 16
114*61046927SAndroid Build Coastguard Worker #define NIR_MAX_MATRIX_COLUMNS 4
115*61046927SAndroid Build Coastguard Worker #define NIR_STREAM_PACKED (1 << 8)
116*61046927SAndroid Build Coastguard Worker typedef uint16_t nir_component_mask_t;
117*61046927SAndroid Build Coastguard Worker
118*61046927SAndroid Build Coastguard Worker static inline bool
nir_num_components_valid(unsigned num_components)119*61046927SAndroid Build Coastguard Worker nir_num_components_valid(unsigned num_components)
120*61046927SAndroid Build Coastguard Worker {
121*61046927SAndroid Build Coastguard Worker return (num_components >= 1 &&
122*61046927SAndroid Build Coastguard Worker num_components <= 5) ||
123*61046927SAndroid Build Coastguard Worker num_components == 8 ||
124*61046927SAndroid Build Coastguard Worker num_components == 16;
125*61046927SAndroid Build Coastguard Worker }
126*61046927SAndroid Build Coastguard Worker
127*61046927SAndroid Build Coastguard Worker static inline nir_component_mask_t
nir_component_mask(unsigned num_components)128*61046927SAndroid Build Coastguard Worker nir_component_mask(unsigned num_components)
129*61046927SAndroid Build Coastguard Worker {
130*61046927SAndroid Build Coastguard Worker assert(nir_num_components_valid(num_components));
131*61046927SAndroid Build Coastguard Worker return (1u << num_components) - 1;
132*61046927SAndroid Build Coastguard Worker }
133*61046927SAndroid Build Coastguard Worker
134*61046927SAndroid Build Coastguard Worker void
135*61046927SAndroid Build Coastguard Worker nir_process_debug_variable(void);
136*61046927SAndroid Build Coastguard Worker
137*61046927SAndroid Build Coastguard Worker bool nir_component_mask_can_reinterpret(nir_component_mask_t mask,
138*61046927SAndroid Build Coastguard Worker unsigned old_bit_size,
139*61046927SAndroid Build Coastguard Worker unsigned new_bit_size);
140*61046927SAndroid Build Coastguard Worker nir_component_mask_t
141*61046927SAndroid Build Coastguard Worker nir_component_mask_reinterpret(nir_component_mask_t mask,
142*61046927SAndroid Build Coastguard Worker unsigned old_bit_size,
143*61046927SAndroid Build Coastguard Worker unsigned new_bit_size);
144*61046927SAndroid Build Coastguard Worker
145*61046927SAndroid Build Coastguard Worker /** Defines a cast function
146*61046927SAndroid Build Coastguard Worker *
147*61046927SAndroid Build Coastguard Worker * This macro defines a cast function from in_type to out_type where
148*61046927SAndroid Build Coastguard Worker * out_type is some structure type that contains a field of type out_type.
149*61046927SAndroid Build Coastguard Worker *
150*61046927SAndroid Build Coastguard Worker * Note that you have to be a bit careful as the generated cast function
151*61046927SAndroid Build Coastguard Worker * destroys constness.
152*61046927SAndroid Build Coastguard Worker */
153*61046927SAndroid Build Coastguard Worker #define NIR_DEFINE_CAST(name, in_type, out_type, field, \
154*61046927SAndroid Build Coastguard Worker type_field, type_value) \
155*61046927SAndroid Build Coastguard Worker static inline out_type * \
156*61046927SAndroid Build Coastguard Worker name(const in_type *parent) \
157*61046927SAndroid Build Coastguard Worker { \
158*61046927SAndroid Build Coastguard Worker assert(parent && parent->type_field == type_value); \
159*61046927SAndroid Build Coastguard Worker return exec_node_data(out_type, parent, field); \
160*61046927SAndroid Build Coastguard Worker }
161*61046927SAndroid Build Coastguard Worker
162*61046927SAndroid Build Coastguard Worker struct nir_function;
163*61046927SAndroid Build Coastguard Worker struct nir_shader;
164*61046927SAndroid Build Coastguard Worker struct nir_instr;
165*61046927SAndroid Build Coastguard Worker struct nir_builder;
166*61046927SAndroid Build Coastguard Worker struct nir_xfb_info;
167*61046927SAndroid Build Coastguard Worker
168*61046927SAndroid Build Coastguard Worker /**
169*61046927SAndroid Build Coastguard Worker * Description of built-in state associated with a uniform
170*61046927SAndroid Build Coastguard Worker *
171*61046927SAndroid Build Coastguard Worker * :c:member:`nir_variable.state_slots`
172*61046927SAndroid Build Coastguard Worker */
173*61046927SAndroid Build Coastguard Worker typedef struct {
174*61046927SAndroid Build Coastguard Worker gl_state_index16 tokens[STATE_LENGTH];
175*61046927SAndroid Build Coastguard Worker } nir_state_slot;
176*61046927SAndroid Build Coastguard Worker
177*61046927SAndroid Build Coastguard Worker /* clang-format off */
178*61046927SAndroid Build Coastguard Worker typedef enum {
179*61046927SAndroid Build Coastguard Worker nir_var_system_value = (1 << 0),
180*61046927SAndroid Build Coastguard Worker nir_var_uniform = (1 << 1),
181*61046927SAndroid Build Coastguard Worker nir_var_shader_in = (1 << 2),
182*61046927SAndroid Build Coastguard Worker nir_var_shader_out = (1 << 3),
183*61046927SAndroid Build Coastguard Worker nir_var_image = (1 << 4),
184*61046927SAndroid Build Coastguard Worker /** Incoming call or ray payload data for ray-tracing shaders */
185*61046927SAndroid Build Coastguard Worker nir_var_shader_call_data = (1 << 5),
186*61046927SAndroid Build Coastguard Worker /** Ray hit attributes */
187*61046927SAndroid Build Coastguard Worker nir_var_ray_hit_attrib = (1 << 6),
188*61046927SAndroid Build Coastguard Worker
189*61046927SAndroid Build Coastguard Worker /* Modes named nir_var_mem_* have explicit data layout */
190*61046927SAndroid Build Coastguard Worker nir_var_mem_ubo = (1 << 7),
191*61046927SAndroid Build Coastguard Worker nir_var_mem_push_const = (1 << 8),
192*61046927SAndroid Build Coastguard Worker nir_var_mem_ssbo = (1 << 9),
193*61046927SAndroid Build Coastguard Worker nir_var_mem_constant = (1 << 10),
194*61046927SAndroid Build Coastguard Worker nir_var_mem_task_payload = (1 << 11),
195*61046927SAndroid Build Coastguard Worker nir_var_mem_node_payload = (1 << 12),
196*61046927SAndroid Build Coastguard Worker nir_var_mem_node_payload_in = (1 << 13),
197*61046927SAndroid Build Coastguard Worker
198*61046927SAndroid Build Coastguard Worker /* Generic modes intentionally come last. See encode_dref_modes() in
199*61046927SAndroid Build Coastguard Worker * nir_serialize.c for more details.
200*61046927SAndroid Build Coastguard Worker */
201*61046927SAndroid Build Coastguard Worker nir_var_shader_temp = (1 << 14),
202*61046927SAndroid Build Coastguard Worker nir_var_function_temp = (1 << 15),
203*61046927SAndroid Build Coastguard Worker nir_var_mem_shared = (1 << 16),
204*61046927SAndroid Build Coastguard Worker nir_var_mem_global = (1 << 17),
205*61046927SAndroid Build Coastguard Worker
206*61046927SAndroid Build Coastguard Worker nir_var_mem_generic = (nir_var_shader_temp |
207*61046927SAndroid Build Coastguard Worker nir_var_function_temp |
208*61046927SAndroid Build Coastguard Worker nir_var_mem_shared |
209*61046927SAndroid Build Coastguard Worker nir_var_mem_global),
210*61046927SAndroid Build Coastguard Worker
211*61046927SAndroid Build Coastguard Worker nir_var_read_only_modes = nir_var_shader_in | nir_var_uniform |
212*61046927SAndroid Build Coastguard Worker nir_var_system_value | nir_var_mem_constant |
213*61046927SAndroid Build Coastguard Worker nir_var_mem_ubo,
214*61046927SAndroid Build Coastguard Worker /* Modes where vector derefs can be indexed as arrays. nir_var_shader_out
215*61046927SAndroid Build Coastguard Worker * is only for mesh stages. nir_var_system_value is only for kernel stages.
216*61046927SAndroid Build Coastguard Worker */
217*61046927SAndroid Build Coastguard Worker nir_var_vec_indexable_modes = nir_var_shader_temp | nir_var_function_temp |
218*61046927SAndroid Build Coastguard Worker nir_var_mem_ubo | nir_var_mem_ssbo |
219*61046927SAndroid Build Coastguard Worker nir_var_mem_shared | nir_var_mem_global |
220*61046927SAndroid Build Coastguard Worker nir_var_mem_push_const | nir_var_mem_task_payload |
221*61046927SAndroid Build Coastguard Worker nir_var_shader_out | nir_var_system_value,
222*61046927SAndroid Build Coastguard Worker nir_num_variable_modes = 18,
223*61046927SAndroid Build Coastguard Worker nir_var_all = (1 << nir_num_variable_modes) - 1,
224*61046927SAndroid Build Coastguard Worker } nir_variable_mode;
225*61046927SAndroid Build Coastguard Worker MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(nir_variable_mode)
226*61046927SAndroid Build Coastguard Worker /* clang-format on */
227*61046927SAndroid Build Coastguard Worker
228*61046927SAndroid Build Coastguard Worker /**
229*61046927SAndroid Build Coastguard Worker * Rounding modes.
230*61046927SAndroid Build Coastguard Worker */
231*61046927SAndroid Build Coastguard Worker typedef enum {
232*61046927SAndroid Build Coastguard Worker nir_rounding_mode_undef = 0,
233*61046927SAndroid Build Coastguard Worker nir_rounding_mode_rtne = 1, /* round to nearest even */
234*61046927SAndroid Build Coastguard Worker nir_rounding_mode_ru = 2, /* round up */
235*61046927SAndroid Build Coastguard Worker nir_rounding_mode_rd = 3, /* round down */
236*61046927SAndroid Build Coastguard Worker nir_rounding_mode_rtz = 4, /* round towards zero */
237*61046927SAndroid Build Coastguard Worker } nir_rounding_mode;
238*61046927SAndroid Build Coastguard Worker
239*61046927SAndroid Build Coastguard Worker /**
240*61046927SAndroid Build Coastguard Worker * Ray query values that can read from a RayQueryKHR object.
241*61046927SAndroid Build Coastguard Worker */
242*61046927SAndroid Build Coastguard Worker typedef enum {
243*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_type,
244*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_t,
245*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_instance_custom_index,
246*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_instance_id,
247*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_instance_sbt_index,
248*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_geometry_index,
249*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_primitive_index,
250*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_barycentrics,
251*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_front_face,
252*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_object_ray_direction,
253*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_object_ray_origin,
254*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_object_to_world,
255*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_world_to_object,
256*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_candidate_aabb_opaque,
257*61046927SAndroid Build Coastguard Worker nir_ray_query_value_tmin,
258*61046927SAndroid Build Coastguard Worker nir_ray_query_value_flags,
259*61046927SAndroid Build Coastguard Worker nir_ray_query_value_world_ray_direction,
260*61046927SAndroid Build Coastguard Worker nir_ray_query_value_world_ray_origin,
261*61046927SAndroid Build Coastguard Worker nir_ray_query_value_intersection_triangle_vertex_positions
262*61046927SAndroid Build Coastguard Worker } nir_ray_query_value;
263*61046927SAndroid Build Coastguard Worker
264*61046927SAndroid Build Coastguard Worker /**
265*61046927SAndroid Build Coastguard Worker * Intel resource flags
266*61046927SAndroid Build Coastguard Worker */
267*61046927SAndroid Build Coastguard Worker typedef enum {
268*61046927SAndroid Build Coastguard Worker nir_resource_intel_bindless = 1u << 0,
269*61046927SAndroid Build Coastguard Worker nir_resource_intel_pushable = 1u << 1,
270*61046927SAndroid Build Coastguard Worker nir_resource_intel_sampler = 1u << 2,
271*61046927SAndroid Build Coastguard Worker nir_resource_intel_non_uniform = 1u << 3,
272*61046927SAndroid Build Coastguard Worker nir_resource_intel_sampler_embedded = 1u << 4,
273*61046927SAndroid Build Coastguard Worker } nir_resource_data_intel;
274*61046927SAndroid Build Coastguard Worker
275*61046927SAndroid Build Coastguard Worker /**
276*61046927SAndroid Build Coastguard Worker * Which components to interpret as signed in cmat_muladd.
277*61046927SAndroid Build Coastguard Worker * See 'Cooperative Matrix Operands' in SPV_KHR_cooperative_matrix.
278*61046927SAndroid Build Coastguard Worker */
279*61046927SAndroid Build Coastguard Worker typedef enum {
280*61046927SAndroid Build Coastguard Worker NIR_CMAT_A_SIGNED = 1u << 0,
281*61046927SAndroid Build Coastguard Worker NIR_CMAT_B_SIGNED = 1u << 1,
282*61046927SAndroid Build Coastguard Worker NIR_CMAT_C_SIGNED = 1u << 2,
283*61046927SAndroid Build Coastguard Worker NIR_CMAT_RESULT_SIGNED = 1u << 3,
284*61046927SAndroid Build Coastguard Worker } nir_cmat_signed;
285*61046927SAndroid Build Coastguard Worker
286*61046927SAndroid Build Coastguard Worker typedef union {
287*61046927SAndroid Build Coastguard Worker bool b;
288*61046927SAndroid Build Coastguard Worker float f32;
289*61046927SAndroid Build Coastguard Worker double f64;
290*61046927SAndroid Build Coastguard Worker int8_t i8;
291*61046927SAndroid Build Coastguard Worker uint8_t u8;
292*61046927SAndroid Build Coastguard Worker int16_t i16;
293*61046927SAndroid Build Coastguard Worker uint16_t u16;
294*61046927SAndroid Build Coastguard Worker int32_t i32;
295*61046927SAndroid Build Coastguard Worker uint32_t u32;
296*61046927SAndroid Build Coastguard Worker int64_t i64;
297*61046927SAndroid Build Coastguard Worker uint64_t u64;
298*61046927SAndroid Build Coastguard Worker } nir_const_value;
299*61046927SAndroid Build Coastguard Worker
300*61046927SAndroid Build Coastguard Worker #define nir_const_value_to_array(arr, c, components, m) \
301*61046927SAndroid Build Coastguard Worker do { \
302*61046927SAndroid Build Coastguard Worker for (unsigned i = 0; i < components; ++i) \
303*61046927SAndroid Build Coastguard Worker arr[i] = c[i].m; \
304*61046927SAndroid Build Coastguard Worker } while (false)
305*61046927SAndroid Build Coastguard Worker
306*61046927SAndroid Build Coastguard Worker static inline nir_const_value
nir_const_value_for_raw_uint(uint64_t x,unsigned bit_size)307*61046927SAndroid Build Coastguard Worker nir_const_value_for_raw_uint(uint64_t x, unsigned bit_size)
308*61046927SAndroid Build Coastguard Worker {
309*61046927SAndroid Build Coastguard Worker nir_const_value v;
310*61046927SAndroid Build Coastguard Worker memset(&v, 0, sizeof(v));
311*61046927SAndroid Build Coastguard Worker
312*61046927SAndroid Build Coastguard Worker /* clang-format off */
313*61046927SAndroid Build Coastguard Worker switch (bit_size) {
314*61046927SAndroid Build Coastguard Worker case 1: v.b = x; break;
315*61046927SAndroid Build Coastguard Worker case 8: v.u8 = x; break;
316*61046927SAndroid Build Coastguard Worker case 16: v.u16 = x; break;
317*61046927SAndroid Build Coastguard Worker case 32: v.u32 = x; break;
318*61046927SAndroid Build Coastguard Worker case 64: v.u64 = x; break;
319*61046927SAndroid Build Coastguard Worker default:
320*61046927SAndroid Build Coastguard Worker unreachable("Invalid bit size");
321*61046927SAndroid Build Coastguard Worker }
322*61046927SAndroid Build Coastguard Worker /* clang-format on */
323*61046927SAndroid Build Coastguard Worker
324*61046927SAndroid Build Coastguard Worker return v;
325*61046927SAndroid Build Coastguard Worker }
326*61046927SAndroid Build Coastguard Worker
327*61046927SAndroid Build Coastguard Worker static inline nir_const_value
nir_const_value_for_int(int64_t i,unsigned bit_size)328*61046927SAndroid Build Coastguard Worker nir_const_value_for_int(int64_t i, unsigned bit_size)
329*61046927SAndroid Build Coastguard Worker {
330*61046927SAndroid Build Coastguard Worker assert(bit_size <= 64);
331*61046927SAndroid Build Coastguard Worker if (bit_size < 64) {
332*61046927SAndroid Build Coastguard Worker assert(i >= (-(1ll << (bit_size - 1))));
333*61046927SAndroid Build Coastguard Worker assert(i < (1ll << (bit_size - 1)));
334*61046927SAndroid Build Coastguard Worker }
335*61046927SAndroid Build Coastguard Worker
336*61046927SAndroid Build Coastguard Worker return nir_const_value_for_raw_uint(i, bit_size);
337*61046927SAndroid Build Coastguard Worker }
338*61046927SAndroid Build Coastguard Worker
339*61046927SAndroid Build Coastguard Worker static inline nir_const_value
nir_const_value_for_uint(uint64_t u,unsigned bit_size)340*61046927SAndroid Build Coastguard Worker nir_const_value_for_uint(uint64_t u, unsigned bit_size)
341*61046927SAndroid Build Coastguard Worker {
342*61046927SAndroid Build Coastguard Worker assert(bit_size <= 64);
343*61046927SAndroid Build Coastguard Worker if (bit_size < 64)
344*61046927SAndroid Build Coastguard Worker assert(u < (1ull << bit_size));
345*61046927SAndroid Build Coastguard Worker
346*61046927SAndroid Build Coastguard Worker return nir_const_value_for_raw_uint(u, bit_size);
347*61046927SAndroid Build Coastguard Worker }
348*61046927SAndroid Build Coastguard Worker
349*61046927SAndroid Build Coastguard Worker static inline nir_const_value
nir_const_value_for_bool(bool b,unsigned bit_size)350*61046927SAndroid Build Coastguard Worker nir_const_value_for_bool(bool b, unsigned bit_size)
351*61046927SAndroid Build Coastguard Worker {
352*61046927SAndroid Build Coastguard Worker /* Booleans use a 0/-1 convention */
353*61046927SAndroid Build Coastguard Worker return nir_const_value_for_int(-(int)b, bit_size);
354*61046927SAndroid Build Coastguard Worker }
355*61046927SAndroid Build Coastguard Worker
356*61046927SAndroid Build Coastguard Worker /* This one isn't inline because it requires half-float conversion */
357*61046927SAndroid Build Coastguard Worker nir_const_value nir_const_value_for_float(double b, unsigned bit_size);
358*61046927SAndroid Build Coastguard Worker
359*61046927SAndroid Build Coastguard Worker static inline int64_t
nir_const_value_as_int(nir_const_value value,unsigned bit_size)360*61046927SAndroid Build Coastguard Worker nir_const_value_as_int(nir_const_value value, unsigned bit_size)
361*61046927SAndroid Build Coastguard Worker {
362*61046927SAndroid Build Coastguard Worker /* clang-format off */
363*61046927SAndroid Build Coastguard Worker switch (bit_size) {
364*61046927SAndroid Build Coastguard Worker /* int1_t uses 0/-1 convention */
365*61046927SAndroid Build Coastguard Worker case 1: return -(int)value.b;
366*61046927SAndroid Build Coastguard Worker case 8: return value.i8;
367*61046927SAndroid Build Coastguard Worker case 16: return value.i16;
368*61046927SAndroid Build Coastguard Worker case 32: return value.i32;
369*61046927SAndroid Build Coastguard Worker case 64: return value.i64;
370*61046927SAndroid Build Coastguard Worker default:
371*61046927SAndroid Build Coastguard Worker unreachable("Invalid bit size");
372*61046927SAndroid Build Coastguard Worker }
373*61046927SAndroid Build Coastguard Worker /* clang-format on */
374*61046927SAndroid Build Coastguard Worker }
375*61046927SAndroid Build Coastguard Worker
376*61046927SAndroid Build Coastguard Worker static inline uint64_t
nir_const_value_as_uint(nir_const_value value,unsigned bit_size)377*61046927SAndroid Build Coastguard Worker nir_const_value_as_uint(nir_const_value value, unsigned bit_size)
378*61046927SAndroid Build Coastguard Worker {
379*61046927SAndroid Build Coastguard Worker /* clang-format off */
380*61046927SAndroid Build Coastguard Worker switch (bit_size) {
381*61046927SAndroid Build Coastguard Worker case 1: return value.b;
382*61046927SAndroid Build Coastguard Worker case 8: return value.u8;
383*61046927SAndroid Build Coastguard Worker case 16: return value.u16;
384*61046927SAndroid Build Coastguard Worker case 32: return value.u32;
385*61046927SAndroid Build Coastguard Worker case 64: return value.u64;
386*61046927SAndroid Build Coastguard Worker default:
387*61046927SAndroid Build Coastguard Worker unreachable("Invalid bit size");
388*61046927SAndroid Build Coastguard Worker }
389*61046927SAndroid Build Coastguard Worker /* clang-format on */
390*61046927SAndroid Build Coastguard Worker }
391*61046927SAndroid Build Coastguard Worker
392*61046927SAndroid Build Coastguard Worker static inline bool
nir_const_value_as_bool(nir_const_value value,unsigned bit_size)393*61046927SAndroid Build Coastguard Worker nir_const_value_as_bool(nir_const_value value, unsigned bit_size)
394*61046927SAndroid Build Coastguard Worker {
395*61046927SAndroid Build Coastguard Worker int64_t i = nir_const_value_as_int(value, bit_size);
396*61046927SAndroid Build Coastguard Worker
397*61046927SAndroid Build Coastguard Worker /* Booleans of any size use 0/-1 convention */
398*61046927SAndroid Build Coastguard Worker assert(i == 0 || i == -1);
399*61046927SAndroid Build Coastguard Worker
400*61046927SAndroid Build Coastguard Worker return i;
401*61046927SAndroid Build Coastguard Worker }
402*61046927SAndroid Build Coastguard Worker
403*61046927SAndroid Build Coastguard Worker /* This one isn't inline because it requires half-float conversion */
404*61046927SAndroid Build Coastguard Worker double nir_const_value_as_float(nir_const_value value, unsigned bit_size);
405*61046927SAndroid Build Coastguard Worker
406*61046927SAndroid Build Coastguard Worker typedef struct nir_constant {
407*61046927SAndroid Build Coastguard Worker /**
408*61046927SAndroid Build Coastguard Worker * Value of the constant.
409*61046927SAndroid Build Coastguard Worker *
410*61046927SAndroid Build Coastguard Worker * The field used to back the values supplied by the constant is determined
411*61046927SAndroid Build Coastguard Worker * by the type associated with the ``nir_variable``. Constants may be
412*61046927SAndroid Build Coastguard Worker * scalars, vectors, or matrices.
413*61046927SAndroid Build Coastguard Worker */
414*61046927SAndroid Build Coastguard Worker nir_const_value values[NIR_MAX_VEC_COMPONENTS];
415*61046927SAndroid Build Coastguard Worker
416*61046927SAndroid Build Coastguard Worker /* Indicates all the values are 0s which can enable some optimizations */
417*61046927SAndroid Build Coastguard Worker bool is_null_constant;
418*61046927SAndroid Build Coastguard Worker
419*61046927SAndroid Build Coastguard Worker /* we could get this from the var->type but makes clone *much* easier to
420*61046927SAndroid Build Coastguard Worker * not have to care about the type.
421*61046927SAndroid Build Coastguard Worker */
422*61046927SAndroid Build Coastguard Worker unsigned num_elements;
423*61046927SAndroid Build Coastguard Worker
424*61046927SAndroid Build Coastguard Worker /* Array elements / Structure Fields */
425*61046927SAndroid Build Coastguard Worker struct nir_constant **elements;
426*61046927SAndroid Build Coastguard Worker } nir_constant;
427*61046927SAndroid Build Coastguard Worker
428*61046927SAndroid Build Coastguard Worker /**
429*61046927SAndroid Build Coastguard Worker * Layout qualifiers for gl_FragDepth.
430*61046927SAndroid Build Coastguard Worker *
431*61046927SAndroid Build Coastguard Worker * The AMD/ARB_conservative_depth extensions allow gl_FragDepth to be redeclared
432*61046927SAndroid Build Coastguard Worker * with a layout qualifier.
433*61046927SAndroid Build Coastguard Worker */
434*61046927SAndroid Build Coastguard Worker typedef enum {
435*61046927SAndroid Build Coastguard Worker /** No depth layout is specified. */
436*61046927SAndroid Build Coastguard Worker nir_depth_layout_none,
437*61046927SAndroid Build Coastguard Worker nir_depth_layout_any,
438*61046927SAndroid Build Coastguard Worker nir_depth_layout_greater,
439*61046927SAndroid Build Coastguard Worker nir_depth_layout_less,
440*61046927SAndroid Build Coastguard Worker nir_depth_layout_unchanged
441*61046927SAndroid Build Coastguard Worker } nir_depth_layout;
442*61046927SAndroid Build Coastguard Worker
443*61046927SAndroid Build Coastguard Worker /**
444*61046927SAndroid Build Coastguard Worker * Enum keeping track of how a variable was declared.
445*61046927SAndroid Build Coastguard Worker */
446*61046927SAndroid Build Coastguard Worker typedef enum {
447*61046927SAndroid Build Coastguard Worker /**
448*61046927SAndroid Build Coastguard Worker * Normal declaration.
449*61046927SAndroid Build Coastguard Worker */
450*61046927SAndroid Build Coastguard Worker nir_var_declared_normally = 0,
451*61046927SAndroid Build Coastguard Worker
452*61046927SAndroid Build Coastguard Worker /**
453*61046927SAndroid Build Coastguard Worker * Variable is an implicitly declared built-in that has not been explicitly
454*61046927SAndroid Build Coastguard Worker * re-declared by the shader.
455*61046927SAndroid Build Coastguard Worker */
456*61046927SAndroid Build Coastguard Worker nir_var_declared_implicitly,
457*61046927SAndroid Build Coastguard Worker
458*61046927SAndroid Build Coastguard Worker /**
459*61046927SAndroid Build Coastguard Worker * Variable is implicitly generated by the compiler and should not be
460*61046927SAndroid Build Coastguard Worker * visible via the API.
461*61046927SAndroid Build Coastguard Worker */
462*61046927SAndroid Build Coastguard Worker nir_var_hidden,
463*61046927SAndroid Build Coastguard Worker } nir_var_declaration_type;
464*61046927SAndroid Build Coastguard Worker
465*61046927SAndroid Build Coastguard Worker /**
466*61046927SAndroid Build Coastguard Worker * Either a uniform, global variable, shader input, or shader output. Based on
467*61046927SAndroid Build Coastguard Worker * ir_variable - it should be easy to translate between the two.
468*61046927SAndroid Build Coastguard Worker */
469*61046927SAndroid Build Coastguard Worker
470*61046927SAndroid Build Coastguard Worker typedef struct nir_variable {
471*61046927SAndroid Build Coastguard Worker struct exec_node node;
472*61046927SAndroid Build Coastguard Worker
473*61046927SAndroid Build Coastguard Worker /**
474*61046927SAndroid Build Coastguard Worker * Declared type of the variable
475*61046927SAndroid Build Coastguard Worker */
476*61046927SAndroid Build Coastguard Worker const struct glsl_type *type;
477*61046927SAndroid Build Coastguard Worker
478*61046927SAndroid Build Coastguard Worker /**
479*61046927SAndroid Build Coastguard Worker * Declared name of the variable
480*61046927SAndroid Build Coastguard Worker */
481*61046927SAndroid Build Coastguard Worker char *name;
482*61046927SAndroid Build Coastguard Worker
483*61046927SAndroid Build Coastguard Worker struct nir_variable_data {
484*61046927SAndroid Build Coastguard Worker /**
485*61046927SAndroid Build Coastguard Worker * Storage class of the variable.
486*61046927SAndroid Build Coastguard Worker *
487*61046927SAndroid Build Coastguard Worker * :c:struct:`nir_variable_mode`
488*61046927SAndroid Build Coastguard Worker */
489*61046927SAndroid Build Coastguard Worker unsigned mode : 18;
490*61046927SAndroid Build Coastguard Worker
491*61046927SAndroid Build Coastguard Worker /**
492*61046927SAndroid Build Coastguard Worker * Is the variable read-only?
493*61046927SAndroid Build Coastguard Worker *
494*61046927SAndroid Build Coastguard Worker * This is set for variables declared as ``const``, shader inputs,
495*61046927SAndroid Build Coastguard Worker * and uniforms.
496*61046927SAndroid Build Coastguard Worker */
497*61046927SAndroid Build Coastguard Worker unsigned read_only : 1;
498*61046927SAndroid Build Coastguard Worker unsigned centroid : 1;
499*61046927SAndroid Build Coastguard Worker unsigned sample : 1;
500*61046927SAndroid Build Coastguard Worker unsigned patch : 1;
501*61046927SAndroid Build Coastguard Worker unsigned invariant : 1;
502*61046927SAndroid Build Coastguard Worker
503*61046927SAndroid Build Coastguard Worker /**
504*61046927SAndroid Build Coastguard Worker * Was an 'invariant' qualifier explicitly set in the shader?
505*61046927SAndroid Build Coastguard Worker *
506*61046927SAndroid Build Coastguard Worker * This is used to cross validate glsl qualifiers.
507*61046927SAndroid Build Coastguard Worker */
508*61046927SAndroid Build Coastguard Worker unsigned explicit_invariant:1;
509*61046927SAndroid Build Coastguard Worker
510*61046927SAndroid Build Coastguard Worker /**
511*61046927SAndroid Build Coastguard Worker * Is the variable a ray query?
512*61046927SAndroid Build Coastguard Worker */
513*61046927SAndroid Build Coastguard Worker unsigned ray_query : 1;
514*61046927SAndroid Build Coastguard Worker
515*61046927SAndroid Build Coastguard Worker /**
516*61046927SAndroid Build Coastguard Worker * Precision qualifier.
517*61046927SAndroid Build Coastguard Worker *
518*61046927SAndroid Build Coastguard Worker * In desktop GLSL we do not care about precision qualifiers at all, in
519*61046927SAndroid Build Coastguard Worker * fact, the spec says that precision qualifiers are ignored.
520*61046927SAndroid Build Coastguard Worker *
521*61046927SAndroid Build Coastguard Worker * To make things easy, we make it so that this field is always
522*61046927SAndroid Build Coastguard Worker * GLSL_PRECISION_NONE on desktop shaders. This way all the variables
523*61046927SAndroid Build Coastguard Worker * have the same precision value and the checks we add in the compiler
524*61046927SAndroid Build Coastguard Worker * for this field will never break a desktop shader compile.
525*61046927SAndroid Build Coastguard Worker */
526*61046927SAndroid Build Coastguard Worker unsigned precision : 2;
527*61046927SAndroid Build Coastguard Worker
528*61046927SAndroid Build Coastguard Worker /**
529*61046927SAndroid Build Coastguard Worker * Has this variable been statically assigned?
530*61046927SAndroid Build Coastguard Worker *
531*61046927SAndroid Build Coastguard Worker * This answers whether the variable was assigned in any path of
532*61046927SAndroid Build Coastguard Worker * the shader during ast_to_hir. This doesn't answer whether it is
533*61046927SAndroid Build Coastguard Worker * still written after dead code removal, nor is it maintained in
534*61046927SAndroid Build Coastguard Worker * non-ast_to_hir.cpp (GLSL parsing) paths.
535*61046927SAndroid Build Coastguard Worker */
536*61046927SAndroid Build Coastguard Worker unsigned assigned : 1;
537*61046927SAndroid Build Coastguard Worker
538*61046927SAndroid Build Coastguard Worker /**
539*61046927SAndroid Build Coastguard Worker * Can this variable be coalesced with another?
540*61046927SAndroid Build Coastguard Worker *
541*61046927SAndroid Build Coastguard Worker * This is set by nir_lower_io_to_temporaries to say that any
542*61046927SAndroid Build Coastguard Worker * copies involving this variable should stay put. Propagating it can
543*61046927SAndroid Build Coastguard Worker * duplicate the resulting load/store, which is not wanted, and may
544*61046927SAndroid Build Coastguard Worker * result in a load/store of the variable with an indirect offset which
545*61046927SAndroid Build Coastguard Worker * the backend may not be able to handle.
546*61046927SAndroid Build Coastguard Worker */
547*61046927SAndroid Build Coastguard Worker unsigned cannot_coalesce : 1;
548*61046927SAndroid Build Coastguard Worker
549*61046927SAndroid Build Coastguard Worker /**
550*61046927SAndroid Build Coastguard Worker * When separate shader programs are enabled, only input/outputs between
551*61046927SAndroid Build Coastguard Worker * the stages of a multi-stage separate program can be safely removed
552*61046927SAndroid Build Coastguard Worker * from the shader interface. Other input/outputs must remains active.
553*61046927SAndroid Build Coastguard Worker *
554*61046927SAndroid Build Coastguard Worker * This is also used to make sure xfb varyings that are unused by the
555*61046927SAndroid Build Coastguard Worker * fragment shader are not removed.
556*61046927SAndroid Build Coastguard Worker */
557*61046927SAndroid Build Coastguard Worker unsigned always_active_io : 1;
558*61046927SAndroid Build Coastguard Worker
559*61046927SAndroid Build Coastguard Worker /**
560*61046927SAndroid Build Coastguard Worker * Interpolation mode for shader inputs / outputs
561*61046927SAndroid Build Coastguard Worker *
562*61046927SAndroid Build Coastguard Worker * :c:enum:`glsl_interp_mode`
563*61046927SAndroid Build Coastguard Worker */
564*61046927SAndroid Build Coastguard Worker unsigned interpolation : 3;
565*61046927SAndroid Build Coastguard Worker
566*61046927SAndroid Build Coastguard Worker /**
567*61046927SAndroid Build Coastguard Worker * If non-zero, then this variable may be packed along with other variables
568*61046927SAndroid Build Coastguard Worker * into a single varying slot, so this offset should be applied when
569*61046927SAndroid Build Coastguard Worker * accessing components. For example, an offset of 1 means that the x
570*61046927SAndroid Build Coastguard Worker * component of this variable is actually stored in component y of the
571*61046927SAndroid Build Coastguard Worker * location specified by ``location``.
572*61046927SAndroid Build Coastguard Worker */
573*61046927SAndroid Build Coastguard Worker unsigned location_frac : 2;
574*61046927SAndroid Build Coastguard Worker
575*61046927SAndroid Build Coastguard Worker /**
576*61046927SAndroid Build Coastguard Worker * If true, this variable represents an array of scalars that should
577*61046927SAndroid Build Coastguard Worker * be tightly packed. In other words, consecutive array elements
578*61046927SAndroid Build Coastguard Worker * should be stored one component apart, rather than one slot apart.
579*61046927SAndroid Build Coastguard Worker */
580*61046927SAndroid Build Coastguard Worker unsigned compact : 1;
581*61046927SAndroid Build Coastguard Worker
582*61046927SAndroid Build Coastguard Worker /**
583*61046927SAndroid Build Coastguard Worker * Whether this is a fragment shader output implicitly initialized with
584*61046927SAndroid Build Coastguard Worker * the previous contents of the specified render target at the
585*61046927SAndroid Build Coastguard Worker * framebuffer location corresponding to this shader invocation.
586*61046927SAndroid Build Coastguard Worker */
587*61046927SAndroid Build Coastguard Worker unsigned fb_fetch_output : 1;
588*61046927SAndroid Build Coastguard Worker
589*61046927SAndroid Build Coastguard Worker /**
590*61046927SAndroid Build Coastguard Worker * Non-zero if this variable is considered bindless as defined by
591*61046927SAndroid Build Coastguard Worker * ARB_bindless_texture.
592*61046927SAndroid Build Coastguard Worker */
593*61046927SAndroid Build Coastguard Worker unsigned bindless : 1;
594*61046927SAndroid Build Coastguard Worker
595*61046927SAndroid Build Coastguard Worker /**
596*61046927SAndroid Build Coastguard Worker * Was an explicit binding set in the shader?
597*61046927SAndroid Build Coastguard Worker */
598*61046927SAndroid Build Coastguard Worker unsigned explicit_binding : 1;
599*61046927SAndroid Build Coastguard Worker
600*61046927SAndroid Build Coastguard Worker /**
601*61046927SAndroid Build Coastguard Worker * Was the location explicitly set in the shader?
602*61046927SAndroid Build Coastguard Worker *
603*61046927SAndroid Build Coastguard Worker * If the location is explicitly set in the shader, it **cannot** be changed
604*61046927SAndroid Build Coastguard Worker * by the linker or by the API (e.g., calls to ``glBindAttribLocation`` have
605*61046927SAndroid Build Coastguard Worker * no effect).
606*61046927SAndroid Build Coastguard Worker */
607*61046927SAndroid Build Coastguard Worker unsigned explicit_location : 1;
608*61046927SAndroid Build Coastguard Worker
609*61046927SAndroid Build Coastguard Worker /* Was the array implicitly sized during linking */
610*61046927SAndroid Build Coastguard Worker unsigned implicit_sized_array : 1;
611*61046927SAndroid Build Coastguard Worker
612*61046927SAndroid Build Coastguard Worker /**
613*61046927SAndroid Build Coastguard Worker * Highest element accessed with a constant array index
614*61046927SAndroid Build Coastguard Worker *
615*61046927SAndroid Build Coastguard Worker * Not used for non-array variables. -1 is never accessed.
616*61046927SAndroid Build Coastguard Worker */
617*61046927SAndroid Build Coastguard Worker int max_array_access;
618*61046927SAndroid Build Coastguard Worker
619*61046927SAndroid Build Coastguard Worker /**
620*61046927SAndroid Build Coastguard Worker * Does this variable have an initializer?
621*61046927SAndroid Build Coastguard Worker *
622*61046927SAndroid Build Coastguard Worker * This is used by the linker to cross-validiate initializers of global
623*61046927SAndroid Build Coastguard Worker * variables.
624*61046927SAndroid Build Coastguard Worker */
625*61046927SAndroid Build Coastguard Worker unsigned has_initializer:1;
626*61046927SAndroid Build Coastguard Worker
627*61046927SAndroid Build Coastguard Worker /**
628*61046927SAndroid Build Coastguard Worker * Is the initializer created by the compiler (glsl_zero_init)
629*61046927SAndroid Build Coastguard Worker */
630*61046927SAndroid Build Coastguard Worker unsigned is_implicit_initializer:1;
631*61046927SAndroid Build Coastguard Worker
632*61046927SAndroid Build Coastguard Worker /**
633*61046927SAndroid Build Coastguard Worker * Is this varying used by transform feedback?
634*61046927SAndroid Build Coastguard Worker *
635*61046927SAndroid Build Coastguard Worker * This is used by the linker to decide if it's safe to pack the varying.
636*61046927SAndroid Build Coastguard Worker */
637*61046927SAndroid Build Coastguard Worker unsigned is_xfb : 1;
638*61046927SAndroid Build Coastguard Worker
639*61046927SAndroid Build Coastguard Worker /**
640*61046927SAndroid Build Coastguard Worker * Is this varying used only by transform feedback?
641*61046927SAndroid Build Coastguard Worker *
642*61046927SAndroid Build Coastguard Worker * This is used by the linker to decide if its safe to pack the varying.
643*61046927SAndroid Build Coastguard Worker */
644*61046927SAndroid Build Coastguard Worker unsigned is_xfb_only : 1;
645*61046927SAndroid Build Coastguard Worker
646*61046927SAndroid Build Coastguard Worker /**
647*61046927SAndroid Build Coastguard Worker * Was a transfer feedback buffer set in the shader?
648*61046927SAndroid Build Coastguard Worker */
649*61046927SAndroid Build Coastguard Worker unsigned explicit_xfb_buffer : 1;
650*61046927SAndroid Build Coastguard Worker
651*61046927SAndroid Build Coastguard Worker /**
652*61046927SAndroid Build Coastguard Worker * Was a transfer feedback stride set in the shader?
653*61046927SAndroid Build Coastguard Worker */
654*61046927SAndroid Build Coastguard Worker unsigned explicit_xfb_stride : 1;
655*61046927SAndroid Build Coastguard Worker
656*61046927SAndroid Build Coastguard Worker /**
657*61046927SAndroid Build Coastguard Worker * Was an explicit offset set in the shader?
658*61046927SAndroid Build Coastguard Worker */
659*61046927SAndroid Build Coastguard Worker unsigned explicit_offset : 1;
660*61046927SAndroid Build Coastguard Worker
661*61046927SAndroid Build Coastguard Worker /**
662*61046927SAndroid Build Coastguard Worker * Layout of the matrix. Uses glsl_matrix_layout values.
663*61046927SAndroid Build Coastguard Worker */
664*61046927SAndroid Build Coastguard Worker unsigned matrix_layout : 2;
665*61046927SAndroid Build Coastguard Worker
666*61046927SAndroid Build Coastguard Worker /**
667*61046927SAndroid Build Coastguard Worker * Non-zero if this variable was created by lowering a named interface
668*61046927SAndroid Build Coastguard Worker * block.
669*61046927SAndroid Build Coastguard Worker */
670*61046927SAndroid Build Coastguard Worker unsigned from_named_ifc_block : 1;
671*61046927SAndroid Build Coastguard Worker
672*61046927SAndroid Build Coastguard Worker /**
673*61046927SAndroid Build Coastguard Worker * Unsized array buffer variable.
674*61046927SAndroid Build Coastguard Worker */
675*61046927SAndroid Build Coastguard Worker unsigned from_ssbo_unsized_array : 1;
676*61046927SAndroid Build Coastguard Worker
677*61046927SAndroid Build Coastguard Worker /**
678*61046927SAndroid Build Coastguard Worker * Non-zero if the variable must be a shader input. This is useful for
679*61046927SAndroid Build Coastguard Worker * constraints on function parameters.
680*61046927SAndroid Build Coastguard Worker */
681*61046927SAndroid Build Coastguard Worker unsigned must_be_shader_input : 1;
682*61046927SAndroid Build Coastguard Worker
683*61046927SAndroid Build Coastguard Worker /**
684*61046927SAndroid Build Coastguard Worker * Has this variable been used for reading or writing?
685*61046927SAndroid Build Coastguard Worker *
686*61046927SAndroid Build Coastguard Worker * Several GLSL semantic checks require knowledge of whether or not a
687*61046927SAndroid Build Coastguard Worker * variable has been used. For example, it is an error to redeclare a
688*61046927SAndroid Build Coastguard Worker * variable as invariant after it has been used.
689*61046927SAndroid Build Coastguard Worker */
690*61046927SAndroid Build Coastguard Worker unsigned used:1;
691*61046927SAndroid Build Coastguard Worker
692*61046927SAndroid Build Coastguard Worker /**
693*61046927SAndroid Build Coastguard Worker * How the variable was declared. See nir_var_declaration_type.
694*61046927SAndroid Build Coastguard Worker *
695*61046927SAndroid Build Coastguard Worker * This is used to detect variables generated by the compiler, so should
696*61046927SAndroid Build Coastguard Worker * not be visible via the API.
697*61046927SAndroid Build Coastguard Worker */
698*61046927SAndroid Build Coastguard Worker unsigned how_declared : 2;
699*61046927SAndroid Build Coastguard Worker
700*61046927SAndroid Build Coastguard Worker /**
701*61046927SAndroid Build Coastguard Worker * Is this variable per-view? If so, we know it must be an array with
702*61046927SAndroid Build Coastguard Worker * size corresponding to the number of views.
703*61046927SAndroid Build Coastguard Worker */
704*61046927SAndroid Build Coastguard Worker unsigned per_view : 1;
705*61046927SAndroid Build Coastguard Worker
706*61046927SAndroid Build Coastguard Worker /**
707*61046927SAndroid Build Coastguard Worker * Whether the variable is per-primitive.
708*61046927SAndroid Build Coastguard Worker * Can be use by Mesh Shader outputs and corresponding Fragment Shader inputs.
709*61046927SAndroid Build Coastguard Worker */
710*61046927SAndroid Build Coastguard Worker unsigned per_primitive : 1;
711*61046927SAndroid Build Coastguard Worker
712*61046927SAndroid Build Coastguard Worker /**
713*61046927SAndroid Build Coastguard Worker * Whether the variable is declared to indicate that a fragment shader
714*61046927SAndroid Build Coastguard Worker * input will not have interpolated values.
715*61046927SAndroid Build Coastguard Worker */
716*61046927SAndroid Build Coastguard Worker unsigned per_vertex : 1;
717*61046927SAndroid Build Coastguard Worker
718*61046927SAndroid Build Coastguard Worker /**
719*61046927SAndroid Build Coastguard Worker * Layout qualifier for gl_FragDepth. See nir_depth_layout.
720*61046927SAndroid Build Coastguard Worker *
721*61046927SAndroid Build Coastguard Worker * This is not equal to ``ir_depth_layout_none`` if and only if this
722*61046927SAndroid Build Coastguard Worker * variable is ``gl_FragDepth`` and a layout qualifier is specified.
723*61046927SAndroid Build Coastguard Worker */
724*61046927SAndroid Build Coastguard Worker unsigned depth_layout : 3;
725*61046927SAndroid Build Coastguard Worker
726*61046927SAndroid Build Coastguard Worker /**
727*61046927SAndroid Build Coastguard Worker * Vertex stream output identifier.
728*61046927SAndroid Build Coastguard Worker *
729*61046927SAndroid Build Coastguard Worker * For packed outputs, NIR_STREAM_PACKED is set and bits [2*i+1,2*i]
730*61046927SAndroid Build Coastguard Worker * indicate the stream of the i-th component.
731*61046927SAndroid Build Coastguard Worker */
732*61046927SAndroid Build Coastguard Worker unsigned stream : 9;
733*61046927SAndroid Build Coastguard Worker
734*61046927SAndroid Build Coastguard Worker /**
735*61046927SAndroid Build Coastguard Worker * See gl_access_qualifier.
736*61046927SAndroid Build Coastguard Worker *
737*61046927SAndroid Build Coastguard Worker * Access flags for memory variables (SSBO/global), image uniforms, and
738*61046927SAndroid Build Coastguard Worker * bindless images in uniforms/inputs/outputs.
739*61046927SAndroid Build Coastguard Worker */
740*61046927SAndroid Build Coastguard Worker unsigned access : 9;
741*61046927SAndroid Build Coastguard Worker
742*61046927SAndroid Build Coastguard Worker /**
743*61046927SAndroid Build Coastguard Worker * Descriptor set binding for sampler or UBO.
744*61046927SAndroid Build Coastguard Worker */
745*61046927SAndroid Build Coastguard Worker unsigned descriptor_set : 5;
746*61046927SAndroid Build Coastguard Worker
747*61046927SAndroid Build Coastguard Worker /**
748*61046927SAndroid Build Coastguard Worker * output index for dual source blending.
749*61046927SAndroid Build Coastguard Worker */
750*61046927SAndroid Build Coastguard Worker unsigned index;
751*61046927SAndroid Build Coastguard Worker
752*61046927SAndroid Build Coastguard Worker /**
753*61046927SAndroid Build Coastguard Worker * Initial binding point for a sampler or UBO.
754*61046927SAndroid Build Coastguard Worker *
755*61046927SAndroid Build Coastguard Worker * For array types, this represents the binding point for the first element.
756*61046927SAndroid Build Coastguard Worker */
757*61046927SAndroid Build Coastguard Worker unsigned binding;
758*61046927SAndroid Build Coastguard Worker
759*61046927SAndroid Build Coastguard Worker /**
760*61046927SAndroid Build Coastguard Worker * Storage location of the base of this variable
761*61046927SAndroid Build Coastguard Worker *
762*61046927SAndroid Build Coastguard Worker * The precise meaning of this field depends on the nature of the variable.
763*61046927SAndroid Build Coastguard Worker *
764*61046927SAndroid Build Coastguard Worker * - Vertex shader input: one of the values from ``gl_vert_attrib``.
765*61046927SAndroid Build Coastguard Worker * - Vertex shader output: one of the values from ``gl_varying_slot``.
766*61046927SAndroid Build Coastguard Worker * - Geometry shader input: one of the values from ``gl_varying_slot``.
767*61046927SAndroid Build Coastguard Worker * - Geometry shader output: one of the values from ``gl_varying_slot``.
768*61046927SAndroid Build Coastguard Worker * - Fragment shader input: one of the values from ``gl_varying_slot``.
769*61046927SAndroid Build Coastguard Worker * - Fragment shader output: one of the values from ``gl_frag_result``.
770*61046927SAndroid Build Coastguard Worker * - Task shader output: one of the values from ``gl_varying_slot``.
771*61046927SAndroid Build Coastguard Worker * - Mesh shader input: one of the values from ``gl_varying_slot``.
772*61046927SAndroid Build Coastguard Worker * - Mesh shader output: one of the values from ``gl_varying_slot``.
773*61046927SAndroid Build Coastguard Worker * - Uniforms: Per-stage uniform slot number for default uniform block.
774*61046927SAndroid Build Coastguard Worker * - Uniforms: Index within the uniform block definition for UBO members.
775*61046927SAndroid Build Coastguard Worker * - Non-UBO Uniforms: uniform slot number.
776*61046927SAndroid Build Coastguard Worker * - Other: This field is not currently used.
777*61046927SAndroid Build Coastguard Worker *
778*61046927SAndroid Build Coastguard Worker * If the variable is a uniform, shader input, or shader output, and the
779*61046927SAndroid Build Coastguard Worker * slot has not been assigned, the value will be -1.
780*61046927SAndroid Build Coastguard Worker */
781*61046927SAndroid Build Coastguard Worker int location;
782*61046927SAndroid Build Coastguard Worker
783*61046927SAndroid Build Coastguard Worker /** Required alignment of this variable */
784*61046927SAndroid Build Coastguard Worker unsigned alignment;
785*61046927SAndroid Build Coastguard Worker
786*61046927SAndroid Build Coastguard Worker /**
787*61046927SAndroid Build Coastguard Worker * The actual location of the variable in the IR. Only valid for inputs,
788*61046927SAndroid Build Coastguard Worker * outputs, uniforms (including samplers and images), and for UBO and SSBO
789*61046927SAndroid Build Coastguard Worker * variables in GLSL.
790*61046927SAndroid Build Coastguard Worker */
791*61046927SAndroid Build Coastguard Worker unsigned driver_location;
792*61046927SAndroid Build Coastguard Worker
793*61046927SAndroid Build Coastguard Worker /**
794*61046927SAndroid Build Coastguard Worker * Location an atomic counter or transform feedback is stored at.
795*61046927SAndroid Build Coastguard Worker */
796*61046927SAndroid Build Coastguard Worker unsigned offset;
797*61046927SAndroid Build Coastguard Worker
798*61046927SAndroid Build Coastguard Worker union {
799*61046927SAndroid Build Coastguard Worker struct {
800*61046927SAndroid Build Coastguard Worker /** Image internal format if specified explicitly, otherwise PIPE_FORMAT_NONE. */
801*61046927SAndroid Build Coastguard Worker enum pipe_format format;
802*61046927SAndroid Build Coastguard Worker } image;
803*61046927SAndroid Build Coastguard Worker
804*61046927SAndroid Build Coastguard Worker struct {
805*61046927SAndroid Build Coastguard Worker /**
806*61046927SAndroid Build Coastguard Worker * For OpenCL inline samplers. See cl_sampler_addressing_mode and cl_sampler_filter_mode
807*61046927SAndroid Build Coastguard Worker */
808*61046927SAndroid Build Coastguard Worker unsigned is_inline_sampler : 1;
809*61046927SAndroid Build Coastguard Worker unsigned addressing_mode : 3;
810*61046927SAndroid Build Coastguard Worker unsigned normalized_coordinates : 1;
811*61046927SAndroid Build Coastguard Worker unsigned filter_mode : 1;
812*61046927SAndroid Build Coastguard Worker } sampler;
813*61046927SAndroid Build Coastguard Worker
814*61046927SAndroid Build Coastguard Worker struct {
815*61046927SAndroid Build Coastguard Worker /**
816*61046927SAndroid Build Coastguard Worker * Transform feedback buffer.
817*61046927SAndroid Build Coastguard Worker */
818*61046927SAndroid Build Coastguard Worker uint16_t buffer : 2;
819*61046927SAndroid Build Coastguard Worker
820*61046927SAndroid Build Coastguard Worker /**
821*61046927SAndroid Build Coastguard Worker * Transform feedback stride.
822*61046927SAndroid Build Coastguard Worker */
823*61046927SAndroid Build Coastguard Worker uint16_t stride;
824*61046927SAndroid Build Coastguard Worker } xfb;
825*61046927SAndroid Build Coastguard Worker };
826*61046927SAndroid Build Coastguard Worker
827*61046927SAndroid Build Coastguard Worker /** Name of the node this payload will be enqueued to. */
828*61046927SAndroid Build Coastguard Worker const char *node_name;
829*61046927SAndroid Build Coastguard Worker } data;
830*61046927SAndroid Build Coastguard Worker
831*61046927SAndroid Build Coastguard Worker /**
832*61046927SAndroid Build Coastguard Worker * Identifier for this variable generated by nir_index_vars() that is unique
833*61046927SAndroid Build Coastguard Worker * among other variables in the same exec_list.
834*61046927SAndroid Build Coastguard Worker */
835*61046927SAndroid Build Coastguard Worker unsigned index;
836*61046927SAndroid Build Coastguard Worker
837*61046927SAndroid Build Coastguard Worker /* Number of nir_variable_data members */
838*61046927SAndroid Build Coastguard Worker uint16_t num_members;
839*61046927SAndroid Build Coastguard Worker
840*61046927SAndroid Build Coastguard Worker /**
841*61046927SAndroid Build Coastguard Worker * Built-in state that backs this uniform
842*61046927SAndroid Build Coastguard Worker *
843*61046927SAndroid Build Coastguard Worker * Once set at variable creation, ``state_slots`` must remain invariant.
844*61046927SAndroid Build Coastguard Worker * This is because, ideally, this array would be shared by all clones of
845*61046927SAndroid Build Coastguard Worker * this variable in the IR tree. In other words, we'd really like for it
846*61046927SAndroid Build Coastguard Worker * to be a fly-weight.
847*61046927SAndroid Build Coastguard Worker *
848*61046927SAndroid Build Coastguard Worker * If the variable is not a uniform, ``num_state_slots`` will be zero and
849*61046927SAndroid Build Coastguard Worker * ``state_slots`` will be ``NULL``.
850*61046927SAndroid Build Coastguard Worker *
851*61046927SAndroid Build Coastguard Worker * Number of state slots used.
852*61046927SAndroid Build Coastguard Worker */
853*61046927SAndroid Build Coastguard Worker uint16_t num_state_slots;
854*61046927SAndroid Build Coastguard Worker /** State descriptors. */
855*61046927SAndroid Build Coastguard Worker nir_state_slot *state_slots;
856*61046927SAndroid Build Coastguard Worker
857*61046927SAndroid Build Coastguard Worker /**
858*61046927SAndroid Build Coastguard Worker * Constant expression assigned in the initializer of the variable
859*61046927SAndroid Build Coastguard Worker *
860*61046927SAndroid Build Coastguard Worker * This field should only be used temporarily by creators of NIR shaders
861*61046927SAndroid Build Coastguard Worker * and then nir_lower_variable_initializers can be used to get rid of them.
862*61046927SAndroid Build Coastguard Worker * Most of the rest of NIR ignores this field or asserts that it's NULL.
863*61046927SAndroid Build Coastguard Worker */
864*61046927SAndroid Build Coastguard Worker nir_constant *constant_initializer;
865*61046927SAndroid Build Coastguard Worker
866*61046927SAndroid Build Coastguard Worker /**
867*61046927SAndroid Build Coastguard Worker * Global variable assigned in the initializer of the variable
868*61046927SAndroid Build Coastguard Worker * This field should only be used temporarily by creators of NIR shaders
869*61046927SAndroid Build Coastguard Worker * and then nir_lower_variable_initializers can be used to get rid of them.
870*61046927SAndroid Build Coastguard Worker * Most of the rest of NIR ignores this field or asserts that it's NULL.
871*61046927SAndroid Build Coastguard Worker */
872*61046927SAndroid Build Coastguard Worker struct nir_variable *pointer_initializer;
873*61046927SAndroid Build Coastguard Worker
874*61046927SAndroid Build Coastguard Worker /**
875*61046927SAndroid Build Coastguard Worker * For variables that are in an interface block or are an instance of an
876*61046927SAndroid Build Coastguard Worker * interface block, this is the ``GLSL_TYPE_INTERFACE`` type for that block.
877*61046927SAndroid Build Coastguard Worker *
878*61046927SAndroid Build Coastguard Worker * ``ir_variable.location``
879*61046927SAndroid Build Coastguard Worker */
880*61046927SAndroid Build Coastguard Worker const struct glsl_type *interface_type;
881*61046927SAndroid Build Coastguard Worker
882*61046927SAndroid Build Coastguard Worker /**
883*61046927SAndroid Build Coastguard Worker * Description of per-member data for per-member struct variables
884*61046927SAndroid Build Coastguard Worker *
885*61046927SAndroid Build Coastguard Worker * This is used for variables which are actually an amalgamation of
886*61046927SAndroid Build Coastguard Worker * multiple entities such as a struct of built-in values or a struct of
887*61046927SAndroid Build Coastguard Worker * inputs each with their own layout specifier. This is only allowed on
888*61046927SAndroid Build Coastguard Worker * variables with a struct or array of array of struct type.
889*61046927SAndroid Build Coastguard Worker */
890*61046927SAndroid Build Coastguard Worker struct nir_variable_data *members;
891*61046927SAndroid Build Coastguard Worker } nir_variable;
892*61046927SAndroid Build Coastguard Worker
893*61046927SAndroid Build Coastguard Worker static inline bool
_nir_shader_variable_has_mode(nir_variable * var,unsigned modes)894*61046927SAndroid Build Coastguard Worker _nir_shader_variable_has_mode(nir_variable *var, unsigned modes)
895*61046927SAndroid Build Coastguard Worker {
896*61046927SAndroid Build Coastguard Worker /* This isn't a shader variable */
897*61046927SAndroid Build Coastguard Worker assert(!(modes & nir_var_function_temp));
898*61046927SAndroid Build Coastguard Worker return var->data.mode & modes;
899*61046927SAndroid Build Coastguard Worker }
900*61046927SAndroid Build Coastguard Worker
901*61046927SAndroid Build Coastguard Worker #define nir_foreach_variable_in_list(var, var_list) \
902*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_variable, var, node, var_list)
903*61046927SAndroid Build Coastguard Worker
904*61046927SAndroid Build Coastguard Worker #define nir_foreach_variable_in_list_safe(var, var_list) \
905*61046927SAndroid Build Coastguard Worker foreach_list_typed_safe(nir_variable, var, node, var_list)
906*61046927SAndroid Build Coastguard Worker
907*61046927SAndroid Build Coastguard Worker #define nir_foreach_variable_in_shader(var, shader) \
908*61046927SAndroid Build Coastguard Worker nir_foreach_variable_in_list(var, &(shader)->variables)
909*61046927SAndroid Build Coastguard Worker
910*61046927SAndroid Build Coastguard Worker #define nir_foreach_variable_in_shader_safe(var, shader) \
911*61046927SAndroid Build Coastguard Worker nir_foreach_variable_in_list_safe(var, &(shader)->variables)
912*61046927SAndroid Build Coastguard Worker
913*61046927SAndroid Build Coastguard Worker #define nir_foreach_variable_with_modes(var, shader, modes) \
914*61046927SAndroid Build Coastguard Worker nir_foreach_variable_in_shader(var, shader) \
915*61046927SAndroid Build Coastguard Worker if (_nir_shader_variable_has_mode(var, modes))
916*61046927SAndroid Build Coastguard Worker
917*61046927SAndroid Build Coastguard Worker #define nir_foreach_variable_with_modes_safe(var, shader, modes) \
918*61046927SAndroid Build Coastguard Worker nir_foreach_variable_in_shader_safe(var, shader) \
919*61046927SAndroid Build Coastguard Worker if (_nir_shader_variable_has_mode(var, modes))
920*61046927SAndroid Build Coastguard Worker
921*61046927SAndroid Build Coastguard Worker #define nir_foreach_shader_in_variable(var, shader) \
922*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes(var, shader, nir_var_shader_in)
923*61046927SAndroid Build Coastguard Worker
924*61046927SAndroid Build Coastguard Worker #define nir_foreach_shader_in_variable_safe(var, shader) \
925*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes_safe(var, shader, nir_var_shader_in)
926*61046927SAndroid Build Coastguard Worker
927*61046927SAndroid Build Coastguard Worker #define nir_foreach_shader_out_variable(var, shader) \
928*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes(var, shader, nir_var_shader_out)
929*61046927SAndroid Build Coastguard Worker
930*61046927SAndroid Build Coastguard Worker #define nir_foreach_shader_out_variable_safe(var, shader) \
931*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes_safe(var, shader, nir_var_shader_out)
932*61046927SAndroid Build Coastguard Worker
933*61046927SAndroid Build Coastguard Worker #define nir_foreach_uniform_variable(var, shader) \
934*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes(var, shader, nir_var_uniform)
935*61046927SAndroid Build Coastguard Worker
936*61046927SAndroid Build Coastguard Worker #define nir_foreach_uniform_variable_safe(var, shader) \
937*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes_safe(var, shader, nir_var_uniform)
938*61046927SAndroid Build Coastguard Worker
939*61046927SAndroid Build Coastguard Worker #define nir_foreach_image_variable(var, shader) \
940*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes(var, shader, nir_var_image)
941*61046927SAndroid Build Coastguard Worker
942*61046927SAndroid Build Coastguard Worker #define nir_foreach_image_variable_safe(var, shader) \
943*61046927SAndroid Build Coastguard Worker nir_foreach_variable_with_modes_safe(var, shader, nir_var_image)
944*61046927SAndroid Build Coastguard Worker
945*61046927SAndroid Build Coastguard Worker static inline bool
nir_variable_is_global(const nir_variable * var)946*61046927SAndroid Build Coastguard Worker nir_variable_is_global(const nir_variable *var)
947*61046927SAndroid Build Coastguard Worker {
948*61046927SAndroid Build Coastguard Worker return var->data.mode != nir_var_function_temp;
949*61046927SAndroid Build Coastguard Worker }
950*61046927SAndroid Build Coastguard Worker
951*61046927SAndroid Build Coastguard Worker typedef enum ENUM_PACKED {
952*61046927SAndroid Build Coastguard Worker nir_instr_type_alu,
953*61046927SAndroid Build Coastguard Worker nir_instr_type_deref,
954*61046927SAndroid Build Coastguard Worker nir_instr_type_call,
955*61046927SAndroid Build Coastguard Worker nir_instr_type_tex,
956*61046927SAndroid Build Coastguard Worker nir_instr_type_intrinsic,
957*61046927SAndroid Build Coastguard Worker nir_instr_type_load_const,
958*61046927SAndroid Build Coastguard Worker nir_instr_type_jump,
959*61046927SAndroid Build Coastguard Worker nir_instr_type_undef,
960*61046927SAndroid Build Coastguard Worker nir_instr_type_phi,
961*61046927SAndroid Build Coastguard Worker nir_instr_type_parallel_copy,
962*61046927SAndroid Build Coastguard Worker nir_instr_type_debug_info,
963*61046927SAndroid Build Coastguard Worker } nir_instr_type;
964*61046927SAndroid Build Coastguard Worker
965*61046927SAndroid Build Coastguard Worker typedef struct nir_instr {
966*61046927SAndroid Build Coastguard Worker struct exec_node node;
967*61046927SAndroid Build Coastguard Worker struct nir_block *block;
968*61046927SAndroid Build Coastguard Worker nir_instr_type type;
969*61046927SAndroid Build Coastguard Worker
970*61046927SAndroid Build Coastguard Worker /* A temporary for optimization and analysis passes to use for storing
971*61046927SAndroid Build Coastguard Worker * flags. For instance, DCE uses this to store the "dead/live" info.
972*61046927SAndroid Build Coastguard Worker */
973*61046927SAndroid Build Coastguard Worker uint8_t pass_flags;
974*61046927SAndroid Build Coastguard Worker
975*61046927SAndroid Build Coastguard Worker /** generic instruction index. */
976*61046927SAndroid Build Coastguard Worker uint32_t index;
977*61046927SAndroid Build Coastguard Worker } nir_instr;
978*61046927SAndroid Build Coastguard Worker
979*61046927SAndroid Build Coastguard Worker static inline nir_instr *
nir_instr_next(nir_instr * instr)980*61046927SAndroid Build Coastguard Worker nir_instr_next(nir_instr *instr)
981*61046927SAndroid Build Coastguard Worker {
982*61046927SAndroid Build Coastguard Worker struct exec_node *next = exec_node_get_next(&instr->node);
983*61046927SAndroid Build Coastguard Worker if (exec_node_is_tail_sentinel(next))
984*61046927SAndroid Build Coastguard Worker return NULL;
985*61046927SAndroid Build Coastguard Worker else
986*61046927SAndroid Build Coastguard Worker return exec_node_data(nir_instr, next, node);
987*61046927SAndroid Build Coastguard Worker }
988*61046927SAndroid Build Coastguard Worker
989*61046927SAndroid Build Coastguard Worker static inline nir_instr *
nir_instr_prev(nir_instr * instr)990*61046927SAndroid Build Coastguard Worker nir_instr_prev(nir_instr *instr)
991*61046927SAndroid Build Coastguard Worker {
992*61046927SAndroid Build Coastguard Worker struct exec_node *prev = exec_node_get_prev(&instr->node);
993*61046927SAndroid Build Coastguard Worker if (exec_node_is_head_sentinel(prev))
994*61046927SAndroid Build Coastguard Worker return NULL;
995*61046927SAndroid Build Coastguard Worker else
996*61046927SAndroid Build Coastguard Worker return exec_node_data(nir_instr, prev, node);
997*61046927SAndroid Build Coastguard Worker }
998*61046927SAndroid Build Coastguard Worker
999*61046927SAndroid Build Coastguard Worker static inline bool
nir_instr_is_first(const nir_instr * instr)1000*61046927SAndroid Build Coastguard Worker nir_instr_is_first(const nir_instr *instr)
1001*61046927SAndroid Build Coastguard Worker {
1002*61046927SAndroid Build Coastguard Worker return exec_node_is_head_sentinel(exec_node_get_prev_const(&instr->node));
1003*61046927SAndroid Build Coastguard Worker }
1004*61046927SAndroid Build Coastguard Worker
1005*61046927SAndroid Build Coastguard Worker static inline bool
nir_instr_is_last(const nir_instr * instr)1006*61046927SAndroid Build Coastguard Worker nir_instr_is_last(const nir_instr *instr)
1007*61046927SAndroid Build Coastguard Worker {
1008*61046927SAndroid Build Coastguard Worker return exec_node_is_tail_sentinel(exec_node_get_next_const(&instr->node));
1009*61046927SAndroid Build Coastguard Worker }
1010*61046927SAndroid Build Coastguard Worker
1011*61046927SAndroid Build Coastguard Worker typedef struct nir_def {
1012*61046927SAndroid Build Coastguard Worker /** Instruction which produces this SSA value. */
1013*61046927SAndroid Build Coastguard Worker nir_instr *parent_instr;
1014*61046927SAndroid Build Coastguard Worker
1015*61046927SAndroid Build Coastguard Worker /** set of nir_instrs where this register is used (read from) */
1016*61046927SAndroid Build Coastguard Worker struct list_head uses;
1017*61046927SAndroid Build Coastguard Worker
1018*61046927SAndroid Build Coastguard Worker /** generic SSA definition index. */
1019*61046927SAndroid Build Coastguard Worker unsigned index;
1020*61046927SAndroid Build Coastguard Worker
1021*61046927SAndroid Build Coastguard Worker uint8_t num_components;
1022*61046927SAndroid Build Coastguard Worker
1023*61046927SAndroid Build Coastguard Worker /* The bit-size of each channel; must be one of 1, 8, 16, 32, or 64 */
1024*61046927SAndroid Build Coastguard Worker uint8_t bit_size;
1025*61046927SAndroid Build Coastguard Worker
1026*61046927SAndroid Build Coastguard Worker /**
1027*61046927SAndroid Build Coastguard Worker * True if this SSA value may have different values in different SIMD
1028*61046927SAndroid Build Coastguard Worker * invocations of the shader. This is set by nir_divergence_analysis.
1029*61046927SAndroid Build Coastguard Worker */
1030*61046927SAndroid Build Coastguard Worker bool divergent;
1031*61046927SAndroid Build Coastguard Worker } nir_def;
1032*61046927SAndroid Build Coastguard Worker
1033*61046927SAndroid Build Coastguard Worker struct nir_src;
1034*61046927SAndroid Build Coastguard Worker struct nir_if;
1035*61046927SAndroid Build Coastguard Worker
1036*61046927SAndroid Build Coastguard Worker typedef struct nir_src {
1037*61046927SAndroid Build Coastguard Worker /* Instruction or if-statement that consumes this value as a source. This
1038*61046927SAndroid Build Coastguard Worker * should only be accessed through nir_src_* helpers.
1039*61046927SAndroid Build Coastguard Worker *
1040*61046927SAndroid Build Coastguard Worker * Internally, it is a tagged pointer to a nir_instr or nir_if.
1041*61046927SAndroid Build Coastguard Worker */
1042*61046927SAndroid Build Coastguard Worker uintptr_t _parent;
1043*61046927SAndroid Build Coastguard Worker
1044*61046927SAndroid Build Coastguard Worker struct list_head use_link;
1045*61046927SAndroid Build Coastguard Worker nir_def *ssa;
1046*61046927SAndroid Build Coastguard Worker } nir_src;
1047*61046927SAndroid Build Coastguard Worker
1048*61046927SAndroid Build Coastguard Worker /* Layout of the _parent pointer. Bottom bit is set for nir_if parents (clear
1049*61046927SAndroid Build Coastguard Worker * for nir_instr parents). Remaining bits are the pointer.
1050*61046927SAndroid Build Coastguard Worker */
1051*61046927SAndroid Build Coastguard Worker #define NIR_SRC_PARENT_IS_IF (0x1)
1052*61046927SAndroid Build Coastguard Worker #define NIR_SRC_PARENT_MASK (~((uintptr_t) NIR_SRC_PARENT_IS_IF))
1053*61046927SAndroid Build Coastguard Worker
1054*61046927SAndroid Build Coastguard Worker static inline bool
nir_src_is_if(const nir_src * src)1055*61046927SAndroid Build Coastguard Worker nir_src_is_if(const nir_src *src)
1056*61046927SAndroid Build Coastguard Worker {
1057*61046927SAndroid Build Coastguard Worker return src->_parent & NIR_SRC_PARENT_IS_IF;
1058*61046927SAndroid Build Coastguard Worker }
1059*61046927SAndroid Build Coastguard Worker
1060*61046927SAndroid Build Coastguard Worker static inline nir_instr *
nir_src_parent_instr(const nir_src * src)1061*61046927SAndroid Build Coastguard Worker nir_src_parent_instr(const nir_src *src)
1062*61046927SAndroid Build Coastguard Worker {
1063*61046927SAndroid Build Coastguard Worker assert(!nir_src_is_if(src));
1064*61046927SAndroid Build Coastguard Worker
1065*61046927SAndroid Build Coastguard Worker /* Because it is not an if, the tag is 0, therefore we do not need to mask */
1066*61046927SAndroid Build Coastguard Worker return (nir_instr *)(src->_parent);
1067*61046927SAndroid Build Coastguard Worker }
1068*61046927SAndroid Build Coastguard Worker
1069*61046927SAndroid Build Coastguard Worker static inline struct nir_if *
nir_src_parent_if(const nir_src * src)1070*61046927SAndroid Build Coastguard Worker nir_src_parent_if(const nir_src *src)
1071*61046927SAndroid Build Coastguard Worker {
1072*61046927SAndroid Build Coastguard Worker assert(nir_src_is_if(src));
1073*61046927SAndroid Build Coastguard Worker
1074*61046927SAndroid Build Coastguard Worker /* Because it is an if, the tag is 1, so we need to mask */
1075*61046927SAndroid Build Coastguard Worker return (struct nir_if *)(src->_parent & NIR_SRC_PARENT_MASK);
1076*61046927SAndroid Build Coastguard Worker }
1077*61046927SAndroid Build Coastguard Worker
1078*61046927SAndroid Build Coastguard Worker static inline void
_nir_src_set_parent(nir_src * src,void * parent,bool is_if)1079*61046927SAndroid Build Coastguard Worker _nir_src_set_parent(nir_src *src, void *parent, bool is_if)
1080*61046927SAndroid Build Coastguard Worker {
1081*61046927SAndroid Build Coastguard Worker uintptr_t ptr = (uintptr_t) parent;
1082*61046927SAndroid Build Coastguard Worker assert((ptr & ~NIR_SRC_PARENT_MASK) == 0 && "pointer must be aligned");
1083*61046927SAndroid Build Coastguard Worker
1084*61046927SAndroid Build Coastguard Worker if (is_if)
1085*61046927SAndroid Build Coastguard Worker ptr |= NIR_SRC_PARENT_IS_IF;
1086*61046927SAndroid Build Coastguard Worker
1087*61046927SAndroid Build Coastguard Worker src->_parent = ptr;
1088*61046927SAndroid Build Coastguard Worker }
1089*61046927SAndroid Build Coastguard Worker
1090*61046927SAndroid Build Coastguard Worker static inline void
nir_src_set_parent_instr(nir_src * src,nir_instr * parent_instr)1091*61046927SAndroid Build Coastguard Worker nir_src_set_parent_instr(nir_src *src, nir_instr *parent_instr)
1092*61046927SAndroid Build Coastguard Worker {
1093*61046927SAndroid Build Coastguard Worker _nir_src_set_parent(src, parent_instr, false);
1094*61046927SAndroid Build Coastguard Worker }
1095*61046927SAndroid Build Coastguard Worker
1096*61046927SAndroid Build Coastguard Worker static inline void
nir_src_set_parent_if(nir_src * src,struct nir_if * parent_if)1097*61046927SAndroid Build Coastguard Worker nir_src_set_parent_if(nir_src *src, struct nir_if *parent_if)
1098*61046927SAndroid Build Coastguard Worker {
1099*61046927SAndroid Build Coastguard Worker _nir_src_set_parent(src, parent_if, true);
1100*61046927SAndroid Build Coastguard Worker }
1101*61046927SAndroid Build Coastguard Worker
1102*61046927SAndroid Build Coastguard Worker static inline nir_src
nir_src_init(void)1103*61046927SAndroid Build Coastguard Worker nir_src_init(void)
1104*61046927SAndroid Build Coastguard Worker {
1105*61046927SAndroid Build Coastguard Worker nir_src src = { 0 };
1106*61046927SAndroid Build Coastguard Worker return src;
1107*61046927SAndroid Build Coastguard Worker }
1108*61046927SAndroid Build Coastguard Worker
1109*61046927SAndroid Build Coastguard Worker #define NIR_SRC_INIT nir_src_init()
1110*61046927SAndroid Build Coastguard Worker
1111*61046927SAndroid Build Coastguard Worker #define nir_foreach_use_including_if(src, reg_or_ssa_def) \
1112*61046927SAndroid Build Coastguard Worker list_for_each_entry(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
1113*61046927SAndroid Build Coastguard Worker
1114*61046927SAndroid Build Coastguard Worker #define nir_foreach_use_including_if_safe(src, reg_or_ssa_def) \
1115*61046927SAndroid Build Coastguard Worker list_for_each_entry_safe(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
1116*61046927SAndroid Build Coastguard Worker
1117*61046927SAndroid Build Coastguard Worker #define nir_foreach_use(src, reg_or_ssa_def) \
1118*61046927SAndroid Build Coastguard Worker nir_foreach_use_including_if(src, reg_or_ssa_def) \
1119*61046927SAndroid Build Coastguard Worker if (!nir_src_is_if(src))
1120*61046927SAndroid Build Coastguard Worker
1121*61046927SAndroid Build Coastguard Worker #define nir_foreach_use_safe(src, reg_or_ssa_def) \
1122*61046927SAndroid Build Coastguard Worker nir_foreach_use_including_if_safe(src, reg_or_ssa_def) \
1123*61046927SAndroid Build Coastguard Worker if (!nir_src_is_if(src))
1124*61046927SAndroid Build Coastguard Worker
1125*61046927SAndroid Build Coastguard Worker #define nir_foreach_if_use(src, reg_or_ssa_def) \
1126*61046927SAndroid Build Coastguard Worker nir_foreach_use_including_if(src, reg_or_ssa_def) \
1127*61046927SAndroid Build Coastguard Worker if (nir_src_is_if(src))
1128*61046927SAndroid Build Coastguard Worker
1129*61046927SAndroid Build Coastguard Worker #define nir_foreach_if_use_safe(src, reg_or_ssa_def) \
1130*61046927SAndroid Build Coastguard Worker nir_foreach_use_including_if_safe(src, reg_or_ssa_def) \
1131*61046927SAndroid Build Coastguard Worker if (nir_src_is_if(src))
1132*61046927SAndroid Build Coastguard Worker
1133*61046927SAndroid Build Coastguard Worker static inline bool
nir_def_used_by_if(const nir_def * def)1134*61046927SAndroid Build Coastguard Worker nir_def_used_by_if(const nir_def *def)
1135*61046927SAndroid Build Coastguard Worker {
1136*61046927SAndroid Build Coastguard Worker nir_foreach_if_use(_, def)
1137*61046927SAndroid Build Coastguard Worker return true;
1138*61046927SAndroid Build Coastguard Worker
1139*61046927SAndroid Build Coastguard Worker return false;
1140*61046927SAndroid Build Coastguard Worker }
1141*61046927SAndroid Build Coastguard Worker
1142*61046927SAndroid Build Coastguard Worker static inline bool
nir_def_only_used_by_if(const nir_def * def)1143*61046927SAndroid Build Coastguard Worker nir_def_only_used_by_if(const nir_def *def)
1144*61046927SAndroid Build Coastguard Worker {
1145*61046927SAndroid Build Coastguard Worker nir_foreach_use(_, def)
1146*61046927SAndroid Build Coastguard Worker return false;
1147*61046927SAndroid Build Coastguard Worker
1148*61046927SAndroid Build Coastguard Worker return true;
1149*61046927SAndroid Build Coastguard Worker }
1150*61046927SAndroid Build Coastguard Worker
1151*61046927SAndroid Build Coastguard Worker static inline nir_src
nir_src_for_ssa(nir_def * def)1152*61046927SAndroid Build Coastguard Worker nir_src_for_ssa(nir_def *def)
1153*61046927SAndroid Build Coastguard Worker {
1154*61046927SAndroid Build Coastguard Worker nir_src src = NIR_SRC_INIT;
1155*61046927SAndroid Build Coastguard Worker
1156*61046927SAndroid Build Coastguard Worker src.ssa = def;
1157*61046927SAndroid Build Coastguard Worker
1158*61046927SAndroid Build Coastguard Worker return src;
1159*61046927SAndroid Build Coastguard Worker }
1160*61046927SAndroid Build Coastguard Worker
1161*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_src_bit_size(nir_src src)1162*61046927SAndroid Build Coastguard Worker nir_src_bit_size(nir_src src)
1163*61046927SAndroid Build Coastguard Worker {
1164*61046927SAndroid Build Coastguard Worker return src.ssa->bit_size;
1165*61046927SAndroid Build Coastguard Worker }
1166*61046927SAndroid Build Coastguard Worker
1167*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_src_num_components(nir_src src)1168*61046927SAndroid Build Coastguard Worker nir_src_num_components(nir_src src)
1169*61046927SAndroid Build Coastguard Worker {
1170*61046927SAndroid Build Coastguard Worker return src.ssa->num_components;
1171*61046927SAndroid Build Coastguard Worker }
1172*61046927SAndroid Build Coastguard Worker
1173*61046927SAndroid Build Coastguard Worker static inline bool
nir_src_is_const(nir_src src)1174*61046927SAndroid Build Coastguard Worker nir_src_is_const(nir_src src)
1175*61046927SAndroid Build Coastguard Worker {
1176*61046927SAndroid Build Coastguard Worker return src.ssa->parent_instr->type == nir_instr_type_load_const;
1177*61046927SAndroid Build Coastguard Worker }
1178*61046927SAndroid Build Coastguard Worker
1179*61046927SAndroid Build Coastguard Worker static inline bool
nir_src_is_undef(nir_src src)1180*61046927SAndroid Build Coastguard Worker nir_src_is_undef(nir_src src)
1181*61046927SAndroid Build Coastguard Worker {
1182*61046927SAndroid Build Coastguard Worker return src.ssa->parent_instr->type == nir_instr_type_undef;
1183*61046927SAndroid Build Coastguard Worker }
1184*61046927SAndroid Build Coastguard Worker
1185*61046927SAndroid Build Coastguard Worker static inline bool
nir_src_is_divergent(nir_src src)1186*61046927SAndroid Build Coastguard Worker nir_src_is_divergent(nir_src src)
1187*61046927SAndroid Build Coastguard Worker {
1188*61046927SAndroid Build Coastguard Worker return src.ssa->divergent;
1189*61046927SAndroid Build Coastguard Worker }
1190*61046927SAndroid Build Coastguard Worker
1191*61046927SAndroid Build Coastguard Worker /* Are all components the same, ie. .xxxx */
1192*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_same_comp_swizzle(uint8_t * swiz,unsigned nr_comp)1193*61046927SAndroid Build Coastguard Worker nir_is_same_comp_swizzle(uint8_t *swiz, unsigned nr_comp)
1194*61046927SAndroid Build Coastguard Worker {
1195*61046927SAndroid Build Coastguard Worker for (unsigned i = 1; i < nr_comp; i++)
1196*61046927SAndroid Build Coastguard Worker if (swiz[i] != swiz[0])
1197*61046927SAndroid Build Coastguard Worker return false;
1198*61046927SAndroid Build Coastguard Worker return true;
1199*61046927SAndroid Build Coastguard Worker }
1200*61046927SAndroid Build Coastguard Worker
1201*61046927SAndroid Build Coastguard Worker /* Are all components sequential, ie. .yzw */
1202*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_sequential_comp_swizzle(uint8_t * swiz,unsigned nr_comp)1203*61046927SAndroid Build Coastguard Worker nir_is_sequential_comp_swizzle(uint8_t *swiz, unsigned nr_comp)
1204*61046927SAndroid Build Coastguard Worker {
1205*61046927SAndroid Build Coastguard Worker for (unsigned i = 1; i < nr_comp; i++)
1206*61046927SAndroid Build Coastguard Worker if (swiz[i] != (swiz[0] + i))
1207*61046927SAndroid Build Coastguard Worker return false;
1208*61046927SAndroid Build Coastguard Worker return true;
1209*61046927SAndroid Build Coastguard Worker }
1210*61046927SAndroid Build Coastguard Worker
1211*61046927SAndroid Build Coastguard Worker /***/
1212*61046927SAndroid Build Coastguard Worker typedef struct nir_alu_src {
1213*61046927SAndroid Build Coastguard Worker /** Base source */
1214*61046927SAndroid Build Coastguard Worker nir_src src;
1215*61046927SAndroid Build Coastguard Worker
1216*61046927SAndroid Build Coastguard Worker /**
1217*61046927SAndroid Build Coastguard Worker * For each input component, says which component of the register it is
1218*61046927SAndroid Build Coastguard Worker * chosen from.
1219*61046927SAndroid Build Coastguard Worker *
1220*61046927SAndroid Build Coastguard Worker * Note that which elements of the swizzle are used and which are ignored
1221*61046927SAndroid Build Coastguard Worker * are based on the write mask for most opcodes - for example, a statement
1222*61046927SAndroid Build Coastguard Worker * like "foo.xzw = bar.zyx" would have a writemask of 1101b and a swizzle
1223*61046927SAndroid Build Coastguard Worker * of {2, 1, x, 0} where x means "don't care."
1224*61046927SAndroid Build Coastguard Worker */
1225*61046927SAndroid Build Coastguard Worker uint8_t swizzle[NIR_MAX_VEC_COMPONENTS];
1226*61046927SAndroid Build Coastguard Worker } nir_alu_src;
1227*61046927SAndroid Build Coastguard Worker
1228*61046927SAndroid Build Coastguard Worker /** NIR sized and unsized types
1229*61046927SAndroid Build Coastguard Worker *
1230*61046927SAndroid Build Coastguard Worker * The values in this enum are carefully chosen so that the sized type is
1231*61046927SAndroid Build Coastguard Worker * just the unsized type OR the number of bits.
1232*61046927SAndroid Build Coastguard Worker */
1233*61046927SAndroid Build Coastguard Worker /* clang-format off */
1234*61046927SAndroid Build Coastguard Worker typedef enum ENUM_PACKED {
1235*61046927SAndroid Build Coastguard Worker nir_type_invalid = 0, /* Not a valid type */
1236*61046927SAndroid Build Coastguard Worker nir_type_int = 2,
1237*61046927SAndroid Build Coastguard Worker nir_type_uint = 4,
1238*61046927SAndroid Build Coastguard Worker nir_type_bool = 6,
1239*61046927SAndroid Build Coastguard Worker nir_type_float = 128,
1240*61046927SAndroid Build Coastguard Worker nir_type_bool1 = 1 | nir_type_bool,
1241*61046927SAndroid Build Coastguard Worker nir_type_bool8 = 8 | nir_type_bool,
1242*61046927SAndroid Build Coastguard Worker nir_type_bool16 = 16 | nir_type_bool,
1243*61046927SAndroid Build Coastguard Worker nir_type_bool32 = 32 | nir_type_bool,
1244*61046927SAndroid Build Coastguard Worker nir_type_int1 = 1 | nir_type_int,
1245*61046927SAndroid Build Coastguard Worker nir_type_int8 = 8 | nir_type_int,
1246*61046927SAndroid Build Coastguard Worker nir_type_int16 = 16 | nir_type_int,
1247*61046927SAndroid Build Coastguard Worker nir_type_int32 = 32 | nir_type_int,
1248*61046927SAndroid Build Coastguard Worker nir_type_int64 = 64 | nir_type_int,
1249*61046927SAndroid Build Coastguard Worker nir_type_uint1 = 1 | nir_type_uint,
1250*61046927SAndroid Build Coastguard Worker nir_type_uint8 = 8 | nir_type_uint,
1251*61046927SAndroid Build Coastguard Worker nir_type_uint16 = 16 | nir_type_uint,
1252*61046927SAndroid Build Coastguard Worker nir_type_uint32 = 32 | nir_type_uint,
1253*61046927SAndroid Build Coastguard Worker nir_type_uint64 = 64 | nir_type_uint,
1254*61046927SAndroid Build Coastguard Worker nir_type_float16 = 16 | nir_type_float,
1255*61046927SAndroid Build Coastguard Worker nir_type_float32 = 32 | nir_type_float,
1256*61046927SAndroid Build Coastguard Worker nir_type_float64 = 64 | nir_type_float,
1257*61046927SAndroid Build Coastguard Worker } nir_alu_type;
1258*61046927SAndroid Build Coastguard Worker /* clang-format on */
1259*61046927SAndroid Build Coastguard Worker
1260*61046927SAndroid Build Coastguard Worker #define NIR_ALU_TYPE_SIZE_MASK 0x79
1261*61046927SAndroid Build Coastguard Worker #define NIR_ALU_TYPE_BASE_TYPE_MASK 0x86
1262*61046927SAndroid Build Coastguard Worker
1263*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_alu_type_get_type_size(nir_alu_type type)1264*61046927SAndroid Build Coastguard Worker nir_alu_type_get_type_size(nir_alu_type type)
1265*61046927SAndroid Build Coastguard Worker {
1266*61046927SAndroid Build Coastguard Worker return type & NIR_ALU_TYPE_SIZE_MASK;
1267*61046927SAndroid Build Coastguard Worker }
1268*61046927SAndroid Build Coastguard Worker
1269*61046927SAndroid Build Coastguard Worker static inline nir_alu_type
nir_alu_type_get_base_type(nir_alu_type type)1270*61046927SAndroid Build Coastguard Worker nir_alu_type_get_base_type(nir_alu_type type)
1271*61046927SAndroid Build Coastguard Worker {
1272*61046927SAndroid Build Coastguard Worker return (nir_alu_type)(type & NIR_ALU_TYPE_BASE_TYPE_MASK);
1273*61046927SAndroid Build Coastguard Worker }
1274*61046927SAndroid Build Coastguard Worker
1275*61046927SAndroid Build Coastguard Worker nir_alu_type
1276*61046927SAndroid Build Coastguard Worker nir_get_nir_type_for_glsl_base_type(enum glsl_base_type base_type);
1277*61046927SAndroid Build Coastguard Worker
1278*61046927SAndroid Build Coastguard Worker static inline nir_alu_type
nir_get_nir_type_for_glsl_type(const struct glsl_type * type)1279*61046927SAndroid Build Coastguard Worker nir_get_nir_type_for_glsl_type(const struct glsl_type *type)
1280*61046927SAndroid Build Coastguard Worker {
1281*61046927SAndroid Build Coastguard Worker return nir_get_nir_type_for_glsl_base_type(glsl_get_base_type(type));
1282*61046927SAndroid Build Coastguard Worker }
1283*61046927SAndroid Build Coastguard Worker
1284*61046927SAndroid Build Coastguard Worker enum glsl_base_type
1285*61046927SAndroid Build Coastguard Worker nir_get_glsl_base_type_for_nir_type(nir_alu_type base_type);
1286*61046927SAndroid Build Coastguard Worker
1287*61046927SAndroid Build Coastguard Worker nir_op nir_type_conversion_op(nir_alu_type src, nir_alu_type dst,
1288*61046927SAndroid Build Coastguard Worker nir_rounding_mode rnd);
1289*61046927SAndroid Build Coastguard Worker
1290*61046927SAndroid Build Coastguard Worker /**
1291*61046927SAndroid Build Coastguard Worker * Atomic intrinsics perform different operations depending on the value of
1292*61046927SAndroid Build Coastguard Worker * their atomic_op constant index. nir_atomic_op defines the operations.
1293*61046927SAndroid Build Coastguard Worker */
1294*61046927SAndroid Build Coastguard Worker typedef enum {
1295*61046927SAndroid Build Coastguard Worker nir_atomic_op_iadd,
1296*61046927SAndroid Build Coastguard Worker nir_atomic_op_imin,
1297*61046927SAndroid Build Coastguard Worker nir_atomic_op_umin,
1298*61046927SAndroid Build Coastguard Worker nir_atomic_op_imax,
1299*61046927SAndroid Build Coastguard Worker nir_atomic_op_umax,
1300*61046927SAndroid Build Coastguard Worker nir_atomic_op_iand,
1301*61046927SAndroid Build Coastguard Worker nir_atomic_op_ior,
1302*61046927SAndroid Build Coastguard Worker nir_atomic_op_ixor,
1303*61046927SAndroid Build Coastguard Worker nir_atomic_op_xchg,
1304*61046927SAndroid Build Coastguard Worker nir_atomic_op_fadd,
1305*61046927SAndroid Build Coastguard Worker nir_atomic_op_fmin,
1306*61046927SAndroid Build Coastguard Worker nir_atomic_op_fmax,
1307*61046927SAndroid Build Coastguard Worker nir_atomic_op_cmpxchg,
1308*61046927SAndroid Build Coastguard Worker nir_atomic_op_fcmpxchg,
1309*61046927SAndroid Build Coastguard Worker nir_atomic_op_inc_wrap,
1310*61046927SAndroid Build Coastguard Worker nir_atomic_op_dec_wrap,
1311*61046927SAndroid Build Coastguard Worker nir_atomic_op_ordered_add_gfx12_amd,
1312*61046927SAndroid Build Coastguard Worker } nir_atomic_op;
1313*61046927SAndroid Build Coastguard Worker
1314*61046927SAndroid Build Coastguard Worker static inline nir_alu_type
nir_atomic_op_type(nir_atomic_op op)1315*61046927SAndroid Build Coastguard Worker nir_atomic_op_type(nir_atomic_op op)
1316*61046927SAndroid Build Coastguard Worker {
1317*61046927SAndroid Build Coastguard Worker switch (op) {
1318*61046927SAndroid Build Coastguard Worker case nir_atomic_op_imin:
1319*61046927SAndroid Build Coastguard Worker case nir_atomic_op_imax:
1320*61046927SAndroid Build Coastguard Worker return nir_type_int;
1321*61046927SAndroid Build Coastguard Worker
1322*61046927SAndroid Build Coastguard Worker case nir_atomic_op_fadd:
1323*61046927SAndroid Build Coastguard Worker case nir_atomic_op_fmin:
1324*61046927SAndroid Build Coastguard Worker case nir_atomic_op_fmax:
1325*61046927SAndroid Build Coastguard Worker case nir_atomic_op_fcmpxchg:
1326*61046927SAndroid Build Coastguard Worker return nir_type_float;
1327*61046927SAndroid Build Coastguard Worker
1328*61046927SAndroid Build Coastguard Worker case nir_atomic_op_iadd:
1329*61046927SAndroid Build Coastguard Worker case nir_atomic_op_iand:
1330*61046927SAndroid Build Coastguard Worker case nir_atomic_op_ior:
1331*61046927SAndroid Build Coastguard Worker case nir_atomic_op_ixor:
1332*61046927SAndroid Build Coastguard Worker case nir_atomic_op_xchg:
1333*61046927SAndroid Build Coastguard Worker case nir_atomic_op_cmpxchg:
1334*61046927SAndroid Build Coastguard Worker case nir_atomic_op_umin:
1335*61046927SAndroid Build Coastguard Worker case nir_atomic_op_umax:
1336*61046927SAndroid Build Coastguard Worker case nir_atomic_op_inc_wrap:
1337*61046927SAndroid Build Coastguard Worker case nir_atomic_op_dec_wrap:
1338*61046927SAndroid Build Coastguard Worker case nir_atomic_op_ordered_add_gfx12_amd:
1339*61046927SAndroid Build Coastguard Worker return nir_type_uint;
1340*61046927SAndroid Build Coastguard Worker }
1341*61046927SAndroid Build Coastguard Worker
1342*61046927SAndroid Build Coastguard Worker unreachable("Invalid nir_atomic_op");
1343*61046927SAndroid Build Coastguard Worker }
1344*61046927SAndroid Build Coastguard Worker
1345*61046927SAndroid Build Coastguard Worker /** Returns nir_op_vec<num_components> or nir_op_mov if num_components == 1
1346*61046927SAndroid Build Coastguard Worker *
1347*61046927SAndroid Build Coastguard Worker * This is subtly different from nir_op_is_vec() which returns false for
1348*61046927SAndroid Build Coastguard Worker * nir_op_mov. Returning nir_op_mov from nir_op_vec() when num_components == 1
1349*61046927SAndroid Build Coastguard Worker * makes sense under the assumption that the num_components of the resulting
1350*61046927SAndroid Build Coastguard Worker * nir_def will same as what is passed in here because a single-component mov
1351*61046927SAndroid Build Coastguard Worker * is effectively a vec1. However, if alu->def.num_components > 1, nir_op_mov
1352*61046927SAndroid Build Coastguard Worker * has different semantics from nir_op_vec* so so code which detects "is this
1353*61046927SAndroid Build Coastguard Worker * a vec?" typically needs to handle nir_op_mov separate from nir_op_vecN.
1354*61046927SAndroid Build Coastguard Worker *
1355*61046927SAndroid Build Coastguard Worker * In the unlikely case where you can handle nir_op_vecN and nir_op_mov
1356*61046927SAndroid Build Coastguard Worker * together, use nir_op_is_vec_or_mov().
1357*61046927SAndroid Build Coastguard Worker */
1358*61046927SAndroid Build Coastguard Worker nir_op
1359*61046927SAndroid Build Coastguard Worker nir_op_vec(unsigned num_components);
1360*61046927SAndroid Build Coastguard Worker
1361*61046927SAndroid Build Coastguard Worker /** Returns true if this op is one of nir_op_vec*
1362*61046927SAndroid Build Coastguard Worker *
1363*61046927SAndroid Build Coastguard Worker * Returns false for nir_op_mov. See nir_op_vec() for more details.
1364*61046927SAndroid Build Coastguard Worker */
1365*61046927SAndroid Build Coastguard Worker bool
1366*61046927SAndroid Build Coastguard Worker nir_op_is_vec(nir_op op);
1367*61046927SAndroid Build Coastguard Worker
1368*61046927SAndroid Build Coastguard Worker static inline bool
nir_op_is_vec_or_mov(nir_op op)1369*61046927SAndroid Build Coastguard Worker nir_op_is_vec_or_mov(nir_op op)
1370*61046927SAndroid Build Coastguard Worker {
1371*61046927SAndroid Build Coastguard Worker return op == nir_op_mov || nir_op_is_vec(op);
1372*61046927SAndroid Build Coastguard Worker }
1373*61046927SAndroid Build Coastguard Worker
1374*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_float_control_signed_zero_preserve(unsigned execution_mode,unsigned bit_size)1375*61046927SAndroid Build Coastguard Worker nir_is_float_control_signed_zero_preserve(unsigned execution_mode, unsigned bit_size)
1376*61046927SAndroid Build Coastguard Worker {
1377*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_PRESERVE_FP16) ||
1378*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_PRESERVE_FP32) ||
1379*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_PRESERVE_FP64);
1380*61046927SAndroid Build Coastguard Worker }
1381*61046927SAndroid Build Coastguard Worker
1382*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_float_control_inf_preserve(unsigned execution_mode,unsigned bit_size)1383*61046927SAndroid Build Coastguard Worker nir_is_float_control_inf_preserve(unsigned execution_mode, unsigned bit_size)
1384*61046927SAndroid Build Coastguard Worker {
1385*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_INF_PRESERVE_FP16) ||
1386*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_INF_PRESERVE_FP32) ||
1387*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_INF_PRESERVE_FP64);
1388*61046927SAndroid Build Coastguard Worker }
1389*61046927SAndroid Build Coastguard Worker
1390*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_float_control_nan_preserve(unsigned execution_mode,unsigned bit_size)1391*61046927SAndroid Build Coastguard Worker nir_is_float_control_nan_preserve(unsigned execution_mode, unsigned bit_size)
1392*61046927SAndroid Build Coastguard Worker {
1393*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_NAN_PRESERVE_FP16) ||
1394*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_NAN_PRESERVE_FP32) ||
1395*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_NAN_PRESERVE_FP64);
1396*61046927SAndroid Build Coastguard Worker }
1397*61046927SAndroid Build Coastguard Worker
1398*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_float_control_signed_zero_inf_nan_preserve(unsigned execution_mode,unsigned bit_size)1399*61046927SAndroid Build Coastguard Worker nir_is_float_control_signed_zero_inf_nan_preserve(unsigned execution_mode, unsigned bit_size)
1400*61046927SAndroid Build Coastguard Worker {
1401*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP16) ||
1402*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP32) ||
1403*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP64);
1404*61046927SAndroid Build Coastguard Worker }
1405*61046927SAndroid Build Coastguard Worker
1406*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_denorm_flush_to_zero(unsigned execution_mode,unsigned bit_size)1407*61046927SAndroid Build Coastguard Worker nir_is_denorm_flush_to_zero(unsigned execution_mode, unsigned bit_size)
1408*61046927SAndroid Build Coastguard Worker {
1409*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP16) ||
1410*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32) ||
1411*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP64);
1412*61046927SAndroid Build Coastguard Worker }
1413*61046927SAndroid Build Coastguard Worker
1414*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_denorm_preserve(unsigned execution_mode,unsigned bit_size)1415*61046927SAndroid Build Coastguard Worker nir_is_denorm_preserve(unsigned execution_mode, unsigned bit_size)
1416*61046927SAndroid Build Coastguard Worker {
1417*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP16) ||
1418*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP32) ||
1419*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP64);
1420*61046927SAndroid Build Coastguard Worker }
1421*61046927SAndroid Build Coastguard Worker
1422*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_rounding_mode_rtne(unsigned execution_mode,unsigned bit_size)1423*61046927SAndroid Build Coastguard Worker nir_is_rounding_mode_rtne(unsigned execution_mode, unsigned bit_size)
1424*61046927SAndroid Build Coastguard Worker {
1425*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16) ||
1426*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32) ||
1427*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64);
1428*61046927SAndroid Build Coastguard Worker }
1429*61046927SAndroid Build Coastguard Worker
1430*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_rounding_mode_rtz(unsigned execution_mode,unsigned bit_size)1431*61046927SAndroid Build Coastguard Worker nir_is_rounding_mode_rtz(unsigned execution_mode, unsigned bit_size)
1432*61046927SAndroid Build Coastguard Worker {
1433*61046927SAndroid Build Coastguard Worker return (16 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16) ||
1434*61046927SAndroid Build Coastguard Worker (32 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32) ||
1435*61046927SAndroid Build Coastguard Worker (64 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64);
1436*61046927SAndroid Build Coastguard Worker }
1437*61046927SAndroid Build Coastguard Worker
1438*61046927SAndroid Build Coastguard Worker static inline bool
nir_has_any_rounding_mode_rtz(unsigned execution_mode)1439*61046927SAndroid Build Coastguard Worker nir_has_any_rounding_mode_rtz(unsigned execution_mode)
1440*61046927SAndroid Build Coastguard Worker {
1441*61046927SAndroid Build Coastguard Worker return (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16) ||
1442*61046927SAndroid Build Coastguard Worker (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32) ||
1443*61046927SAndroid Build Coastguard Worker (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64);
1444*61046927SAndroid Build Coastguard Worker }
1445*61046927SAndroid Build Coastguard Worker
1446*61046927SAndroid Build Coastguard Worker static inline bool
nir_has_any_rounding_mode_rtne(unsigned execution_mode)1447*61046927SAndroid Build Coastguard Worker nir_has_any_rounding_mode_rtne(unsigned execution_mode)
1448*61046927SAndroid Build Coastguard Worker {
1449*61046927SAndroid Build Coastguard Worker return (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16) ||
1450*61046927SAndroid Build Coastguard Worker (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32) ||
1451*61046927SAndroid Build Coastguard Worker (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64);
1452*61046927SAndroid Build Coastguard Worker }
1453*61046927SAndroid Build Coastguard Worker
1454*61046927SAndroid Build Coastguard Worker static inline nir_rounding_mode
nir_get_rounding_mode_from_float_controls(unsigned execution_mode,nir_alu_type type)1455*61046927SAndroid Build Coastguard Worker nir_get_rounding_mode_from_float_controls(unsigned execution_mode,
1456*61046927SAndroid Build Coastguard Worker nir_alu_type type)
1457*61046927SAndroid Build Coastguard Worker {
1458*61046927SAndroid Build Coastguard Worker if (nir_alu_type_get_base_type(type) != nir_type_float)
1459*61046927SAndroid Build Coastguard Worker return nir_rounding_mode_undef;
1460*61046927SAndroid Build Coastguard Worker
1461*61046927SAndroid Build Coastguard Worker unsigned bit_size = nir_alu_type_get_type_size(type);
1462*61046927SAndroid Build Coastguard Worker
1463*61046927SAndroid Build Coastguard Worker if (nir_is_rounding_mode_rtz(execution_mode, bit_size))
1464*61046927SAndroid Build Coastguard Worker return nir_rounding_mode_rtz;
1465*61046927SAndroid Build Coastguard Worker if (nir_is_rounding_mode_rtne(execution_mode, bit_size))
1466*61046927SAndroid Build Coastguard Worker return nir_rounding_mode_rtne;
1467*61046927SAndroid Build Coastguard Worker return nir_rounding_mode_undef;
1468*61046927SAndroid Build Coastguard Worker }
1469*61046927SAndroid Build Coastguard Worker
1470*61046927SAndroid Build Coastguard Worker static inline bool
nir_has_any_rounding_mode_enabled(unsigned execution_mode)1471*61046927SAndroid Build Coastguard Worker nir_has_any_rounding_mode_enabled(unsigned execution_mode)
1472*61046927SAndroid Build Coastguard Worker {
1473*61046927SAndroid Build Coastguard Worker bool result =
1474*61046927SAndroid Build Coastguard Worker nir_has_any_rounding_mode_rtne(execution_mode) ||
1475*61046927SAndroid Build Coastguard Worker nir_has_any_rounding_mode_rtz(execution_mode);
1476*61046927SAndroid Build Coastguard Worker return result;
1477*61046927SAndroid Build Coastguard Worker }
1478*61046927SAndroid Build Coastguard Worker
1479*61046927SAndroid Build Coastguard Worker typedef enum {
1480*61046927SAndroid Build Coastguard Worker /**
1481*61046927SAndroid Build Coastguard Worker * Operation where the first two sources are commutative.
1482*61046927SAndroid Build Coastguard Worker *
1483*61046927SAndroid Build Coastguard Worker * For 2-source operations, this just mathematical commutativity. Some
1484*61046927SAndroid Build Coastguard Worker * 3-source operations, like ffma, are only commutative in the first two
1485*61046927SAndroid Build Coastguard Worker * sources.
1486*61046927SAndroid Build Coastguard Worker */
1487*61046927SAndroid Build Coastguard Worker NIR_OP_IS_2SRC_COMMUTATIVE = (1 << 0),
1488*61046927SAndroid Build Coastguard Worker
1489*61046927SAndroid Build Coastguard Worker /**
1490*61046927SAndroid Build Coastguard Worker * Operation is associative
1491*61046927SAndroid Build Coastguard Worker */
1492*61046927SAndroid Build Coastguard Worker NIR_OP_IS_ASSOCIATIVE = (1 << 1),
1493*61046927SAndroid Build Coastguard Worker
1494*61046927SAndroid Build Coastguard Worker /**
1495*61046927SAndroid Build Coastguard Worker * Operation where src[0] is used to select src[1] on true or src[2] false.
1496*61046927SAndroid Build Coastguard Worker * src[0] may be Boolean, or it may be another type used in an implicit
1497*61046927SAndroid Build Coastguard Worker * comparison.
1498*61046927SAndroid Build Coastguard Worker */
1499*61046927SAndroid Build Coastguard Worker NIR_OP_IS_SELECTION = (1 << 2),
1500*61046927SAndroid Build Coastguard Worker
1501*61046927SAndroid Build Coastguard Worker /**
1502*61046927SAndroid Build Coastguard Worker * Operation where a screen-space derivative is taken of src[0]. Must not be
1503*61046927SAndroid Build Coastguard Worker * moved into non-uniform control flow.
1504*61046927SAndroid Build Coastguard Worker */
1505*61046927SAndroid Build Coastguard Worker NIR_OP_IS_DERIVATIVE = (1 << 3),
1506*61046927SAndroid Build Coastguard Worker } nir_op_algebraic_property;
1507*61046927SAndroid Build Coastguard Worker
1508*61046927SAndroid Build Coastguard Worker /* vec16 is the widest ALU op in NIR, making the max number of input of ALU
1509*61046927SAndroid Build Coastguard Worker * instructions to be the same as NIR_MAX_VEC_COMPONENTS.
1510*61046927SAndroid Build Coastguard Worker */
1511*61046927SAndroid Build Coastguard Worker #define NIR_ALU_MAX_INPUTS NIR_MAX_VEC_COMPONENTS
1512*61046927SAndroid Build Coastguard Worker
1513*61046927SAndroid Build Coastguard Worker /***/
1514*61046927SAndroid Build Coastguard Worker typedef struct nir_op_info {
1515*61046927SAndroid Build Coastguard Worker /** Name of the NIR ALU opcode */
1516*61046927SAndroid Build Coastguard Worker const char *name;
1517*61046927SAndroid Build Coastguard Worker
1518*61046927SAndroid Build Coastguard Worker /** Number of inputs (sources) */
1519*61046927SAndroid Build Coastguard Worker uint8_t num_inputs;
1520*61046927SAndroid Build Coastguard Worker
1521*61046927SAndroid Build Coastguard Worker /**
1522*61046927SAndroid Build Coastguard Worker * The number of components in the output
1523*61046927SAndroid Build Coastguard Worker *
1524*61046927SAndroid Build Coastguard Worker * If non-zero, this is the size of the output and input sizes are
1525*61046927SAndroid Build Coastguard Worker * explicitly given; swizzle and writemask are still in effect, but if
1526*61046927SAndroid Build Coastguard Worker * the output component is masked out, then the input component may
1527*61046927SAndroid Build Coastguard Worker * still be in use.
1528*61046927SAndroid Build Coastguard Worker *
1529*61046927SAndroid Build Coastguard Worker * If zero, the opcode acts in the standard, per-component manner; the
1530*61046927SAndroid Build Coastguard Worker * operation is performed on each component (except the ones that are
1531*61046927SAndroid Build Coastguard Worker * masked out) with the input being taken from the input swizzle for
1532*61046927SAndroid Build Coastguard Worker * that component.
1533*61046927SAndroid Build Coastguard Worker *
1534*61046927SAndroid Build Coastguard Worker * The size of some of the inputs may be given (i.e. non-zero) even
1535*61046927SAndroid Build Coastguard Worker * though output_size is zero; in that case, the inputs with a zero
1536*61046927SAndroid Build Coastguard Worker * size act per-component, while the inputs with non-zero size don't.
1537*61046927SAndroid Build Coastguard Worker */
1538*61046927SAndroid Build Coastguard Worker uint8_t output_size;
1539*61046927SAndroid Build Coastguard Worker
1540*61046927SAndroid Build Coastguard Worker /**
1541*61046927SAndroid Build Coastguard Worker * The type of vector that the instruction outputs. Note that the
1542*61046927SAndroid Build Coastguard Worker * staurate modifier is only allowed on outputs with the float type.
1543*61046927SAndroid Build Coastguard Worker */
1544*61046927SAndroid Build Coastguard Worker nir_alu_type output_type;
1545*61046927SAndroid Build Coastguard Worker
1546*61046927SAndroid Build Coastguard Worker /**
1547*61046927SAndroid Build Coastguard Worker * The number of components in each input
1548*61046927SAndroid Build Coastguard Worker *
1549*61046927SAndroid Build Coastguard Worker * See nir_op_infos::output_size for more detail about the relationship
1550*61046927SAndroid Build Coastguard Worker * between input and output sizes.
1551*61046927SAndroid Build Coastguard Worker */
1552*61046927SAndroid Build Coastguard Worker uint8_t input_sizes[NIR_ALU_MAX_INPUTS];
1553*61046927SAndroid Build Coastguard Worker
1554*61046927SAndroid Build Coastguard Worker /**
1555*61046927SAndroid Build Coastguard Worker * The type of vector that each input takes.
1556*61046927SAndroid Build Coastguard Worker */
1557*61046927SAndroid Build Coastguard Worker nir_alu_type input_types[NIR_ALU_MAX_INPUTS];
1558*61046927SAndroid Build Coastguard Worker
1559*61046927SAndroid Build Coastguard Worker /** Algebraic properties of this opcode */
1560*61046927SAndroid Build Coastguard Worker nir_op_algebraic_property algebraic_properties;
1561*61046927SAndroid Build Coastguard Worker
1562*61046927SAndroid Build Coastguard Worker /** Whether this represents a numeric conversion opcode */
1563*61046927SAndroid Build Coastguard Worker bool is_conversion;
1564*61046927SAndroid Build Coastguard Worker } nir_op_info;
1565*61046927SAndroid Build Coastguard Worker
1566*61046927SAndroid Build Coastguard Worker /** Metadata for each nir_op, indexed by opcode */
1567*61046927SAndroid Build Coastguard Worker extern const nir_op_info nir_op_infos[nir_num_opcodes];
1568*61046927SAndroid Build Coastguard Worker
1569*61046927SAndroid Build Coastguard Worker static inline bool
nir_op_is_selection(nir_op op)1570*61046927SAndroid Build Coastguard Worker nir_op_is_selection(nir_op op)
1571*61046927SAndroid Build Coastguard Worker {
1572*61046927SAndroid Build Coastguard Worker return (nir_op_infos[op].algebraic_properties & NIR_OP_IS_SELECTION) != 0;
1573*61046927SAndroid Build Coastguard Worker }
1574*61046927SAndroid Build Coastguard Worker
1575*61046927SAndroid Build Coastguard Worker static inline bool
nir_op_is_derivative(nir_op op)1576*61046927SAndroid Build Coastguard Worker nir_op_is_derivative(nir_op op)
1577*61046927SAndroid Build Coastguard Worker {
1578*61046927SAndroid Build Coastguard Worker return (nir_op_infos[op].algebraic_properties & NIR_OP_IS_DERIVATIVE) != 0;
1579*61046927SAndroid Build Coastguard Worker }
1580*61046927SAndroid Build Coastguard Worker
1581*61046927SAndroid Build Coastguard Worker /***/
1582*61046927SAndroid Build Coastguard Worker typedef struct nir_alu_instr {
1583*61046927SAndroid Build Coastguard Worker /** Base instruction */
1584*61046927SAndroid Build Coastguard Worker nir_instr instr;
1585*61046927SAndroid Build Coastguard Worker
1586*61046927SAndroid Build Coastguard Worker /** Opcode */
1587*61046927SAndroid Build Coastguard Worker nir_op op;
1588*61046927SAndroid Build Coastguard Worker
1589*61046927SAndroid Build Coastguard Worker /** Indicates that this ALU instruction generates an exact value
1590*61046927SAndroid Build Coastguard Worker *
1591*61046927SAndroid Build Coastguard Worker * This is kind of a mixture of GLSL "precise" and "invariant" and not
1592*61046927SAndroid Build Coastguard Worker * really equivalent to either. This indicates that the value generated by
1593*61046927SAndroid Build Coastguard Worker * this operation is high-precision and any code transformations that touch
1594*61046927SAndroid Build Coastguard Worker * it must ensure that the resulting value is bit-for-bit identical to the
1595*61046927SAndroid Build Coastguard Worker * original.
1596*61046927SAndroid Build Coastguard Worker */
1597*61046927SAndroid Build Coastguard Worker bool exact : 1;
1598*61046927SAndroid Build Coastguard Worker
1599*61046927SAndroid Build Coastguard Worker /**
1600*61046927SAndroid Build Coastguard Worker * Indicates that this instruction doese not cause signed integer wrapping
1601*61046927SAndroid Build Coastguard Worker * to occur, in the form of overflow or underflow.
1602*61046927SAndroid Build Coastguard Worker */
1603*61046927SAndroid Build Coastguard Worker bool no_signed_wrap : 1;
1604*61046927SAndroid Build Coastguard Worker
1605*61046927SAndroid Build Coastguard Worker /**
1606*61046927SAndroid Build Coastguard Worker * Indicates that this instruction does not cause unsigned integer wrapping
1607*61046927SAndroid Build Coastguard Worker * to occur, in the form of overflow or underflow.
1608*61046927SAndroid Build Coastguard Worker */
1609*61046927SAndroid Build Coastguard Worker bool no_unsigned_wrap : 1;
1610*61046927SAndroid Build Coastguard Worker
1611*61046927SAndroid Build Coastguard Worker /**
1612*61046927SAndroid Build Coastguard Worker * The float controls bit float_controls2 cares about. That is,
1613*61046927SAndroid Build Coastguard Worker * NAN/INF/SIGNED_ZERO_PRESERVE only. Allow{Contract,Reassoc,Transform} are
1614*61046927SAndroid Build Coastguard Worker * still handled through the exact bit, and the other float controls bits
1615*61046927SAndroid Build Coastguard Worker * (rounding mode and denorm handling) remain in the execution mode only.
1616*61046927SAndroid Build Coastguard Worker */
1617*61046927SAndroid Build Coastguard Worker uint32_t fp_fast_math : 9;
1618*61046927SAndroid Build Coastguard Worker
1619*61046927SAndroid Build Coastguard Worker /** Destination */
1620*61046927SAndroid Build Coastguard Worker nir_def def;
1621*61046927SAndroid Build Coastguard Worker
1622*61046927SAndroid Build Coastguard Worker /** Sources
1623*61046927SAndroid Build Coastguard Worker *
1624*61046927SAndroid Build Coastguard Worker * The size of the array is given by :c:member:`nir_op_info.num_inputs`.
1625*61046927SAndroid Build Coastguard Worker */
1626*61046927SAndroid Build Coastguard Worker nir_alu_src src[];
1627*61046927SAndroid Build Coastguard Worker } nir_alu_instr;
1628*61046927SAndroid Build Coastguard Worker
1629*61046927SAndroid Build Coastguard Worker static inline bool
nir_alu_instr_is_signed_zero_preserve(nir_alu_instr * alu)1630*61046927SAndroid Build Coastguard Worker nir_alu_instr_is_signed_zero_preserve(nir_alu_instr *alu)
1631*61046927SAndroid Build Coastguard Worker {
1632*61046927SAndroid Build Coastguard Worker return nir_is_float_control_signed_zero_preserve(alu->fp_fast_math, alu->def.bit_size);
1633*61046927SAndroid Build Coastguard Worker }
1634*61046927SAndroid Build Coastguard Worker
1635*61046927SAndroid Build Coastguard Worker static inline bool
nir_alu_instr_is_inf_preserve(nir_alu_instr * alu)1636*61046927SAndroid Build Coastguard Worker nir_alu_instr_is_inf_preserve(nir_alu_instr *alu)
1637*61046927SAndroid Build Coastguard Worker {
1638*61046927SAndroid Build Coastguard Worker return nir_is_float_control_inf_preserve(alu->fp_fast_math, alu->def.bit_size);
1639*61046927SAndroid Build Coastguard Worker }
1640*61046927SAndroid Build Coastguard Worker
1641*61046927SAndroid Build Coastguard Worker static inline bool
nir_alu_instr_is_nan_preserve(nir_alu_instr * alu)1642*61046927SAndroid Build Coastguard Worker nir_alu_instr_is_nan_preserve(nir_alu_instr *alu)
1643*61046927SAndroid Build Coastguard Worker {
1644*61046927SAndroid Build Coastguard Worker return nir_is_float_control_nan_preserve(alu->fp_fast_math, alu->def.bit_size);
1645*61046927SAndroid Build Coastguard Worker }
1646*61046927SAndroid Build Coastguard Worker
1647*61046927SAndroid Build Coastguard Worker static inline bool
nir_alu_instr_is_signed_zero_inf_nan_preserve(nir_alu_instr * alu)1648*61046927SAndroid Build Coastguard Worker nir_alu_instr_is_signed_zero_inf_nan_preserve(nir_alu_instr *alu)
1649*61046927SAndroid Build Coastguard Worker {
1650*61046927SAndroid Build Coastguard Worker return nir_is_float_control_signed_zero_inf_nan_preserve(alu->fp_fast_math, alu->def.bit_size);
1651*61046927SAndroid Build Coastguard Worker }
1652*61046927SAndroid Build Coastguard Worker
1653*61046927SAndroid Build Coastguard Worker void nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src);
1654*61046927SAndroid Build Coastguard Worker
1655*61046927SAndroid Build Coastguard Worker nir_component_mask_t
1656*61046927SAndroid Build Coastguard Worker nir_alu_instr_src_read_mask(const nir_alu_instr *instr, unsigned src);
1657*61046927SAndroid Build Coastguard Worker /**
1658*61046927SAndroid Build Coastguard Worker * Get the number of channels used for a source
1659*61046927SAndroid Build Coastguard Worker */
1660*61046927SAndroid Build Coastguard Worker unsigned
1661*61046927SAndroid Build Coastguard Worker nir_ssa_alu_instr_src_components(const nir_alu_instr *instr, unsigned src);
1662*61046927SAndroid Build Coastguard Worker
1663*61046927SAndroid Build Coastguard Worker /* is this source channel used? */
1664*61046927SAndroid Build Coastguard Worker static inline bool
nir_alu_instr_channel_used(const nir_alu_instr * instr,unsigned src,unsigned channel)1665*61046927SAndroid Build Coastguard Worker nir_alu_instr_channel_used(const nir_alu_instr *instr, unsigned src,
1666*61046927SAndroid Build Coastguard Worker unsigned channel)
1667*61046927SAndroid Build Coastguard Worker {
1668*61046927SAndroid Build Coastguard Worker return channel < nir_ssa_alu_instr_src_components(instr, src);
1669*61046927SAndroid Build Coastguard Worker }
1670*61046927SAndroid Build Coastguard Worker
1671*61046927SAndroid Build Coastguard Worker bool
1672*61046927SAndroid Build Coastguard Worker nir_alu_instr_is_comparison(const nir_alu_instr *instr);
1673*61046927SAndroid Build Coastguard Worker
1674*61046927SAndroid Build Coastguard Worker bool nir_const_value_negative_equal(nir_const_value c1, nir_const_value c2,
1675*61046927SAndroid Build Coastguard Worker nir_alu_type full_type);
1676*61046927SAndroid Build Coastguard Worker
1677*61046927SAndroid Build Coastguard Worker bool nir_alu_srcs_equal(const nir_alu_instr *alu1, const nir_alu_instr *alu2,
1678*61046927SAndroid Build Coastguard Worker unsigned src1, unsigned src2);
1679*61046927SAndroid Build Coastguard Worker
1680*61046927SAndroid Build Coastguard Worker bool nir_alu_srcs_negative_equal(const nir_alu_instr *alu1,
1681*61046927SAndroid Build Coastguard Worker const nir_alu_instr *alu2,
1682*61046927SAndroid Build Coastguard Worker unsigned src1, unsigned src2);
1683*61046927SAndroid Build Coastguard Worker
1684*61046927SAndroid Build Coastguard Worker bool nir_alu_src_is_trivial_ssa(const nir_alu_instr *alu, unsigned srcn);
1685*61046927SAndroid Build Coastguard Worker
1686*61046927SAndroid Build Coastguard Worker typedef enum {
1687*61046927SAndroid Build Coastguard Worker nir_deref_type_var,
1688*61046927SAndroid Build Coastguard Worker nir_deref_type_array,
1689*61046927SAndroid Build Coastguard Worker nir_deref_type_array_wildcard,
1690*61046927SAndroid Build Coastguard Worker nir_deref_type_ptr_as_array,
1691*61046927SAndroid Build Coastguard Worker nir_deref_type_struct,
1692*61046927SAndroid Build Coastguard Worker nir_deref_type_cast,
1693*61046927SAndroid Build Coastguard Worker } nir_deref_type;
1694*61046927SAndroid Build Coastguard Worker
1695*61046927SAndroid Build Coastguard Worker typedef struct {
1696*61046927SAndroid Build Coastguard Worker nir_instr instr;
1697*61046927SAndroid Build Coastguard Worker
1698*61046927SAndroid Build Coastguard Worker /** The type of this deref instruction */
1699*61046927SAndroid Build Coastguard Worker nir_deref_type deref_type;
1700*61046927SAndroid Build Coastguard Worker
1701*61046927SAndroid Build Coastguard Worker /** Bitmask what modes the underlying variable might be
1702*61046927SAndroid Build Coastguard Worker *
1703*61046927SAndroid Build Coastguard Worker * For OpenCL-style generic pointers, we may not know exactly what mode it
1704*61046927SAndroid Build Coastguard Worker * is at any given point in time in the compile process. This bitfield
1705*61046927SAndroid Build Coastguard Worker * contains the set of modes which it MAY be.
1706*61046927SAndroid Build Coastguard Worker *
1707*61046927SAndroid Build Coastguard Worker * Generally, this field should not be accessed directly. Use one of the
1708*61046927SAndroid Build Coastguard Worker * nir_deref_mode_ helpers instead.
1709*61046927SAndroid Build Coastguard Worker */
1710*61046927SAndroid Build Coastguard Worker nir_variable_mode modes;
1711*61046927SAndroid Build Coastguard Worker
1712*61046927SAndroid Build Coastguard Worker /** The dereferenced type of the resulting pointer value */
1713*61046927SAndroid Build Coastguard Worker const struct glsl_type *type;
1714*61046927SAndroid Build Coastguard Worker
1715*61046927SAndroid Build Coastguard Worker union {
1716*61046927SAndroid Build Coastguard Worker /** Variable being dereferenced if deref_type is a deref_var */
1717*61046927SAndroid Build Coastguard Worker nir_variable *var;
1718*61046927SAndroid Build Coastguard Worker
1719*61046927SAndroid Build Coastguard Worker /** Parent deref if deref_type is not deref_var */
1720*61046927SAndroid Build Coastguard Worker nir_src parent;
1721*61046927SAndroid Build Coastguard Worker };
1722*61046927SAndroid Build Coastguard Worker
1723*61046927SAndroid Build Coastguard Worker /** Additional deref parameters */
1724*61046927SAndroid Build Coastguard Worker union {
1725*61046927SAndroid Build Coastguard Worker struct {
1726*61046927SAndroid Build Coastguard Worker nir_src index;
1727*61046927SAndroid Build Coastguard Worker bool in_bounds;
1728*61046927SAndroid Build Coastguard Worker } arr;
1729*61046927SAndroid Build Coastguard Worker
1730*61046927SAndroid Build Coastguard Worker struct {
1731*61046927SAndroid Build Coastguard Worker unsigned index;
1732*61046927SAndroid Build Coastguard Worker } strct;
1733*61046927SAndroid Build Coastguard Worker
1734*61046927SAndroid Build Coastguard Worker struct {
1735*61046927SAndroid Build Coastguard Worker unsigned ptr_stride;
1736*61046927SAndroid Build Coastguard Worker unsigned align_mul;
1737*61046927SAndroid Build Coastguard Worker unsigned align_offset;
1738*61046927SAndroid Build Coastguard Worker } cast;
1739*61046927SAndroid Build Coastguard Worker };
1740*61046927SAndroid Build Coastguard Worker
1741*61046927SAndroid Build Coastguard Worker /** Destination to store the resulting "pointer" */
1742*61046927SAndroid Build Coastguard Worker nir_def def;
1743*61046927SAndroid Build Coastguard Worker } nir_deref_instr;
1744*61046927SAndroid Build Coastguard Worker
1745*61046927SAndroid Build Coastguard Worker /**
1746*61046927SAndroid Build Coastguard Worker * Returns true if the cast is trivial, i.e. the source and destination type is
1747*61046927SAndroid Build Coastguard Worker * the same.
1748*61046927SAndroid Build Coastguard Worker */
1749*61046927SAndroid Build Coastguard Worker bool nir_deref_cast_is_trivial(nir_deref_instr *cast);
1750*61046927SAndroid Build Coastguard Worker
1751*61046927SAndroid Build Coastguard Worker /** Returns true if deref might have one of the given modes
1752*61046927SAndroid Build Coastguard Worker *
1753*61046927SAndroid Build Coastguard Worker * For multi-mode derefs, this returns true if any of the possible modes for
1754*61046927SAndroid Build Coastguard Worker * the deref to have any of the specified modes. This function returning true
1755*61046927SAndroid Build Coastguard Worker * does NOT mean that the deref definitely has one of those modes. It simply
1756*61046927SAndroid Build Coastguard Worker * means that, with the best information we have at the time, it might.
1757*61046927SAndroid Build Coastguard Worker */
1758*61046927SAndroid Build Coastguard Worker static inline bool
nir_deref_mode_may_be(const nir_deref_instr * deref,nir_variable_mode modes)1759*61046927SAndroid Build Coastguard Worker nir_deref_mode_may_be(const nir_deref_instr *deref, nir_variable_mode modes)
1760*61046927SAndroid Build Coastguard Worker {
1761*61046927SAndroid Build Coastguard Worker assert(!(modes & ~nir_var_all));
1762*61046927SAndroid Build Coastguard Worker assert(deref->modes != 0);
1763*61046927SAndroid Build Coastguard Worker return deref->modes & modes;
1764*61046927SAndroid Build Coastguard Worker }
1765*61046927SAndroid Build Coastguard Worker
1766*61046927SAndroid Build Coastguard Worker /** Returns true if deref must have one of the given modes
1767*61046927SAndroid Build Coastguard Worker *
1768*61046927SAndroid Build Coastguard Worker * For multi-mode derefs, this returns true if NIR can prove that the given
1769*61046927SAndroid Build Coastguard Worker * deref has one of the specified modes. This function returning false does
1770*61046927SAndroid Build Coastguard Worker * NOT mean that deref doesn't have one of the given mode. It very well may
1771*61046927SAndroid Build Coastguard Worker * have one of those modes, we just don't have enough information to prove
1772*61046927SAndroid Build Coastguard Worker * that it does for sure.
1773*61046927SAndroid Build Coastguard Worker */
1774*61046927SAndroid Build Coastguard Worker static inline bool
nir_deref_mode_must_be(const nir_deref_instr * deref,nir_variable_mode modes)1775*61046927SAndroid Build Coastguard Worker nir_deref_mode_must_be(const nir_deref_instr *deref, nir_variable_mode modes)
1776*61046927SAndroid Build Coastguard Worker {
1777*61046927SAndroid Build Coastguard Worker assert(!(modes & ~nir_var_all));
1778*61046927SAndroid Build Coastguard Worker assert(deref->modes != 0);
1779*61046927SAndroid Build Coastguard Worker return !(deref->modes & ~modes);
1780*61046927SAndroid Build Coastguard Worker }
1781*61046927SAndroid Build Coastguard Worker
1782*61046927SAndroid Build Coastguard Worker /** Returns true if deref has the given mode
1783*61046927SAndroid Build Coastguard Worker *
1784*61046927SAndroid Build Coastguard Worker * This returns true if the deref has exactly the mode specified. If the
1785*61046927SAndroid Build Coastguard Worker * deref may have that mode but may also have a different mode (i.e. modes has
1786*61046927SAndroid Build Coastguard Worker * multiple bits set), this will assert-fail.
1787*61046927SAndroid Build Coastguard Worker *
1788*61046927SAndroid Build Coastguard Worker * If you're confused about which nir_deref_mode_ helper to use, use this one
1789*61046927SAndroid Build Coastguard Worker * or nir_deref_mode_is_one_of below.
1790*61046927SAndroid Build Coastguard Worker */
1791*61046927SAndroid Build Coastguard Worker static inline bool
nir_deref_mode_is(const nir_deref_instr * deref,nir_variable_mode mode)1792*61046927SAndroid Build Coastguard Worker nir_deref_mode_is(const nir_deref_instr *deref, nir_variable_mode mode)
1793*61046927SAndroid Build Coastguard Worker {
1794*61046927SAndroid Build Coastguard Worker assert(util_bitcount(mode) == 1 && (mode & nir_var_all));
1795*61046927SAndroid Build Coastguard Worker assert(deref->modes != 0);
1796*61046927SAndroid Build Coastguard Worker
1797*61046927SAndroid Build Coastguard Worker /* This is only for "simple" cases so, if modes might interact with this
1798*61046927SAndroid Build Coastguard Worker * deref then the deref has to have a single mode.
1799*61046927SAndroid Build Coastguard Worker */
1800*61046927SAndroid Build Coastguard Worker if (nir_deref_mode_may_be(deref, mode)) {
1801*61046927SAndroid Build Coastguard Worker assert(util_bitcount(deref->modes) == 1);
1802*61046927SAndroid Build Coastguard Worker assert(deref->modes == mode);
1803*61046927SAndroid Build Coastguard Worker }
1804*61046927SAndroid Build Coastguard Worker
1805*61046927SAndroid Build Coastguard Worker return deref->modes == mode;
1806*61046927SAndroid Build Coastguard Worker }
1807*61046927SAndroid Build Coastguard Worker
1808*61046927SAndroid Build Coastguard Worker /** Returns true if deref has one of the given modes
1809*61046927SAndroid Build Coastguard Worker *
1810*61046927SAndroid Build Coastguard Worker * This returns true if the deref has exactly one possible mode and that mode
1811*61046927SAndroid Build Coastguard Worker * is one of the modes specified. If the deref may have one of those modes
1812*61046927SAndroid Build Coastguard Worker * but may also have a different mode (i.e. modes has multiple bits set), this
1813*61046927SAndroid Build Coastguard Worker * will assert-fail.
1814*61046927SAndroid Build Coastguard Worker */
1815*61046927SAndroid Build Coastguard Worker static inline bool
nir_deref_mode_is_one_of(const nir_deref_instr * deref,nir_variable_mode modes)1816*61046927SAndroid Build Coastguard Worker nir_deref_mode_is_one_of(const nir_deref_instr *deref, nir_variable_mode modes)
1817*61046927SAndroid Build Coastguard Worker {
1818*61046927SAndroid Build Coastguard Worker /* This is only for "simple" cases so, if modes might interact with this
1819*61046927SAndroid Build Coastguard Worker * deref then the deref has to have a single mode.
1820*61046927SAndroid Build Coastguard Worker */
1821*61046927SAndroid Build Coastguard Worker if (nir_deref_mode_may_be(deref, modes)) {
1822*61046927SAndroid Build Coastguard Worker assert(util_bitcount(deref->modes) == 1);
1823*61046927SAndroid Build Coastguard Worker assert(nir_deref_mode_must_be(deref, modes));
1824*61046927SAndroid Build Coastguard Worker }
1825*61046927SAndroid Build Coastguard Worker
1826*61046927SAndroid Build Coastguard Worker return nir_deref_mode_may_be(deref, modes);
1827*61046927SAndroid Build Coastguard Worker }
1828*61046927SAndroid Build Coastguard Worker
1829*61046927SAndroid Build Coastguard Worker /** Returns true if deref's possible modes lie in the given set of modes
1830*61046927SAndroid Build Coastguard Worker *
1831*61046927SAndroid Build Coastguard Worker * This returns true if the deref's modes lie in the given set of modes. If
1832*61046927SAndroid Build Coastguard Worker * the deref's modes overlap with the specified modes but aren't entirely
1833*61046927SAndroid Build Coastguard Worker * contained in the specified set of modes, this will assert-fail. In
1834*61046927SAndroid Build Coastguard Worker * particular, if this is used in a generic pointers scenario, the specified
1835*61046927SAndroid Build Coastguard Worker * modes has to contain all or none of the possible generic pointer modes.
1836*61046927SAndroid Build Coastguard Worker *
1837*61046927SAndroid Build Coastguard Worker * This is intended mostly for mass-lowering of derefs which might have
1838*61046927SAndroid Build Coastguard Worker * generic pointers.
1839*61046927SAndroid Build Coastguard Worker */
1840*61046927SAndroid Build Coastguard Worker static inline bool
nir_deref_mode_is_in_set(const nir_deref_instr * deref,nir_variable_mode modes)1841*61046927SAndroid Build Coastguard Worker nir_deref_mode_is_in_set(const nir_deref_instr *deref, nir_variable_mode modes)
1842*61046927SAndroid Build Coastguard Worker {
1843*61046927SAndroid Build Coastguard Worker if (nir_deref_mode_may_be(deref, modes))
1844*61046927SAndroid Build Coastguard Worker assert(nir_deref_mode_must_be(deref, modes));
1845*61046927SAndroid Build Coastguard Worker
1846*61046927SAndroid Build Coastguard Worker return nir_deref_mode_may_be(deref, modes);
1847*61046927SAndroid Build Coastguard Worker }
1848*61046927SAndroid Build Coastguard Worker
1849*61046927SAndroid Build Coastguard Worker static inline nir_deref_instr *nir_src_as_deref(nir_src src);
1850*61046927SAndroid Build Coastguard Worker
1851*61046927SAndroid Build Coastguard Worker static inline nir_deref_instr *
nir_deref_instr_parent(const nir_deref_instr * instr)1852*61046927SAndroid Build Coastguard Worker nir_deref_instr_parent(const nir_deref_instr *instr)
1853*61046927SAndroid Build Coastguard Worker {
1854*61046927SAndroid Build Coastguard Worker if (instr->deref_type == nir_deref_type_var)
1855*61046927SAndroid Build Coastguard Worker return NULL;
1856*61046927SAndroid Build Coastguard Worker else
1857*61046927SAndroid Build Coastguard Worker return nir_src_as_deref(instr->parent);
1858*61046927SAndroid Build Coastguard Worker }
1859*61046927SAndroid Build Coastguard Worker
1860*61046927SAndroid Build Coastguard Worker static inline nir_variable *
nir_deref_instr_get_variable(const nir_deref_instr * instr)1861*61046927SAndroid Build Coastguard Worker nir_deref_instr_get_variable(const nir_deref_instr *instr)
1862*61046927SAndroid Build Coastguard Worker {
1863*61046927SAndroid Build Coastguard Worker while (instr->deref_type != nir_deref_type_var) {
1864*61046927SAndroid Build Coastguard Worker if (instr->deref_type == nir_deref_type_cast)
1865*61046927SAndroid Build Coastguard Worker return NULL;
1866*61046927SAndroid Build Coastguard Worker
1867*61046927SAndroid Build Coastguard Worker instr = nir_deref_instr_parent(instr);
1868*61046927SAndroid Build Coastguard Worker }
1869*61046927SAndroid Build Coastguard Worker
1870*61046927SAndroid Build Coastguard Worker return instr->var;
1871*61046927SAndroid Build Coastguard Worker }
1872*61046927SAndroid Build Coastguard Worker
1873*61046927SAndroid Build Coastguard Worker bool nir_deref_instr_has_indirect(nir_deref_instr *instr);
1874*61046927SAndroid Build Coastguard Worker bool nir_deref_instr_is_known_out_of_bounds(nir_deref_instr *instr);
1875*61046927SAndroid Build Coastguard Worker
1876*61046927SAndroid Build Coastguard Worker typedef enum {
1877*61046927SAndroid Build Coastguard Worker nir_deref_instr_has_complex_use_allow_memcpy_src = (1 << 0),
1878*61046927SAndroid Build Coastguard Worker nir_deref_instr_has_complex_use_allow_memcpy_dst = (1 << 1),
1879*61046927SAndroid Build Coastguard Worker nir_deref_instr_has_complex_use_allow_atomics = (1 << 2),
1880*61046927SAndroid Build Coastguard Worker } nir_deref_instr_has_complex_use_options;
1881*61046927SAndroid Build Coastguard Worker
1882*61046927SAndroid Build Coastguard Worker bool nir_deref_instr_has_complex_use(nir_deref_instr *instr,
1883*61046927SAndroid Build Coastguard Worker nir_deref_instr_has_complex_use_options opts);
1884*61046927SAndroid Build Coastguard Worker
1885*61046927SAndroid Build Coastguard Worker bool nir_deref_instr_remove_if_unused(nir_deref_instr *instr);
1886*61046927SAndroid Build Coastguard Worker
1887*61046927SAndroid Build Coastguard Worker unsigned nir_deref_instr_array_stride(nir_deref_instr *instr);
1888*61046927SAndroid Build Coastguard Worker
1889*61046927SAndroid Build Coastguard Worker typedef struct {
1890*61046927SAndroid Build Coastguard Worker nir_instr instr;
1891*61046927SAndroid Build Coastguard Worker
1892*61046927SAndroid Build Coastguard Worker struct nir_function *callee;
1893*61046927SAndroid Build Coastguard Worker
1894*61046927SAndroid Build Coastguard Worker unsigned num_params;
1895*61046927SAndroid Build Coastguard Worker nir_src params[];
1896*61046927SAndroid Build Coastguard Worker } nir_call_instr;
1897*61046927SAndroid Build Coastguard Worker
1898*61046927SAndroid Build Coastguard Worker #include "nir_intrinsics.h"
1899*61046927SAndroid Build Coastguard Worker
1900*61046927SAndroid Build Coastguard Worker #define NIR_INTRINSIC_MAX_CONST_INDEX 8
1901*61046927SAndroid Build Coastguard Worker
1902*61046927SAndroid Build Coastguard Worker /** Represents an intrinsic
1903*61046927SAndroid Build Coastguard Worker *
1904*61046927SAndroid Build Coastguard Worker * An intrinsic is an instruction type for handling things that are
1905*61046927SAndroid Build Coastguard Worker * more-or-less regular operations but don't just consume and produce SSA
1906*61046927SAndroid Build Coastguard Worker * values like ALU operations do. Intrinsics are not for things that have
1907*61046927SAndroid Build Coastguard Worker * special semantic meaning such as phi nodes and parallel copies.
1908*61046927SAndroid Build Coastguard Worker * Examples of intrinsics include variable load/store operations, system
1909*61046927SAndroid Build Coastguard Worker * value loads, and the like. Even though texturing more-or-less falls
1910*61046927SAndroid Build Coastguard Worker * under this category, texturing is its own instruction type because
1911*61046927SAndroid Build Coastguard Worker * trying to represent texturing with intrinsics would lead to a
1912*61046927SAndroid Build Coastguard Worker * combinatorial explosion of intrinsic opcodes.
1913*61046927SAndroid Build Coastguard Worker *
1914*61046927SAndroid Build Coastguard Worker * By having a single instruction type for handling a lot of different
1915*61046927SAndroid Build Coastguard Worker * cases, optimization passes can look for intrinsics and, for the most
1916*61046927SAndroid Build Coastguard Worker * part, completely ignore them. Each intrinsic type also has a few
1917*61046927SAndroid Build Coastguard Worker * possible flags that govern whether or not they can be reordered or
1918*61046927SAndroid Build Coastguard Worker * eliminated. That way passes like dead code elimination can still work
1919*61046927SAndroid Build Coastguard Worker * on intrisics without understanding the meaning of each.
1920*61046927SAndroid Build Coastguard Worker *
1921*61046927SAndroid Build Coastguard Worker * Each intrinsic has some number of constant indices, some number of
1922*61046927SAndroid Build Coastguard Worker * variables, and some number of sources. What these sources, variables,
1923*61046927SAndroid Build Coastguard Worker * and indices mean depends on the intrinsic and is documented with the
1924*61046927SAndroid Build Coastguard Worker * intrinsic declaration in nir_intrinsics.h. Intrinsics and texture
1925*61046927SAndroid Build Coastguard Worker * instructions are the only types of instruction that can operate on
1926*61046927SAndroid Build Coastguard Worker * variables.
1927*61046927SAndroid Build Coastguard Worker */
1928*61046927SAndroid Build Coastguard Worker typedef struct {
1929*61046927SAndroid Build Coastguard Worker nir_instr instr;
1930*61046927SAndroid Build Coastguard Worker
1931*61046927SAndroid Build Coastguard Worker nir_intrinsic_op intrinsic;
1932*61046927SAndroid Build Coastguard Worker
1933*61046927SAndroid Build Coastguard Worker nir_def def;
1934*61046927SAndroid Build Coastguard Worker
1935*61046927SAndroid Build Coastguard Worker /** number of components if this is a vectorized intrinsic
1936*61046927SAndroid Build Coastguard Worker *
1937*61046927SAndroid Build Coastguard Worker * Similarly to ALU operations, some intrinsics are vectorized.
1938*61046927SAndroid Build Coastguard Worker * An intrinsic is vectorized if nir_intrinsic_infos.dest_components == 0.
1939*61046927SAndroid Build Coastguard Worker * For vectorized intrinsics, the num_components field specifies the
1940*61046927SAndroid Build Coastguard Worker * number of destination components and the number of source components
1941*61046927SAndroid Build Coastguard Worker * for all sources with nir_intrinsic_infos.src_components[i] == 0.
1942*61046927SAndroid Build Coastguard Worker */
1943*61046927SAndroid Build Coastguard Worker uint8_t num_components;
1944*61046927SAndroid Build Coastguard Worker
1945*61046927SAndroid Build Coastguard Worker int const_index[NIR_INTRINSIC_MAX_CONST_INDEX];
1946*61046927SAndroid Build Coastguard Worker
1947*61046927SAndroid Build Coastguard Worker /* a variable name associated with this instr; cannot be modified or freed */
1948*61046927SAndroid Build Coastguard Worker const char *name;
1949*61046927SAndroid Build Coastguard Worker
1950*61046927SAndroid Build Coastguard Worker nir_src src[];
1951*61046927SAndroid Build Coastguard Worker } nir_intrinsic_instr;
1952*61046927SAndroid Build Coastguard Worker
1953*61046927SAndroid Build Coastguard Worker static inline nir_variable *
nir_intrinsic_get_var(const nir_intrinsic_instr * intrin,unsigned i)1954*61046927SAndroid Build Coastguard Worker nir_intrinsic_get_var(const nir_intrinsic_instr *intrin, unsigned i)
1955*61046927SAndroid Build Coastguard Worker {
1956*61046927SAndroid Build Coastguard Worker return nir_deref_instr_get_variable(nir_src_as_deref(intrin->src[i]));
1957*61046927SAndroid Build Coastguard Worker }
1958*61046927SAndroid Build Coastguard Worker
1959*61046927SAndroid Build Coastguard Worker typedef enum {
1960*61046927SAndroid Build Coastguard Worker /* Memory ordering. */
1961*61046927SAndroid Build Coastguard Worker NIR_MEMORY_ACQUIRE = 1 << 0,
1962*61046927SAndroid Build Coastguard Worker NIR_MEMORY_RELEASE = 1 << 1,
1963*61046927SAndroid Build Coastguard Worker NIR_MEMORY_ACQ_REL = NIR_MEMORY_ACQUIRE | NIR_MEMORY_RELEASE,
1964*61046927SAndroid Build Coastguard Worker
1965*61046927SAndroid Build Coastguard Worker /* Memory visibility operations. */
1966*61046927SAndroid Build Coastguard Worker NIR_MEMORY_MAKE_AVAILABLE = 1 << 2,
1967*61046927SAndroid Build Coastguard Worker NIR_MEMORY_MAKE_VISIBLE = 1 << 3,
1968*61046927SAndroid Build Coastguard Worker } nir_memory_semantics;
1969*61046927SAndroid Build Coastguard Worker
1970*61046927SAndroid Build Coastguard Worker /**
1971*61046927SAndroid Build Coastguard Worker * NIR intrinsics semantic flags
1972*61046927SAndroid Build Coastguard Worker *
1973*61046927SAndroid Build Coastguard Worker * information about what the compiler can do with the intrinsics.
1974*61046927SAndroid Build Coastguard Worker *
1975*61046927SAndroid Build Coastguard Worker * :c:member:`nir_intrinsic_info.flags`
1976*61046927SAndroid Build Coastguard Worker */
1977*61046927SAndroid Build Coastguard Worker typedef enum {
1978*61046927SAndroid Build Coastguard Worker /**
1979*61046927SAndroid Build Coastguard Worker * whether the intrinsic can be safely eliminated if none of its output
1980*61046927SAndroid Build Coastguard Worker * value is not being used.
1981*61046927SAndroid Build Coastguard Worker */
1982*61046927SAndroid Build Coastguard Worker NIR_INTRINSIC_CAN_ELIMINATE = (1 << 0),
1983*61046927SAndroid Build Coastguard Worker
1984*61046927SAndroid Build Coastguard Worker /**
1985*61046927SAndroid Build Coastguard Worker * Whether the intrinsic can be reordered with respect to any other
1986*61046927SAndroid Build Coastguard Worker * intrinsic, i.e. whether the only reordering dependencies of the
1987*61046927SAndroid Build Coastguard Worker * intrinsic are due to the register reads/writes.
1988*61046927SAndroid Build Coastguard Worker */
1989*61046927SAndroid Build Coastguard Worker NIR_INTRINSIC_CAN_REORDER = (1 << 1),
1990*61046927SAndroid Build Coastguard Worker } nir_intrinsic_semantic_flag;
1991*61046927SAndroid Build Coastguard Worker
1992*61046927SAndroid Build Coastguard Worker /**
1993*61046927SAndroid Build Coastguard Worker * Maximum valid value for a nir align_mul value (in intrinsics or derefs).
1994*61046927SAndroid Build Coastguard Worker *
1995*61046927SAndroid Build Coastguard Worker * Offsets can be signed, so this is the largest power of two in int32_t.
1996*61046927SAndroid Build Coastguard Worker */
1997*61046927SAndroid Build Coastguard Worker #define NIR_ALIGN_MUL_MAX 0x40000000
1998*61046927SAndroid Build Coastguard Worker
1999*61046927SAndroid Build Coastguard Worker typedef struct nir_io_semantics {
2000*61046927SAndroid Build Coastguard Worker unsigned location : 7; /* gl_vert_attrib, gl_varying_slot, or gl_frag_result */
2001*61046927SAndroid Build Coastguard Worker unsigned num_slots : 6; /* max 32, may be pessimistic with const indexing */
2002*61046927SAndroid Build Coastguard Worker unsigned dual_source_blend_index : 1;
2003*61046927SAndroid Build Coastguard Worker unsigned fb_fetch_output : 1; /* for GL_KHR_blend_equation_advanced */
2004*61046927SAndroid Build Coastguard Worker unsigned gs_streams : 8; /* xxyyzzww: 2-bit stream index for each component */
2005*61046927SAndroid Build Coastguard Worker unsigned medium_precision : 1; /* GLSL mediump qualifier */
2006*61046927SAndroid Build Coastguard Worker unsigned per_view : 1;
2007*61046927SAndroid Build Coastguard Worker unsigned high_16bits : 1; /* whether accessing low or high half of the slot */
2008*61046927SAndroid Build Coastguard Worker unsigned invariant : 1; /* The variable has the invariant flag set */
2009*61046927SAndroid Build Coastguard Worker unsigned high_dvec2 : 1; /* whether accessing the high half of dvec3/dvec4 */
2010*61046927SAndroid Build Coastguard Worker /* CLIP_DISTn, LAYER, VIEWPORT, and TESS_LEVEL_* have up to 3 uses:
2011*61046927SAndroid Build Coastguard Worker * - an output consumed by the next stage
2012*61046927SAndroid Build Coastguard Worker * - a system value output affecting fixed-func hardware, e.g. the clipper
2013*61046927SAndroid Build Coastguard Worker * - a transform feedback output written to memory
2014*61046927SAndroid Build Coastguard Worker * The following fields disable the first two. Transform feedback is disabled
2015*61046927SAndroid Build Coastguard Worker * by transform feedback info.
2016*61046927SAndroid Build Coastguard Worker */
2017*61046927SAndroid Build Coastguard Worker unsigned no_varying : 1; /* whether this output isn't consumed by the next stage */
2018*61046927SAndroid Build Coastguard Worker unsigned no_sysval_output : 1; /* whether this system value output has no
2019*61046927SAndroid Build Coastguard Worker effect due to current pipeline states */
2020*61046927SAndroid Build Coastguard Worker unsigned interp_explicit_strict : 1; /* preserve original vertex order */
2021*61046927SAndroid Build Coastguard Worker unsigned _pad : 1;
2022*61046927SAndroid Build Coastguard Worker } nir_io_semantics;
2023*61046927SAndroid Build Coastguard Worker
2024*61046927SAndroid Build Coastguard Worker /* Transform feedback info for 2 outputs. nir_intrinsic_store_output contains
2025*61046927SAndroid Build Coastguard Worker * this structure twice to support up to 4 outputs. The structure is limited
2026*61046927SAndroid Build Coastguard Worker * to 32 bits because it's stored in nir_intrinsic_instr::const_index[].
2027*61046927SAndroid Build Coastguard Worker */
2028*61046927SAndroid Build Coastguard Worker typedef struct nir_io_xfb {
2029*61046927SAndroid Build Coastguard Worker struct {
2030*61046927SAndroid Build Coastguard Worker /* start_component is equal to the index of out[]; add 2 for io_xfb2 */
2031*61046927SAndroid Build Coastguard Worker /* start_component is not relative to nir_intrinsic_component */
2032*61046927SAndroid Build Coastguard Worker /* get the stream index from nir_io_semantics */
2033*61046927SAndroid Build Coastguard Worker uint8_t num_components : 4; /* max 4; if this is 0, xfb is disabled */
2034*61046927SAndroid Build Coastguard Worker uint8_t buffer : 4; /* buffer index, max 3 */
2035*61046927SAndroid Build Coastguard Worker uint8_t offset; /* transform feedback buffer offset in dwords,
2036*61046927SAndroid Build Coastguard Worker max (1K - 4) bytes */
2037*61046927SAndroid Build Coastguard Worker } out[2];
2038*61046927SAndroid Build Coastguard Worker } nir_io_xfb;
2039*61046927SAndroid Build Coastguard Worker
2040*61046927SAndroid Build Coastguard Worker unsigned
2041*61046927SAndroid Build Coastguard Worker nir_instr_xfb_write_mask(nir_intrinsic_instr *instr);
2042*61046927SAndroid Build Coastguard Worker
2043*61046927SAndroid Build Coastguard Worker #define NIR_INTRINSIC_MAX_INPUTS 11
2044*61046927SAndroid Build Coastguard Worker
2045*61046927SAndroid Build Coastguard Worker typedef struct {
2046*61046927SAndroid Build Coastguard Worker const char *name;
2047*61046927SAndroid Build Coastguard Worker
2048*61046927SAndroid Build Coastguard Worker /** number of register/SSA inputs */
2049*61046927SAndroid Build Coastguard Worker uint8_t num_srcs;
2050*61046927SAndroid Build Coastguard Worker
2051*61046927SAndroid Build Coastguard Worker /** number of components of each input register
2052*61046927SAndroid Build Coastguard Worker *
2053*61046927SAndroid Build Coastguard Worker * If this value is 0, the number of components is given by the
2054*61046927SAndroid Build Coastguard Worker * num_components field of nir_intrinsic_instr. If this value is -1, the
2055*61046927SAndroid Build Coastguard Worker * intrinsic consumes however many components are provided and it is not
2056*61046927SAndroid Build Coastguard Worker * validated at all.
2057*61046927SAndroid Build Coastguard Worker */
2058*61046927SAndroid Build Coastguard Worker int8_t src_components[NIR_INTRINSIC_MAX_INPUTS];
2059*61046927SAndroid Build Coastguard Worker
2060*61046927SAndroid Build Coastguard Worker bool has_dest;
2061*61046927SAndroid Build Coastguard Worker
2062*61046927SAndroid Build Coastguard Worker /** number of components of the output register
2063*61046927SAndroid Build Coastguard Worker *
2064*61046927SAndroid Build Coastguard Worker * If this value is 0, the number of components is given by the
2065*61046927SAndroid Build Coastguard Worker * num_components field of nir_intrinsic_instr.
2066*61046927SAndroid Build Coastguard Worker */
2067*61046927SAndroid Build Coastguard Worker uint8_t dest_components;
2068*61046927SAndroid Build Coastguard Worker
2069*61046927SAndroid Build Coastguard Worker /** bitfield of legal bit sizes */
2070*61046927SAndroid Build Coastguard Worker uint8_t dest_bit_sizes;
2071*61046927SAndroid Build Coastguard Worker
2072*61046927SAndroid Build Coastguard Worker /** source which the destination bit size must match
2073*61046927SAndroid Build Coastguard Worker *
2074*61046927SAndroid Build Coastguard Worker * Some intrinsics, such as subgroup intrinsics, are data manipulation
2075*61046927SAndroid Build Coastguard Worker * intrinsics and they have similar bit-size rules to ALU ops. This enables
2076*61046927SAndroid Build Coastguard Worker * validation to validate a bit more and enables auto-generated builder code
2077*61046927SAndroid Build Coastguard Worker * to properly determine destination bit sizes automatically.
2078*61046927SAndroid Build Coastguard Worker */
2079*61046927SAndroid Build Coastguard Worker int8_t bit_size_src;
2080*61046927SAndroid Build Coastguard Worker
2081*61046927SAndroid Build Coastguard Worker /** the number of constant indices used by the intrinsic */
2082*61046927SAndroid Build Coastguard Worker uint8_t num_indices;
2083*61046927SAndroid Build Coastguard Worker
2084*61046927SAndroid Build Coastguard Worker /** list of indices */
2085*61046927SAndroid Build Coastguard Worker uint8_t indices[NIR_INTRINSIC_MAX_CONST_INDEX];
2086*61046927SAndroid Build Coastguard Worker
2087*61046927SAndroid Build Coastguard Worker /** indicates the usage of intr->const_index[n] */
2088*61046927SAndroid Build Coastguard Worker uint8_t index_map[NIR_INTRINSIC_NUM_INDEX_FLAGS];
2089*61046927SAndroid Build Coastguard Worker
2090*61046927SAndroid Build Coastguard Worker /** semantic flags for calls to this intrinsic */
2091*61046927SAndroid Build Coastguard Worker nir_intrinsic_semantic_flag flags;
2092*61046927SAndroid Build Coastguard Worker } nir_intrinsic_info;
2093*61046927SAndroid Build Coastguard Worker
2094*61046927SAndroid Build Coastguard Worker extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
2095*61046927SAndroid Build Coastguard Worker
2096*61046927SAndroid Build Coastguard Worker unsigned
2097*61046927SAndroid Build Coastguard Worker nir_intrinsic_src_components(const nir_intrinsic_instr *intr, unsigned srcn);
2098*61046927SAndroid Build Coastguard Worker
2099*61046927SAndroid Build Coastguard Worker unsigned
2100*61046927SAndroid Build Coastguard Worker nir_intrinsic_dest_components(nir_intrinsic_instr *intr);
2101*61046927SAndroid Build Coastguard Worker
2102*61046927SAndroid Build Coastguard Worker nir_alu_type
2103*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr_src_type(const nir_intrinsic_instr *intrin, unsigned src);
2104*61046927SAndroid Build Coastguard Worker
2105*61046927SAndroid Build Coastguard Worker nir_alu_type
2106*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr_dest_type(const nir_intrinsic_instr *intrin);
2107*61046927SAndroid Build Coastguard Worker
2108*61046927SAndroid Build Coastguard Worker /**
2109*61046927SAndroid Build Coastguard Worker * Helper to copy const_index[] from src to dst, without assuming they
2110*61046927SAndroid Build Coastguard Worker * match in order.
2111*61046927SAndroid Build Coastguard Worker */
2112*61046927SAndroid Build Coastguard Worker void nir_intrinsic_copy_const_indices(nir_intrinsic_instr *dst, nir_intrinsic_instr *src);
2113*61046927SAndroid Build Coastguard Worker
2114*61046927SAndroid Build Coastguard Worker #include "nir_intrinsics_indices.h"
2115*61046927SAndroid Build Coastguard Worker
2116*61046927SAndroid Build Coastguard Worker static inline void
nir_intrinsic_set_align(nir_intrinsic_instr * intrin,unsigned align_mul,unsigned align_offset)2117*61046927SAndroid Build Coastguard Worker nir_intrinsic_set_align(nir_intrinsic_instr *intrin,
2118*61046927SAndroid Build Coastguard Worker unsigned align_mul, unsigned align_offset)
2119*61046927SAndroid Build Coastguard Worker {
2120*61046927SAndroid Build Coastguard Worker assert(util_is_power_of_two_nonzero(align_mul));
2121*61046927SAndroid Build Coastguard Worker assert(align_offset < align_mul);
2122*61046927SAndroid Build Coastguard Worker nir_intrinsic_set_align_mul(intrin, align_mul);
2123*61046927SAndroid Build Coastguard Worker nir_intrinsic_set_align_offset(intrin, align_offset);
2124*61046927SAndroid Build Coastguard Worker }
2125*61046927SAndroid Build Coastguard Worker
2126*61046927SAndroid Build Coastguard Worker /** Returns a simple alignment for an align_mul/offset pair
2127*61046927SAndroid Build Coastguard Worker *
2128*61046927SAndroid Build Coastguard Worker * This helper converts from the full mul+offset alignment scheme used by
2129*61046927SAndroid Build Coastguard Worker * most NIR intrinsics to a simple alignment. The returned value is the
2130*61046927SAndroid Build Coastguard Worker * largest power of two which divides both align_mul and align_offset.
2131*61046927SAndroid Build Coastguard Worker * For any offset X which satisfies the complex alignment described by
2132*61046927SAndroid Build Coastguard Worker * align_mul/offset, X % align == 0.
2133*61046927SAndroid Build Coastguard Worker */
2134*61046927SAndroid Build Coastguard Worker static inline uint32_t
nir_combined_align(uint32_t align_mul,uint32_t align_offset)2135*61046927SAndroid Build Coastguard Worker nir_combined_align(uint32_t align_mul, uint32_t align_offset)
2136*61046927SAndroid Build Coastguard Worker {
2137*61046927SAndroid Build Coastguard Worker assert(util_is_power_of_two_nonzero(align_mul));
2138*61046927SAndroid Build Coastguard Worker assert(align_offset < align_mul);
2139*61046927SAndroid Build Coastguard Worker return align_offset ? 1 << (ffs(align_offset) - 1) : align_mul;
2140*61046927SAndroid Build Coastguard Worker }
2141*61046927SAndroid Build Coastguard Worker
2142*61046927SAndroid Build Coastguard Worker /** Returns a simple alignment for a load/store intrinsic offset
2143*61046927SAndroid Build Coastguard Worker *
2144*61046927SAndroid Build Coastguard Worker * Instead of the full mul+offset alignment scheme provided by the ALIGN_MUL
2145*61046927SAndroid Build Coastguard Worker * and ALIGN_OFFSET parameters, this helper takes both into account and
2146*61046927SAndroid Build Coastguard Worker * provides a single simple alignment parameter. The offset X is guaranteed
2147*61046927SAndroid Build Coastguard Worker * to satisfy X % align == 0.
2148*61046927SAndroid Build Coastguard Worker */
2149*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_intrinsic_align(const nir_intrinsic_instr * intrin)2150*61046927SAndroid Build Coastguard Worker nir_intrinsic_align(const nir_intrinsic_instr *intrin)
2151*61046927SAndroid Build Coastguard Worker {
2152*61046927SAndroid Build Coastguard Worker return nir_combined_align(nir_intrinsic_align_mul(intrin),
2153*61046927SAndroid Build Coastguard Worker nir_intrinsic_align_offset(intrin));
2154*61046927SAndroid Build Coastguard Worker }
2155*61046927SAndroid Build Coastguard Worker
2156*61046927SAndroid Build Coastguard Worker static inline bool
nir_intrinsic_has_align(const nir_intrinsic_instr * intrin)2157*61046927SAndroid Build Coastguard Worker nir_intrinsic_has_align(const nir_intrinsic_instr *intrin)
2158*61046927SAndroid Build Coastguard Worker {
2159*61046927SAndroid Build Coastguard Worker return nir_intrinsic_has_align_mul(intrin) &&
2160*61046927SAndroid Build Coastguard Worker nir_intrinsic_has_align_offset(intrin);
2161*61046927SAndroid Build Coastguard Worker }
2162*61046927SAndroid Build Coastguard Worker
2163*61046927SAndroid Build Coastguard Worker unsigned
2164*61046927SAndroid Build Coastguard Worker nir_image_intrinsic_coord_components(const nir_intrinsic_instr *instr);
2165*61046927SAndroid Build Coastguard Worker
2166*61046927SAndroid Build Coastguard Worker /* Converts a image_deref_* intrinsic into a image_* one */
2167*61046927SAndroid Build Coastguard Worker void nir_rewrite_image_intrinsic(nir_intrinsic_instr *instr,
2168*61046927SAndroid Build Coastguard Worker nir_def *handle, bool bindless);
2169*61046927SAndroid Build Coastguard Worker
2170*61046927SAndroid Build Coastguard Worker /* Determine if an intrinsic can be arbitrarily reordered and eliminated. */
2171*61046927SAndroid Build Coastguard Worker static inline bool
nir_intrinsic_can_reorder(nir_intrinsic_instr * instr)2172*61046927SAndroid Build Coastguard Worker nir_intrinsic_can_reorder(nir_intrinsic_instr *instr)
2173*61046927SAndroid Build Coastguard Worker {
2174*61046927SAndroid Build Coastguard Worker if (nir_intrinsic_has_access(instr) &&
2175*61046927SAndroid Build Coastguard Worker nir_intrinsic_access(instr) & ACCESS_VOLATILE)
2176*61046927SAndroid Build Coastguard Worker return false;
2177*61046927SAndroid Build Coastguard Worker
2178*61046927SAndroid Build Coastguard Worker if (instr->intrinsic == nir_intrinsic_load_deref) {
2179*61046927SAndroid Build Coastguard Worker nir_deref_instr *deref = nir_src_as_deref(instr->src[0]);
2180*61046927SAndroid Build Coastguard Worker return nir_deref_mode_is_in_set(deref, nir_var_read_only_modes) ||
2181*61046927SAndroid Build Coastguard Worker (nir_intrinsic_access(instr) & ACCESS_CAN_REORDER);
2182*61046927SAndroid Build Coastguard Worker } else if (instr->intrinsic == nir_intrinsic_load_ssbo ||
2183*61046927SAndroid Build Coastguard Worker instr->intrinsic == nir_intrinsic_bindless_image_load ||
2184*61046927SAndroid Build Coastguard Worker instr->intrinsic == nir_intrinsic_image_deref_load ||
2185*61046927SAndroid Build Coastguard Worker instr->intrinsic == nir_intrinsic_image_load ||
2186*61046927SAndroid Build Coastguard Worker instr->intrinsic == nir_intrinsic_ald_nv ||
2187*61046927SAndroid Build Coastguard Worker instr->intrinsic == nir_intrinsic_load_sysval_nv) {
2188*61046927SAndroid Build Coastguard Worker return nir_intrinsic_access(instr) & ACCESS_CAN_REORDER;
2189*61046927SAndroid Build Coastguard Worker } else {
2190*61046927SAndroid Build Coastguard Worker const nir_intrinsic_info *info =
2191*61046927SAndroid Build Coastguard Worker &nir_intrinsic_infos[instr->intrinsic];
2192*61046927SAndroid Build Coastguard Worker return (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
2193*61046927SAndroid Build Coastguard Worker (info->flags & NIR_INTRINSIC_CAN_REORDER);
2194*61046927SAndroid Build Coastguard Worker }
2195*61046927SAndroid Build Coastguard Worker }
2196*61046927SAndroid Build Coastguard Worker
2197*61046927SAndroid Build Coastguard Worker bool nir_intrinsic_writes_external_memory(const nir_intrinsic_instr *instr);
2198*61046927SAndroid Build Coastguard Worker
2199*61046927SAndroid Build Coastguard Worker static inline bool
nir_intrinsic_is_ray_query(nir_intrinsic_op intrinsic)2200*61046927SAndroid Build Coastguard Worker nir_intrinsic_is_ray_query(nir_intrinsic_op intrinsic)
2201*61046927SAndroid Build Coastguard Worker {
2202*61046927SAndroid Build Coastguard Worker switch (intrinsic) {
2203*61046927SAndroid Build Coastguard Worker case nir_intrinsic_rq_confirm_intersection:
2204*61046927SAndroid Build Coastguard Worker case nir_intrinsic_rq_generate_intersection:
2205*61046927SAndroid Build Coastguard Worker case nir_intrinsic_rq_initialize:
2206*61046927SAndroid Build Coastguard Worker case nir_intrinsic_rq_load:
2207*61046927SAndroid Build Coastguard Worker case nir_intrinsic_rq_proceed:
2208*61046927SAndroid Build Coastguard Worker case nir_intrinsic_rq_terminate:
2209*61046927SAndroid Build Coastguard Worker return true;
2210*61046927SAndroid Build Coastguard Worker default:
2211*61046927SAndroid Build Coastguard Worker return false;
2212*61046927SAndroid Build Coastguard Worker }
2213*61046927SAndroid Build Coastguard Worker }
2214*61046927SAndroid Build Coastguard Worker
2215*61046927SAndroid Build Coastguard Worker /** Texture instruction source type */
2216*61046927SAndroid Build Coastguard Worker typedef enum nir_tex_src_type {
2217*61046927SAndroid Build Coastguard Worker /** Texture coordinate
2218*61046927SAndroid Build Coastguard Worker *
2219*61046927SAndroid Build Coastguard Worker * Must have :c:member:`nir_tex_instr.coord_components` components.
2220*61046927SAndroid Build Coastguard Worker */
2221*61046927SAndroid Build Coastguard Worker nir_tex_src_coord,
2222*61046927SAndroid Build Coastguard Worker
2223*61046927SAndroid Build Coastguard Worker /** Projector
2224*61046927SAndroid Build Coastguard Worker *
2225*61046927SAndroid Build Coastguard Worker * The texture coordinate (except for the array component, if any) is
2226*61046927SAndroid Build Coastguard Worker * divided by this value before LOD computation and sampling.
2227*61046927SAndroid Build Coastguard Worker *
2228*61046927SAndroid Build Coastguard Worker * Must be a float scalar.
2229*61046927SAndroid Build Coastguard Worker */
2230*61046927SAndroid Build Coastguard Worker nir_tex_src_projector,
2231*61046927SAndroid Build Coastguard Worker
2232*61046927SAndroid Build Coastguard Worker /** Shadow comparator
2233*61046927SAndroid Build Coastguard Worker *
2234*61046927SAndroid Build Coastguard Worker * For shadow sampling, the fetched texel values are compared against the
2235*61046927SAndroid Build Coastguard Worker * shadow comparator using the compare op specified by the sampler object
2236*61046927SAndroid Build Coastguard Worker * and converted to 1.0 if the comparison succeeds and 0.0 if it fails.
2237*61046927SAndroid Build Coastguard Worker * Interpolation happens after this conversion so the actual result may be
2238*61046927SAndroid Build Coastguard Worker * anywhere in the range [0.0, 1.0].
2239*61046927SAndroid Build Coastguard Worker *
2240*61046927SAndroid Build Coastguard Worker * Only valid if :c:member:`nir_tex_instr.is_shadow` and must be a float
2241*61046927SAndroid Build Coastguard Worker * scalar.
2242*61046927SAndroid Build Coastguard Worker */
2243*61046927SAndroid Build Coastguard Worker nir_tex_src_comparator,
2244*61046927SAndroid Build Coastguard Worker
2245*61046927SAndroid Build Coastguard Worker /** Coordinate offset
2246*61046927SAndroid Build Coastguard Worker *
2247*61046927SAndroid Build Coastguard Worker * An integer value that is added to the texel address before sampling.
2248*61046927SAndroid Build Coastguard Worker * This is only allowed with operations that take an explicit LOD as it is
2249*61046927SAndroid Build Coastguard Worker * applied in integer texel space after LOD selection and not normalized
2250*61046927SAndroid Build Coastguard Worker * coordinate space.
2251*61046927SAndroid Build Coastguard Worker */
2252*61046927SAndroid Build Coastguard Worker nir_tex_src_offset,
2253*61046927SAndroid Build Coastguard Worker
2254*61046927SAndroid Build Coastguard Worker /** LOD bias
2255*61046927SAndroid Build Coastguard Worker *
2256*61046927SAndroid Build Coastguard Worker * This value is added to the computed LOD before mip-mapping.
2257*61046927SAndroid Build Coastguard Worker */
2258*61046927SAndroid Build Coastguard Worker nir_tex_src_bias,
2259*61046927SAndroid Build Coastguard Worker
2260*61046927SAndroid Build Coastguard Worker /** Explicit LOD */
2261*61046927SAndroid Build Coastguard Worker nir_tex_src_lod,
2262*61046927SAndroid Build Coastguard Worker
2263*61046927SAndroid Build Coastguard Worker /** Min LOD
2264*61046927SAndroid Build Coastguard Worker *
2265*61046927SAndroid Build Coastguard Worker * The computed LOD is clamped to be at least as large as min_lod before
2266*61046927SAndroid Build Coastguard Worker * mip-mapping.
2267*61046927SAndroid Build Coastguard Worker */
2268*61046927SAndroid Build Coastguard Worker nir_tex_src_min_lod,
2269*61046927SAndroid Build Coastguard Worker
2270*61046927SAndroid Build Coastguard Worker /** MSAA sample index */
2271*61046927SAndroid Build Coastguard Worker nir_tex_src_ms_index,
2272*61046927SAndroid Build Coastguard Worker
2273*61046927SAndroid Build Coastguard Worker /** Intel-specific MSAA compression data */
2274*61046927SAndroid Build Coastguard Worker nir_tex_src_ms_mcs_intel,
2275*61046927SAndroid Build Coastguard Worker
2276*61046927SAndroid Build Coastguard Worker /** Explicit horizontal (X-major) coordinate derivative */
2277*61046927SAndroid Build Coastguard Worker nir_tex_src_ddx,
2278*61046927SAndroid Build Coastguard Worker
2279*61046927SAndroid Build Coastguard Worker /** Explicit vertical (Y-major) coordinate derivative */
2280*61046927SAndroid Build Coastguard Worker nir_tex_src_ddy,
2281*61046927SAndroid Build Coastguard Worker
2282*61046927SAndroid Build Coastguard Worker /** Texture variable dereference */
2283*61046927SAndroid Build Coastguard Worker nir_tex_src_texture_deref,
2284*61046927SAndroid Build Coastguard Worker
2285*61046927SAndroid Build Coastguard Worker /** Sampler variable dereference */
2286*61046927SAndroid Build Coastguard Worker nir_tex_src_sampler_deref,
2287*61046927SAndroid Build Coastguard Worker
2288*61046927SAndroid Build Coastguard Worker /** Texture index offset
2289*61046927SAndroid Build Coastguard Worker *
2290*61046927SAndroid Build Coastguard Worker * This is added to :c:member:`nir_tex_instr.texture_index`. Unless
2291*61046927SAndroid Build Coastguard Worker * :c:member:`nir_tex_instr.texture_non_uniform` is set, this is guaranteed
2292*61046927SAndroid Build Coastguard Worker * to be dynamically uniform.
2293*61046927SAndroid Build Coastguard Worker */
2294*61046927SAndroid Build Coastguard Worker nir_tex_src_texture_offset,
2295*61046927SAndroid Build Coastguard Worker
2296*61046927SAndroid Build Coastguard Worker /** Dynamically uniform sampler index offset
2297*61046927SAndroid Build Coastguard Worker *
2298*61046927SAndroid Build Coastguard Worker * This is added to :c:member:`nir_tex_instr.sampler_index`. Unless
2299*61046927SAndroid Build Coastguard Worker * :c:member:`nir_tex_instr.sampler_non_uniform` is set, this is guaranteed to be
2300*61046927SAndroid Build Coastguard Worker * dynamically uniform. This should not be present until GLSL ES 3.20, GLSL
2301*61046927SAndroid Build Coastguard Worker * 4.00, or ARB_gpu_shader5, because in ES 3.10 and GL 3.30 samplers said
2302*61046927SAndroid Build Coastguard Worker * "When aggregated into arrays within a shader, samplers can only be indexed
2303*61046927SAndroid Build Coastguard Worker * with a constant integral expression."
2304*61046927SAndroid Build Coastguard Worker */
2305*61046927SAndroid Build Coastguard Worker nir_tex_src_sampler_offset,
2306*61046927SAndroid Build Coastguard Worker
2307*61046927SAndroid Build Coastguard Worker /** Bindless texture handle
2308*61046927SAndroid Build Coastguard Worker *
2309*61046927SAndroid Build Coastguard Worker * This is, unfortunately, a bit overloaded at the moment. There are
2310*61046927SAndroid Build Coastguard Worker * generally two types of bindless handles:
2311*61046927SAndroid Build Coastguard Worker *
2312*61046927SAndroid Build Coastguard Worker * 1. For GL_ARB_bindless bindless handles. These are part of the
2313*61046927SAndroid Build Coastguard Worker * GL/Gallium-level API and are always a 64-bit integer.
2314*61046927SAndroid Build Coastguard Worker *
2315*61046927SAndroid Build Coastguard Worker * 2. HW-specific handles. GL_ARB_bindless handles may be lowered to
2316*61046927SAndroid Build Coastguard Worker * these. Also, these are used by many Vulkan drivers to implement
2317*61046927SAndroid Build Coastguard Worker * descriptor sets, especially for UPDATE_AFTER_BIND descriptors.
2318*61046927SAndroid Build Coastguard Worker * The details of hardware handles (bit size, format, etc.) is
2319*61046927SAndroid Build Coastguard Worker * HW-specific.
2320*61046927SAndroid Build Coastguard Worker *
2321*61046927SAndroid Build Coastguard Worker * Because of this overloading and the resulting ambiguity, we currently
2322*61046927SAndroid Build Coastguard Worker * don't validate anything for these.
2323*61046927SAndroid Build Coastguard Worker */
2324*61046927SAndroid Build Coastguard Worker nir_tex_src_texture_handle,
2325*61046927SAndroid Build Coastguard Worker
2326*61046927SAndroid Build Coastguard Worker /** Bindless sampler handle
2327*61046927SAndroid Build Coastguard Worker *
2328*61046927SAndroid Build Coastguard Worker * See nir_tex_src_texture_handle,
2329*61046927SAndroid Build Coastguard Worker */
2330*61046927SAndroid Build Coastguard Worker nir_tex_src_sampler_handle,
2331*61046927SAndroid Build Coastguard Worker
2332*61046927SAndroid Build Coastguard Worker /** Tex src intrinsic
2333*61046927SAndroid Build Coastguard Worker *
2334*61046927SAndroid Build Coastguard Worker * This is an intrinsic used before function inlining i.e. before we know
2335*61046927SAndroid Build Coastguard Worker * if a bindless value has been given as function param for use as a tex
2336*61046927SAndroid Build Coastguard Worker * src.
2337*61046927SAndroid Build Coastguard Worker */
2338*61046927SAndroid Build Coastguard Worker nir_tex_src_sampler_deref_intrinsic,
2339*61046927SAndroid Build Coastguard Worker nir_tex_src_texture_deref_intrinsic,
2340*61046927SAndroid Build Coastguard Worker
2341*61046927SAndroid Build Coastguard Worker /** Plane index for multi-plane YCbCr textures */
2342*61046927SAndroid Build Coastguard Worker nir_tex_src_plane,
2343*61046927SAndroid Build Coastguard Worker
2344*61046927SAndroid Build Coastguard Worker /**
2345*61046927SAndroid Build Coastguard Worker * Backend-specific vec4 tex src argument.
2346*61046927SAndroid Build Coastguard Worker *
2347*61046927SAndroid Build Coastguard Worker * Can be used to have NIR optimization (copy propagation, lower_vec_to_regs)
2348*61046927SAndroid Build Coastguard Worker * apply to the packing of the tex srcs. This lowering must only happen
2349*61046927SAndroid Build Coastguard Worker * after nir_lower_tex().
2350*61046927SAndroid Build Coastguard Worker *
2351*61046927SAndroid Build Coastguard Worker * The nir_tex_instr_src_type() of this argument is float, so no lowering
2352*61046927SAndroid Build Coastguard Worker * will happen if nir_lower_int_to_float is used.
2353*61046927SAndroid Build Coastguard Worker */
2354*61046927SAndroid Build Coastguard Worker nir_tex_src_backend1,
2355*61046927SAndroid Build Coastguard Worker
2356*61046927SAndroid Build Coastguard Worker /** Second backend-specific vec4 tex src argument, see nir_tex_src_backend1. */
2357*61046927SAndroid Build Coastguard Worker nir_tex_src_backend2,
2358*61046927SAndroid Build Coastguard Worker
2359*61046927SAndroid Build Coastguard Worker nir_num_tex_src_types
2360*61046927SAndroid Build Coastguard Worker } nir_tex_src_type;
2361*61046927SAndroid Build Coastguard Worker
2362*61046927SAndroid Build Coastguard Worker /** A texture instruction source */
2363*61046927SAndroid Build Coastguard Worker typedef struct nir_tex_src {
2364*61046927SAndroid Build Coastguard Worker /** Base source */
2365*61046927SAndroid Build Coastguard Worker nir_src src;
2366*61046927SAndroid Build Coastguard Worker
2367*61046927SAndroid Build Coastguard Worker /** Type of this source */
2368*61046927SAndroid Build Coastguard Worker nir_tex_src_type src_type;
2369*61046927SAndroid Build Coastguard Worker } nir_tex_src;
2370*61046927SAndroid Build Coastguard Worker
2371*61046927SAndroid Build Coastguard Worker /** Texture instruction opcode */
2372*61046927SAndroid Build Coastguard Worker typedef enum nir_texop {
2373*61046927SAndroid Build Coastguard Worker /** Regular texture look-up */
2374*61046927SAndroid Build Coastguard Worker nir_texop_tex,
2375*61046927SAndroid Build Coastguard Worker /** Texture look-up with LOD bias */
2376*61046927SAndroid Build Coastguard Worker nir_texop_txb,
2377*61046927SAndroid Build Coastguard Worker /** Texture look-up with explicit LOD */
2378*61046927SAndroid Build Coastguard Worker nir_texop_txl,
2379*61046927SAndroid Build Coastguard Worker /** Texture look-up with partial derivatives */
2380*61046927SAndroid Build Coastguard Worker nir_texop_txd,
2381*61046927SAndroid Build Coastguard Worker /** Texel fetch with explicit LOD */
2382*61046927SAndroid Build Coastguard Worker nir_texop_txf,
2383*61046927SAndroid Build Coastguard Worker /** Multisample texture fetch */
2384*61046927SAndroid Build Coastguard Worker nir_texop_txf_ms,
2385*61046927SAndroid Build Coastguard Worker /** Multisample texture fetch from framebuffer */
2386*61046927SAndroid Build Coastguard Worker nir_texop_txf_ms_fb,
2387*61046927SAndroid Build Coastguard Worker /** Multisample compression value fetch */
2388*61046927SAndroid Build Coastguard Worker nir_texop_txf_ms_mcs_intel,
2389*61046927SAndroid Build Coastguard Worker /** Texture size */
2390*61046927SAndroid Build Coastguard Worker nir_texop_txs,
2391*61046927SAndroid Build Coastguard Worker /** Texture lod query */
2392*61046927SAndroid Build Coastguard Worker nir_texop_lod,
2393*61046927SAndroid Build Coastguard Worker /** Texture gather */
2394*61046927SAndroid Build Coastguard Worker nir_texop_tg4,
2395*61046927SAndroid Build Coastguard Worker /** Texture levels query */
2396*61046927SAndroid Build Coastguard Worker nir_texop_query_levels,
2397*61046927SAndroid Build Coastguard Worker /** Texture samples query */
2398*61046927SAndroid Build Coastguard Worker nir_texop_texture_samples,
2399*61046927SAndroid Build Coastguard Worker /** Query whether all samples are definitely identical. */
2400*61046927SAndroid Build Coastguard Worker nir_texop_samples_identical,
2401*61046927SAndroid Build Coastguard Worker /** Regular texture look-up, eligible for pre-dispatch */
2402*61046927SAndroid Build Coastguard Worker nir_texop_tex_prefetch,
2403*61046927SAndroid Build Coastguard Worker /** Multisample fragment color texture fetch */
2404*61046927SAndroid Build Coastguard Worker nir_texop_fragment_fetch_amd,
2405*61046927SAndroid Build Coastguard Worker /** Multisample fragment mask texture fetch */
2406*61046927SAndroid Build Coastguard Worker nir_texop_fragment_mask_fetch_amd,
2407*61046927SAndroid Build Coastguard Worker /** Returns a buffer or image descriptor. */
2408*61046927SAndroid Build Coastguard Worker nir_texop_descriptor_amd,
2409*61046927SAndroid Build Coastguard Worker /** Returns a sampler descriptor. */
2410*61046927SAndroid Build Coastguard Worker nir_texop_sampler_descriptor_amd,
2411*61046927SAndroid Build Coastguard Worker /** Returns the sampler's LOD bias */
2412*61046927SAndroid Build Coastguard Worker nir_texop_lod_bias_agx,
2413*61046927SAndroid Build Coastguard Worker /** Returns a bool indicating that the sampler uses a custom border colour */
2414*61046927SAndroid Build Coastguard Worker nir_texop_has_custom_border_color_agx,
2415*61046927SAndroid Build Coastguard Worker /** Returns the sampler's custom border colour (if has_custom_border_agx) */
2416*61046927SAndroid Build Coastguard Worker nir_texop_custom_border_color_agx,
2417*61046927SAndroid Build Coastguard Worker /** Maps to TXQ.DIMENSION */
2418*61046927SAndroid Build Coastguard Worker nir_texop_hdr_dim_nv,
2419*61046927SAndroid Build Coastguard Worker /** Maps to TXQ.TEXTURE_TYPE */
2420*61046927SAndroid Build Coastguard Worker nir_texop_tex_type_nv,
2421*61046927SAndroid Build Coastguard Worker } nir_texop;
2422*61046927SAndroid Build Coastguard Worker
2423*61046927SAndroid Build Coastguard Worker /** Represents a texture instruction */
2424*61046927SAndroid Build Coastguard Worker typedef struct nir_tex_instr {
2425*61046927SAndroid Build Coastguard Worker /** Base instruction */
2426*61046927SAndroid Build Coastguard Worker nir_instr instr;
2427*61046927SAndroid Build Coastguard Worker
2428*61046927SAndroid Build Coastguard Worker /** Dimensionality of the texture operation
2429*61046927SAndroid Build Coastguard Worker *
2430*61046927SAndroid Build Coastguard Worker * This will typically match the dimensionality of the texture deref type
2431*61046927SAndroid Build Coastguard Worker * if a nir_tex_src_texture_deref is present. However, it may not if
2432*61046927SAndroid Build Coastguard Worker * texture lowering has occurred.
2433*61046927SAndroid Build Coastguard Worker */
2434*61046927SAndroid Build Coastguard Worker enum glsl_sampler_dim sampler_dim;
2435*61046927SAndroid Build Coastguard Worker
2436*61046927SAndroid Build Coastguard Worker /** ALU type of the destination
2437*61046927SAndroid Build Coastguard Worker *
2438*61046927SAndroid Build Coastguard Worker * This is the canonical sampled type for this texture operation and may
2439*61046927SAndroid Build Coastguard Worker * not exactly match the sampled type of the deref type when a
2440*61046927SAndroid Build Coastguard Worker * nir_tex_src_texture_deref is present. For OpenCL, the sampled type of
2441*61046927SAndroid Build Coastguard Worker * the texture deref will be GLSL_TYPE_VOID and this is allowed to be
2442*61046927SAndroid Build Coastguard Worker * anything. With SPIR-V, the signedness of integer types is allowed to
2443*61046927SAndroid Build Coastguard Worker * differ. For all APIs, the bit size may differ if the driver has done
2444*61046927SAndroid Build Coastguard Worker * any sort of mediump or similar lowering since texture types always have
2445*61046927SAndroid Build Coastguard Worker * 32-bit sampled types.
2446*61046927SAndroid Build Coastguard Worker */
2447*61046927SAndroid Build Coastguard Worker nir_alu_type dest_type;
2448*61046927SAndroid Build Coastguard Worker
2449*61046927SAndroid Build Coastguard Worker /** Texture opcode */
2450*61046927SAndroid Build Coastguard Worker nir_texop op;
2451*61046927SAndroid Build Coastguard Worker
2452*61046927SAndroid Build Coastguard Worker /** Destination */
2453*61046927SAndroid Build Coastguard Worker nir_def def;
2454*61046927SAndroid Build Coastguard Worker
2455*61046927SAndroid Build Coastguard Worker /** Array of sources
2456*61046927SAndroid Build Coastguard Worker *
2457*61046927SAndroid Build Coastguard Worker * This array has :c:member:`nir_tex_instr.num_srcs` elements
2458*61046927SAndroid Build Coastguard Worker */
2459*61046927SAndroid Build Coastguard Worker nir_tex_src *src;
2460*61046927SAndroid Build Coastguard Worker
2461*61046927SAndroid Build Coastguard Worker /** Number of sources */
2462*61046927SAndroid Build Coastguard Worker unsigned num_srcs;
2463*61046927SAndroid Build Coastguard Worker
2464*61046927SAndroid Build Coastguard Worker /** Number of components in the coordinate, if any */
2465*61046927SAndroid Build Coastguard Worker unsigned coord_components;
2466*61046927SAndroid Build Coastguard Worker
2467*61046927SAndroid Build Coastguard Worker /** True if the texture instruction acts on an array texture */
2468*61046927SAndroid Build Coastguard Worker bool is_array;
2469*61046927SAndroid Build Coastguard Worker
2470*61046927SAndroid Build Coastguard Worker /** True if the texture instruction performs a shadow comparison
2471*61046927SAndroid Build Coastguard Worker *
2472*61046927SAndroid Build Coastguard Worker * If this is true, the texture instruction must have a
2473*61046927SAndroid Build Coastguard Worker * nir_tex_src_comparator.
2474*61046927SAndroid Build Coastguard Worker */
2475*61046927SAndroid Build Coastguard Worker bool is_shadow;
2476*61046927SAndroid Build Coastguard Worker
2477*61046927SAndroid Build Coastguard Worker /**
2478*61046927SAndroid Build Coastguard Worker * If is_shadow is true, whether this is the old-style shadow that outputs
2479*61046927SAndroid Build Coastguard Worker * 4 components or the new-style shadow that outputs 1 component.
2480*61046927SAndroid Build Coastguard Worker */
2481*61046927SAndroid Build Coastguard Worker bool is_new_style_shadow;
2482*61046927SAndroid Build Coastguard Worker
2483*61046927SAndroid Build Coastguard Worker /**
2484*61046927SAndroid Build Coastguard Worker * True if this texture instruction should return a sparse residency code.
2485*61046927SAndroid Build Coastguard Worker * The code is in the last component of the result.
2486*61046927SAndroid Build Coastguard Worker */
2487*61046927SAndroid Build Coastguard Worker bool is_sparse;
2488*61046927SAndroid Build Coastguard Worker
2489*61046927SAndroid Build Coastguard Worker /** nir_texop_tg4 component selector
2490*61046927SAndroid Build Coastguard Worker *
2491*61046927SAndroid Build Coastguard Worker * This determines which RGBA component is gathered.
2492*61046927SAndroid Build Coastguard Worker */
2493*61046927SAndroid Build Coastguard Worker unsigned component : 2;
2494*61046927SAndroid Build Coastguard Worker
2495*61046927SAndroid Build Coastguard Worker /** Validation needs to know this for gradient component count */
2496*61046927SAndroid Build Coastguard Worker unsigned array_is_lowered_cube : 1;
2497*61046927SAndroid Build Coastguard Worker
2498*61046927SAndroid Build Coastguard Worker /** True if this tg4 instruction has an implicit LOD or LOD bias, instead of using level 0 */
2499*61046927SAndroid Build Coastguard Worker unsigned is_gather_implicit_lod : 1;
2500*61046927SAndroid Build Coastguard Worker
2501*61046927SAndroid Build Coastguard Worker /** Gather offsets */
2502*61046927SAndroid Build Coastguard Worker int8_t tg4_offsets[4][2];
2503*61046927SAndroid Build Coastguard Worker
2504*61046927SAndroid Build Coastguard Worker /** True if the texture index or handle is not dynamically uniform */
2505*61046927SAndroid Build Coastguard Worker bool texture_non_uniform;
2506*61046927SAndroid Build Coastguard Worker
2507*61046927SAndroid Build Coastguard Worker /** True if the sampler index or handle is not dynamically uniform.
2508*61046927SAndroid Build Coastguard Worker *
2509*61046927SAndroid Build Coastguard Worker * This may be set when VK_EXT_descriptor_indexing is supported and the
2510*61046927SAndroid Build Coastguard Worker * appropriate capability is enabled.
2511*61046927SAndroid Build Coastguard Worker *
2512*61046927SAndroid Build Coastguard Worker * This should always be false in GLSL (GLSL ES 3.20 says "When aggregated
2513*61046927SAndroid Build Coastguard Worker * into arrays within a shader, opaque types can only be indexed with a
2514*61046927SAndroid Build Coastguard Worker * dynamically uniform integral expression", and GLSL 4.60 says "When
2515*61046927SAndroid Build Coastguard Worker * aggregated into arrays within a shader, [texture, sampler, and
2516*61046927SAndroid Build Coastguard Worker * samplerShadow] types can only be indexed with a dynamically uniform
2517*61046927SAndroid Build Coastguard Worker * expression, or texture lookup will result in undefined values.").
2518*61046927SAndroid Build Coastguard Worker */
2519*61046927SAndroid Build Coastguard Worker bool sampler_non_uniform;
2520*61046927SAndroid Build Coastguard Worker
2521*61046927SAndroid Build Coastguard Worker /** The texture index
2522*61046927SAndroid Build Coastguard Worker *
2523*61046927SAndroid Build Coastguard Worker * If this texture instruction has a nir_tex_src_texture_offset source,
2524*61046927SAndroid Build Coastguard Worker * then the texture index is given by texture_index + texture_offset.
2525*61046927SAndroid Build Coastguard Worker */
2526*61046927SAndroid Build Coastguard Worker unsigned texture_index;
2527*61046927SAndroid Build Coastguard Worker
2528*61046927SAndroid Build Coastguard Worker /** The sampler index
2529*61046927SAndroid Build Coastguard Worker *
2530*61046927SAndroid Build Coastguard Worker * The following operations do not require a sampler and, as such, this
2531*61046927SAndroid Build Coastguard Worker * field should be ignored:
2532*61046927SAndroid Build Coastguard Worker *
2533*61046927SAndroid Build Coastguard Worker * - nir_texop_txf
2534*61046927SAndroid Build Coastguard Worker * - nir_texop_txf_ms
2535*61046927SAndroid Build Coastguard Worker * - nir_texop_txs
2536*61046927SAndroid Build Coastguard Worker * - nir_texop_query_levels
2537*61046927SAndroid Build Coastguard Worker * - nir_texop_texture_samples
2538*61046927SAndroid Build Coastguard Worker * - nir_texop_samples_identical
2539*61046927SAndroid Build Coastguard Worker *
2540*61046927SAndroid Build Coastguard Worker * If this texture instruction has a nir_tex_src_sampler_offset source,
2541*61046927SAndroid Build Coastguard Worker * then the sampler index is given by sampler_index + sampler_offset.
2542*61046927SAndroid Build Coastguard Worker */
2543*61046927SAndroid Build Coastguard Worker unsigned sampler_index;
2544*61046927SAndroid Build Coastguard Worker
2545*61046927SAndroid Build Coastguard Worker /* Back-end specific flags, intended to be used in combination with
2546*61046927SAndroid Build Coastguard Worker * nir_tex_src_backend1/2 to provide additional hw-specific information
2547*61046927SAndroid Build Coastguard Worker * to the back-end compiler.
2548*61046927SAndroid Build Coastguard Worker */
2549*61046927SAndroid Build Coastguard Worker uint32_t backend_flags;
2550*61046927SAndroid Build Coastguard Worker } nir_tex_instr;
2551*61046927SAndroid Build Coastguard Worker
2552*61046927SAndroid Build Coastguard Worker /**
2553*61046927SAndroid Build Coastguard Worker * Returns true if the texture operation requires a sampler as a general rule
2554*61046927SAndroid Build Coastguard Worker *
2555*61046927SAndroid Build Coastguard Worker * Note that the specific hw/driver backend could require to a sampler
2556*61046927SAndroid Build Coastguard Worker * object/configuration packet in any case, for some other reason.
2557*61046927SAndroid Build Coastguard Worker *
2558*61046927SAndroid Build Coastguard Worker * See also :c:member:`nir_tex_instr.sampler_index`.
2559*61046927SAndroid Build Coastguard Worker */
2560*61046927SAndroid Build Coastguard Worker bool nir_tex_instr_need_sampler(const nir_tex_instr *instr);
2561*61046927SAndroid Build Coastguard Worker
2562*61046927SAndroid Build Coastguard Worker /** Returns the number of components returned by this nir_tex_instr
2563*61046927SAndroid Build Coastguard Worker *
2564*61046927SAndroid Build Coastguard Worker * Useful for code building texture instructions when you don't want to think
2565*61046927SAndroid Build Coastguard Worker * about how many components a particular texture op returns. This does not
2566*61046927SAndroid Build Coastguard Worker * include the sparse residency code.
2567*61046927SAndroid Build Coastguard Worker */
2568*61046927SAndroid Build Coastguard Worker unsigned
2569*61046927SAndroid Build Coastguard Worker nir_tex_instr_result_size(const nir_tex_instr *instr);
2570*61046927SAndroid Build Coastguard Worker
2571*61046927SAndroid Build Coastguard Worker /**
2572*61046927SAndroid Build Coastguard Worker * Returns the destination size of this nir_tex_instr including the sparse
2573*61046927SAndroid Build Coastguard Worker * residency code, if any.
2574*61046927SAndroid Build Coastguard Worker */
2575*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_tex_instr_dest_size(const nir_tex_instr * instr)2576*61046927SAndroid Build Coastguard Worker nir_tex_instr_dest_size(const nir_tex_instr *instr)
2577*61046927SAndroid Build Coastguard Worker {
2578*61046927SAndroid Build Coastguard Worker /* One more component is needed for the residency code. */
2579*61046927SAndroid Build Coastguard Worker return nir_tex_instr_result_size(instr) + instr->is_sparse;
2580*61046927SAndroid Build Coastguard Worker }
2581*61046927SAndroid Build Coastguard Worker
2582*61046927SAndroid Build Coastguard Worker /**
2583*61046927SAndroid Build Coastguard Worker * Returns true if this texture operation queries something about the texture
2584*61046927SAndroid Build Coastguard Worker * rather than actually sampling it.
2585*61046927SAndroid Build Coastguard Worker */
2586*61046927SAndroid Build Coastguard Worker bool
2587*61046927SAndroid Build Coastguard Worker nir_tex_instr_is_query(const nir_tex_instr *instr);
2588*61046927SAndroid Build Coastguard Worker
2589*61046927SAndroid Build Coastguard Worker /** Returns true if this texture instruction does implicit derivatives
2590*61046927SAndroid Build Coastguard Worker *
2591*61046927SAndroid Build Coastguard Worker * This is important as there are extra control-flow rules around derivatives
2592*61046927SAndroid Build Coastguard Worker * and texture instructions which perform them implicitly.
2593*61046927SAndroid Build Coastguard Worker */
2594*61046927SAndroid Build Coastguard Worker bool
2595*61046927SAndroid Build Coastguard Worker nir_tex_instr_has_implicit_derivative(const nir_tex_instr *instr);
2596*61046927SAndroid Build Coastguard Worker
2597*61046927SAndroid Build Coastguard Worker /** Returns the ALU type of the given texture instruction source */
2598*61046927SAndroid Build Coastguard Worker nir_alu_type
2599*61046927SAndroid Build Coastguard Worker nir_tex_instr_src_type(const nir_tex_instr *instr, unsigned src);
2600*61046927SAndroid Build Coastguard Worker
2601*61046927SAndroid Build Coastguard Worker /**
2602*61046927SAndroid Build Coastguard Worker * Returns the number of components required by the given texture instruction
2603*61046927SAndroid Build Coastguard Worker * source
2604*61046927SAndroid Build Coastguard Worker */
2605*61046927SAndroid Build Coastguard Worker unsigned
2606*61046927SAndroid Build Coastguard Worker nir_tex_instr_src_size(const nir_tex_instr *instr, unsigned src);
2607*61046927SAndroid Build Coastguard Worker
2608*61046927SAndroid Build Coastguard Worker /**
2609*61046927SAndroid Build Coastguard Worker * Returns the index of the texture instruction source with the given
2610*61046927SAndroid Build Coastguard Worker * nir_tex_src_type or -1 if no such source exists.
2611*61046927SAndroid Build Coastguard Worker */
2612*61046927SAndroid Build Coastguard Worker static inline int
nir_tex_instr_src_index(const nir_tex_instr * instr,nir_tex_src_type type)2613*61046927SAndroid Build Coastguard Worker nir_tex_instr_src_index(const nir_tex_instr *instr, nir_tex_src_type type)
2614*61046927SAndroid Build Coastguard Worker {
2615*61046927SAndroid Build Coastguard Worker for (unsigned i = 0; i < instr->num_srcs; i++)
2616*61046927SAndroid Build Coastguard Worker if (instr->src[i].src_type == type)
2617*61046927SAndroid Build Coastguard Worker return (int)i;
2618*61046927SAndroid Build Coastguard Worker
2619*61046927SAndroid Build Coastguard Worker return -1;
2620*61046927SAndroid Build Coastguard Worker }
2621*61046927SAndroid Build Coastguard Worker
2622*61046927SAndroid Build Coastguard Worker /** Adds a source to a texture instruction */
2623*61046927SAndroid Build Coastguard Worker void nir_tex_instr_add_src(nir_tex_instr *tex,
2624*61046927SAndroid Build Coastguard Worker nir_tex_src_type src_type,
2625*61046927SAndroid Build Coastguard Worker nir_def *src);
2626*61046927SAndroid Build Coastguard Worker
2627*61046927SAndroid Build Coastguard Worker /** Removes a source from a texture instruction */
2628*61046927SAndroid Build Coastguard Worker void nir_tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx);
2629*61046927SAndroid Build Coastguard Worker
2630*61046927SAndroid Build Coastguard Worker bool nir_tex_instr_has_explicit_tg4_offsets(nir_tex_instr *tex);
2631*61046927SAndroid Build Coastguard Worker
2632*61046927SAndroid Build Coastguard Worker typedef struct {
2633*61046927SAndroid Build Coastguard Worker nir_instr instr;
2634*61046927SAndroid Build Coastguard Worker
2635*61046927SAndroid Build Coastguard Worker nir_def def;
2636*61046927SAndroid Build Coastguard Worker
2637*61046927SAndroid Build Coastguard Worker nir_const_value value[];
2638*61046927SAndroid Build Coastguard Worker } nir_load_const_instr;
2639*61046927SAndroid Build Coastguard Worker
2640*61046927SAndroid Build Coastguard Worker typedef enum {
2641*61046927SAndroid Build Coastguard Worker /** Return from a function
2642*61046927SAndroid Build Coastguard Worker *
2643*61046927SAndroid Build Coastguard Worker * This instruction is a classic function return. It jumps to
2644*61046927SAndroid Build Coastguard Worker * nir_function_impl::end_block. No return value is provided in this
2645*61046927SAndroid Build Coastguard Worker * instruction. Instead, the function is expected to write any return
2646*61046927SAndroid Build Coastguard Worker * data to a deref passed in from the caller.
2647*61046927SAndroid Build Coastguard Worker */
2648*61046927SAndroid Build Coastguard Worker nir_jump_return,
2649*61046927SAndroid Build Coastguard Worker
2650*61046927SAndroid Build Coastguard Worker /** Immediately exit the current shader
2651*61046927SAndroid Build Coastguard Worker *
2652*61046927SAndroid Build Coastguard Worker * This instruction is roughly the equivalent of C's "exit()" in that it
2653*61046927SAndroid Build Coastguard Worker * immediately terminates the current shader invocation. From a CFG
2654*61046927SAndroid Build Coastguard Worker * perspective, it looks like a jump to nir_function_impl::end_block but
2655*61046927SAndroid Build Coastguard Worker * it actually jumps to the end block of the shader entrypoint. A halt
2656*61046927SAndroid Build Coastguard Worker * instruction in the shader entrypoint itself is semantically identical
2657*61046927SAndroid Build Coastguard Worker * to a return.
2658*61046927SAndroid Build Coastguard Worker *
2659*61046927SAndroid Build Coastguard Worker * For shaders with built-in I/O, any outputs written prior to a halt
2660*61046927SAndroid Build Coastguard Worker * instruction remain written and any outputs not written prior to the
2661*61046927SAndroid Build Coastguard Worker * halt have undefined values. It does NOT cause an implicit discard of
2662*61046927SAndroid Build Coastguard Worker * written results. If one wants discard results in a fragment shader,
2663*61046927SAndroid Build Coastguard Worker * for instance, a discard or demote intrinsic is required.
2664*61046927SAndroid Build Coastguard Worker */
2665*61046927SAndroid Build Coastguard Worker nir_jump_halt,
2666*61046927SAndroid Build Coastguard Worker
2667*61046927SAndroid Build Coastguard Worker /** Break out of the inner-most loop
2668*61046927SAndroid Build Coastguard Worker *
2669*61046927SAndroid Build Coastguard Worker * This has the same semantics as C's "break" statement.
2670*61046927SAndroid Build Coastguard Worker */
2671*61046927SAndroid Build Coastguard Worker nir_jump_break,
2672*61046927SAndroid Build Coastguard Worker
2673*61046927SAndroid Build Coastguard Worker /** Jump back to the top of the inner-most loop
2674*61046927SAndroid Build Coastguard Worker *
2675*61046927SAndroid Build Coastguard Worker * This has the same semantics as C's "continue" statement assuming that a
2676*61046927SAndroid Build Coastguard Worker * NIR loop is implemented as "while (1) { body }".
2677*61046927SAndroid Build Coastguard Worker */
2678*61046927SAndroid Build Coastguard Worker nir_jump_continue,
2679*61046927SAndroid Build Coastguard Worker
2680*61046927SAndroid Build Coastguard Worker /** Jumps for unstructured CFG.
2681*61046927SAndroid Build Coastguard Worker *
2682*61046927SAndroid Build Coastguard Worker * As within an unstructured CFG we can't rely on block ordering we need to
2683*61046927SAndroid Build Coastguard Worker * place explicit jumps at the end of every block.
2684*61046927SAndroid Build Coastguard Worker */
2685*61046927SAndroid Build Coastguard Worker nir_jump_goto,
2686*61046927SAndroid Build Coastguard Worker nir_jump_goto_if,
2687*61046927SAndroid Build Coastguard Worker } nir_jump_type;
2688*61046927SAndroid Build Coastguard Worker
2689*61046927SAndroid Build Coastguard Worker typedef struct {
2690*61046927SAndroid Build Coastguard Worker nir_instr instr;
2691*61046927SAndroid Build Coastguard Worker nir_jump_type type;
2692*61046927SAndroid Build Coastguard Worker nir_src condition;
2693*61046927SAndroid Build Coastguard Worker struct nir_block *target;
2694*61046927SAndroid Build Coastguard Worker struct nir_block *else_target;
2695*61046927SAndroid Build Coastguard Worker } nir_jump_instr;
2696*61046927SAndroid Build Coastguard Worker
2697*61046927SAndroid Build Coastguard Worker /* creates a new SSA variable in an undefined state */
2698*61046927SAndroid Build Coastguard Worker
2699*61046927SAndroid Build Coastguard Worker typedef struct {
2700*61046927SAndroid Build Coastguard Worker nir_instr instr;
2701*61046927SAndroid Build Coastguard Worker nir_def def;
2702*61046927SAndroid Build Coastguard Worker } nir_undef_instr;
2703*61046927SAndroid Build Coastguard Worker
2704*61046927SAndroid Build Coastguard Worker typedef struct {
2705*61046927SAndroid Build Coastguard Worker struct exec_node node;
2706*61046927SAndroid Build Coastguard Worker
2707*61046927SAndroid Build Coastguard Worker /* The predecessor block corresponding to this source */
2708*61046927SAndroid Build Coastguard Worker struct nir_block *pred;
2709*61046927SAndroid Build Coastguard Worker
2710*61046927SAndroid Build Coastguard Worker nir_src src;
2711*61046927SAndroid Build Coastguard Worker } nir_phi_src;
2712*61046927SAndroid Build Coastguard Worker
2713*61046927SAndroid Build Coastguard Worker #define nir_foreach_phi_src(phi_src, phi) \
2714*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_phi_src, phi_src, node, &(phi)->srcs)
2715*61046927SAndroid Build Coastguard Worker #define nir_foreach_phi_src_safe(phi_src, phi) \
2716*61046927SAndroid Build Coastguard Worker foreach_list_typed_safe(nir_phi_src, phi_src, node, &(phi)->srcs)
2717*61046927SAndroid Build Coastguard Worker
2718*61046927SAndroid Build Coastguard Worker typedef struct {
2719*61046927SAndroid Build Coastguard Worker nir_instr instr;
2720*61046927SAndroid Build Coastguard Worker
2721*61046927SAndroid Build Coastguard Worker /** list of nir_phi_src */
2722*61046927SAndroid Build Coastguard Worker struct exec_list srcs;
2723*61046927SAndroid Build Coastguard Worker
2724*61046927SAndroid Build Coastguard Worker nir_def def;
2725*61046927SAndroid Build Coastguard Worker } nir_phi_instr;
2726*61046927SAndroid Build Coastguard Worker
2727*61046927SAndroid Build Coastguard Worker static inline nir_phi_src *
nir_phi_get_src_from_block(nir_phi_instr * phi,struct nir_block * block)2728*61046927SAndroid Build Coastguard Worker nir_phi_get_src_from_block(nir_phi_instr *phi, struct nir_block *block)
2729*61046927SAndroid Build Coastguard Worker {
2730*61046927SAndroid Build Coastguard Worker nir_foreach_phi_src(src, phi) {
2731*61046927SAndroid Build Coastguard Worker if (src->pred == block)
2732*61046927SAndroid Build Coastguard Worker return src;
2733*61046927SAndroid Build Coastguard Worker }
2734*61046927SAndroid Build Coastguard Worker
2735*61046927SAndroid Build Coastguard Worker assert(!"Block is not a predecessor of phi.");
2736*61046927SAndroid Build Coastguard Worker return NULL;
2737*61046927SAndroid Build Coastguard Worker }
2738*61046927SAndroid Build Coastguard Worker
2739*61046927SAndroid Build Coastguard Worker typedef struct {
2740*61046927SAndroid Build Coastguard Worker struct exec_node node;
2741*61046927SAndroid Build Coastguard Worker bool src_is_reg;
2742*61046927SAndroid Build Coastguard Worker bool dest_is_reg;
2743*61046927SAndroid Build Coastguard Worker nir_src src;
2744*61046927SAndroid Build Coastguard Worker union {
2745*61046927SAndroid Build Coastguard Worker nir_def def;
2746*61046927SAndroid Build Coastguard Worker nir_src reg;
2747*61046927SAndroid Build Coastguard Worker } dest;
2748*61046927SAndroid Build Coastguard Worker } nir_parallel_copy_entry;
2749*61046927SAndroid Build Coastguard Worker
2750*61046927SAndroid Build Coastguard Worker #define nir_foreach_parallel_copy_entry(entry, pcopy) \
2751*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_parallel_copy_entry, entry, node, &(pcopy)->entries)
2752*61046927SAndroid Build Coastguard Worker
2753*61046927SAndroid Build Coastguard Worker typedef struct {
2754*61046927SAndroid Build Coastguard Worker nir_instr instr;
2755*61046927SAndroid Build Coastguard Worker
2756*61046927SAndroid Build Coastguard Worker /* A list of nir_parallel_copy_entrys. The sources of all of the
2757*61046927SAndroid Build Coastguard Worker * entries are copied to the corresponding destinations "in parallel".
2758*61046927SAndroid Build Coastguard Worker * In other words, if we have two entries: a -> b and b -> a, the values
2759*61046927SAndroid Build Coastguard Worker * get swapped.
2760*61046927SAndroid Build Coastguard Worker */
2761*61046927SAndroid Build Coastguard Worker struct exec_list entries;
2762*61046927SAndroid Build Coastguard Worker } nir_parallel_copy_instr;
2763*61046927SAndroid Build Coastguard Worker
2764*61046927SAndroid Build Coastguard Worker typedef enum nir_debug_info_type {
2765*61046927SAndroid Build Coastguard Worker nir_debug_info_src_loc,
2766*61046927SAndroid Build Coastguard Worker nir_debug_info_string,
2767*61046927SAndroid Build Coastguard Worker } nir_debug_info_type;
2768*61046927SAndroid Build Coastguard Worker
2769*61046927SAndroid Build Coastguard Worker typedef enum nir_debug_info_source {
2770*61046927SAndroid Build Coastguard Worker nir_debug_info_spirv,
2771*61046927SAndroid Build Coastguard Worker nir_debug_info_nir,
2772*61046927SAndroid Build Coastguard Worker } nir_debug_info_source;
2773*61046927SAndroid Build Coastguard Worker
2774*61046927SAndroid Build Coastguard Worker typedef struct nir_debug_info_instr {
2775*61046927SAndroid Build Coastguard Worker nir_instr instr;
2776*61046927SAndroid Build Coastguard Worker
2777*61046927SAndroid Build Coastguard Worker nir_debug_info_type type;
2778*61046927SAndroid Build Coastguard Worker
2779*61046927SAndroid Build Coastguard Worker union {
2780*61046927SAndroid Build Coastguard Worker struct {
2781*61046927SAndroid Build Coastguard Worker nir_src filename;
2782*61046927SAndroid Build Coastguard Worker /* 0 if only the spirv_offset is available. */
2783*61046927SAndroid Build Coastguard Worker uint32_t line;
2784*61046927SAndroid Build Coastguard Worker uint32_t column;
2785*61046927SAndroid Build Coastguard Worker
2786*61046927SAndroid Build Coastguard Worker uint32_t spirv_offset;
2787*61046927SAndroid Build Coastguard Worker
2788*61046927SAndroid Build Coastguard Worker nir_debug_info_source source;
2789*61046927SAndroid Build Coastguard Worker } src_loc;
2790*61046927SAndroid Build Coastguard Worker
2791*61046927SAndroid Build Coastguard Worker uint16_t string_length;
2792*61046927SAndroid Build Coastguard Worker };
2793*61046927SAndroid Build Coastguard Worker
2794*61046927SAndroid Build Coastguard Worker nir_def def;
2795*61046927SAndroid Build Coastguard Worker
2796*61046927SAndroid Build Coastguard Worker char string[];
2797*61046927SAndroid Build Coastguard Worker } nir_debug_info_instr;
2798*61046927SAndroid Build Coastguard Worker
2799*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_alu, nir_instr, nir_alu_instr, instr,
2800*61046927SAndroid Build Coastguard Worker type, nir_instr_type_alu)
2801*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_deref, nir_instr, nir_deref_instr, instr,
2802*61046927SAndroid Build Coastguard Worker type, nir_instr_type_deref)
2803*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_call, nir_instr, nir_call_instr, instr,
2804*61046927SAndroid Build Coastguard Worker type, nir_instr_type_call)
2805*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_jump, nir_instr, nir_jump_instr, instr,
2806*61046927SAndroid Build Coastguard Worker type, nir_instr_type_jump)
2807*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_tex, nir_instr, nir_tex_instr, instr,
2808*61046927SAndroid Build Coastguard Worker type, nir_instr_type_tex)
2809*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_intrinsic, nir_instr, nir_intrinsic_instr, instr,
2810*61046927SAndroid Build Coastguard Worker type, nir_instr_type_intrinsic)
2811*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_load_const, nir_instr, nir_load_const_instr, instr,
2812*61046927SAndroid Build Coastguard Worker type, nir_instr_type_load_const)
2813*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_undef, nir_instr, nir_undef_instr, instr,
2814*61046927SAndroid Build Coastguard Worker type, nir_instr_type_undef)
2815*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_phi, nir_instr, nir_phi_instr, instr,
2816*61046927SAndroid Build Coastguard Worker type, nir_instr_type_phi)
2817*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_parallel_copy, nir_instr,
2818*61046927SAndroid Build Coastguard Worker nir_parallel_copy_instr, instr,
2819*61046927SAndroid Build Coastguard Worker type, nir_instr_type_parallel_copy)
2820*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_instr_as_debug_info, nir_instr,
2821*61046927SAndroid Build Coastguard Worker nir_debug_info_instr, instr,
2822*61046927SAndroid Build Coastguard Worker type, nir_instr_type_debug_info)
2823*61046927SAndroid Build Coastguard Worker
2824*61046927SAndroid Build Coastguard Worker #define NIR_DEFINE_SRC_AS_CONST(type, suffix) \
2825*61046927SAndroid Build Coastguard Worker static inline type \
2826*61046927SAndroid Build Coastguard Worker nir_src_comp_as_##suffix(nir_src src, unsigned comp) \
2827*61046927SAndroid Build Coastguard Worker { \
2828*61046927SAndroid Build Coastguard Worker assert(nir_src_is_const(src)); \
2829*61046927SAndroid Build Coastguard Worker nir_load_const_instr *load = \
2830*61046927SAndroid Build Coastguard Worker nir_instr_as_load_const(src.ssa->parent_instr); \
2831*61046927SAndroid Build Coastguard Worker assert(comp < load->def.num_components); \
2832*61046927SAndroid Build Coastguard Worker return nir_const_value_as_##suffix(load->value[comp], \
2833*61046927SAndroid Build Coastguard Worker load->def.bit_size); \
2834*61046927SAndroid Build Coastguard Worker } \
2835*61046927SAndroid Build Coastguard Worker \
2836*61046927SAndroid Build Coastguard Worker static inline type \
2837*61046927SAndroid Build Coastguard Worker nir_src_as_##suffix(nir_src src) \
2838*61046927SAndroid Build Coastguard Worker { \
2839*61046927SAndroid Build Coastguard Worker assert(nir_src_num_components(src) == 1); \
2840*61046927SAndroid Build Coastguard Worker return nir_src_comp_as_##suffix(src, 0); \
2841*61046927SAndroid Build Coastguard Worker }
2842*61046927SAndroid Build Coastguard Worker
2843*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SRC_AS_CONST(int64_t, int)
2844*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SRC_AS_CONST(uint64_t, uint)
2845*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SRC_AS_CONST(bool, bool)
2846*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SRC_AS_CONST(double, float)
2847*61046927SAndroid Build Coastguard Worker
2848*61046927SAndroid Build Coastguard Worker #undef NIR_DEFINE_SRC_AS_CONST
2849*61046927SAndroid Build Coastguard Worker
2850*61046927SAndroid Build Coastguard Worker typedef struct {
2851*61046927SAndroid Build Coastguard Worker nir_def *def;
2852*61046927SAndroid Build Coastguard Worker unsigned comp;
2853*61046927SAndroid Build Coastguard Worker } nir_scalar;
2854*61046927SAndroid Build Coastguard Worker
2855*61046927SAndroid Build Coastguard Worker static inline bool
nir_scalar_is_const(nir_scalar s)2856*61046927SAndroid Build Coastguard Worker nir_scalar_is_const(nir_scalar s)
2857*61046927SAndroid Build Coastguard Worker {
2858*61046927SAndroid Build Coastguard Worker return s.def->parent_instr->type == nir_instr_type_load_const;
2859*61046927SAndroid Build Coastguard Worker }
2860*61046927SAndroid Build Coastguard Worker
2861*61046927SAndroid Build Coastguard Worker static inline bool
nir_scalar_is_undef(nir_scalar s)2862*61046927SAndroid Build Coastguard Worker nir_scalar_is_undef(nir_scalar s)
2863*61046927SAndroid Build Coastguard Worker {
2864*61046927SAndroid Build Coastguard Worker return s.def->parent_instr->type == nir_instr_type_undef;
2865*61046927SAndroid Build Coastguard Worker }
2866*61046927SAndroid Build Coastguard Worker
2867*61046927SAndroid Build Coastguard Worker static inline nir_const_value
nir_scalar_as_const_value(nir_scalar s)2868*61046927SAndroid Build Coastguard Worker nir_scalar_as_const_value(nir_scalar s)
2869*61046927SAndroid Build Coastguard Worker {
2870*61046927SAndroid Build Coastguard Worker assert(s.comp < s.def->num_components);
2871*61046927SAndroid Build Coastguard Worker nir_load_const_instr *load = nir_instr_as_load_const(s.def->parent_instr);
2872*61046927SAndroid Build Coastguard Worker return load->value[s.comp];
2873*61046927SAndroid Build Coastguard Worker }
2874*61046927SAndroid Build Coastguard Worker
2875*61046927SAndroid Build Coastguard Worker #define NIR_DEFINE_SCALAR_AS_CONST(type, suffix) \
2876*61046927SAndroid Build Coastguard Worker static inline type \
2877*61046927SAndroid Build Coastguard Worker nir_scalar_as_##suffix(nir_scalar s) \
2878*61046927SAndroid Build Coastguard Worker { \
2879*61046927SAndroid Build Coastguard Worker return nir_const_value_as_##suffix( \
2880*61046927SAndroid Build Coastguard Worker nir_scalar_as_const_value(s), s.def->bit_size); \
2881*61046927SAndroid Build Coastguard Worker }
2882*61046927SAndroid Build Coastguard Worker
NIR_DEFINE_SCALAR_AS_CONST(int64_t,int)2883*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SCALAR_AS_CONST(int64_t, int)
2884*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SCALAR_AS_CONST(uint64_t, uint)
2885*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SCALAR_AS_CONST(bool, bool)
2886*61046927SAndroid Build Coastguard Worker NIR_DEFINE_SCALAR_AS_CONST(double, float)
2887*61046927SAndroid Build Coastguard Worker
2888*61046927SAndroid Build Coastguard Worker #undef NIR_DEFINE_SCALAR_AS_CONST
2889*61046927SAndroid Build Coastguard Worker
2890*61046927SAndroid Build Coastguard Worker static inline bool
2891*61046927SAndroid Build Coastguard Worker nir_scalar_is_alu(nir_scalar s)
2892*61046927SAndroid Build Coastguard Worker {
2893*61046927SAndroid Build Coastguard Worker return s.def->parent_instr->type == nir_instr_type_alu;
2894*61046927SAndroid Build Coastguard Worker }
2895*61046927SAndroid Build Coastguard Worker
2896*61046927SAndroid Build Coastguard Worker static inline nir_op
nir_scalar_alu_op(nir_scalar s)2897*61046927SAndroid Build Coastguard Worker nir_scalar_alu_op(nir_scalar s)
2898*61046927SAndroid Build Coastguard Worker {
2899*61046927SAndroid Build Coastguard Worker return nir_instr_as_alu(s.def->parent_instr)->op;
2900*61046927SAndroid Build Coastguard Worker }
2901*61046927SAndroid Build Coastguard Worker
2902*61046927SAndroid Build Coastguard Worker static inline bool
nir_scalar_is_intrinsic(nir_scalar s)2903*61046927SAndroid Build Coastguard Worker nir_scalar_is_intrinsic(nir_scalar s)
2904*61046927SAndroid Build Coastguard Worker {
2905*61046927SAndroid Build Coastguard Worker return s.def->parent_instr->type == nir_instr_type_intrinsic;
2906*61046927SAndroid Build Coastguard Worker }
2907*61046927SAndroid Build Coastguard Worker
2908*61046927SAndroid Build Coastguard Worker static inline nir_intrinsic_op
nir_scalar_intrinsic_op(nir_scalar s)2909*61046927SAndroid Build Coastguard Worker nir_scalar_intrinsic_op(nir_scalar s)
2910*61046927SAndroid Build Coastguard Worker {
2911*61046927SAndroid Build Coastguard Worker return nir_instr_as_intrinsic(s.def->parent_instr)->intrinsic;
2912*61046927SAndroid Build Coastguard Worker }
2913*61046927SAndroid Build Coastguard Worker
2914*61046927SAndroid Build Coastguard Worker static inline nir_scalar
nir_scalar_chase_alu_src(nir_scalar s,unsigned alu_src_idx)2915*61046927SAndroid Build Coastguard Worker nir_scalar_chase_alu_src(nir_scalar s, unsigned alu_src_idx)
2916*61046927SAndroid Build Coastguard Worker {
2917*61046927SAndroid Build Coastguard Worker nir_scalar out = { NULL, 0 };
2918*61046927SAndroid Build Coastguard Worker
2919*61046927SAndroid Build Coastguard Worker nir_alu_instr *alu = nir_instr_as_alu(s.def->parent_instr);
2920*61046927SAndroid Build Coastguard Worker assert(alu_src_idx < nir_op_infos[alu->op].num_inputs);
2921*61046927SAndroid Build Coastguard Worker
2922*61046927SAndroid Build Coastguard Worker /* Our component must be written */
2923*61046927SAndroid Build Coastguard Worker assert(s.comp < s.def->num_components);
2924*61046927SAndroid Build Coastguard Worker
2925*61046927SAndroid Build Coastguard Worker out.def = alu->src[alu_src_idx].src.ssa;
2926*61046927SAndroid Build Coastguard Worker
2927*61046927SAndroid Build Coastguard Worker if (nir_op_infos[alu->op].input_sizes[alu_src_idx] == 0) {
2928*61046927SAndroid Build Coastguard Worker /* The ALU src is unsized so the source component follows the
2929*61046927SAndroid Build Coastguard Worker * destination component.
2930*61046927SAndroid Build Coastguard Worker */
2931*61046927SAndroid Build Coastguard Worker out.comp = alu->src[alu_src_idx].swizzle[s.comp];
2932*61046927SAndroid Build Coastguard Worker } else {
2933*61046927SAndroid Build Coastguard Worker /* This is a sized source so all source components work together to
2934*61046927SAndroid Build Coastguard Worker * produce all the destination components. Since we need to return a
2935*61046927SAndroid Build Coastguard Worker * scalar, this only works if the source is a scalar.
2936*61046927SAndroid Build Coastguard Worker */
2937*61046927SAndroid Build Coastguard Worker assert(nir_op_infos[alu->op].input_sizes[alu_src_idx] == 1);
2938*61046927SAndroid Build Coastguard Worker out.comp = alu->src[alu_src_idx].swizzle[0];
2939*61046927SAndroid Build Coastguard Worker }
2940*61046927SAndroid Build Coastguard Worker assert(out.comp < out.def->num_components);
2941*61046927SAndroid Build Coastguard Worker
2942*61046927SAndroid Build Coastguard Worker return out;
2943*61046927SAndroid Build Coastguard Worker }
2944*61046927SAndroid Build Coastguard Worker
2945*61046927SAndroid Build Coastguard Worker nir_scalar nir_scalar_chase_movs(nir_scalar s);
2946*61046927SAndroid Build Coastguard Worker
2947*61046927SAndroid Build Coastguard Worker static inline nir_scalar
nir_get_scalar(nir_def * def,unsigned channel)2948*61046927SAndroid Build Coastguard Worker nir_get_scalar(nir_def *def, unsigned channel)
2949*61046927SAndroid Build Coastguard Worker {
2950*61046927SAndroid Build Coastguard Worker nir_scalar s = { def, channel };
2951*61046927SAndroid Build Coastguard Worker return s;
2952*61046927SAndroid Build Coastguard Worker }
2953*61046927SAndroid Build Coastguard Worker
2954*61046927SAndroid Build Coastguard Worker /** Returns a nir_scalar where we've followed the bit-exact mov/vec use chain to the original definition */
2955*61046927SAndroid Build Coastguard Worker static inline nir_scalar
nir_scalar_resolved(nir_def * def,unsigned channel)2956*61046927SAndroid Build Coastguard Worker nir_scalar_resolved(nir_def *def, unsigned channel)
2957*61046927SAndroid Build Coastguard Worker {
2958*61046927SAndroid Build Coastguard Worker return nir_scalar_chase_movs(nir_get_scalar(def, channel));
2959*61046927SAndroid Build Coastguard Worker }
2960*61046927SAndroid Build Coastguard Worker
2961*61046927SAndroid Build Coastguard Worker static inline bool
nir_scalar_equal(nir_scalar s1,nir_scalar s2)2962*61046927SAndroid Build Coastguard Worker nir_scalar_equal(nir_scalar s1, nir_scalar s2)
2963*61046927SAndroid Build Coastguard Worker {
2964*61046927SAndroid Build Coastguard Worker return s1.def == s2.def && s1.comp == s2.comp;
2965*61046927SAndroid Build Coastguard Worker }
2966*61046927SAndroid Build Coastguard Worker
2967*61046927SAndroid Build Coastguard Worker static inline uint64_t
nir_alu_src_as_uint(nir_alu_src src)2968*61046927SAndroid Build Coastguard Worker nir_alu_src_as_uint(nir_alu_src src)
2969*61046927SAndroid Build Coastguard Worker {
2970*61046927SAndroid Build Coastguard Worker nir_scalar scalar = nir_get_scalar(src.src.ssa, src.swizzle[0]);
2971*61046927SAndroid Build Coastguard Worker return nir_scalar_as_uint(scalar);
2972*61046927SAndroid Build Coastguard Worker }
2973*61046927SAndroid Build Coastguard Worker
2974*61046927SAndroid Build Coastguard Worker typedef struct {
2975*61046927SAndroid Build Coastguard Worker bool success;
2976*61046927SAndroid Build Coastguard Worker
2977*61046927SAndroid Build Coastguard Worker nir_variable *var;
2978*61046927SAndroid Build Coastguard Worker unsigned desc_set;
2979*61046927SAndroid Build Coastguard Worker unsigned binding;
2980*61046927SAndroid Build Coastguard Worker unsigned num_indices;
2981*61046927SAndroid Build Coastguard Worker nir_src indices[4];
2982*61046927SAndroid Build Coastguard Worker bool read_first_invocation;
2983*61046927SAndroid Build Coastguard Worker } nir_binding;
2984*61046927SAndroid Build Coastguard Worker
2985*61046927SAndroid Build Coastguard Worker nir_binding nir_chase_binding(nir_src rsrc);
2986*61046927SAndroid Build Coastguard Worker nir_variable *nir_get_binding_variable(struct nir_shader *shader, nir_binding binding);
2987*61046927SAndroid Build Coastguard Worker
2988*61046927SAndroid Build Coastguard Worker /*
2989*61046927SAndroid Build Coastguard Worker * Control flow
2990*61046927SAndroid Build Coastguard Worker *
2991*61046927SAndroid Build Coastguard Worker * Control flow consists of a tree of control flow nodes, which include
2992*61046927SAndroid Build Coastguard Worker * if-statements and loops. The leaves of the tree are basic blocks, lists of
2993*61046927SAndroid Build Coastguard Worker * instructions that always run start-to-finish. Each basic block also keeps
2994*61046927SAndroid Build Coastguard Worker * track of its successors (blocks which may run immediately after the current
2995*61046927SAndroid Build Coastguard Worker * block) and predecessors (blocks which could have run immediately before the
2996*61046927SAndroid Build Coastguard Worker * current block). Each function also has a start block and an end block which
2997*61046927SAndroid Build Coastguard Worker * all return statements point to (which is always empty). Together, all the
2998*61046927SAndroid Build Coastguard Worker * blocks with their predecessors and successors make up the control flow
2999*61046927SAndroid Build Coastguard Worker * graph (CFG) of the function. There are helpers that modify the tree of
3000*61046927SAndroid Build Coastguard Worker * control flow nodes while modifying the CFG appropriately; these should be
3001*61046927SAndroid Build Coastguard Worker * used instead of modifying the tree directly.
3002*61046927SAndroid Build Coastguard Worker */
3003*61046927SAndroid Build Coastguard Worker
3004*61046927SAndroid Build Coastguard Worker typedef enum {
3005*61046927SAndroid Build Coastguard Worker nir_cf_node_block,
3006*61046927SAndroid Build Coastguard Worker nir_cf_node_if,
3007*61046927SAndroid Build Coastguard Worker nir_cf_node_loop,
3008*61046927SAndroid Build Coastguard Worker nir_cf_node_function
3009*61046927SAndroid Build Coastguard Worker } nir_cf_node_type;
3010*61046927SAndroid Build Coastguard Worker
3011*61046927SAndroid Build Coastguard Worker typedef struct nir_cf_node {
3012*61046927SAndroid Build Coastguard Worker struct exec_node node;
3013*61046927SAndroid Build Coastguard Worker nir_cf_node_type type;
3014*61046927SAndroid Build Coastguard Worker struct nir_cf_node *parent;
3015*61046927SAndroid Build Coastguard Worker } nir_cf_node;
3016*61046927SAndroid Build Coastguard Worker
3017*61046927SAndroid Build Coastguard Worker typedef struct nir_block {
3018*61046927SAndroid Build Coastguard Worker nir_cf_node cf_node;
3019*61046927SAndroid Build Coastguard Worker
3020*61046927SAndroid Build Coastguard Worker /** list of nir_instr */
3021*61046927SAndroid Build Coastguard Worker struct exec_list instr_list;
3022*61046927SAndroid Build Coastguard Worker
3023*61046927SAndroid Build Coastguard Worker /** generic block index; generated by nir_index_blocks */
3024*61046927SAndroid Build Coastguard Worker unsigned index;
3025*61046927SAndroid Build Coastguard Worker
3026*61046927SAndroid Build Coastguard Worker /* This indicates whether the block or any parent block is executed
3027*61046927SAndroid Build Coastguard Worker * conditionally and whether the condition uses a divergent value.
3028*61046927SAndroid Build Coastguard Worker */
3029*61046927SAndroid Build Coastguard Worker bool divergent;
3030*61046927SAndroid Build Coastguard Worker
3031*61046927SAndroid Build Coastguard Worker /*
3032*61046927SAndroid Build Coastguard Worker * Each block can only have up to 2 successors, so we put them in a simple
3033*61046927SAndroid Build Coastguard Worker * array - no need for anything more complicated.
3034*61046927SAndroid Build Coastguard Worker */
3035*61046927SAndroid Build Coastguard Worker struct nir_block *successors[2];
3036*61046927SAndroid Build Coastguard Worker
3037*61046927SAndroid Build Coastguard Worker /* Set of nir_block predecessors in the CFG */
3038*61046927SAndroid Build Coastguard Worker struct set *predecessors;
3039*61046927SAndroid Build Coastguard Worker
3040*61046927SAndroid Build Coastguard Worker /*
3041*61046927SAndroid Build Coastguard Worker * this node's immediate dominator in the dominance tree - set to NULL for
3042*61046927SAndroid Build Coastguard Worker * the start block and any unreachable blocks.
3043*61046927SAndroid Build Coastguard Worker */
3044*61046927SAndroid Build Coastguard Worker struct nir_block *imm_dom;
3045*61046927SAndroid Build Coastguard Worker
3046*61046927SAndroid Build Coastguard Worker /* This node's children in the dominance tree */
3047*61046927SAndroid Build Coastguard Worker unsigned num_dom_children;
3048*61046927SAndroid Build Coastguard Worker struct nir_block **dom_children;
3049*61046927SAndroid Build Coastguard Worker
3050*61046927SAndroid Build Coastguard Worker /* Set of nir_blocks on the dominance frontier of this block */
3051*61046927SAndroid Build Coastguard Worker struct set *dom_frontier;
3052*61046927SAndroid Build Coastguard Worker
3053*61046927SAndroid Build Coastguard Worker /*
3054*61046927SAndroid Build Coastguard Worker * These two indices have the property that dom_{pre,post}_index for each
3055*61046927SAndroid Build Coastguard Worker * child of this block in the dominance tree will always be between
3056*61046927SAndroid Build Coastguard Worker * dom_pre_index and dom_post_index for this block, which makes testing if
3057*61046927SAndroid Build Coastguard Worker * a given block is dominated by another block an O(1) operation.
3058*61046927SAndroid Build Coastguard Worker */
3059*61046927SAndroid Build Coastguard Worker uint32_t dom_pre_index, dom_post_index;
3060*61046927SAndroid Build Coastguard Worker
3061*61046927SAndroid Build Coastguard Worker /**
3062*61046927SAndroid Build Coastguard Worker * Value just before the first nir_instr->index in the block, but after
3063*61046927SAndroid Build Coastguard Worker * end_ip that of any predecessor block.
3064*61046927SAndroid Build Coastguard Worker */
3065*61046927SAndroid Build Coastguard Worker uint32_t start_ip;
3066*61046927SAndroid Build Coastguard Worker /**
3067*61046927SAndroid Build Coastguard Worker * Value just after the last nir_instr->index in the block, but before the
3068*61046927SAndroid Build Coastguard Worker * start_ip of any successor block.
3069*61046927SAndroid Build Coastguard Worker */
3070*61046927SAndroid Build Coastguard Worker uint32_t end_ip;
3071*61046927SAndroid Build Coastguard Worker
3072*61046927SAndroid Build Coastguard Worker /* SSA def live in and out for this block; used for liveness analysis.
3073*61046927SAndroid Build Coastguard Worker * Indexed by ssa_def->index
3074*61046927SAndroid Build Coastguard Worker */
3075*61046927SAndroid Build Coastguard Worker BITSET_WORD *live_in;
3076*61046927SAndroid Build Coastguard Worker BITSET_WORD *live_out;
3077*61046927SAndroid Build Coastguard Worker } nir_block;
3078*61046927SAndroid Build Coastguard Worker
3079*61046927SAndroid Build Coastguard Worker static inline bool
nir_block_is_reachable(nir_block * b)3080*61046927SAndroid Build Coastguard Worker nir_block_is_reachable(nir_block *b)
3081*61046927SAndroid Build Coastguard Worker {
3082*61046927SAndroid Build Coastguard Worker /* See also nir_block_dominates */
3083*61046927SAndroid Build Coastguard Worker return b->dom_post_index != 0;
3084*61046927SAndroid Build Coastguard Worker }
3085*61046927SAndroid Build Coastguard Worker
3086*61046927SAndroid Build Coastguard Worker static inline nir_instr *
nir_block_first_instr(nir_block * block)3087*61046927SAndroid Build Coastguard Worker nir_block_first_instr(nir_block *block)
3088*61046927SAndroid Build Coastguard Worker {
3089*61046927SAndroid Build Coastguard Worker struct exec_node *head = exec_list_get_head(&block->instr_list);
3090*61046927SAndroid Build Coastguard Worker return exec_node_data(nir_instr, head, node);
3091*61046927SAndroid Build Coastguard Worker }
3092*61046927SAndroid Build Coastguard Worker
3093*61046927SAndroid Build Coastguard Worker static inline nir_instr *
nir_block_last_instr(nir_block * block)3094*61046927SAndroid Build Coastguard Worker nir_block_last_instr(nir_block *block)
3095*61046927SAndroid Build Coastguard Worker {
3096*61046927SAndroid Build Coastguard Worker struct exec_node *tail = exec_list_get_tail(&block->instr_list);
3097*61046927SAndroid Build Coastguard Worker return exec_node_data(nir_instr, tail, node);
3098*61046927SAndroid Build Coastguard Worker }
3099*61046927SAndroid Build Coastguard Worker
3100*61046927SAndroid Build Coastguard Worker static inline bool
nir_block_ends_in_jump(nir_block * block)3101*61046927SAndroid Build Coastguard Worker nir_block_ends_in_jump(nir_block *block)
3102*61046927SAndroid Build Coastguard Worker {
3103*61046927SAndroid Build Coastguard Worker return !exec_list_is_empty(&block->instr_list) &&
3104*61046927SAndroid Build Coastguard Worker nir_block_last_instr(block)->type == nir_instr_type_jump;
3105*61046927SAndroid Build Coastguard Worker }
3106*61046927SAndroid Build Coastguard Worker
3107*61046927SAndroid Build Coastguard Worker static inline bool
nir_block_ends_in_return_or_halt(nir_block * block)3108*61046927SAndroid Build Coastguard Worker nir_block_ends_in_return_or_halt(nir_block *block)
3109*61046927SAndroid Build Coastguard Worker {
3110*61046927SAndroid Build Coastguard Worker if (exec_list_is_empty(&block->instr_list))
3111*61046927SAndroid Build Coastguard Worker return false;
3112*61046927SAndroid Build Coastguard Worker
3113*61046927SAndroid Build Coastguard Worker nir_instr *instr = nir_block_last_instr(block);
3114*61046927SAndroid Build Coastguard Worker if (instr->type != nir_instr_type_jump)
3115*61046927SAndroid Build Coastguard Worker return false;
3116*61046927SAndroid Build Coastguard Worker
3117*61046927SAndroid Build Coastguard Worker nir_jump_instr *jump_instr = nir_instr_as_jump(instr);
3118*61046927SAndroid Build Coastguard Worker return jump_instr->type == nir_jump_return ||
3119*61046927SAndroid Build Coastguard Worker jump_instr->type == nir_jump_halt;
3120*61046927SAndroid Build Coastguard Worker }
3121*61046927SAndroid Build Coastguard Worker
3122*61046927SAndroid Build Coastguard Worker static inline bool
nir_block_ends_in_break(nir_block * block)3123*61046927SAndroid Build Coastguard Worker nir_block_ends_in_break(nir_block *block)
3124*61046927SAndroid Build Coastguard Worker {
3125*61046927SAndroid Build Coastguard Worker if (exec_list_is_empty(&block->instr_list))
3126*61046927SAndroid Build Coastguard Worker return false;
3127*61046927SAndroid Build Coastguard Worker
3128*61046927SAndroid Build Coastguard Worker nir_instr *instr = nir_block_last_instr(block);
3129*61046927SAndroid Build Coastguard Worker return instr->type == nir_instr_type_jump &&
3130*61046927SAndroid Build Coastguard Worker nir_instr_as_jump(instr)->type == nir_jump_break;
3131*61046927SAndroid Build Coastguard Worker }
3132*61046927SAndroid Build Coastguard Worker
3133*61046927SAndroid Build Coastguard Worker bool nir_block_contains_work(nir_block *block);
3134*61046927SAndroid Build Coastguard Worker
3135*61046927SAndroid Build Coastguard Worker #define nir_foreach_instr(instr, block) \
3136*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_instr, instr, node, &(block)->instr_list)
3137*61046927SAndroid Build Coastguard Worker #define nir_foreach_instr_reverse(instr, block) \
3138*61046927SAndroid Build Coastguard Worker foreach_list_typed_reverse(nir_instr, instr, node, &(block)->instr_list)
3139*61046927SAndroid Build Coastguard Worker #define nir_foreach_instr_safe(instr, block) \
3140*61046927SAndroid Build Coastguard Worker foreach_list_typed_safe(nir_instr, instr, node, &(block)->instr_list)
3141*61046927SAndroid Build Coastguard Worker #define nir_foreach_instr_reverse_safe(instr, block) \
3142*61046927SAndroid Build Coastguard Worker foreach_list_typed_reverse_safe(nir_instr, instr, node, &(block)->instr_list)
3143*61046927SAndroid Build Coastguard Worker
3144*61046927SAndroid Build Coastguard Worker /* Phis come first in the block */
3145*61046927SAndroid Build Coastguard Worker static inline nir_phi_instr *
nir_first_phi_in_block(nir_block * block)3146*61046927SAndroid Build Coastguard Worker nir_first_phi_in_block(nir_block *block)
3147*61046927SAndroid Build Coastguard Worker {
3148*61046927SAndroid Build Coastguard Worker nir_foreach_instr(instr, block) {
3149*61046927SAndroid Build Coastguard Worker if (instr->type == nir_instr_type_phi)
3150*61046927SAndroid Build Coastguard Worker return nir_instr_as_phi(instr);
3151*61046927SAndroid Build Coastguard Worker else
3152*61046927SAndroid Build Coastguard Worker return NULL;
3153*61046927SAndroid Build Coastguard Worker }
3154*61046927SAndroid Build Coastguard Worker
3155*61046927SAndroid Build Coastguard Worker return NULL;
3156*61046927SAndroid Build Coastguard Worker }
3157*61046927SAndroid Build Coastguard Worker
3158*61046927SAndroid Build Coastguard Worker static inline nir_phi_instr *
nir_next_phi(nir_phi_instr * phi)3159*61046927SAndroid Build Coastguard Worker nir_next_phi(nir_phi_instr *phi)
3160*61046927SAndroid Build Coastguard Worker {
3161*61046927SAndroid Build Coastguard Worker nir_instr *next = nir_instr_next(&phi->instr);
3162*61046927SAndroid Build Coastguard Worker
3163*61046927SAndroid Build Coastguard Worker if (next && next->type == nir_instr_type_phi)
3164*61046927SAndroid Build Coastguard Worker return nir_instr_as_phi(next);
3165*61046927SAndroid Build Coastguard Worker else
3166*61046927SAndroid Build Coastguard Worker return NULL;
3167*61046927SAndroid Build Coastguard Worker }
3168*61046927SAndroid Build Coastguard Worker
3169*61046927SAndroid Build Coastguard Worker #define nir_foreach_phi(instr, block) \
3170*61046927SAndroid Build Coastguard Worker for (nir_phi_instr *instr = nir_first_phi_in_block(block); instr != NULL; \
3171*61046927SAndroid Build Coastguard Worker instr = nir_next_phi(instr))
3172*61046927SAndroid Build Coastguard Worker
3173*61046927SAndroid Build Coastguard Worker #define nir_foreach_phi_safe(instr, block) \
3174*61046927SAndroid Build Coastguard Worker for (nir_phi_instr *instr = nir_first_phi_in_block(block), \
3175*61046927SAndroid Build Coastguard Worker *__next = instr ? nir_next_phi(instr) : NULL; \
3176*61046927SAndroid Build Coastguard Worker instr != NULL; \
3177*61046927SAndroid Build Coastguard Worker instr = __next, __next = instr ? nir_next_phi(instr) : NULL)
3178*61046927SAndroid Build Coastguard Worker
3179*61046927SAndroid Build Coastguard Worker static inline nir_phi_instr *
nir_block_last_phi_instr(nir_block * block)3180*61046927SAndroid Build Coastguard Worker nir_block_last_phi_instr(nir_block *block)
3181*61046927SAndroid Build Coastguard Worker {
3182*61046927SAndroid Build Coastguard Worker nir_phi_instr *last_phi = NULL;
3183*61046927SAndroid Build Coastguard Worker nir_foreach_phi(instr, block)
3184*61046927SAndroid Build Coastguard Worker last_phi = instr;
3185*61046927SAndroid Build Coastguard Worker
3186*61046927SAndroid Build Coastguard Worker return last_phi;
3187*61046927SAndroid Build Coastguard Worker }
3188*61046927SAndroid Build Coastguard Worker
3189*61046927SAndroid Build Coastguard Worker typedef enum {
3190*61046927SAndroid Build Coastguard Worker nir_selection_control_none = 0x0,
3191*61046927SAndroid Build Coastguard Worker
3192*61046927SAndroid Build Coastguard Worker /**
3193*61046927SAndroid Build Coastguard Worker * Defined by SPIR-V spec 3.22 "Selection Control".
3194*61046927SAndroid Build Coastguard Worker * The application prefers to remove control flow.
3195*61046927SAndroid Build Coastguard Worker */
3196*61046927SAndroid Build Coastguard Worker nir_selection_control_flatten = 0x1,
3197*61046927SAndroid Build Coastguard Worker
3198*61046927SAndroid Build Coastguard Worker /**
3199*61046927SAndroid Build Coastguard Worker * Defined by SPIR-V spec 3.22 "Selection Control".
3200*61046927SAndroid Build Coastguard Worker * The application prefers to keep control flow.
3201*61046927SAndroid Build Coastguard Worker */
3202*61046927SAndroid Build Coastguard Worker nir_selection_control_dont_flatten = 0x2,
3203*61046927SAndroid Build Coastguard Worker
3204*61046927SAndroid Build Coastguard Worker /**
3205*61046927SAndroid Build Coastguard Worker * May be applied by the compiler stack when it knows
3206*61046927SAndroid Build Coastguard Worker * that a branch is divergent, and:
3207*61046927SAndroid Build Coastguard Worker * - either both the if and else are always taken
3208*61046927SAndroid Build Coastguard Worker * - the if or else is empty and the other is always taken
3209*61046927SAndroid Build Coastguard Worker */
3210*61046927SAndroid Build Coastguard Worker nir_selection_control_divergent_always_taken = 0x3,
3211*61046927SAndroid Build Coastguard Worker } nir_selection_control;
3212*61046927SAndroid Build Coastguard Worker
3213*61046927SAndroid Build Coastguard Worker typedef struct nir_if {
3214*61046927SAndroid Build Coastguard Worker nir_cf_node cf_node;
3215*61046927SAndroid Build Coastguard Worker nir_src condition;
3216*61046927SAndroid Build Coastguard Worker nir_selection_control control;
3217*61046927SAndroid Build Coastguard Worker
3218*61046927SAndroid Build Coastguard Worker /** list of nir_cf_node */
3219*61046927SAndroid Build Coastguard Worker struct exec_list then_list;
3220*61046927SAndroid Build Coastguard Worker
3221*61046927SAndroid Build Coastguard Worker /** list of nir_cf_node */
3222*61046927SAndroid Build Coastguard Worker struct exec_list else_list;
3223*61046927SAndroid Build Coastguard Worker } nir_if;
3224*61046927SAndroid Build Coastguard Worker
3225*61046927SAndroid Build Coastguard Worker typedef struct {
3226*61046927SAndroid Build Coastguard Worker nir_if *nif;
3227*61046927SAndroid Build Coastguard Worker
3228*61046927SAndroid Build Coastguard Worker /** Condition instruction that contains the induction variable */
3229*61046927SAndroid Build Coastguard Worker nir_instr *conditional_instr;
3230*61046927SAndroid Build Coastguard Worker
3231*61046927SAndroid Build Coastguard Worker /** Block within ::nif that has the break instruction. */
3232*61046927SAndroid Build Coastguard Worker nir_block *break_block;
3233*61046927SAndroid Build Coastguard Worker
3234*61046927SAndroid Build Coastguard Worker /** Last block for the then- or else-path that does not contain the break. */
3235*61046927SAndroid Build Coastguard Worker nir_block *continue_from_block;
3236*61046927SAndroid Build Coastguard Worker
3237*61046927SAndroid Build Coastguard Worker /** True when ::break_block is in the else-path of ::nif. */
3238*61046927SAndroid Build Coastguard Worker bool continue_from_then;
3239*61046927SAndroid Build Coastguard Worker bool induction_rhs;
3240*61046927SAndroid Build Coastguard Worker
3241*61046927SAndroid Build Coastguard Worker /* This is true if the terminators exact trip count is unknown. For
3242*61046927SAndroid Build Coastguard Worker * example:
3243*61046927SAndroid Build Coastguard Worker *
3244*61046927SAndroid Build Coastguard Worker * for (int i = 0; i < imin(x, 4); i++)
3245*61046927SAndroid Build Coastguard Worker * ...
3246*61046927SAndroid Build Coastguard Worker *
3247*61046927SAndroid Build Coastguard Worker * Here loop analysis would have set a max_trip_count of 4 however we dont
3248*61046927SAndroid Build Coastguard Worker * know for sure that this is the exact trip count.
3249*61046927SAndroid Build Coastguard Worker */
3250*61046927SAndroid Build Coastguard Worker bool exact_trip_count_unknown;
3251*61046927SAndroid Build Coastguard Worker
3252*61046927SAndroid Build Coastguard Worker struct list_head loop_terminator_link;
3253*61046927SAndroid Build Coastguard Worker } nir_loop_terminator;
3254*61046927SAndroid Build Coastguard Worker
3255*61046927SAndroid Build Coastguard Worker typedef struct {
3256*61046927SAndroid Build Coastguard Worker /* Induction variable. */
3257*61046927SAndroid Build Coastguard Worker nir_def *def;
3258*61046927SAndroid Build Coastguard Worker
3259*61046927SAndroid Build Coastguard Worker /* Init statement with only uniform. */
3260*61046927SAndroid Build Coastguard Worker nir_src *init_src;
3261*61046927SAndroid Build Coastguard Worker
3262*61046927SAndroid Build Coastguard Worker /* Update statement with only uniform. */
3263*61046927SAndroid Build Coastguard Worker nir_alu_src *update_src;
3264*61046927SAndroid Build Coastguard Worker } nir_loop_induction_variable;
3265*61046927SAndroid Build Coastguard Worker
3266*61046927SAndroid Build Coastguard Worker typedef struct {
3267*61046927SAndroid Build Coastguard Worker /* Estimated cost (in number of instructions) of the loop */
3268*61046927SAndroid Build Coastguard Worker unsigned instr_cost;
3269*61046927SAndroid Build Coastguard Worker
3270*61046927SAndroid Build Coastguard Worker /* Contains fp64 ops that will be lowered */
3271*61046927SAndroid Build Coastguard Worker bool has_soft_fp64;
3272*61046927SAndroid Build Coastguard Worker
3273*61046927SAndroid Build Coastguard Worker /* Guessed trip count based on array indexing */
3274*61046927SAndroid Build Coastguard Worker unsigned guessed_trip_count;
3275*61046927SAndroid Build Coastguard Worker
3276*61046927SAndroid Build Coastguard Worker /* Maximum number of times the loop is run (if known) */
3277*61046927SAndroid Build Coastguard Worker unsigned max_trip_count;
3278*61046927SAndroid Build Coastguard Worker
3279*61046927SAndroid Build Coastguard Worker /* Do we know the exact number of times the loop will be run */
3280*61046927SAndroid Build Coastguard Worker bool exact_trip_count_known;
3281*61046927SAndroid Build Coastguard Worker
3282*61046927SAndroid Build Coastguard Worker /* Unroll the loop regardless of its size */
3283*61046927SAndroid Build Coastguard Worker bool force_unroll;
3284*61046927SAndroid Build Coastguard Worker
3285*61046927SAndroid Build Coastguard Worker /* Does the loop contain complex loop terminators, continues or other
3286*61046927SAndroid Build Coastguard Worker * complex behaviours? If this is true we can't rely on
3287*61046927SAndroid Build Coastguard Worker * loop_terminator_list to be complete or accurate.
3288*61046927SAndroid Build Coastguard Worker */
3289*61046927SAndroid Build Coastguard Worker bool complex_loop;
3290*61046927SAndroid Build Coastguard Worker
3291*61046927SAndroid Build Coastguard Worker nir_loop_terminator *limiting_terminator;
3292*61046927SAndroid Build Coastguard Worker
3293*61046927SAndroid Build Coastguard Worker /* A list of loop_terminators terminating this loop. */
3294*61046927SAndroid Build Coastguard Worker struct list_head loop_terminator_list;
3295*61046927SAndroid Build Coastguard Worker
3296*61046927SAndroid Build Coastguard Worker /* array of induction variables for this loop */
3297*61046927SAndroid Build Coastguard Worker nir_loop_induction_variable *induction_vars;
3298*61046927SAndroid Build Coastguard Worker unsigned num_induction_vars;
3299*61046927SAndroid Build Coastguard Worker } nir_loop_info;
3300*61046927SAndroid Build Coastguard Worker
3301*61046927SAndroid Build Coastguard Worker typedef enum {
3302*61046927SAndroid Build Coastguard Worker nir_loop_control_none = 0x0,
3303*61046927SAndroid Build Coastguard Worker nir_loop_control_unroll = 0x1,
3304*61046927SAndroid Build Coastguard Worker nir_loop_control_dont_unroll = 0x2,
3305*61046927SAndroid Build Coastguard Worker } nir_loop_control;
3306*61046927SAndroid Build Coastguard Worker
3307*61046927SAndroid Build Coastguard Worker typedef struct {
3308*61046927SAndroid Build Coastguard Worker nir_cf_node cf_node;
3309*61046927SAndroid Build Coastguard Worker
3310*61046927SAndroid Build Coastguard Worker /** list of nir_cf_node */
3311*61046927SAndroid Build Coastguard Worker struct exec_list body;
3312*61046927SAndroid Build Coastguard Worker
3313*61046927SAndroid Build Coastguard Worker /** (optional) list of nir_cf_node */
3314*61046927SAndroid Build Coastguard Worker struct exec_list continue_list;
3315*61046927SAndroid Build Coastguard Worker
3316*61046927SAndroid Build Coastguard Worker nir_loop_info *info;
3317*61046927SAndroid Build Coastguard Worker nir_loop_control control;
3318*61046927SAndroid Build Coastguard Worker bool partially_unrolled;
3319*61046927SAndroid Build Coastguard Worker bool divergent;
3320*61046927SAndroid Build Coastguard Worker } nir_loop;
3321*61046927SAndroid Build Coastguard Worker
3322*61046927SAndroid Build Coastguard Worker /**
3323*61046927SAndroid Build Coastguard Worker * Various bits of metadata that can may be created or required by
3324*61046927SAndroid Build Coastguard Worker * optimization and analysis passes
3325*61046927SAndroid Build Coastguard Worker */
3326*61046927SAndroid Build Coastguard Worker typedef enum {
3327*61046927SAndroid Build Coastguard Worker nir_metadata_none = 0x0,
3328*61046927SAndroid Build Coastguard Worker
3329*61046927SAndroid Build Coastguard Worker /** Indicates that nir_block::index values are valid.
3330*61046927SAndroid Build Coastguard Worker *
3331*61046927SAndroid Build Coastguard Worker * The start block has index 0 and they increase through a natural walk of
3332*61046927SAndroid Build Coastguard Worker * the CFG. nir_function_impl::num_blocks is the number of blocks and
3333*61046927SAndroid Build Coastguard Worker * every block index is in the range [0, nir_function_impl::num_blocks].
3334*61046927SAndroid Build Coastguard Worker *
3335*61046927SAndroid Build Coastguard Worker * A pass can preserve this metadata type if it doesn't touch the CFG.
3336*61046927SAndroid Build Coastguard Worker */
3337*61046927SAndroid Build Coastguard Worker nir_metadata_block_index = 0x1,
3338*61046927SAndroid Build Coastguard Worker
3339*61046927SAndroid Build Coastguard Worker /** Indicates that block dominance information is valid
3340*61046927SAndroid Build Coastguard Worker *
3341*61046927SAndroid Build Coastguard Worker * This includes:
3342*61046927SAndroid Build Coastguard Worker *
3343*61046927SAndroid Build Coastguard Worker * - nir_block::num_dom_children
3344*61046927SAndroid Build Coastguard Worker * - nir_block::dom_children
3345*61046927SAndroid Build Coastguard Worker * - nir_block::dom_frontier
3346*61046927SAndroid Build Coastguard Worker * - nir_block::dom_pre_index
3347*61046927SAndroid Build Coastguard Worker * - nir_block::dom_post_index
3348*61046927SAndroid Build Coastguard Worker *
3349*61046927SAndroid Build Coastguard Worker * A pass can preserve this metadata type if it doesn't touch the CFG.
3350*61046927SAndroid Build Coastguard Worker */
3351*61046927SAndroid Build Coastguard Worker nir_metadata_dominance = 0x2,
3352*61046927SAndroid Build Coastguard Worker
3353*61046927SAndroid Build Coastguard Worker /** Indicates that SSA def data-flow liveness information is valid
3354*61046927SAndroid Build Coastguard Worker *
3355*61046927SAndroid Build Coastguard Worker * This includes:
3356*61046927SAndroid Build Coastguard Worker *
3357*61046927SAndroid Build Coastguard Worker * - nir_block::live_in
3358*61046927SAndroid Build Coastguard Worker * - nir_block::live_out
3359*61046927SAndroid Build Coastguard Worker *
3360*61046927SAndroid Build Coastguard Worker * A pass can preserve this metadata type if it never adds or removes any
3361*61046927SAndroid Build Coastguard Worker * SSA defs or uses of SSA defs (most passes shouldn't preserve this
3362*61046927SAndroid Build Coastguard Worker * metadata type).
3363*61046927SAndroid Build Coastguard Worker */
3364*61046927SAndroid Build Coastguard Worker nir_metadata_live_defs = 0x4,
3365*61046927SAndroid Build Coastguard Worker
3366*61046927SAndroid Build Coastguard Worker /** A dummy metadata value to track when a pass forgot to call
3367*61046927SAndroid Build Coastguard Worker * nir_metadata_preserve.
3368*61046927SAndroid Build Coastguard Worker *
3369*61046927SAndroid Build Coastguard Worker * A pass should always clear this value even if it doesn't make any
3370*61046927SAndroid Build Coastguard Worker * progress to indicate that it thought about preserving metadata.
3371*61046927SAndroid Build Coastguard Worker */
3372*61046927SAndroid Build Coastguard Worker nir_metadata_not_properly_reset = 0x8,
3373*61046927SAndroid Build Coastguard Worker
3374*61046927SAndroid Build Coastguard Worker /** Indicates that loop analysis information is valid.
3375*61046927SAndroid Build Coastguard Worker *
3376*61046927SAndroid Build Coastguard Worker * This includes everything pointed to by nir_loop::info.
3377*61046927SAndroid Build Coastguard Worker *
3378*61046927SAndroid Build Coastguard Worker * A pass can preserve this metadata type if it is guaranteed to not affect
3379*61046927SAndroid Build Coastguard Worker * any loop metadata. However, since loop metadata includes things like
3380*61046927SAndroid Build Coastguard Worker * loop counts which depend on arithmetic in the loop, this is very hard to
3381*61046927SAndroid Build Coastguard Worker * determine. Most passes shouldn't preserve this metadata type.
3382*61046927SAndroid Build Coastguard Worker */
3383*61046927SAndroid Build Coastguard Worker nir_metadata_loop_analysis = 0x10,
3384*61046927SAndroid Build Coastguard Worker
3385*61046927SAndroid Build Coastguard Worker /** Indicates that nir_instr::index values are valid.
3386*61046927SAndroid Build Coastguard Worker *
3387*61046927SAndroid Build Coastguard Worker * The start instruction has index 0 and they increase through a natural
3388*61046927SAndroid Build Coastguard Worker * walk of instructions in blocks in the CFG. The indices my have holes
3389*61046927SAndroid Build Coastguard Worker * after passes such as DCE.
3390*61046927SAndroid Build Coastguard Worker *
3391*61046927SAndroid Build Coastguard Worker * A pass can preserve this metadata type if it never adds or moves any
3392*61046927SAndroid Build Coastguard Worker * instructions (most passes shouldn't preserve this metadata type), but
3393*61046927SAndroid Build Coastguard Worker * can preserve it if it only removes instructions.
3394*61046927SAndroid Build Coastguard Worker */
3395*61046927SAndroid Build Coastguard Worker nir_metadata_instr_index = 0x20,
3396*61046927SAndroid Build Coastguard Worker
3397*61046927SAndroid Build Coastguard Worker /** All control flow metadata
3398*61046927SAndroid Build Coastguard Worker *
3399*61046927SAndroid Build Coastguard Worker * This includes all metadata preserved by a pass that preserves control flow
3400*61046927SAndroid Build Coastguard Worker * but modifies instructions. For example, a pass using
3401*61046927SAndroid Build Coastguard Worker * nir_shader_instructions_pass will typically preserve this if it does not
3402*61046927SAndroid Build Coastguard Worker * insert control flow.
3403*61046927SAndroid Build Coastguard Worker *
3404*61046927SAndroid Build Coastguard Worker * This is the most common metadata set to preserve, so it has its own alias.
3405*61046927SAndroid Build Coastguard Worker */
3406*61046927SAndroid Build Coastguard Worker nir_metadata_control_flow = nir_metadata_block_index |
3407*61046927SAndroid Build Coastguard Worker nir_metadata_dominance,
3408*61046927SAndroid Build Coastguard Worker
3409*61046927SAndroid Build Coastguard Worker /** All metadata
3410*61046927SAndroid Build Coastguard Worker *
3411*61046927SAndroid Build Coastguard Worker * This includes all nir_metadata flags except not_properly_reset. Passes
3412*61046927SAndroid Build Coastguard Worker * which do not change the shader in any way should call
3413*61046927SAndroid Build Coastguard Worker *
3414*61046927SAndroid Build Coastguard Worker * nir_metadata_preserve(impl, nir_metadata_all);
3415*61046927SAndroid Build Coastguard Worker */
3416*61046927SAndroid Build Coastguard Worker nir_metadata_all = ~nir_metadata_not_properly_reset,
3417*61046927SAndroid Build Coastguard Worker } nir_metadata;
3418*61046927SAndroid Build Coastguard Worker MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(nir_metadata)
3419*61046927SAndroid Build Coastguard Worker
3420*61046927SAndroid Build Coastguard Worker typedef struct {
3421*61046927SAndroid Build Coastguard Worker nir_cf_node cf_node;
3422*61046927SAndroid Build Coastguard Worker
3423*61046927SAndroid Build Coastguard Worker /** pointer to the function of which this is an implementation */
3424*61046927SAndroid Build Coastguard Worker struct nir_function *function;
3425*61046927SAndroid Build Coastguard Worker
3426*61046927SAndroid Build Coastguard Worker /**
3427*61046927SAndroid Build Coastguard Worker * For entrypoints, a pointer to a nir_function_impl which runs before
3428*61046927SAndroid Build Coastguard Worker * it, once per draw or dispatch, communicating via store_preamble and
3429*61046927SAndroid Build Coastguard Worker * load_preamble intrinsics. If NULL then there is no preamble.
3430*61046927SAndroid Build Coastguard Worker */
3431*61046927SAndroid Build Coastguard Worker struct nir_function *preamble;
3432*61046927SAndroid Build Coastguard Worker
3433*61046927SAndroid Build Coastguard Worker /** list of nir_cf_node */
3434*61046927SAndroid Build Coastguard Worker struct exec_list body;
3435*61046927SAndroid Build Coastguard Worker
3436*61046927SAndroid Build Coastguard Worker nir_block *end_block;
3437*61046927SAndroid Build Coastguard Worker
3438*61046927SAndroid Build Coastguard Worker /** list for all local variables in the function */
3439*61046927SAndroid Build Coastguard Worker struct exec_list locals;
3440*61046927SAndroid Build Coastguard Worker
3441*61046927SAndroid Build Coastguard Worker /** next available SSA value index */
3442*61046927SAndroid Build Coastguard Worker unsigned ssa_alloc;
3443*61046927SAndroid Build Coastguard Worker
3444*61046927SAndroid Build Coastguard Worker /* total number of basic blocks, only valid when block_index_dirty = false */
3445*61046927SAndroid Build Coastguard Worker unsigned num_blocks;
3446*61046927SAndroid Build Coastguard Worker
3447*61046927SAndroid Build Coastguard Worker /** True if this nir_function_impl uses structured control-flow
3448*61046927SAndroid Build Coastguard Worker *
3449*61046927SAndroid Build Coastguard Worker * Structured nir_function_impls have different validation rules.
3450*61046927SAndroid Build Coastguard Worker */
3451*61046927SAndroid Build Coastguard Worker bool structured;
3452*61046927SAndroid Build Coastguard Worker
3453*61046927SAndroid Build Coastguard Worker nir_metadata valid_metadata;
3454*61046927SAndroid Build Coastguard Worker } nir_function_impl;
3455*61046927SAndroid Build Coastguard Worker
3456*61046927SAndroid Build Coastguard Worker #define nir_foreach_function_temp_variable(var, impl) \
3457*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_variable, var, node, &(impl)->locals)
3458*61046927SAndroid Build Coastguard Worker
3459*61046927SAndroid Build Coastguard Worker #define nir_foreach_function_temp_variable_safe(var, impl) \
3460*61046927SAndroid Build Coastguard Worker foreach_list_typed_safe(nir_variable, var, node, &(impl)->locals)
3461*61046927SAndroid Build Coastguard Worker
3462*61046927SAndroid Build Coastguard Worker ATTRIBUTE_RETURNS_NONNULL static inline nir_block *
nir_start_block(nir_function_impl * impl)3463*61046927SAndroid Build Coastguard Worker nir_start_block(nir_function_impl *impl)
3464*61046927SAndroid Build Coastguard Worker {
3465*61046927SAndroid Build Coastguard Worker return (nir_block *)impl->body.head_sentinel.next;
3466*61046927SAndroid Build Coastguard Worker }
3467*61046927SAndroid Build Coastguard Worker
3468*61046927SAndroid Build Coastguard Worker ATTRIBUTE_RETURNS_NONNULL static inline nir_block *
nir_impl_last_block(nir_function_impl * impl)3469*61046927SAndroid Build Coastguard Worker nir_impl_last_block(nir_function_impl *impl)
3470*61046927SAndroid Build Coastguard Worker {
3471*61046927SAndroid Build Coastguard Worker return (nir_block *)impl->body.tail_sentinel.prev;
3472*61046927SAndroid Build Coastguard Worker }
3473*61046927SAndroid Build Coastguard Worker
3474*61046927SAndroid Build Coastguard Worker static inline nir_cf_node *
nir_cf_node_next(nir_cf_node * node)3475*61046927SAndroid Build Coastguard Worker nir_cf_node_next(nir_cf_node *node)
3476*61046927SAndroid Build Coastguard Worker {
3477*61046927SAndroid Build Coastguard Worker struct exec_node *next = exec_node_get_next(&node->node);
3478*61046927SAndroid Build Coastguard Worker if (exec_node_is_tail_sentinel(next))
3479*61046927SAndroid Build Coastguard Worker return NULL;
3480*61046927SAndroid Build Coastguard Worker else
3481*61046927SAndroid Build Coastguard Worker return exec_node_data(nir_cf_node, next, node);
3482*61046927SAndroid Build Coastguard Worker }
3483*61046927SAndroid Build Coastguard Worker
3484*61046927SAndroid Build Coastguard Worker static inline nir_cf_node *
nir_cf_node_prev(nir_cf_node * node)3485*61046927SAndroid Build Coastguard Worker nir_cf_node_prev(nir_cf_node *node)
3486*61046927SAndroid Build Coastguard Worker {
3487*61046927SAndroid Build Coastguard Worker struct exec_node *prev = exec_node_get_prev(&node->node);
3488*61046927SAndroid Build Coastguard Worker if (exec_node_is_head_sentinel(prev))
3489*61046927SAndroid Build Coastguard Worker return NULL;
3490*61046927SAndroid Build Coastguard Worker else
3491*61046927SAndroid Build Coastguard Worker return exec_node_data(nir_cf_node, prev, node);
3492*61046927SAndroid Build Coastguard Worker }
3493*61046927SAndroid Build Coastguard Worker
3494*61046927SAndroid Build Coastguard Worker static inline bool
nir_cf_node_is_first(const nir_cf_node * node)3495*61046927SAndroid Build Coastguard Worker nir_cf_node_is_first(const nir_cf_node *node)
3496*61046927SAndroid Build Coastguard Worker {
3497*61046927SAndroid Build Coastguard Worker return exec_node_is_head_sentinel(node->node.prev);
3498*61046927SAndroid Build Coastguard Worker }
3499*61046927SAndroid Build Coastguard Worker
3500*61046927SAndroid Build Coastguard Worker static inline bool
nir_cf_node_is_last(const nir_cf_node * node)3501*61046927SAndroid Build Coastguard Worker nir_cf_node_is_last(const nir_cf_node *node)
3502*61046927SAndroid Build Coastguard Worker {
3503*61046927SAndroid Build Coastguard Worker return exec_node_is_tail_sentinel(node->node.next);
3504*61046927SAndroid Build Coastguard Worker }
3505*61046927SAndroid Build Coastguard Worker
NIR_DEFINE_CAST(nir_cf_node_as_block,nir_cf_node,nir_block,cf_node,type,nir_cf_node_block)3506*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_cf_node_as_block, nir_cf_node, nir_block, cf_node,
3507*61046927SAndroid Build Coastguard Worker type, nir_cf_node_block)
3508*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_cf_node_as_if, nir_cf_node, nir_if, cf_node,
3509*61046927SAndroid Build Coastguard Worker type, nir_cf_node_if)
3510*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_cf_node_as_loop, nir_cf_node, nir_loop, cf_node,
3511*61046927SAndroid Build Coastguard Worker type, nir_cf_node_loop)
3512*61046927SAndroid Build Coastguard Worker NIR_DEFINE_CAST(nir_cf_node_as_function, nir_cf_node,
3513*61046927SAndroid Build Coastguard Worker nir_function_impl, cf_node, type, nir_cf_node_function)
3514*61046927SAndroid Build Coastguard Worker
3515*61046927SAndroid Build Coastguard Worker static inline nir_block *
3516*61046927SAndroid Build Coastguard Worker nir_if_first_then_block(nir_if *if_stmt)
3517*61046927SAndroid Build Coastguard Worker {
3518*61046927SAndroid Build Coastguard Worker struct exec_node *head = exec_list_get_head(&if_stmt->then_list);
3519*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
3520*61046927SAndroid Build Coastguard Worker }
3521*61046927SAndroid Build Coastguard Worker
3522*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_if_last_then_block(nir_if * if_stmt)3523*61046927SAndroid Build Coastguard Worker nir_if_last_then_block(nir_if *if_stmt)
3524*61046927SAndroid Build Coastguard Worker {
3525*61046927SAndroid Build Coastguard Worker struct exec_node *tail = exec_list_get_tail(&if_stmt->then_list);
3526*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
3527*61046927SAndroid Build Coastguard Worker }
3528*61046927SAndroid Build Coastguard Worker
3529*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_if_first_else_block(nir_if * if_stmt)3530*61046927SAndroid Build Coastguard Worker nir_if_first_else_block(nir_if *if_stmt)
3531*61046927SAndroid Build Coastguard Worker {
3532*61046927SAndroid Build Coastguard Worker struct exec_node *head = exec_list_get_head(&if_stmt->else_list);
3533*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
3534*61046927SAndroid Build Coastguard Worker }
3535*61046927SAndroid Build Coastguard Worker
3536*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_if_last_else_block(nir_if * if_stmt)3537*61046927SAndroid Build Coastguard Worker nir_if_last_else_block(nir_if *if_stmt)
3538*61046927SAndroid Build Coastguard Worker {
3539*61046927SAndroid Build Coastguard Worker struct exec_node *tail = exec_list_get_tail(&if_stmt->else_list);
3540*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
3541*61046927SAndroid Build Coastguard Worker }
3542*61046927SAndroid Build Coastguard Worker
3543*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_loop_first_block(nir_loop * loop)3544*61046927SAndroid Build Coastguard Worker nir_loop_first_block(nir_loop *loop)
3545*61046927SAndroid Build Coastguard Worker {
3546*61046927SAndroid Build Coastguard Worker struct exec_node *head = exec_list_get_head(&loop->body);
3547*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
3548*61046927SAndroid Build Coastguard Worker }
3549*61046927SAndroid Build Coastguard Worker
3550*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_loop_last_block(nir_loop * loop)3551*61046927SAndroid Build Coastguard Worker nir_loop_last_block(nir_loop *loop)
3552*61046927SAndroid Build Coastguard Worker {
3553*61046927SAndroid Build Coastguard Worker struct exec_node *tail = exec_list_get_tail(&loop->body);
3554*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
3555*61046927SAndroid Build Coastguard Worker }
3556*61046927SAndroid Build Coastguard Worker
3557*61046927SAndroid Build Coastguard Worker static inline bool
nir_loop_has_continue_construct(const nir_loop * loop)3558*61046927SAndroid Build Coastguard Worker nir_loop_has_continue_construct(const nir_loop *loop)
3559*61046927SAndroid Build Coastguard Worker {
3560*61046927SAndroid Build Coastguard Worker return !exec_list_is_empty(&loop->continue_list);
3561*61046927SAndroid Build Coastguard Worker }
3562*61046927SAndroid Build Coastguard Worker
3563*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_loop_first_continue_block(nir_loop * loop)3564*61046927SAndroid Build Coastguard Worker nir_loop_first_continue_block(nir_loop *loop)
3565*61046927SAndroid Build Coastguard Worker {
3566*61046927SAndroid Build Coastguard Worker assert(nir_loop_has_continue_construct(loop));
3567*61046927SAndroid Build Coastguard Worker struct exec_node *head = exec_list_get_head(&loop->continue_list);
3568*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
3569*61046927SAndroid Build Coastguard Worker }
3570*61046927SAndroid Build Coastguard Worker
3571*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_loop_last_continue_block(nir_loop * loop)3572*61046927SAndroid Build Coastguard Worker nir_loop_last_continue_block(nir_loop *loop)
3573*61046927SAndroid Build Coastguard Worker {
3574*61046927SAndroid Build Coastguard Worker assert(nir_loop_has_continue_construct(loop));
3575*61046927SAndroid Build Coastguard Worker struct exec_node *tail = exec_list_get_tail(&loop->continue_list);
3576*61046927SAndroid Build Coastguard Worker return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
3577*61046927SAndroid Build Coastguard Worker }
3578*61046927SAndroid Build Coastguard Worker
3579*61046927SAndroid Build Coastguard Worker /**
3580*61046927SAndroid Build Coastguard Worker * Return the target block of a nir_jump_continue statement
3581*61046927SAndroid Build Coastguard Worker */
3582*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_loop_continue_target(nir_loop * loop)3583*61046927SAndroid Build Coastguard Worker nir_loop_continue_target(nir_loop *loop)
3584*61046927SAndroid Build Coastguard Worker {
3585*61046927SAndroid Build Coastguard Worker if (nir_loop_has_continue_construct(loop))
3586*61046927SAndroid Build Coastguard Worker return nir_loop_first_continue_block(loop);
3587*61046927SAndroid Build Coastguard Worker else
3588*61046927SAndroid Build Coastguard Worker return nir_loop_first_block(loop);
3589*61046927SAndroid Build Coastguard Worker }
3590*61046927SAndroid Build Coastguard Worker
3591*61046927SAndroid Build Coastguard Worker /**
3592*61046927SAndroid Build Coastguard Worker * Return true if this list of cf_nodes contains a single empty block.
3593*61046927SAndroid Build Coastguard Worker */
3594*61046927SAndroid Build Coastguard Worker static inline bool
nir_cf_list_is_empty_block(struct exec_list * cf_list)3595*61046927SAndroid Build Coastguard Worker nir_cf_list_is_empty_block(struct exec_list *cf_list)
3596*61046927SAndroid Build Coastguard Worker {
3597*61046927SAndroid Build Coastguard Worker if (exec_list_is_singular(cf_list)) {
3598*61046927SAndroid Build Coastguard Worker struct exec_node *head = exec_list_get_head(cf_list);
3599*61046927SAndroid Build Coastguard Worker nir_block *block =
3600*61046927SAndroid Build Coastguard Worker nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
3601*61046927SAndroid Build Coastguard Worker return exec_list_is_empty(&block->instr_list);
3602*61046927SAndroid Build Coastguard Worker }
3603*61046927SAndroid Build Coastguard Worker return false;
3604*61046927SAndroid Build Coastguard Worker }
3605*61046927SAndroid Build Coastguard Worker
3606*61046927SAndroid Build Coastguard Worker typedef struct {
3607*61046927SAndroid Build Coastguard Worker uint8_t num_components;
3608*61046927SAndroid Build Coastguard Worker uint8_t bit_size;
3609*61046927SAndroid Build Coastguard Worker
3610*61046927SAndroid Build Coastguard Worker /* True if this paramater is actually the function return variable */
3611*61046927SAndroid Build Coastguard Worker bool is_return;
3612*61046927SAndroid Build Coastguard Worker
3613*61046927SAndroid Build Coastguard Worker /* The type of the function param */
3614*61046927SAndroid Build Coastguard Worker const struct glsl_type *type;
3615*61046927SAndroid Build Coastguard Worker } nir_parameter;
3616*61046927SAndroid Build Coastguard Worker
3617*61046927SAndroid Build Coastguard Worker typedef struct nir_function {
3618*61046927SAndroid Build Coastguard Worker struct exec_node node;
3619*61046927SAndroid Build Coastguard Worker
3620*61046927SAndroid Build Coastguard Worker const char *name;
3621*61046927SAndroid Build Coastguard Worker struct nir_shader *shader;
3622*61046927SAndroid Build Coastguard Worker
3623*61046927SAndroid Build Coastguard Worker unsigned num_params;
3624*61046927SAndroid Build Coastguard Worker nir_parameter *params;
3625*61046927SAndroid Build Coastguard Worker
3626*61046927SAndroid Build Coastguard Worker /** The implementation of this function.
3627*61046927SAndroid Build Coastguard Worker *
3628*61046927SAndroid Build Coastguard Worker * If the function is only declared and not implemented, this is NULL.
3629*61046927SAndroid Build Coastguard Worker *
3630*61046927SAndroid Build Coastguard Worker * Unless setting to NULL or NIR_SERIALIZE_FUNC_HAS_IMPL, set with
3631*61046927SAndroid Build Coastguard Worker * nir_function_set_impl to maintain IR invariants.
3632*61046927SAndroid Build Coastguard Worker */
3633*61046927SAndroid Build Coastguard Worker nir_function_impl *impl;
3634*61046927SAndroid Build Coastguard Worker
3635*61046927SAndroid Build Coastguard Worker bool is_entrypoint;
3636*61046927SAndroid Build Coastguard Worker /* from SPIR-V linkage, only for libraries */
3637*61046927SAndroid Build Coastguard Worker bool is_exported;
3638*61046927SAndroid Build Coastguard Worker bool is_preamble;
3639*61046927SAndroid Build Coastguard Worker /* from SPIR-V function control */
3640*61046927SAndroid Build Coastguard Worker bool should_inline;
3641*61046927SAndroid Build Coastguard Worker bool dont_inline; /* from SPIR-V */
3642*61046927SAndroid Build Coastguard Worker
3643*61046927SAndroid Build Coastguard Worker /**
3644*61046927SAndroid Build Coastguard Worker * Is this function a subroutine type declaration
3645*61046927SAndroid Build Coastguard Worker * e.g. subroutine void type1(float arg1);
3646*61046927SAndroid Build Coastguard Worker */
3647*61046927SAndroid Build Coastguard Worker bool is_subroutine;
3648*61046927SAndroid Build Coastguard Worker
3649*61046927SAndroid Build Coastguard Worker /**
3650*61046927SAndroid Build Coastguard Worker * Is this function associated to a subroutine type
3651*61046927SAndroid Build Coastguard Worker * e.g. subroutine (type1, type2) function_name { function_body };
3652*61046927SAndroid Build Coastguard Worker * would have num_subroutine_types 2,
3653*61046927SAndroid Build Coastguard Worker * and pointers to the type1 and type2 types.
3654*61046927SAndroid Build Coastguard Worker */
3655*61046927SAndroid Build Coastguard Worker int num_subroutine_types;
3656*61046927SAndroid Build Coastguard Worker const struct glsl_type **subroutine_types;
3657*61046927SAndroid Build Coastguard Worker
3658*61046927SAndroid Build Coastguard Worker int subroutine_index;
3659*61046927SAndroid Build Coastguard Worker } nir_function;
3660*61046927SAndroid Build Coastguard Worker
3661*61046927SAndroid Build Coastguard Worker typedef enum {
3662*61046927SAndroid Build Coastguard Worker nir_lower_imul64 = (1 << 0),
3663*61046927SAndroid Build Coastguard Worker nir_lower_isign64 = (1 << 1),
3664*61046927SAndroid Build Coastguard Worker /** Lower all int64 modulus and division opcodes */
3665*61046927SAndroid Build Coastguard Worker nir_lower_divmod64 = (1 << 2),
3666*61046927SAndroid Build Coastguard Worker /** Lower all 64-bit umul_high and imul_high opcodes */
3667*61046927SAndroid Build Coastguard Worker nir_lower_imul_high64 = (1 << 3),
3668*61046927SAndroid Build Coastguard Worker nir_lower_bcsel64 = (1 << 4),
3669*61046927SAndroid Build Coastguard Worker nir_lower_icmp64 = (1 << 5),
3670*61046927SAndroid Build Coastguard Worker nir_lower_iadd64 = (1 << 6),
3671*61046927SAndroid Build Coastguard Worker nir_lower_iabs64 = (1 << 7),
3672*61046927SAndroid Build Coastguard Worker nir_lower_ineg64 = (1 << 8),
3673*61046927SAndroid Build Coastguard Worker nir_lower_logic64 = (1 << 9),
3674*61046927SAndroid Build Coastguard Worker nir_lower_minmax64 = (1 << 10),
3675*61046927SAndroid Build Coastguard Worker nir_lower_shift64 = (1 << 11),
3676*61046927SAndroid Build Coastguard Worker nir_lower_imul_2x32_64 = (1 << 12),
3677*61046927SAndroid Build Coastguard Worker nir_lower_extract64 = (1 << 13),
3678*61046927SAndroid Build Coastguard Worker nir_lower_ufind_msb64 = (1 << 14),
3679*61046927SAndroid Build Coastguard Worker nir_lower_bit_count64 = (1 << 15),
3680*61046927SAndroid Build Coastguard Worker nir_lower_subgroup_shuffle64 = (1 << 16),
3681*61046927SAndroid Build Coastguard Worker nir_lower_scan_reduce_bitwise64 = (1 << 17),
3682*61046927SAndroid Build Coastguard Worker nir_lower_scan_reduce_iadd64 = (1 << 18),
3683*61046927SAndroid Build Coastguard Worker nir_lower_vote_ieq64 = (1 << 19),
3684*61046927SAndroid Build Coastguard Worker nir_lower_usub_sat64 = (1 << 20),
3685*61046927SAndroid Build Coastguard Worker nir_lower_iadd_sat64 = (1 << 21),
3686*61046927SAndroid Build Coastguard Worker nir_lower_find_lsb64 = (1 << 22),
3687*61046927SAndroid Build Coastguard Worker nir_lower_conv64 = (1 << 23),
3688*61046927SAndroid Build Coastguard Worker nir_lower_uadd_sat64 = (1 << 24),
3689*61046927SAndroid Build Coastguard Worker nir_lower_iadd3_64 = (1 << 25),
3690*61046927SAndroid Build Coastguard Worker } nir_lower_int64_options;
3691*61046927SAndroid Build Coastguard Worker
3692*61046927SAndroid Build Coastguard Worker typedef enum {
3693*61046927SAndroid Build Coastguard Worker nir_lower_drcp = (1 << 0),
3694*61046927SAndroid Build Coastguard Worker nir_lower_dsqrt = (1 << 1),
3695*61046927SAndroid Build Coastguard Worker nir_lower_drsq = (1 << 2),
3696*61046927SAndroid Build Coastguard Worker nir_lower_dtrunc = (1 << 3),
3697*61046927SAndroid Build Coastguard Worker nir_lower_dfloor = (1 << 4),
3698*61046927SAndroid Build Coastguard Worker nir_lower_dceil = (1 << 5),
3699*61046927SAndroid Build Coastguard Worker nir_lower_dfract = (1 << 6),
3700*61046927SAndroid Build Coastguard Worker nir_lower_dround_even = (1 << 7),
3701*61046927SAndroid Build Coastguard Worker nir_lower_dmod = (1 << 8),
3702*61046927SAndroid Build Coastguard Worker nir_lower_dsub = (1 << 9),
3703*61046927SAndroid Build Coastguard Worker nir_lower_ddiv = (1 << 10),
3704*61046927SAndroid Build Coastguard Worker nir_lower_dsign = (1 << 11),
3705*61046927SAndroid Build Coastguard Worker nir_lower_dminmax = (1 << 12),
3706*61046927SAndroid Build Coastguard Worker nir_lower_dsat = (1 << 13),
3707*61046927SAndroid Build Coastguard Worker nir_lower_fp64_full_software = (1 << 14),
3708*61046927SAndroid Build Coastguard Worker } nir_lower_doubles_options;
3709*61046927SAndroid Build Coastguard Worker
3710*61046927SAndroid Build Coastguard Worker typedef enum {
3711*61046927SAndroid Build Coastguard Worker nir_divergence_single_prim_per_subgroup = (1 << 0),
3712*61046927SAndroid Build Coastguard Worker nir_divergence_single_patch_per_tcs_subgroup = (1 << 1),
3713*61046927SAndroid Build Coastguard Worker nir_divergence_single_patch_per_tes_subgroup = (1 << 2),
3714*61046927SAndroid Build Coastguard Worker nir_divergence_view_index_uniform = (1 << 3),
3715*61046927SAndroid Build Coastguard Worker nir_divergence_single_frag_shading_rate_per_subgroup = (1 << 4),
3716*61046927SAndroid Build Coastguard Worker nir_divergence_multiple_workgroup_per_compute_subgroup = (1 << 5),
3717*61046927SAndroid Build Coastguard Worker nir_divergence_shader_record_ptr_uniform = (1 << 6),
3718*61046927SAndroid Build Coastguard Worker nir_divergence_uniform_load_tears = (1 << 7),
3719*61046927SAndroid Build Coastguard Worker } nir_divergence_options;
3720*61046927SAndroid Build Coastguard Worker
3721*61046927SAndroid Build Coastguard Worker typedef enum {
3722*61046927SAndroid Build Coastguard Worker /**
3723*61046927SAndroid Build Coastguard Worker * Whether a fragment shader can interpolate the same input multiple times
3724*61046927SAndroid Build Coastguard Worker * with different modes (smooth, noperspective) and locations (pixel,
3725*61046927SAndroid Build Coastguard Worker * centroid, sample, at_offset, at_sample), excluding the flat mode.
3726*61046927SAndroid Build Coastguard Worker *
3727*61046927SAndroid Build Coastguard Worker * This matches AMD GPU flexibility and limitations and is a superset of
3728*61046927SAndroid Build Coastguard Worker * the GL4 requirement that each input can be interpolated at its specified
3729*61046927SAndroid Build Coastguard Worker * location, and then also as centroid, at_offset, and at_sample.
3730*61046927SAndroid Build Coastguard Worker */
3731*61046927SAndroid Build Coastguard Worker nir_io_has_flexible_input_interpolation_except_flat = BITFIELD_BIT(0),
3732*61046927SAndroid Build Coastguard Worker
3733*61046927SAndroid Build Coastguard Worker /**
3734*61046927SAndroid Build Coastguard Worker * nir_opt_varyings compacts (relocates) components of varyings by
3735*61046927SAndroid Build Coastguard Worker * rewriting their locations completely, effectively moving components of
3736*61046927SAndroid Build Coastguard Worker * varyings between slots. This option forces nir_opt_varyings to make
3737*61046927SAndroid Build Coastguard Worker * VARYING_SLOT_POS unused by moving its contents to VARn if the consumer
3738*61046927SAndroid Build Coastguard Worker * is not FS. If this option is not set and POS is unused, it moves
3739*61046927SAndroid Build Coastguard Worker * components of VARn to POS until it's fully used.
3740*61046927SAndroid Build Coastguard Worker */
3741*61046927SAndroid Build Coastguard Worker nir_io_dont_use_pos_for_non_fs_varyings = BITFIELD_BIT(1),
3742*61046927SAndroid Build Coastguard Worker
3743*61046927SAndroid Build Coastguard Worker nir_io_16bit_input_output_support = BITFIELD_BIT(2),
3744*61046927SAndroid Build Coastguard Worker
3745*61046927SAndroid Build Coastguard Worker /**
3746*61046927SAndroid Build Coastguard Worker * Implement mediump inputs and outputs as normal 32-bit IO.
3747*61046927SAndroid Build Coastguard Worker * Causes the mediump flag to be not set for IO semantics, essentially
3748*61046927SAndroid Build Coastguard Worker * destroying any mediump-related IO information in the shader.
3749*61046927SAndroid Build Coastguard Worker */
3750*61046927SAndroid Build Coastguard Worker nir_io_mediump_is_32bit = BITFIELD_BIT(3),
3751*61046927SAndroid Build Coastguard Worker
3752*61046927SAndroid Build Coastguard Worker /**
3753*61046927SAndroid Build Coastguard Worker * Whether nir_opt_vectorize_io should ignore FS inputs.
3754*61046927SAndroid Build Coastguard Worker */
3755*61046927SAndroid Build Coastguard Worker nir_io_prefer_scalar_fs_inputs = BITFIELD_BIT(4),
3756*61046927SAndroid Build Coastguard Worker
3757*61046927SAndroid Build Coastguard Worker /**
3758*61046927SAndroid Build Coastguard Worker * Whether interpolated fragment shader vec4 slots can use load_input for
3759*61046927SAndroid Build Coastguard Worker * a subset of its components to skip interpolation for those components.
3760*61046927SAndroid Build Coastguard Worker * The result of such load_input is a value from a random (not necessarily
3761*61046927SAndroid Build Coastguard Worker * provoking) vertex. If a value from the provoking vertex is required,
3762*61046927SAndroid Build Coastguard Worker * the vec4 slot should have no load_interpolated_input instructions.
3763*61046927SAndroid Build Coastguard Worker *
3764*61046927SAndroid Build Coastguard Worker * This exposes the AMD capability that allows packing flat inputs with
3765*61046927SAndroid Build Coastguard Worker * interpolated inputs in a limited number of cases. Normally, flat
3766*61046927SAndroid Build Coastguard Worker * components must be in a separate vec4 slot to get the value from
3767*61046927SAndroid Build Coastguard Worker * the provoking vertex. If the compiler can prove that all per-vertex
3768*61046927SAndroid Build Coastguard Worker * values are equal (convergent, i.e. the provoking vertex doesn't matter),
3769*61046927SAndroid Build Coastguard Worker * it can put such flat components into any interpolated vec4 slot.
3770*61046927SAndroid Build Coastguard Worker *
3771*61046927SAndroid Build Coastguard Worker * It should also be set if the hw can mix flat and interpolated components
3772*61046927SAndroid Build Coastguard Worker * in the same vec4 slot.
3773*61046927SAndroid Build Coastguard Worker *
3774*61046927SAndroid Build Coastguard Worker * This causes nir_opt_varyings to skip interpolation for all varyings
3775*61046927SAndroid Build Coastguard Worker * that are convergent, and enables better compaction and inter-shader code
3776*61046927SAndroid Build Coastguard Worker * motion for convergent varyings.
3777*61046927SAndroid Build Coastguard Worker */
3778*61046927SAndroid Build Coastguard Worker nir_io_mix_convergent_flat_with_interpolated = BITFIELD_BIT(5),
3779*61046927SAndroid Build Coastguard Worker
3780*61046927SAndroid Build Coastguard Worker /**
3781*61046927SAndroid Build Coastguard Worker * Whether src_type and dest_type of IO intrinsics are irrelevant and
3782*61046927SAndroid Build Coastguard Worker * should be ignored by nir_opt_vectorize_io. All drivers that always treat
3783*61046927SAndroid Build Coastguard Worker * load_input and store_output as untyped and load_interpolated_input as
3784*61046927SAndroid Build Coastguard Worker * float##bit_size should set this.
3785*61046927SAndroid Build Coastguard Worker */
3786*61046927SAndroid Build Coastguard Worker nir_io_vectorizer_ignores_types = BITFIELD_BIT(6),
3787*61046927SAndroid Build Coastguard Worker
3788*61046927SAndroid Build Coastguard Worker /* Options affecting the GLSL compiler are below. */
3789*61046927SAndroid Build Coastguard Worker
3790*61046927SAndroid Build Coastguard Worker /**
3791*61046927SAndroid Build Coastguard Worker * Lower load_deref/store_deref to load_input/store_output/etc. intrinsics.
3792*61046927SAndroid Build Coastguard Worker * This is only affects GLSL compilation.
3793*61046927SAndroid Build Coastguard Worker */
3794*61046927SAndroid Build Coastguard Worker nir_io_glsl_lower_derefs = BITFIELD_BIT(16),
3795*61046927SAndroid Build Coastguard Worker
3796*61046927SAndroid Build Coastguard Worker /**
3797*61046927SAndroid Build Coastguard Worker * Run nir_opt_varyings in the GLSL linker. If false, optimize varyings
3798*61046927SAndroid Build Coastguard Worker * the old way and lower IO later.
3799*61046927SAndroid Build Coastguard Worker *
3800*61046927SAndroid Build Coastguard Worker * nir_io_lower_to_intrinsics must be set for this to take effect.
3801*61046927SAndroid Build Coastguard Worker *
3802*61046927SAndroid Build Coastguard Worker * TODO: remove this and default to enabled once we are sure that this
3803*61046927SAndroid Build Coastguard Worker * codepath is solid.
3804*61046927SAndroid Build Coastguard Worker */
3805*61046927SAndroid Build Coastguard Worker nir_io_glsl_opt_varyings = BITFIELD_BIT(17),
3806*61046927SAndroid Build Coastguard Worker } nir_io_options;
3807*61046927SAndroid Build Coastguard Worker
3808*61046927SAndroid Build Coastguard Worker typedef enum {
3809*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_pack_64_2x32,
3810*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_unpack_64_2x32,
3811*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_pack_64_4x16,
3812*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_unpack_64_4x16,
3813*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_pack_32_2x16,
3814*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_unpack_32_2x16,
3815*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_pack_32_4x8,
3816*61046927SAndroid Build Coastguard Worker nir_lower_packing_op_unpack_32_4x8,
3817*61046927SAndroid Build Coastguard Worker nir_lower_packing_num_ops,
3818*61046927SAndroid Build Coastguard Worker } nir_lower_packing_op;
3819*61046927SAndroid Build Coastguard Worker
3820*61046927SAndroid Build Coastguard Worker /** An instruction filtering callback
3821*61046927SAndroid Build Coastguard Worker *
3822*61046927SAndroid Build Coastguard Worker * Returns true if the instruction should be processed and false otherwise.
3823*61046927SAndroid Build Coastguard Worker */
3824*61046927SAndroid Build Coastguard Worker typedef bool (*nir_instr_filter_cb)(const nir_instr *, const void *);
3825*61046927SAndroid Build Coastguard Worker
3826*61046927SAndroid Build Coastguard Worker /** A vectorization width callback
3827*61046927SAndroid Build Coastguard Worker *
3828*61046927SAndroid Build Coastguard Worker * Returns the maximum vectorization width per instruction.
3829*61046927SAndroid Build Coastguard Worker * 0, if the instruction must not be modified.
3830*61046927SAndroid Build Coastguard Worker *
3831*61046927SAndroid Build Coastguard Worker * The vectorization width must be a power of 2.
3832*61046927SAndroid Build Coastguard Worker */
3833*61046927SAndroid Build Coastguard Worker typedef uint8_t (*nir_vectorize_cb)(const nir_instr *, const void *);
3834*61046927SAndroid Build Coastguard Worker
3835*61046927SAndroid Build Coastguard Worker typedef struct nir_shader_compiler_options {
3836*61046927SAndroid Build Coastguard Worker bool lower_fdiv;
3837*61046927SAndroid Build Coastguard Worker bool lower_ffma16;
3838*61046927SAndroid Build Coastguard Worker bool lower_ffma32;
3839*61046927SAndroid Build Coastguard Worker bool lower_ffma64;
3840*61046927SAndroid Build Coastguard Worker bool fuse_ffma16;
3841*61046927SAndroid Build Coastguard Worker bool fuse_ffma32;
3842*61046927SAndroid Build Coastguard Worker bool fuse_ffma64;
3843*61046927SAndroid Build Coastguard Worker bool lower_flrp16;
3844*61046927SAndroid Build Coastguard Worker bool lower_flrp32;
3845*61046927SAndroid Build Coastguard Worker /** Lowers flrp when it does not support doubles */
3846*61046927SAndroid Build Coastguard Worker bool lower_flrp64;
3847*61046927SAndroid Build Coastguard Worker bool lower_fpow;
3848*61046927SAndroid Build Coastguard Worker bool lower_fsat;
3849*61046927SAndroid Build Coastguard Worker bool lower_fsqrt;
3850*61046927SAndroid Build Coastguard Worker bool lower_sincos;
3851*61046927SAndroid Build Coastguard Worker bool lower_fmod;
3852*61046927SAndroid Build Coastguard Worker /** Lowers ibitfield_extract/ubitfield_extract. */
3853*61046927SAndroid Build Coastguard Worker bool lower_bitfield_extract;
3854*61046927SAndroid Build Coastguard Worker /** Lowers bitfield_insert. */
3855*61046927SAndroid Build Coastguard Worker bool lower_bitfield_insert;
3856*61046927SAndroid Build Coastguard Worker /** Lowers bitfield_reverse to shifts. */
3857*61046927SAndroid Build Coastguard Worker bool lower_bitfield_reverse;
3858*61046927SAndroid Build Coastguard Worker /** Lowers bit_count to shifts. */
3859*61046927SAndroid Build Coastguard Worker bool lower_bit_count;
3860*61046927SAndroid Build Coastguard Worker /** Lowers ifind_msb. */
3861*61046927SAndroid Build Coastguard Worker bool lower_ifind_msb;
3862*61046927SAndroid Build Coastguard Worker /** Lowers ufind_msb. */
3863*61046927SAndroid Build Coastguard Worker bool lower_ufind_msb;
3864*61046927SAndroid Build Coastguard Worker /** Lowers find_lsb to ufind_msb and logic ops */
3865*61046927SAndroid Build Coastguard Worker bool lower_find_lsb;
3866*61046927SAndroid Build Coastguard Worker bool lower_uadd_carry;
3867*61046927SAndroid Build Coastguard Worker bool lower_usub_borrow;
3868*61046927SAndroid Build Coastguard Worker /** Lowers imul_high/umul_high to 16-bit multiplies and carry operations. */
3869*61046927SAndroid Build Coastguard Worker bool lower_mul_high;
3870*61046927SAndroid Build Coastguard Worker /** lowers fneg to fmul(x, -1.0). Driver must call nir_opt_algebraic_late() */
3871*61046927SAndroid Build Coastguard Worker bool lower_fneg;
3872*61046927SAndroid Build Coastguard Worker /** lowers ineg to isub. Driver must call nir_opt_algebraic_late(). */
3873*61046927SAndroid Build Coastguard Worker bool lower_ineg;
3874*61046927SAndroid Build Coastguard Worker /** lowers fisnormal to alu ops. */
3875*61046927SAndroid Build Coastguard Worker bool lower_fisnormal;
3876*61046927SAndroid Build Coastguard Worker
3877*61046927SAndroid Build Coastguard Worker /* lower {slt,sge,seq,sne} to {flt,fge,feq,fneu} + b2f: */
3878*61046927SAndroid Build Coastguard Worker bool lower_scmp;
3879*61046927SAndroid Build Coastguard Worker
3880*61046927SAndroid Build Coastguard Worker /* lower b/fall_equalN/b/fany_nequalN (ex:fany_nequal4 to sne+fdot4+fsat) */
3881*61046927SAndroid Build Coastguard Worker bool lower_vector_cmp;
3882*61046927SAndroid Build Coastguard Worker
3883*61046927SAndroid Build Coastguard Worker /** enable rules to avoid bit ops */
3884*61046927SAndroid Build Coastguard Worker bool lower_bitops;
3885*61046927SAndroid Build Coastguard Worker
3886*61046927SAndroid Build Coastguard Worker /** enables rules to lower isign to imin+imax */
3887*61046927SAndroid Build Coastguard Worker bool lower_isign;
3888*61046927SAndroid Build Coastguard Worker
3889*61046927SAndroid Build Coastguard Worker /** enables rules to lower fsign to fsub and flt */
3890*61046927SAndroid Build Coastguard Worker bool lower_fsign;
3891*61046927SAndroid Build Coastguard Worker
3892*61046927SAndroid Build Coastguard Worker /** enables rules to lower iabs to ineg+imax */
3893*61046927SAndroid Build Coastguard Worker bool lower_iabs;
3894*61046927SAndroid Build Coastguard Worker
3895*61046927SAndroid Build Coastguard Worker /** enable rules that avoid generating umax from signed integer ops */
3896*61046927SAndroid Build Coastguard Worker bool lower_umax;
3897*61046927SAndroid Build Coastguard Worker
3898*61046927SAndroid Build Coastguard Worker /** enable rules that avoid generating umin from signed integer ops */
3899*61046927SAndroid Build Coastguard Worker bool lower_umin;
3900*61046927SAndroid Build Coastguard Worker
3901*61046927SAndroid Build Coastguard Worker /* lower fmin/fmax with signed zero preserve to fmin/fmax with
3902*61046927SAndroid Build Coastguard Worker * no_signed_zero, for backends whose fmin/fmax implementations do not
3903*61046927SAndroid Build Coastguard Worker * implement IEEE-754-2019 semantics for signed zero.
3904*61046927SAndroid Build Coastguard Worker */
3905*61046927SAndroid Build Coastguard Worker bool lower_fminmax_signed_zero;
3906*61046927SAndroid Build Coastguard Worker
3907*61046927SAndroid Build Coastguard Worker /* lower fdph to fdot4 */
3908*61046927SAndroid Build Coastguard Worker bool lower_fdph;
3909*61046927SAndroid Build Coastguard Worker
3910*61046927SAndroid Build Coastguard Worker /** lower fdot to fmul and fsum/fadd. */
3911*61046927SAndroid Build Coastguard Worker bool lower_fdot;
3912*61046927SAndroid Build Coastguard Worker
3913*61046927SAndroid Build Coastguard Worker /* Does the native fdot instruction replicate its result for four
3914*61046927SAndroid Build Coastguard Worker * components? If so, then opt_algebraic_late will turn all fdotN
3915*61046927SAndroid Build Coastguard Worker * instructions into fdotN_replicated instructions.
3916*61046927SAndroid Build Coastguard Worker */
3917*61046927SAndroid Build Coastguard Worker bool fdot_replicates;
3918*61046927SAndroid Build Coastguard Worker
3919*61046927SAndroid Build Coastguard Worker /** lowers ffloor to fsub+ffract: */
3920*61046927SAndroid Build Coastguard Worker bool lower_ffloor;
3921*61046927SAndroid Build Coastguard Worker
3922*61046927SAndroid Build Coastguard Worker /** lowers ffract to fsub+ffloor: */
3923*61046927SAndroid Build Coastguard Worker bool lower_ffract;
3924*61046927SAndroid Build Coastguard Worker
3925*61046927SAndroid Build Coastguard Worker /** lowers fceil to fneg+ffloor+fneg: */
3926*61046927SAndroid Build Coastguard Worker bool lower_fceil;
3927*61046927SAndroid Build Coastguard Worker
3928*61046927SAndroid Build Coastguard Worker bool lower_ftrunc;
3929*61046927SAndroid Build Coastguard Worker
3930*61046927SAndroid Build Coastguard Worker /** Lowers fround_even to ffract+feq+csel.
3931*61046927SAndroid Build Coastguard Worker *
3932*61046927SAndroid Build Coastguard Worker * Not correct in that it doesn't correctly handle the "_even" part of the
3933*61046927SAndroid Build Coastguard Worker * rounding, but good enough for DX9 array indexing handling on DX9-class
3934*61046927SAndroid Build Coastguard Worker * hardware.
3935*61046927SAndroid Build Coastguard Worker */
3936*61046927SAndroid Build Coastguard Worker bool lower_fround_even;
3937*61046927SAndroid Build Coastguard Worker
3938*61046927SAndroid Build Coastguard Worker bool lower_ldexp;
3939*61046927SAndroid Build Coastguard Worker
3940*61046927SAndroid Build Coastguard Worker bool lower_pack_half_2x16;
3941*61046927SAndroid Build Coastguard Worker bool lower_pack_unorm_2x16;
3942*61046927SAndroid Build Coastguard Worker bool lower_pack_snorm_2x16;
3943*61046927SAndroid Build Coastguard Worker bool lower_pack_unorm_4x8;
3944*61046927SAndroid Build Coastguard Worker bool lower_pack_snorm_4x8;
3945*61046927SAndroid Build Coastguard Worker bool lower_pack_64_2x32;
3946*61046927SAndroid Build Coastguard Worker bool lower_pack_64_4x16;
3947*61046927SAndroid Build Coastguard Worker bool lower_pack_32_2x16;
3948*61046927SAndroid Build Coastguard Worker bool lower_pack_64_2x32_split;
3949*61046927SAndroid Build Coastguard Worker bool lower_pack_32_2x16_split;
3950*61046927SAndroid Build Coastguard Worker bool lower_unpack_half_2x16;
3951*61046927SAndroid Build Coastguard Worker bool lower_unpack_unorm_2x16;
3952*61046927SAndroid Build Coastguard Worker bool lower_unpack_snorm_2x16;
3953*61046927SAndroid Build Coastguard Worker bool lower_unpack_unorm_4x8;
3954*61046927SAndroid Build Coastguard Worker bool lower_unpack_snorm_4x8;
3955*61046927SAndroid Build Coastguard Worker bool lower_unpack_64_2x32_split;
3956*61046927SAndroid Build Coastguard Worker bool lower_unpack_32_2x16_split;
3957*61046927SAndroid Build Coastguard Worker
3958*61046927SAndroid Build Coastguard Worker bool lower_pack_split;
3959*61046927SAndroid Build Coastguard Worker
3960*61046927SAndroid Build Coastguard Worker bool lower_extract_byte;
3961*61046927SAndroid Build Coastguard Worker bool lower_extract_word;
3962*61046927SAndroid Build Coastguard Worker bool lower_insert_byte;
3963*61046927SAndroid Build Coastguard Worker bool lower_insert_word;
3964*61046927SAndroid Build Coastguard Worker
3965*61046927SAndroid Build Coastguard Worker bool lower_all_io_to_temps;
3966*61046927SAndroid Build Coastguard Worker bool lower_all_io_to_elements;
3967*61046927SAndroid Build Coastguard Worker
3968*61046927SAndroid Build Coastguard Worker /* Indicates that the driver only has zero-based vertex id */
3969*61046927SAndroid Build Coastguard Worker bool vertex_id_zero_based;
3970*61046927SAndroid Build Coastguard Worker
3971*61046927SAndroid Build Coastguard Worker /**
3972*61046927SAndroid Build Coastguard Worker * If enabled, gl_BaseVertex will be lowered as:
3973*61046927SAndroid Build Coastguard Worker * is_indexed_draw (~0/0) & firstvertex
3974*61046927SAndroid Build Coastguard Worker */
3975*61046927SAndroid Build Coastguard Worker bool lower_base_vertex;
3976*61046927SAndroid Build Coastguard Worker
3977*61046927SAndroid Build Coastguard Worker /**
3978*61046927SAndroid Build Coastguard Worker * If enabled, gl_HelperInvocation will be lowered as:
3979*61046927SAndroid Build Coastguard Worker *
3980*61046927SAndroid Build Coastguard Worker * !((1 << sample_id) & sample_mask_in))
3981*61046927SAndroid Build Coastguard Worker *
3982*61046927SAndroid Build Coastguard Worker * This depends on some possibly hw implementation details, which may
3983*61046927SAndroid Build Coastguard Worker * not be true for all hw. In particular that the FS is only executed
3984*61046927SAndroid Build Coastguard Worker * for covered samples or for helper invocations. So, do not blindly
3985*61046927SAndroid Build Coastguard Worker * enable this option.
3986*61046927SAndroid Build Coastguard Worker *
3987*61046927SAndroid Build Coastguard Worker * Note: See also issue #22 in ARB_shader_image_load_store
3988*61046927SAndroid Build Coastguard Worker */
3989*61046927SAndroid Build Coastguard Worker bool lower_helper_invocation;
3990*61046927SAndroid Build Coastguard Worker
3991*61046927SAndroid Build Coastguard Worker /**
3992*61046927SAndroid Build Coastguard Worker * Convert gl_SampleMaskIn to gl_HelperInvocation as follows:
3993*61046927SAndroid Build Coastguard Worker *
3994*61046927SAndroid Build Coastguard Worker * gl_SampleMaskIn == 0 ---> gl_HelperInvocation
3995*61046927SAndroid Build Coastguard Worker * gl_SampleMaskIn != 0 ---> !gl_HelperInvocation
3996*61046927SAndroid Build Coastguard Worker */
3997*61046927SAndroid Build Coastguard Worker bool optimize_sample_mask_in;
3998*61046927SAndroid Build Coastguard Worker
3999*61046927SAndroid Build Coastguard Worker /**
4000*61046927SAndroid Build Coastguard Worker * Optimize boolean reductions of quad broadcasts. This should only be enabled if
4001*61046927SAndroid Build Coastguard Worker * nir_intrinsic_reduce supports INCLUDE_HELPERS.
4002*61046927SAndroid Build Coastguard Worker */
4003*61046927SAndroid Build Coastguard Worker bool optimize_quad_vote_to_reduce;
4004*61046927SAndroid Build Coastguard Worker
4005*61046927SAndroid Build Coastguard Worker bool lower_cs_local_index_to_id;
4006*61046927SAndroid Build Coastguard Worker bool lower_cs_local_id_to_index;
4007*61046927SAndroid Build Coastguard Worker
4008*61046927SAndroid Build Coastguard Worker /* Prevents lowering global_invocation_id to be in terms of workgroup_id */
4009*61046927SAndroid Build Coastguard Worker bool has_cs_global_id;
4010*61046927SAndroid Build Coastguard Worker
4011*61046927SAndroid Build Coastguard Worker bool lower_device_index_to_zero;
4012*61046927SAndroid Build Coastguard Worker
4013*61046927SAndroid Build Coastguard Worker /* Set if nir_lower_pntc_ytransform() should invert gl_PointCoord.
4014*61046927SAndroid Build Coastguard Worker * Either when frame buffer is flipped or GL_POINT_SPRITE_COORD_ORIGIN
4015*61046927SAndroid Build Coastguard Worker * is GL_LOWER_LEFT.
4016*61046927SAndroid Build Coastguard Worker */
4017*61046927SAndroid Build Coastguard Worker bool lower_wpos_pntc;
4018*61046927SAndroid Build Coastguard Worker
4019*61046927SAndroid Build Coastguard Worker /**
4020*61046927SAndroid Build Coastguard Worker * Set if nir_op_[iu]hadd and nir_op_[iu]rhadd instructions should be
4021*61046927SAndroid Build Coastguard Worker * lowered to simple arithmetic.
4022*61046927SAndroid Build Coastguard Worker *
4023*61046927SAndroid Build Coastguard Worker * If this flag is set, the lowering will be applied to all bit-sizes of
4024*61046927SAndroid Build Coastguard Worker * these instructions.
4025*61046927SAndroid Build Coastguard Worker *
4026*61046927SAndroid Build Coastguard Worker * :c:member:`lower_hadd64`
4027*61046927SAndroid Build Coastguard Worker */
4028*61046927SAndroid Build Coastguard Worker bool lower_hadd;
4029*61046927SAndroid Build Coastguard Worker
4030*61046927SAndroid Build Coastguard Worker /**
4031*61046927SAndroid Build Coastguard Worker * Set if only 64-bit nir_op_[iu]hadd and nir_op_[iu]rhadd instructions
4032*61046927SAndroid Build Coastguard Worker * should be lowered to simple arithmetic.
4033*61046927SAndroid Build Coastguard Worker *
4034*61046927SAndroid Build Coastguard Worker * If this flag is set, the lowering will be applied to only 64-bit
4035*61046927SAndroid Build Coastguard Worker * versions of these instructions.
4036*61046927SAndroid Build Coastguard Worker *
4037*61046927SAndroid Build Coastguard Worker * :c:member:`lower_hadd`
4038*61046927SAndroid Build Coastguard Worker */
4039*61046927SAndroid Build Coastguard Worker bool lower_hadd64;
4040*61046927SAndroid Build Coastguard Worker
4041*61046927SAndroid Build Coastguard Worker /**
4042*61046927SAndroid Build Coastguard Worker * Set if nir_op_uadd_sat should be lowered to simple arithmetic.
4043*61046927SAndroid Build Coastguard Worker *
4044*61046927SAndroid Build Coastguard Worker * If this flag is set, the lowering will be applied to all bit-sizes of
4045*61046927SAndroid Build Coastguard Worker * these instructions.
4046*61046927SAndroid Build Coastguard Worker */
4047*61046927SAndroid Build Coastguard Worker bool lower_uadd_sat;
4048*61046927SAndroid Build Coastguard Worker
4049*61046927SAndroid Build Coastguard Worker /**
4050*61046927SAndroid Build Coastguard Worker * Set if nir_op_usub_sat should be lowered to simple arithmetic.
4051*61046927SAndroid Build Coastguard Worker *
4052*61046927SAndroid Build Coastguard Worker * If this flag is set, the lowering will be applied to all bit-sizes of
4053*61046927SAndroid Build Coastguard Worker * these instructions.
4054*61046927SAndroid Build Coastguard Worker */
4055*61046927SAndroid Build Coastguard Worker bool lower_usub_sat;
4056*61046927SAndroid Build Coastguard Worker
4057*61046927SAndroid Build Coastguard Worker /**
4058*61046927SAndroid Build Coastguard Worker * Set if nir_op_iadd_sat and nir_op_isub_sat should be lowered to simple
4059*61046927SAndroid Build Coastguard Worker * arithmetic.
4060*61046927SAndroid Build Coastguard Worker *
4061*61046927SAndroid Build Coastguard Worker * If this flag is set, the lowering will be applied to all bit-sizes of
4062*61046927SAndroid Build Coastguard Worker * these instructions.
4063*61046927SAndroid Build Coastguard Worker */
4064*61046927SAndroid Build Coastguard Worker bool lower_iadd_sat;
4065*61046927SAndroid Build Coastguard Worker
4066*61046927SAndroid Build Coastguard Worker /**
4067*61046927SAndroid Build Coastguard Worker * Set if imul_32x16 and umul_32x16 should be lowered to simple
4068*61046927SAndroid Build Coastguard Worker * arithmetic.
4069*61046927SAndroid Build Coastguard Worker */
4070*61046927SAndroid Build Coastguard Worker bool lower_mul_32x16;
4071*61046927SAndroid Build Coastguard Worker
4072*61046927SAndroid Build Coastguard Worker /**
4073*61046927SAndroid Build Coastguard Worker * Should IO be re-vectorized? Some scalar ISAs still operate on vec4's
4074*61046927SAndroid Build Coastguard Worker * for IO purposes and would prefer loads/stores be vectorized.
4075*61046927SAndroid Build Coastguard Worker */
4076*61046927SAndroid Build Coastguard Worker bool vectorize_io;
4077*61046927SAndroid Build Coastguard Worker bool vectorize_tess_levels;
4078*61046927SAndroid Build Coastguard Worker bool lower_to_scalar;
4079*61046927SAndroid Build Coastguard Worker nir_instr_filter_cb lower_to_scalar_filter;
4080*61046927SAndroid Build Coastguard Worker
4081*61046927SAndroid Build Coastguard Worker /**
4082*61046927SAndroid Build Coastguard Worker * Disables potentially harmful algebraic transformations for architectures
4083*61046927SAndroid Build Coastguard Worker * with SIMD-within-a-register semantics.
4084*61046927SAndroid Build Coastguard Worker *
4085*61046927SAndroid Build Coastguard Worker * Note, to actually vectorize 16bit instructions, use nir_opt_vectorize()
4086*61046927SAndroid Build Coastguard Worker * with a suitable callback function.
4087*61046927SAndroid Build Coastguard Worker */
4088*61046927SAndroid Build Coastguard Worker bool vectorize_vec2_16bit;
4089*61046927SAndroid Build Coastguard Worker
4090*61046927SAndroid Build Coastguard Worker /**
4091*61046927SAndroid Build Coastguard Worker * Should the linker unify inputs_read/outputs_written between adjacent
4092*61046927SAndroid Build Coastguard Worker * shader stages which are linked into a single program?
4093*61046927SAndroid Build Coastguard Worker */
4094*61046927SAndroid Build Coastguard Worker bool unify_interfaces;
4095*61046927SAndroid Build Coastguard Worker
4096*61046927SAndroid Build Coastguard Worker /**
4097*61046927SAndroid Build Coastguard Worker * Should nir_lower_io() create load_interpolated_input intrinsics?
4098*61046927SAndroid Build Coastguard Worker *
4099*61046927SAndroid Build Coastguard Worker * If not, it generates regular load_input intrinsics and interpolation
4100*61046927SAndroid Build Coastguard Worker * information must be inferred from the list of input nir_variables.
4101*61046927SAndroid Build Coastguard Worker */
4102*61046927SAndroid Build Coastguard Worker bool use_interpolated_input_intrinsics;
4103*61046927SAndroid Build Coastguard Worker
4104*61046927SAndroid Build Coastguard Worker /**
4105*61046927SAndroid Build Coastguard Worker * Whether nir_lower_io() will lower interpolateAt functions to
4106*61046927SAndroid Build Coastguard Worker * load_interpolated_input intrinsics.
4107*61046927SAndroid Build Coastguard Worker *
4108*61046927SAndroid Build Coastguard Worker * Unlike use_interpolated_input_intrinsics this will only lower these
4109*61046927SAndroid Build Coastguard Worker * functions and leave input load intrinsics untouched.
4110*61046927SAndroid Build Coastguard Worker */
4111*61046927SAndroid Build Coastguard Worker bool lower_interpolate_at;
4112*61046927SAndroid Build Coastguard Worker
4113*61046927SAndroid Build Coastguard Worker /* Lowers when 32x32->64 bit multiplication is not supported */
4114*61046927SAndroid Build Coastguard Worker bool lower_mul_2x32_64;
4115*61046927SAndroid Build Coastguard Worker
4116*61046927SAndroid Build Coastguard Worker /* Indicates that urol and uror are supported */
4117*61046927SAndroid Build Coastguard Worker bool has_rotate8;
4118*61046927SAndroid Build Coastguard Worker bool has_rotate16;
4119*61046927SAndroid Build Coastguard Worker bool has_rotate32;
4120*61046927SAndroid Build Coastguard Worker
4121*61046927SAndroid Build Coastguard Worker /** Backend supports shfr */
4122*61046927SAndroid Build Coastguard Worker bool has_shfr32;
4123*61046927SAndroid Build Coastguard Worker
4124*61046927SAndroid Build Coastguard Worker /** Backend supports ternary addition */
4125*61046927SAndroid Build Coastguard Worker bool has_iadd3;
4126*61046927SAndroid Build Coastguard Worker
4127*61046927SAndroid Build Coastguard Worker /**
4128*61046927SAndroid Build Coastguard Worker * Backend supports imul24, and would like to use it (when possible)
4129*61046927SAndroid Build Coastguard Worker * for address/offset calculation. If true, driver should call
4130*61046927SAndroid Build Coastguard Worker * nir_lower_amul(). (If not set, amul will automatically be lowered
4131*61046927SAndroid Build Coastguard Worker * to imul.)
4132*61046927SAndroid Build Coastguard Worker */
4133*61046927SAndroid Build Coastguard Worker bool has_imul24;
4134*61046927SAndroid Build Coastguard Worker
4135*61046927SAndroid Build Coastguard Worker /** Backend supports umul24, if not set umul24 will automatically be lowered
4136*61046927SAndroid Build Coastguard Worker * to imul with masked inputs */
4137*61046927SAndroid Build Coastguard Worker bool has_umul24;
4138*61046927SAndroid Build Coastguard Worker
4139*61046927SAndroid Build Coastguard Worker /** Backend supports 32-bit imad */
4140*61046927SAndroid Build Coastguard Worker bool has_imad32;
4141*61046927SAndroid Build Coastguard Worker
4142*61046927SAndroid Build Coastguard Worker /** Backend supports umad24, if not set umad24 will automatically be lowered
4143*61046927SAndroid Build Coastguard Worker * to imul with masked inputs and iadd */
4144*61046927SAndroid Build Coastguard Worker bool has_umad24;
4145*61046927SAndroid Build Coastguard Worker
4146*61046927SAndroid Build Coastguard Worker /* Backend supports fused comapre against zero and csel */
4147*61046927SAndroid Build Coastguard Worker bool has_fused_comp_and_csel;
4148*61046927SAndroid Build Coastguard Worker
4149*61046927SAndroid Build Coastguard Worker /* Backend supports fneo, fequ, fltu, fgeu. */
4150*61046927SAndroid Build Coastguard Worker bool has_fneo_fcmpu;
4151*61046927SAndroid Build Coastguard Worker
4152*61046927SAndroid Build Coastguard Worker /* Backend supports ford and funord. */
4153*61046927SAndroid Build Coastguard Worker bool has_ford_funord;
4154*61046927SAndroid Build Coastguard Worker
4155*61046927SAndroid Build Coastguard Worker /** Backend supports fsub, if not set fsub will automatically be lowered to
4156*61046927SAndroid Build Coastguard Worker * fadd(x, fneg(y)). If true, driver should call nir_opt_algebraic_late(). */
4157*61046927SAndroid Build Coastguard Worker bool has_fsub;
4158*61046927SAndroid Build Coastguard Worker
4159*61046927SAndroid Build Coastguard Worker /** Backend supports isub, if not set isub will automatically be lowered to
4160*61046927SAndroid Build Coastguard Worker * iadd(x, ineg(y)). If true, driver should call nir_opt_algebraic_late(). */
4161*61046927SAndroid Build Coastguard Worker bool has_isub;
4162*61046927SAndroid Build Coastguard Worker
4163*61046927SAndroid Build Coastguard Worker /** Backend supports pack_32_4x8 or pack_32_4x8_split. */
4164*61046927SAndroid Build Coastguard Worker bool has_pack_32_4x8;
4165*61046927SAndroid Build Coastguard Worker
4166*61046927SAndroid Build Coastguard Worker /** Backend supports nir_load_texture_scale and prefers it over txs for nir
4167*61046927SAndroid Build Coastguard Worker * lowerings. */
4168*61046927SAndroid Build Coastguard Worker bool has_texture_scaling;
4169*61046927SAndroid Build Coastguard Worker
4170*61046927SAndroid Build Coastguard Worker /** Backend supports sdot_4x8_iadd. */
4171*61046927SAndroid Build Coastguard Worker bool has_sdot_4x8;
4172*61046927SAndroid Build Coastguard Worker
4173*61046927SAndroid Build Coastguard Worker /** Backend supports udot_4x8_uadd. */
4174*61046927SAndroid Build Coastguard Worker bool has_udot_4x8;
4175*61046927SAndroid Build Coastguard Worker
4176*61046927SAndroid Build Coastguard Worker /** Backend supports sudot_4x8_iadd. */
4177*61046927SAndroid Build Coastguard Worker bool has_sudot_4x8;
4178*61046927SAndroid Build Coastguard Worker
4179*61046927SAndroid Build Coastguard Worker /** Backend supports sdot_4x8_iadd_sat. */
4180*61046927SAndroid Build Coastguard Worker bool has_sdot_4x8_sat;
4181*61046927SAndroid Build Coastguard Worker
4182*61046927SAndroid Build Coastguard Worker /** Backend supports udot_4x8_uadd_sat. */
4183*61046927SAndroid Build Coastguard Worker bool has_udot_4x8_sat;
4184*61046927SAndroid Build Coastguard Worker
4185*61046927SAndroid Build Coastguard Worker /** Backend supports sudot_4x8_iadd_sat. */
4186*61046927SAndroid Build Coastguard Worker bool has_sudot_4x8_sat;
4187*61046927SAndroid Build Coastguard Worker
4188*61046927SAndroid Build Coastguard Worker /** Backend supports sdot_2x16 and udot_2x16 opcodes. */
4189*61046927SAndroid Build Coastguard Worker bool has_dot_2x16;
4190*61046927SAndroid Build Coastguard Worker
4191*61046927SAndroid Build Coastguard Worker /** Backend supports fmulz (and ffmaz if lower_ffma32=false) */
4192*61046927SAndroid Build Coastguard Worker bool has_fmulz;
4193*61046927SAndroid Build Coastguard Worker
4194*61046927SAndroid Build Coastguard Worker /**
4195*61046927SAndroid Build Coastguard Worker * Backend supports fmulz (and ffmaz if lower_ffma32=false) but only if
4196*61046927SAndroid Build Coastguard Worker * FLOAT_CONTROLS_DENORM_PRESERVE_FP32 is not set
4197*61046927SAndroid Build Coastguard Worker */
4198*61046927SAndroid Build Coastguard Worker bool has_fmulz_no_denorms;
4199*61046927SAndroid Build Coastguard Worker
4200*61046927SAndroid Build Coastguard Worker /** Backend supports 32bit ufind_msb_rev and ifind_msb_rev. */
4201*61046927SAndroid Build Coastguard Worker bool has_find_msb_rev;
4202*61046927SAndroid Build Coastguard Worker
4203*61046927SAndroid Build Coastguard Worker /** Backend supports pack_half_2x16_rtz_split. */
4204*61046927SAndroid Build Coastguard Worker bool has_pack_half_2x16_rtz;
4205*61046927SAndroid Build Coastguard Worker
4206*61046927SAndroid Build Coastguard Worker /** Backend supports bitz/bitnz. */
4207*61046927SAndroid Build Coastguard Worker bool has_bit_test;
4208*61046927SAndroid Build Coastguard Worker
4209*61046927SAndroid Build Coastguard Worker /** Backend supports ubfe/ibfe. */
4210*61046927SAndroid Build Coastguard Worker bool has_bfe;
4211*61046927SAndroid Build Coastguard Worker
4212*61046927SAndroid Build Coastguard Worker /** Backend supports bfm. */
4213*61046927SAndroid Build Coastguard Worker bool has_bfm;
4214*61046927SAndroid Build Coastguard Worker
4215*61046927SAndroid Build Coastguard Worker /** Backend supports bfi. */
4216*61046927SAndroid Build Coastguard Worker bool has_bfi;
4217*61046927SAndroid Build Coastguard Worker
4218*61046927SAndroid Build Coastguard Worker /** Backend supports bitfield_select. */
4219*61046927SAndroid Build Coastguard Worker bool has_bitfield_select;
4220*61046927SAndroid Build Coastguard Worker
4221*61046927SAndroid Build Coastguard Worker /** Backend supports uclz. */
4222*61046927SAndroid Build Coastguard Worker bool has_uclz;
4223*61046927SAndroid Build Coastguard Worker
4224*61046927SAndroid Build Coastguard Worker /** Backend support msad_u4x8. */
4225*61046927SAndroid Build Coastguard Worker bool has_msad;
4226*61046927SAndroid Build Coastguard Worker
4227*61046927SAndroid Build Coastguard Worker /**
4228*61046927SAndroid Build Coastguard Worker * Is this the Intel vec4 backend?
4229*61046927SAndroid Build Coastguard Worker *
4230*61046927SAndroid Build Coastguard Worker * Used to inhibit algebraic optimizations that are known to be harmful on
4231*61046927SAndroid Build Coastguard Worker * the Intel vec4 backend. This is generally applicable to any
4232*61046927SAndroid Build Coastguard Worker * optimization that might cause more immediate values to be used in
4233*61046927SAndroid Build Coastguard Worker * 3-source (e.g., ffma and flrp) instructions.
4234*61046927SAndroid Build Coastguard Worker */
4235*61046927SAndroid Build Coastguard Worker bool intel_vec4;
4236*61046927SAndroid Build Coastguard Worker
4237*61046927SAndroid Build Coastguard Worker /**
4238*61046927SAndroid Build Coastguard Worker * For most Intel GPUs, all ternary operations such as FMA and BFE cannot
4239*61046927SAndroid Build Coastguard Worker * have immediates, so two to three instructions may eventually be needed.
4240*61046927SAndroid Build Coastguard Worker */
4241*61046927SAndroid Build Coastguard Worker bool avoid_ternary_with_two_constants;
4242*61046927SAndroid Build Coastguard Worker
4243*61046927SAndroid Build Coastguard Worker /** Whether 8-bit ALU is supported. */
4244*61046927SAndroid Build Coastguard Worker bool support_8bit_alu;
4245*61046927SAndroid Build Coastguard Worker
4246*61046927SAndroid Build Coastguard Worker /** Whether 16-bit ALU is supported. */
4247*61046927SAndroid Build Coastguard Worker bool support_16bit_alu;
4248*61046927SAndroid Build Coastguard Worker
4249*61046927SAndroid Build Coastguard Worker unsigned max_unroll_iterations;
4250*61046927SAndroid Build Coastguard Worker unsigned max_unroll_iterations_aggressive;
4251*61046927SAndroid Build Coastguard Worker unsigned max_unroll_iterations_fp64;
4252*61046927SAndroid Build Coastguard Worker
4253*61046927SAndroid Build Coastguard Worker bool lower_uniforms_to_ubo;
4254*61046927SAndroid Build Coastguard Worker
4255*61046927SAndroid Build Coastguard Worker /* If the precision is ignored, backends that don't handle
4256*61046927SAndroid Build Coastguard Worker * different precisions when passing data between stages and use
4257*61046927SAndroid Build Coastguard Worker * vectorized IO can pack more varyings when linking. */
4258*61046927SAndroid Build Coastguard Worker bool linker_ignore_precision;
4259*61046927SAndroid Build Coastguard Worker
4260*61046927SAndroid Build Coastguard Worker /* Specifies if indirect sampler array access will trigger forced loop
4261*61046927SAndroid Build Coastguard Worker * unrolling.
4262*61046927SAndroid Build Coastguard Worker */
4263*61046927SAndroid Build Coastguard Worker bool force_indirect_unrolling_sampler;
4264*61046927SAndroid Build Coastguard Worker
4265*61046927SAndroid Build Coastguard Worker /* Some older drivers don't support GLSL versions with the concept of flat
4266*61046927SAndroid Build Coastguard Worker * varyings and also don't support integers. This setting helps us avoid
4267*61046927SAndroid Build Coastguard Worker * marking varyings as flat and potentially having them changed to ints via
4268*61046927SAndroid Build Coastguard Worker * varying packing.
4269*61046927SAndroid Build Coastguard Worker */
4270*61046927SAndroid Build Coastguard Worker bool no_integers;
4271*61046927SAndroid Build Coastguard Worker
4272*61046927SAndroid Build Coastguard Worker /**
4273*61046927SAndroid Build Coastguard Worker * Specifies which type of indirectly accessed variables should force
4274*61046927SAndroid Build Coastguard Worker * loop unrolling.
4275*61046927SAndroid Build Coastguard Worker */
4276*61046927SAndroid Build Coastguard Worker nir_variable_mode force_indirect_unrolling;
4277*61046927SAndroid Build Coastguard Worker
4278*61046927SAndroid Build Coastguard Worker bool driver_functions;
4279*61046927SAndroid Build Coastguard Worker
4280*61046927SAndroid Build Coastguard Worker nir_lower_int64_options lower_int64_options;
4281*61046927SAndroid Build Coastguard Worker nir_lower_doubles_options lower_doubles_options;
4282*61046927SAndroid Build Coastguard Worker nir_divergence_options divergence_analysis_options;
4283*61046927SAndroid Build Coastguard Worker
4284*61046927SAndroid Build Coastguard Worker /**
4285*61046927SAndroid Build Coastguard Worker * The masks of shader stages that support indirect indexing with
4286*61046927SAndroid Build Coastguard Worker * load_input and store_output intrinsics. It's used by
4287*61046927SAndroid Build Coastguard Worker * nir_lower_io_passes.
4288*61046927SAndroid Build Coastguard Worker */
4289*61046927SAndroid Build Coastguard Worker uint8_t support_indirect_inputs;
4290*61046927SAndroid Build Coastguard Worker uint8_t support_indirect_outputs;
4291*61046927SAndroid Build Coastguard Worker
4292*61046927SAndroid Build Coastguard Worker /**
4293*61046927SAndroid Build Coastguard Worker * Remove varying loaded from uniform, let fragment shader load the
4294*61046927SAndroid Build Coastguard Worker * uniform directly. GPU passing varying by memory can benifit from it
4295*61046927SAndroid Build Coastguard Worker * for sure; but GPU passing varying by on chip resource may not.
4296*61046927SAndroid Build Coastguard Worker * Because it saves on chip resource but may increase memory pressure when
4297*61046927SAndroid Build Coastguard Worker * fragment task is far more than vertex one, so better left it disabled.
4298*61046927SAndroid Build Coastguard Worker */
4299*61046927SAndroid Build Coastguard Worker bool lower_varying_from_uniform;
4300*61046927SAndroid Build Coastguard Worker
4301*61046927SAndroid Build Coastguard Worker /** store the variable offset into the instrinsic range_base instead
4302*61046927SAndroid Build Coastguard Worker * of adding it to the image index.
4303*61046927SAndroid Build Coastguard Worker */
4304*61046927SAndroid Build Coastguard Worker bool lower_image_offset_to_range_base;
4305*61046927SAndroid Build Coastguard Worker
4306*61046927SAndroid Build Coastguard Worker /** store the variable offset into the instrinsic range_base instead
4307*61046927SAndroid Build Coastguard Worker * of adding it to the atomic source
4308*61046927SAndroid Build Coastguard Worker */
4309*61046927SAndroid Build Coastguard Worker bool lower_atomic_offset_to_range_base;
4310*61046927SAndroid Build Coastguard Worker
4311*61046927SAndroid Build Coastguard Worker /** Don't convert medium-precision casts (e.g. f2fmp) into concrete
4312*61046927SAndroid Build Coastguard Worker * type casts (e.g. f2f16).
4313*61046927SAndroid Build Coastguard Worker */
4314*61046927SAndroid Build Coastguard Worker bool preserve_mediump;
4315*61046927SAndroid Build Coastguard Worker
4316*61046927SAndroid Build Coastguard Worker /** lowers fquantize2f16 to alu ops. */
4317*61046927SAndroid Build Coastguard Worker bool lower_fquantize2f16;
4318*61046927SAndroid Build Coastguard Worker
4319*61046927SAndroid Build Coastguard Worker /** Lower f2f16 to f2f16_rtz when execution mode is not rtne. */
4320*61046927SAndroid Build Coastguard Worker bool force_f2f16_rtz;
4321*61046927SAndroid Build Coastguard Worker
4322*61046927SAndroid Build Coastguard Worker /** Lower VARYING_SLOT_LAYER in FS to SYSTEM_VALUE_LAYER_ID. */
4323*61046927SAndroid Build Coastguard Worker bool lower_layer_fs_input_to_sysval;
4324*61046927SAndroid Build Coastguard Worker
4325*61046927SAndroid Build Coastguard Worker /** clip/cull distance and tess level arrays use compact semantics */
4326*61046927SAndroid Build Coastguard Worker bool compact_arrays;
4327*61046927SAndroid Build Coastguard Worker
4328*61046927SAndroid Build Coastguard Worker /**
4329*61046927SAndroid Build Coastguard Worker * Whether discard gets emitted as nir_intrinsic_demote.
4330*61046927SAndroid Build Coastguard Worker * Otherwise, nir_intrinsic_terminate is being used.
4331*61046927SAndroid Build Coastguard Worker */
4332*61046927SAndroid Build Coastguard Worker bool discard_is_demote;
4333*61046927SAndroid Build Coastguard Worker
4334*61046927SAndroid Build Coastguard Worker /**
4335*61046927SAndroid Build Coastguard Worker * Whether the new-style derivative intrinsics are supported. If false,
4336*61046927SAndroid Build Coastguard Worker * legacy ALU derivative ops will be emitted. This transitional option will
4337*61046927SAndroid Build Coastguard Worker * be removed once all drivers are converted to derivative intrinsics.
4338*61046927SAndroid Build Coastguard Worker */
4339*61046927SAndroid Build Coastguard Worker bool has_ddx_intrinsics;
4340*61046927SAndroid Build Coastguard Worker
4341*61046927SAndroid Build Coastguard Worker /** Whether derivative intrinsics must be scalarized. */
4342*61046927SAndroid Build Coastguard Worker bool scalarize_ddx;
4343*61046927SAndroid Build Coastguard Worker
4344*61046927SAndroid Build Coastguard Worker /** Options determining lowering and behavior of inputs and outputs. */
4345*61046927SAndroid Build Coastguard Worker nir_io_options io_options;
4346*61046927SAndroid Build Coastguard Worker
4347*61046927SAndroid Build Coastguard Worker /**
4348*61046927SAndroid Build Coastguard Worker * Bit mask of nir_lower_packing_op to skip lowering some nir ops in
4349*61046927SAndroid Build Coastguard Worker * nir_lower_packing().
4350*61046927SAndroid Build Coastguard Worker */
4351*61046927SAndroid Build Coastguard Worker unsigned skip_lower_packing_ops;
4352*61046927SAndroid Build Coastguard Worker
4353*61046927SAndroid Build Coastguard Worker /** Driver callback where drivers can define how to lower mediump.
4354*61046927SAndroid Build Coastguard Worker * Used by nir_lower_io_passes.
4355*61046927SAndroid Build Coastguard Worker */
4356*61046927SAndroid Build Coastguard Worker void (*lower_mediump_io)(struct nir_shader *nir);
4357*61046927SAndroid Build Coastguard Worker
4358*61046927SAndroid Build Coastguard Worker /**
4359*61046927SAndroid Build Coastguard Worker * Return the maximum cost of an expression that's written to a shader
4360*61046927SAndroid Build Coastguard Worker * output that can be moved into the next shader to remove that output.
4361*61046927SAndroid Build Coastguard Worker *
4362*61046927SAndroid Build Coastguard Worker * Currently only uniform expressions are moved. A uniform expression is
4363*61046927SAndroid Build Coastguard Worker * any ALU expression sourcing only constants, uniforms, and UBO loads.
4364*61046927SAndroid Build Coastguard Worker *
4365*61046927SAndroid Build Coastguard Worker * Set to NULL or return 0 if you only want to propagate constants from
4366*61046927SAndroid Build Coastguard Worker * outputs to inputs.
4367*61046927SAndroid Build Coastguard Worker *
4368*61046927SAndroid Build Coastguard Worker * Drivers can set the maximum cost based on the types of consecutive
4369*61046927SAndroid Build Coastguard Worker * shaders or shader SHA1s.
4370*61046927SAndroid Build Coastguard Worker *
4371*61046927SAndroid Build Coastguard Worker * Drivers should also set "varying_estimate_instr_cost".
4372*61046927SAndroid Build Coastguard Worker */
4373*61046927SAndroid Build Coastguard Worker unsigned (*varying_expression_max_cost)(struct nir_shader *consumer,
4374*61046927SAndroid Build Coastguard Worker struct nir_shader *producer);
4375*61046927SAndroid Build Coastguard Worker
4376*61046927SAndroid Build Coastguard Worker /**
4377*61046927SAndroid Build Coastguard Worker * Return the cost of an instruction that could be moved into the next
4378*61046927SAndroid Build Coastguard Worker * shader. If the cost of all instructions in an expression is <=
4379*61046927SAndroid Build Coastguard Worker * varying_expression_max_cost(), the instruction is moved.
4380*61046927SAndroid Build Coastguard Worker */
4381*61046927SAndroid Build Coastguard Worker unsigned (*varying_estimate_instr_cost)(struct nir_instr *instr);
4382*61046927SAndroid Build Coastguard Worker } nir_shader_compiler_options;
4383*61046927SAndroid Build Coastguard Worker
4384*61046927SAndroid Build Coastguard Worker typedef struct nir_shader {
4385*61046927SAndroid Build Coastguard Worker gc_ctx *gctx;
4386*61046927SAndroid Build Coastguard Worker
4387*61046927SAndroid Build Coastguard Worker /** list of uniforms (nir_variable) */
4388*61046927SAndroid Build Coastguard Worker struct exec_list variables;
4389*61046927SAndroid Build Coastguard Worker
4390*61046927SAndroid Build Coastguard Worker /** Set of driver-specific options for the shader.
4391*61046927SAndroid Build Coastguard Worker *
4392*61046927SAndroid Build Coastguard Worker * The memory for the options is expected to be kept in a single static
4393*61046927SAndroid Build Coastguard Worker * copy by the driver.
4394*61046927SAndroid Build Coastguard Worker */
4395*61046927SAndroid Build Coastguard Worker const struct nir_shader_compiler_options *options;
4396*61046927SAndroid Build Coastguard Worker
4397*61046927SAndroid Build Coastguard Worker /** Various bits of compile-time information about a given shader */
4398*61046927SAndroid Build Coastguard Worker struct shader_info info;
4399*61046927SAndroid Build Coastguard Worker
4400*61046927SAndroid Build Coastguard Worker /** list of nir_function */
4401*61046927SAndroid Build Coastguard Worker struct exec_list functions;
4402*61046927SAndroid Build Coastguard Worker
4403*61046927SAndroid Build Coastguard Worker /**
4404*61046927SAndroid Build Coastguard Worker * The size of the variable space for load_input_*, load_uniform_*, etc.
4405*61046927SAndroid Build Coastguard Worker * intrinsics. This is in back-end specific units which is likely one of
4406*61046927SAndroid Build Coastguard Worker * bytes, dwords, or vec4s depending on context and back-end.
4407*61046927SAndroid Build Coastguard Worker */
4408*61046927SAndroid Build Coastguard Worker unsigned num_inputs, num_uniforms, num_outputs;
4409*61046927SAndroid Build Coastguard Worker
4410*61046927SAndroid Build Coastguard Worker /** Size in bytes of required implicitly bound global memory */
4411*61046927SAndroid Build Coastguard Worker unsigned global_mem_size;
4412*61046927SAndroid Build Coastguard Worker
4413*61046927SAndroid Build Coastguard Worker /** Size in bytes of required scratch space */
4414*61046927SAndroid Build Coastguard Worker unsigned scratch_size;
4415*61046927SAndroid Build Coastguard Worker
4416*61046927SAndroid Build Coastguard Worker /** Constant data associated with this shader.
4417*61046927SAndroid Build Coastguard Worker *
4418*61046927SAndroid Build Coastguard Worker * Constant data is loaded through load_constant intrinsics (as compared to
4419*61046927SAndroid Build Coastguard Worker * the NIR load_const instructions which have the constant value inlined
4420*61046927SAndroid Build Coastguard Worker * into them). This is usually generated by nir_opt_large_constants (so
4421*61046927SAndroid Build Coastguard Worker * shaders don't have to load_const into a temporary array when they want
4422*61046927SAndroid Build Coastguard Worker * to indirect on a const array).
4423*61046927SAndroid Build Coastguard Worker */
4424*61046927SAndroid Build Coastguard Worker void *constant_data;
4425*61046927SAndroid Build Coastguard Worker /** Size of the constant data associated with the shader, in bytes */
4426*61046927SAndroid Build Coastguard Worker unsigned constant_data_size;
4427*61046927SAndroid Build Coastguard Worker
4428*61046927SAndroid Build Coastguard Worker struct nir_xfb_info *xfb_info;
4429*61046927SAndroid Build Coastguard Worker
4430*61046927SAndroid Build Coastguard Worker unsigned printf_info_count;
4431*61046927SAndroid Build Coastguard Worker u_printf_info *printf_info;
4432*61046927SAndroid Build Coastguard Worker } nir_shader;
4433*61046927SAndroid Build Coastguard Worker
4434*61046927SAndroid Build Coastguard Worker #define nir_foreach_function(func, shader) \
4435*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_function, func, node, &(shader)->functions)
4436*61046927SAndroid Build Coastguard Worker
4437*61046927SAndroid Build Coastguard Worker #define nir_foreach_function_safe(func, shader) \
4438*61046927SAndroid Build Coastguard Worker foreach_list_typed_safe(nir_function, func, node, &(shader)->functions)
4439*61046927SAndroid Build Coastguard Worker
4440*61046927SAndroid Build Coastguard Worker static inline nir_function *
nir_foreach_function_with_impl_first(const nir_shader * shader)4441*61046927SAndroid Build Coastguard Worker nir_foreach_function_with_impl_first(const nir_shader *shader)
4442*61046927SAndroid Build Coastguard Worker {
4443*61046927SAndroid Build Coastguard Worker foreach_list_typed(nir_function, func, node, &shader->functions) {
4444*61046927SAndroid Build Coastguard Worker if (func->impl != NULL)
4445*61046927SAndroid Build Coastguard Worker return func;
4446*61046927SAndroid Build Coastguard Worker }
4447*61046927SAndroid Build Coastguard Worker
4448*61046927SAndroid Build Coastguard Worker return NULL;
4449*61046927SAndroid Build Coastguard Worker }
4450*61046927SAndroid Build Coastguard Worker
4451*61046927SAndroid Build Coastguard Worker static inline nir_function_impl *
nir_foreach_function_with_impl_next(nir_function ** it)4452*61046927SAndroid Build Coastguard Worker nir_foreach_function_with_impl_next(nir_function **it)
4453*61046927SAndroid Build Coastguard Worker {
4454*61046927SAndroid Build Coastguard Worker foreach_list_typed_from(nir_function, func, node, _, (*it)->node.next) {
4455*61046927SAndroid Build Coastguard Worker if (func->impl != NULL) {
4456*61046927SAndroid Build Coastguard Worker *it = func;
4457*61046927SAndroid Build Coastguard Worker return func->impl;
4458*61046927SAndroid Build Coastguard Worker }
4459*61046927SAndroid Build Coastguard Worker }
4460*61046927SAndroid Build Coastguard Worker
4461*61046927SAndroid Build Coastguard Worker return NULL;
4462*61046927SAndroid Build Coastguard Worker }
4463*61046927SAndroid Build Coastguard Worker
4464*61046927SAndroid Build Coastguard Worker #define nir_foreach_function_with_impl(it, impl_it, shader) \
4465*61046927SAndroid Build Coastguard Worker for (nir_function *it = nir_foreach_function_with_impl_first(shader); \
4466*61046927SAndroid Build Coastguard Worker it != NULL; \
4467*61046927SAndroid Build Coastguard Worker it = NULL) \
4468*61046927SAndroid Build Coastguard Worker \
4469*61046927SAndroid Build Coastguard Worker for (nir_function_impl *impl_it = it->impl; \
4470*61046927SAndroid Build Coastguard Worker impl_it != NULL; \
4471*61046927SAndroid Build Coastguard Worker impl_it = nir_foreach_function_with_impl_next(&it))
4472*61046927SAndroid Build Coastguard Worker
4473*61046927SAndroid Build Coastguard Worker /* Equivalent to
4474*61046927SAndroid Build Coastguard Worker *
4475*61046927SAndroid Build Coastguard Worker * nir_foreach_function(func, shader) {
4476*61046927SAndroid Build Coastguard Worker * if (func->impl != NULL) {
4477*61046927SAndroid Build Coastguard Worker * ...
4478*61046927SAndroid Build Coastguard Worker * }
4479*61046927SAndroid Build Coastguard Worker * }
4480*61046927SAndroid Build Coastguard Worker *
4481*61046927SAndroid Build Coastguard Worker * Carefully written to ensure break/continue work in the user code.
4482*61046927SAndroid Build Coastguard Worker */
4483*61046927SAndroid Build Coastguard Worker
4484*61046927SAndroid Build Coastguard Worker #define nir_foreach_function_impl(it, shader) \
4485*61046927SAndroid Build Coastguard Worker nir_foreach_function_with_impl(_func_##it, it, shader)
4486*61046927SAndroid Build Coastguard Worker
4487*61046927SAndroid Build Coastguard Worker static inline nir_function_impl *
nir_shader_get_entrypoint(const nir_shader * shader)4488*61046927SAndroid Build Coastguard Worker nir_shader_get_entrypoint(const nir_shader *shader)
4489*61046927SAndroid Build Coastguard Worker {
4490*61046927SAndroid Build Coastguard Worker nir_function *func = NULL;
4491*61046927SAndroid Build Coastguard Worker
4492*61046927SAndroid Build Coastguard Worker nir_foreach_function(function, shader) {
4493*61046927SAndroid Build Coastguard Worker assert(func == NULL);
4494*61046927SAndroid Build Coastguard Worker if (function->is_entrypoint) {
4495*61046927SAndroid Build Coastguard Worker func = function;
4496*61046927SAndroid Build Coastguard Worker #ifndef NDEBUG
4497*61046927SAndroid Build Coastguard Worker break;
4498*61046927SAndroid Build Coastguard Worker #endif
4499*61046927SAndroid Build Coastguard Worker }
4500*61046927SAndroid Build Coastguard Worker }
4501*61046927SAndroid Build Coastguard Worker
4502*61046927SAndroid Build Coastguard Worker if (!func)
4503*61046927SAndroid Build Coastguard Worker return NULL;
4504*61046927SAndroid Build Coastguard Worker
4505*61046927SAndroid Build Coastguard Worker assert(func->num_params == 0);
4506*61046927SAndroid Build Coastguard Worker assert(func->impl);
4507*61046927SAndroid Build Coastguard Worker return func->impl;
4508*61046927SAndroid Build Coastguard Worker }
4509*61046927SAndroid Build Coastguard Worker
4510*61046927SAndroid Build Coastguard Worker static inline nir_function *
nir_shader_get_function_for_name(const nir_shader * shader,const char * name)4511*61046927SAndroid Build Coastguard Worker nir_shader_get_function_for_name(const nir_shader *shader, const char *name)
4512*61046927SAndroid Build Coastguard Worker {
4513*61046927SAndroid Build Coastguard Worker nir_foreach_function(func, shader) {
4514*61046927SAndroid Build Coastguard Worker if (func->name && strcmp(func->name, name) == 0)
4515*61046927SAndroid Build Coastguard Worker return func;
4516*61046927SAndroid Build Coastguard Worker }
4517*61046927SAndroid Build Coastguard Worker
4518*61046927SAndroid Build Coastguard Worker return NULL;
4519*61046927SAndroid Build Coastguard Worker }
4520*61046927SAndroid Build Coastguard Worker
4521*61046927SAndroid Build Coastguard Worker /*
4522*61046927SAndroid Build Coastguard Worker * After all functions are forcibly inlined, these passes remove redundant
4523*61046927SAndroid Build Coastguard Worker * functions from a shader and library respectively.
4524*61046927SAndroid Build Coastguard Worker */
4525*61046927SAndroid Build Coastguard Worker void nir_remove_non_entrypoints(nir_shader *shader);
4526*61046927SAndroid Build Coastguard Worker void nir_remove_non_exported(nir_shader *shader);
4527*61046927SAndroid Build Coastguard Worker
4528*61046927SAndroid Build Coastguard Worker nir_shader *nir_shader_create(void *mem_ctx,
4529*61046927SAndroid Build Coastguard Worker gl_shader_stage stage,
4530*61046927SAndroid Build Coastguard Worker const nir_shader_compiler_options *options,
4531*61046927SAndroid Build Coastguard Worker shader_info *si);
4532*61046927SAndroid Build Coastguard Worker
4533*61046927SAndroid Build Coastguard Worker /** Adds a variable to the appropriate list in nir_shader */
4534*61046927SAndroid Build Coastguard Worker void nir_shader_add_variable(nir_shader *shader, nir_variable *var);
4535*61046927SAndroid Build Coastguard Worker
4536*61046927SAndroid Build Coastguard Worker static inline void
nir_function_impl_add_variable(nir_function_impl * impl,nir_variable * var)4537*61046927SAndroid Build Coastguard Worker nir_function_impl_add_variable(nir_function_impl *impl, nir_variable *var)
4538*61046927SAndroid Build Coastguard Worker {
4539*61046927SAndroid Build Coastguard Worker assert(var->data.mode == nir_var_function_temp);
4540*61046927SAndroid Build Coastguard Worker exec_list_push_tail(&impl->locals, &var->node);
4541*61046927SAndroid Build Coastguard Worker }
4542*61046927SAndroid Build Coastguard Worker
4543*61046927SAndroid Build Coastguard Worker /** creates a variable, sets a few defaults, and adds it to the list */
4544*61046927SAndroid Build Coastguard Worker nir_variable *nir_variable_create(nir_shader *shader,
4545*61046927SAndroid Build Coastguard Worker nir_variable_mode mode,
4546*61046927SAndroid Build Coastguard Worker const struct glsl_type *type,
4547*61046927SAndroid Build Coastguard Worker const char *name);
4548*61046927SAndroid Build Coastguard Worker /** creates a local variable and adds it to the list */
4549*61046927SAndroid Build Coastguard Worker nir_variable *nir_local_variable_create(nir_function_impl *impl,
4550*61046927SAndroid Build Coastguard Worker const struct glsl_type *type,
4551*61046927SAndroid Build Coastguard Worker const char *name);
4552*61046927SAndroid Build Coastguard Worker
4553*61046927SAndroid Build Coastguard Worker /** Creates a uniform builtin state variable. */
4554*61046927SAndroid Build Coastguard Worker nir_variable *
4555*61046927SAndroid Build Coastguard Worker nir_state_variable_create(nir_shader *shader,
4556*61046927SAndroid Build Coastguard Worker const struct glsl_type *type,
4557*61046927SAndroid Build Coastguard Worker const char *name,
4558*61046927SAndroid Build Coastguard Worker const gl_state_index16 tokens[STATE_LENGTH]);
4559*61046927SAndroid Build Coastguard Worker
4560*61046927SAndroid Build Coastguard Worker /* Gets the variable for the given mode and location, creating it (with the given
4561*61046927SAndroid Build Coastguard Worker * type) if necessary.
4562*61046927SAndroid Build Coastguard Worker */
4563*61046927SAndroid Build Coastguard Worker nir_variable *
4564*61046927SAndroid Build Coastguard Worker nir_get_variable_with_location(nir_shader *shader, nir_variable_mode mode, int location,
4565*61046927SAndroid Build Coastguard Worker const struct glsl_type *type);
4566*61046927SAndroid Build Coastguard Worker
4567*61046927SAndroid Build Coastguard Worker /* Creates a variable for the given mode and location.
4568*61046927SAndroid Build Coastguard Worker */
4569*61046927SAndroid Build Coastguard Worker nir_variable *
4570*61046927SAndroid Build Coastguard Worker nir_create_variable_with_location(nir_shader *shader, nir_variable_mode mode, int location,
4571*61046927SAndroid Build Coastguard Worker const struct glsl_type *type);
4572*61046927SAndroid Build Coastguard Worker
4573*61046927SAndroid Build Coastguard Worker nir_variable *nir_find_variable_with_location(nir_shader *shader,
4574*61046927SAndroid Build Coastguard Worker nir_variable_mode mode,
4575*61046927SAndroid Build Coastguard Worker unsigned location);
4576*61046927SAndroid Build Coastguard Worker
4577*61046927SAndroid Build Coastguard Worker nir_variable *nir_find_variable_with_driver_location(nir_shader *shader,
4578*61046927SAndroid Build Coastguard Worker nir_variable_mode mode,
4579*61046927SAndroid Build Coastguard Worker unsigned location);
4580*61046927SAndroid Build Coastguard Worker
4581*61046927SAndroid Build Coastguard Worker nir_variable *nir_find_state_variable(nir_shader *s,
4582*61046927SAndroid Build Coastguard Worker gl_state_index16 tokens[STATE_LENGTH]);
4583*61046927SAndroid Build Coastguard Worker
4584*61046927SAndroid Build Coastguard Worker nir_variable *nir_find_sampler_variable_with_tex_index(nir_shader *shader,
4585*61046927SAndroid Build Coastguard Worker unsigned texture_index);
4586*61046927SAndroid Build Coastguard Worker
4587*61046927SAndroid Build Coastguard Worker void nir_sort_variables_with_modes(nir_shader *shader,
4588*61046927SAndroid Build Coastguard Worker int (*compar)(const nir_variable *,
4589*61046927SAndroid Build Coastguard Worker const nir_variable *),
4590*61046927SAndroid Build Coastguard Worker nir_variable_mode modes);
4591*61046927SAndroid Build Coastguard Worker
4592*61046927SAndroid Build Coastguard Worker /** creates a function and adds it to the shader's list of functions */
4593*61046927SAndroid Build Coastguard Worker nir_function *nir_function_create(nir_shader *shader, const char *name);
4594*61046927SAndroid Build Coastguard Worker
4595*61046927SAndroid Build Coastguard Worker static inline void
nir_function_set_impl(nir_function * func,nir_function_impl * impl)4596*61046927SAndroid Build Coastguard Worker nir_function_set_impl(nir_function *func, nir_function_impl *impl)
4597*61046927SAndroid Build Coastguard Worker {
4598*61046927SAndroid Build Coastguard Worker func->impl = impl;
4599*61046927SAndroid Build Coastguard Worker impl->function = func;
4600*61046927SAndroid Build Coastguard Worker }
4601*61046927SAndroid Build Coastguard Worker
4602*61046927SAndroid Build Coastguard Worker nir_function_impl *nir_function_impl_create(nir_function *func);
4603*61046927SAndroid Build Coastguard Worker /** creates a function_impl that isn't tied to any particular function */
4604*61046927SAndroid Build Coastguard Worker nir_function_impl *nir_function_impl_create_bare(nir_shader *shader);
4605*61046927SAndroid Build Coastguard Worker
4606*61046927SAndroid Build Coastguard Worker nir_block *nir_block_create(nir_shader *shader);
4607*61046927SAndroid Build Coastguard Worker nir_if *nir_if_create(nir_shader *shader);
4608*61046927SAndroid Build Coastguard Worker nir_loop *nir_loop_create(nir_shader *shader);
4609*61046927SAndroid Build Coastguard Worker
4610*61046927SAndroid Build Coastguard Worker nir_function_impl *nir_cf_node_get_function(nir_cf_node *node);
4611*61046927SAndroid Build Coastguard Worker
4612*61046927SAndroid Build Coastguard Worker /** requests that the given pieces of metadata be generated */
4613*61046927SAndroid Build Coastguard Worker void nir_metadata_require(nir_function_impl *impl, nir_metadata required, ...);
4614*61046927SAndroid Build Coastguard Worker /** dirties all but the preserved metadata */
4615*61046927SAndroid Build Coastguard Worker void nir_metadata_preserve(nir_function_impl *impl, nir_metadata preserved);
4616*61046927SAndroid Build Coastguard Worker /** Preserves all metadata for the given shader */
4617*61046927SAndroid Build Coastguard Worker void nir_shader_preserve_all_metadata(nir_shader *shader);
4618*61046927SAndroid Build Coastguard Worker
4619*61046927SAndroid Build Coastguard Worker /** creates an instruction with default swizzle/writemask/etc. with NULL registers */
4620*61046927SAndroid Build Coastguard Worker nir_alu_instr *nir_alu_instr_create(nir_shader *shader, nir_op op);
4621*61046927SAndroid Build Coastguard Worker
4622*61046927SAndroid Build Coastguard Worker nir_deref_instr *nir_deref_instr_create(nir_shader *shader,
4623*61046927SAndroid Build Coastguard Worker nir_deref_type deref_type);
4624*61046927SAndroid Build Coastguard Worker
4625*61046927SAndroid Build Coastguard Worker nir_jump_instr *nir_jump_instr_create(nir_shader *shader, nir_jump_type type);
4626*61046927SAndroid Build Coastguard Worker
4627*61046927SAndroid Build Coastguard Worker nir_load_const_instr *nir_load_const_instr_create(nir_shader *shader,
4628*61046927SAndroid Build Coastguard Worker unsigned num_components,
4629*61046927SAndroid Build Coastguard Worker unsigned bit_size);
4630*61046927SAndroid Build Coastguard Worker
4631*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *nir_intrinsic_instr_create(nir_shader *shader,
4632*61046927SAndroid Build Coastguard Worker nir_intrinsic_op op);
4633*61046927SAndroid Build Coastguard Worker
4634*61046927SAndroid Build Coastguard Worker nir_call_instr *nir_call_instr_create(nir_shader *shader,
4635*61046927SAndroid Build Coastguard Worker nir_function *callee);
4636*61046927SAndroid Build Coastguard Worker
4637*61046927SAndroid Build Coastguard Worker /** Creates a NIR texture instruction */
4638*61046927SAndroid Build Coastguard Worker nir_tex_instr *nir_tex_instr_create(nir_shader *shader, unsigned num_srcs);
4639*61046927SAndroid Build Coastguard Worker
4640*61046927SAndroid Build Coastguard Worker nir_phi_instr *nir_phi_instr_create(nir_shader *shader);
4641*61046927SAndroid Build Coastguard Worker nir_phi_src *nir_phi_instr_add_src(nir_phi_instr *instr,
4642*61046927SAndroid Build Coastguard Worker nir_block *pred, nir_def *src);
4643*61046927SAndroid Build Coastguard Worker
4644*61046927SAndroid Build Coastguard Worker nir_parallel_copy_instr *nir_parallel_copy_instr_create(nir_shader *shader);
4645*61046927SAndroid Build Coastguard Worker
4646*61046927SAndroid Build Coastguard Worker nir_debug_info_instr *nir_debug_info_instr_create(nir_shader *shader,
4647*61046927SAndroid Build Coastguard Worker nir_debug_info_type type,
4648*61046927SAndroid Build Coastguard Worker uint32_t string_length);
4649*61046927SAndroid Build Coastguard Worker
4650*61046927SAndroid Build Coastguard Worker nir_undef_instr *nir_undef_instr_create(nir_shader *shader,
4651*61046927SAndroid Build Coastguard Worker unsigned num_components,
4652*61046927SAndroid Build Coastguard Worker unsigned bit_size);
4653*61046927SAndroid Build Coastguard Worker
4654*61046927SAndroid Build Coastguard Worker nir_const_value nir_alu_binop_identity(nir_op binop, unsigned bit_size);
4655*61046927SAndroid Build Coastguard Worker
4656*61046927SAndroid Build Coastguard Worker /**
4657*61046927SAndroid Build Coastguard Worker * NIR Cursors and Instruction Insertion API
4658*61046927SAndroid Build Coastguard Worker * @{
4659*61046927SAndroid Build Coastguard Worker *
4660*61046927SAndroid Build Coastguard Worker * A tiny struct representing a point to insert/extract instructions or
4661*61046927SAndroid Build Coastguard Worker * control flow nodes. Helps reduce the combinatorial explosion of possible
4662*61046927SAndroid Build Coastguard Worker * points to insert/extract.
4663*61046927SAndroid Build Coastguard Worker *
4664*61046927SAndroid Build Coastguard Worker * \sa nir_control_flow.h
4665*61046927SAndroid Build Coastguard Worker */
4666*61046927SAndroid Build Coastguard Worker typedef enum {
4667*61046927SAndroid Build Coastguard Worker nir_cursor_before_block,
4668*61046927SAndroid Build Coastguard Worker nir_cursor_after_block,
4669*61046927SAndroid Build Coastguard Worker nir_cursor_before_instr,
4670*61046927SAndroid Build Coastguard Worker nir_cursor_after_instr,
4671*61046927SAndroid Build Coastguard Worker } nir_cursor_option;
4672*61046927SAndroid Build Coastguard Worker
4673*61046927SAndroid Build Coastguard Worker typedef struct {
4674*61046927SAndroid Build Coastguard Worker nir_cursor_option option;
4675*61046927SAndroid Build Coastguard Worker union {
4676*61046927SAndroid Build Coastguard Worker nir_block *block;
4677*61046927SAndroid Build Coastguard Worker nir_instr *instr;
4678*61046927SAndroid Build Coastguard Worker };
4679*61046927SAndroid Build Coastguard Worker } nir_cursor;
4680*61046927SAndroid Build Coastguard Worker
4681*61046927SAndroid Build Coastguard Worker static inline nir_block *
nir_cursor_current_block(nir_cursor cursor)4682*61046927SAndroid Build Coastguard Worker nir_cursor_current_block(nir_cursor cursor)
4683*61046927SAndroid Build Coastguard Worker {
4684*61046927SAndroid Build Coastguard Worker if (cursor.option == nir_cursor_before_instr ||
4685*61046927SAndroid Build Coastguard Worker cursor.option == nir_cursor_after_instr) {
4686*61046927SAndroid Build Coastguard Worker return cursor.instr->block;
4687*61046927SAndroid Build Coastguard Worker } else {
4688*61046927SAndroid Build Coastguard Worker return cursor.block;
4689*61046927SAndroid Build Coastguard Worker }
4690*61046927SAndroid Build Coastguard Worker }
4691*61046927SAndroid Build Coastguard Worker
4692*61046927SAndroid Build Coastguard Worker bool nir_cursors_equal(nir_cursor a, nir_cursor b);
4693*61046927SAndroid Build Coastguard Worker
4694*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_block(nir_block * block)4695*61046927SAndroid Build Coastguard Worker nir_before_block(nir_block *block)
4696*61046927SAndroid Build Coastguard Worker {
4697*61046927SAndroid Build Coastguard Worker nir_cursor cursor;
4698*61046927SAndroid Build Coastguard Worker cursor.option = nir_cursor_before_block;
4699*61046927SAndroid Build Coastguard Worker cursor.block = block;
4700*61046927SAndroid Build Coastguard Worker return cursor;
4701*61046927SAndroid Build Coastguard Worker }
4702*61046927SAndroid Build Coastguard Worker
4703*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_block(nir_block * block)4704*61046927SAndroid Build Coastguard Worker nir_after_block(nir_block *block)
4705*61046927SAndroid Build Coastguard Worker {
4706*61046927SAndroid Build Coastguard Worker nir_cursor cursor;
4707*61046927SAndroid Build Coastguard Worker cursor.option = nir_cursor_after_block;
4708*61046927SAndroid Build Coastguard Worker cursor.block = block;
4709*61046927SAndroid Build Coastguard Worker return cursor;
4710*61046927SAndroid Build Coastguard Worker }
4711*61046927SAndroid Build Coastguard Worker
4712*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_instr(nir_instr * instr)4713*61046927SAndroid Build Coastguard Worker nir_before_instr(nir_instr *instr)
4714*61046927SAndroid Build Coastguard Worker {
4715*61046927SAndroid Build Coastguard Worker nir_cursor cursor;
4716*61046927SAndroid Build Coastguard Worker cursor.option = nir_cursor_before_instr;
4717*61046927SAndroid Build Coastguard Worker cursor.instr = instr;
4718*61046927SAndroid Build Coastguard Worker return cursor;
4719*61046927SAndroid Build Coastguard Worker }
4720*61046927SAndroid Build Coastguard Worker
4721*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_instr(nir_instr * instr)4722*61046927SAndroid Build Coastguard Worker nir_after_instr(nir_instr *instr)
4723*61046927SAndroid Build Coastguard Worker {
4724*61046927SAndroid Build Coastguard Worker nir_cursor cursor;
4725*61046927SAndroid Build Coastguard Worker cursor.option = nir_cursor_after_instr;
4726*61046927SAndroid Build Coastguard Worker cursor.instr = instr;
4727*61046927SAndroid Build Coastguard Worker return cursor;
4728*61046927SAndroid Build Coastguard Worker }
4729*61046927SAndroid Build Coastguard Worker
4730*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_block_after_phis(nir_block * block)4731*61046927SAndroid Build Coastguard Worker nir_before_block_after_phis(nir_block *block)
4732*61046927SAndroid Build Coastguard Worker {
4733*61046927SAndroid Build Coastguard Worker nir_phi_instr *last_phi = nir_block_last_phi_instr(block);
4734*61046927SAndroid Build Coastguard Worker if (last_phi)
4735*61046927SAndroid Build Coastguard Worker return nir_after_instr(&last_phi->instr);
4736*61046927SAndroid Build Coastguard Worker else
4737*61046927SAndroid Build Coastguard Worker return nir_before_block(block);
4738*61046927SAndroid Build Coastguard Worker }
4739*61046927SAndroid Build Coastguard Worker
4740*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_block_before_jump(nir_block * block)4741*61046927SAndroid Build Coastguard Worker nir_after_block_before_jump(nir_block *block)
4742*61046927SAndroid Build Coastguard Worker {
4743*61046927SAndroid Build Coastguard Worker nir_instr *last_instr = nir_block_last_instr(block);
4744*61046927SAndroid Build Coastguard Worker if (last_instr && last_instr->type == nir_instr_type_jump) {
4745*61046927SAndroid Build Coastguard Worker return nir_before_instr(last_instr);
4746*61046927SAndroid Build Coastguard Worker } else {
4747*61046927SAndroid Build Coastguard Worker return nir_after_block(block);
4748*61046927SAndroid Build Coastguard Worker }
4749*61046927SAndroid Build Coastguard Worker }
4750*61046927SAndroid Build Coastguard Worker
4751*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_src(nir_src * src)4752*61046927SAndroid Build Coastguard Worker nir_before_src(nir_src *src)
4753*61046927SAndroid Build Coastguard Worker {
4754*61046927SAndroid Build Coastguard Worker if (nir_src_is_if(src)) {
4755*61046927SAndroid Build Coastguard Worker nir_block *prev_block =
4756*61046927SAndroid Build Coastguard Worker nir_cf_node_as_block(nir_cf_node_prev(&nir_src_parent_if(src)->cf_node));
4757*61046927SAndroid Build Coastguard Worker return nir_after_block(prev_block);
4758*61046927SAndroid Build Coastguard Worker } else if (nir_src_parent_instr(src)->type == nir_instr_type_phi) {
4759*61046927SAndroid Build Coastguard Worker #ifndef NDEBUG
4760*61046927SAndroid Build Coastguard Worker nir_phi_instr *cond_phi = nir_instr_as_phi(nir_src_parent_instr(src));
4761*61046927SAndroid Build Coastguard Worker bool found = false;
4762*61046927SAndroid Build Coastguard Worker nir_foreach_phi_src(phi_src, cond_phi) {
4763*61046927SAndroid Build Coastguard Worker if (phi_src->src.ssa == src->ssa) {
4764*61046927SAndroid Build Coastguard Worker found = true;
4765*61046927SAndroid Build Coastguard Worker break;
4766*61046927SAndroid Build Coastguard Worker }
4767*61046927SAndroid Build Coastguard Worker }
4768*61046927SAndroid Build Coastguard Worker assert(found);
4769*61046927SAndroid Build Coastguard Worker #endif
4770*61046927SAndroid Build Coastguard Worker /* The list_entry() macro is a generic container-of macro, it just happens
4771*61046927SAndroid Build Coastguard Worker * to have a more specific name.
4772*61046927SAndroid Build Coastguard Worker */
4773*61046927SAndroid Build Coastguard Worker nir_phi_src *phi_src = list_entry(src, nir_phi_src, src);
4774*61046927SAndroid Build Coastguard Worker return nir_after_block_before_jump(phi_src->pred);
4775*61046927SAndroid Build Coastguard Worker } else {
4776*61046927SAndroid Build Coastguard Worker return nir_before_instr(nir_src_parent_instr(src));
4777*61046927SAndroid Build Coastguard Worker }
4778*61046927SAndroid Build Coastguard Worker }
4779*61046927SAndroid Build Coastguard Worker
4780*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_cf_node(nir_cf_node * node)4781*61046927SAndroid Build Coastguard Worker nir_before_cf_node(nir_cf_node *node)
4782*61046927SAndroid Build Coastguard Worker {
4783*61046927SAndroid Build Coastguard Worker if (node->type == nir_cf_node_block)
4784*61046927SAndroid Build Coastguard Worker return nir_before_block(nir_cf_node_as_block(node));
4785*61046927SAndroid Build Coastguard Worker
4786*61046927SAndroid Build Coastguard Worker return nir_after_block(nir_cf_node_as_block(nir_cf_node_prev(node)));
4787*61046927SAndroid Build Coastguard Worker }
4788*61046927SAndroid Build Coastguard Worker
4789*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_cf_node(nir_cf_node * node)4790*61046927SAndroid Build Coastguard Worker nir_after_cf_node(nir_cf_node *node)
4791*61046927SAndroid Build Coastguard Worker {
4792*61046927SAndroid Build Coastguard Worker if (node->type == nir_cf_node_block)
4793*61046927SAndroid Build Coastguard Worker return nir_after_block(nir_cf_node_as_block(node));
4794*61046927SAndroid Build Coastguard Worker
4795*61046927SAndroid Build Coastguard Worker return nir_before_block(nir_cf_node_as_block(nir_cf_node_next(node)));
4796*61046927SAndroid Build Coastguard Worker }
4797*61046927SAndroid Build Coastguard Worker
4798*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_phis(nir_block * block)4799*61046927SAndroid Build Coastguard Worker nir_after_phis(nir_block *block)
4800*61046927SAndroid Build Coastguard Worker {
4801*61046927SAndroid Build Coastguard Worker nir_foreach_instr(instr, block) {
4802*61046927SAndroid Build Coastguard Worker if (instr->type != nir_instr_type_phi)
4803*61046927SAndroid Build Coastguard Worker return nir_before_instr(instr);
4804*61046927SAndroid Build Coastguard Worker }
4805*61046927SAndroid Build Coastguard Worker return nir_after_block(block);
4806*61046927SAndroid Build Coastguard Worker }
4807*61046927SAndroid Build Coastguard Worker
4808*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_instr_and_phis(nir_instr * instr)4809*61046927SAndroid Build Coastguard Worker nir_after_instr_and_phis(nir_instr *instr)
4810*61046927SAndroid Build Coastguard Worker {
4811*61046927SAndroid Build Coastguard Worker if (instr->type == nir_instr_type_phi)
4812*61046927SAndroid Build Coastguard Worker return nir_after_phis(instr->block);
4813*61046927SAndroid Build Coastguard Worker else
4814*61046927SAndroid Build Coastguard Worker return nir_after_instr(instr);
4815*61046927SAndroid Build Coastguard Worker }
4816*61046927SAndroid Build Coastguard Worker
4817*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_cf_node_and_phis(nir_cf_node * node)4818*61046927SAndroid Build Coastguard Worker nir_after_cf_node_and_phis(nir_cf_node *node)
4819*61046927SAndroid Build Coastguard Worker {
4820*61046927SAndroid Build Coastguard Worker if (node->type == nir_cf_node_block)
4821*61046927SAndroid Build Coastguard Worker return nir_after_block(nir_cf_node_as_block(node));
4822*61046927SAndroid Build Coastguard Worker
4823*61046927SAndroid Build Coastguard Worker nir_block *block = nir_cf_node_as_block(nir_cf_node_next(node));
4824*61046927SAndroid Build Coastguard Worker
4825*61046927SAndroid Build Coastguard Worker return nir_after_phis(block);
4826*61046927SAndroid Build Coastguard Worker }
4827*61046927SAndroid Build Coastguard Worker
4828*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_cf_list(struct exec_list * cf_list)4829*61046927SAndroid Build Coastguard Worker nir_before_cf_list(struct exec_list *cf_list)
4830*61046927SAndroid Build Coastguard Worker {
4831*61046927SAndroid Build Coastguard Worker nir_cf_node *first_node = exec_node_data(nir_cf_node,
4832*61046927SAndroid Build Coastguard Worker exec_list_get_head(cf_list), node);
4833*61046927SAndroid Build Coastguard Worker return nir_before_cf_node(first_node);
4834*61046927SAndroid Build Coastguard Worker }
4835*61046927SAndroid Build Coastguard Worker
4836*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_cf_list(struct exec_list * cf_list)4837*61046927SAndroid Build Coastguard Worker nir_after_cf_list(struct exec_list *cf_list)
4838*61046927SAndroid Build Coastguard Worker {
4839*61046927SAndroid Build Coastguard Worker nir_cf_node *last_node = exec_node_data(nir_cf_node,
4840*61046927SAndroid Build Coastguard Worker exec_list_get_tail(cf_list), node);
4841*61046927SAndroid Build Coastguard Worker return nir_after_cf_node(last_node);
4842*61046927SAndroid Build Coastguard Worker }
4843*61046927SAndroid Build Coastguard Worker
4844*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_before_impl(nir_function_impl * impl)4845*61046927SAndroid Build Coastguard Worker nir_before_impl(nir_function_impl *impl)
4846*61046927SAndroid Build Coastguard Worker {
4847*61046927SAndroid Build Coastguard Worker return nir_before_cf_list(&impl->body);
4848*61046927SAndroid Build Coastguard Worker }
4849*61046927SAndroid Build Coastguard Worker
4850*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_impl(nir_function_impl * impl)4851*61046927SAndroid Build Coastguard Worker nir_after_impl(nir_function_impl *impl)
4852*61046927SAndroid Build Coastguard Worker {
4853*61046927SAndroid Build Coastguard Worker return nir_after_cf_list(&impl->body);
4854*61046927SAndroid Build Coastguard Worker }
4855*61046927SAndroid Build Coastguard Worker
4856*61046927SAndroid Build Coastguard Worker /**
4857*61046927SAndroid Build Coastguard Worker * Insert a NIR instruction at the given cursor.
4858*61046927SAndroid Build Coastguard Worker *
4859*61046927SAndroid Build Coastguard Worker * Note: This does not update the cursor.
4860*61046927SAndroid Build Coastguard Worker */
4861*61046927SAndroid Build Coastguard Worker void nir_instr_insert(nir_cursor cursor, nir_instr *instr);
4862*61046927SAndroid Build Coastguard Worker
4863*61046927SAndroid Build Coastguard Worker bool nir_instr_move(nir_cursor cursor, nir_instr *instr);
4864*61046927SAndroid Build Coastguard Worker
4865*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_before(nir_instr * instr,nir_instr * before)4866*61046927SAndroid Build Coastguard Worker nir_instr_insert_before(nir_instr *instr, nir_instr *before)
4867*61046927SAndroid Build Coastguard Worker {
4868*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_before_instr(instr), before);
4869*61046927SAndroid Build Coastguard Worker }
4870*61046927SAndroid Build Coastguard Worker
4871*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_after(nir_instr * instr,nir_instr * after)4872*61046927SAndroid Build Coastguard Worker nir_instr_insert_after(nir_instr *instr, nir_instr *after)
4873*61046927SAndroid Build Coastguard Worker {
4874*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_after_instr(instr), after);
4875*61046927SAndroid Build Coastguard Worker }
4876*61046927SAndroid Build Coastguard Worker
4877*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_before_block(nir_block * block,nir_instr * before)4878*61046927SAndroid Build Coastguard Worker nir_instr_insert_before_block(nir_block *block, nir_instr *before)
4879*61046927SAndroid Build Coastguard Worker {
4880*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_before_block(block), before);
4881*61046927SAndroid Build Coastguard Worker }
4882*61046927SAndroid Build Coastguard Worker
4883*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_after_block(nir_block * block,nir_instr * after)4884*61046927SAndroid Build Coastguard Worker nir_instr_insert_after_block(nir_block *block, nir_instr *after)
4885*61046927SAndroid Build Coastguard Worker {
4886*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_after_block(block), after);
4887*61046927SAndroid Build Coastguard Worker }
4888*61046927SAndroid Build Coastguard Worker
4889*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_before_cf(nir_cf_node * node,nir_instr * before)4890*61046927SAndroid Build Coastguard Worker nir_instr_insert_before_cf(nir_cf_node *node, nir_instr *before)
4891*61046927SAndroid Build Coastguard Worker {
4892*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_before_cf_node(node), before);
4893*61046927SAndroid Build Coastguard Worker }
4894*61046927SAndroid Build Coastguard Worker
4895*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_after_cf(nir_cf_node * node,nir_instr * after)4896*61046927SAndroid Build Coastguard Worker nir_instr_insert_after_cf(nir_cf_node *node, nir_instr *after)
4897*61046927SAndroid Build Coastguard Worker {
4898*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_after_cf_node(node), after);
4899*61046927SAndroid Build Coastguard Worker }
4900*61046927SAndroid Build Coastguard Worker
4901*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_before_cf_list(struct exec_list * list,nir_instr * before)4902*61046927SAndroid Build Coastguard Worker nir_instr_insert_before_cf_list(struct exec_list *list, nir_instr *before)
4903*61046927SAndroid Build Coastguard Worker {
4904*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_before_cf_list(list), before);
4905*61046927SAndroid Build Coastguard Worker }
4906*61046927SAndroid Build Coastguard Worker
4907*61046927SAndroid Build Coastguard Worker static inline void
nir_instr_insert_after_cf_list(struct exec_list * list,nir_instr * after)4908*61046927SAndroid Build Coastguard Worker nir_instr_insert_after_cf_list(struct exec_list *list, nir_instr *after)
4909*61046927SAndroid Build Coastguard Worker {
4910*61046927SAndroid Build Coastguard Worker nir_instr_insert(nir_after_cf_list(list), after);
4911*61046927SAndroid Build Coastguard Worker }
4912*61046927SAndroid Build Coastguard Worker
4913*61046927SAndroid Build Coastguard Worker void nir_instr_remove_v(nir_instr *instr);
4914*61046927SAndroid Build Coastguard Worker void nir_instr_free(nir_instr *instr);
4915*61046927SAndroid Build Coastguard Worker void nir_instr_free_list(struct exec_list *list);
4916*61046927SAndroid Build Coastguard Worker
4917*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_instr_remove(nir_instr * instr)4918*61046927SAndroid Build Coastguard Worker nir_instr_remove(nir_instr *instr)
4919*61046927SAndroid Build Coastguard Worker {
4920*61046927SAndroid Build Coastguard Worker nir_cursor cursor;
4921*61046927SAndroid Build Coastguard Worker nir_instr *prev = nir_instr_prev(instr);
4922*61046927SAndroid Build Coastguard Worker if (prev) {
4923*61046927SAndroid Build Coastguard Worker cursor = nir_after_instr(prev);
4924*61046927SAndroid Build Coastguard Worker } else {
4925*61046927SAndroid Build Coastguard Worker cursor = nir_before_block(instr->block);
4926*61046927SAndroid Build Coastguard Worker }
4927*61046927SAndroid Build Coastguard Worker nir_instr_remove_v(instr);
4928*61046927SAndroid Build Coastguard Worker return cursor;
4929*61046927SAndroid Build Coastguard Worker }
4930*61046927SAndroid Build Coastguard Worker
4931*61046927SAndroid Build Coastguard Worker nir_cursor nir_instr_free_and_dce(nir_instr *instr);
4932*61046927SAndroid Build Coastguard Worker
4933*61046927SAndroid Build Coastguard Worker /** @} */
4934*61046927SAndroid Build Coastguard Worker
4935*61046927SAndroid Build Coastguard Worker nir_def *nir_instr_def(nir_instr *instr);
4936*61046927SAndroid Build Coastguard Worker
4937*61046927SAndroid Build Coastguard Worker typedef bool (*nir_foreach_def_cb)(nir_def *def, void *state);
4938*61046927SAndroid Build Coastguard Worker typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
4939*61046927SAndroid Build Coastguard Worker static inline bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
4940*61046927SAndroid Build Coastguard Worker bool nir_foreach_phi_src_leaving_block(nir_block *instr,
4941*61046927SAndroid Build Coastguard Worker nir_foreach_src_cb cb,
4942*61046927SAndroid Build Coastguard Worker void *state);
4943*61046927SAndroid Build Coastguard Worker
4944*61046927SAndroid Build Coastguard Worker nir_const_value *nir_src_as_const_value(nir_src src);
4945*61046927SAndroid Build Coastguard Worker
4946*61046927SAndroid Build Coastguard Worker #define NIR_SRC_AS_(name, c_type, type_enum, cast_macro) \
4947*61046927SAndroid Build Coastguard Worker static inline c_type * \
4948*61046927SAndroid Build Coastguard Worker nir_src_as_##name(nir_src src) \
4949*61046927SAndroid Build Coastguard Worker { \
4950*61046927SAndroid Build Coastguard Worker return src.ssa->parent_instr->type == type_enum \
4951*61046927SAndroid Build Coastguard Worker ? cast_macro(src.ssa->parent_instr) \
4952*61046927SAndroid Build Coastguard Worker : NULL; \
4953*61046927SAndroid Build Coastguard Worker }
4954*61046927SAndroid Build Coastguard Worker
4955*61046927SAndroid Build Coastguard Worker NIR_SRC_AS_(alu_instr, nir_alu_instr, nir_instr_type_alu, nir_instr_as_alu)
4956*61046927SAndroid Build Coastguard Worker NIR_SRC_AS_(intrinsic, nir_intrinsic_instr,
4957*61046927SAndroid Build Coastguard Worker nir_instr_type_intrinsic, nir_instr_as_intrinsic)
4958*61046927SAndroid Build Coastguard Worker NIR_SRC_AS_(deref, nir_deref_instr, nir_instr_type_deref, nir_instr_as_deref)
4959*61046927SAndroid Build Coastguard Worker NIR_SRC_AS_(debug_info, nir_debug_info_instr, nir_instr_type_debug_info, nir_instr_as_debug_info)
4960*61046927SAndroid Build Coastguard Worker
4961*61046927SAndroid Build Coastguard Worker const char *nir_src_as_string(nir_src src);
4962*61046927SAndroid Build Coastguard Worker
4963*61046927SAndroid Build Coastguard Worker bool nir_src_is_always_uniform(nir_src src);
4964*61046927SAndroid Build Coastguard Worker bool nir_srcs_equal(nir_src src1, nir_src src2);
4965*61046927SAndroid Build Coastguard Worker bool nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2);
4966*61046927SAndroid Build Coastguard Worker nir_block *nir_src_get_block(nir_src *src);
4967*61046927SAndroid Build Coastguard Worker
4968*61046927SAndroid Build Coastguard Worker static inline void
nir_src_rewrite(nir_src * src,nir_def * new_ssa)4969*61046927SAndroid Build Coastguard Worker nir_src_rewrite(nir_src *src, nir_def *new_ssa)
4970*61046927SAndroid Build Coastguard Worker {
4971*61046927SAndroid Build Coastguard Worker assert(src->ssa);
4972*61046927SAndroid Build Coastguard Worker assert(nir_src_is_if(src) ? (nir_src_parent_if(src) != NULL) : (nir_src_parent_instr(src) != NULL));
4973*61046927SAndroid Build Coastguard Worker list_del(&src->use_link);
4974*61046927SAndroid Build Coastguard Worker src->ssa = new_ssa;
4975*61046927SAndroid Build Coastguard Worker list_addtail(&src->use_link, &new_ssa->uses);
4976*61046927SAndroid Build Coastguard Worker }
4977*61046927SAndroid Build Coastguard Worker
4978*61046927SAndroid Build Coastguard Worker /** Initialize a nir_src
4979*61046927SAndroid Build Coastguard Worker *
4980*61046927SAndroid Build Coastguard Worker * This is almost never the helper you want to use. This helper assumes that
4981*61046927SAndroid Build Coastguard Worker * the source is uninitialized garbage and blasts over it without doing any
4982*61046927SAndroid Build Coastguard Worker * tear-down the existing source, including removing it from uses lists.
4983*61046927SAndroid Build Coastguard Worker * Using this helper on a source that currently exists in any uses list will
4984*61046927SAndroid Build Coastguard Worker * result in linked list corruption. It also assumes that the instruction is
4985*61046927SAndroid Build Coastguard Worker * currently live in the IR and adds the source to the uses list for the given
4986*61046927SAndroid Build Coastguard Worker * nir_def as part of setup.
4987*61046927SAndroid Build Coastguard Worker *
4988*61046927SAndroid Build Coastguard Worker * This is pretty much only useful for adding sources to extant instructions
4989*61046927SAndroid Build Coastguard Worker * or manipulating parallel copy instructions as part of out-of-SSA.
4990*61046927SAndroid Build Coastguard Worker *
4991*61046927SAndroid Build Coastguard Worker * When in doubt, use nir_src_rewrite() instead.
4992*61046927SAndroid Build Coastguard Worker */
4993*61046927SAndroid Build Coastguard Worker void nir_instr_init_src(nir_instr *instr, nir_src *src, nir_def *def);
4994*61046927SAndroid Build Coastguard Worker
4995*61046927SAndroid Build Coastguard Worker /** Clear a nir_src
4996*61046927SAndroid Build Coastguard Worker *
4997*61046927SAndroid Build Coastguard Worker * This helper clears a nir_src by removing it from any uses lists and
4998*61046927SAndroid Build Coastguard Worker * resetting its contents to NIR_SRC_INIT. This is typically used as a
4999*61046927SAndroid Build Coastguard Worker * precursor to removing the source from the instruction by adjusting a
5000*61046927SAndroid Build Coastguard Worker * num_srcs parameter somewhere or overwriting it with nir_instr_move_src().
5001*61046927SAndroid Build Coastguard Worker */
5002*61046927SAndroid Build Coastguard Worker void nir_instr_clear_src(nir_instr *instr, nir_src *src);
5003*61046927SAndroid Build Coastguard Worker
5004*61046927SAndroid Build Coastguard Worker void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
5005*61046927SAndroid Build Coastguard Worker
5006*61046927SAndroid Build Coastguard Worker void nir_def_init(nir_instr *instr, nir_def *def,
5007*61046927SAndroid Build Coastguard Worker unsigned num_components, unsigned bit_size);
5008*61046927SAndroid Build Coastguard Worker static inline void
nir_def_init_for_type(nir_instr * instr,nir_def * def,const struct glsl_type * type)5009*61046927SAndroid Build Coastguard Worker nir_def_init_for_type(nir_instr *instr, nir_def *def,
5010*61046927SAndroid Build Coastguard Worker const struct glsl_type *type)
5011*61046927SAndroid Build Coastguard Worker {
5012*61046927SAndroid Build Coastguard Worker assert(glsl_type_is_vector_or_scalar(type));
5013*61046927SAndroid Build Coastguard Worker nir_def_init(instr, def, glsl_get_components(type),
5014*61046927SAndroid Build Coastguard Worker glsl_get_bit_size(type));
5015*61046927SAndroid Build Coastguard Worker }
5016*61046927SAndroid Build Coastguard Worker void nir_def_rewrite_uses(nir_def *def, nir_def *new_ssa);
5017*61046927SAndroid Build Coastguard Worker void nir_def_rewrite_uses_src(nir_def *def, nir_src new_src);
5018*61046927SAndroid Build Coastguard Worker void nir_def_rewrite_uses_after(nir_def *def, nir_def *new_ssa,
5019*61046927SAndroid Build Coastguard Worker nir_instr *after_me);
5020*61046927SAndroid Build Coastguard Worker
5021*61046927SAndroid Build Coastguard Worker static inline void
nir_def_replace(nir_def * def,nir_def * new_ssa)5022*61046927SAndroid Build Coastguard Worker nir_def_replace(nir_def *def, nir_def *new_ssa)
5023*61046927SAndroid Build Coastguard Worker {
5024*61046927SAndroid Build Coastguard Worker nir_def_rewrite_uses(def, new_ssa);
5025*61046927SAndroid Build Coastguard Worker nir_instr_remove(def->parent_instr);
5026*61046927SAndroid Build Coastguard Worker }
5027*61046927SAndroid Build Coastguard Worker
5028*61046927SAndroid Build Coastguard Worker nir_component_mask_t nir_src_components_read(const nir_src *src);
5029*61046927SAndroid Build Coastguard Worker nir_component_mask_t nir_def_components_read(const nir_def *def);
5030*61046927SAndroid Build Coastguard Worker bool nir_def_all_uses_are_fsat(const nir_def *def);
5031*61046927SAndroid Build Coastguard Worker
5032*61046927SAndroid Build Coastguard Worker static inline bool
nir_def_is_unused(nir_def * ssa)5033*61046927SAndroid Build Coastguard Worker nir_def_is_unused(nir_def *ssa)
5034*61046927SAndroid Build Coastguard Worker {
5035*61046927SAndroid Build Coastguard Worker return list_is_empty(&ssa->uses);
5036*61046927SAndroid Build Coastguard Worker }
5037*61046927SAndroid Build Coastguard Worker
5038*61046927SAndroid Build Coastguard Worker /** Sorts unstructured blocks
5039*61046927SAndroid Build Coastguard Worker *
5040*61046927SAndroid Build Coastguard Worker * NIR requires that unstructured blocks be sorted in reverse post
5041*61046927SAndroid Build Coastguard Worker * depth-first-search order. This is the standard ordering used in the
5042*61046927SAndroid Build Coastguard Worker * compiler literature which guarantees dominance. In particular, reverse
5043*61046927SAndroid Build Coastguard Worker * post-DFS order guarantees that dominators occur in the list before the
5044*61046927SAndroid Build Coastguard Worker * blocks they dominate.
5045*61046927SAndroid Build Coastguard Worker *
5046*61046927SAndroid Build Coastguard Worker * NOTE: This function also implicitly deletes any unreachable blocks.
5047*61046927SAndroid Build Coastguard Worker */
5048*61046927SAndroid Build Coastguard Worker void nir_sort_unstructured_blocks(nir_function_impl *impl);
5049*61046927SAndroid Build Coastguard Worker
5050*61046927SAndroid Build Coastguard Worker /** Returns the next block
5051*61046927SAndroid Build Coastguard Worker *
5052*61046927SAndroid Build Coastguard Worker * For structured control-flow, this follows the same order as
5053*61046927SAndroid Build Coastguard Worker * nir_block_cf_tree_next(). For unstructured control-flow the blocks are in
5054*61046927SAndroid Build Coastguard Worker * reverse post-DFS order. (See nir_sort_unstructured_blocks() above.)
5055*61046927SAndroid Build Coastguard Worker */
5056*61046927SAndroid Build Coastguard Worker nir_block *nir_block_unstructured_next(nir_block *block);
5057*61046927SAndroid Build Coastguard Worker nir_block *nir_unstructured_start_block(nir_function_impl *impl);
5058*61046927SAndroid Build Coastguard Worker
5059*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_unstructured(block, impl) \
5060*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_unstructured_start_block(impl); block != NULL; \
5061*61046927SAndroid Build Coastguard Worker block = nir_block_unstructured_next(block))
5062*61046927SAndroid Build Coastguard Worker
5063*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_unstructured_safe(block, impl) \
5064*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_unstructured_start_block(impl), \
5065*61046927SAndroid Build Coastguard Worker *next = nir_block_unstructured_next(block); \
5066*61046927SAndroid Build Coastguard Worker block != NULL; \
5067*61046927SAndroid Build Coastguard Worker block = next, next = nir_block_unstructured_next(block))
5068*61046927SAndroid Build Coastguard Worker
5069*61046927SAndroid Build Coastguard Worker /*
5070*61046927SAndroid Build Coastguard Worker * finds the next basic block in source-code order, returns NULL if there is
5071*61046927SAndroid Build Coastguard Worker * none
5072*61046927SAndroid Build Coastguard Worker */
5073*61046927SAndroid Build Coastguard Worker
5074*61046927SAndroid Build Coastguard Worker nir_block *nir_block_cf_tree_next(nir_block *block);
5075*61046927SAndroid Build Coastguard Worker
5076*61046927SAndroid Build Coastguard Worker /* Performs the opposite of nir_block_cf_tree_next() */
5077*61046927SAndroid Build Coastguard Worker
5078*61046927SAndroid Build Coastguard Worker nir_block *nir_block_cf_tree_prev(nir_block *block);
5079*61046927SAndroid Build Coastguard Worker
5080*61046927SAndroid Build Coastguard Worker /* Gets the first block in a CF node in source-code order */
5081*61046927SAndroid Build Coastguard Worker
5082*61046927SAndroid Build Coastguard Worker nir_block *nir_cf_node_cf_tree_first(nir_cf_node *node);
5083*61046927SAndroid Build Coastguard Worker
5084*61046927SAndroid Build Coastguard Worker /* Gets the last block in a CF node in source-code order */
5085*61046927SAndroid Build Coastguard Worker
5086*61046927SAndroid Build Coastguard Worker nir_block *nir_cf_node_cf_tree_last(nir_cf_node *node);
5087*61046927SAndroid Build Coastguard Worker
5088*61046927SAndroid Build Coastguard Worker /* Gets the next block after a CF node in source-code order */
5089*61046927SAndroid Build Coastguard Worker
5090*61046927SAndroid Build Coastguard Worker nir_block *nir_cf_node_cf_tree_next(nir_cf_node *node);
5091*61046927SAndroid Build Coastguard Worker
5092*61046927SAndroid Build Coastguard Worker /* Gets the block before a CF node in source-code order */
5093*61046927SAndroid Build Coastguard Worker
5094*61046927SAndroid Build Coastguard Worker nir_block *nir_cf_node_cf_tree_prev(nir_cf_node *node);
5095*61046927SAndroid Build Coastguard Worker
5096*61046927SAndroid Build Coastguard Worker /* Macros for loops that visit blocks in source-code order */
5097*61046927SAndroid Build Coastguard Worker
5098*61046927SAndroid Build Coastguard Worker #define nir_foreach_block(block, impl) \
5099*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_start_block(impl); block != NULL; \
5100*61046927SAndroid Build Coastguard Worker block = nir_block_cf_tree_next(block))
5101*61046927SAndroid Build Coastguard Worker
5102*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_safe(block, impl) \
5103*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_start_block(impl), \
5104*61046927SAndroid Build Coastguard Worker *next = nir_block_cf_tree_next(block); \
5105*61046927SAndroid Build Coastguard Worker block != NULL; \
5106*61046927SAndroid Build Coastguard Worker block = next, next = nir_block_cf_tree_next(block))
5107*61046927SAndroid Build Coastguard Worker
5108*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_reverse(block, impl) \
5109*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_impl_last_block(impl); block != NULL; \
5110*61046927SAndroid Build Coastguard Worker block = nir_block_cf_tree_prev(block))
5111*61046927SAndroid Build Coastguard Worker
5112*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_reverse_safe(block, impl) \
5113*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_impl_last_block(impl), \
5114*61046927SAndroid Build Coastguard Worker *prev = nir_block_cf_tree_prev(block); \
5115*61046927SAndroid Build Coastguard Worker block != NULL; \
5116*61046927SAndroid Build Coastguard Worker block = prev, prev = nir_block_cf_tree_prev(block))
5117*61046927SAndroid Build Coastguard Worker
5118*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_in_cf_node(block, node) \
5119*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_cf_node_cf_tree_first(node); \
5120*61046927SAndroid Build Coastguard Worker block != nir_cf_node_cf_tree_next(node); \
5121*61046927SAndroid Build Coastguard Worker block = nir_block_cf_tree_next(block))
5122*61046927SAndroid Build Coastguard Worker
5123*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_in_cf_node_safe(block, node) \
5124*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_cf_node_cf_tree_first(node), \
5125*61046927SAndroid Build Coastguard Worker *next = nir_block_cf_tree_next(block); \
5126*61046927SAndroid Build Coastguard Worker block != nir_cf_node_cf_tree_next(node); \
5127*61046927SAndroid Build Coastguard Worker block = next, next = nir_block_cf_tree_next(block))
5128*61046927SAndroid Build Coastguard Worker
5129*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_in_cf_node_reverse(block, node) \
5130*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_cf_node_cf_tree_last(node); \
5131*61046927SAndroid Build Coastguard Worker block != nir_cf_node_cf_tree_prev(node); \
5132*61046927SAndroid Build Coastguard Worker block = nir_block_cf_tree_prev(block))
5133*61046927SAndroid Build Coastguard Worker
5134*61046927SAndroid Build Coastguard Worker #define nir_foreach_block_in_cf_node_reverse_safe(block, node) \
5135*61046927SAndroid Build Coastguard Worker for (nir_block *block = nir_cf_node_cf_tree_last(node), \
5136*61046927SAndroid Build Coastguard Worker *prev = nir_block_cf_tree_prev(block); \
5137*61046927SAndroid Build Coastguard Worker block != nir_cf_node_cf_tree_prev(node); \
5138*61046927SAndroid Build Coastguard Worker block = prev, prev = nir_block_cf_tree_prev(block))
5139*61046927SAndroid Build Coastguard Worker
5140*61046927SAndroid Build Coastguard Worker /* If the following CF node is an if, this function returns that if.
5141*61046927SAndroid Build Coastguard Worker * Otherwise, it returns NULL.
5142*61046927SAndroid Build Coastguard Worker */
5143*61046927SAndroid Build Coastguard Worker nir_if *nir_block_get_following_if(nir_block *block);
5144*61046927SAndroid Build Coastguard Worker
5145*61046927SAndroid Build Coastguard Worker nir_loop *nir_block_get_following_loop(nir_block *block);
5146*61046927SAndroid Build Coastguard Worker
5147*61046927SAndroid Build Coastguard Worker nir_block **nir_block_get_predecessors_sorted(const nir_block *block, void *mem_ctx);
5148*61046927SAndroid Build Coastguard Worker
5149*61046927SAndroid Build Coastguard Worker void nir_index_ssa_defs(nir_function_impl *impl);
5150*61046927SAndroid Build Coastguard Worker unsigned nir_index_instrs(nir_function_impl *impl);
5151*61046927SAndroid Build Coastguard Worker
5152*61046927SAndroid Build Coastguard Worker void nir_index_blocks(nir_function_impl *impl);
5153*61046927SAndroid Build Coastguard Worker
5154*61046927SAndroid Build Coastguard Worker void nir_shader_clear_pass_flags(nir_shader *shader);
5155*61046927SAndroid Build Coastguard Worker
5156*61046927SAndroid Build Coastguard Worker unsigned nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes);
5157*61046927SAndroid Build Coastguard Worker unsigned nir_function_impl_index_vars(nir_function_impl *impl);
5158*61046927SAndroid Build Coastguard Worker
5159*61046927SAndroid Build Coastguard Worker void nir_print_shader(nir_shader *shader, FILE *fp);
5160*61046927SAndroid Build Coastguard Worker void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors);
5161*61046927SAndroid Build Coastguard Worker void nir_print_instr(const nir_instr *instr, FILE *fp);
5162*61046927SAndroid Build Coastguard Worker void nir_print_deref(const nir_deref_instr *deref, FILE *fp);
5163*61046927SAndroid Build Coastguard Worker void nir_log_shader_annotated_tagged(enum mesa_log_level level, const char *tag, nir_shader *shader, struct hash_table *annotations);
5164*61046927SAndroid Build Coastguard Worker #define nir_log_shadere(s) nir_log_shader_annotated_tagged(MESA_LOG_ERROR, (MESA_LOG_TAG), (s), NULL)
5165*61046927SAndroid Build Coastguard Worker #define nir_log_shaderw(s) nir_log_shader_annotated_tagged(MESA_LOG_WARN, (MESA_LOG_TAG), (s), NULL)
5166*61046927SAndroid Build Coastguard Worker #define nir_log_shaderi(s) nir_log_shader_annotated_tagged(MESA_LOG_INFO, (MESA_LOG_TAG), (s), NULL)
5167*61046927SAndroid Build Coastguard Worker #define nir_log_shader_annotated(s, annotations) nir_log_shader_annotated_tagged(MESA_LOG_ERROR, (MESA_LOG_TAG), (s), annotations)
5168*61046927SAndroid Build Coastguard Worker
5169*61046927SAndroid Build Coastguard Worker char *nir_shader_as_str(nir_shader *nir, void *mem_ctx);
5170*61046927SAndroid Build Coastguard Worker char *nir_shader_as_str_annotated(nir_shader *nir, struct hash_table *annotations, void *mem_ctx);
5171*61046927SAndroid Build Coastguard Worker char *nir_instr_as_str(const nir_instr *instr, void *mem_ctx);
5172*61046927SAndroid Build Coastguard Worker
5173*61046927SAndroid Build Coastguard Worker char *nir_shader_gather_debug_info(nir_shader *shader, const char *filename);
5174*61046927SAndroid Build Coastguard Worker
5175*61046927SAndroid Build Coastguard Worker /** Shallow clone of a single instruction. */
5176*61046927SAndroid Build Coastguard Worker nir_instr *nir_instr_clone(nir_shader *s, const nir_instr *orig);
5177*61046927SAndroid Build Coastguard Worker
5178*61046927SAndroid Build Coastguard Worker /** Clone a single instruction, including a remap table to rewrite sources. */
5179*61046927SAndroid Build Coastguard Worker nir_instr *nir_instr_clone_deep(nir_shader *s, const nir_instr *orig,
5180*61046927SAndroid Build Coastguard Worker struct hash_table *remap_table);
5181*61046927SAndroid Build Coastguard Worker
5182*61046927SAndroid Build Coastguard Worker /** Shallow clone of a single ALU instruction. */
5183*61046927SAndroid Build Coastguard Worker nir_alu_instr *nir_alu_instr_clone(nir_shader *s, const nir_alu_instr *orig);
5184*61046927SAndroid Build Coastguard Worker
5185*61046927SAndroid Build Coastguard Worker nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s);
5186*61046927SAndroid Build Coastguard Worker nir_function *nir_function_clone(nir_shader *ns, const nir_function *fxn);
5187*61046927SAndroid Build Coastguard Worker nir_function_impl *nir_function_impl_clone(nir_shader *shader,
5188*61046927SAndroid Build Coastguard Worker const nir_function_impl *fi);
5189*61046927SAndroid Build Coastguard Worker nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var);
5190*61046927SAndroid Build Coastguard Worker nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);
5191*61046927SAndroid Build Coastguard Worker
5192*61046927SAndroid Build Coastguard Worker void nir_shader_replace(nir_shader *dest, nir_shader *src);
5193*61046927SAndroid Build Coastguard Worker
5194*61046927SAndroid Build Coastguard Worker void nir_shader_serialize_deserialize(nir_shader *s);
5195*61046927SAndroid Build Coastguard Worker
5196*61046927SAndroid Build Coastguard Worker #ifndef NDEBUG
5197*61046927SAndroid Build Coastguard Worker void nir_validate_shader(nir_shader *shader, const char *when);
5198*61046927SAndroid Build Coastguard Worker void nir_validate_ssa_dominance(nir_shader *shader, const char *when);
5199*61046927SAndroid Build Coastguard Worker void nir_metadata_set_validation_flag(nir_shader *shader);
5200*61046927SAndroid Build Coastguard Worker void nir_metadata_check_validation_flag(nir_shader *shader);
5201*61046927SAndroid Build Coastguard Worker
5202*61046927SAndroid Build Coastguard Worker static inline bool
should_skip_nir(const char * name)5203*61046927SAndroid Build Coastguard Worker should_skip_nir(const char *name)
5204*61046927SAndroid Build Coastguard Worker {
5205*61046927SAndroid Build Coastguard Worker static const char *list = NULL;
5206*61046927SAndroid Build Coastguard Worker if (!list) {
5207*61046927SAndroid Build Coastguard Worker /* Comma separated list of names to skip. */
5208*61046927SAndroid Build Coastguard Worker list = getenv("NIR_SKIP");
5209*61046927SAndroid Build Coastguard Worker if (!list)
5210*61046927SAndroid Build Coastguard Worker list = "";
5211*61046927SAndroid Build Coastguard Worker }
5212*61046927SAndroid Build Coastguard Worker
5213*61046927SAndroid Build Coastguard Worker if (!list[0])
5214*61046927SAndroid Build Coastguard Worker return false;
5215*61046927SAndroid Build Coastguard Worker
5216*61046927SAndroid Build Coastguard Worker return comma_separated_list_contains(list, name);
5217*61046927SAndroid Build Coastguard Worker }
5218*61046927SAndroid Build Coastguard Worker
5219*61046927SAndroid Build Coastguard Worker static inline bool
should_print_nir(nir_shader * shader)5220*61046927SAndroid Build Coastguard Worker should_print_nir(nir_shader *shader)
5221*61046927SAndroid Build Coastguard Worker {
5222*61046927SAndroid Build Coastguard Worker if ((shader->info.internal && !NIR_DEBUG(PRINT_INTERNAL)) ||
5223*61046927SAndroid Build Coastguard Worker shader->info.stage < 0 ||
5224*61046927SAndroid Build Coastguard Worker shader->info.stage > MESA_SHADER_KERNEL)
5225*61046927SAndroid Build Coastguard Worker return false;
5226*61046927SAndroid Build Coastguard Worker
5227*61046927SAndroid Build Coastguard Worker return unlikely(nir_debug_print_shader[shader->info.stage]);
5228*61046927SAndroid Build Coastguard Worker }
5229*61046927SAndroid Build Coastguard Worker #else
5230*61046927SAndroid Build Coastguard Worker static inline void
nir_validate_shader(nir_shader * shader,const char * when)5231*61046927SAndroid Build Coastguard Worker nir_validate_shader(nir_shader *shader, const char *when)
5232*61046927SAndroid Build Coastguard Worker {
5233*61046927SAndroid Build Coastguard Worker (void)shader;
5234*61046927SAndroid Build Coastguard Worker (void)when;
5235*61046927SAndroid Build Coastguard Worker }
5236*61046927SAndroid Build Coastguard Worker static inline void
nir_validate_ssa_dominance(nir_shader * shader,const char * when)5237*61046927SAndroid Build Coastguard Worker nir_validate_ssa_dominance(nir_shader *shader, const char *when)
5238*61046927SAndroid Build Coastguard Worker {
5239*61046927SAndroid Build Coastguard Worker (void)shader;
5240*61046927SAndroid Build Coastguard Worker (void)when;
5241*61046927SAndroid Build Coastguard Worker }
5242*61046927SAndroid Build Coastguard Worker static inline void
nir_metadata_set_validation_flag(nir_shader * shader)5243*61046927SAndroid Build Coastguard Worker nir_metadata_set_validation_flag(nir_shader *shader)
5244*61046927SAndroid Build Coastguard Worker {
5245*61046927SAndroid Build Coastguard Worker (void)shader;
5246*61046927SAndroid Build Coastguard Worker }
5247*61046927SAndroid Build Coastguard Worker static inline void
nir_metadata_check_validation_flag(nir_shader * shader)5248*61046927SAndroid Build Coastguard Worker nir_metadata_check_validation_flag(nir_shader *shader)
5249*61046927SAndroid Build Coastguard Worker {
5250*61046927SAndroid Build Coastguard Worker (void)shader;
5251*61046927SAndroid Build Coastguard Worker }
5252*61046927SAndroid Build Coastguard Worker static inline bool
should_skip_nir(UNUSED const char * pass_name)5253*61046927SAndroid Build Coastguard Worker should_skip_nir(UNUSED const char *pass_name)
5254*61046927SAndroid Build Coastguard Worker {
5255*61046927SAndroid Build Coastguard Worker return false;
5256*61046927SAndroid Build Coastguard Worker }
5257*61046927SAndroid Build Coastguard Worker static inline bool
should_print_nir(UNUSED nir_shader * shader)5258*61046927SAndroid Build Coastguard Worker should_print_nir(UNUSED nir_shader *shader)
5259*61046927SAndroid Build Coastguard Worker {
5260*61046927SAndroid Build Coastguard Worker return false;
5261*61046927SAndroid Build Coastguard Worker }
5262*61046927SAndroid Build Coastguard Worker #endif /* NDEBUG */
5263*61046927SAndroid Build Coastguard Worker
5264*61046927SAndroid Build Coastguard Worker #define _PASS(pass, nir, do_pass) \
5265*61046927SAndroid Build Coastguard Worker do { \
5266*61046927SAndroid Build Coastguard Worker if (should_skip_nir(#pass)) { \
5267*61046927SAndroid Build Coastguard Worker printf("skipping %s\n", #pass); \
5268*61046927SAndroid Build Coastguard Worker break; \
5269*61046927SAndroid Build Coastguard Worker } \
5270*61046927SAndroid Build Coastguard Worker do_pass if (NIR_DEBUG(CLONE)) \
5271*61046927SAndroid Build Coastguard Worker { \
5272*61046927SAndroid Build Coastguard Worker nir_shader *_clone = nir_shader_clone(ralloc_parent(nir), nir);\
5273*61046927SAndroid Build Coastguard Worker nir_shader_replace(nir, _clone); \
5274*61046927SAndroid Build Coastguard Worker } \
5275*61046927SAndroid Build Coastguard Worker if (NIR_DEBUG(SERIALIZE)) { \
5276*61046927SAndroid Build Coastguard Worker nir_shader_serialize_deserialize(nir); \
5277*61046927SAndroid Build Coastguard Worker } \
5278*61046927SAndroid Build Coastguard Worker } while (0)
5279*61046927SAndroid Build Coastguard Worker
5280*61046927SAndroid Build Coastguard Worker #define NIR_PASS(progress, nir, pass, ...) _PASS(pass, nir, { \
5281*61046927SAndroid Build Coastguard Worker nir_metadata_set_validation_flag(nir); \
5282*61046927SAndroid Build Coastguard Worker if (should_print_nir(nir)) \
5283*61046927SAndroid Build Coastguard Worker printf("%s\n", #pass); \
5284*61046927SAndroid Build Coastguard Worker if (pass(nir, ##__VA_ARGS__)) { \
5285*61046927SAndroid Build Coastguard Worker nir_validate_shader(nir, "after " #pass " in " __FILE__); \
5286*61046927SAndroid Build Coastguard Worker UNUSED bool _; \
5287*61046927SAndroid Build Coastguard Worker progress = true; \
5288*61046927SAndroid Build Coastguard Worker if (should_print_nir(nir)) \
5289*61046927SAndroid Build Coastguard Worker nir_print_shader(nir, stdout); \
5290*61046927SAndroid Build Coastguard Worker nir_metadata_check_validation_flag(nir); \
5291*61046927SAndroid Build Coastguard Worker } \
5292*61046927SAndroid Build Coastguard Worker })
5293*61046927SAndroid Build Coastguard Worker
5294*61046927SAndroid Build Coastguard Worker #define NIR_PASS_V(nir, pass, ...) _PASS(pass, nir, { \
5295*61046927SAndroid Build Coastguard Worker if (should_print_nir(nir)) \
5296*61046927SAndroid Build Coastguard Worker printf("%s\n", #pass); \
5297*61046927SAndroid Build Coastguard Worker pass(nir, ##__VA_ARGS__); \
5298*61046927SAndroid Build Coastguard Worker nir_validate_shader(nir, "after " #pass " in " __FILE__); \
5299*61046927SAndroid Build Coastguard Worker if (should_print_nir(nir)) \
5300*61046927SAndroid Build Coastguard Worker nir_print_shader(nir, stdout); \
5301*61046927SAndroid Build Coastguard Worker })
5302*61046927SAndroid Build Coastguard Worker
5303*61046927SAndroid Build Coastguard Worker #define _NIR_LOOP_PASS(progress, idempotent, skip, nir, pass, ...) \
5304*61046927SAndroid Build Coastguard Worker do { \
5305*61046927SAndroid Build Coastguard Worker bool nir_loop_pass_progress = false; \
5306*61046927SAndroid Build Coastguard Worker if (!_mesa_set_search(skip, (void (*)())&pass)) \
5307*61046927SAndroid Build Coastguard Worker NIR_PASS(nir_loop_pass_progress, nir, pass, ##__VA_ARGS__); \
5308*61046927SAndroid Build Coastguard Worker if (nir_loop_pass_progress) \
5309*61046927SAndroid Build Coastguard Worker _mesa_set_clear(skip, NULL); \
5310*61046927SAndroid Build Coastguard Worker if (idempotent || !nir_loop_pass_progress) \
5311*61046927SAndroid Build Coastguard Worker _mesa_set_add(skip, (void (*)())&pass); \
5312*61046927SAndroid Build Coastguard Worker UNUSED bool _ = false; \
5313*61046927SAndroid Build Coastguard Worker progress |= nir_loop_pass_progress; \
5314*61046927SAndroid Build Coastguard Worker } while (0)
5315*61046927SAndroid Build Coastguard Worker
5316*61046927SAndroid Build Coastguard Worker /* Helper to skip a pass if no different passes have made progress since it was
5317*61046927SAndroid Build Coastguard Worker * previously run. Note that two passes are considered the same if they have
5318*61046927SAndroid Build Coastguard Worker * the same function pointer, even if they used different options.
5319*61046927SAndroid Build Coastguard Worker *
5320*61046927SAndroid Build Coastguard Worker * The usage of this is mostly identical to NIR_PASS. "skip" is a "struct set *"
5321*61046927SAndroid Build Coastguard Worker * (created by _mesa_pointer_set_create) which the macro uses to keep track of
5322*61046927SAndroid Build Coastguard Worker * already run passes.
5323*61046927SAndroid Build Coastguard Worker *
5324*61046927SAndroid Build Coastguard Worker * Example:
5325*61046927SAndroid Build Coastguard Worker * bool progress = true;
5326*61046927SAndroid Build Coastguard Worker * struct set *skip = _mesa_pointer_set_create(NULL);
5327*61046927SAndroid Build Coastguard Worker * while (progress) {
5328*61046927SAndroid Build Coastguard Worker * progress = false;
5329*61046927SAndroid Build Coastguard Worker * NIR_LOOP_PASS(progress, skip, nir, pass1);
5330*61046927SAndroid Build Coastguard Worker * NIR_LOOP_PASS_NOT_IDEMPOTENT(progress, skip, nir, nir_opt_algebraic);
5331*61046927SAndroid Build Coastguard Worker * NIR_LOOP_PASS(progress, skip, nir, pass2);
5332*61046927SAndroid Build Coastguard Worker * ...
5333*61046927SAndroid Build Coastguard Worker * }
5334*61046927SAndroid Build Coastguard Worker * _mesa_set_destroy(skip, NULL);
5335*61046927SAndroid Build Coastguard Worker *
5336*61046927SAndroid Build Coastguard Worker * You shouldn't mix usage of this with the NIR_PASS set of helpers, without
5337*61046927SAndroid Build Coastguard Worker * using a new "skip" in-between.
5338*61046927SAndroid Build Coastguard Worker */
5339*61046927SAndroid Build Coastguard Worker #define NIR_LOOP_PASS(progress, skip, nir, pass, ...) \
5340*61046927SAndroid Build Coastguard Worker _NIR_LOOP_PASS(progress, true, skip, nir, pass, ##__VA_ARGS__)
5341*61046927SAndroid Build Coastguard Worker
5342*61046927SAndroid Build Coastguard Worker /* Like NIR_LOOP_PASS, but use this for passes which may make further progress
5343*61046927SAndroid Build Coastguard Worker * when repeated.
5344*61046927SAndroid Build Coastguard Worker */
5345*61046927SAndroid Build Coastguard Worker #define NIR_LOOP_PASS_NOT_IDEMPOTENT(progress, skip, nir, pass, ...) \
5346*61046927SAndroid Build Coastguard Worker _NIR_LOOP_PASS(progress, false, skip, nir, pass, ##__VA_ARGS__)
5347*61046927SAndroid Build Coastguard Worker
5348*61046927SAndroid Build Coastguard Worker #define NIR_SKIP(name) should_skip_nir(#name)
5349*61046927SAndroid Build Coastguard Worker
5350*61046927SAndroid Build Coastguard Worker /** An instruction filtering callback with writemask
5351*61046927SAndroid Build Coastguard Worker *
5352*61046927SAndroid Build Coastguard Worker * Returns true if the instruction should be processed with the associated
5353*61046927SAndroid Build Coastguard Worker * writemask and false otherwise.
5354*61046927SAndroid Build Coastguard Worker */
5355*61046927SAndroid Build Coastguard Worker typedef bool (*nir_instr_writemask_filter_cb)(const nir_instr *,
5356*61046927SAndroid Build Coastguard Worker unsigned writemask, const void *);
5357*61046927SAndroid Build Coastguard Worker
5358*61046927SAndroid Build Coastguard Worker /** A simple instruction lowering callback
5359*61046927SAndroid Build Coastguard Worker *
5360*61046927SAndroid Build Coastguard Worker * Many instruction lowering passes can be written as a simple function which
5361*61046927SAndroid Build Coastguard Worker * takes an instruction as its input and returns a sequence of instructions
5362*61046927SAndroid Build Coastguard Worker * that implement the consumed instruction. This function type represents
5363*61046927SAndroid Build Coastguard Worker * such a lowering function. When called, a function with this prototype
5364*61046927SAndroid Build Coastguard Worker * should either return NULL indicating that no lowering needs to be done or
5365*61046927SAndroid Build Coastguard Worker * emit a sequence of instructions using the provided builder (whose cursor
5366*61046927SAndroid Build Coastguard Worker * will already be placed after the instruction to be lowered) and return the
5367*61046927SAndroid Build Coastguard Worker * resulting nir_def.
5368*61046927SAndroid Build Coastguard Worker */
5369*61046927SAndroid Build Coastguard Worker typedef nir_def *(*nir_lower_instr_cb)(struct nir_builder *,
5370*61046927SAndroid Build Coastguard Worker nir_instr *, void *);
5371*61046927SAndroid Build Coastguard Worker
5372*61046927SAndroid Build Coastguard Worker /**
5373*61046927SAndroid Build Coastguard Worker * Special return value for nir_lower_instr_cb when some progress occurred
5374*61046927SAndroid Build Coastguard Worker * (like changing an input to the instr) that didn't result in a replacement
5375*61046927SAndroid Build Coastguard Worker * SSA def being generated.
5376*61046927SAndroid Build Coastguard Worker */
5377*61046927SAndroid Build Coastguard Worker #define NIR_LOWER_INSTR_PROGRESS ((nir_def *)(uintptr_t)1)
5378*61046927SAndroid Build Coastguard Worker
5379*61046927SAndroid Build Coastguard Worker /**
5380*61046927SAndroid Build Coastguard Worker * Special return value for nir_lower_instr_cb when some progress occurred
5381*61046927SAndroid Build Coastguard Worker * that should remove the current instruction that doesn't create an output
5382*61046927SAndroid Build Coastguard Worker * (like a store)
5383*61046927SAndroid Build Coastguard Worker */
5384*61046927SAndroid Build Coastguard Worker
5385*61046927SAndroid Build Coastguard Worker #define NIR_LOWER_INSTR_PROGRESS_REPLACE ((nir_def *)(uintptr_t)2)
5386*61046927SAndroid Build Coastguard Worker
5387*61046927SAndroid Build Coastguard Worker /** Iterate over all the instructions in a nir_function_impl and lower them
5388*61046927SAndroid Build Coastguard Worker * using the provided callbacks
5389*61046927SAndroid Build Coastguard Worker *
5390*61046927SAndroid Build Coastguard Worker * This function implements the guts of a standard lowering pass for you. It
5391*61046927SAndroid Build Coastguard Worker * iterates over all of the instructions in a nir_function_impl and calls the
5392*61046927SAndroid Build Coastguard Worker * filter callback on each one. If the filter callback returns true, it then
5393*61046927SAndroid Build Coastguard Worker * calls the lowering call back on the instruction. (Splitting it this way
5394*61046927SAndroid Build Coastguard Worker * allows us to avoid some save/restore work for instructions we know won't be
5395*61046927SAndroid Build Coastguard Worker * lowered.) If the instruction is dead after the lowering is complete, it
5396*61046927SAndroid Build Coastguard Worker * will be removed. If new instructions are added, the lowering callback will
5397*61046927SAndroid Build Coastguard Worker * also be called on them in case multiple lowerings are required.
5398*61046927SAndroid Build Coastguard Worker *
5399*61046927SAndroid Build Coastguard Worker * If the callback indicates that the original instruction is replaced (either
5400*61046927SAndroid Build Coastguard Worker * through a new SSA def or NIR_LOWER_INSTR_PROGRESS_REPLACE), then the
5401*61046927SAndroid Build Coastguard Worker * instruction is removed along with any now-dead SSA defs it used.
5402*61046927SAndroid Build Coastguard Worker *
5403*61046927SAndroid Build Coastguard Worker * The metadata for the nir_function_impl will also be updated. If any blocks
5404*61046927SAndroid Build Coastguard Worker * are added (they cannot be removed), dominance and block indices will be
5405*61046927SAndroid Build Coastguard Worker * invalidated.
5406*61046927SAndroid Build Coastguard Worker */
5407*61046927SAndroid Build Coastguard Worker bool nir_function_impl_lower_instructions(nir_function_impl *impl,
5408*61046927SAndroid Build Coastguard Worker nir_instr_filter_cb filter,
5409*61046927SAndroid Build Coastguard Worker nir_lower_instr_cb lower,
5410*61046927SAndroid Build Coastguard Worker void *cb_data);
5411*61046927SAndroid Build Coastguard Worker bool nir_shader_lower_instructions(nir_shader *shader,
5412*61046927SAndroid Build Coastguard Worker nir_instr_filter_cb filter,
5413*61046927SAndroid Build Coastguard Worker nir_lower_instr_cb lower,
5414*61046927SAndroid Build Coastguard Worker void *cb_data);
5415*61046927SAndroid Build Coastguard Worker
5416*61046927SAndroid Build Coastguard Worker void nir_calc_dominance_impl(nir_function_impl *impl);
5417*61046927SAndroid Build Coastguard Worker void nir_calc_dominance(nir_shader *shader);
5418*61046927SAndroid Build Coastguard Worker
5419*61046927SAndroid Build Coastguard Worker nir_block *nir_dominance_lca(nir_block *b1, nir_block *b2);
5420*61046927SAndroid Build Coastguard Worker bool nir_block_dominates(nir_block *parent, nir_block *child);
5421*61046927SAndroid Build Coastguard Worker bool nir_block_is_unreachable(nir_block *block);
5422*61046927SAndroid Build Coastguard Worker
5423*61046927SAndroid Build Coastguard Worker void nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp);
5424*61046927SAndroid Build Coastguard Worker void nir_dump_dom_tree(nir_shader *shader, FILE *fp);
5425*61046927SAndroid Build Coastguard Worker
5426*61046927SAndroid Build Coastguard Worker void nir_dump_dom_frontier_impl(nir_function_impl *impl, FILE *fp);
5427*61046927SAndroid Build Coastguard Worker void nir_dump_dom_frontier(nir_shader *shader, FILE *fp);
5428*61046927SAndroid Build Coastguard Worker
5429*61046927SAndroid Build Coastguard Worker void nir_dump_cfg_impl(nir_function_impl *impl, FILE *fp);
5430*61046927SAndroid Build Coastguard Worker void nir_dump_cfg(nir_shader *shader, FILE *fp);
5431*61046927SAndroid Build Coastguard Worker
5432*61046927SAndroid Build Coastguard Worker void nir_gs_count_vertices_and_primitives(const nir_shader *shader,
5433*61046927SAndroid Build Coastguard Worker int *out_vtxcnt,
5434*61046927SAndroid Build Coastguard Worker int *out_prmcnt,
5435*61046927SAndroid Build Coastguard Worker int *out_decomposed_prmcnt,
5436*61046927SAndroid Build Coastguard Worker unsigned num_streams);
5437*61046927SAndroid Build Coastguard Worker
5438*61046927SAndroid Build Coastguard Worker typedef enum {
5439*61046927SAndroid Build Coastguard Worker nir_group_all,
5440*61046927SAndroid Build Coastguard Worker nir_group_same_resource_only,
5441*61046927SAndroid Build Coastguard Worker } nir_load_grouping;
5442*61046927SAndroid Build Coastguard Worker
5443*61046927SAndroid Build Coastguard Worker void nir_group_loads(nir_shader *shader, nir_load_grouping grouping,
5444*61046927SAndroid Build Coastguard Worker unsigned max_distance);
5445*61046927SAndroid Build Coastguard Worker
5446*61046927SAndroid Build Coastguard Worker bool nir_shrink_vec_array_vars(nir_shader *shader, nir_variable_mode modes);
5447*61046927SAndroid Build Coastguard Worker bool nir_split_array_vars(nir_shader *shader, nir_variable_mode modes);
5448*61046927SAndroid Build Coastguard Worker bool nir_split_var_copies(nir_shader *shader);
5449*61046927SAndroid Build Coastguard Worker bool nir_split_per_member_structs(nir_shader *shader);
5450*61046927SAndroid Build Coastguard Worker bool nir_split_struct_vars(nir_shader *shader, nir_variable_mode modes);
5451*61046927SAndroid Build Coastguard Worker
5452*61046927SAndroid Build Coastguard Worker bool nir_lower_returns_impl(nir_function_impl *impl);
5453*61046927SAndroid Build Coastguard Worker bool nir_lower_returns(nir_shader *shader);
5454*61046927SAndroid Build Coastguard Worker
5455*61046927SAndroid Build Coastguard Worker void nir_inline_function_impl(struct nir_builder *b,
5456*61046927SAndroid Build Coastguard Worker const nir_function_impl *impl,
5457*61046927SAndroid Build Coastguard Worker nir_def **params,
5458*61046927SAndroid Build Coastguard Worker struct hash_table *shader_var_remap);
5459*61046927SAndroid Build Coastguard Worker bool nir_inline_functions(nir_shader *shader);
5460*61046927SAndroid Build Coastguard Worker void nir_cleanup_functions(nir_shader *shader);
5461*61046927SAndroid Build Coastguard Worker bool nir_link_shader_functions(nir_shader *shader,
5462*61046927SAndroid Build Coastguard Worker const nir_shader *link_shader);
5463*61046927SAndroid Build Coastguard Worker
5464*61046927SAndroid Build Coastguard Worker void nir_find_inlinable_uniforms(nir_shader *shader);
5465*61046927SAndroid Build Coastguard Worker void nir_inline_uniforms(nir_shader *shader, unsigned num_uniforms,
5466*61046927SAndroid Build Coastguard Worker const uint32_t *uniform_values,
5467*61046927SAndroid Build Coastguard Worker const uint16_t *uniform_dw_offsets);
5468*61046927SAndroid Build Coastguard Worker bool nir_collect_src_uniforms(const nir_src *src, int component,
5469*61046927SAndroid Build Coastguard Worker uint32_t *uni_offsets, uint8_t *num_offsets,
5470*61046927SAndroid Build Coastguard Worker unsigned max_num_bo, unsigned max_offset);
5471*61046927SAndroid Build Coastguard Worker void nir_add_inlinable_uniforms(const nir_src *cond, nir_loop_info *info,
5472*61046927SAndroid Build Coastguard Worker uint32_t *uni_offsets, uint8_t *num_offsets,
5473*61046927SAndroid Build Coastguard Worker unsigned max_num_bo, unsigned max_offset);
5474*61046927SAndroid Build Coastguard Worker
5475*61046927SAndroid Build Coastguard Worker bool nir_propagate_invariant(nir_shader *shader, bool invariant_prim);
5476*61046927SAndroid Build Coastguard Worker
5477*61046927SAndroid Build Coastguard Worker void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, nir_shader *shader);
5478*61046927SAndroid Build Coastguard Worker void nir_lower_deref_copy_instr(struct nir_builder *b,
5479*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *copy);
5480*61046927SAndroid Build Coastguard Worker bool nir_lower_var_copies(nir_shader *shader);
5481*61046927SAndroid Build Coastguard Worker
5482*61046927SAndroid Build Coastguard Worker bool nir_opt_memcpy(nir_shader *shader);
5483*61046927SAndroid Build Coastguard Worker bool nir_lower_memcpy(nir_shader *shader);
5484*61046927SAndroid Build Coastguard Worker
5485*61046927SAndroid Build Coastguard Worker void nir_fixup_deref_modes(nir_shader *shader);
5486*61046927SAndroid Build Coastguard Worker void nir_fixup_deref_types(nir_shader *shader);
5487*61046927SAndroid Build Coastguard Worker
5488*61046927SAndroid Build Coastguard Worker bool nir_lower_global_vars_to_local(nir_shader *shader);
5489*61046927SAndroid Build Coastguard Worker
5490*61046927SAndroid Build Coastguard Worker typedef enum {
5491*61046927SAndroid Build Coastguard Worker nir_lower_direct_array_deref_of_vec_load = (1 << 0),
5492*61046927SAndroid Build Coastguard Worker nir_lower_indirect_array_deref_of_vec_load = (1 << 1),
5493*61046927SAndroid Build Coastguard Worker nir_lower_direct_array_deref_of_vec_store = (1 << 2),
5494*61046927SAndroid Build Coastguard Worker nir_lower_indirect_array_deref_of_vec_store = (1 << 3),
5495*61046927SAndroid Build Coastguard Worker } nir_lower_array_deref_of_vec_options;
5496*61046927SAndroid Build Coastguard Worker
5497*61046927SAndroid Build Coastguard Worker bool nir_lower_array_deref_of_vec(nir_shader *shader, nir_variable_mode modes,
5498*61046927SAndroid Build Coastguard Worker bool (*filter)(nir_variable *),
5499*61046927SAndroid Build Coastguard Worker nir_lower_array_deref_of_vec_options options);
5500*61046927SAndroid Build Coastguard Worker
5501*61046927SAndroid Build Coastguard Worker bool nir_lower_indirect_derefs(nir_shader *shader, nir_variable_mode modes,
5502*61046927SAndroid Build Coastguard Worker uint32_t max_lower_array_len);
5503*61046927SAndroid Build Coastguard Worker
5504*61046927SAndroid Build Coastguard Worker bool nir_lower_indirect_var_derefs(nir_shader *shader,
5505*61046927SAndroid Build Coastguard Worker const struct set *vars);
5506*61046927SAndroid Build Coastguard Worker
5507*61046927SAndroid Build Coastguard Worker bool nir_lower_locals_to_regs(nir_shader *shader, uint8_t bool_bitsize);
5508*61046927SAndroid Build Coastguard Worker
5509*61046927SAndroid Build Coastguard Worker bool nir_lower_io_to_temporaries(nir_shader *shader,
5510*61046927SAndroid Build Coastguard Worker nir_function_impl *entrypoint,
5511*61046927SAndroid Build Coastguard Worker bool outputs, bool inputs);
5512*61046927SAndroid Build Coastguard Worker
5513*61046927SAndroid Build Coastguard Worker bool nir_lower_vars_to_scratch(nir_shader *shader,
5514*61046927SAndroid Build Coastguard Worker nir_variable_mode modes,
5515*61046927SAndroid Build Coastguard Worker int size_threshold,
5516*61046927SAndroid Build Coastguard Worker glsl_type_size_align_func variable_size_align,
5517*61046927SAndroid Build Coastguard Worker glsl_type_size_align_func scratch_layout_size_align);
5518*61046927SAndroid Build Coastguard Worker
5519*61046927SAndroid Build Coastguard Worker void nir_lower_clip_halfz(nir_shader *shader);
5520*61046927SAndroid Build Coastguard Worker
5521*61046927SAndroid Build Coastguard Worker void nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint);
5522*61046927SAndroid Build Coastguard Worker
5523*61046927SAndroid Build Coastguard Worker void nir_gather_types(nir_function_impl *impl,
5524*61046927SAndroid Build Coastguard Worker BITSET_WORD *float_types,
5525*61046927SAndroid Build Coastguard Worker BITSET_WORD *int_types);
5526*61046927SAndroid Build Coastguard Worker
5527*61046927SAndroid Build Coastguard Worker void nir_assign_var_locations(nir_shader *shader, nir_variable_mode mode,
5528*61046927SAndroid Build Coastguard Worker unsigned *size,
5529*61046927SAndroid Build Coastguard Worker int (*type_size)(const struct glsl_type *, bool));
5530*61046927SAndroid Build Coastguard Worker
5531*61046927SAndroid Build Coastguard Worker /* Some helpers to do very simple linking */
5532*61046927SAndroid Build Coastguard Worker bool nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer);
5533*61046927SAndroid Build Coastguard Worker bool nir_remove_unused_io_vars(nir_shader *shader, nir_variable_mode mode,
5534*61046927SAndroid Build Coastguard Worker uint64_t *used_by_other_stage,
5535*61046927SAndroid Build Coastguard Worker uint64_t *used_by_other_stage_patches);
5536*61046927SAndroid Build Coastguard Worker void nir_compact_varyings(nir_shader *producer, nir_shader *consumer,
5537*61046927SAndroid Build Coastguard Worker bool default_to_smooth_interp);
5538*61046927SAndroid Build Coastguard Worker void nir_link_xfb_varyings(nir_shader *producer, nir_shader *consumer);
5539*61046927SAndroid Build Coastguard Worker bool nir_link_opt_varyings(nir_shader *producer, nir_shader *consumer);
5540*61046927SAndroid Build Coastguard Worker void nir_link_varying_precision(nir_shader *producer, nir_shader *consumer);
5541*61046927SAndroid Build Coastguard Worker nir_variable *nir_clone_uniform_variable(nir_shader *nir,
5542*61046927SAndroid Build Coastguard Worker nir_variable *uniform, bool spirv);
5543*61046927SAndroid Build Coastguard Worker nir_deref_instr *nir_clone_deref_instr(struct nir_builder *b,
5544*61046927SAndroid Build Coastguard Worker nir_variable *var,
5545*61046927SAndroid Build Coastguard Worker nir_deref_instr *deref);
5546*61046927SAndroid Build Coastguard Worker
5547*61046927SAndroid Build Coastguard Worker
5548*61046927SAndroid Build Coastguard Worker /* Return status from nir_opt_varyings. */
5549*61046927SAndroid Build Coastguard Worker typedef enum {
5550*61046927SAndroid Build Coastguard Worker /* Whether the IR changed such that NIR optimizations should be run, such
5551*61046927SAndroid Build Coastguard Worker * as due to removal of loads and stores. IO semantic changes such as
5552*61046927SAndroid Build Coastguard Worker * compaction don't count as IR changes because they don't affect NIR
5553*61046927SAndroid Build Coastguard Worker * optimizations.
5554*61046927SAndroid Build Coastguard Worker */
5555*61046927SAndroid Build Coastguard Worker nir_progress_producer = BITFIELD_BIT(0),
5556*61046927SAndroid Build Coastguard Worker nir_progress_consumer = BITFIELD_BIT(1),
5557*61046927SAndroid Build Coastguard Worker } nir_opt_varyings_progress;
5558*61046927SAndroid Build Coastguard Worker
5559*61046927SAndroid Build Coastguard Worker nir_opt_varyings_progress
5560*61046927SAndroid Build Coastguard Worker nir_opt_varyings(nir_shader *producer, nir_shader *consumer, bool spirv,
5561*61046927SAndroid Build Coastguard Worker unsigned max_uniform_components, unsigned max_ubos_per_stage);
5562*61046927SAndroid Build Coastguard Worker
5563*61046927SAndroid Build Coastguard Worker bool nir_slot_is_sysval_output(gl_varying_slot slot,
5564*61046927SAndroid Build Coastguard Worker gl_shader_stage next_shader);
5565*61046927SAndroid Build Coastguard Worker bool nir_slot_is_varying(gl_varying_slot slot);
5566*61046927SAndroid Build Coastguard Worker bool nir_slot_is_sysval_output_and_varying(gl_varying_slot slot,
5567*61046927SAndroid Build Coastguard Worker gl_shader_stage next_shader);
5568*61046927SAndroid Build Coastguard Worker bool nir_remove_varying(nir_intrinsic_instr *intr, gl_shader_stage next_shader);
5569*61046927SAndroid Build Coastguard Worker bool nir_remove_sysval_output(nir_intrinsic_instr *intr);
5570*61046927SAndroid Build Coastguard Worker
5571*61046927SAndroid Build Coastguard Worker bool nir_lower_amul(nir_shader *shader,
5572*61046927SAndroid Build Coastguard Worker int (*type_size)(const struct glsl_type *, bool));
5573*61046927SAndroid Build Coastguard Worker
5574*61046927SAndroid Build Coastguard Worker bool nir_lower_ubo_vec4(nir_shader *shader);
5575*61046927SAndroid Build Coastguard Worker
5576*61046927SAndroid Build Coastguard Worker void nir_sort_variables_by_location(nir_shader *shader, nir_variable_mode mode);
5577*61046927SAndroid Build Coastguard Worker void nir_assign_io_var_locations(nir_shader *shader,
5578*61046927SAndroid Build Coastguard Worker nir_variable_mode mode,
5579*61046927SAndroid Build Coastguard Worker unsigned *size,
5580*61046927SAndroid Build Coastguard Worker gl_shader_stage stage);
5581*61046927SAndroid Build Coastguard Worker
5582*61046927SAndroid Build Coastguard Worker typedef enum {
5583*61046927SAndroid Build Coastguard Worker /* If set, this causes all 64-bit IO operations to be lowered on-the-fly
5584*61046927SAndroid Build Coastguard Worker * to 32-bit operations. This is only valid for nir_var_shader_in/out
5585*61046927SAndroid Build Coastguard Worker * modes.
5586*61046927SAndroid Build Coastguard Worker *
5587*61046927SAndroid Build Coastguard Worker * Note that this destroys dual-slot information i.e. whether an input
5588*61046927SAndroid Build Coastguard Worker * occupies the low or high half of dvec4. Instead, it adds an offset of 1
5589*61046927SAndroid Build Coastguard Worker * to the load (which is ambiguous) and expects driver locations of inputs
5590*61046927SAndroid Build Coastguard Worker * to be final, which prevents any further optimizations.
5591*61046927SAndroid Build Coastguard Worker *
5592*61046927SAndroid Build Coastguard Worker * TODO: remove this in favor of nir_lower_io_lower_64bit_to_32_new.
5593*61046927SAndroid Build Coastguard Worker */
5594*61046927SAndroid Build Coastguard Worker nir_lower_io_lower_64bit_to_32 = (1 << 0),
5595*61046927SAndroid Build Coastguard Worker
5596*61046927SAndroid Build Coastguard Worker /* If set, this causes the subset of 64-bit IO operations involving floats to be lowered on-the-fly
5597*61046927SAndroid Build Coastguard Worker * to 32-bit operations. This is only valid for nir_var_shader_in/out
5598*61046927SAndroid Build Coastguard Worker * modes.
5599*61046927SAndroid Build Coastguard Worker */
5600*61046927SAndroid Build Coastguard Worker nir_lower_io_lower_64bit_float_to_32 = (1 << 1),
5601*61046927SAndroid Build Coastguard Worker
5602*61046927SAndroid Build Coastguard Worker /* This causes all 64-bit IO operations to be lowered to 32-bit operations.
5603*61046927SAndroid Build Coastguard Worker * This is only valid for nir_var_shader_in/out modes.
5604*61046927SAndroid Build Coastguard Worker *
5605*61046927SAndroid Build Coastguard Worker * Only VS inputs: Dual slot information is preserved as nir_io_semantics::
5606*61046927SAndroid Build Coastguard Worker * high_dvec2 and gathered into shader_info::dual_slot_inputs, so that
5607*61046927SAndroid Build Coastguard Worker * the shader can be arbitrarily optimized and the low or high half of
5608*61046927SAndroid Build Coastguard Worker * dvec4 can be DCE'd independently without affecting the other half.
5609*61046927SAndroid Build Coastguard Worker */
5610*61046927SAndroid Build Coastguard Worker nir_lower_io_lower_64bit_to_32_new = (1 << 2),
5611*61046927SAndroid Build Coastguard Worker } nir_lower_io_options;
5612*61046927SAndroid Build Coastguard Worker bool nir_lower_io(nir_shader *shader,
5613*61046927SAndroid Build Coastguard Worker nir_variable_mode modes,
5614*61046927SAndroid Build Coastguard Worker int (*type_size)(const struct glsl_type *, bool),
5615*61046927SAndroid Build Coastguard Worker nir_lower_io_options);
5616*61046927SAndroid Build Coastguard Worker
5617*61046927SAndroid Build Coastguard Worker bool nir_io_add_const_offset_to_base(nir_shader *nir, nir_variable_mode modes);
5618*61046927SAndroid Build Coastguard Worker bool nir_lower_color_inputs(nir_shader *nir);
5619*61046927SAndroid Build Coastguard Worker void nir_lower_io_passes(nir_shader *nir, bool renumber_vs_inputs);
5620*61046927SAndroid Build Coastguard Worker bool nir_io_add_intrinsic_xfb_info(nir_shader *nir);
5621*61046927SAndroid Build Coastguard Worker
5622*61046927SAndroid Build Coastguard Worker bool
5623*61046927SAndroid Build Coastguard Worker nir_lower_vars_to_explicit_types(nir_shader *shader,
5624*61046927SAndroid Build Coastguard Worker nir_variable_mode modes,
5625*61046927SAndroid Build Coastguard Worker glsl_type_size_align_func type_info);
5626*61046927SAndroid Build Coastguard Worker void
5627*61046927SAndroid Build Coastguard Worker nir_gather_explicit_io_initializers(nir_shader *shader,
5628*61046927SAndroid Build Coastguard Worker void *dst, size_t dst_size,
5629*61046927SAndroid Build Coastguard Worker nir_variable_mode mode);
5630*61046927SAndroid Build Coastguard Worker
5631*61046927SAndroid Build Coastguard Worker bool nir_lower_vec3_to_vec4(nir_shader *shader, nir_variable_mode modes);
5632*61046927SAndroid Build Coastguard Worker
5633*61046927SAndroid Build Coastguard Worker typedef enum {
5634*61046927SAndroid Build Coastguard Worker /**
5635*61046927SAndroid Build Coastguard Worker * An address format which is a simple 32-bit global GPU address.
5636*61046927SAndroid Build Coastguard Worker */
5637*61046927SAndroid Build Coastguard Worker nir_address_format_32bit_global,
5638*61046927SAndroid Build Coastguard Worker
5639*61046927SAndroid Build Coastguard Worker /**
5640*61046927SAndroid Build Coastguard Worker * An address format which is a simple 64-bit global GPU address.
5641*61046927SAndroid Build Coastguard Worker */
5642*61046927SAndroid Build Coastguard Worker nir_address_format_64bit_global,
5643*61046927SAndroid Build Coastguard Worker
5644*61046927SAndroid Build Coastguard Worker /**
5645*61046927SAndroid Build Coastguard Worker * An address format which is a 64-bit global GPU address encoded as a
5646*61046927SAndroid Build Coastguard Worker * 2x32-bit vector.
5647*61046927SAndroid Build Coastguard Worker */
5648*61046927SAndroid Build Coastguard Worker nir_address_format_2x32bit_global,
5649*61046927SAndroid Build Coastguard Worker
5650*61046927SAndroid Build Coastguard Worker /**
5651*61046927SAndroid Build Coastguard Worker * An address format which is a 64-bit global base address and a 32-bit
5652*61046927SAndroid Build Coastguard Worker * offset.
5653*61046927SAndroid Build Coastguard Worker *
5654*61046927SAndroid Build Coastguard Worker * This is identical to 64bit_bounded_global except that bounds checking
5655*61046927SAndroid Build Coastguard Worker * is not applied when lowering to global access. Even though the size is
5656*61046927SAndroid Build Coastguard Worker * never used for an actual bounds check, it needs to be valid so we can
5657*61046927SAndroid Build Coastguard Worker * lower deref_buffer_array_length properly.
5658*61046927SAndroid Build Coastguard Worker */
5659*61046927SAndroid Build Coastguard Worker nir_address_format_64bit_global_32bit_offset,
5660*61046927SAndroid Build Coastguard Worker
5661*61046927SAndroid Build Coastguard Worker /**
5662*61046927SAndroid Build Coastguard Worker * An address format which is a bounds-checked 64-bit global GPU address.
5663*61046927SAndroid Build Coastguard Worker *
5664*61046927SAndroid Build Coastguard Worker * The address is comprised as a 32-bit vec4 where .xy are a uint64_t base
5665*61046927SAndroid Build Coastguard Worker * address stored with the low bits in .x and high bits in .y, .z is a
5666*61046927SAndroid Build Coastguard Worker * size, and .w is an offset. When the final I/O operation is lowered, .w
5667*61046927SAndroid Build Coastguard Worker * is checked against .z and the operation is predicated on the result.
5668*61046927SAndroid Build Coastguard Worker */
5669*61046927SAndroid Build Coastguard Worker nir_address_format_64bit_bounded_global,
5670*61046927SAndroid Build Coastguard Worker
5671*61046927SAndroid Build Coastguard Worker /**
5672*61046927SAndroid Build Coastguard Worker * An address format which is comprised of a vec2 where the first
5673*61046927SAndroid Build Coastguard Worker * component is a buffer index and the second is an offset.
5674*61046927SAndroid Build Coastguard Worker */
5675*61046927SAndroid Build Coastguard Worker nir_address_format_32bit_index_offset,
5676*61046927SAndroid Build Coastguard Worker
5677*61046927SAndroid Build Coastguard Worker /**
5678*61046927SAndroid Build Coastguard Worker * An address format which is a 64-bit value, where the high 32 bits
5679*61046927SAndroid Build Coastguard Worker * are a buffer index, and the low 32 bits are an offset.
5680*61046927SAndroid Build Coastguard Worker */
5681*61046927SAndroid Build Coastguard Worker nir_address_format_32bit_index_offset_pack64,
5682*61046927SAndroid Build Coastguard Worker
5683*61046927SAndroid Build Coastguard Worker /**
5684*61046927SAndroid Build Coastguard Worker * An address format which is comprised of a vec3 where the first two
5685*61046927SAndroid Build Coastguard Worker * components specify the buffer and the third is an offset.
5686*61046927SAndroid Build Coastguard Worker */
5687*61046927SAndroid Build Coastguard Worker nir_address_format_vec2_index_32bit_offset,
5688*61046927SAndroid Build Coastguard Worker
5689*61046927SAndroid Build Coastguard Worker /**
5690*61046927SAndroid Build Coastguard Worker * An address format which represents generic pointers with a 62-bit
5691*61046927SAndroid Build Coastguard Worker * pointer and a 2-bit enum in the top two bits. The top two bits have
5692*61046927SAndroid Build Coastguard Worker * the following meanings:
5693*61046927SAndroid Build Coastguard Worker *
5694*61046927SAndroid Build Coastguard Worker * - 0x0: Global memory
5695*61046927SAndroid Build Coastguard Worker * - 0x1: Shared memory
5696*61046927SAndroid Build Coastguard Worker * - 0x2: Scratch memory
5697*61046927SAndroid Build Coastguard Worker * - 0x3: Global memory
5698*61046927SAndroid Build Coastguard Worker *
5699*61046927SAndroid Build Coastguard Worker * The redundancy between 0x0 and 0x3 is because of Intel sign-extension of
5700*61046927SAndroid Build Coastguard Worker * addresses. Valid global memory addresses may naturally have either 0 or
5701*61046927SAndroid Build Coastguard Worker * ~0 as their high bits.
5702*61046927SAndroid Build Coastguard Worker *
5703*61046927SAndroid Build Coastguard Worker * Shared and scratch pointers are represented as 32-bit offsets with the
5704*61046927SAndroid Build Coastguard Worker * top 32 bits only being used for the enum. This allows us to avoid
5705*61046927SAndroid Build Coastguard Worker * 64-bit address calculations in a bunch of cases.
5706*61046927SAndroid Build Coastguard Worker */
5707*61046927SAndroid Build Coastguard Worker nir_address_format_62bit_generic,
5708*61046927SAndroid Build Coastguard Worker
5709*61046927SAndroid Build Coastguard Worker /**
5710*61046927SAndroid Build Coastguard Worker * An address format which is a simple 32-bit offset.
5711*61046927SAndroid Build Coastguard Worker */
5712*61046927SAndroid Build Coastguard Worker nir_address_format_32bit_offset,
5713*61046927SAndroid Build Coastguard Worker
5714*61046927SAndroid Build Coastguard Worker /**
5715*61046927SAndroid Build Coastguard Worker * An address format which is a simple 32-bit offset cast to 64-bit.
5716*61046927SAndroid Build Coastguard Worker */
5717*61046927SAndroid Build Coastguard Worker nir_address_format_32bit_offset_as_64bit,
5718*61046927SAndroid Build Coastguard Worker
5719*61046927SAndroid Build Coastguard Worker /**
5720*61046927SAndroid Build Coastguard Worker * An address format representing a purely logical addressing model. In
5721*61046927SAndroid Build Coastguard Worker * this model, all deref chains must be complete from the dereference
5722*61046927SAndroid Build Coastguard Worker * operation to the variable. Cast derefs are not allowed. These
5723*61046927SAndroid Build Coastguard Worker * addresses will be 32-bit scalars but the format is immaterial because
5724*61046927SAndroid Build Coastguard Worker * you can always chase the chain.
5725*61046927SAndroid Build Coastguard Worker */
5726*61046927SAndroid Build Coastguard Worker nir_address_format_logical,
5727*61046927SAndroid Build Coastguard Worker } nir_address_format;
5728*61046927SAndroid Build Coastguard Worker
5729*61046927SAndroid Build Coastguard Worker unsigned
5730*61046927SAndroid Build Coastguard Worker nir_address_format_bit_size(nir_address_format addr_format);
5731*61046927SAndroid Build Coastguard Worker
5732*61046927SAndroid Build Coastguard Worker unsigned
5733*61046927SAndroid Build Coastguard Worker nir_address_format_num_components(nir_address_format addr_format);
5734*61046927SAndroid Build Coastguard Worker
5735*61046927SAndroid Build Coastguard Worker static inline const struct glsl_type *
nir_address_format_to_glsl_type(nir_address_format addr_format)5736*61046927SAndroid Build Coastguard Worker nir_address_format_to_glsl_type(nir_address_format addr_format)
5737*61046927SAndroid Build Coastguard Worker {
5738*61046927SAndroid Build Coastguard Worker unsigned bit_size = nir_address_format_bit_size(addr_format);
5739*61046927SAndroid Build Coastguard Worker assert(bit_size == 32 || bit_size == 64);
5740*61046927SAndroid Build Coastguard Worker return glsl_vector_type(bit_size == 32 ? GLSL_TYPE_UINT : GLSL_TYPE_UINT64,
5741*61046927SAndroid Build Coastguard Worker nir_address_format_num_components(addr_format));
5742*61046927SAndroid Build Coastguard Worker }
5743*61046927SAndroid Build Coastguard Worker
5744*61046927SAndroid Build Coastguard Worker const nir_const_value *nir_address_format_null_value(nir_address_format addr_format);
5745*61046927SAndroid Build Coastguard Worker
5746*61046927SAndroid Build Coastguard Worker nir_def *nir_build_addr_iadd(struct nir_builder *b, nir_def *addr,
5747*61046927SAndroid Build Coastguard Worker nir_address_format addr_format,
5748*61046927SAndroid Build Coastguard Worker nir_variable_mode modes,
5749*61046927SAndroid Build Coastguard Worker nir_def *offset);
5750*61046927SAndroid Build Coastguard Worker
5751*61046927SAndroid Build Coastguard Worker nir_def *nir_build_addr_iadd_imm(struct nir_builder *b, nir_def *addr,
5752*61046927SAndroid Build Coastguard Worker nir_address_format addr_format,
5753*61046927SAndroid Build Coastguard Worker nir_variable_mode modes,
5754*61046927SAndroid Build Coastguard Worker int64_t offset);
5755*61046927SAndroid Build Coastguard Worker
5756*61046927SAndroid Build Coastguard Worker nir_def *nir_build_addr_ieq(struct nir_builder *b, nir_def *addr0, nir_def *addr1,
5757*61046927SAndroid Build Coastguard Worker nir_address_format addr_format);
5758*61046927SAndroid Build Coastguard Worker
5759*61046927SAndroid Build Coastguard Worker nir_def *nir_build_addr_isub(struct nir_builder *b, nir_def *addr0, nir_def *addr1,
5760*61046927SAndroid Build Coastguard Worker nir_address_format addr_format);
5761*61046927SAndroid Build Coastguard Worker
5762*61046927SAndroid Build Coastguard Worker nir_def *nir_explicit_io_address_from_deref(struct nir_builder *b,
5763*61046927SAndroid Build Coastguard Worker nir_deref_instr *deref,
5764*61046927SAndroid Build Coastguard Worker nir_def *base_addr,
5765*61046927SAndroid Build Coastguard Worker nir_address_format addr_format);
5766*61046927SAndroid Build Coastguard Worker
5767*61046927SAndroid Build Coastguard Worker bool nir_get_explicit_deref_align(nir_deref_instr *deref,
5768*61046927SAndroid Build Coastguard Worker bool default_to_type_align,
5769*61046927SAndroid Build Coastguard Worker uint32_t *align_mul,
5770*61046927SAndroid Build Coastguard Worker uint32_t *align_offset);
5771*61046927SAndroid Build Coastguard Worker
5772*61046927SAndroid Build Coastguard Worker void nir_lower_explicit_io_instr(struct nir_builder *b,
5773*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *io_instr,
5774*61046927SAndroid Build Coastguard Worker nir_def *addr,
5775*61046927SAndroid Build Coastguard Worker nir_address_format addr_format);
5776*61046927SAndroid Build Coastguard Worker
5777*61046927SAndroid Build Coastguard Worker bool nir_lower_explicit_io(nir_shader *shader,
5778*61046927SAndroid Build Coastguard Worker nir_variable_mode modes,
5779*61046927SAndroid Build Coastguard Worker nir_address_format);
5780*61046927SAndroid Build Coastguard Worker
5781*61046927SAndroid Build Coastguard Worker typedef struct {
5782*61046927SAndroid Build Coastguard Worker uint8_t num_components;
5783*61046927SAndroid Build Coastguard Worker uint8_t bit_size;
5784*61046927SAndroid Build Coastguard Worker uint16_t align;
5785*61046927SAndroid Build Coastguard Worker } nir_mem_access_size_align;
5786*61046927SAndroid Build Coastguard Worker
5787*61046927SAndroid Build Coastguard Worker /* clang-format off */
5788*61046927SAndroid Build Coastguard Worker typedef nir_mem_access_size_align
5789*61046927SAndroid Build Coastguard Worker (*nir_lower_mem_access_bit_sizes_cb)(nir_intrinsic_op intrin,
5790*61046927SAndroid Build Coastguard Worker uint8_t bytes,
5791*61046927SAndroid Build Coastguard Worker uint8_t bit_size,
5792*61046927SAndroid Build Coastguard Worker uint32_t align_mul,
5793*61046927SAndroid Build Coastguard Worker uint32_t align_offset,
5794*61046927SAndroid Build Coastguard Worker bool offset_is_const,
5795*61046927SAndroid Build Coastguard Worker const void *cb_data);
5796*61046927SAndroid Build Coastguard Worker /* clang-format on */
5797*61046927SAndroid Build Coastguard Worker
5798*61046927SAndroid Build Coastguard Worker typedef struct {
5799*61046927SAndroid Build Coastguard Worker nir_lower_mem_access_bit_sizes_cb callback;
5800*61046927SAndroid Build Coastguard Worker nir_variable_mode modes;
5801*61046927SAndroid Build Coastguard Worker bool may_lower_unaligned_stores_to_atomics;
5802*61046927SAndroid Build Coastguard Worker void *cb_data;
5803*61046927SAndroid Build Coastguard Worker } nir_lower_mem_access_bit_sizes_options;
5804*61046927SAndroid Build Coastguard Worker
5805*61046927SAndroid Build Coastguard Worker bool nir_lower_mem_access_bit_sizes(nir_shader *shader,
5806*61046927SAndroid Build Coastguard Worker const nir_lower_mem_access_bit_sizes_options *options);
5807*61046927SAndroid Build Coastguard Worker
5808*61046927SAndroid Build Coastguard Worker typedef struct {
5809*61046927SAndroid Build Coastguard Worker /* Lower load_ubo to be robust. Out-of-bounds loads will return UNDEFINED
5810*61046927SAndroid Build Coastguard Worker * values (not necessarily zero).
5811*61046927SAndroid Build Coastguard Worker */
5812*61046927SAndroid Build Coastguard Worker bool lower_ubo;
5813*61046927SAndroid Build Coastguard Worker
5814*61046927SAndroid Build Coastguard Worker /* Lower load_ssbo/store_ssbo/ssbo_atomic(_swap) to be robust. Out-of-bounds
5815*61046927SAndroid Build Coastguard Worker * loads and atomics will return UNDEFINED values (not necessarily zero).
5816*61046927SAndroid Build Coastguard Worker * Out-of-bounds stores and atomics CORRUPT the contents of the SSBO.
5817*61046927SAndroid Build Coastguard Worker *
5818*61046927SAndroid Build Coastguard Worker * This suffices for robustBufferAccess but not robustBufferAccess2.
5819*61046927SAndroid Build Coastguard Worker */
5820*61046927SAndroid Build Coastguard Worker bool lower_ssbo;
5821*61046927SAndroid Build Coastguard Worker
5822*61046927SAndroid Build Coastguard Worker /* Lower all image_load/image_store/image_atomic(_swap) instructions to be
5823*61046927SAndroid Build Coastguard Worker * robust. Out-of-bounds loads will return ZERO.
5824*61046927SAndroid Build Coastguard Worker *
5825*61046927SAndroid Build Coastguard Worker * This suffices for robustImageAccess but not robustImageAccess2.
5826*61046927SAndroid Build Coastguard Worker */
5827*61046927SAndroid Build Coastguard Worker bool lower_image;
5828*61046927SAndroid Build Coastguard Worker
5829*61046927SAndroid Build Coastguard Worker /* Lower all buffer image instructions as above. Implied by lower_image. */
5830*61046927SAndroid Build Coastguard Worker bool lower_buffer_image;
5831*61046927SAndroid Build Coastguard Worker
5832*61046927SAndroid Build Coastguard Worker /* Lower image_atomic(_swap) for all dimensions. Implied by lower_image. */
5833*61046927SAndroid Build Coastguard Worker bool lower_image_atomic;
5834*61046927SAndroid Build Coastguard Worker
5835*61046927SAndroid Build Coastguard Worker /* Vulkan's robustBufferAccess feature is only concerned with buffers that
5836*61046927SAndroid Build Coastguard Worker * are bound through descriptor sets, so shared memory is not included, but
5837*61046927SAndroid Build Coastguard Worker * it may be useful to enable this for debugging.
5838*61046927SAndroid Build Coastguard Worker */
5839*61046927SAndroid Build Coastguard Worker bool lower_shared;
5840*61046927SAndroid Build Coastguard Worker } nir_lower_robust_access_options;
5841*61046927SAndroid Build Coastguard Worker
5842*61046927SAndroid Build Coastguard Worker bool nir_lower_robust_access(nir_shader *s,
5843*61046927SAndroid Build Coastguard Worker const nir_lower_robust_access_options *opts);
5844*61046927SAndroid Build Coastguard Worker
5845*61046927SAndroid Build Coastguard Worker /* clang-format off */
5846*61046927SAndroid Build Coastguard Worker typedef bool (*nir_should_vectorize_mem_func)(unsigned align_mul,
5847*61046927SAndroid Build Coastguard Worker unsigned align_offset,
5848*61046927SAndroid Build Coastguard Worker unsigned bit_size,
5849*61046927SAndroid Build Coastguard Worker unsigned num_components,
5850*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *low,
5851*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *high,
5852*61046927SAndroid Build Coastguard Worker void *data);
5853*61046927SAndroid Build Coastguard Worker /* clang-format on */
5854*61046927SAndroid Build Coastguard Worker
5855*61046927SAndroid Build Coastguard Worker typedef struct {
5856*61046927SAndroid Build Coastguard Worker nir_should_vectorize_mem_func callback;
5857*61046927SAndroid Build Coastguard Worker nir_variable_mode modes;
5858*61046927SAndroid Build Coastguard Worker nir_variable_mode robust_modes;
5859*61046927SAndroid Build Coastguard Worker void *cb_data;
5860*61046927SAndroid Build Coastguard Worker bool has_shared2_amd;
5861*61046927SAndroid Build Coastguard Worker } nir_load_store_vectorize_options;
5862*61046927SAndroid Build Coastguard Worker
5863*61046927SAndroid Build Coastguard Worker bool nir_opt_load_store_vectorize(nir_shader *shader, const nir_load_store_vectorize_options *options);
5864*61046927SAndroid Build Coastguard Worker bool nir_opt_load_store_update_alignments(nir_shader *shader);
5865*61046927SAndroid Build Coastguard Worker
5866*61046927SAndroid Build Coastguard Worker typedef bool (*nir_lower_shader_calls_should_remat_func)(nir_instr *instr, void *data);
5867*61046927SAndroid Build Coastguard Worker
5868*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_shader_calls_options {
5869*61046927SAndroid Build Coastguard Worker /* Address format used for load/store operations on the call stack. */
5870*61046927SAndroid Build Coastguard Worker nir_address_format address_format;
5871*61046927SAndroid Build Coastguard Worker
5872*61046927SAndroid Build Coastguard Worker /* Stack alignment */
5873*61046927SAndroid Build Coastguard Worker unsigned stack_alignment;
5874*61046927SAndroid Build Coastguard Worker
5875*61046927SAndroid Build Coastguard Worker /* Put loads from the stack as close as possible from where they're needed.
5876*61046927SAndroid Build Coastguard Worker * You might want to disable combined_loads for best effects.
5877*61046927SAndroid Build Coastguard Worker */
5878*61046927SAndroid Build Coastguard Worker bool localized_loads;
5879*61046927SAndroid Build Coastguard Worker
5880*61046927SAndroid Build Coastguard Worker /* If this function pointer is not NULL, lower_shader_calls will run
5881*61046927SAndroid Build Coastguard Worker * nir_opt_load_store_vectorize for stack load/store operations. Otherwise
5882*61046927SAndroid Build Coastguard Worker * the optimizaion is not run.
5883*61046927SAndroid Build Coastguard Worker */
5884*61046927SAndroid Build Coastguard Worker nir_should_vectorize_mem_func vectorizer_callback;
5885*61046927SAndroid Build Coastguard Worker
5886*61046927SAndroid Build Coastguard Worker /* Data passed to vectorizer_callback */
5887*61046927SAndroid Build Coastguard Worker void *vectorizer_data;
5888*61046927SAndroid Build Coastguard Worker
5889*61046927SAndroid Build Coastguard Worker /* If this function pointer is not NULL, lower_shader_calls will call this
5890*61046927SAndroid Build Coastguard Worker * function on instructions that require spill/fill/rematerialization of
5891*61046927SAndroid Build Coastguard Worker * their value. If this function returns true, lower_shader_calls will
5892*61046927SAndroid Build Coastguard Worker * ensure that the instruction is rematerialized, adding the sources of the
5893*61046927SAndroid Build Coastguard Worker * instruction to be spilled/filled.
5894*61046927SAndroid Build Coastguard Worker */
5895*61046927SAndroid Build Coastguard Worker nir_lower_shader_calls_should_remat_func should_remat_callback;
5896*61046927SAndroid Build Coastguard Worker
5897*61046927SAndroid Build Coastguard Worker /* Data passed to should_remat_callback */
5898*61046927SAndroid Build Coastguard Worker void *should_remat_data;
5899*61046927SAndroid Build Coastguard Worker } nir_lower_shader_calls_options;
5900*61046927SAndroid Build Coastguard Worker
5901*61046927SAndroid Build Coastguard Worker bool
5902*61046927SAndroid Build Coastguard Worker nir_lower_shader_calls(nir_shader *shader,
5903*61046927SAndroid Build Coastguard Worker const nir_lower_shader_calls_options *options,
5904*61046927SAndroid Build Coastguard Worker nir_shader ***resume_shaders_out,
5905*61046927SAndroid Build Coastguard Worker uint32_t *num_resume_shaders_out,
5906*61046927SAndroid Build Coastguard Worker void *mem_ctx);
5907*61046927SAndroid Build Coastguard Worker
5908*61046927SAndroid Build Coastguard Worker int nir_get_io_offset_src_number(const nir_intrinsic_instr *instr);
5909*61046927SAndroid Build Coastguard Worker int nir_get_io_arrayed_index_src_number(const nir_intrinsic_instr *instr);
5910*61046927SAndroid Build Coastguard Worker
5911*61046927SAndroid Build Coastguard Worker nir_src *nir_get_io_offset_src(nir_intrinsic_instr *instr);
5912*61046927SAndroid Build Coastguard Worker nir_src *nir_get_io_arrayed_index_src(nir_intrinsic_instr *instr);
5913*61046927SAndroid Build Coastguard Worker nir_src *nir_get_shader_call_payload_src(nir_intrinsic_instr *call);
5914*61046927SAndroid Build Coastguard Worker
5915*61046927SAndroid Build Coastguard Worker bool nir_is_arrayed_io(const nir_variable *var, gl_shader_stage stage);
5916*61046927SAndroid Build Coastguard Worker
5917*61046927SAndroid Build Coastguard Worker bool nir_lower_reg_intrinsics_to_ssa_impl(nir_function_impl *impl);
5918*61046927SAndroid Build Coastguard Worker bool nir_lower_reg_intrinsics_to_ssa(nir_shader *shader);
5919*61046927SAndroid Build Coastguard Worker bool nir_lower_vars_to_ssa(nir_shader *shader);
5920*61046927SAndroid Build Coastguard Worker
5921*61046927SAndroid Build Coastguard Worker bool nir_remove_dead_derefs(nir_shader *shader);
5922*61046927SAndroid Build Coastguard Worker bool nir_remove_dead_derefs_impl(nir_function_impl *impl);
5923*61046927SAndroid Build Coastguard Worker
5924*61046927SAndroid Build Coastguard Worker typedef struct nir_remove_dead_variables_options {
5925*61046927SAndroid Build Coastguard Worker bool (*can_remove_var)(nir_variable *var, void *data);
5926*61046927SAndroid Build Coastguard Worker void *can_remove_var_data;
5927*61046927SAndroid Build Coastguard Worker } nir_remove_dead_variables_options;
5928*61046927SAndroid Build Coastguard Worker
5929*61046927SAndroid Build Coastguard Worker bool nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes,
5930*61046927SAndroid Build Coastguard Worker const nir_remove_dead_variables_options *options);
5931*61046927SAndroid Build Coastguard Worker
5932*61046927SAndroid Build Coastguard Worker bool nir_lower_variable_initializers(nir_shader *shader,
5933*61046927SAndroid Build Coastguard Worker nir_variable_mode modes);
5934*61046927SAndroid Build Coastguard Worker bool nir_zero_initialize_shared_memory(nir_shader *shader,
5935*61046927SAndroid Build Coastguard Worker const unsigned shared_size,
5936*61046927SAndroid Build Coastguard Worker const unsigned chunk_size);
5937*61046927SAndroid Build Coastguard Worker bool nir_clear_shared_memory(nir_shader *shader,
5938*61046927SAndroid Build Coastguard Worker const unsigned shared_size,
5939*61046927SAndroid Build Coastguard Worker const unsigned chunk_size);
5940*61046927SAndroid Build Coastguard Worker
5941*61046927SAndroid Build Coastguard Worker bool nir_move_vec_src_uses_to_dest(nir_shader *shader, bool skip_const_srcs);
5942*61046927SAndroid Build Coastguard Worker bool nir_lower_vec_to_regs(nir_shader *shader, nir_instr_writemask_filter_cb cb,
5943*61046927SAndroid Build Coastguard Worker const void *_data);
5944*61046927SAndroid Build Coastguard Worker bool nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
5945*61046927SAndroid Build Coastguard Worker bool alpha_to_one,
5946*61046927SAndroid Build Coastguard Worker const gl_state_index16 *alpha_ref_state_tokens);
5947*61046927SAndroid Build Coastguard Worker bool nir_lower_alu(nir_shader *shader);
5948*61046927SAndroid Build Coastguard Worker
5949*61046927SAndroid Build Coastguard Worker bool nir_lower_flrp(nir_shader *shader, unsigned lowering_mask,
5950*61046927SAndroid Build Coastguard Worker bool always_precise);
5951*61046927SAndroid Build Coastguard Worker
5952*61046927SAndroid Build Coastguard Worker bool nir_scale_fdiv(nir_shader *shader);
5953*61046927SAndroid Build Coastguard Worker
5954*61046927SAndroid Build Coastguard Worker bool nir_lower_alu_to_scalar(nir_shader *shader, nir_instr_filter_cb cb, const void *data);
5955*61046927SAndroid Build Coastguard Worker bool nir_lower_alu_width(nir_shader *shader, nir_vectorize_cb cb, const void *data);
5956*61046927SAndroid Build Coastguard Worker bool nir_lower_alu_vec8_16_srcs(nir_shader *shader);
5957*61046927SAndroid Build Coastguard Worker bool nir_lower_bool_to_bitsize(nir_shader *shader);
5958*61046927SAndroid Build Coastguard Worker bool nir_lower_bool_to_float(nir_shader *shader, bool has_fcsel_ne);
5959*61046927SAndroid Build Coastguard Worker bool nir_lower_bool_to_int32(nir_shader *shader);
5960*61046927SAndroid Build Coastguard Worker bool nir_opt_simplify_convert_alu_types(nir_shader *shader);
5961*61046927SAndroid Build Coastguard Worker bool nir_lower_const_arrays_to_uniforms(nir_shader *shader,
5962*61046927SAndroid Build Coastguard Worker unsigned max_uniform_components);
5963*61046927SAndroid Build Coastguard Worker bool nir_lower_convert_alu_types(nir_shader *shader,
5964*61046927SAndroid Build Coastguard Worker bool (*should_lower)(nir_intrinsic_instr *));
5965*61046927SAndroid Build Coastguard Worker bool nir_lower_constant_convert_alu_types(nir_shader *shader);
5966*61046927SAndroid Build Coastguard Worker bool nir_lower_alu_conversion_to_intrinsic(nir_shader *shader);
5967*61046927SAndroid Build Coastguard Worker bool nir_lower_int_to_float(nir_shader *shader);
5968*61046927SAndroid Build Coastguard Worker bool nir_lower_load_const_to_scalar(nir_shader *shader);
5969*61046927SAndroid Build Coastguard Worker bool nir_lower_read_invocation_to_scalar(nir_shader *shader);
5970*61046927SAndroid Build Coastguard Worker bool nir_lower_phis_to_scalar(nir_shader *shader, bool lower_all);
5971*61046927SAndroid Build Coastguard Worker void nir_lower_io_arrays_to_elements(nir_shader *producer, nir_shader *consumer);
5972*61046927SAndroid Build Coastguard Worker bool nir_lower_io_arrays_to_elements_no_indirects(nir_shader *shader,
5973*61046927SAndroid Build Coastguard Worker bool outputs_only);
5974*61046927SAndroid Build Coastguard Worker bool nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask, nir_instr_filter_cb filter, void *filter_data);
5975*61046927SAndroid Build Coastguard Worker bool nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
5976*61046927SAndroid Build Coastguard Worker bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
5977*61046927SAndroid Build Coastguard Worker bool nir_vectorize_tess_levels(nir_shader *shader);
5978*61046927SAndroid Build Coastguard Worker nir_shader *nir_create_passthrough_tcs_impl(const nir_shader_compiler_options *options,
5979*61046927SAndroid Build Coastguard Worker unsigned *locations, unsigned num_locations,
5980*61046927SAndroid Build Coastguard Worker uint8_t patch_vertices);
5981*61046927SAndroid Build Coastguard Worker nir_shader *nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
5982*61046927SAndroid Build Coastguard Worker const nir_shader *vs, uint8_t patch_vertices);
5983*61046927SAndroid Build Coastguard Worker nir_shader *nir_create_passthrough_gs(const nir_shader_compiler_options *options,
5984*61046927SAndroid Build Coastguard Worker const nir_shader *prev_stage,
5985*61046927SAndroid Build Coastguard Worker enum mesa_prim primitive_type,
5986*61046927SAndroid Build Coastguard Worker enum mesa_prim output_primitive_type,
5987*61046927SAndroid Build Coastguard Worker bool emulate_edgeflags,
5988*61046927SAndroid Build Coastguard Worker bool force_line_strip_out);
5989*61046927SAndroid Build Coastguard Worker
5990*61046927SAndroid Build Coastguard Worker bool nir_lower_fragcolor(nir_shader *shader, unsigned max_cbufs);
5991*61046927SAndroid Build Coastguard Worker bool nir_lower_fragcoord_wtrans(nir_shader *shader);
5992*61046927SAndroid Build Coastguard Worker bool nir_lower_frag_coord_to_pixel_coord(nir_shader *shader);
5993*61046927SAndroid Build Coastguard Worker bool nir_lower_viewport_transform(nir_shader *shader);
5994*61046927SAndroid Build Coastguard Worker bool nir_lower_uniforms_to_ubo(nir_shader *shader, bool dword_packed, bool load_vec4);
5995*61046927SAndroid Build Coastguard Worker
5996*61046927SAndroid Build Coastguard Worker bool nir_lower_is_helper_invocation(nir_shader *shader);
5997*61046927SAndroid Build Coastguard Worker
5998*61046927SAndroid Build Coastguard Worker bool nir_lower_single_sampled(nir_shader *shader);
5999*61046927SAndroid Build Coastguard Worker
6000*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_subgroups_options {
6001*61046927SAndroid Build Coastguard Worker /* In addition to the boolean lowering options below, this optional callback
6002*61046927SAndroid Build Coastguard Worker * will filter instructions for lowering if non-NULL. The data passed will be
6003*61046927SAndroid Build Coastguard Worker * this options struct itself.
6004*61046927SAndroid Build Coastguard Worker */
6005*61046927SAndroid Build Coastguard Worker nir_instr_filter_cb filter;
6006*61046927SAndroid Build Coastguard Worker
6007*61046927SAndroid Build Coastguard Worker uint8_t subgroup_size;
6008*61046927SAndroid Build Coastguard Worker uint8_t ballot_bit_size;
6009*61046927SAndroid Build Coastguard Worker uint8_t ballot_components;
6010*61046927SAndroid Build Coastguard Worker bool lower_to_scalar : 1;
6011*61046927SAndroid Build Coastguard Worker bool lower_vote_trivial : 1;
6012*61046927SAndroid Build Coastguard Worker bool lower_vote_eq : 1;
6013*61046927SAndroid Build Coastguard Worker bool lower_vote_bool_eq : 1;
6014*61046927SAndroid Build Coastguard Worker bool lower_first_invocation_to_ballot : 1;
6015*61046927SAndroid Build Coastguard Worker bool lower_read_first_invocation : 1;
6016*61046927SAndroid Build Coastguard Worker bool lower_subgroup_masks : 1;
6017*61046927SAndroid Build Coastguard Worker bool lower_relative_shuffle : 1;
6018*61046927SAndroid Build Coastguard Worker bool lower_shuffle_to_32bit : 1;
6019*61046927SAndroid Build Coastguard Worker bool lower_shuffle_to_swizzle_amd : 1;
6020*61046927SAndroid Build Coastguard Worker bool lower_shuffle : 1;
6021*61046927SAndroid Build Coastguard Worker bool lower_quad : 1;
6022*61046927SAndroid Build Coastguard Worker bool lower_quad_broadcast_dynamic : 1;
6023*61046927SAndroid Build Coastguard Worker bool lower_quad_broadcast_dynamic_to_const : 1;
6024*61046927SAndroid Build Coastguard Worker bool lower_elect : 1;
6025*61046927SAndroid Build Coastguard Worker bool lower_read_invocation_to_cond : 1;
6026*61046927SAndroid Build Coastguard Worker bool lower_rotate_to_shuffle : 1;
6027*61046927SAndroid Build Coastguard Worker bool lower_ballot_bit_count_to_mbcnt_amd : 1;
6028*61046927SAndroid Build Coastguard Worker bool lower_inverse_ballot : 1;
6029*61046927SAndroid Build Coastguard Worker bool lower_reduce : 1;
6030*61046927SAndroid Build Coastguard Worker bool lower_boolean_reduce : 1;
6031*61046927SAndroid Build Coastguard Worker bool lower_boolean_shuffle : 1;
6032*61046927SAndroid Build Coastguard Worker } nir_lower_subgroups_options;
6033*61046927SAndroid Build Coastguard Worker
6034*61046927SAndroid Build Coastguard Worker bool nir_lower_subgroups(nir_shader *shader,
6035*61046927SAndroid Build Coastguard Worker const nir_lower_subgroups_options *options);
6036*61046927SAndroid Build Coastguard Worker
6037*61046927SAndroid Build Coastguard Worker bool nir_lower_system_values(nir_shader *shader);
6038*61046927SAndroid Build Coastguard Worker
6039*61046927SAndroid Build Coastguard Worker nir_def *
6040*61046927SAndroid Build Coastguard Worker nir_build_lowered_load_helper_invocation(struct nir_builder *b);
6041*61046927SAndroid Build Coastguard Worker
6042*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_compute_system_values_options {
6043*61046927SAndroid Build Coastguard Worker bool has_base_global_invocation_id : 1;
6044*61046927SAndroid Build Coastguard Worker bool has_base_workgroup_id : 1;
6045*61046927SAndroid Build Coastguard Worker bool has_global_size : 1;
6046*61046927SAndroid Build Coastguard Worker bool shuffle_local_ids_for_quad_derivatives : 1;
6047*61046927SAndroid Build Coastguard Worker bool lower_local_invocation_index : 1;
6048*61046927SAndroid Build Coastguard Worker bool lower_cs_local_id_to_index : 1;
6049*61046927SAndroid Build Coastguard Worker bool lower_workgroup_id_to_index : 1;
6050*61046927SAndroid Build Coastguard Worker /* At shader execution time, check if WorkGroupId should be 1D
6051*61046927SAndroid Build Coastguard Worker * and compute it quickly. Fall back to slow computation if not.
6052*61046927SAndroid Build Coastguard Worker */
6053*61046927SAndroid Build Coastguard Worker bool shortcut_1d_workgroup_id : 1;
6054*61046927SAndroid Build Coastguard Worker uint32_t num_workgroups[3]; /* Compile-time-known dispatch sizes, or 0 if unknown. */
6055*61046927SAndroid Build Coastguard Worker } nir_lower_compute_system_values_options;
6056*61046927SAndroid Build Coastguard Worker
6057*61046927SAndroid Build Coastguard Worker bool nir_lower_compute_system_values(nir_shader *shader,
6058*61046927SAndroid Build Coastguard Worker const nir_lower_compute_system_values_options *options);
6059*61046927SAndroid Build Coastguard Worker
6060*61046927SAndroid Build Coastguard Worker struct nir_lower_sysvals_to_varyings_options {
6061*61046927SAndroid Build Coastguard Worker bool frag_coord : 1;
6062*61046927SAndroid Build Coastguard Worker bool front_face : 1;
6063*61046927SAndroid Build Coastguard Worker bool point_coord : 1;
6064*61046927SAndroid Build Coastguard Worker };
6065*61046927SAndroid Build Coastguard Worker
6066*61046927SAndroid Build Coastguard Worker bool
6067*61046927SAndroid Build Coastguard Worker nir_lower_sysvals_to_varyings(nir_shader *shader,
6068*61046927SAndroid Build Coastguard Worker const struct nir_lower_sysvals_to_varyings_options *options);
6069*61046927SAndroid Build Coastguard Worker
6070*61046927SAndroid Build Coastguard Worker /***/
6071*61046927SAndroid Build Coastguard Worker enum ENUM_PACKED nir_lower_tex_packing {
6072*61046927SAndroid Build Coastguard Worker /** No packing */
6073*61046927SAndroid Build Coastguard Worker nir_lower_tex_packing_none = 0,
6074*61046927SAndroid Build Coastguard Worker /**
6075*61046927SAndroid Build Coastguard Worker * The sampler returns up to 2 32-bit words of half floats or 16-bit signed
6076*61046927SAndroid Build Coastguard Worker * or unsigned ints based on the sampler type
6077*61046927SAndroid Build Coastguard Worker */
6078*61046927SAndroid Build Coastguard Worker nir_lower_tex_packing_16,
6079*61046927SAndroid Build Coastguard Worker /** The sampler returns 1 32-bit word of 4x8 unorm */
6080*61046927SAndroid Build Coastguard Worker nir_lower_tex_packing_8,
6081*61046927SAndroid Build Coastguard Worker };
6082*61046927SAndroid Build Coastguard Worker
6083*61046927SAndroid Build Coastguard Worker /***/
6084*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_tex_options {
6085*61046927SAndroid Build Coastguard Worker /**
6086*61046927SAndroid Build Coastguard Worker * bitmask of (1 << GLSL_SAMPLER_DIM_x) to control for which
6087*61046927SAndroid Build Coastguard Worker * sampler types a texture projector is lowered.
6088*61046927SAndroid Build Coastguard Worker */
6089*61046927SAndroid Build Coastguard Worker unsigned lower_txp;
6090*61046927SAndroid Build Coastguard Worker
6091*61046927SAndroid Build Coastguard Worker /**
6092*61046927SAndroid Build Coastguard Worker * If true, lower texture projector for any array sampler dims
6093*61046927SAndroid Build Coastguard Worker */
6094*61046927SAndroid Build Coastguard Worker bool lower_txp_array;
6095*61046927SAndroid Build Coastguard Worker
6096*61046927SAndroid Build Coastguard Worker /**
6097*61046927SAndroid Build Coastguard Worker * If true, lower away nir_tex_src_offset for all texelfetch instructions.
6098*61046927SAndroid Build Coastguard Worker */
6099*61046927SAndroid Build Coastguard Worker bool lower_txf_offset;
6100*61046927SAndroid Build Coastguard Worker
6101*61046927SAndroid Build Coastguard Worker /**
6102*61046927SAndroid Build Coastguard Worker * If true, lower away nir_tex_src_offset for all rect textures.
6103*61046927SAndroid Build Coastguard Worker */
6104*61046927SAndroid Build Coastguard Worker bool lower_rect_offset;
6105*61046927SAndroid Build Coastguard Worker
6106*61046927SAndroid Build Coastguard Worker /**
6107*61046927SAndroid Build Coastguard Worker * If not NULL, this filter will return true for tex instructions that
6108*61046927SAndroid Build Coastguard Worker * should lower away nir_tex_src_offset.
6109*61046927SAndroid Build Coastguard Worker */
6110*61046927SAndroid Build Coastguard Worker nir_instr_filter_cb lower_offset_filter;
6111*61046927SAndroid Build Coastguard Worker
6112*61046927SAndroid Build Coastguard Worker /**
6113*61046927SAndroid Build Coastguard Worker * If true, lower rect textures to 2D, using txs to fetch the
6114*61046927SAndroid Build Coastguard Worker * texture dimensions and dividing the texture coords by the
6115*61046927SAndroid Build Coastguard Worker * texture dims to normalize.
6116*61046927SAndroid Build Coastguard Worker */
6117*61046927SAndroid Build Coastguard Worker bool lower_rect;
6118*61046927SAndroid Build Coastguard Worker
6119*61046927SAndroid Build Coastguard Worker /**
6120*61046927SAndroid Build Coastguard Worker * If true, lower 1D textures to 2D. This requires the GL/VK driver to map 1D
6121*61046927SAndroid Build Coastguard Worker * textures to 2D textures with height=1.
6122*61046927SAndroid Build Coastguard Worker *
6123*61046927SAndroid Build Coastguard Worker * lower_1d_shadow does this lowering for shadow textures only.
6124*61046927SAndroid Build Coastguard Worker */
6125*61046927SAndroid Build Coastguard Worker bool lower_1d;
6126*61046927SAndroid Build Coastguard Worker bool lower_1d_shadow;
6127*61046927SAndroid Build Coastguard Worker
6128*61046927SAndroid Build Coastguard Worker /**
6129*61046927SAndroid Build Coastguard Worker * If true, convert yuv to rgb.
6130*61046927SAndroid Build Coastguard Worker */
6131*61046927SAndroid Build Coastguard Worker unsigned lower_y_uv_external;
6132*61046927SAndroid Build Coastguard Worker unsigned lower_y_vu_external;
6133*61046927SAndroid Build Coastguard Worker unsigned lower_y_u_v_external;
6134*61046927SAndroid Build Coastguard Worker unsigned lower_yx_xuxv_external;
6135*61046927SAndroid Build Coastguard Worker unsigned lower_yx_xvxu_external;
6136*61046927SAndroid Build Coastguard Worker unsigned lower_xy_uxvx_external;
6137*61046927SAndroid Build Coastguard Worker unsigned lower_xy_vxux_external;
6138*61046927SAndroid Build Coastguard Worker unsigned lower_ayuv_external;
6139*61046927SAndroid Build Coastguard Worker unsigned lower_xyuv_external;
6140*61046927SAndroid Build Coastguard Worker unsigned lower_yuv_external;
6141*61046927SAndroid Build Coastguard Worker unsigned lower_yu_yv_external;
6142*61046927SAndroid Build Coastguard Worker unsigned lower_yv_yu_external;
6143*61046927SAndroid Build Coastguard Worker unsigned lower_y41x_external;
6144*61046927SAndroid Build Coastguard Worker unsigned bt709_external;
6145*61046927SAndroid Build Coastguard Worker unsigned bt2020_external;
6146*61046927SAndroid Build Coastguard Worker unsigned yuv_full_range_external;
6147*61046927SAndroid Build Coastguard Worker
6148*61046927SAndroid Build Coastguard Worker /**
6149*61046927SAndroid Build Coastguard Worker * To emulate certain texture wrap modes, this can be used
6150*61046927SAndroid Build Coastguard Worker * to saturate the specified tex coord to [0.0, 1.0]. The
6151*61046927SAndroid Build Coastguard Worker * bits are according to sampler #, ie. if, for example:
6152*61046927SAndroid Build Coastguard Worker *
6153*61046927SAndroid Build Coastguard Worker * (conf->saturate_s & (1 << n))
6154*61046927SAndroid Build Coastguard Worker *
6155*61046927SAndroid Build Coastguard Worker * is true, then the s coord for sampler n is saturated.
6156*61046927SAndroid Build Coastguard Worker *
6157*61046927SAndroid Build Coastguard Worker * Note that clamping must happen *after* projector lowering
6158*61046927SAndroid Build Coastguard Worker * so any projected texture sample instruction with a clamped
6159*61046927SAndroid Build Coastguard Worker * coordinate gets automatically lowered, regardless of the
6160*61046927SAndroid Build Coastguard Worker * 'lower_txp' setting.
6161*61046927SAndroid Build Coastguard Worker */
6162*61046927SAndroid Build Coastguard Worker unsigned saturate_s;
6163*61046927SAndroid Build Coastguard Worker unsigned saturate_t;
6164*61046927SAndroid Build Coastguard Worker unsigned saturate_r;
6165*61046927SAndroid Build Coastguard Worker
6166*61046927SAndroid Build Coastguard Worker /* Bitmask of textures that need swizzling.
6167*61046927SAndroid Build Coastguard Worker *
6168*61046927SAndroid Build Coastguard Worker * If (swizzle_result & (1 << texture_index)), then the swizzle in
6169*61046927SAndroid Build Coastguard Worker * swizzles[texture_index] is applied to the result of the texturing
6170*61046927SAndroid Build Coastguard Worker * operation.
6171*61046927SAndroid Build Coastguard Worker */
6172*61046927SAndroid Build Coastguard Worker unsigned swizzle_result;
6173*61046927SAndroid Build Coastguard Worker
6174*61046927SAndroid Build Coastguard Worker /* A swizzle for each texture. Values 0-3 represent x, y, z, or w swizzles
6175*61046927SAndroid Build Coastguard Worker * while 4 and 5 represent 0 and 1 respectively.
6176*61046927SAndroid Build Coastguard Worker *
6177*61046927SAndroid Build Coastguard Worker * Indexed by texture-id.
6178*61046927SAndroid Build Coastguard Worker */
6179*61046927SAndroid Build Coastguard Worker uint8_t swizzles[32][4];
6180*61046927SAndroid Build Coastguard Worker
6181*61046927SAndroid Build Coastguard Worker /* Can be used to scale sampled values in range required by the
6182*61046927SAndroid Build Coastguard Worker * format.
6183*61046927SAndroid Build Coastguard Worker *
6184*61046927SAndroid Build Coastguard Worker * Indexed by texture-id.
6185*61046927SAndroid Build Coastguard Worker */
6186*61046927SAndroid Build Coastguard Worker float scale_factors[32];
6187*61046927SAndroid Build Coastguard Worker
6188*61046927SAndroid Build Coastguard Worker /**
6189*61046927SAndroid Build Coastguard Worker * Bitmap of textures that need srgb to linear conversion. If
6190*61046927SAndroid Build Coastguard Worker * (lower_srgb & (1 << texture_index)) then the rgb (xyz) components
6191*61046927SAndroid Build Coastguard Worker * of the texture are lowered to linear.
6192*61046927SAndroid Build Coastguard Worker */
6193*61046927SAndroid Build Coastguard Worker unsigned lower_srgb;
6194*61046927SAndroid Build Coastguard Worker
6195*61046927SAndroid Build Coastguard Worker /**
6196*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd on cube maps with nir_texop_txl.
6197*61046927SAndroid Build Coastguard Worker */
6198*61046927SAndroid Build Coastguard Worker bool lower_txd_cube_map;
6199*61046927SAndroid Build Coastguard Worker
6200*61046927SAndroid Build Coastguard Worker /**
6201*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd on 3D surfaces with nir_texop_txl.
6202*61046927SAndroid Build Coastguard Worker */
6203*61046927SAndroid Build Coastguard Worker bool lower_txd_3d;
6204*61046927SAndroid Build Coastguard Worker
6205*61046927SAndroid Build Coastguard Worker /**
6206*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd any array surfaces with nir_texop_txl.
6207*61046927SAndroid Build Coastguard Worker */
6208*61046927SAndroid Build Coastguard Worker bool lower_txd_array;
6209*61046927SAndroid Build Coastguard Worker
6210*61046927SAndroid Build Coastguard Worker /**
6211*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd on shadow samplers (except cube maps)
6212*61046927SAndroid Build Coastguard Worker * with nir_texop_txl. Notice that cube map shadow samplers are lowered
6213*61046927SAndroid Build Coastguard Worker * with lower_txd_cube_map.
6214*61046927SAndroid Build Coastguard Worker */
6215*61046927SAndroid Build Coastguard Worker bool lower_txd_shadow;
6216*61046927SAndroid Build Coastguard Worker
6217*61046927SAndroid Build Coastguard Worker /**
6218*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd on all samplers to a nir_texop_txl.
6219*61046927SAndroid Build Coastguard Worker * Implies lower_txd_cube_map and lower_txd_shadow.
6220*61046927SAndroid Build Coastguard Worker */
6221*61046927SAndroid Build Coastguard Worker bool lower_txd;
6222*61046927SAndroid Build Coastguard Worker
6223*61046927SAndroid Build Coastguard Worker /**
6224*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd when it uses min_lod.
6225*61046927SAndroid Build Coastguard Worker */
6226*61046927SAndroid Build Coastguard Worker bool lower_txd_clamp;
6227*61046927SAndroid Build Coastguard Worker
6228*61046927SAndroid Build Coastguard Worker /**
6229*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txb that try to use shadow compare and min_lod
6230*61046927SAndroid Build Coastguard Worker * at the same time to a nir_texop_lod, some math, and nir_texop_tex.
6231*61046927SAndroid Build Coastguard Worker */
6232*61046927SAndroid Build Coastguard Worker bool lower_txb_shadow_clamp;
6233*61046927SAndroid Build Coastguard Worker
6234*61046927SAndroid Build Coastguard Worker /**
6235*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd on shadow samplers when it uses min_lod
6236*61046927SAndroid Build Coastguard Worker * with nir_texop_txl. This includes cube maps.
6237*61046927SAndroid Build Coastguard Worker */
6238*61046927SAndroid Build Coastguard Worker bool lower_txd_shadow_clamp;
6239*61046927SAndroid Build Coastguard Worker
6240*61046927SAndroid Build Coastguard Worker /**
6241*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd on when it uses both offset and min_lod
6242*61046927SAndroid Build Coastguard Worker * with nir_texop_txl. This includes cube maps.
6243*61046927SAndroid Build Coastguard Worker */
6244*61046927SAndroid Build Coastguard Worker bool lower_txd_offset_clamp;
6245*61046927SAndroid Build Coastguard Worker
6246*61046927SAndroid Build Coastguard Worker /**
6247*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd with min_lod to a nir_texop_txl if the
6248*61046927SAndroid Build Coastguard Worker * sampler is bindless.
6249*61046927SAndroid Build Coastguard Worker */
6250*61046927SAndroid Build Coastguard Worker bool lower_txd_clamp_bindless_sampler;
6251*61046927SAndroid Build Coastguard Worker
6252*61046927SAndroid Build Coastguard Worker /**
6253*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txd with min_lod to a nir_texop_txl if the
6254*61046927SAndroid Build Coastguard Worker * sampler index is not statically determinable to be less than 16.
6255*61046927SAndroid Build Coastguard Worker */
6256*61046927SAndroid Build Coastguard Worker bool lower_txd_clamp_if_sampler_index_not_lt_16;
6257*61046927SAndroid Build Coastguard Worker
6258*61046927SAndroid Build Coastguard Worker /**
6259*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txs with a non-0-lod into nir_texop_txs with
6260*61046927SAndroid Build Coastguard Worker * 0-lod followed by a nir_ishr.
6261*61046927SAndroid Build Coastguard Worker */
6262*61046927SAndroid Build Coastguard Worker bool lower_txs_lod;
6263*61046927SAndroid Build Coastguard Worker
6264*61046927SAndroid Build Coastguard Worker /**
6265*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_txs for cube arrays to a nir_texop_txs with a
6266*61046927SAndroid Build Coastguard Worker * 2D array type followed by a nir_idiv by 6.
6267*61046927SAndroid Build Coastguard Worker */
6268*61046927SAndroid Build Coastguard Worker bool lower_txs_cube_array;
6269*61046927SAndroid Build Coastguard Worker
6270*61046927SAndroid Build Coastguard Worker /**
6271*61046927SAndroid Build Coastguard Worker * If true, apply a .bagr swizzle on tg4 results to handle Broadcom's
6272*61046927SAndroid Build Coastguard Worker * mixed-up tg4 locations.
6273*61046927SAndroid Build Coastguard Worker */
6274*61046927SAndroid Build Coastguard Worker bool lower_tg4_broadcom_swizzle;
6275*61046927SAndroid Build Coastguard Worker
6276*61046927SAndroid Build Coastguard Worker /**
6277*61046927SAndroid Build Coastguard Worker * If true, lowers tg4 with 4 constant offsets to 4 tg4 calls
6278*61046927SAndroid Build Coastguard Worker */
6279*61046927SAndroid Build Coastguard Worker bool lower_tg4_offsets;
6280*61046927SAndroid Build Coastguard Worker
6281*61046927SAndroid Build Coastguard Worker /**
6282*61046927SAndroid Build Coastguard Worker * Lower txf_ms to fragment_mask_fetch and fragment_fetch and samples_identical to
6283*61046927SAndroid Build Coastguard Worker * fragment_mask_fetch.
6284*61046927SAndroid Build Coastguard Worker */
6285*61046927SAndroid Build Coastguard Worker bool lower_to_fragment_fetch_amd;
6286*61046927SAndroid Build Coastguard Worker
6287*61046927SAndroid Build Coastguard Worker /**
6288*61046927SAndroid Build Coastguard Worker * To lower packed sampler return formats. This will be called for all
6289*61046927SAndroid Build Coastguard Worker * tex instructions.
6290*61046927SAndroid Build Coastguard Worker */
6291*61046927SAndroid Build Coastguard Worker enum nir_lower_tex_packing (*lower_tex_packing_cb)(const nir_tex_instr *tex, const void *data);
6292*61046927SAndroid Build Coastguard Worker const void *lower_tex_packing_data;
6293*61046927SAndroid Build Coastguard Worker
6294*61046927SAndroid Build Coastguard Worker /**
6295*61046927SAndroid Build Coastguard Worker * If true, lower nir_texop_lod to return -FLT_MAX if the sum of the
6296*61046927SAndroid Build Coastguard Worker * absolute values of derivatives is 0 for all coordinates.
6297*61046927SAndroid Build Coastguard Worker */
6298*61046927SAndroid Build Coastguard Worker bool lower_lod_zero_width;
6299*61046927SAndroid Build Coastguard Worker
6300*61046927SAndroid Build Coastguard Worker /* Turns nir_op_tex and other ops with an implicit derivative, in stages
6301*61046927SAndroid Build Coastguard Worker * without implicit derivatives (like the vertex shader) to have an explicit
6302*61046927SAndroid Build Coastguard Worker * LOD with a value of 0.
6303*61046927SAndroid Build Coastguard Worker */
6304*61046927SAndroid Build Coastguard Worker bool lower_invalid_implicit_lod;
6305*61046927SAndroid Build Coastguard Worker
6306*61046927SAndroid Build Coastguard Worker /* If true, texture_index (sampler_index) will be zero if a texture_offset
6307*61046927SAndroid Build Coastguard Worker * (sampler_offset) source is present. This is convenient for backends that
6308*61046927SAndroid Build Coastguard Worker * support indirect indexing of textures (samplers) but not offsetting it.
6309*61046927SAndroid Build Coastguard Worker */
6310*61046927SAndroid Build Coastguard Worker bool lower_index_to_offset;
6311*61046927SAndroid Build Coastguard Worker
6312*61046927SAndroid Build Coastguard Worker /**
6313*61046927SAndroid Build Coastguard Worker * Payload data to be sent to callback / filter functions.
6314*61046927SAndroid Build Coastguard Worker */
6315*61046927SAndroid Build Coastguard Worker void *callback_data;
6316*61046927SAndroid Build Coastguard Worker } nir_lower_tex_options;
6317*61046927SAndroid Build Coastguard Worker
6318*61046927SAndroid Build Coastguard Worker /** Lowers complex texture instructions to simpler ones */
6319*61046927SAndroid Build Coastguard Worker bool nir_lower_tex(nir_shader *shader,
6320*61046927SAndroid Build Coastguard Worker const nir_lower_tex_options *options);
6321*61046927SAndroid Build Coastguard Worker
6322*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_tex_shadow_swizzle {
6323*61046927SAndroid Build Coastguard Worker unsigned swizzle_r : 3;
6324*61046927SAndroid Build Coastguard Worker unsigned swizzle_g : 3;
6325*61046927SAndroid Build Coastguard Worker unsigned swizzle_b : 3;
6326*61046927SAndroid Build Coastguard Worker unsigned swizzle_a : 3;
6327*61046927SAndroid Build Coastguard Worker } nir_lower_tex_shadow_swizzle;
6328*61046927SAndroid Build Coastguard Worker
6329*61046927SAndroid Build Coastguard Worker bool
6330*61046927SAndroid Build Coastguard Worker nir_lower_tex_shadow(nir_shader *s,
6331*61046927SAndroid Build Coastguard Worker unsigned n_states,
6332*61046927SAndroid Build Coastguard Worker enum compare_func *compare_func,
6333*61046927SAndroid Build Coastguard Worker nir_lower_tex_shadow_swizzle *tex_swizzles);
6334*61046927SAndroid Build Coastguard Worker
6335*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_image_options {
6336*61046927SAndroid Build Coastguard Worker /**
6337*61046927SAndroid Build Coastguard Worker * If true, lower cube size operations.
6338*61046927SAndroid Build Coastguard Worker */
6339*61046927SAndroid Build Coastguard Worker bool lower_cube_size;
6340*61046927SAndroid Build Coastguard Worker
6341*61046927SAndroid Build Coastguard Worker /**
6342*61046927SAndroid Build Coastguard Worker * Lower multi sample image load and samples_identical to use fragment_mask_load.
6343*61046927SAndroid Build Coastguard Worker */
6344*61046927SAndroid Build Coastguard Worker bool lower_to_fragment_mask_load_amd;
6345*61046927SAndroid Build Coastguard Worker
6346*61046927SAndroid Build Coastguard Worker /**
6347*61046927SAndroid Build Coastguard Worker * Lower image_samples to a constant in case the driver doesn't support multisampled
6348*61046927SAndroid Build Coastguard Worker * images.
6349*61046927SAndroid Build Coastguard Worker */
6350*61046927SAndroid Build Coastguard Worker bool lower_image_samples_to_one;
6351*61046927SAndroid Build Coastguard Worker } nir_lower_image_options;
6352*61046927SAndroid Build Coastguard Worker
6353*61046927SAndroid Build Coastguard Worker bool nir_lower_image(nir_shader *nir,
6354*61046927SAndroid Build Coastguard Worker const nir_lower_image_options *options);
6355*61046927SAndroid Build Coastguard Worker
6356*61046927SAndroid Build Coastguard Worker bool
6357*61046927SAndroid Build Coastguard Worker nir_lower_image_atomics_to_global(nir_shader *s);
6358*61046927SAndroid Build Coastguard Worker
6359*61046927SAndroid Build Coastguard Worker bool nir_lower_readonly_images_to_tex(nir_shader *shader, bool per_variable);
6360*61046927SAndroid Build Coastguard Worker
6361*61046927SAndroid Build Coastguard Worker enum nir_lower_non_uniform_access_type {
6362*61046927SAndroid Build Coastguard Worker nir_lower_non_uniform_ubo_access = (1 << 0),
6363*61046927SAndroid Build Coastguard Worker nir_lower_non_uniform_ssbo_access = (1 << 1),
6364*61046927SAndroid Build Coastguard Worker nir_lower_non_uniform_texture_access = (1 << 2),
6365*61046927SAndroid Build Coastguard Worker nir_lower_non_uniform_image_access = (1 << 3),
6366*61046927SAndroid Build Coastguard Worker nir_lower_non_uniform_get_ssbo_size = (1 << 4),
6367*61046927SAndroid Build Coastguard Worker };
6368*61046927SAndroid Build Coastguard Worker
6369*61046927SAndroid Build Coastguard Worker /* Given the nir_src used for the resource, return the channels which might be non-uniform. */
6370*61046927SAndroid Build Coastguard Worker typedef nir_component_mask_t (*nir_lower_non_uniform_access_callback)(const nir_src *, void *);
6371*61046927SAndroid Build Coastguard Worker
6372*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_non_uniform_access_options {
6373*61046927SAndroid Build Coastguard Worker enum nir_lower_non_uniform_access_type types;
6374*61046927SAndroid Build Coastguard Worker nir_lower_non_uniform_access_callback callback;
6375*61046927SAndroid Build Coastguard Worker void *callback_data;
6376*61046927SAndroid Build Coastguard Worker } nir_lower_non_uniform_access_options;
6377*61046927SAndroid Build Coastguard Worker
6378*61046927SAndroid Build Coastguard Worker bool nir_has_non_uniform_access(nir_shader *shader, enum nir_lower_non_uniform_access_type types);
6379*61046927SAndroid Build Coastguard Worker bool nir_opt_non_uniform_access(nir_shader *shader);
6380*61046927SAndroid Build Coastguard Worker bool nir_lower_non_uniform_access(nir_shader *shader,
6381*61046927SAndroid Build Coastguard Worker const nir_lower_non_uniform_access_options *options);
6382*61046927SAndroid Build Coastguard Worker
6383*61046927SAndroid Build Coastguard Worker typedef struct {
6384*61046927SAndroid Build Coastguard Worker /* Whether 16-bit floating point arithmetic should be allowed in 8-bit
6385*61046927SAndroid Build Coastguard Worker * division lowering
6386*61046927SAndroid Build Coastguard Worker */
6387*61046927SAndroid Build Coastguard Worker bool allow_fp16;
6388*61046927SAndroid Build Coastguard Worker } nir_lower_idiv_options;
6389*61046927SAndroid Build Coastguard Worker
6390*61046927SAndroid Build Coastguard Worker bool nir_lower_idiv(nir_shader *shader, const nir_lower_idiv_options *options);
6391*61046927SAndroid Build Coastguard Worker
6392*61046927SAndroid Build Coastguard Worker typedef struct nir_input_attachment_options {
6393*61046927SAndroid Build Coastguard Worker bool use_fragcoord_sysval;
6394*61046927SAndroid Build Coastguard Worker bool use_layer_id_sysval;
6395*61046927SAndroid Build Coastguard Worker bool use_view_id_for_layer;
6396*61046927SAndroid Build Coastguard Worker uint32_t unscaled_input_attachment_ir3;
6397*61046927SAndroid Build Coastguard Worker } nir_input_attachment_options;
6398*61046927SAndroid Build Coastguard Worker
6399*61046927SAndroid Build Coastguard Worker bool nir_lower_input_attachments(nir_shader *shader,
6400*61046927SAndroid Build Coastguard Worker const nir_input_attachment_options *options);
6401*61046927SAndroid Build Coastguard Worker
6402*61046927SAndroid Build Coastguard Worker bool nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables,
6403*61046927SAndroid Build Coastguard Worker bool use_vars,
6404*61046927SAndroid Build Coastguard Worker bool use_clipdist_array,
6405*61046927SAndroid Build Coastguard Worker const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH]);
6406*61046927SAndroid Build Coastguard Worker bool nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables,
6407*61046927SAndroid Build Coastguard Worker bool use_clipdist_array,
6408*61046927SAndroid Build Coastguard Worker const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH]);
6409*61046927SAndroid Build Coastguard Worker bool nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables,
6410*61046927SAndroid Build Coastguard Worker bool use_clipdist_array);
6411*61046927SAndroid Build Coastguard Worker
6412*61046927SAndroid Build Coastguard Worker bool nir_lower_clip_cull_distance_to_vec4s(nir_shader *shader);
6413*61046927SAndroid Build Coastguard Worker bool nir_lower_clip_cull_distance_arrays(nir_shader *nir);
6414*61046927SAndroid Build Coastguard Worker bool nir_lower_clip_disable(nir_shader *shader, unsigned clip_plane_enable);
6415*61046927SAndroid Build Coastguard Worker
6416*61046927SAndroid Build Coastguard Worker bool nir_lower_point_size_mov(nir_shader *shader,
6417*61046927SAndroid Build Coastguard Worker const gl_state_index16 *pointsize_state_tokens);
6418*61046927SAndroid Build Coastguard Worker
6419*61046927SAndroid Build Coastguard Worker bool nir_lower_frexp(nir_shader *nir);
6420*61046927SAndroid Build Coastguard Worker
6421*61046927SAndroid Build Coastguard Worker bool nir_lower_two_sided_color(nir_shader *shader, bool face_sysval);
6422*61046927SAndroid Build Coastguard Worker
6423*61046927SAndroid Build Coastguard Worker bool nir_lower_clamp_color_outputs(nir_shader *shader);
6424*61046927SAndroid Build Coastguard Worker
6425*61046927SAndroid Build Coastguard Worker bool nir_lower_flatshade(nir_shader *shader);
6426*61046927SAndroid Build Coastguard Worker
6427*61046927SAndroid Build Coastguard Worker bool nir_lower_passthrough_edgeflags(nir_shader *shader);
6428*61046927SAndroid Build Coastguard Worker bool nir_lower_patch_vertices(nir_shader *nir, unsigned static_count,
6429*61046927SAndroid Build Coastguard Worker const gl_state_index16 *uniform_state_tokens);
6430*61046927SAndroid Build Coastguard Worker
6431*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_wpos_ytransform_options {
6432*61046927SAndroid Build Coastguard Worker gl_state_index16 state_tokens[STATE_LENGTH];
6433*61046927SAndroid Build Coastguard Worker bool fs_coord_origin_upper_left : 1;
6434*61046927SAndroid Build Coastguard Worker bool fs_coord_origin_lower_left : 1;
6435*61046927SAndroid Build Coastguard Worker bool fs_coord_pixel_center_integer : 1;
6436*61046927SAndroid Build Coastguard Worker bool fs_coord_pixel_center_half_integer : 1;
6437*61046927SAndroid Build Coastguard Worker } nir_lower_wpos_ytransform_options;
6438*61046927SAndroid Build Coastguard Worker
6439*61046927SAndroid Build Coastguard Worker bool nir_lower_wpos_ytransform(nir_shader *shader,
6440*61046927SAndroid Build Coastguard Worker const nir_lower_wpos_ytransform_options *options);
6441*61046927SAndroid Build Coastguard Worker bool nir_lower_wpos_center(nir_shader *shader);
6442*61046927SAndroid Build Coastguard Worker
6443*61046927SAndroid Build Coastguard Worker bool nir_lower_pntc_ytransform(nir_shader *shader,
6444*61046927SAndroid Build Coastguard Worker const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH]);
6445*61046927SAndroid Build Coastguard Worker
6446*61046927SAndroid Build Coastguard Worker bool nir_lower_wrmasks(nir_shader *shader, nir_instr_filter_cb cb, const void *data);
6447*61046927SAndroid Build Coastguard Worker
6448*61046927SAndroid Build Coastguard Worker bool nir_lower_fb_read(nir_shader *shader);
6449*61046927SAndroid Build Coastguard Worker
6450*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_drawpixels_options {
6451*61046927SAndroid Build Coastguard Worker gl_state_index16 texcoord_state_tokens[STATE_LENGTH];
6452*61046927SAndroid Build Coastguard Worker gl_state_index16 scale_state_tokens[STATE_LENGTH];
6453*61046927SAndroid Build Coastguard Worker gl_state_index16 bias_state_tokens[STATE_LENGTH];
6454*61046927SAndroid Build Coastguard Worker unsigned drawpix_sampler;
6455*61046927SAndroid Build Coastguard Worker unsigned pixelmap_sampler;
6456*61046927SAndroid Build Coastguard Worker bool pixel_maps : 1;
6457*61046927SAndroid Build Coastguard Worker bool scale_and_bias : 1;
6458*61046927SAndroid Build Coastguard Worker } nir_lower_drawpixels_options;
6459*61046927SAndroid Build Coastguard Worker
6460*61046927SAndroid Build Coastguard Worker bool nir_lower_drawpixels(nir_shader *shader,
6461*61046927SAndroid Build Coastguard Worker const nir_lower_drawpixels_options *options);
6462*61046927SAndroid Build Coastguard Worker
6463*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_bitmap_options {
6464*61046927SAndroid Build Coastguard Worker unsigned sampler;
6465*61046927SAndroid Build Coastguard Worker bool swizzle_xxxx;
6466*61046927SAndroid Build Coastguard Worker } nir_lower_bitmap_options;
6467*61046927SAndroid Build Coastguard Worker
6468*61046927SAndroid Build Coastguard Worker bool nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options *options);
6469*61046927SAndroid Build Coastguard Worker
6470*61046927SAndroid Build Coastguard Worker bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned offset_align_state);
6471*61046927SAndroid Build Coastguard Worker
6472*61046927SAndroid Build Coastguard Worker typedef enum {
6473*61046927SAndroid Build Coastguard Worker nir_lower_gs_intrinsics_per_stream = 1 << 0,
6474*61046927SAndroid Build Coastguard Worker nir_lower_gs_intrinsics_count_primitives = 1 << 1,
6475*61046927SAndroid Build Coastguard Worker nir_lower_gs_intrinsics_count_vertices_per_primitive = 1 << 2,
6476*61046927SAndroid Build Coastguard Worker nir_lower_gs_intrinsics_overwrite_incomplete = 1 << 3,
6477*61046927SAndroid Build Coastguard Worker nir_lower_gs_intrinsics_always_end_primitive = 1 << 4,
6478*61046927SAndroid Build Coastguard Worker nir_lower_gs_intrinsics_count_decomposed_primitives = 1 << 5,
6479*61046927SAndroid Build Coastguard Worker } nir_lower_gs_intrinsics_flags;
6480*61046927SAndroid Build Coastguard Worker
6481*61046927SAndroid Build Coastguard Worker bool nir_lower_gs_intrinsics(nir_shader *shader, nir_lower_gs_intrinsics_flags options);
6482*61046927SAndroid Build Coastguard Worker
6483*61046927SAndroid Build Coastguard Worker bool nir_lower_tess_coord_z(nir_shader *shader, bool triangles);
6484*61046927SAndroid Build Coastguard Worker
6485*61046927SAndroid Build Coastguard Worker typedef struct {
6486*61046927SAndroid Build Coastguard Worker bool payload_to_shared_for_atomics : 1;
6487*61046927SAndroid Build Coastguard Worker bool payload_to_shared_for_small_types : 1;
6488*61046927SAndroid Build Coastguard Worker uint32_t payload_offset_in_bytes;
6489*61046927SAndroid Build Coastguard Worker } nir_lower_task_shader_options;
6490*61046927SAndroid Build Coastguard Worker
6491*61046927SAndroid Build Coastguard Worker bool nir_lower_task_shader(nir_shader *shader, nir_lower_task_shader_options options);
6492*61046927SAndroid Build Coastguard Worker
6493*61046927SAndroid Build Coastguard Worker typedef unsigned (*nir_lower_bit_size_callback)(const nir_instr *, void *);
6494*61046927SAndroid Build Coastguard Worker
6495*61046927SAndroid Build Coastguard Worker bool nir_lower_bit_size(nir_shader *shader,
6496*61046927SAndroid Build Coastguard Worker nir_lower_bit_size_callback callback,
6497*61046927SAndroid Build Coastguard Worker void *callback_data);
6498*61046927SAndroid Build Coastguard Worker bool nir_lower_64bit_phis(nir_shader *shader);
6499*61046927SAndroid Build Coastguard Worker
6500*61046927SAndroid Build Coastguard Worker bool nir_split_64bit_vec3_and_vec4(nir_shader *shader);
6501*61046927SAndroid Build Coastguard Worker
6502*61046927SAndroid Build Coastguard Worker nir_lower_int64_options nir_lower_int64_op_to_options_mask(nir_op opcode);
6503*61046927SAndroid Build Coastguard Worker bool nir_lower_int64(nir_shader *shader);
6504*61046927SAndroid Build Coastguard Worker bool nir_lower_int64_float_conversions(nir_shader *shader);
6505*61046927SAndroid Build Coastguard Worker
6506*61046927SAndroid Build Coastguard Worker nir_lower_doubles_options nir_lower_doubles_op_to_options_mask(nir_op opcode);
6507*61046927SAndroid Build Coastguard Worker bool nir_lower_doubles(nir_shader *shader, const nir_shader *softfp64,
6508*61046927SAndroid Build Coastguard Worker nir_lower_doubles_options options);
6509*61046927SAndroid Build Coastguard Worker bool nir_lower_pack(nir_shader *shader);
6510*61046927SAndroid Build Coastguard Worker
6511*61046927SAndroid Build Coastguard Worker bool nir_recompute_io_bases(nir_shader *nir, nir_variable_mode modes);
6512*61046927SAndroid Build Coastguard Worker bool nir_lower_mediump_vars(nir_shader *nir, nir_variable_mode modes);
6513*61046927SAndroid Build Coastguard Worker bool nir_lower_mediump_io(nir_shader *nir, nir_variable_mode modes,
6514*61046927SAndroid Build Coastguard Worker uint64_t varying_mask, bool use_16bit_slots);
6515*61046927SAndroid Build Coastguard Worker bool nir_force_mediump_io(nir_shader *nir, nir_variable_mode modes,
6516*61046927SAndroid Build Coastguard Worker nir_alu_type types);
6517*61046927SAndroid Build Coastguard Worker bool nir_unpack_16bit_varying_slots(nir_shader *nir, nir_variable_mode modes);
6518*61046927SAndroid Build Coastguard Worker
6519*61046927SAndroid Build Coastguard Worker struct nir_opt_tex_srcs_options {
6520*61046927SAndroid Build Coastguard Worker unsigned sampler_dims;
6521*61046927SAndroid Build Coastguard Worker unsigned src_types;
6522*61046927SAndroid Build Coastguard Worker };
6523*61046927SAndroid Build Coastguard Worker
6524*61046927SAndroid Build Coastguard Worker struct nir_opt_16bit_tex_image_options {
6525*61046927SAndroid Build Coastguard Worker nir_rounding_mode rounding_mode;
6526*61046927SAndroid Build Coastguard Worker nir_alu_type opt_tex_dest_types;
6527*61046927SAndroid Build Coastguard Worker nir_alu_type opt_image_dest_types;
6528*61046927SAndroid Build Coastguard Worker bool integer_dest_saturates;
6529*61046927SAndroid Build Coastguard Worker bool opt_image_store_data;
6530*61046927SAndroid Build Coastguard Worker bool opt_image_srcs;
6531*61046927SAndroid Build Coastguard Worker unsigned opt_srcs_options_count;
6532*61046927SAndroid Build Coastguard Worker struct nir_opt_tex_srcs_options *opt_srcs_options;
6533*61046927SAndroid Build Coastguard Worker };
6534*61046927SAndroid Build Coastguard Worker
6535*61046927SAndroid Build Coastguard Worker bool nir_opt_16bit_tex_image(nir_shader *nir,
6536*61046927SAndroid Build Coastguard Worker struct nir_opt_16bit_tex_image_options *options);
6537*61046927SAndroid Build Coastguard Worker
6538*61046927SAndroid Build Coastguard Worker typedef struct {
6539*61046927SAndroid Build Coastguard Worker bool legalize_type; /* whether this src should be legalized */
6540*61046927SAndroid Build Coastguard Worker uint8_t bit_size; /* bit_size to enforce */
6541*61046927SAndroid Build Coastguard Worker nir_tex_src_type match_src; /* if bit_size is 0, match bit size of this */
6542*61046927SAndroid Build Coastguard Worker } nir_tex_src_type_constraint, nir_tex_src_type_constraints[nir_num_tex_src_types];
6543*61046927SAndroid Build Coastguard Worker
6544*61046927SAndroid Build Coastguard Worker bool nir_legalize_16bit_sampler_srcs(nir_shader *nir,
6545*61046927SAndroid Build Coastguard Worker nir_tex_src_type_constraints constraints);
6546*61046927SAndroid Build Coastguard Worker
6547*61046927SAndroid Build Coastguard Worker bool nir_lower_point_size(nir_shader *shader, float min, float max);
6548*61046927SAndroid Build Coastguard Worker
6549*61046927SAndroid Build Coastguard Worker void nir_lower_texcoord_replace(nir_shader *s, unsigned coord_replace,
6550*61046927SAndroid Build Coastguard Worker bool point_coord_is_sysval, bool yinvert);
6551*61046927SAndroid Build Coastguard Worker
6552*61046927SAndroid Build Coastguard Worker void nir_lower_texcoord_replace_late(nir_shader *s, unsigned coord_replace,
6553*61046927SAndroid Build Coastguard Worker bool point_coord_is_sysval);
6554*61046927SAndroid Build Coastguard Worker
6555*61046927SAndroid Build Coastguard Worker typedef enum {
6556*61046927SAndroid Build Coastguard Worker nir_lower_interpolation_at_sample = (1 << 1),
6557*61046927SAndroid Build Coastguard Worker nir_lower_interpolation_at_offset = (1 << 2),
6558*61046927SAndroid Build Coastguard Worker nir_lower_interpolation_centroid = (1 << 3),
6559*61046927SAndroid Build Coastguard Worker nir_lower_interpolation_pixel = (1 << 4),
6560*61046927SAndroid Build Coastguard Worker nir_lower_interpolation_sample = (1 << 5),
6561*61046927SAndroid Build Coastguard Worker } nir_lower_interpolation_options;
6562*61046927SAndroid Build Coastguard Worker
6563*61046927SAndroid Build Coastguard Worker bool nir_lower_interpolation(nir_shader *shader,
6564*61046927SAndroid Build Coastguard Worker nir_lower_interpolation_options options);
6565*61046927SAndroid Build Coastguard Worker
6566*61046927SAndroid Build Coastguard Worker typedef enum {
6567*61046927SAndroid Build Coastguard Worker nir_lower_discard_if_to_cf = (1 << 0),
6568*61046927SAndroid Build Coastguard Worker nir_lower_demote_if_to_cf = (1 << 1),
6569*61046927SAndroid Build Coastguard Worker nir_lower_terminate_if_to_cf = (1 << 2),
6570*61046927SAndroid Build Coastguard Worker } nir_lower_discard_if_options;
6571*61046927SAndroid Build Coastguard Worker
6572*61046927SAndroid Build Coastguard Worker bool nir_lower_discard_if(nir_shader *shader, nir_lower_discard_if_options options);
6573*61046927SAndroid Build Coastguard Worker
6574*61046927SAndroid Build Coastguard Worker bool nir_lower_terminate_to_demote(nir_shader *nir);
6575*61046927SAndroid Build Coastguard Worker
6576*61046927SAndroid Build Coastguard Worker bool nir_lower_memory_model(nir_shader *shader);
6577*61046927SAndroid Build Coastguard Worker
6578*61046927SAndroid Build Coastguard Worker bool nir_lower_goto_ifs(nir_shader *shader);
6579*61046927SAndroid Build Coastguard Worker bool nir_lower_continue_constructs(nir_shader *shader);
6580*61046927SAndroid Build Coastguard Worker
6581*61046927SAndroid Build Coastguard Worker bool nir_shader_uses_view_index(nir_shader *shader);
6582*61046927SAndroid Build Coastguard Worker bool nir_can_lower_multiview(nir_shader *shader);
6583*61046927SAndroid Build Coastguard Worker bool nir_lower_multiview(nir_shader *shader, uint32_t view_mask);
6584*61046927SAndroid Build Coastguard Worker
6585*61046927SAndroid Build Coastguard Worker bool nir_lower_view_index_to_device_index(nir_shader *shader);
6586*61046927SAndroid Build Coastguard Worker
6587*61046927SAndroid Build Coastguard Worker typedef enum {
6588*61046927SAndroid Build Coastguard Worker nir_lower_fp16_rtz = (1 << 0),
6589*61046927SAndroid Build Coastguard Worker nir_lower_fp16_rtne = (1 << 1),
6590*61046927SAndroid Build Coastguard Worker nir_lower_fp16_ru = (1 << 2),
6591*61046927SAndroid Build Coastguard Worker nir_lower_fp16_rd = (1 << 3),
6592*61046927SAndroid Build Coastguard Worker nir_lower_fp16_all = 0xf,
6593*61046927SAndroid Build Coastguard Worker nir_lower_fp16_split_fp64 = (1 << 4),
6594*61046927SAndroid Build Coastguard Worker } nir_lower_fp16_cast_options;
6595*61046927SAndroid Build Coastguard Worker bool nir_lower_fp16_casts(nir_shader *shader, nir_lower_fp16_cast_options options);
6596*61046927SAndroid Build Coastguard Worker bool nir_normalize_cubemap_coords(nir_shader *shader);
6597*61046927SAndroid Build Coastguard Worker
6598*61046927SAndroid Build Coastguard Worker bool nir_shader_supports_implicit_lod(nir_shader *shader);
6599*61046927SAndroid Build Coastguard Worker
6600*61046927SAndroid Build Coastguard Worker void nir_live_defs_impl(nir_function_impl *impl);
6601*61046927SAndroid Build Coastguard Worker
6602*61046927SAndroid Build Coastguard Worker const BITSET_WORD *nir_get_live_defs(nir_cursor cursor, void *mem_ctx);
6603*61046927SAndroid Build Coastguard Worker
6604*61046927SAndroid Build Coastguard Worker void nir_loop_analyze_impl(nir_function_impl *impl,
6605*61046927SAndroid Build Coastguard Worker nir_variable_mode indirect_mask,
6606*61046927SAndroid Build Coastguard Worker bool force_unroll_sampler_indirect);
6607*61046927SAndroid Build Coastguard Worker
6608*61046927SAndroid Build Coastguard Worker bool nir_defs_interfere(nir_def *a, nir_def *b);
6609*61046927SAndroid Build Coastguard Worker
6610*61046927SAndroid Build Coastguard Worker bool nir_repair_ssa_impl(nir_function_impl *impl);
6611*61046927SAndroid Build Coastguard Worker bool nir_repair_ssa(nir_shader *shader);
6612*61046927SAndroid Build Coastguard Worker
6613*61046927SAndroid Build Coastguard Worker void nir_convert_loop_to_lcssa(nir_loop *loop);
6614*61046927SAndroid Build Coastguard Worker bool nir_convert_to_lcssa(nir_shader *shader, bool skip_invariants, bool skip_bool_invariants);
6615*61046927SAndroid Build Coastguard Worker void nir_divergence_analysis(nir_shader *shader);
6616*61046927SAndroid Build Coastguard Worker void nir_vertex_divergence_analysis(nir_shader *shader);
6617*61046927SAndroid Build Coastguard Worker bool nir_update_instr_divergence(nir_shader *shader, nir_instr *instr);
6618*61046927SAndroid Build Coastguard Worker bool nir_has_divergent_loop(nir_shader *shader);
6619*61046927SAndroid Build Coastguard Worker
6620*61046927SAndroid Build Coastguard Worker void
6621*61046927SAndroid Build Coastguard Worker nir_rewrite_uses_to_load_reg(struct nir_builder *b, nir_def *old,
6622*61046927SAndroid Build Coastguard Worker nir_def *reg);
6623*61046927SAndroid Build Coastguard Worker
6624*61046927SAndroid Build Coastguard Worker /* If phi_webs_only is true, only convert SSA values involved in phi nodes to
6625*61046927SAndroid Build Coastguard Worker * registers. If false, convert all values (even those not involved in a phi
6626*61046927SAndroid Build Coastguard Worker * node) to registers.
6627*61046927SAndroid Build Coastguard Worker */
6628*61046927SAndroid Build Coastguard Worker bool nir_convert_from_ssa(nir_shader *shader,
6629*61046927SAndroid Build Coastguard Worker bool phi_webs_only);
6630*61046927SAndroid Build Coastguard Worker
6631*61046927SAndroid Build Coastguard Worker bool nir_lower_phis_to_regs_block(nir_block *block);
6632*61046927SAndroid Build Coastguard Worker bool nir_lower_ssa_defs_to_regs_block(nir_block *block);
6633*61046927SAndroid Build Coastguard Worker
6634*61046927SAndroid Build Coastguard Worker bool nir_rematerialize_deref_in_use_blocks(nir_deref_instr *instr);
6635*61046927SAndroid Build Coastguard Worker bool nir_rematerialize_derefs_in_use_blocks_impl(nir_function_impl *impl);
6636*61046927SAndroid Build Coastguard Worker
6637*61046927SAndroid Build Coastguard Worker bool nir_lower_samplers(nir_shader *shader);
6638*61046927SAndroid Build Coastguard Worker bool nir_lower_cl_images(nir_shader *shader, bool lower_image_derefs, bool lower_sampler_derefs);
6639*61046927SAndroid Build Coastguard Worker bool nir_dedup_inline_samplers(nir_shader *shader);
6640*61046927SAndroid Build Coastguard Worker
6641*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_ssbo_options {
6642*61046927SAndroid Build Coastguard Worker bool native_loads;
6643*61046927SAndroid Build Coastguard Worker bool native_offset;
6644*61046927SAndroid Build Coastguard Worker } nir_lower_ssbo_options;
6645*61046927SAndroid Build Coastguard Worker
6646*61046927SAndroid Build Coastguard Worker bool nir_lower_ssbo(nir_shader *shader, const nir_lower_ssbo_options *opts);
6647*61046927SAndroid Build Coastguard Worker
6648*61046927SAndroid Build Coastguard Worker bool nir_lower_helper_writes(nir_shader *shader, bool lower_plain_stores);
6649*61046927SAndroid Build Coastguard Worker
6650*61046927SAndroid Build Coastguard Worker typedef struct nir_lower_printf_options {
6651*61046927SAndroid Build Coastguard Worker unsigned max_buffer_size;
6652*61046927SAndroid Build Coastguard Worker unsigned ptr_bit_size;
6653*61046927SAndroid Build Coastguard Worker bool use_printf_base_identifier;
6654*61046927SAndroid Build Coastguard Worker } nir_lower_printf_options;
6655*61046927SAndroid Build Coastguard Worker
6656*61046927SAndroid Build Coastguard Worker bool nir_lower_printf(nir_shader *nir, const nir_lower_printf_options *options);
6657*61046927SAndroid Build Coastguard Worker
6658*61046927SAndroid Build Coastguard Worker /* This is here for unit tests. */
6659*61046927SAndroid Build Coastguard Worker bool nir_opt_comparison_pre_impl(nir_function_impl *impl);
6660*61046927SAndroid Build Coastguard Worker
6661*61046927SAndroid Build Coastguard Worker bool nir_opt_comparison_pre(nir_shader *shader);
6662*61046927SAndroid Build Coastguard Worker
6663*61046927SAndroid Build Coastguard Worker typedef struct nir_opt_access_options {
6664*61046927SAndroid Build Coastguard Worker bool is_vulkan;
6665*61046927SAndroid Build Coastguard Worker } nir_opt_access_options;
6666*61046927SAndroid Build Coastguard Worker
6667*61046927SAndroid Build Coastguard Worker bool nir_opt_access(nir_shader *shader, const nir_opt_access_options *options);
6668*61046927SAndroid Build Coastguard Worker bool nir_opt_algebraic(nir_shader *shader);
6669*61046927SAndroid Build Coastguard Worker bool nir_opt_algebraic_before_ffma(nir_shader *shader);
6670*61046927SAndroid Build Coastguard Worker bool nir_opt_algebraic_before_lower_int64(nir_shader *shader);
6671*61046927SAndroid Build Coastguard Worker bool nir_opt_algebraic_late(nir_shader *shader);
6672*61046927SAndroid Build Coastguard Worker bool nir_opt_algebraic_distribute_src_mods(nir_shader *shader);
6673*61046927SAndroid Build Coastguard Worker bool nir_opt_constant_folding(nir_shader *shader);
6674*61046927SAndroid Build Coastguard Worker
6675*61046927SAndroid Build Coastguard Worker /* Try to combine a and b into a. Return true if combination was possible,
6676*61046927SAndroid Build Coastguard Worker * which will result in b being removed by the pass. Return false if
6677*61046927SAndroid Build Coastguard Worker * combination wasn't possible.
6678*61046927SAndroid Build Coastguard Worker */
6679*61046927SAndroid Build Coastguard Worker typedef bool (*nir_combine_barrier_cb)(
6680*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *a, nir_intrinsic_instr *b, void *data);
6681*61046927SAndroid Build Coastguard Worker
6682*61046927SAndroid Build Coastguard Worker bool nir_opt_combine_barriers(nir_shader *shader,
6683*61046927SAndroid Build Coastguard Worker nir_combine_barrier_cb combine_cb,
6684*61046927SAndroid Build Coastguard Worker void *data);
6685*61046927SAndroid Build Coastguard Worker bool nir_opt_barrier_modes(nir_shader *shader);
6686*61046927SAndroid Build Coastguard Worker
6687*61046927SAndroid Build Coastguard Worker bool nir_opt_combine_stores(nir_shader *shader, nir_variable_mode modes);
6688*61046927SAndroid Build Coastguard Worker
6689*61046927SAndroid Build Coastguard Worker bool nir_copy_prop_impl(nir_function_impl *impl);
6690*61046927SAndroid Build Coastguard Worker bool nir_copy_prop(nir_shader *shader);
6691*61046927SAndroid Build Coastguard Worker
6692*61046927SAndroid Build Coastguard Worker bool nir_opt_copy_prop_vars(nir_shader *shader);
6693*61046927SAndroid Build Coastguard Worker
6694*61046927SAndroid Build Coastguard Worker bool nir_opt_cse(nir_shader *shader);
6695*61046927SAndroid Build Coastguard Worker
6696*61046927SAndroid Build Coastguard Worker bool nir_opt_dce(nir_shader *shader);
6697*61046927SAndroid Build Coastguard Worker
6698*61046927SAndroid Build Coastguard Worker bool nir_opt_dead_cf(nir_shader *shader);
6699*61046927SAndroid Build Coastguard Worker
6700*61046927SAndroid Build Coastguard Worker bool nir_opt_dead_write_vars(nir_shader *shader);
6701*61046927SAndroid Build Coastguard Worker
6702*61046927SAndroid Build Coastguard Worker bool nir_opt_deref_impl(nir_function_impl *impl);
6703*61046927SAndroid Build Coastguard Worker bool nir_opt_deref(nir_shader *shader);
6704*61046927SAndroid Build Coastguard Worker
6705*61046927SAndroid Build Coastguard Worker bool nir_opt_find_array_copies(nir_shader *shader);
6706*61046927SAndroid Build Coastguard Worker
6707*61046927SAndroid Build Coastguard Worker bool nir_opt_fragdepth(nir_shader *shader);
6708*61046927SAndroid Build Coastguard Worker
6709*61046927SAndroid Build Coastguard Worker bool nir_opt_gcm(nir_shader *shader, bool value_number);
6710*61046927SAndroid Build Coastguard Worker
6711*61046927SAndroid Build Coastguard Worker bool nir_opt_generate_bfi(nir_shader *shader);
6712*61046927SAndroid Build Coastguard Worker
6713*61046927SAndroid Build Coastguard Worker bool nir_opt_idiv_const(nir_shader *shader, unsigned min_bit_size);
6714*61046927SAndroid Build Coastguard Worker
6715*61046927SAndroid Build Coastguard Worker bool nir_opt_mqsad(nir_shader *shader);
6716*61046927SAndroid Build Coastguard Worker
6717*61046927SAndroid Build Coastguard Worker typedef enum {
6718*61046927SAndroid Build Coastguard Worker nir_opt_if_optimize_phi_true_false = (1 << 0),
6719*61046927SAndroid Build Coastguard Worker nir_opt_if_avoid_64bit_phis = (1 << 1),
6720*61046927SAndroid Build Coastguard Worker } nir_opt_if_options;
6721*61046927SAndroid Build Coastguard Worker
6722*61046927SAndroid Build Coastguard Worker bool nir_opt_if(nir_shader *shader, nir_opt_if_options options);
6723*61046927SAndroid Build Coastguard Worker
6724*61046927SAndroid Build Coastguard Worker bool nir_opt_intrinsics(nir_shader *shader);
6725*61046927SAndroid Build Coastguard Worker
6726*61046927SAndroid Build Coastguard Worker bool nir_opt_large_constants(nir_shader *shader,
6727*61046927SAndroid Build Coastguard Worker glsl_type_size_align_func size_align,
6728*61046927SAndroid Build Coastguard Worker unsigned threshold);
6729*61046927SAndroid Build Coastguard Worker
6730*61046927SAndroid Build Coastguard Worker bool nir_opt_licm(nir_shader *shader);
6731*61046927SAndroid Build Coastguard Worker bool nir_opt_loop(nir_shader *shader);
6732*61046927SAndroid Build Coastguard Worker
6733*61046927SAndroid Build Coastguard Worker bool nir_opt_loop_unroll(nir_shader *shader);
6734*61046927SAndroid Build Coastguard Worker
6735*61046927SAndroid Build Coastguard Worker typedef enum {
6736*61046927SAndroid Build Coastguard Worker nir_move_const_undef = (1 << 0),
6737*61046927SAndroid Build Coastguard Worker nir_move_load_ubo = (1 << 1),
6738*61046927SAndroid Build Coastguard Worker nir_move_load_input = (1 << 2),
6739*61046927SAndroid Build Coastguard Worker nir_move_comparisons = (1 << 3),
6740*61046927SAndroid Build Coastguard Worker nir_move_copies = (1 << 4),
6741*61046927SAndroid Build Coastguard Worker nir_move_load_ssbo = (1 << 5),
6742*61046927SAndroid Build Coastguard Worker nir_move_load_uniform = (1 << 6),
6743*61046927SAndroid Build Coastguard Worker nir_move_alu = (1 << 7),
6744*61046927SAndroid Build Coastguard Worker } nir_move_options;
6745*61046927SAndroid Build Coastguard Worker
6746*61046927SAndroid Build Coastguard Worker bool nir_can_move_instr(nir_instr *instr, nir_move_options options);
6747*61046927SAndroid Build Coastguard Worker
6748*61046927SAndroid Build Coastguard Worker bool nir_opt_sink(nir_shader *shader, nir_move_options options);
6749*61046927SAndroid Build Coastguard Worker
6750*61046927SAndroid Build Coastguard Worker bool nir_opt_move(nir_shader *shader, nir_move_options options);
6751*61046927SAndroid Build Coastguard Worker
6752*61046927SAndroid Build Coastguard Worker typedef struct {
6753*61046927SAndroid Build Coastguard Worker /** nir_load_uniform max base offset */
6754*61046927SAndroid Build Coastguard Worker uint32_t uniform_max;
6755*61046927SAndroid Build Coastguard Worker
6756*61046927SAndroid Build Coastguard Worker /** nir_load_ubo_vec4 max base offset */
6757*61046927SAndroid Build Coastguard Worker uint32_t ubo_vec4_max;
6758*61046927SAndroid Build Coastguard Worker
6759*61046927SAndroid Build Coastguard Worker /** nir_var_mem_shared max base offset */
6760*61046927SAndroid Build Coastguard Worker uint32_t shared_max;
6761*61046927SAndroid Build Coastguard Worker
6762*61046927SAndroid Build Coastguard Worker /** nir_load/store_buffer_amd max base offset */
6763*61046927SAndroid Build Coastguard Worker uint32_t buffer_max;
6764*61046927SAndroid Build Coastguard Worker
6765*61046927SAndroid Build Coastguard Worker /**
6766*61046927SAndroid Build Coastguard Worker * Callback to get the max base offset for instructions for which the
6767*61046927SAndroid Build Coastguard Worker * corresponding value above is zero.
6768*61046927SAndroid Build Coastguard Worker */
6769*61046927SAndroid Build Coastguard Worker uint32_t (*max_offset_cb)(nir_intrinsic_instr *intr, const void *data);
6770*61046927SAndroid Build Coastguard Worker
6771*61046927SAndroid Build Coastguard Worker /** Data to pass to max_offset_cb. */
6772*61046927SAndroid Build Coastguard Worker const void *max_offset_data;
6773*61046927SAndroid Build Coastguard Worker
6774*61046927SAndroid Build Coastguard Worker /**
6775*61046927SAndroid Build Coastguard Worker * Allow the offset calculation to wrap. If false, constant additions that
6776*61046927SAndroid Build Coastguard Worker * might wrap will not be folded into the offset.
6777*61046927SAndroid Build Coastguard Worker */
6778*61046927SAndroid Build Coastguard Worker bool allow_offset_wrap;
6779*61046927SAndroid Build Coastguard Worker } nir_opt_offsets_options;
6780*61046927SAndroid Build Coastguard Worker
6781*61046927SAndroid Build Coastguard Worker bool nir_opt_offsets(nir_shader *shader, const nir_opt_offsets_options *options);
6782*61046927SAndroid Build Coastguard Worker
6783*61046927SAndroid Build Coastguard Worker bool nir_opt_peephole_select(nir_shader *shader, unsigned limit,
6784*61046927SAndroid Build Coastguard Worker bool indirect_load_ok, bool expensive_alu_ok);
6785*61046927SAndroid Build Coastguard Worker
6786*61046927SAndroid Build Coastguard Worker bool nir_opt_reassociate_bfi(nir_shader *shader);
6787*61046927SAndroid Build Coastguard Worker
6788*61046927SAndroid Build Coastguard Worker bool nir_opt_rematerialize_compares(nir_shader *shader);
6789*61046927SAndroid Build Coastguard Worker
6790*61046927SAndroid Build Coastguard Worker bool nir_opt_remove_phis(nir_shader *shader);
6791*61046927SAndroid Build Coastguard Worker bool nir_opt_remove_phis_block(nir_block *block);
6792*61046927SAndroid Build Coastguard Worker
6793*61046927SAndroid Build Coastguard Worker bool nir_opt_phi_precision(nir_shader *shader);
6794*61046927SAndroid Build Coastguard Worker
6795*61046927SAndroid Build Coastguard Worker bool nir_opt_shrink_stores(nir_shader *shader, bool shrink_image_store);
6796*61046927SAndroid Build Coastguard Worker
6797*61046927SAndroid Build Coastguard Worker bool nir_opt_shrink_vectors(nir_shader *shader, bool shrink_start);
6798*61046927SAndroid Build Coastguard Worker
6799*61046927SAndroid Build Coastguard Worker bool nir_opt_undef(nir_shader *shader);
6800*61046927SAndroid Build Coastguard Worker
6801*61046927SAndroid Build Coastguard Worker bool nir_lower_undef_to_zero(nir_shader *shader);
6802*61046927SAndroid Build Coastguard Worker
6803*61046927SAndroid Build Coastguard Worker bool nir_opt_uniform_atomics(nir_shader *shader, bool fs_atomics_predicated);
6804*61046927SAndroid Build Coastguard Worker
6805*61046927SAndroid Build Coastguard Worker bool nir_opt_uniform_subgroup(nir_shader *shader,
6806*61046927SAndroid Build Coastguard Worker const nir_lower_subgroups_options *);
6807*61046927SAndroid Build Coastguard Worker
6808*61046927SAndroid Build Coastguard Worker bool nir_opt_vectorize(nir_shader *shader, nir_vectorize_cb filter,
6809*61046927SAndroid Build Coastguard Worker void *data);
6810*61046927SAndroid Build Coastguard Worker bool nir_opt_vectorize_io(nir_shader *shader, nir_variable_mode modes);
6811*61046927SAndroid Build Coastguard Worker
6812*61046927SAndroid Build Coastguard Worker bool nir_opt_conditional_discard(nir_shader *shader);
6813*61046927SAndroid Build Coastguard Worker bool nir_opt_move_discards_to_top(nir_shader *shader);
6814*61046927SAndroid Build Coastguard Worker
6815*61046927SAndroid Build Coastguard Worker bool nir_opt_ray_queries(nir_shader *shader);
6816*61046927SAndroid Build Coastguard Worker
6817*61046927SAndroid Build Coastguard Worker bool nir_opt_ray_query_ranges(nir_shader *shader);
6818*61046927SAndroid Build Coastguard Worker
6819*61046927SAndroid Build Coastguard Worker bool nir_opt_reuse_constants(nir_shader *shader);
6820*61046927SAndroid Build Coastguard Worker
6821*61046927SAndroid Build Coastguard Worker void nir_sweep(nir_shader *shader);
6822*61046927SAndroid Build Coastguard Worker
6823*61046927SAndroid Build Coastguard Worker void nir_remap_dual_slot_attributes(nir_shader *shader,
6824*61046927SAndroid Build Coastguard Worker uint64_t *dual_slot_inputs);
6825*61046927SAndroid Build Coastguard Worker uint64_t nir_get_single_slot_attribs_mask(uint64_t attribs, uint64_t dual_slot);
6826*61046927SAndroid Build Coastguard Worker
6827*61046927SAndroid Build Coastguard Worker nir_intrinsic_op nir_intrinsic_from_system_value(gl_system_value val);
6828*61046927SAndroid Build Coastguard Worker gl_system_value nir_system_value_from_intrinsic(nir_intrinsic_op intrin);
6829*61046927SAndroid Build Coastguard Worker
6830*61046927SAndroid Build Coastguard Worker static inline bool
nir_variable_is_in_ubo(const nir_variable * var)6831*61046927SAndroid Build Coastguard Worker nir_variable_is_in_ubo(const nir_variable *var)
6832*61046927SAndroid Build Coastguard Worker {
6833*61046927SAndroid Build Coastguard Worker return (var->data.mode == nir_var_mem_ubo &&
6834*61046927SAndroid Build Coastguard Worker var->interface_type != NULL);
6835*61046927SAndroid Build Coastguard Worker }
6836*61046927SAndroid Build Coastguard Worker
6837*61046927SAndroid Build Coastguard Worker static inline bool
nir_variable_is_in_ssbo(const nir_variable * var)6838*61046927SAndroid Build Coastguard Worker nir_variable_is_in_ssbo(const nir_variable *var)
6839*61046927SAndroid Build Coastguard Worker {
6840*61046927SAndroid Build Coastguard Worker return (var->data.mode == nir_var_mem_ssbo &&
6841*61046927SAndroid Build Coastguard Worker var->interface_type != NULL);
6842*61046927SAndroid Build Coastguard Worker }
6843*61046927SAndroid Build Coastguard Worker
6844*61046927SAndroid Build Coastguard Worker static inline bool
nir_variable_is_in_block(const nir_variable * var)6845*61046927SAndroid Build Coastguard Worker nir_variable_is_in_block(const nir_variable *var)
6846*61046927SAndroid Build Coastguard Worker {
6847*61046927SAndroid Build Coastguard Worker return nir_variable_is_in_ubo(var) || nir_variable_is_in_ssbo(var);
6848*61046927SAndroid Build Coastguard Worker }
6849*61046927SAndroid Build Coastguard Worker
6850*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_variable_count_slots(const nir_variable * var,const struct glsl_type * type)6851*61046927SAndroid Build Coastguard Worker nir_variable_count_slots(const nir_variable *var, const struct glsl_type *type)
6852*61046927SAndroid Build Coastguard Worker {
6853*61046927SAndroid Build Coastguard Worker return var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(type), 4) : glsl_count_attribute_slots(type, false);
6854*61046927SAndroid Build Coastguard Worker }
6855*61046927SAndroid Build Coastguard Worker
6856*61046927SAndroid Build Coastguard Worker static inline unsigned
nir_deref_count_slots(nir_deref_instr * deref,nir_variable * var)6857*61046927SAndroid Build Coastguard Worker nir_deref_count_slots(nir_deref_instr *deref, nir_variable *var)
6858*61046927SAndroid Build Coastguard Worker {
6859*61046927SAndroid Build Coastguard Worker if (var->data.compact) {
6860*61046927SAndroid Build Coastguard Worker switch (deref->deref_type) {
6861*61046927SAndroid Build Coastguard Worker case nir_deref_type_array:
6862*61046927SAndroid Build Coastguard Worker return 1;
6863*61046927SAndroid Build Coastguard Worker case nir_deref_type_var:
6864*61046927SAndroid Build Coastguard Worker return nir_variable_count_slots(var, deref->type);
6865*61046927SAndroid Build Coastguard Worker default:
6866*61046927SAndroid Build Coastguard Worker unreachable("illegal deref type");
6867*61046927SAndroid Build Coastguard Worker }
6868*61046927SAndroid Build Coastguard Worker }
6869*61046927SAndroid Build Coastguard Worker return glsl_count_attribute_slots(deref->type, false);
6870*61046927SAndroid Build Coastguard Worker }
6871*61046927SAndroid Build Coastguard Worker
6872*61046927SAndroid Build Coastguard Worker /* See default_ub_config in nir_range_analysis.c for documentation. */
6873*61046927SAndroid Build Coastguard Worker typedef struct nir_unsigned_upper_bound_config {
6874*61046927SAndroid Build Coastguard Worker unsigned min_subgroup_size;
6875*61046927SAndroid Build Coastguard Worker unsigned max_subgroup_size;
6876*61046927SAndroid Build Coastguard Worker unsigned max_workgroup_invocations;
6877*61046927SAndroid Build Coastguard Worker unsigned max_workgroup_count[3];
6878*61046927SAndroid Build Coastguard Worker unsigned max_workgroup_size[3];
6879*61046927SAndroid Build Coastguard Worker
6880*61046927SAndroid Build Coastguard Worker uint32_t vertex_attrib_max[32];
6881*61046927SAndroid Build Coastguard Worker } nir_unsigned_upper_bound_config;
6882*61046927SAndroid Build Coastguard Worker
6883*61046927SAndroid Build Coastguard Worker uint32_t
6884*61046927SAndroid Build Coastguard Worker nir_unsigned_upper_bound(nir_shader *shader, struct hash_table *range_ht,
6885*61046927SAndroid Build Coastguard Worker nir_scalar scalar,
6886*61046927SAndroid Build Coastguard Worker const nir_unsigned_upper_bound_config *config);
6887*61046927SAndroid Build Coastguard Worker
6888*61046927SAndroid Build Coastguard Worker bool
6889*61046927SAndroid Build Coastguard Worker nir_addition_might_overflow(nir_shader *shader, struct hash_table *range_ht,
6890*61046927SAndroid Build Coastguard Worker nir_scalar ssa, unsigned const_val,
6891*61046927SAndroid Build Coastguard Worker const nir_unsigned_upper_bound_config *config);
6892*61046927SAndroid Build Coastguard Worker
6893*61046927SAndroid Build Coastguard Worker typedef struct {
6894*61046927SAndroid Build Coastguard Worker /* True if gl_DrawID is considered uniform, i.e. if the preamble is run
6895*61046927SAndroid Build Coastguard Worker * at least once per "internal" draw rather than per user-visible draw.
6896*61046927SAndroid Build Coastguard Worker */
6897*61046927SAndroid Build Coastguard Worker bool drawid_uniform;
6898*61046927SAndroid Build Coastguard Worker
6899*61046927SAndroid Build Coastguard Worker /* True if the subgroup size is uniform. */
6900*61046927SAndroid Build Coastguard Worker bool subgroup_size_uniform;
6901*61046927SAndroid Build Coastguard Worker
6902*61046927SAndroid Build Coastguard Worker /* True if load_workgroup_size is supported in the preamble. */
6903*61046927SAndroid Build Coastguard Worker bool load_workgroup_size_allowed;
6904*61046927SAndroid Build Coastguard Worker
6905*61046927SAndroid Build Coastguard Worker /* size/align for load/store_preamble. */
6906*61046927SAndroid Build Coastguard Worker void (*def_size)(nir_def *def, unsigned *size, unsigned *align);
6907*61046927SAndroid Build Coastguard Worker
6908*61046927SAndroid Build Coastguard Worker /* Total available size for load/store_preamble storage, in units
6909*61046927SAndroid Build Coastguard Worker * determined by def_size.
6910*61046927SAndroid Build Coastguard Worker */
6911*61046927SAndroid Build Coastguard Worker unsigned preamble_storage_size;
6912*61046927SAndroid Build Coastguard Worker
6913*61046927SAndroid Build Coastguard Worker /* Give the cost for an instruction. nir_opt_preamble will prioritize
6914*61046927SAndroid Build Coastguard Worker * instructions with higher costs. Instructions with cost 0 may still be
6915*61046927SAndroid Build Coastguard Worker * lifted, but only when required to lift other instructions with non-0
6916*61046927SAndroid Build Coastguard Worker * cost (e.g. a load_const source of an expression).
6917*61046927SAndroid Build Coastguard Worker */
6918*61046927SAndroid Build Coastguard Worker float (*instr_cost_cb)(nir_instr *instr, const void *data);
6919*61046927SAndroid Build Coastguard Worker
6920*61046927SAndroid Build Coastguard Worker /* Give the cost of rewriting the instruction to use load_preamble. This
6921*61046927SAndroid Build Coastguard Worker * may happen from inserting move instructions, etc. If the benefit doesn't
6922*61046927SAndroid Build Coastguard Worker * exceed the cost here then we won't rewrite it.
6923*61046927SAndroid Build Coastguard Worker */
6924*61046927SAndroid Build Coastguard Worker float (*rewrite_cost_cb)(nir_def *def, const void *data);
6925*61046927SAndroid Build Coastguard Worker
6926*61046927SAndroid Build Coastguard Worker /* Instructions whose definitions should not be rewritten. These could
6927*61046927SAndroid Build Coastguard Worker * still be moved to the preamble, but they shouldn't be the root of a
6928*61046927SAndroid Build Coastguard Worker * replacement expression. Instructions with cost 0 and derefs are
6929*61046927SAndroid Build Coastguard Worker * automatically included by the pass.
6930*61046927SAndroid Build Coastguard Worker */
6931*61046927SAndroid Build Coastguard Worker nir_instr_filter_cb avoid_instr_cb;
6932*61046927SAndroid Build Coastguard Worker
6933*61046927SAndroid Build Coastguard Worker const void *cb_data;
6934*61046927SAndroid Build Coastguard Worker } nir_opt_preamble_options;
6935*61046927SAndroid Build Coastguard Worker
6936*61046927SAndroid Build Coastguard Worker bool
6937*61046927SAndroid Build Coastguard Worker nir_opt_preamble(nir_shader *shader,
6938*61046927SAndroid Build Coastguard Worker const nir_opt_preamble_options *options,
6939*61046927SAndroid Build Coastguard Worker unsigned *size);
6940*61046927SAndroid Build Coastguard Worker
6941*61046927SAndroid Build Coastguard Worker nir_function_impl *nir_shader_get_preamble(nir_shader *shader);
6942*61046927SAndroid Build Coastguard Worker
6943*61046927SAndroid Build Coastguard Worker bool nir_lower_point_smooth(nir_shader *shader);
6944*61046927SAndroid Build Coastguard Worker bool nir_lower_poly_line_smooth(nir_shader *shader, unsigned num_smooth_aa_sample);
6945*61046927SAndroid Build Coastguard Worker
6946*61046927SAndroid Build Coastguard Worker bool nir_mod_analysis(nir_scalar val, nir_alu_type val_type, unsigned div, unsigned *mod);
6947*61046927SAndroid Build Coastguard Worker
6948*61046927SAndroid Build Coastguard Worker bool
6949*61046927SAndroid Build Coastguard Worker nir_remove_tex_shadow(nir_shader *shader, unsigned textures_bitmask);
6950*61046927SAndroid Build Coastguard Worker
6951*61046927SAndroid Build Coastguard Worker void
6952*61046927SAndroid Build Coastguard Worker nir_trivialize_registers(nir_shader *s);
6953*61046927SAndroid Build Coastguard Worker
6954*61046927SAndroid Build Coastguard Worker unsigned
6955*61046927SAndroid Build Coastguard Worker nir_static_workgroup_size(const nir_shader *s);
6956*61046927SAndroid Build Coastguard Worker
6957*61046927SAndroid Build Coastguard Worker static inline nir_intrinsic_instr *
nir_reg_get_decl(nir_def * reg)6958*61046927SAndroid Build Coastguard Worker nir_reg_get_decl(nir_def *reg)
6959*61046927SAndroid Build Coastguard Worker {
6960*61046927SAndroid Build Coastguard Worker assert(reg->parent_instr->type == nir_instr_type_intrinsic);
6961*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *decl = nir_instr_as_intrinsic(reg->parent_instr);
6962*61046927SAndroid Build Coastguard Worker assert(decl->intrinsic == nir_intrinsic_decl_reg);
6963*61046927SAndroid Build Coastguard Worker
6964*61046927SAndroid Build Coastguard Worker return decl;
6965*61046927SAndroid Build Coastguard Worker }
6966*61046927SAndroid Build Coastguard Worker
6967*61046927SAndroid Build Coastguard Worker static inline nir_intrinsic_instr *
nir_next_decl_reg(nir_intrinsic_instr * prev,nir_function_impl * impl)6968*61046927SAndroid Build Coastguard Worker nir_next_decl_reg(nir_intrinsic_instr *prev, nir_function_impl *impl)
6969*61046927SAndroid Build Coastguard Worker {
6970*61046927SAndroid Build Coastguard Worker nir_instr *start;
6971*61046927SAndroid Build Coastguard Worker if (prev != NULL)
6972*61046927SAndroid Build Coastguard Worker start = nir_instr_next(&prev->instr);
6973*61046927SAndroid Build Coastguard Worker else if (impl != NULL)
6974*61046927SAndroid Build Coastguard Worker start = nir_block_first_instr(nir_start_block(impl));
6975*61046927SAndroid Build Coastguard Worker else
6976*61046927SAndroid Build Coastguard Worker return NULL;
6977*61046927SAndroid Build Coastguard Worker
6978*61046927SAndroid Build Coastguard Worker for (nir_instr *instr = start; instr; instr = nir_instr_next(instr)) {
6979*61046927SAndroid Build Coastguard Worker if (instr->type != nir_instr_type_intrinsic)
6980*61046927SAndroid Build Coastguard Worker continue;
6981*61046927SAndroid Build Coastguard Worker
6982*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
6983*61046927SAndroid Build Coastguard Worker if (intrin->intrinsic == nir_intrinsic_decl_reg)
6984*61046927SAndroid Build Coastguard Worker return intrin;
6985*61046927SAndroid Build Coastguard Worker }
6986*61046927SAndroid Build Coastguard Worker
6987*61046927SAndroid Build Coastguard Worker return NULL;
6988*61046927SAndroid Build Coastguard Worker }
6989*61046927SAndroid Build Coastguard Worker
6990*61046927SAndroid Build Coastguard Worker #define nir_foreach_reg_decl(reg, impl) \
6991*61046927SAndroid Build Coastguard Worker for (nir_intrinsic_instr *reg = nir_next_decl_reg(NULL, impl); \
6992*61046927SAndroid Build Coastguard Worker reg; reg = nir_next_decl_reg(reg, NULL))
6993*61046927SAndroid Build Coastguard Worker
6994*61046927SAndroid Build Coastguard Worker #define nir_foreach_reg_decl_safe(reg, impl) \
6995*61046927SAndroid Build Coastguard Worker for (nir_intrinsic_instr *reg = nir_next_decl_reg(NULL, impl), \
6996*61046927SAndroid Build Coastguard Worker *next_ = nir_next_decl_reg(reg, NULL); \
6997*61046927SAndroid Build Coastguard Worker reg; reg = next_, next_ = nir_next_decl_reg(next_, NULL))
6998*61046927SAndroid Build Coastguard Worker
6999*61046927SAndroid Build Coastguard Worker static inline nir_cursor
nir_after_reg_decls(nir_function_impl * impl)7000*61046927SAndroid Build Coastguard Worker nir_after_reg_decls(nir_function_impl *impl)
7001*61046927SAndroid Build Coastguard Worker {
7002*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *last_reg_decl = NULL;
7003*61046927SAndroid Build Coastguard Worker nir_foreach_reg_decl(reg_decl, impl)
7004*61046927SAndroid Build Coastguard Worker last_reg_decl = reg_decl;
7005*61046927SAndroid Build Coastguard Worker
7006*61046927SAndroid Build Coastguard Worker if (last_reg_decl != NULL)
7007*61046927SAndroid Build Coastguard Worker return nir_after_instr(&last_reg_decl->instr);
7008*61046927SAndroid Build Coastguard Worker return nir_before_impl(impl);
7009*61046927SAndroid Build Coastguard Worker }
7010*61046927SAndroid Build Coastguard Worker
7011*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_load_reg(nir_intrinsic_instr * intr)7012*61046927SAndroid Build Coastguard Worker nir_is_load_reg(nir_intrinsic_instr *intr)
7013*61046927SAndroid Build Coastguard Worker {
7014*61046927SAndroid Build Coastguard Worker return intr->intrinsic == nir_intrinsic_load_reg ||
7015*61046927SAndroid Build Coastguard Worker intr->intrinsic == nir_intrinsic_load_reg_indirect;
7016*61046927SAndroid Build Coastguard Worker }
7017*61046927SAndroid Build Coastguard Worker
7018*61046927SAndroid Build Coastguard Worker static inline bool
nir_is_store_reg(nir_intrinsic_instr * intr)7019*61046927SAndroid Build Coastguard Worker nir_is_store_reg(nir_intrinsic_instr *intr)
7020*61046927SAndroid Build Coastguard Worker {
7021*61046927SAndroid Build Coastguard Worker return intr->intrinsic == nir_intrinsic_store_reg ||
7022*61046927SAndroid Build Coastguard Worker intr->intrinsic == nir_intrinsic_store_reg_indirect;
7023*61046927SAndroid Build Coastguard Worker }
7024*61046927SAndroid Build Coastguard Worker
7025*61046927SAndroid Build Coastguard Worker #define nir_foreach_reg_load(load, reg) \
7026*61046927SAndroid Build Coastguard Worker assert(reg->intrinsic == nir_intrinsic_decl_reg); \
7027*61046927SAndroid Build Coastguard Worker \
7028*61046927SAndroid Build Coastguard Worker nir_foreach_use(load, ®->def) \
7029*61046927SAndroid Build Coastguard Worker if (nir_is_load_reg(nir_instr_as_intrinsic(nir_src_parent_instr(load))))
7030*61046927SAndroid Build Coastguard Worker
7031*61046927SAndroid Build Coastguard Worker #define nir_foreach_reg_load_safe(load, reg) \
7032*61046927SAndroid Build Coastguard Worker assert(reg->intrinsic == nir_intrinsic_decl_reg); \
7033*61046927SAndroid Build Coastguard Worker \
7034*61046927SAndroid Build Coastguard Worker nir_foreach_use_safe(load, ®->def) \
7035*61046927SAndroid Build Coastguard Worker if (nir_is_load_reg(nir_instr_as_intrinsic(nir_src_parent_instr(load))))
7036*61046927SAndroid Build Coastguard Worker
7037*61046927SAndroid Build Coastguard Worker #define nir_foreach_reg_store(store, reg) \
7038*61046927SAndroid Build Coastguard Worker assert(reg->intrinsic == nir_intrinsic_decl_reg); \
7039*61046927SAndroid Build Coastguard Worker \
7040*61046927SAndroid Build Coastguard Worker nir_foreach_use(store, ®->def) \
7041*61046927SAndroid Build Coastguard Worker if (nir_is_store_reg(nir_instr_as_intrinsic(nir_src_parent_instr(store))))
7042*61046927SAndroid Build Coastguard Worker
7043*61046927SAndroid Build Coastguard Worker #define nir_foreach_reg_store_safe(store, reg) \
7044*61046927SAndroid Build Coastguard Worker assert(reg->intrinsic == nir_intrinsic_decl_reg); \
7045*61046927SAndroid Build Coastguard Worker \
7046*61046927SAndroid Build Coastguard Worker nir_foreach_use_safe(store, ®->def) \
7047*61046927SAndroid Build Coastguard Worker if (nir_is_store_reg(nir_instr_as_intrinsic(nir_src_parent_instr(store))))
7048*61046927SAndroid Build Coastguard Worker
7049*61046927SAndroid Build Coastguard Worker static inline nir_intrinsic_instr *
nir_load_reg_for_def(const nir_def * def)7050*61046927SAndroid Build Coastguard Worker nir_load_reg_for_def(const nir_def *def)
7051*61046927SAndroid Build Coastguard Worker {
7052*61046927SAndroid Build Coastguard Worker if (def->parent_instr->type != nir_instr_type_intrinsic)
7053*61046927SAndroid Build Coastguard Worker return NULL;
7054*61046927SAndroid Build Coastguard Worker
7055*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *intr = nir_instr_as_intrinsic(def->parent_instr);
7056*61046927SAndroid Build Coastguard Worker if (!nir_is_load_reg(intr))
7057*61046927SAndroid Build Coastguard Worker return NULL;
7058*61046927SAndroid Build Coastguard Worker
7059*61046927SAndroid Build Coastguard Worker return intr;
7060*61046927SAndroid Build Coastguard Worker }
7061*61046927SAndroid Build Coastguard Worker
7062*61046927SAndroid Build Coastguard Worker static inline nir_intrinsic_instr *
nir_store_reg_for_def(const nir_def * def)7063*61046927SAndroid Build Coastguard Worker nir_store_reg_for_def(const nir_def *def)
7064*61046927SAndroid Build Coastguard Worker {
7065*61046927SAndroid Build Coastguard Worker /* Look for the trivial store: single use of our destination by a
7066*61046927SAndroid Build Coastguard Worker * store_register intrinsic.
7067*61046927SAndroid Build Coastguard Worker */
7068*61046927SAndroid Build Coastguard Worker if (!list_is_singular(&def->uses))
7069*61046927SAndroid Build Coastguard Worker return NULL;
7070*61046927SAndroid Build Coastguard Worker
7071*61046927SAndroid Build Coastguard Worker nir_src *src = list_first_entry(&def->uses, nir_src, use_link);
7072*61046927SAndroid Build Coastguard Worker if (nir_src_is_if(src))
7073*61046927SAndroid Build Coastguard Worker return NULL;
7074*61046927SAndroid Build Coastguard Worker
7075*61046927SAndroid Build Coastguard Worker nir_instr *parent = nir_src_parent_instr(src);
7076*61046927SAndroid Build Coastguard Worker if (parent->type != nir_instr_type_intrinsic)
7077*61046927SAndroid Build Coastguard Worker return NULL;
7078*61046927SAndroid Build Coastguard Worker
7079*61046927SAndroid Build Coastguard Worker nir_intrinsic_instr *intr = nir_instr_as_intrinsic(parent);
7080*61046927SAndroid Build Coastguard Worker if (!nir_is_store_reg(intr))
7081*61046927SAndroid Build Coastguard Worker return NULL;
7082*61046927SAndroid Build Coastguard Worker
7083*61046927SAndroid Build Coastguard Worker /* The first value is data. Third is indirect index, ignore that one. */
7084*61046927SAndroid Build Coastguard Worker if (&intr->src[0] != src)
7085*61046927SAndroid Build Coastguard Worker return NULL;
7086*61046927SAndroid Build Coastguard Worker
7087*61046927SAndroid Build Coastguard Worker return intr;
7088*61046927SAndroid Build Coastguard Worker }
7089*61046927SAndroid Build Coastguard Worker
7090*61046927SAndroid Build Coastguard Worker struct nir_use_dominance_state;
7091*61046927SAndroid Build Coastguard Worker
7092*61046927SAndroid Build Coastguard Worker struct nir_use_dominance_state *
7093*61046927SAndroid Build Coastguard Worker nir_calc_use_dominance_impl(nir_function_impl *impl, bool post_dominance);
7094*61046927SAndroid Build Coastguard Worker
7095*61046927SAndroid Build Coastguard Worker nir_instr *
7096*61046927SAndroid Build Coastguard Worker nir_get_immediate_use_dominator(struct nir_use_dominance_state *state,
7097*61046927SAndroid Build Coastguard Worker nir_instr *instr);
7098*61046927SAndroid Build Coastguard Worker nir_instr *nir_use_dominance_lca(struct nir_use_dominance_state *state,
7099*61046927SAndroid Build Coastguard Worker nir_instr *i1, nir_instr *i2);
7100*61046927SAndroid Build Coastguard Worker bool nir_instr_dominates_use(struct nir_use_dominance_state *state,
7101*61046927SAndroid Build Coastguard Worker nir_instr *parent, nir_instr *child);
7102*61046927SAndroid Build Coastguard Worker void nir_print_use_dominators(struct nir_use_dominance_state *state,
7103*61046927SAndroid Build Coastguard Worker nir_instr **instructions,
7104*61046927SAndroid Build Coastguard Worker unsigned num_instructions);
7105*61046927SAndroid Build Coastguard Worker
7106*61046927SAndroid Build Coastguard Worker #include "nir_inline_helpers.h"
7107*61046927SAndroid Build Coastguard Worker
7108*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
7109*61046927SAndroid Build Coastguard Worker } /* extern "C" */
7110*61046927SAndroid Build Coastguard Worker #endif
7111*61046927SAndroid Build Coastguard Worker
7112*61046927SAndroid Build Coastguard Worker #endif /* NIR_H */
7113