1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef BRW_NIR_H
25 #define BRW_NIR_H
26
27 #include "brw_reg.h"
28 #include "compiler/nir/nir.h"
29 #include "brw_compiler.h"
30 #include "nir_builder.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 int type_size_vec4(const struct glsl_type *type, bool bindless);
37 int type_size_dvec4(const struct glsl_type *type, bool bindless);
38
39 static inline int
type_size_scalar_bytes(const struct glsl_type * type,bool bindless)40 type_size_scalar_bytes(const struct glsl_type *type, bool bindless)
41 {
42 return glsl_count_dword_slots(type, bindless) * 4;
43 }
44
45 static inline int
type_size_vec4_bytes(const struct glsl_type * type,bool bindless)46 type_size_vec4_bytes(const struct glsl_type *type, bool bindless)
47 {
48 return type_size_vec4(type, bindless) * 16;
49 }
50
51 /* Flags set in the instr->pass_flags field by i965 analysis passes */
52 enum {
53 BRW_NIR_NON_BOOLEAN = 0x0,
54
55 /* Indicates that the given instruction's destination is a boolean
56 * value but that it needs to be resolved before it can be used.
57 * On Gen <= 5, CMP instructions return a 32-bit value where the bottom
58 * bit represents the actual true/false value of the compare and the top
59 * 31 bits are undefined. In order to use this value, we have to do a
60 * "resolve" operation by replacing the value of the CMP with -(x & 1)
61 * to sign-extend the bottom bit to 0/~0.
62 */
63 BRW_NIR_BOOLEAN_NEEDS_RESOLVE = 0x1,
64
65 /* Indicates that the given instruction's destination is a boolean
66 * value that has intentionally been left unresolved. Not all boolean
67 * values need to be resolved immediately. For instance, if we have
68 *
69 * CMP r1 r2 r3
70 * CMP r4 r5 r6
71 * AND r7 r1 r4
72 *
73 * We don't have to resolve the result of the two CMP instructions
74 * immediately because the AND still does an AND of the bottom bits.
75 * Instead, we can save ourselves instructions by delaying the resolve
76 * until after the AND. The result of the two CMP instructions is left
77 * as BRW_NIR_BOOLEAN_UNRESOLVED.
78 */
79 BRW_NIR_BOOLEAN_UNRESOLVED = 0x2,
80
81 /* Indicates a that the given instruction's destination is a boolean
82 * value that does not need a resolve. For instance, if you AND two
83 * values that are BRW_NIR_BOOLEAN_NEEDS_RESOLVE then we know that both
84 * values will be 0/~0 before we get them and the result of the AND is
85 * also guaranteed to be 0/~0 and does not need a resolve.
86 */
87 BRW_NIR_BOOLEAN_NO_RESOLVE = 0x3,
88
89 /* A mask to mask the boolean status values off of instr->pass_flags */
90 BRW_NIR_BOOLEAN_MASK = 0x3,
91 };
92
93 void brw_nir_analyze_boolean_resolves(nir_shader *nir);
94
95 void brw_preprocess_nir(const struct brw_compiler *compiler,
96 nir_shader *nir,
97 const nir_shader *softfp64);
98
99 void
100 brw_nir_link_shaders(const struct brw_compiler *compiler,
101 nir_shader *producer, nir_shader *consumer);
102
103 bool brw_nir_lower_cs_intrinsics(nir_shader *nir);
104 bool brw_nir_lower_alpha_to_coverage(nir_shader *shader);
105 void brw_nir_lower_vs_inputs(nir_shader *nir,
106 bool edgeflag_is_last,
107 const uint8_t *vs_attrib_wa_flags);
108 void brw_nir_lower_vue_inputs(nir_shader *nir,
109 const struct brw_vue_map *vue_map);
110 void brw_nir_lower_tes_inputs(nir_shader *nir, const struct brw_vue_map *vue);
111 void brw_nir_lower_fs_inputs(nir_shader *nir,
112 const struct intel_device_info *devinfo,
113 const struct brw_wm_prog_key *key);
114 void brw_nir_lower_vue_outputs(nir_shader *nir);
115 void brw_nir_lower_tcs_outputs(nir_shader *nir, const struct brw_vue_map *vue,
116 enum tess_primitive_mode tes_primitive_mode);
117 void brw_nir_lower_fs_outputs(nir_shader *nir);
118
119 bool brw_nir_lower_conversions(nir_shader *nir);
120
121 bool brw_nir_lower_scoped_barriers(nir_shader *nir);
122
123 bool brw_nir_lower_shading_rate_output(nir_shader *nir);
124
125 bool brw_nir_lower_storage_image(nir_shader *nir,
126 const struct intel_device_info *devinfo);
127
128 bool brw_nir_lower_mem_access_bit_sizes(nir_shader *shader,
129 const struct
130 intel_device_info *devinfo);
131
132 void brw_postprocess_nir(nir_shader *nir,
133 const struct brw_compiler *compiler,
134 bool is_scalar,
135 bool debug_enabled,
136 bool robust_buffer_access);
137
138 bool brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader);
139
140 bool brw_nir_apply_attribute_workarounds(nir_shader *nir,
141 const uint8_t *attrib_wa_flags);
142
143 bool brw_nir_apply_trig_workarounds(nir_shader *nir);
144
145 bool brw_nir_limit_trig_input_range_workaround(nir_shader *nir);
146
147 void brw_nir_apply_tcs_quads_workaround(nir_shader *nir);
148
149 void brw_nir_apply_key(nir_shader *nir,
150 const struct brw_compiler *compiler,
151 const struct brw_base_prog_key *key,
152 unsigned max_subgroup_size,
153 bool is_scalar);
154
155 enum brw_conditional_mod brw_cmod_for_nir_comparison(nir_op op);
156 uint32_t brw_aop_for_nir_intrinsic(const nir_intrinsic_instr *atomic);
157 enum brw_reg_type brw_type_for_nir_type(const struct intel_device_info *devinfo,
158 nir_alu_type type);
159
160 void brw_nir_setup_glsl_uniforms(void *mem_ctx, nir_shader *shader,
161 const struct gl_program *prog,
162 struct brw_stage_prog_data *stage_prog_data,
163 bool is_scalar);
164
165 void brw_nir_setup_arb_uniforms(void *mem_ctx, nir_shader *shader,
166 struct gl_program *prog,
167 struct brw_stage_prog_data *stage_prog_data);
168
169 void brw_nir_lower_gl_images(nir_shader *shader,
170 const struct gl_program *prog);
171
172 void brw_nir_analyze_ubo_ranges(const struct brw_compiler *compiler,
173 nir_shader *nir,
174 const struct brw_vs_prog_key *vs_key,
175 struct brw_ubo_range out_ranges[4]);
176
177 bool brw_nir_opt_peephole_ffma(nir_shader *shader);
178
179 void brw_nir_optimize(nir_shader *nir,
180 const struct brw_compiler *compiler,
181 bool is_scalar,
182 bool allow_copies);
183
184 nir_shader *brw_nir_create_passthrough_tcs(void *mem_ctx,
185 const struct brw_compiler *compiler,
186 const nir_shader_compiler_options *options,
187 const struct brw_tcs_prog_key *key);
188
189 #define BRW_NIR_FRAG_OUTPUT_INDEX_SHIFT 0
190 #define BRW_NIR_FRAG_OUTPUT_INDEX_MASK INTEL_MASK(0, 0)
191 #define BRW_NIR_FRAG_OUTPUT_LOCATION_SHIFT 1
192 #define BRW_NIR_FRAG_OUTPUT_LOCATION_MASK INTEL_MASK(31, 1)
193
194 bool brw_nir_move_interpolation_to_top(nir_shader *nir);
195 bool brw_nir_demote_sample_qualifiers(nir_shader *nir);
196 nir_ssa_def *brw_nir_load_global_const(nir_builder *b,
197 nir_intrinsic_instr *load_uniform,
198 nir_ssa_def *base_addr,
199 unsigned off);
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif /* BRW_NIR_H */
206