blob: 49d3cf36564755827df6d3404bc5f36e8ebe1b5a [file] [log] [blame]
Kenneth Graunke89c1feb2015-04-07 15:15:09 -07001/*
2 * Copyright © 2014 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#include "brw_nir.h"
Kenneth Graunke6c33d6bb2015-08-12 14:29:25 -070025#include "brw_shader.h"
Jason Ekstrandd5b355c2017-03-01 11:20:25 -080026#include "common/gen_debug.h"
Juan A. Suarez Romerod6281a92016-04-15 12:51:05 +020027#include "compiler/glsl_types.h"
Emil Velikova39a8fb2016-01-18 12:54:03 +020028#include "compiler/nir/nir_builder.h"
Kenneth Graunke89c1feb2015-04-07 15:15:09 -070029
Kenneth Graunke8c4deb12015-12-09 02:37:52 -080030static bool
31is_input(nir_intrinsic_instr *intrin)
32{
33 return intrin->intrinsic == nir_intrinsic_load_input ||
Kenneth Graunke1eef0b72016-07-12 03:57:25 -070034 intrin->intrinsic == nir_intrinsic_load_per_vertex_input ||
35 intrin->intrinsic == nir_intrinsic_load_interpolated_input;
Kenneth Graunke8c4deb12015-12-09 02:37:52 -080036}
37
38static bool
39is_output(nir_intrinsic_instr *intrin)
40{
41 return intrin->intrinsic == nir_intrinsic_load_output ||
42 intrin->intrinsic == nir_intrinsic_load_per_vertex_output ||
43 intrin->intrinsic == nir_intrinsic_store_output ||
44 intrin->intrinsic == nir_intrinsic_store_per_vertex_output;
45}
46
47/**
48 * In many cases, we just add the base and offset together, so there's no
49 * reason to keep them separate. Sometimes, combining them is essential:
50 * if a shader only accesses part of a compound variable (such as a matrix
51 * or array), the variable's base may not actually exist in the VUE map.
52 *
53 * This pass adds constant offsets to instr->const_index[0], and resets
54 * the offset source to 0. Non-constant offsets remain unchanged - since
55 * we don't know what part of a compound variable is accessed, we allocate
56 * storage for the entire thing.
57 */
Kenneth Graunkebd198b92015-08-14 16:01:33 -070058
Jason Ekstrand78b81be2015-11-25 14:14:05 -080059static bool
Connor Abbott7efff102016-04-12 22:56:14 -040060add_const_offset_to_base_block(nir_block *block, nir_builder *b,
61 nir_variable_mode mode)
Jason Ekstrand78b81be2015-11-25 14:14:05 -080062{
Jason Ekstrand707e72f2016-04-26 18:34:19 -070063 nir_foreach_instr_safe(instr, block) {
Kenneth Graunkebd198b92015-08-14 16:01:33 -070064 if (instr->type != nir_instr_type_intrinsic)
65 continue;
66
67 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
68
Connor Abbott7efff102016-04-12 22:56:14 -040069 if ((mode == nir_var_shader_in && is_input(intrin)) ||
70 (mode == nir_var_shader_out && is_output(intrin))) {
Kenneth Graunke8c4deb12015-12-09 02:37:52 -080071 nir_src *offset = nir_get_io_offset_src(intrin);
72 nir_const_value *const_offset = nir_src_as_const_value(*offset);
73
74 if (const_offset) {
Iago Toral Quiroga084b24f2016-03-16 12:11:34 +010075 intrin->const_index[0] += const_offset->u32[0];
Kenneth Graunke8c4deb12015-12-09 02:37:52 -080076 b->cursor = nir_before_instr(&intrin->instr);
77 nir_instr_rewrite_src(&intrin->instr, offset,
78 nir_src_for_ssa(nir_imm_int(b, 0)));
79 }
80 }
81 }
82 return true;
Kenneth Graunkea3500f92016-01-13 15:04:39 -080083}
Kenneth Graunke8c4deb12015-12-09 02:37:52 -080084
Kenneth Graunkea3500f92016-01-13 15:04:39 -080085static void
86add_const_offset_to_base(nir_shader *nir, nir_variable_mode mode)
87{
Jason Ekstrand9464d8c2016-04-26 20:26:42 -070088 nir_foreach_function(f, nir) {
Kenneth Graunkea3500f92016-01-13 15:04:39 -080089 if (f->impl) {
Connor Abbott7efff102016-04-12 22:56:14 -040090 nir_builder b;
91 nir_builder_init(&b, f->impl);
92 nir_foreach_block(block, f->impl) {
93 add_const_offset_to_base_block(block, &b, mode);
94 }
Kenneth Graunkea3500f92016-01-13 15:04:39 -080095 }
96 }
Kenneth Graunke8c4deb12015-12-09 02:37:52 -080097}
98
99static bool
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800100remap_tess_levels(nir_builder *b, nir_intrinsic_instr *intr,
101 GLenum primitive_mode)
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800102{
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800103 const int location = nir_intrinsic_base(intr);
104 const unsigned component = nir_intrinsic_component(intr);
105 bool out_of_bounds;
106
107 if (location == VARYING_SLOT_TESS_LEVEL_INNER) {
108 switch (primitive_mode) {
109 case GL_QUADS:
110 /* gl_TessLevelInner[0..1] lives at DWords 3-2 (reversed). */
111 nir_intrinsic_set_base(intr, 0);
112 nir_intrinsic_set_component(intr, 3 - component);
113 out_of_bounds = false;
114 break;
115 case GL_TRIANGLES:
116 /* gl_TessLevelInner[0] lives at DWord 4. */
117 nir_intrinsic_set_base(intr, 1);
118 out_of_bounds = component > 0;
119 break;
120 case GL_ISOLINES:
121 out_of_bounds = true;
122 break;
123 default:
124 unreachable("Bogus tessellation domain");
125 }
126 } else if (location == VARYING_SLOT_TESS_LEVEL_OUTER) {
127 if (primitive_mode == GL_ISOLINES) {
128 /* gl_TessLevelOuter[0..1] lives at DWords 6-7 (in order). */
129 nir_intrinsic_set_base(intr, 1);
130 nir_intrinsic_set_component(intr, 2 + nir_intrinsic_component(intr));
131 out_of_bounds = component > 1;
132 } else {
133 /* Triangles use DWords 7-5 (reversed); Quads use 7-4 (reversed) */
134 nir_intrinsic_set_base(intr, 1);
135 nir_intrinsic_set_component(intr, 3 - nir_intrinsic_component(intr));
136 out_of_bounds = component == 3 && primitive_mode == GL_TRIANGLES;
137 }
138 } else {
139 return false;
140 }
141
142 if (out_of_bounds) {
143 if (nir_intrinsic_infos[intr->intrinsic].has_dest) {
144 b->cursor = nir_before_instr(&intr->instr);
145 nir_ssa_def *undef = nir_ssa_undef(b, 1, 32);
146 nir_ssa_def_rewrite_uses(&intr->dest.ssa, nir_src_for_ssa(undef));
147 }
148 nir_instr_remove(&intr->instr);
149 }
150
151 return true;
152}
153
154static bool
155remap_patch_urb_offsets(nir_block *block, nir_builder *b,
156 const struct brw_vue_map *vue_map,
157 GLenum tes_primitive_mode)
158{
Jason Ekstrandb86dba82017-05-08 09:20:21 -0700159 const bool is_passthrough_tcs = b->shader->info.name &&
160 strcmp(b->shader->info.name, "passthrough") == 0;
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800161
Jason Ekstrand707e72f2016-04-26 18:34:19 -0700162 nir_foreach_instr_safe(instr, block) {
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800163 if (instr->type != nir_instr_type_intrinsic)
164 continue;
165
166 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
167
Connor Abbott7efff102016-04-12 22:56:14 -0400168 gl_shader_stage stage = b->shader->stage;
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800169
170 if ((stage == MESA_SHADER_TESS_CTRL && is_output(intrin)) ||
171 (stage == MESA_SHADER_TESS_EVAL && is_input(intrin))) {
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800172
173 if (!is_passthrough_tcs &&
174 remap_tess_levels(b, intrin, tes_primitive_mode))
175 continue;
176
Connor Abbott7efff102016-04-12 22:56:14 -0400177 int vue_slot = vue_map->varying_to_slot[intrin->const_index[0]];
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800178 assert(vue_slot != -1);
179 intrin->const_index[0] = vue_slot;
180
181 nir_src *vertex = nir_get_io_vertex_index_src(intrin);
182 if (vertex) {
183 nir_const_value *const_vertex = nir_src_as_const_value(*vertex);
184 if (const_vertex) {
Iago Toral Quiroga084b24f2016-03-16 12:11:34 +0100185 intrin->const_index[0] += const_vertex->u32[0] *
Connor Abbott7efff102016-04-12 22:56:14 -0400186 vue_map->num_per_vertex_slots;
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800187 } else {
Connor Abbott7efff102016-04-12 22:56:14 -0400188 b->cursor = nir_before_instr(&intrin->instr);
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800189
190 /* Multiply by the number of per-vertex slots. */
191 nir_ssa_def *vertex_offset =
Connor Abbott7efff102016-04-12 22:56:14 -0400192 nir_imul(b,
193 nir_ssa_for_src(b, *vertex, 1),
194 nir_imm_int(b,
195 vue_map->num_per_vertex_slots));
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800196
197 /* Add it to the existing offset */
198 nir_src *offset = nir_get_io_offset_src(intrin);
199 nir_ssa_def *total_offset =
Connor Abbott7efff102016-04-12 22:56:14 -0400200 nir_iadd(b, vertex_offset,
201 nir_ssa_for_src(b, *offset, 1));
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800202
203 nir_instr_rewrite_src(&intrin->instr, offset,
204 nir_src_for_ssa(total_offset));
205 }
206 }
207 }
208 }
209 return true;
210}
211
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800212void
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800213brw_nir_lower_vs_inputs(nir_shader *nir,
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800214 bool use_legacy_snorm_formula,
215 const uint8_t *vs_attrib_wa_flags)
Kenneth Graunke193d2952015-08-26 03:07:29 -0700216{
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800217 /* Start with the location of the variable's base. */
218 foreach_list_typed(nir_variable, var, node, &nir->inputs) {
219 var->data.driver_location = var->data.location;
Kenneth Graunkec9541a72015-09-23 20:52:19 -0700220 }
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800221
Juan A. Suarez Romerob0fb08e2016-04-01 17:25:03 +0200222 /* Now use nir_lower_io to walk dereference chains. Attribute arrays are
223 * loaded as one vec4 or dvec4 per element (or matrix column), depending on
224 * whether it is a double-precision type or not.
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800225 */
Juan A. Suarez Romeroc2acf972016-12-16 10:24:43 +0100226 nir_lower_io(nir, nir_var_shader_in, type_size_vec4, 0);
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800227
228 /* This pass needs actual constants */
229 nir_opt_constant_folding(nir);
230
231 add_const_offset_to_base(nir, nir_var_shader_in);
232
233 brw_nir_apply_attribute_workarounds(nir, use_legacy_snorm_formula,
234 vs_attrib_wa_flags);
235
Jason Ekstrand0d5f89c2017-05-03 17:40:54 -0700236 /* The last step is to remap VERT_ATTRIB_* to actual registers */
Juan A. Suarez Romero56ee2df2017-01-13 17:47:57 +0100237
Jason Ekstrandca4d1922017-05-03 16:53:40 -0700238 /* Whether or not we have any system generated values. gl_DrawID is not
239 * included here as it lives in its own vec4.
240 */
241 const bool has_sgvs =
242 nir->info.system_values_read &
243 (BITFIELD64_BIT(SYSTEM_VALUE_BASE_VERTEX) |
244 BITFIELD64_BIT(SYSTEM_VALUE_BASE_INSTANCE) |
245 BITFIELD64_BIT(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) |
246 BITFIELD64_BIT(SYSTEM_VALUE_INSTANCE_ID));
247
248 const unsigned num_inputs = _mesa_bitcount_64(nir->info.inputs_read);
249
Jason Ekstrand36764b62017-05-03 16:41:43 -0700250 nir_foreach_function(function, nir) {
251 if (!function->impl)
252 continue;
253
Jason Ekstrandca4d1922017-05-03 16:53:40 -0700254 nir_builder b;
255 nir_builder_init(&b, function->impl);
256
Jason Ekstrand36764b62017-05-03 16:41:43 -0700257 nir_foreach_block(block, function->impl) {
Jason Ekstrandca4d1922017-05-03 16:53:40 -0700258 nir_foreach_instr_safe(instr, block) {
Jason Ekstrand36764b62017-05-03 16:41:43 -0700259 if (instr->type != nir_instr_type_intrinsic)
260 continue;
261
262 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
263
Jason Ekstrandca4d1922017-05-03 16:53:40 -0700264 switch (intrin->intrinsic) {
265 case nir_intrinsic_load_base_vertex:
266 case nir_intrinsic_load_base_instance:
267 case nir_intrinsic_load_vertex_id_zero_base:
268 case nir_intrinsic_load_instance_id:
269 case nir_intrinsic_load_draw_id: {
270 b.cursor = nir_after_instr(&intrin->instr);
271
272 /* gl_VertexID and friends are stored by the VF as the last
273 * vertex element. We convert them to load_input intrinsics at
274 * the right location.
275 */
276 nir_intrinsic_instr *load =
277 nir_intrinsic_instr_create(nir, nir_intrinsic_load_input);
278 load->src[0] = nir_src_for_ssa(nir_imm_int(&b, 0));
279
280 nir_intrinsic_set_base(load, num_inputs);
281 switch (intrin->intrinsic) {
282 case nir_intrinsic_load_base_vertex:
283 nir_intrinsic_set_component(load, 0);
284 break;
285 case nir_intrinsic_load_base_instance:
286 nir_intrinsic_set_component(load, 1);
287 break;
288 case nir_intrinsic_load_vertex_id_zero_base:
289 nir_intrinsic_set_component(load, 2);
290 break;
291 case nir_intrinsic_load_instance_id:
292 nir_intrinsic_set_component(load, 3);
293 break;
294 case nir_intrinsic_load_draw_id:
295 /* gl_DrawID is stored right after gl_VertexID and friends
296 * if any of them exist.
297 */
298 nir_intrinsic_set_base(load, num_inputs + has_sgvs);
299 nir_intrinsic_set_component(load, 0);
300 break;
301 default:
302 unreachable("Invalid system value intrinsic");
303 }
304
305 load->num_components = 1;
306 nir_ssa_dest_init(&load->instr, &load->dest, 1, 32, NULL);
307 nir_builder_instr_insert(&b, &load->instr);
308
309 nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
310 nir_src_for_ssa(&load->dest.ssa));
311 nir_instr_remove(&intrin->instr);
312 break;
313 }
314
315 case nir_intrinsic_load_input: {
Jason Ekstrand36764b62017-05-03 16:41:43 -0700316 /* Attributes come in a contiguous block, ordered by their
317 * gl_vert_attrib value. That means we can compute the slot
318 * number for an attribute by masking out the enabled attributes
319 * before it and counting the bits.
320 */
321 int attr = nir_intrinsic_base(intrin);
322 int slot = _mesa_bitcount_64(nir->info.inputs_read &
323 BITFIELD64_MASK(attr));
Jason Ekstrand5e832302017-05-03 16:56:15 -0700324 nir_intrinsic_set_base(intrin, slot);
Jason Ekstrandca4d1922017-05-03 16:53:40 -0700325 break;
326 }
327
328 default:
329 break; /* Nothing to do */
Juan A. Suarez Romero56ee2df2017-01-13 17:47:57 +0100330 }
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800331 }
332 }
333 }
334}
335
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800336void
Jason Ekstrand2e9916e2017-05-04 16:36:26 -0700337brw_nir_lower_vue_inputs(nir_shader *nir,
Kenneth Graunke81510032016-02-24 23:43:17 -0800338 const struct brw_vue_map *vue_map)
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800339{
Kenneth Graunkea0294c22016-02-24 23:44:46 -0800340 foreach_list_typed(nir_variable, var, node, &nir->inputs) {
341 var->data.driver_location = var->data.location;
342 }
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800343
Kenneth Graunkea0294c22016-02-24 23:44:46 -0800344 /* Inputs are stored in vec4 slots, so use type_size_vec4(). */
Jason Ekstranded65e6e2016-09-14 10:29:38 -0700345 nir_lower_io(nir, nir_var_shader_in, type_size_vec4, 0);
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800346
Jason Ekstrand5b00c3c2017-05-04 14:57:52 -0700347 /* This pass needs actual constants */
348 nir_opt_constant_folding(nir);
Kenneth Graunkea3500f92016-01-13 15:04:39 -0800349
Jason Ekstrand5b00c3c2017-05-04 14:57:52 -0700350 add_const_offset_to_base(nir, nir_var_shader_in);
351
352 nir_foreach_function(function, nir) {
353 if (!function->impl)
354 continue;
355
356 nir_foreach_block(block, function->impl) {
357 nir_foreach_instr(instr, block) {
358 if (instr->type != nir_instr_type_intrinsic)
359 continue;
360
361 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
362
363 if (intrin->intrinsic == nir_intrinsic_load_input ||
364 intrin->intrinsic == nir_intrinsic_load_per_vertex_input) {
Jason Ekstrande31042a2017-05-04 16:33:32 -0700365 /* Offset 0 is the VUE header, which contains
366 * VARYING_SLOT_LAYER [.y], VARYING_SLOT_VIEWPORT [.z], and
367 * VARYING_SLOT_PSIZ [.w].
368 */
369 int varying = nir_intrinsic_base(intrin);
370 int vue_slot;
371 switch (varying) {
372 case VARYING_SLOT_PSIZ:
373 nir_intrinsic_set_base(intrin, 0);
374 nir_intrinsic_set_component(intrin, 3);
375 break;
376
377 default:
378 vue_slot = vue_map->varying_to_slot[varying];
379 assert(vue_slot != -1);
380 nir_intrinsic_set_base(intrin, vue_slot);
381 break;
382 }
Connor Abbott7efff102016-04-12 22:56:14 -0400383 }
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800384 }
385 }
Kenneth Graunkebee42cc2015-12-09 21:41:35 -0800386 }
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800387}
388
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800389void
Kenneth Graunke15b36392016-02-24 22:34:51 -0800390brw_nir_lower_tes_inputs(nir_shader *nir, const struct brw_vue_map *vue_map)
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800391{
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800392 foreach_list_typed(nir_variable, var, node, &nir->inputs) {
393 var->data.driver_location = var->data.location;
394 }
395
Jason Ekstranded65e6e2016-09-14 10:29:38 -0700396 nir_lower_io(nir, nir_var_shader_in, type_size_vec4, 0);
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800397
398 /* This pass needs actual constants */
399 nir_opt_constant_folding(nir);
400
401 add_const_offset_to_base(nir, nir_var_shader_in);
402
Jason Ekstrand9464d8c2016-04-26 20:26:42 -0700403 nir_foreach_function(function, nir) {
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800404 if (function->impl) {
Connor Abbott7efff102016-04-12 22:56:14 -0400405 nir_builder b;
406 nir_builder_init(&b, function->impl);
407 nir_foreach_block(block, function->impl) {
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800408 remap_patch_urb_offsets(block, &b, vue_map,
Jason Ekstrandb86dba82017-05-08 09:20:21 -0700409 nir->info.tess.primitive_mode);
Connor Abbott7efff102016-04-12 22:56:14 -0400410 }
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800411 }
412 }
413}
414
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800415void
Kenneth Graunke0d5071d2017-01-13 14:29:52 -0800416brw_nir_lower_fs_inputs(nir_shader *nir,
Jason Ekstrand111f6b22016-09-14 10:42:42 -0700417 const struct gen_device_info *devinfo,
Jason Ekstrand246db002016-09-14 10:39:52 -0700418 const struct brw_wm_prog_key *key)
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800419{
Kenneth Graunke1eef0b72016-07-12 03:57:25 -0700420 foreach_list_typed(nir_variable, var, node, &nir->inputs) {
421 var->data.driver_location = var->data.location;
Jason Ekstrand111f6b22016-09-14 10:42:42 -0700422
423 /* Apply default interpolation mode.
424 *
425 * Everything defaults to smooth except for the legacy GL color
426 * built-in variables, which might be flat depending on API state.
427 */
428 if (var->data.interpolation == INTERP_MODE_NONE) {
429 const bool flat = key->flat_shade &&
430 (var->data.location == VARYING_SLOT_COL0 ||
431 var->data.location == VARYING_SLOT_COL1);
432
433 var->data.interpolation = flat ? INTERP_MODE_FLAT
434 : INTERP_MODE_SMOOTH;
435 }
436
437 /* On Ironlake and below, there is only one interpolation mode.
438 * Centroid interpolation doesn't mean anything on this hardware --
439 * there is no multisampling.
440 */
441 if (devinfo->gen < 6) {
442 var->data.centroid = false;
443 var->data.sample = false;
444 }
Kenneth Graunke1eef0b72016-07-12 03:57:25 -0700445 }
446
Jason Ekstrand246db002016-09-14 10:39:52 -0700447 nir_lower_io_options lower_io_options = 0;
448 if (key->persample_interp)
449 lower_io_options |= nir_lower_io_force_sample_interpolation;
450
451 nir_lower_io(nir, nir_var_shader_in, type_size_vec4, lower_io_options);
Kenneth Graunke1eef0b72016-07-12 03:57:25 -0700452
453 /* This pass needs actual constants */
454 nir_opt_constant_folding(nir);
455
456 add_const_offset_to_base(nir, nir_var_shader_in);
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800457}
458
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800459void
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800460brw_nir_lower_vue_outputs(nir_shader *nir,
461 bool is_scalar)
462{
Kenneth Graunke59864e82016-10-12 22:41:09 -0700463 nir_foreach_variable(var, &nir->outputs) {
464 var->data.driver_location = var->data.location;
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800465 }
Kenneth Graunke59864e82016-10-12 22:41:09 -0700466
467 nir_lower_io(nir, nir_var_shader_out, type_size_vec4, 0);
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800468}
469
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800470void
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800471brw_nir_lower_tcs_outputs(nir_shader *nir, const struct brw_vue_map *vue_map,
472 GLenum tes_primitive_mode)
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800473{
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800474 nir_foreach_variable(var, &nir->outputs) {
475 var->data.driver_location = var->data.location;
476 }
477
Jason Ekstranded65e6e2016-09-14 10:29:38 -0700478 nir_lower_io(nir, nir_var_shader_out, type_size_vec4, 0);
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800479
480 /* This pass needs actual constants */
481 nir_opt_constant_folding(nir);
482
483 add_const_offset_to_base(nir, nir_var_shader_out);
484
Jason Ekstrand9464d8c2016-04-26 20:26:42 -0700485 nir_foreach_function(function, nir) {
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800486 if (function->impl) {
Connor Abbott7efff102016-04-12 22:56:14 -0400487 nir_builder b;
488 nir_builder_init(&b, function->impl);
489 nir_foreach_block(block, function->impl) {
Kenneth Graunkee6ae1992016-11-24 01:50:10 -0800490 remap_patch_urb_offsets(block, &b, vue_map, tes_primitive_mode);
Connor Abbott7efff102016-04-12 22:56:14 -0400491 }
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800492 }
493 }
494}
495
Kenneth Graunkecfbd9832016-02-24 22:11:35 -0800496void
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800497brw_nir_lower_fs_outputs(nir_shader *nir)
498{
Francisco Jerez7dac8822016-07-21 21:26:20 -0700499 nir_foreach_variable(var, &nir->outputs) {
500 var->data.driver_location =
501 SET_FIELD(var->data.index, BRW_NIR_FRAG_OUTPUT_INDEX) |
502 SET_FIELD(var->data.location, BRW_NIR_FRAG_OUTPUT_LOCATION);
503 }
504
Jason Ekstranded65e6e2016-09-14 10:29:38 -0700505 nir_lower_io(nir, nir_var_shader_out, type_size_dvec4, 0);
Kenneth Graunkeb96ddd22016-02-24 22:02:28 -0800506}
507
Jordan Justen7d021cb2016-01-18 09:45:46 -0800508void
509brw_nir_lower_cs_shared(nir_shader *nir)
510{
Timothy Arceri2e423ca2016-10-25 10:23:25 +1100511 nir_assign_var_locations(&nir->shared, &nir->num_shared,
Jordan Justen7d021cb2016-01-18 09:45:46 -0800512 type_size_scalar_bytes);
Jason Ekstranded65e6e2016-09-14 10:29:38 -0700513 nir_lower_io(nir, nir_var_shared, type_size_scalar_bytes, 0);
Jordan Justen7d021cb2016-01-18 09:45:46 -0800514}
515
Rob Clark317628d2015-11-18 16:33:41 -0500516#define OPT(pass, ...) ({ \
517 bool this_progress = false; \
518 NIR_PASS(this_progress, nir, pass, ##__VA_ARGS__); \
519 if (this_progress) \
520 progress = true; \
521 this_progress; \
522})
Rob Clarkd278e312015-11-18 16:43:31 -0500523
Jason Ekstrand0bee3ac2015-11-16 11:48:05 -0800524static nir_shader *
Timothy Arceri715f0d02016-12-13 11:36:51 +1100525nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
526 bool is_scalar)
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700527{
Timothy Arceri715f0d02016-12-13 11:36:51 +1100528 nir_variable_mode indirect_mask = 0;
529 if (compiler->glsl_compiler_options[nir->stage].EmitNoIndirectInput)
530 indirect_mask |= nir_var_shader_in;
531 if (compiler->glsl_compiler_options[nir->stage].EmitNoIndirectOutput)
532 indirect_mask |= nir_var_shader_out;
533 if (compiler->glsl_compiler_options[nir->stage].EmitNoIndirectTemp)
534 indirect_mask |= nir_var_local;
535
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700536 bool progress;
537 do {
538 progress = false;
Matt Turner7499bc72017-03-09 11:40:17 -0800539 OPT(nir_lower_vars_to_ssa);
Jason Ekstrand45912fb2016-12-09 22:32:08 -0800540 OPT(nir_opt_copy_prop_vars);
Alejandro Piñeiro9e5d8272015-06-25 09:52:35 +0200541
542 if (is_scalar) {
Kenneth Graunke32630e22016-09-13 15:14:28 -0700543 OPT(nir_lower_alu_to_scalar);
Alejandro Piñeiro9e5d8272015-06-25 09:52:35 +0200544 }
545
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800546 OPT(nir_copy_prop);
Iago Toral Quirogada1b1bf2015-07-15 09:32:17 +0200547
548 if (is_scalar) {
Kenneth Graunke2d8a3fa2016-09-13 15:14:28 -0700549 OPT(nir_lower_phis_to_scalar);
Iago Toral Quirogada1b1bf2015-07-15 09:32:17 +0200550 }
551
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800552 OPT(nir_copy_prop);
553 OPT(nir_opt_dce);
554 OPT(nir_opt_cse);
Eric Anholt36f0f032016-09-06 19:45:51 -0700555 OPT(nir_opt_peephole_select, 0);
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800556 OPT(nir_opt_algebraic);
557 OPT(nir_opt_constant_folding);
558 OPT(nir_opt_dead_cf);
Jason Ekstrand8962cc92016-12-16 23:30:40 -0800559 if (OPT(nir_opt_trivial_continues)) {
560 /* If nir_opt_trivial_continues makes progress, then we need to clean
561 * things up if we want any hope of nir_opt_if or nir_opt_loop_unroll
562 * to make progress.
563 */
564 OPT(nir_copy_prop);
565 OPT(nir_opt_dce);
566 }
567 OPT(nir_opt_if);
Timothy Arceri715f0d02016-12-13 11:36:51 +1100568 if (nir->options->max_unroll_iterations != 0) {
569 OPT(nir_opt_loop_unroll, indirect_mask);
570 }
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800571 OPT(nir_opt_remove_phis);
572 OPT(nir_opt_undef);
Matt Turner7499bc72017-03-09 11:40:17 -0800573 OPT(nir_lower_doubles, nir_lower_drcp |
574 nir_lower_dsqrt |
575 nir_lower_drsq |
576 nir_lower_dtrunc |
577 nir_lower_dfloor |
578 nir_lower_dceil |
579 nir_lower_dfract |
580 nir_lower_dround_even |
581 nir_lower_dmod);
582 OPT(nir_lower_64bit_pack);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700583 } while (progress);
Jason Ekstrand0bee3ac2015-11-16 11:48:05 -0800584
585 return nir;
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700586}
587
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800588/* Does some simple lowering and runs the standard suite of optimizations
589 *
590 * This is intended to be called more-or-less directly after you get the
591 * shader out of GLSL or some other source. While it is geared towards i965,
592 * it is not at all generator-specific except for the is_scalar flag. Even
593 * there, it is safe to call with is_scalar = false for a shader that is
594 * intended for the FS backend as long as nir_optimize is called again with
595 * is_scalar = true to scalarize everything prior to code gen.
596 */
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700597nir_shader *
Kenneth Graunkeb0dffdc2016-04-07 15:09:56 -0700598brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir)
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700599{
Jason Ekstranda8ef92b2016-11-08 13:21:39 -0800600 const struct gen_device_info *devinfo = compiler->devinfo;
Matt Turner7499bc72017-03-09 11:40:17 -0800601 UNUSED bool progress; /* Written by OPT */
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800602
Kenneth Graunkeb0dffdc2016-04-07 15:09:56 -0700603 const bool is_scalar = compiler->scalar_stage[nir->stage];
604
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800605 if (nir->stage == MESA_SHADER_GEOMETRY)
606 OPT(nir_lower_gs_intrinsics);
607
Jason Ekstranda8ef92b2016-11-08 13:21:39 -0800608 /* See also brw_nir_trig_workarounds.py */
609 if (compiler->precise_trig &&
610 !(devinfo->gen >= 10 || devinfo->is_kabylake))
Kenneth Graunkebfd17c72016-04-07 15:04:35 -0700611 OPT(brw_nir_apply_trig_workarounds);
612
Rob Clarkfaf5f172015-09-16 12:56:58 -0400613 static const nir_lower_tex_options tex_options = {
614 .lower_txp = ~0,
Jason Ekstrand9f327212016-07-21 12:55:21 -0700615 .lower_txf_offset = true,
616 .lower_rect_offset = true,
Iago Toral Quirogaf90da642016-11-30 09:44:20 +0100617 .lower_txd_cube_map = true,
Rob Clarkfaf5f172015-09-16 12:56:58 -0400618 };
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700619
Jason Ekstrand1417f6a2015-11-11 10:46:09 -0800620 OPT(nir_lower_tex, &tex_options);
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800621 OPT(nir_normalize_cubemap_coords);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700622
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800623 OPT(nir_lower_global_vars_to_local);
624
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800625 OPT(nir_split_var_copies);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700626
Timothy Arceri715f0d02016-12-13 11:36:51 +1100627 nir = nir_optimize(nir, compiler, is_scalar);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700628
Kenneth Graunke74f956c2016-01-21 16:37:20 -0800629 if (is_scalar) {
Matt Turner7499bc72017-03-09 11:40:17 -0800630 OPT(nir_lower_load_const_to_scalar);
Kenneth Graunke74f956c2016-01-21 16:37:20 -0800631 }
632
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700633 /* Lower a bunch of stuff */
Matt Turner7499bc72017-03-09 11:40:17 -0800634 OPT(nir_lower_var_copies);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700635
Matt Turner7499bc72017-03-09 11:40:17 -0800636 OPT(nir_lower_clip_cull_distance_arrays);
Timothy Arcerieda3ec72016-12-06 12:12:20 +1100637
638 nir_variable_mode indirect_mask = 0;
639 if (compiler->glsl_compiler_options[nir->stage].EmitNoIndirectInput)
640 indirect_mask |= nir_var_shader_in;
641 if (compiler->glsl_compiler_options[nir->stage].EmitNoIndirectOutput)
642 indirect_mask |= nir_var_shader_out;
643 if (compiler->glsl_compiler_options[nir->stage].EmitNoIndirectTemp)
644 indirect_mask |= nir_var_local;
645
646 nir_lower_indirect_derefs(nir, indirect_mask);
647
Jason Ekstrand424ac802017-02-23 14:54:13 -0800648 nir_lower_int64(nir, nir_lower_imul64 |
649 nir_lower_isign64 |
650 nir_lower_divmod64);
651
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700652 /* Get rid of split copies */
Timothy Arceri715f0d02016-12-13 11:36:51 +1100653 nir = nir_optimize(nir, compiler, is_scalar);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700654
Jason Ekstrandb63a98b2016-03-25 14:26:11 -0700655 OPT(nir_remove_dead_variables, nir_var_local);
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800656
657 return nir;
658}
659
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800660/* Prepare the given shader for codegen
661 *
662 * This function is intended to be called right before going into the actual
663 * backend and is highly backend-specific. Also, once this function has been
664 * called on a shader, it will no longer be in SSA form so most optimizations
665 * will not work.
666 */
667nir_shader *
Timothy Arcerie7295042016-09-15 12:20:38 +1000668brw_postprocess_nir(nir_shader *nir, const struct brw_compiler *compiler,
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800669 bool is_scalar)
670{
Timothy Arcerie7295042016-09-15 12:20:38 +1000671 const struct gen_device_info *devinfo = compiler->devinfo;
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800672 bool debug_enabled =
673 (INTEL_DEBUG & intel_debug_flag_for_shader_stage(nir->stage));
674
Matt Turner7499bc72017-03-09 11:40:17 -0800675 UNUSED bool progress; /* Written by OPT */
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800676
Timothy Arceri7a7ee402017-01-13 17:25:11 +1100677
678 do {
679 progress = false;
680 OPT(nir_opt_algebraic_before_ffma);
681 } while (progress);
682
Timothy Arceri715f0d02016-12-13 11:36:51 +1100683 nir = nir_optimize(nir, compiler, is_scalar);
Kenneth Graunke51f87972016-02-24 21:40:37 -0800684
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800685 if (devinfo->gen >= 6) {
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700686 /* Try and fuse multiply-adds */
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800687 OPT(brw_nir_opt_peephole_ffma);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700688 }
689
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800690 OPT(nir_opt_algebraic_late);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700691
Matt Turner7499bc72017-03-09 11:40:17 -0800692 OPT(nir_lower_to_source_mods);
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800693 OPT(nir_copy_prop);
694 OPT(nir_opt_dce);
Kenneth Graunkeb4c44ff2016-08-08 14:44:06 -0700695 OPT(nir_opt_move_comparisons);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700696
Kenneth Graunkeb5e682a2016-08-09 18:02:46 -0700697 OPT(nir_lower_locals_to_regs);
698
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700699 if (unlikely(debug_enabled)) {
Kenneth Graunkef4310cd2015-06-10 01:46:13 -0700700 /* Re-index SSA defs so we print more sensible numbers. */
Jason Ekstrand9464d8c2016-04-26 20:26:42 -0700701 nir_foreach_function(function, nir) {
Jason Ekstrand237f2f22015-12-26 10:00:47 -0800702 if (function->impl)
703 nir_index_ssa_defs(function->impl);
Kenneth Graunkef4310cd2015-06-10 01:46:13 -0700704 }
705
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700706 fprintf(stderr, "NIR (SSA form) for %s shader:\n",
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800707 _mesa_shader_stage_to_string(nir->stage));
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700708 nir_print_shader(nir, stderr);
709 }
710
Matt Turner7499bc72017-03-09 11:40:17 -0800711 OPT(nir_convert_from_ssa, true);
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700712
Antia Puentese4f02f42015-06-16 22:58:15 +0200713 if (!is_scalar) {
Matt Turner7499bc72017-03-09 11:40:17 -0800714 OPT(nir_move_vec_src_uses_to_dest);
Kenneth Graunke7bc09782015-11-03 00:31:15 -0800715 OPT(nir_lower_vec_to_movs);
Antia Puentese4f02f42015-06-16 22:58:15 +0200716 }
717
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700718 /* This is the last pass we run before we start emitting stuff. It
719 * determines when we need to insert boolean resolves on Gen <= 5. We
720 * run it last because it stashes data in instr->pass_flags and we don't
721 * want that to be squashed by other NIR passes.
722 */
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800723 if (devinfo->gen <= 5)
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700724 brw_nir_analyze_boolean_resolves(nir);
725
726 nir_sweep(nir);
727
728 if (unlikely(debug_enabled)) {
729 fprintf(stderr, "NIR (final form) for %s shader:\n",
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800730 _mesa_shader_stage_to_string(nir->stage));
Kenneth Graunke89c1feb2015-04-07 15:15:09 -0700731 nir_print_shader(nir, stderr);
732 }
733
734 return nir;
735}
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200736
Jason Ekstrand9cf108192015-11-11 09:40:51 -0800737nir_shader *
Jason Ekstrand6c8ba592015-11-11 11:01:59 -0800738brw_nir_apply_sampler_key(nir_shader *nir,
Timothy Arcerie7295042016-09-15 12:20:38 +1000739 const struct brw_compiler *compiler,
Jason Ekstrand6c8ba592015-11-11 11:01:59 -0800740 const struct brw_sampler_prog_key_data *key_tex,
741 bool is_scalar)
742{
Timothy Arcerie7295042016-09-15 12:20:38 +1000743 const struct gen_device_info *devinfo = compiler->devinfo;
Jason Ekstrand6c8ba592015-11-11 11:01:59 -0800744 nir_lower_tex_options tex_options = { 0 };
745
746 /* Iron Lake and prior require lowering of all rectangle textures */
747 if (devinfo->gen < 6)
748 tex_options.lower_rect = true;
749
750 /* Prior to Broadwell, our hardware can't actually do GL_CLAMP */
751 if (devinfo->gen < 8) {
752 tex_options.saturate_s = key_tex->gl_clamp_mask[0];
753 tex_options.saturate_t = key_tex->gl_clamp_mask[1];
754 tex_options.saturate_r = key_tex->gl_clamp_mask[2];
755 }
756
Jason Ekstrandd9b8fde2015-11-11 18:41:37 -0800757 /* Prior to Haswell, we have to fake texture swizzle */
758 for (unsigned s = 0; s < MAX_SAMPLERS; s++) {
759 if (key_tex->swizzles[s] == SWIZZLE_NOOP)
760 continue;
761
762 tex_options.swizzle_result |= (1 << s);
763 for (unsigned c = 0; c < 4; c++)
764 tex_options.swizzles[s][c] = GET_SWZ(key_tex->swizzles[s], c);
765 }
766
Iago Toral Quiroga77f65b32016-12-13 10:24:19 +0100767 /* Prior to Haswell, we have to lower gradients on shadow samplers */
768 tex_options.lower_txd_shadow = devinfo->gen < 8 && !devinfo->is_haswell;
769
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -0700770 tex_options.lower_y_uv_external = key_tex->y_uv_image_mask;
771 tex_options.lower_y_u_v_external = key_tex->y_u_v_image_mask;
772 tex_options.lower_yx_xuxv_external = key_tex->yx_xuxv_image_mask;
Johnson Lin165e7042017-06-16 13:51:34 +0800773 tex_options.lower_xy_uxvx_external = key_tex->xy_uxvx_image_mask;
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -0700774
Jason Ekstrand6c8ba592015-11-11 11:01:59 -0800775 if (nir_lower_tex(nir, &tex_options)) {
776 nir_validate_shader(nir);
Timothy Arceri715f0d02016-12-13 11:36:51 +1100777 nir = nir_optimize(nir, compiler, is_scalar);
Jason Ekstrand6c8ba592015-11-11 11:01:59 -0800778 }
779
780 return nir;
781}
782
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200783enum brw_reg_type
Matt Turnerd871f8e2017-01-20 19:03:21 -0800784brw_type_for_nir_type(const struct gen_device_info *devinfo, nir_alu_type type)
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200785{
786 switch (type) {
Jason Ekstrandf5881382015-05-15 09:14:47 -0700787 case nir_type_uint:
Connor Abbott9076c4e2015-08-14 10:45:06 -0700788 case nir_type_uint32:
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200789 return BRW_REGISTER_TYPE_UD;
790 case nir_type_bool:
791 case nir_type_int:
Connor Abbott9076c4e2015-08-14 10:45:06 -0700792 case nir_type_bool32:
793 case nir_type_int32:
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200794 return BRW_REGISTER_TYPE_D;
795 case nir_type_float:
Connor Abbott9076c4e2015-08-14 10:45:06 -0700796 case nir_type_float32:
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200797 return BRW_REGISTER_TYPE_F;
Connor Abbott9076c4e2015-08-14 10:45:06 -0700798 case nir_type_float64:
799 return BRW_REGISTER_TYPE_DF;
800 case nir_type_int64:
Matt Turnerd871f8e2017-01-20 19:03:21 -0800801 return devinfo->gen < 8 ? BRW_REGISTER_TYPE_DF : BRW_REGISTER_TYPE_Q;
Connor Abbott9076c4e2015-08-14 10:45:06 -0700802 case nir_type_uint64:
Matt Turnerd871f8e2017-01-20 19:03:21 -0800803 return devinfo->gen < 8 ? BRW_REGISTER_TYPE_DF : BRW_REGISTER_TYPE_UQ;
Eduardo Lima Mitev97e205f2015-04-17 18:10:50 +0200804 default:
805 unreachable("unknown type");
806 }
807
808 return BRW_REGISTER_TYPE_F;
809}
Eduardo Lima Mitevdb8a6de2015-06-17 10:59:10 +0200810
811/* Returns the glsl_base_type corresponding to a nir_alu_type.
812 * This is used by both brw_vec4_nir and brw_fs_nir.
813 */
814enum glsl_base_type
815brw_glsl_base_type_for_nir_type(nir_alu_type type)
816{
817 switch (type) {
818 case nir_type_float:
Connor Abbott9076c4e2015-08-14 10:45:06 -0700819 case nir_type_float32:
Eduardo Lima Mitevdb8a6de2015-06-17 10:59:10 +0200820 return GLSL_TYPE_FLOAT;
821
Connor Abbott9076c4e2015-08-14 10:45:06 -0700822 case nir_type_float64:
823 return GLSL_TYPE_DOUBLE;
824
Eduardo Lima Mitevdb8a6de2015-06-17 10:59:10 +0200825 case nir_type_int:
Connor Abbott9076c4e2015-08-14 10:45:06 -0700826 case nir_type_int32:
Eduardo Lima Mitevdb8a6de2015-06-17 10:59:10 +0200827 return GLSL_TYPE_INT;
828
Jason Ekstrandf5881382015-05-15 09:14:47 -0700829 case nir_type_uint:
Connor Abbott9076c4e2015-08-14 10:45:06 -0700830 case nir_type_uint32:
Eduardo Lima Mitevdb8a6de2015-06-17 10:59:10 +0200831 return GLSL_TYPE_UINT;
832
833 default:
834 unreachable("bad type");
835 }
836}