i965: Use LZD to implement nir_op_ufind_msb
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vec4_nir.cpp
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 #include "brw_nir.h"
25 #include "brw_vec4.h"
26 #include "brw_vec4_builder.h"
27 #include "brw_vec4_surface_builder.h"
28 #include "brw_program.h"
29
30 using namespace brw;
31 using namespace brw::surface_access;
32
33 namespace brw {
34
35 void
36 vec4_visitor::emit_nir_code()
37 {
38 if (nir->num_uniforms > 0)
39 nir_setup_uniforms();
40
41 nir_setup_system_values();
42
43 /* get the main function and emit it */
44 nir_foreach_function(function, nir) {
45 assert(strcmp(function->name, "main") == 0);
46 assert(function->impl);
47 nir_emit_impl(function->impl);
48 }
49 }
50
51 void
52 vec4_visitor::nir_setup_system_value_intrinsic(nir_intrinsic_instr *instr)
53 {
54 dst_reg *reg;
55
56 switch (instr->intrinsic) {
57 case nir_intrinsic_load_vertex_id:
58 unreachable("should be lowered by lower_vertex_id().");
59
60 case nir_intrinsic_load_vertex_id_zero_base:
61 reg = &nir_system_values[SYSTEM_VALUE_VERTEX_ID_ZERO_BASE];
62 if (reg->file == BAD_FILE)
63 *reg = *make_reg_for_system_value(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE);
64 break;
65
66 case nir_intrinsic_load_base_vertex:
67 reg = &nir_system_values[SYSTEM_VALUE_BASE_VERTEX];
68 if (reg->file == BAD_FILE)
69 *reg = *make_reg_for_system_value(SYSTEM_VALUE_BASE_VERTEX);
70 break;
71
72 case nir_intrinsic_load_instance_id:
73 reg = &nir_system_values[SYSTEM_VALUE_INSTANCE_ID];
74 if (reg->file == BAD_FILE)
75 *reg = *make_reg_for_system_value(SYSTEM_VALUE_INSTANCE_ID);
76 break;
77
78 case nir_intrinsic_load_base_instance:
79 reg = &nir_system_values[SYSTEM_VALUE_BASE_INSTANCE];
80 if (reg->file == BAD_FILE)
81 *reg = *make_reg_for_system_value(SYSTEM_VALUE_BASE_INSTANCE);
82 break;
83
84 case nir_intrinsic_load_draw_id:
85 reg = &nir_system_values[SYSTEM_VALUE_DRAW_ID];
86 if (reg->file == BAD_FILE)
87 *reg = *make_reg_for_system_value(SYSTEM_VALUE_DRAW_ID);
88 break;
89
90 default:
91 break;
92 }
93 }
94
95 static bool
96 setup_system_values_block(nir_block *block, vec4_visitor *v)
97 {
98 nir_foreach_instr(instr, block) {
99 if (instr->type != nir_instr_type_intrinsic)
100 continue;
101
102 nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
103 v->nir_setup_system_value_intrinsic(intrin);
104 }
105
106 return true;
107 }
108
109 void
110 vec4_visitor::nir_setup_system_values()
111 {
112 nir_system_values = ralloc_array(mem_ctx, dst_reg, SYSTEM_VALUE_MAX);
113 for (unsigned i = 0; i < SYSTEM_VALUE_MAX; i++) {
114 nir_system_values[i] = dst_reg();
115 }
116
117 nir_foreach_function(function, nir) {
118 assert(strcmp(function->name, "main") == 0);
119 assert(function->impl);
120 nir_foreach_block(block, function->impl) {
121 setup_system_values_block(block, this);
122 }
123 }
124 }
125
126 void
127 vec4_visitor::nir_setup_uniforms()
128 {
129 uniforms = nir->num_uniforms / 16;
130 }
131
132 void
133 vec4_visitor::nir_emit_impl(nir_function_impl *impl)
134 {
135 nir_locals = ralloc_array(mem_ctx, dst_reg, impl->reg_alloc);
136 for (unsigned i = 0; i < impl->reg_alloc; i++) {
137 nir_locals[i] = dst_reg();
138 }
139
140 foreach_list_typed(nir_register, reg, node, &impl->registers) {
141 unsigned array_elems =
142 reg->num_array_elems == 0 ? 1 : reg->num_array_elems;
143
144 nir_locals[reg->index] = dst_reg(VGRF, alloc.allocate(array_elems));
145 }
146
147 nir_ssa_values = ralloc_array(mem_ctx, dst_reg, impl->ssa_alloc);
148
149 nir_emit_cf_list(&impl->body);
150 }
151
152 void
153 vec4_visitor::nir_emit_cf_list(exec_list *list)
154 {
155 exec_list_validate(list);
156 foreach_list_typed(nir_cf_node, node, node, list) {
157 switch (node->type) {
158 case nir_cf_node_if:
159 nir_emit_if(nir_cf_node_as_if(node));
160 break;
161
162 case nir_cf_node_loop:
163 nir_emit_loop(nir_cf_node_as_loop(node));
164 break;
165
166 case nir_cf_node_block:
167 nir_emit_block(nir_cf_node_as_block(node));
168 break;
169
170 default:
171 unreachable("Invalid CFG node block");
172 }
173 }
174 }
175
176 void
177 vec4_visitor::nir_emit_if(nir_if *if_stmt)
178 {
179 /* First, put the condition in f0 */
180 src_reg condition = get_nir_src(if_stmt->condition, BRW_REGISTER_TYPE_D, 1);
181 vec4_instruction *inst = emit(MOV(dst_null_d(), condition));
182 inst->conditional_mod = BRW_CONDITIONAL_NZ;
183
184 /* We can just predicate based on the X channel, as the condition only
185 * goes on its own line */
186 emit(IF(BRW_PREDICATE_ALIGN16_REPLICATE_X));
187
188 nir_emit_cf_list(&if_stmt->then_list);
189
190 /* note: if the else is empty, dead CF elimination will remove it */
191 emit(BRW_OPCODE_ELSE);
192
193 nir_emit_cf_list(&if_stmt->else_list);
194
195 emit(BRW_OPCODE_ENDIF);
196 }
197
198 void
199 vec4_visitor::nir_emit_loop(nir_loop *loop)
200 {
201 emit(BRW_OPCODE_DO);
202
203 nir_emit_cf_list(&loop->body);
204
205 emit(BRW_OPCODE_WHILE);
206 }
207
208 void
209 vec4_visitor::nir_emit_block(nir_block *block)
210 {
211 nir_foreach_instr(instr, block) {
212 nir_emit_instr(instr);
213 }
214 }
215
216 void
217 vec4_visitor::nir_emit_instr(nir_instr *instr)
218 {
219 base_ir = instr;
220
221 switch (instr->type) {
222 case nir_instr_type_load_const:
223 nir_emit_load_const(nir_instr_as_load_const(instr));
224 break;
225
226 case nir_instr_type_intrinsic:
227 nir_emit_intrinsic(nir_instr_as_intrinsic(instr));
228 break;
229
230 case nir_instr_type_alu:
231 nir_emit_alu(nir_instr_as_alu(instr));
232 break;
233
234 case nir_instr_type_jump:
235 nir_emit_jump(nir_instr_as_jump(instr));
236 break;
237
238 case nir_instr_type_tex:
239 nir_emit_texture(nir_instr_as_tex(instr));
240 break;
241
242 case nir_instr_type_ssa_undef:
243 nir_emit_undef(nir_instr_as_ssa_undef(instr));
244 break;
245
246 default:
247 fprintf(stderr, "VS instruction not yet implemented by NIR->vec4\n");
248 break;
249 }
250 }
251
252 static dst_reg
253 dst_reg_for_nir_reg(vec4_visitor *v, nir_register *nir_reg,
254 unsigned base_offset, nir_src *indirect)
255 {
256 dst_reg reg;
257
258 reg = v->nir_locals[nir_reg->index];
259 reg = offset(reg, base_offset);
260 if (indirect) {
261 reg.reladdr =
262 new(v->mem_ctx) src_reg(v->get_nir_src(*indirect,
263 BRW_REGISTER_TYPE_D,
264 1));
265 }
266 return reg;
267 }
268
269 dst_reg
270 vec4_visitor::get_nir_dest(const nir_dest &dest)
271 {
272 if (dest.is_ssa) {
273 dst_reg dst = dst_reg(VGRF, alloc.allocate(1));
274 nir_ssa_values[dest.ssa.index] = dst;
275 return dst;
276 } else {
277 return dst_reg_for_nir_reg(this, dest.reg.reg, dest.reg.base_offset,
278 dest.reg.indirect);
279 }
280 }
281
282 dst_reg
283 vec4_visitor::get_nir_dest(const nir_dest &dest, enum brw_reg_type type)
284 {
285 return retype(get_nir_dest(dest), type);
286 }
287
288 dst_reg
289 vec4_visitor::get_nir_dest(const nir_dest &dest, nir_alu_type type)
290 {
291 return get_nir_dest(dest, brw_type_for_nir_type(type));
292 }
293
294 src_reg
295 vec4_visitor::get_nir_src(const nir_src &src, enum brw_reg_type type,
296 unsigned num_components)
297 {
298 dst_reg reg;
299
300 if (src.is_ssa) {
301 assert(src.ssa != NULL);
302 reg = nir_ssa_values[src.ssa->index];
303 }
304 else {
305 reg = dst_reg_for_nir_reg(this, src.reg.reg, src.reg.base_offset,
306 src.reg.indirect);
307 }
308
309 reg = retype(reg, type);
310
311 src_reg reg_as_src = src_reg(reg);
312 reg_as_src.swizzle = brw_swizzle_for_size(num_components);
313 return reg_as_src;
314 }
315
316 src_reg
317 vec4_visitor::get_nir_src(const nir_src &src, nir_alu_type type,
318 unsigned num_components)
319 {
320 return get_nir_src(src, brw_type_for_nir_type(type), num_components);
321 }
322
323 src_reg
324 vec4_visitor::get_nir_src(const nir_src &src, unsigned num_components)
325 {
326 /* if type is not specified, default to signed int */
327 return get_nir_src(src, nir_type_int, num_components);
328 }
329
330 src_reg
331 vec4_visitor::get_indirect_offset(nir_intrinsic_instr *instr)
332 {
333 nir_src *offset_src = nir_get_io_offset_src(instr);
334 nir_const_value *const_value = nir_src_as_const_value(*offset_src);
335
336 if (const_value) {
337 /* The only constant offset we should find is 0. brw_nir.c's
338 * add_const_offset_to_base() will fold other constant offsets
339 * into instr->const_index[0].
340 */
341 assert(const_value->u32[0] == 0);
342 return src_reg();
343 }
344
345 return get_nir_src(*offset_src, BRW_REGISTER_TYPE_UD, 1);
346 }
347
348 void
349 vec4_visitor::nir_emit_load_const(nir_load_const_instr *instr)
350 {
351 dst_reg reg = dst_reg(VGRF, alloc.allocate(1));
352 reg.type = BRW_REGISTER_TYPE_D;
353
354 unsigned remaining = brw_writemask_for_size(instr->def.num_components);
355
356 /* @FIXME: consider emitting vector operations to save some MOVs in
357 * cases where the components are representable in 8 bits.
358 * For now, we emit a MOV for each distinct value.
359 */
360 for (unsigned i = 0; i < instr->def.num_components; i++) {
361 unsigned writemask = 1 << i;
362
363 if ((remaining & writemask) == 0)
364 continue;
365
366 for (unsigned j = i; j < instr->def.num_components; j++) {
367 if (instr->value.u32[i] == instr->value.u32[j]) {
368 writemask |= 1 << j;
369 }
370 }
371
372 reg.writemask = writemask;
373 emit(MOV(reg, brw_imm_d(instr->value.i32[i])));
374
375 remaining &= ~writemask;
376 }
377
378 /* Set final writemask */
379 reg.writemask = brw_writemask_for_size(instr->def.num_components);
380
381 nir_ssa_values[instr->def.index] = reg;
382 }
383
384 void
385 vec4_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)
386 {
387 dst_reg dest;
388 src_reg src;
389
390 switch (instr->intrinsic) {
391
392 case nir_intrinsic_load_input: {
393 nir_const_value *const_offset = nir_src_as_const_value(instr->src[0]);
394
395 /* We set EmitNoIndirectInput for VS */
396 assert(const_offset);
397
398 src = src_reg(ATTR, instr->const_index[0] + const_offset->u32[0],
399 glsl_type::uvec4_type);
400
401 dest = get_nir_dest(instr->dest, src.type);
402 dest.writemask = brw_writemask_for_size(instr->num_components);
403
404 emit(MOV(dest, src));
405 break;
406 }
407
408 case nir_intrinsic_store_output: {
409 nir_const_value *const_offset = nir_src_as_const_value(instr->src[1]);
410 assert(const_offset);
411
412 int varying = instr->const_index[0] + const_offset->u32[0];
413
414 src = get_nir_src(instr->src[0], BRW_REGISTER_TYPE_F,
415 instr->num_components);
416
417 output_reg[varying] = dst_reg(src);
418 break;
419 }
420
421 case nir_intrinsic_get_buffer_size: {
422 nir_const_value *const_uniform_block = nir_src_as_const_value(instr->src[0]);
423 unsigned ssbo_index = const_uniform_block ? const_uniform_block->u32[0] : 0;
424
425 const unsigned index =
426 prog_data->base.binding_table.ssbo_start + ssbo_index;
427 dst_reg result_dst = get_nir_dest(instr->dest);
428 vec4_instruction *inst = new(mem_ctx)
429 vec4_instruction(VS_OPCODE_GET_BUFFER_SIZE, result_dst);
430
431 inst->base_mrf = 2;
432 inst->mlen = 1; /* always at least one */
433 inst->src[1] = brw_imm_ud(index);
434
435 /* MRF for the first parameter */
436 src_reg lod = brw_imm_d(0);
437 int param_base = inst->base_mrf;
438 int writemask = WRITEMASK_X;
439 emit(MOV(dst_reg(MRF, param_base, glsl_type::int_type, writemask), lod));
440
441 emit(inst);
442
443 brw_mark_surface_used(&prog_data->base, index);
444 break;
445 }
446
447 case nir_intrinsic_store_ssbo: {
448 assert(devinfo->gen >= 7);
449
450 /* Block index */
451 src_reg surf_index;
452 nir_const_value *const_uniform_block =
453 nir_src_as_const_value(instr->src[1]);
454 if (const_uniform_block) {
455 unsigned index = prog_data->base.binding_table.ssbo_start +
456 const_uniform_block->u32[0];
457 surf_index = brw_imm_ud(index);
458 brw_mark_surface_used(&prog_data->base, index);
459 } else {
460 surf_index = src_reg(this, glsl_type::uint_type);
461 emit(ADD(dst_reg(surf_index), get_nir_src(instr->src[1], 1),
462 brw_imm_ud(prog_data->base.binding_table.ssbo_start)));
463 surf_index = emit_uniformize(surf_index);
464
465 brw_mark_surface_used(&prog_data->base,
466 prog_data->base.binding_table.ssbo_start +
467 nir->info.num_ssbos - 1);
468 }
469
470 /* Offset */
471 src_reg offset_reg;
472 nir_const_value *const_offset = nir_src_as_const_value(instr->src[2]);
473 if (const_offset) {
474 offset_reg = brw_imm_ud(const_offset->u32[0]);
475 } else {
476 offset_reg = get_nir_src(instr->src[2], 1);
477 }
478
479 /* Value */
480 src_reg val_reg = get_nir_src(instr->src[0], 4);
481
482 /* Writemask */
483 unsigned write_mask = instr->const_index[0];
484
485 /* IvyBridge does not have a native SIMD4x2 untyped write message so untyped
486 * writes will use SIMD8 mode. In order to hide this and keep symmetry across
487 * typed and untyped messages and across hardware platforms, the
488 * current implementation of the untyped messages will transparently convert
489 * the SIMD4x2 payload into an equivalent SIMD8 payload by transposing it
490 * and enabling only channel X on the SEND instruction.
491 *
492 * The above, works well for full vector writes, but not for partial writes
493 * where we want to write some channels and not others, like when we have
494 * code such as v.xyw = vec3(1,2,4). Because the untyped write messages are
495 * quite restrictive with regards to the channel enables we can configure in
496 * the message descriptor (not all combinations are allowed) we cannot simply
497 * implement these scenarios with a single message while keeping the
498 * aforementioned symmetry in the implementation. For now we de decided that
499 * it is better to keep the symmetry to reduce complexity, so in situations
500 * such as the one described we end up emitting two untyped write messages
501 * (one for xy and another for w).
502 *
503 * The code below packs consecutive channels into a single write message,
504 * detects gaps in the vector write and if needed, sends a second message
505 * with the remaining channels. If in the future we decide that we want to
506 * emit a single message at the expense of losing the symmetry in the
507 * implementation we can:
508 *
509 * 1) For IvyBridge: Only use the red channel of the untyped write SIMD8
510 * message payload. In this mode we can write up to 8 offsets and dwords
511 * to the red channel only (for the two vec4s in the SIMD4x2 execution)
512 * and select which of the 8 channels carry data to write by setting the
513 * appropriate writemask in the dst register of the SEND instruction.
514 * It would require to write a new generator opcode specifically for
515 * IvyBridge since we would need to prepare a SIMD8 payload that could
516 * use any channel, not just X.
517 *
518 * 2) For Haswell+: Simply send a single write message but set the writemask
519 * on the dst of the SEND instruction to select the channels we want to
520 * write. It would require to modify the current messages to receive
521 * and honor the writemask provided.
522 */
523 const vec4_builder bld = vec4_builder(this).at_end()
524 .annotate(current_annotation, base_ir);
525
526 int swizzle[4] = { 0, 0, 0, 0};
527 int num_channels = 0;
528 unsigned skipped_channels = 0;
529 int num_components = instr->num_components;
530 for (int i = 0; i < num_components; i++) {
531 /* Check if this channel needs to be written. If so, record the
532 * channel we need to take the data from in the swizzle array
533 */
534 int component_mask = 1 << i;
535 int write_test = write_mask & component_mask;
536 if (write_test)
537 swizzle[num_channels++] = i;
538
539 /* If we don't have to write this channel it means we have a gap in the
540 * vector, so write the channels we accumulated until now, if any. Do
541 * the same if this was the last component in the vector.
542 */
543 if (!write_test || i == num_components - 1) {
544 if (num_channels > 0) {
545 /* We have channels to write, so update the offset we need to
546 * write at to skip the channels we skipped, if any.
547 */
548 if (skipped_channels > 0) {
549 if (offset_reg.file == IMM) {
550 offset_reg.ud += 4 * skipped_channels;
551 } else {
552 emit(ADD(dst_reg(offset_reg), offset_reg,
553 brw_imm_ud(4 * skipped_channels)));
554 }
555 }
556
557 /* Swizzle the data register so we take the data from the channels
558 * we need to write and send the write message. This will write
559 * num_channels consecutive dwords starting at offset.
560 */
561 val_reg.swizzle =
562 BRW_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
563 emit_untyped_write(bld, surf_index, offset_reg, val_reg,
564 1 /* dims */, num_channels /* size */,
565 BRW_PREDICATE_NONE);
566
567 /* If we have to do a second write we will have to update the
568 * offset so that we jump over the channels we have just written
569 * now.
570 */
571 skipped_channels = num_channels;
572
573 /* Restart the count for the next write message */
574 num_channels = 0;
575 }
576
577 /* We did not write the current channel, so increase skipped count */
578 skipped_channels++;
579 }
580 }
581
582 break;
583 }
584
585 case nir_intrinsic_load_ssbo: {
586 assert(devinfo->gen >= 7);
587
588 nir_const_value *const_uniform_block =
589 nir_src_as_const_value(instr->src[0]);
590
591 src_reg surf_index;
592 if (const_uniform_block) {
593 unsigned index = prog_data->base.binding_table.ssbo_start +
594 const_uniform_block->u32[0];
595 surf_index = brw_imm_ud(index);
596
597 brw_mark_surface_used(&prog_data->base, index);
598 } else {
599 surf_index = src_reg(this, glsl_type::uint_type);
600 emit(ADD(dst_reg(surf_index), get_nir_src(instr->src[0], 1),
601 brw_imm_ud(prog_data->base.binding_table.ssbo_start)));
602 surf_index = emit_uniformize(surf_index);
603
604 /* Assume this may touch any UBO. It would be nice to provide
605 * a tighter bound, but the array information is already lowered away.
606 */
607 brw_mark_surface_used(&prog_data->base,
608 prog_data->base.binding_table.ssbo_start +
609 nir->info.num_ssbos - 1);
610 }
611
612 src_reg offset_reg;
613 nir_const_value *const_offset = nir_src_as_const_value(instr->src[1]);
614 if (const_offset) {
615 offset_reg = brw_imm_ud(const_offset->u32[0]);
616 } else {
617 offset_reg = get_nir_src(instr->src[1], 1);
618 }
619
620 /* Read the vector */
621 const vec4_builder bld = vec4_builder(this).at_end()
622 .annotate(current_annotation, base_ir);
623
624 src_reg read_result = emit_untyped_read(bld, surf_index, offset_reg,
625 1 /* dims */, 4 /* size*/,
626 BRW_PREDICATE_NONE);
627 dst_reg dest = get_nir_dest(instr->dest);
628 read_result.type = dest.type;
629 read_result.swizzle = brw_swizzle_for_size(instr->num_components);
630 emit(MOV(dest, read_result));
631
632 break;
633 }
634
635 case nir_intrinsic_ssbo_atomic_add:
636 nir_emit_ssbo_atomic(BRW_AOP_ADD, instr);
637 break;
638 case nir_intrinsic_ssbo_atomic_imin:
639 nir_emit_ssbo_atomic(BRW_AOP_IMIN, instr);
640 break;
641 case nir_intrinsic_ssbo_atomic_umin:
642 nir_emit_ssbo_atomic(BRW_AOP_UMIN, instr);
643 break;
644 case nir_intrinsic_ssbo_atomic_imax:
645 nir_emit_ssbo_atomic(BRW_AOP_IMAX, instr);
646 break;
647 case nir_intrinsic_ssbo_atomic_umax:
648 nir_emit_ssbo_atomic(BRW_AOP_UMAX, instr);
649 break;
650 case nir_intrinsic_ssbo_atomic_and:
651 nir_emit_ssbo_atomic(BRW_AOP_AND, instr);
652 break;
653 case nir_intrinsic_ssbo_atomic_or:
654 nir_emit_ssbo_atomic(BRW_AOP_OR, instr);
655 break;
656 case nir_intrinsic_ssbo_atomic_xor:
657 nir_emit_ssbo_atomic(BRW_AOP_XOR, instr);
658 break;
659 case nir_intrinsic_ssbo_atomic_exchange:
660 nir_emit_ssbo_atomic(BRW_AOP_MOV, instr);
661 break;
662 case nir_intrinsic_ssbo_atomic_comp_swap:
663 nir_emit_ssbo_atomic(BRW_AOP_CMPWR, instr);
664 break;
665
666 case nir_intrinsic_load_vertex_id:
667 unreachable("should be lowered by lower_vertex_id()");
668
669 case nir_intrinsic_load_vertex_id_zero_base:
670 case nir_intrinsic_load_base_vertex:
671 case nir_intrinsic_load_instance_id:
672 case nir_intrinsic_load_base_instance:
673 case nir_intrinsic_load_draw_id:
674 case nir_intrinsic_load_invocation_id: {
675 gl_system_value sv = nir_system_value_from_intrinsic(instr->intrinsic);
676 src_reg val = src_reg(nir_system_values[sv]);
677 assert(val.file != BAD_FILE);
678 dest = get_nir_dest(instr->dest, val.type);
679 emit(MOV(dest, val));
680 break;
681 }
682
683 case nir_intrinsic_load_uniform: {
684 /* Offsets are in bytes but they should always be multiples of 4 */
685 assert(nir_intrinsic_base(instr) % 4 == 0);
686
687 dest = get_nir_dest(instr->dest);
688
689 src = src_reg(dst_reg(UNIFORM, nir_intrinsic_base(instr) / 16));
690 src.type = dest.type;
691
692 /* Uniforms don't actually have to be vec4 aligned. In the case that
693 * it isn't, we have to use a swizzle to shift things around. They
694 * do still have the std140 alignment requirement that vec2's have to
695 * be vec2-aligned and vec3's and vec4's have to be vec4-aligned.
696 *
697 * The swizzle also works in the indirect case as the generator adds
698 * the swizzle to the offset for us.
699 */
700 unsigned shift = (nir_intrinsic_base(instr) % 16) / 4;
701 assert(shift + instr->num_components <= 4);
702
703 nir_const_value *const_offset = nir_src_as_const_value(instr->src[0]);
704 if (const_offset) {
705 /* Offsets are in bytes but they should always be multiples of 4 */
706 assert(const_offset->u32[0] % 4 == 0);
707
708 unsigned offset = const_offset->u32[0] + shift * 4;
709 src.reg_offset = offset / 16;
710 shift = (offset % 16) / 4;
711 src.swizzle += BRW_SWIZZLE4(shift, shift, shift, shift);
712
713 emit(MOV(dest, src));
714 } else {
715 src.swizzle += BRW_SWIZZLE4(shift, shift, shift, shift);
716
717 src_reg indirect = get_nir_src(instr->src[0], BRW_REGISTER_TYPE_UD, 1);
718
719 /* MOV_INDIRECT is going to stomp the whole thing anyway */
720 dest.writemask = WRITEMASK_XYZW;
721
722 emit(SHADER_OPCODE_MOV_INDIRECT, dest, src,
723 indirect, brw_imm_ud(instr->const_index[1]));
724 }
725 break;
726 }
727
728 case nir_intrinsic_atomic_counter_read:
729 case nir_intrinsic_atomic_counter_inc:
730 case nir_intrinsic_atomic_counter_dec: {
731 unsigned surf_index = prog_data->base.binding_table.abo_start +
732 (unsigned) instr->const_index[0];
733 src_reg offset = get_nir_src(instr->src[0], nir_type_int,
734 instr->num_components);
735 const src_reg surface = brw_imm_ud(surf_index);
736 const vec4_builder bld =
737 vec4_builder(this).at_end().annotate(current_annotation, base_ir);
738 src_reg tmp;
739
740 dest = get_nir_dest(instr->dest);
741
742 switch (instr->intrinsic) {
743 case nir_intrinsic_atomic_counter_inc:
744 tmp = emit_untyped_atomic(bld, surface, offset,
745 src_reg(), src_reg(),
746 1, 1,
747 BRW_AOP_INC);
748 break;
749 case nir_intrinsic_atomic_counter_dec:
750 tmp = emit_untyped_atomic(bld, surface, offset,
751 src_reg(), src_reg(),
752 1, 1,
753 BRW_AOP_PREDEC);
754 break;
755 case nir_intrinsic_atomic_counter_read:
756 tmp = emit_untyped_read(bld, surface, offset, 1, 1);
757 break;
758 default:
759 unreachable("Unreachable");
760 }
761
762 bld.MOV(retype(dest, tmp.type), tmp);
763 brw_mark_surface_used(stage_prog_data, surf_index);
764 break;
765 }
766
767 case nir_intrinsic_load_ubo: {
768 nir_const_value *const_block_index = nir_src_as_const_value(instr->src[0]);
769 src_reg surf_index;
770
771 dest = get_nir_dest(instr->dest);
772
773 if (const_block_index) {
774 /* The block index is a constant, so just emit the binding table entry
775 * as an immediate.
776 */
777 const unsigned index = prog_data->base.binding_table.ubo_start +
778 const_block_index->u32[0];
779 surf_index = brw_imm_ud(index);
780 brw_mark_surface_used(&prog_data->base, index);
781 } else {
782 /* The block index is not a constant. Evaluate the index expression
783 * per-channel and add the base UBO index; we have to select a value
784 * from any live channel.
785 */
786 surf_index = src_reg(this, glsl_type::uint_type);
787 emit(ADD(dst_reg(surf_index), get_nir_src(instr->src[0], nir_type_int,
788 instr->num_components),
789 brw_imm_ud(prog_data->base.binding_table.ubo_start)));
790 surf_index = emit_uniformize(surf_index);
791
792 /* Assume this may touch any UBO. It would be nice to provide
793 * a tighter bound, but the array information is already lowered away.
794 */
795 brw_mark_surface_used(&prog_data->base,
796 prog_data->base.binding_table.ubo_start +
797 nir->info.num_ubos - 1);
798 }
799
800 src_reg offset;
801 nir_const_value *const_offset = nir_src_as_const_value(instr->src[1]);
802 if (const_offset) {
803 offset = brw_imm_ud(const_offset->u32[0] & ~15);
804 } else {
805 offset = get_nir_src(instr->src[1], nir_type_int, 1);
806 }
807
808 src_reg packed_consts = src_reg(this, glsl_type::vec4_type);
809 packed_consts.type = dest.type;
810
811 emit_pull_constant_load_reg(dst_reg(packed_consts),
812 surf_index,
813 offset,
814 NULL, NULL /* before_block/inst */);
815
816 packed_consts.swizzle = brw_swizzle_for_size(instr->num_components);
817 if (const_offset) {
818 packed_consts.swizzle += BRW_SWIZZLE4(const_offset->u32[0] % 16 / 4,
819 const_offset->u32[0] % 16 / 4,
820 const_offset->u32[0] % 16 / 4,
821 const_offset->u32[0] % 16 / 4);
822 }
823
824 emit(MOV(dest, packed_consts));
825 break;
826 }
827
828 case nir_intrinsic_memory_barrier: {
829 const vec4_builder bld =
830 vec4_builder(this).at_end().annotate(current_annotation, base_ir);
831 const dst_reg tmp = bld.vgrf(BRW_REGISTER_TYPE_UD, 2);
832 bld.emit(SHADER_OPCODE_MEMORY_FENCE, tmp)
833 ->regs_written = 2;
834 break;
835 }
836
837 case nir_intrinsic_shader_clock: {
838 /* We cannot do anything if there is an event, so ignore it for now */
839 const src_reg shader_clock = get_timestamp();
840 const enum brw_reg_type type = brw_type_for_base_type(glsl_type::uvec2_type);
841
842 dest = get_nir_dest(instr->dest, type);
843 emit(MOV(dest, shader_clock));
844 break;
845 }
846
847 default:
848 unreachable("Unknown intrinsic");
849 }
850 }
851
852 void
853 vec4_visitor::nir_emit_ssbo_atomic(int op, nir_intrinsic_instr *instr)
854 {
855 dst_reg dest;
856 if (nir_intrinsic_infos[instr->intrinsic].has_dest)
857 dest = get_nir_dest(instr->dest);
858
859 src_reg surface;
860 nir_const_value *const_surface = nir_src_as_const_value(instr->src[0]);
861 if (const_surface) {
862 unsigned surf_index = prog_data->base.binding_table.ssbo_start +
863 const_surface->u32[0];
864 surface = brw_imm_ud(surf_index);
865 brw_mark_surface_used(&prog_data->base, surf_index);
866 } else {
867 surface = src_reg(this, glsl_type::uint_type);
868 emit(ADD(dst_reg(surface), get_nir_src(instr->src[0]),
869 brw_imm_ud(prog_data->base.binding_table.ssbo_start)));
870
871 /* Assume this may touch any UBO. This is the same we do for other
872 * UBO/SSBO accesses with non-constant surface.
873 */
874 brw_mark_surface_used(&prog_data->base,
875 prog_data->base.binding_table.ssbo_start +
876 nir->info.num_ssbos - 1);
877 }
878
879 src_reg offset = get_nir_src(instr->src[1], 1);
880 src_reg data1 = get_nir_src(instr->src[2], 1);
881 src_reg data2;
882 if (op == BRW_AOP_CMPWR)
883 data2 = get_nir_src(instr->src[3], 1);
884
885 /* Emit the actual atomic operation operation */
886 const vec4_builder bld =
887 vec4_builder(this).at_end().annotate(current_annotation, base_ir);
888
889 src_reg atomic_result = emit_untyped_atomic(bld, surface, offset,
890 data1, data2,
891 1 /* dims */, 1 /* rsize */,
892 op,
893 BRW_PREDICATE_NONE);
894 dest.type = atomic_result.type;
895 bld.MOV(dest, atomic_result);
896 }
897
898 static unsigned
899 brw_swizzle_for_nir_swizzle(uint8_t swizzle[4])
900 {
901 return BRW_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
902 }
903
904 static enum brw_conditional_mod
905 brw_conditional_for_nir_comparison(nir_op op)
906 {
907 switch (op) {
908 case nir_op_flt:
909 case nir_op_ilt:
910 case nir_op_ult:
911 return BRW_CONDITIONAL_L;
912
913 case nir_op_fge:
914 case nir_op_ige:
915 case nir_op_uge:
916 return BRW_CONDITIONAL_GE;
917
918 case nir_op_feq:
919 case nir_op_ieq:
920 case nir_op_ball_fequal2:
921 case nir_op_ball_iequal2:
922 case nir_op_ball_fequal3:
923 case nir_op_ball_iequal3:
924 case nir_op_ball_fequal4:
925 case nir_op_ball_iequal4:
926 return BRW_CONDITIONAL_Z;
927
928 case nir_op_fne:
929 case nir_op_ine:
930 case nir_op_bany_fnequal2:
931 case nir_op_bany_inequal2:
932 case nir_op_bany_fnequal3:
933 case nir_op_bany_inequal3:
934 case nir_op_bany_fnequal4:
935 case nir_op_bany_inequal4:
936 return BRW_CONDITIONAL_NZ;
937
938 default:
939 unreachable("not reached: bad operation for comparison");
940 }
941 }
942
943 bool
944 vec4_visitor::optimize_predicate(nir_alu_instr *instr,
945 enum brw_predicate *predicate)
946 {
947 if (!instr->src[0].src.is_ssa ||
948 instr->src[0].src.ssa->parent_instr->type != nir_instr_type_alu)
949 return false;
950
951 nir_alu_instr *cmp_instr =
952 nir_instr_as_alu(instr->src[0].src.ssa->parent_instr);
953
954 switch (cmp_instr->op) {
955 case nir_op_bany_fnequal2:
956 case nir_op_bany_inequal2:
957 case nir_op_bany_fnequal3:
958 case nir_op_bany_inequal3:
959 case nir_op_bany_fnequal4:
960 case nir_op_bany_inequal4:
961 *predicate = BRW_PREDICATE_ALIGN16_ANY4H;
962 break;
963 case nir_op_ball_fequal2:
964 case nir_op_ball_iequal2:
965 case nir_op_ball_fequal3:
966 case nir_op_ball_iequal3:
967 case nir_op_ball_fequal4:
968 case nir_op_ball_iequal4:
969 *predicate = BRW_PREDICATE_ALIGN16_ALL4H;
970 break;
971 default:
972 return false;
973 }
974
975 unsigned size_swizzle =
976 brw_swizzle_for_size(nir_op_infos[cmp_instr->op].input_sizes[0]);
977
978 src_reg op[2];
979 assert(nir_op_infos[cmp_instr->op].num_inputs == 2);
980 for (unsigned i = 0; i < 2; i++) {
981 op[i] = get_nir_src(cmp_instr->src[i].src,
982 nir_op_infos[cmp_instr->op].input_types[i], 4);
983 unsigned base_swizzle =
984 brw_swizzle_for_nir_swizzle(cmp_instr->src[i].swizzle);
985 op[i].swizzle = brw_compose_swizzle(size_swizzle, base_swizzle);
986 op[i].abs = cmp_instr->src[i].abs;
987 op[i].negate = cmp_instr->src[i].negate;
988 }
989
990 emit(CMP(dst_null_d(), op[0], op[1],
991 brw_conditional_for_nir_comparison(cmp_instr->op)));
992
993 return true;
994 }
995
996 static void
997 emit_find_msb_using_lzd(const vec4_builder &bld,
998 const dst_reg &dst,
999 const src_reg &src,
1000 bool is_signed)
1001 {
1002 vec4_instruction *inst;
1003
1004 bld.LZD(retype(dst, BRW_REGISTER_TYPE_UD), src);
1005
1006 /* LZD counts from the MSB side, while GLSL's findMSB() wants the count
1007 * from the LSB side. Subtract the result from 31 to convert the MSB count
1008 * into an LSB count. If no bits are set, LZD will return 32. 31-32 = -1,
1009 * which is exactly what findMSB() is supposed to return.
1010 */
1011 inst = bld.ADD(dst, retype(src_reg(dst), BRW_REGISTER_TYPE_D),
1012 brw_imm_d(31));
1013 inst->src[0].negate = true;
1014 }
1015
1016 void
1017 vec4_visitor::nir_emit_alu(nir_alu_instr *instr)
1018 {
1019 vec4_instruction *inst;
1020
1021 dst_reg dst = get_nir_dest(instr->dest.dest,
1022 nir_op_infos[instr->op].output_type);
1023 dst.writemask = instr->dest.write_mask;
1024
1025 src_reg op[4];
1026 for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
1027 op[i] = get_nir_src(instr->src[i].src,
1028 nir_op_infos[instr->op].input_types[i], 4);
1029 op[i].swizzle = brw_swizzle_for_nir_swizzle(instr->src[i].swizzle);
1030 op[i].abs = instr->src[i].abs;
1031 op[i].negate = instr->src[i].negate;
1032 }
1033
1034 switch (instr->op) {
1035 case nir_op_imov:
1036 case nir_op_fmov:
1037 inst = emit(MOV(dst, op[0]));
1038 inst->saturate = instr->dest.saturate;
1039 break;
1040
1041 case nir_op_vec2:
1042 case nir_op_vec3:
1043 case nir_op_vec4:
1044 unreachable("not reached: should be handled by lower_vec_to_movs()");
1045
1046 case nir_op_i2f:
1047 case nir_op_u2f:
1048 inst = emit(MOV(dst, op[0]));
1049 inst->saturate = instr->dest.saturate;
1050 break;
1051
1052 case nir_op_f2i:
1053 case nir_op_f2u:
1054 inst = emit(MOV(dst, op[0]));
1055 break;
1056
1057 case nir_op_fadd:
1058 /* fall through */
1059 case nir_op_iadd:
1060 inst = emit(ADD(dst, op[0], op[1]));
1061 inst->saturate = instr->dest.saturate;
1062 break;
1063
1064 case nir_op_fmul:
1065 inst = emit(MUL(dst, op[0], op[1]));
1066 inst->saturate = instr->dest.saturate;
1067 break;
1068
1069 case nir_op_imul: {
1070 if (devinfo->gen < 8) {
1071 nir_const_value *value0 = nir_src_as_const_value(instr->src[0].src);
1072 nir_const_value *value1 = nir_src_as_const_value(instr->src[1].src);
1073
1074 /* For integer multiplication, the MUL uses the low 16 bits of one of
1075 * the operands (src0 through SNB, src1 on IVB and later). The MACH
1076 * accumulates in the contribution of the upper 16 bits of that
1077 * operand. If we can determine that one of the args is in the low
1078 * 16 bits, though, we can just emit a single MUL.
1079 */
1080 if (value0 && value0->u32[0] < (1 << 16)) {
1081 if (devinfo->gen < 7)
1082 emit(MUL(dst, op[0], op[1]));
1083 else
1084 emit(MUL(dst, op[1], op[0]));
1085 } else if (value1 && value1->u32[0] < (1 << 16)) {
1086 if (devinfo->gen < 7)
1087 emit(MUL(dst, op[1], op[0]));
1088 else
1089 emit(MUL(dst, op[0], op[1]));
1090 } else {
1091 struct brw_reg acc = retype(brw_acc_reg(8), dst.type);
1092
1093 emit(MUL(acc, op[0], op[1]));
1094 emit(MACH(dst_null_d(), op[0], op[1]));
1095 emit(MOV(dst, src_reg(acc)));
1096 }
1097 } else {
1098 emit(MUL(dst, op[0], op[1]));
1099 }
1100 break;
1101 }
1102
1103 case nir_op_imul_high:
1104 case nir_op_umul_high: {
1105 struct brw_reg acc = retype(brw_acc_reg(8), dst.type);
1106
1107 if (devinfo->gen >= 8)
1108 emit(MUL(acc, op[0], retype(op[1], BRW_REGISTER_TYPE_UW)));
1109 else
1110 emit(MUL(acc, op[0], op[1]));
1111
1112 emit(MACH(dst, op[0], op[1]));
1113 break;
1114 }
1115
1116 case nir_op_frcp:
1117 inst = emit_math(SHADER_OPCODE_RCP, dst, op[0]);
1118 inst->saturate = instr->dest.saturate;
1119 break;
1120
1121 case nir_op_fexp2:
1122 inst = emit_math(SHADER_OPCODE_EXP2, dst, op[0]);
1123 inst->saturate = instr->dest.saturate;
1124 break;
1125
1126 case nir_op_flog2:
1127 inst = emit_math(SHADER_OPCODE_LOG2, dst, op[0]);
1128 inst->saturate = instr->dest.saturate;
1129 break;
1130
1131 case nir_op_fsin:
1132 inst = emit_math(SHADER_OPCODE_SIN, dst, op[0]);
1133 inst->saturate = instr->dest.saturate;
1134 break;
1135
1136 case nir_op_fcos:
1137 inst = emit_math(SHADER_OPCODE_COS, dst, op[0]);
1138 inst->saturate = instr->dest.saturate;
1139 break;
1140
1141 case nir_op_idiv:
1142 case nir_op_udiv:
1143 emit_math(SHADER_OPCODE_INT_QUOTIENT, dst, op[0], op[1]);
1144 break;
1145
1146 case nir_op_umod:
1147 case nir_op_irem:
1148 /* According to the sign table for INT DIV in the Ivy Bridge PRM, it
1149 * appears that our hardware just does the right thing for signed
1150 * remainder.
1151 */
1152 emit_math(SHADER_OPCODE_INT_REMAINDER, dst, op[0], op[1]);
1153 break;
1154
1155 case nir_op_imod: {
1156 /* Get a regular C-style remainder. If a % b == 0, set the predicate. */
1157 inst = emit_math(SHADER_OPCODE_INT_REMAINDER, dst, op[0], op[1]);
1158
1159 /* Math instructions don't support conditional mod */
1160 inst = emit(MOV(dst_null_d(), src_reg(dst)));
1161 inst->conditional_mod = BRW_CONDITIONAL_NZ;
1162
1163 /* Now, we need to determine if signs of the sources are different.
1164 * When we XOR the sources, the top bit is 0 if they are the same and 1
1165 * if they are different. We can then use a conditional modifier to
1166 * turn that into a predicate. This leads us to an XOR.l instruction.
1167 *
1168 * Technically, according to the PRM, you're not allowed to use .l on a
1169 * XOR instruction. However, emperical experiments and Curro's reading
1170 * of the simulator source both indicate that it's safe.
1171 */
1172 src_reg tmp = src_reg(this, glsl_type::ivec4_type);
1173 inst = emit(XOR(dst_reg(tmp), op[0], op[1]));
1174 inst->predicate = BRW_PREDICATE_NORMAL;
1175 inst->conditional_mod = BRW_CONDITIONAL_L;
1176
1177 /* If the result of the initial remainder operation is non-zero and the
1178 * two sources have different signs, add in a copy of op[1] to get the
1179 * final integer modulus value.
1180 */
1181 inst = emit(ADD(dst, src_reg(dst), op[1]));
1182 inst->predicate = BRW_PREDICATE_NORMAL;
1183 break;
1184 }
1185
1186 case nir_op_ldexp:
1187 unreachable("not reached: should be handled by ldexp_to_arith()");
1188
1189 case nir_op_fsqrt:
1190 inst = emit_math(SHADER_OPCODE_SQRT, dst, op[0]);
1191 inst->saturate = instr->dest.saturate;
1192 break;
1193
1194 case nir_op_frsq:
1195 inst = emit_math(SHADER_OPCODE_RSQ, dst, op[0]);
1196 inst->saturate = instr->dest.saturate;
1197 break;
1198
1199 case nir_op_fpow:
1200 inst = emit_math(SHADER_OPCODE_POW, dst, op[0], op[1]);
1201 inst->saturate = instr->dest.saturate;
1202 break;
1203
1204 case nir_op_uadd_carry: {
1205 struct brw_reg acc = retype(brw_acc_reg(8), BRW_REGISTER_TYPE_UD);
1206
1207 emit(ADDC(dst_null_ud(), op[0], op[1]));
1208 emit(MOV(dst, src_reg(acc)));
1209 break;
1210 }
1211
1212 case nir_op_usub_borrow: {
1213 struct brw_reg acc = retype(brw_acc_reg(8), BRW_REGISTER_TYPE_UD);
1214
1215 emit(SUBB(dst_null_ud(), op[0], op[1]));
1216 emit(MOV(dst, src_reg(acc)));
1217 break;
1218 }
1219
1220 case nir_op_ftrunc:
1221 inst = emit(RNDZ(dst, op[0]));
1222 inst->saturate = instr->dest.saturate;
1223 break;
1224
1225 case nir_op_fceil: {
1226 src_reg tmp = src_reg(this, glsl_type::float_type);
1227 tmp.swizzle =
1228 brw_swizzle_for_size(instr->src[0].src.is_ssa ?
1229 instr->src[0].src.ssa->num_components :
1230 instr->src[0].src.reg.reg->num_components);
1231
1232 op[0].negate = !op[0].negate;
1233 emit(RNDD(dst_reg(tmp), op[0]));
1234 tmp.negate = true;
1235 inst = emit(MOV(dst, tmp));
1236 inst->saturate = instr->dest.saturate;
1237 break;
1238 }
1239
1240 case nir_op_ffloor:
1241 inst = emit(RNDD(dst, op[0]));
1242 inst->saturate = instr->dest.saturate;
1243 break;
1244
1245 case nir_op_ffract:
1246 inst = emit(FRC(dst, op[0]));
1247 inst->saturate = instr->dest.saturate;
1248 break;
1249
1250 case nir_op_fround_even:
1251 inst = emit(RNDE(dst, op[0]));
1252 inst->saturate = instr->dest.saturate;
1253 break;
1254
1255 case nir_op_fquantize2f16: {
1256 /* See also vec4_visitor::emit_pack_half_2x16() */
1257 src_reg tmp16 = src_reg(this, glsl_type::uvec4_type);
1258 src_reg tmp32 = src_reg(this, glsl_type::vec4_type);
1259 src_reg zero = src_reg(this, glsl_type::vec4_type);
1260
1261 /* Check for denormal */
1262 src_reg abs_src0 = op[0];
1263 abs_src0.abs = true;
1264 emit(CMP(dst_null_f(), abs_src0, brw_imm_f(ldexpf(1.0, -14)),
1265 BRW_CONDITIONAL_L));
1266 /* Get the appropriately signed zero */
1267 emit(AND(retype(dst_reg(zero), BRW_REGISTER_TYPE_UD),
1268 retype(op[0], BRW_REGISTER_TYPE_UD),
1269 brw_imm_ud(0x80000000)));
1270 /* Do the actual F32 -> F16 -> F32 conversion */
1271 emit(F32TO16(dst_reg(tmp16), op[0]));
1272 emit(F16TO32(dst_reg(tmp32), tmp16));
1273 /* Select that or zero based on normal status */
1274 inst = emit(BRW_OPCODE_SEL, dst, zero, tmp32);
1275 inst->predicate = BRW_PREDICATE_NORMAL;
1276 inst->saturate = instr->dest.saturate;
1277 break;
1278 }
1279
1280 case nir_op_fmin:
1281 case nir_op_imin:
1282 case nir_op_umin:
1283 inst = emit_minmax(BRW_CONDITIONAL_L, dst, op[0], op[1]);
1284 inst->saturate = instr->dest.saturate;
1285 break;
1286
1287 case nir_op_fmax:
1288 case nir_op_imax:
1289 case nir_op_umax:
1290 inst = emit_minmax(BRW_CONDITIONAL_GE, dst, op[0], op[1]);
1291 inst->saturate = instr->dest.saturate;
1292 break;
1293
1294 case nir_op_fddx:
1295 case nir_op_fddx_coarse:
1296 case nir_op_fddx_fine:
1297 case nir_op_fddy:
1298 case nir_op_fddy_coarse:
1299 case nir_op_fddy_fine:
1300 unreachable("derivatives are not valid in vertex shaders");
1301
1302 case nir_op_flt:
1303 case nir_op_ilt:
1304 case nir_op_ult:
1305 case nir_op_fge:
1306 case nir_op_ige:
1307 case nir_op_uge:
1308 case nir_op_feq:
1309 case nir_op_ieq:
1310 case nir_op_fne:
1311 case nir_op_ine:
1312 emit(CMP(dst, op[0], op[1],
1313 brw_conditional_for_nir_comparison(instr->op)));
1314 break;
1315
1316 case nir_op_ball_fequal2:
1317 case nir_op_ball_iequal2:
1318 case nir_op_ball_fequal3:
1319 case nir_op_ball_iequal3:
1320 case nir_op_ball_fequal4:
1321 case nir_op_ball_iequal4: {
1322 unsigned swiz =
1323 brw_swizzle_for_size(nir_op_infos[instr->op].input_sizes[0]);
1324
1325 emit(CMP(dst_null_d(), swizzle(op[0], swiz), swizzle(op[1], swiz),
1326 brw_conditional_for_nir_comparison(instr->op)));
1327 emit(MOV(dst, brw_imm_d(0)));
1328 inst = emit(MOV(dst, brw_imm_d(~0)));
1329 inst->predicate = BRW_PREDICATE_ALIGN16_ALL4H;
1330 break;
1331 }
1332
1333 case nir_op_bany_fnequal2:
1334 case nir_op_bany_inequal2:
1335 case nir_op_bany_fnequal3:
1336 case nir_op_bany_inequal3:
1337 case nir_op_bany_fnequal4:
1338 case nir_op_bany_inequal4: {
1339 unsigned swiz =
1340 brw_swizzle_for_size(nir_op_infos[instr->op].input_sizes[0]);
1341
1342 emit(CMP(dst_null_d(), swizzle(op[0], swiz), swizzle(op[1], swiz),
1343 brw_conditional_for_nir_comparison(instr->op)));
1344
1345 emit(MOV(dst, brw_imm_d(0)));
1346 inst = emit(MOV(dst, brw_imm_d(~0)));
1347 inst->predicate = BRW_PREDICATE_ALIGN16_ANY4H;
1348 break;
1349 }
1350
1351 case nir_op_inot:
1352 if (devinfo->gen >= 8) {
1353 op[0] = resolve_source_modifiers(op[0]);
1354 }
1355 emit(NOT(dst, op[0]));
1356 break;
1357
1358 case nir_op_ixor:
1359 if (devinfo->gen >= 8) {
1360 op[0] = resolve_source_modifiers(op[0]);
1361 op[1] = resolve_source_modifiers(op[1]);
1362 }
1363 emit(XOR(dst, op[0], op[1]));
1364 break;
1365
1366 case nir_op_ior:
1367 if (devinfo->gen >= 8) {
1368 op[0] = resolve_source_modifiers(op[0]);
1369 op[1] = resolve_source_modifiers(op[1]);
1370 }
1371 emit(OR(dst, op[0], op[1]));
1372 break;
1373
1374 case nir_op_iand:
1375 if (devinfo->gen >= 8) {
1376 op[0] = resolve_source_modifiers(op[0]);
1377 op[1] = resolve_source_modifiers(op[1]);
1378 }
1379 emit(AND(dst, op[0], op[1]));
1380 break;
1381
1382 case nir_op_b2i:
1383 case nir_op_b2f:
1384 emit(MOV(dst, negate(op[0])));
1385 break;
1386
1387 case nir_op_f2b:
1388 emit(CMP(dst, op[0], brw_imm_f(0.0f), BRW_CONDITIONAL_NZ));
1389 break;
1390
1391 case nir_op_i2b:
1392 emit(CMP(dst, op[0], brw_imm_d(0), BRW_CONDITIONAL_NZ));
1393 break;
1394
1395 case nir_op_fnoise1_1:
1396 case nir_op_fnoise1_2:
1397 case nir_op_fnoise1_3:
1398 case nir_op_fnoise1_4:
1399 case nir_op_fnoise2_1:
1400 case nir_op_fnoise2_2:
1401 case nir_op_fnoise2_3:
1402 case nir_op_fnoise2_4:
1403 case nir_op_fnoise3_1:
1404 case nir_op_fnoise3_2:
1405 case nir_op_fnoise3_3:
1406 case nir_op_fnoise3_4:
1407 case nir_op_fnoise4_1:
1408 case nir_op_fnoise4_2:
1409 case nir_op_fnoise4_3:
1410 case nir_op_fnoise4_4:
1411 unreachable("not reached: should be handled by lower_noise");
1412
1413 case nir_op_unpack_half_2x16_split_x:
1414 case nir_op_unpack_half_2x16_split_y:
1415 case nir_op_pack_half_2x16_split:
1416 unreachable("not reached: should not occur in vertex shader");
1417
1418 case nir_op_unpack_snorm_2x16:
1419 case nir_op_unpack_unorm_2x16:
1420 case nir_op_pack_snorm_2x16:
1421 case nir_op_pack_unorm_2x16:
1422 unreachable("not reached: should be handled by lower_packing_builtins");
1423
1424 case nir_op_pack_uvec4_to_uint:
1425 unreachable("not reached");
1426
1427 case nir_op_pack_uvec2_to_uint: {
1428 dst_reg tmp1 = dst_reg(this, glsl_type::uint_type);
1429 tmp1.writemask = WRITEMASK_X;
1430 op[0].swizzle = BRW_SWIZZLE_YYYY;
1431 emit(SHL(tmp1, op[0], src_reg(brw_imm_ud(16u))));
1432
1433 dst_reg tmp2 = dst_reg(this, glsl_type::uint_type);
1434 tmp2.writemask = WRITEMASK_X;
1435 op[0].swizzle = BRW_SWIZZLE_XXXX;
1436 emit(AND(tmp2, op[0], src_reg(brw_imm_ud(0xffffu))));
1437
1438 emit(OR(dst, src_reg(tmp1), src_reg(tmp2)));
1439 break;
1440 }
1441
1442 case nir_op_unpack_half_2x16:
1443 /* As NIR does not guarantee that we have a correct swizzle outside the
1444 * boundaries of a vector, and the implementation of emit_unpack_half_2x16
1445 * uses the source operand in an operation with WRITEMASK_Y while our
1446 * source operand has only size 1, it accessed incorrect data producing
1447 * regressions in Piglit. We repeat the swizzle of the first component on the
1448 * rest of components to avoid regressions. In the vec4_visitor IR code path
1449 * this is not needed because the operand has already the correct swizzle.
1450 */
1451 op[0].swizzle = brw_compose_swizzle(BRW_SWIZZLE_XXXX, op[0].swizzle);
1452 emit_unpack_half_2x16(dst, op[0]);
1453 break;
1454
1455 case nir_op_pack_half_2x16:
1456 emit_pack_half_2x16(dst, op[0]);
1457 break;
1458
1459 case nir_op_unpack_unorm_4x8:
1460 emit_unpack_unorm_4x8(dst, op[0]);
1461 break;
1462
1463 case nir_op_pack_unorm_4x8:
1464 emit_pack_unorm_4x8(dst, op[0]);
1465 break;
1466
1467 case nir_op_unpack_snorm_4x8:
1468 emit_unpack_snorm_4x8(dst, op[0]);
1469 break;
1470
1471 case nir_op_pack_snorm_4x8:
1472 emit_pack_snorm_4x8(dst, op[0]);
1473 break;
1474
1475 case nir_op_bitfield_reverse:
1476 emit(BFREV(dst, op[0]));
1477 break;
1478
1479 case nir_op_bit_count:
1480 emit(CBIT(dst, op[0]));
1481 break;
1482
1483 case nir_op_ufind_msb:
1484 emit_find_msb_using_lzd(vec4_builder(this).at_end(), dst, op[0], false);
1485 break;
1486
1487 case nir_op_ifind_msb: {
1488 emit(FBH(retype(dst, BRW_REGISTER_TYPE_UD), op[0]));
1489
1490 /* FBH counts from the MSB side, while GLSL's findMSB() wants the count
1491 * from the LSB side. If FBH didn't return an error (0xFFFFFFFF), then
1492 * subtract the result from 31 to convert the MSB count into an LSB count.
1493 */
1494 src_reg src(dst);
1495 emit(CMP(dst_null_d(), src, brw_imm_d(-1), BRW_CONDITIONAL_NZ));
1496
1497 inst = emit(ADD(dst, src, brw_imm_d(31)));
1498 inst->predicate = BRW_PREDICATE_NORMAL;
1499 inst->src[0].negate = true;
1500 break;
1501 }
1502
1503 case nir_op_find_lsb:
1504 emit(FBL(dst, op[0]));
1505 break;
1506
1507 case nir_op_ubitfield_extract:
1508 case nir_op_ibitfield_extract:
1509 unreachable("should have been lowered");
1510 case nir_op_ubfe:
1511 case nir_op_ibfe:
1512 op[0] = fix_3src_operand(op[0]);
1513 op[1] = fix_3src_operand(op[1]);
1514 op[2] = fix_3src_operand(op[2]);
1515
1516 emit(BFE(dst, op[2], op[1], op[0]));
1517 break;
1518
1519 case nir_op_bfm:
1520 emit(BFI1(dst, op[0], op[1]));
1521 break;
1522
1523 case nir_op_bfi:
1524 op[0] = fix_3src_operand(op[0]);
1525 op[1] = fix_3src_operand(op[1]);
1526 op[2] = fix_3src_operand(op[2]);
1527
1528 emit(BFI2(dst, op[0], op[1], op[2]));
1529 break;
1530
1531 case nir_op_bitfield_insert:
1532 unreachable("not reached: should have been lowered");
1533
1534 case nir_op_fsign:
1535 /* AND(val, 0x80000000) gives the sign bit.
1536 *
1537 * Predicated OR ORs 1.0 (0x3f800000) with the sign bit if val is not
1538 * zero.
1539 */
1540 emit(CMP(dst_null_f(), op[0], brw_imm_f(0.0f), BRW_CONDITIONAL_NZ));
1541
1542 op[0].type = BRW_REGISTER_TYPE_UD;
1543 dst.type = BRW_REGISTER_TYPE_UD;
1544 emit(AND(dst, op[0], brw_imm_ud(0x80000000u)));
1545
1546 inst = emit(OR(dst, src_reg(dst), brw_imm_ud(0x3f800000u)));
1547 inst->predicate = BRW_PREDICATE_NORMAL;
1548 dst.type = BRW_REGISTER_TYPE_F;
1549
1550 if (instr->dest.saturate) {
1551 inst = emit(MOV(dst, src_reg(dst)));
1552 inst->saturate = true;
1553 }
1554 break;
1555
1556 case nir_op_isign:
1557 /* ASR(val, 31) -> negative val generates 0xffffffff (signed -1).
1558 * -> non-negative val generates 0x00000000.
1559 * Predicated OR sets 1 if val is positive.
1560 */
1561 emit(CMP(dst_null_d(), op[0], brw_imm_d(0), BRW_CONDITIONAL_G));
1562 emit(ASR(dst, op[0], brw_imm_d(31)));
1563 inst = emit(OR(dst, src_reg(dst), brw_imm_d(1)));
1564 inst->predicate = BRW_PREDICATE_NORMAL;
1565 break;
1566
1567 case nir_op_ishl:
1568 emit(SHL(dst, op[0], op[1]));
1569 break;
1570
1571 case nir_op_ishr:
1572 emit(ASR(dst, op[0], op[1]));
1573 break;
1574
1575 case nir_op_ushr:
1576 emit(SHR(dst, op[0], op[1]));
1577 break;
1578
1579 case nir_op_ffma:
1580 op[0] = fix_3src_operand(op[0]);
1581 op[1] = fix_3src_operand(op[1]);
1582 op[2] = fix_3src_operand(op[2]);
1583
1584 inst = emit(MAD(dst, op[2], op[1], op[0]));
1585 inst->saturate = instr->dest.saturate;
1586 break;
1587
1588 case nir_op_flrp:
1589 inst = emit_lrp(dst, op[0], op[1], op[2]);
1590 inst->saturate = instr->dest.saturate;
1591 break;
1592
1593 case nir_op_bcsel:
1594 enum brw_predicate predicate;
1595 if (!optimize_predicate(instr, &predicate)) {
1596 emit(CMP(dst_null_d(), op[0], brw_imm_d(0), BRW_CONDITIONAL_NZ));
1597 switch (dst.writemask) {
1598 case WRITEMASK_X:
1599 predicate = BRW_PREDICATE_ALIGN16_REPLICATE_X;
1600 break;
1601 case WRITEMASK_Y:
1602 predicate = BRW_PREDICATE_ALIGN16_REPLICATE_Y;
1603 break;
1604 case WRITEMASK_Z:
1605 predicate = BRW_PREDICATE_ALIGN16_REPLICATE_Z;
1606 break;
1607 case WRITEMASK_W:
1608 predicate = BRW_PREDICATE_ALIGN16_REPLICATE_W;
1609 break;
1610 default:
1611 predicate = BRW_PREDICATE_NORMAL;
1612 break;
1613 }
1614 }
1615 inst = emit(BRW_OPCODE_SEL, dst, op[1], op[2]);
1616 inst->predicate = predicate;
1617 break;
1618
1619 case nir_op_fdot_replicated2:
1620 inst = emit(BRW_OPCODE_DP2, dst, op[0], op[1]);
1621 inst->saturate = instr->dest.saturate;
1622 break;
1623
1624 case nir_op_fdot_replicated3:
1625 inst = emit(BRW_OPCODE_DP3, dst, op[0], op[1]);
1626 inst->saturate = instr->dest.saturate;
1627 break;
1628
1629 case nir_op_fdot_replicated4:
1630 inst = emit(BRW_OPCODE_DP4, dst, op[0], op[1]);
1631 inst->saturate = instr->dest.saturate;
1632 break;
1633
1634 case nir_op_fdph_replicated:
1635 inst = emit(BRW_OPCODE_DPH, dst, op[0], op[1]);
1636 inst->saturate = instr->dest.saturate;
1637 break;
1638
1639 case nir_op_fabs:
1640 case nir_op_iabs:
1641 case nir_op_fneg:
1642 case nir_op_ineg:
1643 case nir_op_fsat:
1644 unreachable("not reached: should be lowered by lower_source mods");
1645
1646 case nir_op_fdiv:
1647 unreachable("not reached: should be lowered by DIV_TO_MUL_RCP in the compiler");
1648
1649 case nir_op_fmod:
1650 unreachable("not reached: should be lowered by MOD_TO_FLOOR in the compiler");
1651
1652 case nir_op_fsub:
1653 case nir_op_isub:
1654 unreachable("not reached: should be handled by ir_sub_to_add_neg");
1655
1656 default:
1657 unreachable("Unimplemented ALU operation");
1658 }
1659
1660 /* If we need to do a boolean resolve, replace the result with -(x & 1)
1661 * to sign extend the low bit to 0/~0
1662 */
1663 if (devinfo->gen <= 5 &&
1664 (instr->instr.pass_flags & BRW_NIR_BOOLEAN_MASK) ==
1665 BRW_NIR_BOOLEAN_NEEDS_RESOLVE) {
1666 dst_reg masked = dst_reg(this, glsl_type::int_type);
1667 masked.writemask = dst.writemask;
1668 emit(AND(masked, src_reg(dst), brw_imm_d(1)));
1669 src_reg masked_neg = src_reg(masked);
1670 masked_neg.negate = true;
1671 emit(MOV(retype(dst, BRW_REGISTER_TYPE_D), masked_neg));
1672 }
1673 }
1674
1675 void
1676 vec4_visitor::nir_emit_jump(nir_jump_instr *instr)
1677 {
1678 switch (instr->type) {
1679 case nir_jump_break:
1680 emit(BRW_OPCODE_BREAK);
1681 break;
1682
1683 case nir_jump_continue:
1684 emit(BRW_OPCODE_CONTINUE);
1685 break;
1686
1687 case nir_jump_return:
1688 /* fall through */
1689 default:
1690 unreachable("unknown jump");
1691 }
1692 }
1693
1694 enum ir_texture_opcode
1695 ir_texture_opcode_for_nir_texop(nir_texop texop)
1696 {
1697 enum ir_texture_opcode op;
1698
1699 switch (texop) {
1700 case nir_texop_lod: op = ir_lod; break;
1701 case nir_texop_query_levels: op = ir_query_levels; break;
1702 case nir_texop_texture_samples: op = ir_texture_samples; break;
1703 case nir_texop_tex: op = ir_tex; break;
1704 case nir_texop_tg4: op = ir_tg4; break;
1705 case nir_texop_txb: op = ir_txb; break;
1706 case nir_texop_txd: op = ir_txd; break;
1707 case nir_texop_txf: op = ir_txf; break;
1708 case nir_texop_txf_ms: op = ir_txf_ms; break;
1709 case nir_texop_txl: op = ir_txl; break;
1710 case nir_texop_txs: op = ir_txs; break;
1711 case nir_texop_samples_identical: op = ir_samples_identical; break;
1712 default:
1713 unreachable("unknown texture opcode");
1714 }
1715
1716 return op;
1717 }
1718 const glsl_type *
1719 glsl_type_for_nir_alu_type(nir_alu_type alu_type,
1720 unsigned components)
1721 {
1722 switch (alu_type) {
1723 case nir_type_float:
1724 return glsl_type::vec(components);
1725 case nir_type_int:
1726 return glsl_type::ivec(components);
1727 case nir_type_uint:
1728 return glsl_type::uvec(components);
1729 case nir_type_bool:
1730 return glsl_type::bvec(components);
1731 default:
1732 return glsl_type::error_type;
1733 }
1734
1735 return glsl_type::error_type;
1736 }
1737
1738 void
1739 vec4_visitor::nir_emit_texture(nir_tex_instr *instr)
1740 {
1741 unsigned texture = instr->texture_index;
1742 unsigned sampler = instr->sampler_index;
1743 src_reg texture_reg = brw_imm_ud(texture);
1744 src_reg sampler_reg = brw_imm_ud(sampler);
1745 src_reg coordinate;
1746 const glsl_type *coord_type = NULL;
1747 src_reg shadow_comparitor;
1748 src_reg offset_value;
1749 src_reg lod, lod2;
1750 src_reg sample_index;
1751 src_reg mcs;
1752
1753 const glsl_type *dest_type =
1754 glsl_type_for_nir_alu_type(instr->dest_type,
1755 nir_tex_instr_dest_size(instr));
1756 dst_reg dest = get_nir_dest(instr->dest, instr->dest_type);
1757
1758 /* The hardware requires a LOD for buffer textures */
1759 if (instr->sampler_dim == GLSL_SAMPLER_DIM_BUF)
1760 lod = brw_imm_d(0);
1761
1762 /* Load the texture operation sources */
1763 uint32_t constant_offset = 0;
1764 for (unsigned i = 0; i < instr->num_srcs; i++) {
1765 switch (instr->src[i].src_type) {
1766 case nir_tex_src_comparitor:
1767 shadow_comparitor = get_nir_src(instr->src[i].src,
1768 BRW_REGISTER_TYPE_F, 1);
1769 break;
1770
1771 case nir_tex_src_coord: {
1772 unsigned src_size = nir_tex_instr_src_size(instr, i);
1773
1774 switch (instr->op) {
1775 case nir_texop_txf:
1776 case nir_texop_txf_ms:
1777 case nir_texop_samples_identical:
1778 coordinate = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D,
1779 src_size);
1780 coord_type = glsl_type::ivec(src_size);
1781 break;
1782
1783 default:
1784 coordinate = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_F,
1785 src_size);
1786 coord_type = glsl_type::vec(src_size);
1787 break;
1788 }
1789 break;
1790 }
1791
1792 case nir_tex_src_ddx:
1793 lod = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_F,
1794 nir_tex_instr_src_size(instr, i));
1795 break;
1796
1797 case nir_tex_src_ddy:
1798 lod2 = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_F,
1799 nir_tex_instr_src_size(instr, i));
1800 break;
1801
1802 case nir_tex_src_lod:
1803 switch (instr->op) {
1804 case nir_texop_txs:
1805 case nir_texop_txf:
1806 lod = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D, 1);
1807 break;
1808
1809 default:
1810 lod = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_F, 1);
1811 break;
1812 }
1813 break;
1814
1815 case nir_tex_src_ms_index: {
1816 sample_index = get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D, 1);
1817 break;
1818 }
1819
1820 case nir_tex_src_offset: {
1821 nir_const_value *const_offset =
1822 nir_src_as_const_value(instr->src[i].src);
1823 if (const_offset) {
1824 constant_offset = brw_texture_offset(const_offset->i32, 3);
1825 } else {
1826 offset_value =
1827 get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D, 2);
1828 }
1829 break;
1830 }
1831
1832 case nir_tex_src_texture_offset: {
1833 /* The highest texture which may be used by this operation is
1834 * the last element of the array. Mark it here, because the generator
1835 * doesn't have enough information to determine the bound.
1836 */
1837 uint32_t array_size = instr->texture_array_size;
1838 uint32_t max_used = texture + array_size - 1;
1839 if (instr->op == nir_texop_tg4) {
1840 max_used += prog_data->base.binding_table.gather_texture_start;
1841 } else {
1842 max_used += prog_data->base.binding_table.texture_start;
1843 }
1844
1845 brw_mark_surface_used(&prog_data->base, max_used);
1846
1847 /* Emit code to evaluate the actual indexing expression */
1848 src_reg src = get_nir_src(instr->src[i].src, 1);
1849 src_reg temp(this, glsl_type::uint_type);
1850 emit(ADD(dst_reg(temp), src, brw_imm_ud(texture)));
1851 texture_reg = emit_uniformize(temp);
1852 break;
1853 }
1854
1855 case nir_tex_src_sampler_offset: {
1856 /* Emit code to evaluate the actual indexing expression */
1857 src_reg src = get_nir_src(instr->src[i].src, 1);
1858 src_reg temp(this, glsl_type::uint_type);
1859 emit(ADD(dst_reg(temp), src, brw_imm_ud(sampler)));
1860 sampler_reg = emit_uniformize(temp);
1861 break;
1862 }
1863
1864 case nir_tex_src_projector:
1865 unreachable("Should be lowered by do_lower_texture_projection");
1866
1867 case nir_tex_src_bias:
1868 unreachable("LOD bias is not valid for vertex shaders.\n");
1869
1870 default:
1871 unreachable("unknown texture source");
1872 }
1873 }
1874
1875 if (instr->op == nir_texop_txf_ms ||
1876 instr->op == nir_texop_samples_identical) {
1877 assert(coord_type != NULL);
1878 if (devinfo->gen >= 7 &&
1879 key_tex->compressed_multisample_layout_mask & (1 << texture)) {
1880 mcs = emit_mcs_fetch(coord_type, coordinate, texture_reg);
1881 } else {
1882 mcs = brw_imm_ud(0u);
1883 }
1884 }
1885
1886 /* Stuff the channel select bits in the top of the texture offset */
1887 if (instr->op == nir_texop_tg4) {
1888 if (instr->component == 1 &&
1889 (key_tex->gather_channel_quirk_mask & (1 << texture))) {
1890 /* gather4 sampler is broken for green channel on RG32F --
1891 * we must ask for blue instead.
1892 */
1893 constant_offset |= 2 << 16;
1894 } else {
1895 constant_offset |= instr->component << 16;
1896 }
1897 }
1898
1899 ir_texture_opcode op = ir_texture_opcode_for_nir_texop(instr->op);
1900
1901 bool is_cube_array =
1902 instr->op == nir_texop_txs &&
1903 instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE &&
1904 instr->is_array;
1905
1906 emit_texture(op, dest, dest_type, coordinate, instr->coord_components,
1907 shadow_comparitor,
1908 lod, lod2, sample_index,
1909 constant_offset, offset_value,
1910 mcs, is_cube_array,
1911 texture, texture_reg, sampler, sampler_reg);
1912 }
1913
1914 void
1915 vec4_visitor::nir_emit_undef(nir_ssa_undef_instr *instr)
1916 {
1917 nir_ssa_values[instr->def.index] = dst_reg(VGRF, alloc.allocate(1));
1918 }
1919
1920 }