2 * Copyright © 2014 Intel Corporation
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:
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
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
24 * Connor Abbott (cwabbott0@gmail.com)
28 #include "glsl_to_nir.h"
29 #include "nir_control_flow.h"
30 #include "ir_visitor.h"
31 #include "ir_hierarchical_visitor.h"
35 * pass to lower GLSL IR to NIR
37 * This will lower variable dereferences to loads/stores of corresponding
38 * variables in NIR - the variables will be converted to registers in a later
44 class nir_visitor
: public ir_visitor
47 nir_visitor(nir_shader
*shader
);
50 virtual void visit(ir_variable
*);
51 virtual void visit(ir_function
*);
52 virtual void visit(ir_function_signature
*);
53 virtual void visit(ir_loop
*);
54 virtual void visit(ir_if
*);
55 virtual void visit(ir_discard
*);
56 virtual void visit(ir_loop_jump
*);
57 virtual void visit(ir_return
*);
58 virtual void visit(ir_call
*);
59 virtual void visit(ir_assignment
*);
60 virtual void visit(ir_emit_vertex
*);
61 virtual void visit(ir_end_primitive
*);
62 virtual void visit(ir_expression
*);
63 virtual void visit(ir_swizzle
*);
64 virtual void visit(ir_texture
*);
65 virtual void visit(ir_constant
*);
66 virtual void visit(ir_dereference_variable
*);
67 virtual void visit(ir_dereference_record
*);
68 virtual void visit(ir_dereference_array
*);
69 virtual void visit(ir_barrier
*);
71 void create_function(ir_function
*ir
);
74 void create_overload(ir_function_signature
*ir
, nir_function
*function
);
75 void add_instr(nir_instr
*instr
, unsigned num_components
);
76 nir_src
evaluate_rvalue(ir_rvalue
*ir
);
78 nir_alu_instr
*emit(nir_op op
, unsigned dest_size
, nir_src
*srcs
);
79 nir_alu_instr
*emit(nir_op op
, unsigned dest_size
, nir_src src1
);
80 nir_alu_instr
*emit(nir_op op
, unsigned dest_size
, nir_src src1
,
82 nir_alu_instr
*emit(nir_op op
, unsigned dest_size
, nir_src src1
,
83 nir_src src2
, nir_src src3
);
88 nir_function_impl
*impl
;
89 exec_list
*cf_node_list
;
90 nir_instr
*result
; /* result of the expression tree last visited */
92 nir_deref_var
*evaluate_deref(nir_instr
*mem_ctx
, ir_instruction
*ir
);
94 /* the head of the dereference chain we're creating */
95 nir_deref_var
*deref_head
;
96 /* the tail of the dereference chain we're creating */
97 nir_deref
*deref_tail
;
99 nir_variable
*var
; /* variable created by ir_variable visitor */
101 /* whether the IR we're operating on is per-function or global */
104 /* map of ir_variable -> nir_variable */
105 struct hash_table
*var_table
;
107 /* map of ir_function_signature -> nir_function_overload */
108 struct hash_table
*overload_table
;
112 * This visitor runs before the main visitor, calling create_function() for
113 * each function so that the main visitor can resolve forward references in
117 class nir_function_visitor
: public ir_hierarchical_visitor
120 nir_function_visitor(nir_visitor
*v
) : visitor(v
)
123 virtual ir_visitor_status
visit_enter(ir_function
*);
126 nir_visitor
*visitor
;
129 }; /* end of anonymous namespace */
132 glsl_to_nir(struct gl_shader
*sh
, const nir_shader_compiler_options
*options
)
134 nir_shader
*shader
= nir_shader_create(NULL
, sh
->Stage
, options
);
136 nir_visitor
v1(shader
);
137 nir_function_visitor
v2(&v1
);
139 visit_exec_list(sh
->ir
, &v1
);
141 nir_lower_outputs_to_temporaries(shader
);
143 shader
->gs
.vertices_out
= sh
->Geom
.VerticesOut
;
144 shader
->gs
.invocations
= sh
->Geom
.Invocations
;
149 nir_visitor::nir_visitor(nir_shader
*shader
)
151 this->supports_ints
= shader
->options
->native_integers
;
152 this->shader
= shader
;
153 this->is_global
= true;
154 this->var_table
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
155 _mesa_key_pointer_equal
);
156 this->overload_table
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
157 _mesa_key_pointer_equal
);
160 nir_visitor::~nir_visitor()
162 _mesa_hash_table_destroy(this->var_table
, NULL
);
163 _mesa_hash_table_destroy(this->overload_table
, NULL
);
167 nir_visitor::evaluate_deref(nir_instr
*mem_ctx
, ir_instruction
*ir
)
170 ralloc_steal(mem_ctx
, this->deref_head
);
171 return this->deref_head
;
174 static nir_constant
*
175 constant_copy(ir_constant
*ir
, void *mem_ctx
)
180 nir_constant
*ret
= ralloc(mem_ctx
, nir_constant
);
182 unsigned total_elems
= ir
->type
->components();
184 switch (ir
->type
->base_type
) {
186 for (i
= 0; i
< total_elems
; i
++)
187 ret
->value
.u
[i
] = ir
->value
.u
[i
];
191 for (i
= 0; i
< total_elems
; i
++)
192 ret
->value
.i
[i
] = ir
->value
.i
[i
];
195 case GLSL_TYPE_FLOAT
:
196 for (i
= 0; i
< total_elems
; i
++)
197 ret
->value
.f
[i
] = ir
->value
.f
[i
];
201 for (i
= 0; i
< total_elems
; i
++)
202 ret
->value
.b
[i
] = ir
->value
.b
[i
];
205 case GLSL_TYPE_STRUCT
:
206 ret
->elements
= ralloc_array(mem_ctx
, nir_constant
*,
209 foreach_in_list(ir_constant
, field
, &ir
->components
) {
210 ret
->elements
[i
] = constant_copy(field
, mem_ctx
);
215 case GLSL_TYPE_ARRAY
:
216 ret
->elements
= ralloc_array(mem_ctx
, nir_constant
*,
219 for (i
= 0; i
< ir
->type
->length
; i
++)
220 ret
->elements
[i
] = constant_copy(ir
->array_elements
[i
], mem_ctx
);
224 unreachable("not reached");
231 nir_visitor::visit(ir_variable
*ir
)
233 nir_variable
*var
= ralloc(shader
, nir_variable
);
234 var
->type
= ir
->type
;
235 var
->name
= ralloc_strdup(var
, ir
->name
);
237 if (ir
->is_interface_instance() && ir
->get_max_ifc_array_access() != NULL
) {
238 unsigned size
= ir
->get_interface_type()->length
;
239 var
->max_ifc_array_access
= ralloc_array(var
, unsigned, size
);
240 memcpy(var
->max_ifc_array_access
, ir
->get_max_ifc_array_access(),
241 size
* sizeof(unsigned));
243 var
->max_ifc_array_access
= NULL
;
246 var
->data
.read_only
= ir
->data
.read_only
;
247 var
->data
.centroid
= ir
->data
.centroid
;
248 var
->data
.sample
= ir
->data
.sample
;
249 var
->data
.invariant
= ir
->data
.invariant
;
250 var
->data
.location
= ir
->data
.location
;
252 switch(ir
->data
.mode
) {
254 case ir_var_temporary
:
256 var
->data
.mode
= nir_var_global
;
258 var
->data
.mode
= nir_var_local
;
261 case ir_var_function_in
:
262 case ir_var_function_out
:
263 case ir_var_function_inout
:
264 case ir_var_const_in
:
265 var
->data
.mode
= nir_var_local
;
268 case ir_var_shader_in
:
269 if (shader
->stage
== MESA_SHADER_FRAGMENT
&&
270 ir
->data
.location
== VARYING_SLOT_FACE
) {
271 /* For whatever reason, GLSL IR makes gl_FrontFacing an input */
272 var
->data
.location
= SYSTEM_VALUE_FRONT_FACE
;
273 var
->data
.mode
= nir_var_system_value
;
275 var
->data
.mode
= nir_var_shader_in
;
279 case ir_var_shader_out
:
280 var
->data
.mode
= nir_var_shader_out
;
284 var
->data
.mode
= nir_var_uniform
;
287 case ir_var_shader_storage
:
288 var
->data
.mode
= nir_var_shader_storage
;
291 case ir_var_system_value
:
292 var
->data
.mode
= nir_var_system_value
;
296 unreachable("not reached");
299 var
->data
.interpolation
= ir
->data
.interpolation
;
300 var
->data
.origin_upper_left
= ir
->data
.origin_upper_left
;
301 var
->data
.pixel_center_integer
= ir
->data
.pixel_center_integer
;
302 var
->data
.explicit_location
= ir
->data
.explicit_location
;
303 var
->data
.explicit_index
= ir
->data
.explicit_index
;
304 var
->data
.explicit_binding
= ir
->data
.explicit_binding
;
305 var
->data
.has_initializer
= ir
->data
.has_initializer
;
306 var
->data
.is_unmatched_generic_inout
= ir
->data
.is_unmatched_generic_inout
;
307 var
->data
.location_frac
= ir
->data
.location_frac
;
308 var
->data
.from_named_ifc_block_array
= ir
->data
.from_named_ifc_block_array
;
309 var
->data
.from_named_ifc_block_nonarray
= ir
->data
.from_named_ifc_block_nonarray
;
311 switch (ir
->data
.depth_layout
) {
312 case ir_depth_layout_none
:
313 var
->data
.depth_layout
= nir_depth_layout_none
;
315 case ir_depth_layout_any
:
316 var
->data
.depth_layout
= nir_depth_layout_any
;
318 case ir_depth_layout_greater
:
319 var
->data
.depth_layout
= nir_depth_layout_greater
;
321 case ir_depth_layout_less
:
322 var
->data
.depth_layout
= nir_depth_layout_less
;
324 case ir_depth_layout_unchanged
:
325 var
->data
.depth_layout
= nir_depth_layout_unchanged
;
328 unreachable("not reached");
331 var
->data
.index
= ir
->data
.index
;
332 var
->data
.binding
= ir
->data
.binding
;
333 /* XXX Get rid of buffer_index */
334 var
->data
.atomic
.buffer_index
= ir
->data
.binding
;
335 var
->data
.atomic
.offset
= ir
->data
.atomic
.offset
;
336 var
->data
.image
.read_only
= ir
->data
.image_read_only
;
337 var
->data
.image
.write_only
= ir
->data
.image_write_only
;
338 var
->data
.image
.coherent
= ir
->data
.image_coherent
;
339 var
->data
.image
._volatile
= ir
->data
.image_volatile
;
340 var
->data
.image
.restrict_flag
= ir
->data
.image_restrict
;
341 var
->data
.image
.format
= ir
->data
.image_format
;
342 var
->data
.max_array_access
= ir
->data
.max_array_access
;
344 var
->num_state_slots
= ir
->get_num_state_slots();
345 if (var
->num_state_slots
> 0) {
346 var
->state_slots
= ralloc_array(var
, nir_state_slot
,
347 var
->num_state_slots
);
349 ir_state_slot
*state_slots
= ir
->get_state_slots();
350 for (unsigned i
= 0; i
< var
->num_state_slots
; i
++) {
351 for (unsigned j
= 0; j
< 5; j
++)
352 var
->state_slots
[i
].tokens
[j
] = state_slots
[i
].tokens
[j
];
353 var
->state_slots
[i
].swizzle
= state_slots
[i
].swizzle
;
356 var
->state_slots
= NULL
;
359 var
->constant_initializer
= constant_copy(ir
->constant_initializer
, var
);
361 var
->interface_type
= ir
->get_interface_type();
363 switch (var
->data
.mode
) {
365 exec_list_push_tail(&impl
->locals
, &var
->node
);
369 exec_list_push_tail(&shader
->globals
, &var
->node
);
372 case nir_var_shader_in
:
373 exec_list_push_tail(&shader
->inputs
, &var
->node
);
376 case nir_var_shader_out
:
377 exec_list_push_tail(&shader
->outputs
, &var
->node
);
380 case nir_var_uniform
:
381 case nir_var_shader_storage
:
382 exec_list_push_tail(&shader
->uniforms
, &var
->node
);
385 case nir_var_system_value
:
386 exec_list_push_tail(&shader
->system_values
, &var
->node
);
390 unreachable("not reached");
393 _mesa_hash_table_insert(var_table
, ir
, var
);
398 nir_function_visitor::visit_enter(ir_function
*ir
)
400 visitor
->create_function(ir
);
401 return visit_continue_with_parent
;
406 nir_visitor::create_function(ir_function
*ir
)
408 nir_function
*func
= nir_function_create(this->shader
, ir
->name
);
409 foreach_in_list(ir_function_signature
, sig
, &ir
->signatures
) {
410 create_overload(sig
, func
);
417 nir_visitor::create_overload(ir_function_signature
*ir
, nir_function
*function
)
419 if (ir
->is_intrinsic
)
422 nir_function_overload
*overload
= nir_function_overload_create(function
);
424 unsigned num_params
= ir
->parameters
.length();
425 overload
->num_params
= num_params
;
426 overload
->params
= ralloc_array(shader
, nir_parameter
, num_params
);
429 foreach_in_list(ir_variable
, param
, &ir
->parameters
) {
430 switch (param
->data
.mode
) {
431 case ir_var_function_in
:
432 overload
->params
[i
].param_type
= nir_parameter_in
;
435 case ir_var_function_out
:
436 overload
->params
[i
].param_type
= nir_parameter_out
;
439 case ir_var_function_inout
:
440 overload
->params
[i
].param_type
= nir_parameter_inout
;
444 unreachable("not reached");
447 overload
->params
[i
].type
= param
->type
;
451 overload
->return_type
= ir
->return_type
;
453 _mesa_hash_table_insert(this->overload_table
, ir
, overload
);
457 nir_visitor::visit(ir_function
*ir
)
459 foreach_in_list(ir_function_signature
, sig
, &ir
->signatures
)
464 nir_visitor::visit(ir_function_signature
*ir
)
466 if (ir
->is_intrinsic
)
469 struct hash_entry
*entry
=
470 _mesa_hash_table_search(this->overload_table
, ir
);
473 nir_function_overload
*overload
= (nir_function_overload
*) entry
->data
;
475 if (ir
->is_defined
) {
476 nir_function_impl
*impl
= nir_function_impl_create(overload
);
479 unsigned num_params
= overload
->num_params
;
480 impl
->num_params
= num_params
;
481 impl
->params
= ralloc_array(this->shader
, nir_variable
*, num_params
);
483 foreach_in_list(ir_variable
, param
, &ir
->parameters
) {
485 impl
->params
[i
] = this->var
;
489 if (overload
->return_type
== glsl_type::void_type
) {
490 impl
->return_var
= NULL
;
492 impl
->return_var
= ralloc(this->shader
, nir_variable
);
493 impl
->return_var
->name
= ralloc_strdup(impl
->return_var
,
495 impl
->return_var
->type
= overload
->return_type
;
498 this->is_global
= false;
500 this->cf_node_list
= &impl
->body
;
501 visit_exec_list(&ir
->body
, this);
503 this->is_global
= true;
505 overload
->impl
= NULL
;
510 nir_visitor::visit(ir_loop
*ir
)
512 exec_list
*old_list
= this->cf_node_list
;
514 nir_loop
*loop
= nir_loop_create(this->shader
);
515 nir_cf_node_insert_end(old_list
, &loop
->cf_node
);
516 this->cf_node_list
= &loop
->body
;
517 visit_exec_list(&ir
->body_instructions
, this);
519 this->cf_node_list
= old_list
;
523 nir_visitor::visit(ir_if
*ir
)
525 nir_src condition
= evaluate_rvalue(ir
->condition
);
527 exec_list
*old_list
= this->cf_node_list
;
529 nir_if
*if_stmt
= nir_if_create(this->shader
);
530 if_stmt
->condition
= condition
;
531 nir_cf_node_insert_end(old_list
, &if_stmt
->cf_node
);
533 this->cf_node_list
= &if_stmt
->then_list
;
534 visit_exec_list(&ir
->then_instructions
, this);
536 this->cf_node_list
= &if_stmt
->else_list
;
537 visit_exec_list(&ir
->else_instructions
, this);
539 this->cf_node_list
= old_list
;
543 nir_visitor::visit(ir_discard
*ir
)
546 * discards aren't treated as control flow, because before we lower them
547 * they can appear anywhere in the shader and the stuff after them may still
548 * be executed (yay, crazy GLSL rules!). However, after lowering, all the
549 * discards will be immediately followed by a return.
552 nir_intrinsic_instr
*discard
;
554 discard
= nir_intrinsic_instr_create(this->shader
,
555 nir_intrinsic_discard_if
);
556 discard
->src
[0] = evaluate_rvalue(ir
->condition
);
558 discard
= nir_intrinsic_instr_create(this->shader
, nir_intrinsic_discard
);
560 nir_instr_insert_after_cf_list(this->cf_node_list
, &discard
->instr
);
564 nir_visitor::visit(ir_emit_vertex
*ir
)
566 nir_intrinsic_instr
*instr
=
567 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_emit_vertex
);
568 instr
->const_index
[0] = ir
->stream_id();
569 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
573 nir_visitor::visit(ir_end_primitive
*ir
)
575 nir_intrinsic_instr
*instr
=
576 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_end_primitive
);
577 instr
->const_index
[0] = ir
->stream_id();
578 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
582 nir_visitor::visit(ir_loop_jump
*ir
)
586 case ir_loop_jump::jump_break
:
587 type
= nir_jump_break
;
589 case ir_loop_jump::jump_continue
:
590 type
= nir_jump_continue
;
593 unreachable("not reached");
596 nir_jump_instr
*instr
= nir_jump_instr_create(this->shader
, type
);
597 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
601 nir_visitor::visit(ir_return
*ir
)
603 if (ir
->value
!= NULL
) {
604 nir_intrinsic_instr
*copy
=
605 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_copy_var
);
607 copy
->variables
[0] = nir_deref_var_create(copy
, this->impl
->return_var
);
608 copy
->variables
[1] = evaluate_deref(©
->instr
, ir
->value
);
611 nir_jump_instr
*instr
= nir_jump_instr_create(this->shader
, nir_jump_return
);
612 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
616 nir_visitor::visit(ir_call
*ir
)
618 if (ir
->callee
->is_intrinsic
) {
620 if (strcmp(ir
->callee_name(), "__intrinsic_atomic_read") == 0) {
621 op
= nir_intrinsic_atomic_counter_read_var
;
622 } else if (strcmp(ir
->callee_name(), "__intrinsic_atomic_increment") == 0) {
623 op
= nir_intrinsic_atomic_counter_inc_var
;
624 } else if (strcmp(ir
->callee_name(), "__intrinsic_atomic_predecrement") == 0) {
625 op
= nir_intrinsic_atomic_counter_dec_var
;
626 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_load") == 0) {
627 op
= nir_intrinsic_image_load
;
628 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_store") == 0) {
629 op
= nir_intrinsic_image_store
;
630 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_add") == 0) {
631 op
= nir_intrinsic_image_atomic_add
;
632 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_min") == 0) {
633 op
= nir_intrinsic_image_atomic_min
;
634 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_max") == 0) {
635 op
= nir_intrinsic_image_atomic_max
;
636 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_and") == 0) {
637 op
= nir_intrinsic_image_atomic_and
;
638 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_or") == 0) {
639 op
= nir_intrinsic_image_atomic_or
;
640 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_xor") == 0) {
641 op
= nir_intrinsic_image_atomic_xor
;
642 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_exchange") == 0) {
643 op
= nir_intrinsic_image_atomic_exchange
;
644 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_atomic_comp_swap") == 0) {
645 op
= nir_intrinsic_image_atomic_comp_swap
;
646 } else if (strcmp(ir
->callee_name(), "__intrinsic_memory_barrier") == 0) {
647 op
= nir_intrinsic_memory_barrier
;
648 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_size") == 0) {
649 op
= nir_intrinsic_image_size
;
650 } else if (strcmp(ir
->callee_name(), "__intrinsic_image_samples") == 0) {
651 op
= nir_intrinsic_image_samples
;
652 } else if (strcmp(ir
->callee_name(), "__intrinsic_store_ssbo") == 0) {
653 op
= nir_intrinsic_store_ssbo
;
654 } else if (strcmp(ir
->callee_name(), "__intrinsic_load_ssbo") == 0) {
655 op
= nir_intrinsic_load_ssbo
;
657 unreachable("not reached");
660 nir_intrinsic_instr
*instr
= nir_intrinsic_instr_create(shader
, op
);
661 nir_dest
*dest
= &instr
->dest
;
664 case nir_intrinsic_atomic_counter_read_var
:
665 case nir_intrinsic_atomic_counter_inc_var
:
666 case nir_intrinsic_atomic_counter_dec_var
: {
667 ir_dereference
*param
=
668 (ir_dereference
*) ir
->actual_parameters
.get_head();
669 instr
->variables
[0] = evaluate_deref(&instr
->instr
, param
);
670 nir_ssa_dest_init(&instr
->instr
, &instr
->dest
, 1, NULL
);
671 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
674 case nir_intrinsic_image_load
:
675 case nir_intrinsic_image_store
:
676 case nir_intrinsic_image_atomic_add
:
677 case nir_intrinsic_image_atomic_min
:
678 case nir_intrinsic_image_atomic_max
:
679 case nir_intrinsic_image_atomic_and
:
680 case nir_intrinsic_image_atomic_or
:
681 case nir_intrinsic_image_atomic_xor
:
682 case nir_intrinsic_image_atomic_exchange
:
683 case nir_intrinsic_image_atomic_comp_swap
:
684 case nir_intrinsic_image_samples
:
685 case nir_intrinsic_image_size
: {
686 nir_ssa_undef_instr
*instr_undef
=
687 nir_ssa_undef_instr_create(shader
, 1);
688 nir_instr_insert_after_cf_list(this->cf_node_list
,
689 &instr_undef
->instr
);
691 /* Set the image variable dereference. */
692 exec_node
*param
= ir
->actual_parameters
.get_head();
693 ir_dereference
*image
= (ir_dereference
*)param
;
694 const glsl_type
*type
=
695 image
->variable_referenced()->type
->without_array();
697 instr
->variables
[0] = evaluate_deref(&instr
->instr
, image
);
698 param
= param
->get_next();
700 /* Set the intrinsic destination. */
701 if (ir
->return_deref
) {
702 const nir_intrinsic_info
*info
=
703 &nir_intrinsic_infos
[instr
->intrinsic
];
704 nir_ssa_dest_init(&instr
->instr
, &instr
->dest
,
705 info
->dest_components
, NULL
);
708 if (op
== nir_intrinsic_image_size
||
709 op
== nir_intrinsic_image_samples
) {
710 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
714 /* Set the address argument, extending the coordinate vector to four
717 const nir_src src_addr
= evaluate_rvalue((ir_dereference
*)param
);
718 nir_alu_instr
*instr_addr
= nir_alu_instr_create(shader
, nir_op_vec4
);
719 nir_ssa_dest_init(&instr_addr
->instr
, &instr_addr
->dest
.dest
, 4, NULL
);
721 for (int i
= 0; i
< 4; i
++) {
722 if (i
< type
->coordinate_components()) {
723 instr_addr
->src
[i
].src
= src_addr
;
724 instr_addr
->src
[i
].swizzle
[0] = i
;
726 instr_addr
->src
[i
].src
= nir_src_for_ssa(&instr_undef
->def
);
730 nir_instr_insert_after_cf_list(cf_node_list
, &instr_addr
->instr
);
731 instr
->src
[0] = nir_src_for_ssa(&instr_addr
->dest
.dest
.ssa
);
732 param
= param
->get_next();
734 /* Set the sample argument, which is undefined for single-sample
737 if (type
->sampler_dimensionality
== GLSL_SAMPLER_DIM_MS
) {
738 instr
->src
[1] = evaluate_rvalue((ir_dereference
*)param
);
739 param
= param
->get_next();
741 instr
->src
[1] = nir_src_for_ssa(&instr_undef
->def
);
744 /* Set the intrinsic parameters. */
745 if (!param
->is_tail_sentinel()) {
746 instr
->src
[2] = evaluate_rvalue((ir_dereference
*)param
);
747 param
= param
->get_next();
750 if (!param
->is_tail_sentinel()) {
751 instr
->src
[3] = evaluate_rvalue((ir_dereference
*)param
);
752 param
= param
->get_next();
754 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
757 case nir_intrinsic_memory_barrier
:
758 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
760 case nir_intrinsic_store_ssbo
: {
761 exec_node
*param
= ir
->actual_parameters
.get_head();
762 ir_rvalue
*block
= ((ir_instruction
*)param
)->as_rvalue();
764 param
= param
->get_next();
765 ir_rvalue
*offset
= ((ir_instruction
*)param
)->as_rvalue();
767 param
= param
->get_next();
768 ir_rvalue
*val
= ((ir_instruction
*)param
)->as_rvalue();
770 param
= param
->get_next();
771 ir_constant
*write_mask
= ((ir_instruction
*)param
)->as_constant();
774 /* Check if we need the indirect version */
775 ir_constant
*const_offset
= offset
->as_constant();
777 op
= nir_intrinsic_store_ssbo_indirect
;
779 instr
= nir_intrinsic_instr_create(shader
, op
);
780 instr
->src
[2] = evaluate_rvalue(offset
);
781 instr
->const_index
[0] = 0;
784 instr
->const_index
[0] = const_offset
->value
.u
[0];
787 instr
->const_index
[1] = write_mask
->value
.u
[0];
789 instr
->src
[0] = evaluate_rvalue(val
);
790 instr
->num_components
= val
->type
->vector_elements
;
792 instr
->src
[1] = evaluate_rvalue(block
);
793 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
796 case nir_intrinsic_load_ssbo
: {
797 exec_node
*param
= ir
->actual_parameters
.get_head();
798 ir_rvalue
*block
= ((ir_instruction
*)param
)->as_rvalue();
800 param
= param
->get_next();
801 ir_rvalue
*offset
= ((ir_instruction
*)param
)->as_rvalue();
803 /* Check if we need the indirect version */
804 ir_constant
*const_offset
= offset
->as_constant();
806 op
= nir_intrinsic_load_ssbo_indirect
;
808 instr
= nir_intrinsic_instr_create(shader
, op
);
809 instr
->src
[1] = evaluate_rvalue(offset
);
810 instr
->const_index
[0] = 0;
813 instr
->const_index
[0] = const_offset
->value
.u
[0];
816 instr
->src
[0] = evaluate_rvalue(block
);
818 const glsl_type
*type
= ir
->return_deref
->var
->type
;
819 instr
->num_components
= type
->vector_elements
;
821 /* Setup destination register */
822 nir_ssa_dest_init(&instr
->instr
, &instr
->dest
,
823 type
->vector_elements
, NULL
);
825 /* Insert the created nir instruction now since in the case of boolean
826 * result we will need to emit another instruction after it
828 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
831 * In SSBO/UBO's, a true boolean value is any non-zero value, but we
832 * consider a true boolean to be ~0. Fix this up with a != 0
835 if (type
->base_type
== GLSL_TYPE_BOOL
) {
836 nir_load_const_instr
*const_zero
=
837 nir_load_const_instr_create(shader
, 1);
838 const_zero
->value
.u
[0] = 0;
839 nir_instr_insert_after_cf_list(this->cf_node_list
,
842 nir_alu_instr
*load_ssbo_compare
=
843 nir_alu_instr_create(shader
, nir_op_ine
);
844 load_ssbo_compare
->src
[0].src
.is_ssa
= true;
845 load_ssbo_compare
->src
[0].src
.ssa
= &instr
->dest
.ssa
;
846 load_ssbo_compare
->src
[1].src
.is_ssa
= true;
847 load_ssbo_compare
->src
[1].src
.ssa
= &const_zero
->def
;
848 for (unsigned i
= 0; i
< type
->vector_elements
; i
++)
849 load_ssbo_compare
->src
[1].swizzle
[i
] = 0;
850 nir_ssa_dest_init(&load_ssbo_compare
->instr
,
851 &load_ssbo_compare
->dest
.dest
,
852 type
->vector_elements
, NULL
);
853 load_ssbo_compare
->dest
.write_mask
= (1 << type
->vector_elements
) - 1;
854 nir_instr_insert_after_cf_list(this->cf_node_list
,
855 &load_ssbo_compare
->instr
);
856 dest
= &load_ssbo_compare
->dest
.dest
;
862 unreachable("not reached");
865 if (ir
->return_deref
) {
866 nir_intrinsic_instr
*store_instr
=
867 nir_intrinsic_instr_create(shader
, nir_intrinsic_store_var
);
868 store_instr
->num_components
= ir
->return_deref
->type
->vector_elements
;
870 store_instr
->variables
[0] =
871 evaluate_deref(&store_instr
->instr
, ir
->return_deref
);
872 store_instr
->src
[0] = nir_src_for_ssa(&dest
->ssa
);
874 nir_instr_insert_after_cf_list(this->cf_node_list
,
875 &store_instr
->instr
);
881 struct hash_entry
*entry
=
882 _mesa_hash_table_search(this->overload_table
, ir
->callee
);
884 nir_function_overload
*callee
= (nir_function_overload
*) entry
->data
;
886 nir_call_instr
*instr
= nir_call_instr_create(this->shader
, callee
);
889 foreach_in_list(ir_dereference
, param
, &ir
->actual_parameters
) {
890 instr
->params
[i
] = evaluate_deref(&instr
->instr
, param
);
894 instr
->return_deref
= evaluate_deref(&instr
->instr
, ir
->return_deref
);
895 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);
899 nir_visitor::visit(ir_assignment
*ir
)
901 unsigned num_components
= ir
->lhs
->type
->vector_elements
;
903 if ((ir
->rhs
->as_dereference() || ir
->rhs
->as_constant()) &&
904 (ir
->write_mask
== (1 << num_components
) - 1 || ir
->write_mask
== 0)) {
905 /* We're doing a plain-as-can-be copy, so emit a copy_var */
906 nir_intrinsic_instr
*copy
=
907 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_copy_var
);
909 copy
->variables
[0] = evaluate_deref(©
->instr
, ir
->lhs
);
910 copy
->variables
[1] = evaluate_deref(©
->instr
, ir
->rhs
);
913 nir_if
*if_stmt
= nir_if_create(this->shader
);
914 if_stmt
->condition
= evaluate_rvalue(ir
->condition
);
915 nir_cf_node_insert_end(this->cf_node_list
, &if_stmt
->cf_node
);
916 nir_instr_insert_after_cf_list(&if_stmt
->then_list
, ©
->instr
);
918 nir_instr_insert_after_cf_list(this->cf_node_list
, ©
->instr
);
923 assert(ir
->rhs
->type
->is_scalar() || ir
->rhs
->type
->is_vector());
925 ir
->lhs
->accept(this);
926 nir_deref_var
*lhs_deref
= this->deref_head
;
927 nir_src src
= evaluate_rvalue(ir
->rhs
);
929 if (ir
->write_mask
!= (1 << num_components
) - 1 && ir
->write_mask
!= 0) {
931 * We have no good way to update only part of a variable, so just load
932 * the LHS and do a vec operation to combine the old with the new, and
934 * back into the LHS. Copy propagation should get rid of the mess.
937 nir_intrinsic_instr
*load
=
938 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_load_var
);
939 load
->num_components
= ir
->lhs
->type
->vector_elements
;
940 nir_ssa_dest_init(&load
->instr
, &load
->dest
, num_components
, NULL
);
941 load
->variables
[0] = lhs_deref
;
942 ralloc_steal(load
, load
->variables
[0]);
943 nir_instr_insert_after_cf_list(this->cf_node_list
, &load
->instr
);
946 switch (ir
->lhs
->type
->vector_elements
) {
947 case 1: vec_op
= nir_op_imov
; break;
948 case 2: vec_op
= nir_op_vec2
; break;
949 case 3: vec_op
= nir_op_vec3
; break;
950 case 4: vec_op
= nir_op_vec4
; break;
951 default: unreachable("Invalid number of components"); break;
953 nir_alu_instr
*vec
= nir_alu_instr_create(this->shader
, vec_op
);
954 nir_ssa_dest_init(&vec
->instr
, &vec
->dest
.dest
, num_components
, NULL
);
955 vec
->dest
.write_mask
= (1 << num_components
) - 1;
957 unsigned component
= 0;
958 for (unsigned i
= 0; i
< ir
->lhs
->type
->vector_elements
; i
++) {
959 if (ir
->write_mask
& (1 << i
)) {
960 vec
->src
[i
].src
= src
;
962 /* GLSL IR will give us the input to the write-masked assignment
963 * in a single packed vector. So, for example, if the
964 * writemask is xzw, then we have to swizzle x -> x, y -> z,
965 * and z -> w and get the y component from the load.
967 vec
->src
[i
].swizzle
[0] = component
++;
969 vec
->src
[i
].src
.is_ssa
= true;
970 vec
->src
[i
].src
.ssa
= &load
->dest
.ssa
;
971 vec
->src
[i
].swizzle
[0] = i
;
975 nir_instr_insert_after_cf_list(this->cf_node_list
, &vec
->instr
);
978 src
.ssa
= &vec
->dest
.dest
.ssa
;
981 nir_intrinsic_instr
*store
=
982 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_store_var
);
983 store
->num_components
= ir
->lhs
->type
->vector_elements
;
984 nir_deref
*store_deref
= nir_copy_deref(store
, &lhs_deref
->deref
);
985 store
->variables
[0] = nir_deref_as_var(store_deref
);
989 nir_if
*if_stmt
= nir_if_create(this->shader
);
990 if_stmt
->condition
= evaluate_rvalue(ir
->condition
);
991 nir_cf_node_insert_end(this->cf_node_list
, &if_stmt
->cf_node
);
992 nir_instr_insert_after_cf_list(&if_stmt
->then_list
, &store
->instr
);
994 nir_instr_insert_after_cf_list(this->cf_node_list
, &store
->instr
);
999 * Given an instruction, returns a pointer to its destination or NULL if there
1000 * is no destination.
1002 * Note that this only handles instructions we generate at this level.
1005 get_instr_dest(nir_instr
*instr
)
1007 nir_alu_instr
*alu_instr
;
1008 nir_intrinsic_instr
*intrinsic_instr
;
1009 nir_tex_instr
*tex_instr
;
1011 switch (instr
->type
) {
1012 case nir_instr_type_alu
:
1013 alu_instr
= nir_instr_as_alu(instr
);
1014 return &alu_instr
->dest
.dest
;
1016 case nir_instr_type_intrinsic
:
1017 intrinsic_instr
= nir_instr_as_intrinsic(instr
);
1018 if (nir_intrinsic_infos
[intrinsic_instr
->intrinsic
].has_dest
)
1019 return &intrinsic_instr
->dest
;
1023 case nir_instr_type_tex
:
1024 tex_instr
= nir_instr_as_tex(instr
);
1025 return &tex_instr
->dest
;
1028 unreachable("not reached");
1035 nir_visitor::add_instr(nir_instr
*instr
, unsigned num_components
)
1037 nir_dest
*dest
= get_instr_dest(instr
);
1040 nir_ssa_dest_init(instr
, dest
, num_components
, NULL
);
1042 nir_instr_insert_after_cf_list(this->cf_node_list
, instr
);
1043 this->result
= instr
;
1047 nir_visitor::evaluate_rvalue(ir_rvalue
* ir
)
1050 if (ir
->as_dereference() || ir
->as_constant()) {
1052 * A dereference is being used on the right hand side, which means we
1053 * must emit a variable load.
1056 nir_intrinsic_instr
*load_instr
=
1057 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_load_var
);
1058 load_instr
->num_components
= ir
->type
->vector_elements
;
1059 load_instr
->variables
[0] = this->deref_head
;
1060 ralloc_steal(load_instr
, load_instr
->variables
[0]);
1061 add_instr(&load_instr
->instr
, ir
->type
->vector_elements
);
1064 nir_dest
*dest
= get_instr_dest(this->result
);
1065 assert(dest
->is_ssa
);
1067 return nir_src_for_ssa(&dest
->ssa
);
1071 nir_visitor::emit(nir_op op
, unsigned dest_size
, nir_src
*srcs
)
1073 nir_alu_instr
*instr
= nir_alu_instr_create(this->shader
, op
);
1074 for (unsigned i
= 0; i
< nir_op_infos
[op
].num_inputs
; i
++)
1075 instr
->src
[i
].src
= srcs
[i
];
1076 instr
->dest
.write_mask
= (1 << dest_size
) - 1;
1077 add_instr(&instr
->instr
, dest_size
);
1082 nir_visitor::emit(nir_op op
, unsigned dest_size
, nir_src src1
)
1084 assert(nir_op_infos
[op
].num_inputs
== 1);
1085 return emit(op
, dest_size
, &src1
);
1089 nir_visitor::emit(nir_op op
, unsigned dest_size
, nir_src src1
,
1092 assert(nir_op_infos
[op
].num_inputs
== 2);
1093 nir_src srcs
[] = { src1
, src2
};
1094 return emit(op
, dest_size
, srcs
);
1098 nir_visitor::emit(nir_op op
, unsigned dest_size
, nir_src src1
,
1099 nir_src src2
, nir_src src3
)
1101 assert(nir_op_infos
[op
].num_inputs
== 3);
1102 nir_src srcs
[] = { src1
, src2
, src3
};
1103 return emit(op
, dest_size
, srcs
);
1107 nir_visitor::visit(ir_expression
*ir
)
1109 /* Some special cases */
1110 switch (ir
->operation
) {
1111 case ir_binop_ubo_load
: {
1112 ir_constant
*const_index
= ir
->operands
[1]->as_constant();
1114 nir_intrinsic_op op
;
1116 op
= nir_intrinsic_load_ubo
;
1118 op
= nir_intrinsic_load_ubo_indirect
;
1120 nir_intrinsic_instr
*load
= nir_intrinsic_instr_create(this->shader
, op
);
1121 load
->num_components
= ir
->type
->vector_elements
;
1122 load
->const_index
[0] = const_index
? const_index
->value
.u
[0] : 0; /* base offset */
1123 load
->src
[0] = evaluate_rvalue(ir
->operands
[0]);
1125 load
->src
[1] = evaluate_rvalue(ir
->operands
[1]);
1126 add_instr(&load
->instr
, ir
->type
->vector_elements
);
1129 * In UBO's, a true boolean value is any non-zero value, but we consider
1130 * a true boolean to be ~0. Fix this up with a != 0 comparison.
1133 if (ir
->type
->base_type
== GLSL_TYPE_BOOL
) {
1134 nir_load_const_instr
*const_zero
= nir_load_const_instr_create(shader
, 1);
1135 const_zero
->value
.u
[0] = 0;
1136 nir_instr_insert_after_cf_list(this->cf_node_list
, &const_zero
->instr
);
1138 nir_alu_instr
*compare
= nir_alu_instr_create(shader
, nir_op_ine
);
1139 compare
->src
[0].src
.is_ssa
= true;
1140 compare
->src
[0].src
.ssa
= &load
->dest
.ssa
;
1141 compare
->src
[1].src
.is_ssa
= true;
1142 compare
->src
[1].src
.ssa
= &const_zero
->def
;
1143 for (unsigned i
= 0; i
< ir
->type
->vector_elements
; i
++)
1144 compare
->src
[1].swizzle
[i
] = 0;
1145 compare
->dest
.write_mask
= (1 << ir
->type
->vector_elements
) - 1;
1147 add_instr(&compare
->instr
, ir
->type
->vector_elements
);
1153 case ir_unop_interpolate_at_centroid
:
1154 case ir_binop_interpolate_at_offset
:
1155 case ir_binop_interpolate_at_sample
: {
1156 ir_dereference
*deref
= ir
->operands
[0]->as_dereference();
1157 ir_swizzle
*swizzle
= NULL
;
1159 /* the api does not allow a swizzle here, but the varying packing code
1160 * may have pushed one into here.
1162 swizzle
= ir
->operands
[0]->as_swizzle();
1164 deref
= swizzle
->val
->as_dereference();
1168 deref
->accept(this);
1170 nir_intrinsic_op op
;
1171 if (this->deref_head
->var
->data
.mode
== nir_var_shader_in
) {
1172 switch (ir
->operation
) {
1173 case ir_unop_interpolate_at_centroid
:
1174 op
= nir_intrinsic_interp_var_at_centroid
;
1176 case ir_binop_interpolate_at_offset
:
1177 op
= nir_intrinsic_interp_var_at_offset
;
1179 case ir_binop_interpolate_at_sample
:
1180 op
= nir_intrinsic_interp_var_at_sample
;
1183 unreachable("Invalid interpolation intrinsic");
1186 /* This case can happen if the vertex shader does not write the
1187 * given varying. In this case, the linker will lower it to a
1188 * global variable. Since interpolating a variable makes no
1189 * sense, we'll just turn it into a load which will probably
1190 * eventually end up as an SSA definition.
1192 assert(this->deref_head
->var
->data
.mode
== nir_var_global
);
1193 op
= nir_intrinsic_load_var
;
1196 nir_intrinsic_instr
*intrin
= nir_intrinsic_instr_create(shader
, op
);
1197 intrin
->num_components
= deref
->type
->vector_elements
;
1198 intrin
->variables
[0] = this->deref_head
;
1199 ralloc_steal(intrin
, intrin
->variables
[0]);
1201 if (intrin
->intrinsic
== nir_intrinsic_interp_var_at_offset
||
1202 intrin
->intrinsic
== nir_intrinsic_interp_var_at_sample
)
1203 intrin
->src
[0] = evaluate_rvalue(ir
->operands
[1]);
1205 add_instr(&intrin
->instr
, deref
->type
->vector_elements
);
1208 nir_alu_instr
*mov
= nir_alu_instr_create(shader
, nir_op_imov
);
1209 mov
->dest
.write_mask
= (1 << swizzle
->type
->vector_elements
) - 1;
1210 mov
->src
[0].src
.is_ssa
= true;
1211 mov
->src
[0].src
.ssa
= &intrin
->dest
.ssa
;
1213 mov
->src
[0].swizzle
[0] = swizzle
->mask
.x
;
1214 mov
->src
[0].swizzle
[1] = swizzle
->mask
.y
;
1215 mov
->src
[0].swizzle
[2] = swizzle
->mask
.z
;
1216 mov
->src
[0].swizzle
[3] = swizzle
->mask
.w
;
1217 for (unsigned i
= deref
->type
->vector_elements
; i
< 4; i
++)
1218 mov
->src
[0].swizzle
[i
] = 0;
1220 add_instr(&mov
->instr
, swizzle
->type
->vector_elements
);
1231 for (unsigned i
= 0; i
< ir
->get_num_operands(); i
++)
1232 srcs
[i
] = evaluate_rvalue(ir
->operands
[i
]);
1234 glsl_base_type types
[4];
1235 for (unsigned i
= 0; i
< ir
->get_num_operands(); i
++)
1237 types
[i
] = ir
->operands
[i
]->type
->base_type
;
1239 types
[i
] = GLSL_TYPE_FLOAT
;
1241 glsl_base_type out_type
;
1243 out_type
= ir
->type
->base_type
;
1245 out_type
= GLSL_TYPE_FLOAT
;
1247 unsigned dest_size
= ir
->type
->vector_elements
;
1249 nir_alu_instr
*instr
;
1252 switch (ir
->operation
) {
1253 case ir_unop_bit_not
: emit(nir_op_inot
, dest_size
, srcs
); break;
1254 case ir_unop_logic_not
:
1255 emit(supports_ints
? nir_op_inot
: nir_op_fnot
, dest_size
, srcs
);
1258 instr
= emit(types
[0] == GLSL_TYPE_FLOAT
? nir_op_fneg
: nir_op_ineg
,
1262 instr
= emit(types
[0] == GLSL_TYPE_FLOAT
? nir_op_fabs
: nir_op_iabs
,
1265 case ir_unop_saturate
:
1266 assert(types
[0] == GLSL_TYPE_FLOAT
);
1267 instr
= emit(nir_op_fsat
, dest_size
, srcs
);
1270 emit(types
[0] == GLSL_TYPE_FLOAT
? nir_op_fsign
: nir_op_isign
,
1273 case ir_unop_rcp
: emit(nir_op_frcp
, dest_size
, srcs
); break;
1274 case ir_unop_rsq
: emit(nir_op_frsq
, dest_size
, srcs
); break;
1275 case ir_unop_sqrt
: emit(nir_op_fsqrt
, dest_size
, srcs
); break;
1276 case ir_unop_exp
: unreachable("ir_unop_exp should have been lowered");
1277 case ir_unop_log
: unreachable("ir_unop_log should have been lowered");
1278 case ir_unop_exp2
: emit(nir_op_fexp2
, dest_size
, srcs
); break;
1279 case ir_unop_log2
: emit(nir_op_flog2
, dest_size
, srcs
); break;
1281 emit(supports_ints
? nir_op_i2f
: nir_op_fmov
, dest_size
, srcs
);
1284 emit(supports_ints
? nir_op_u2f
: nir_op_fmov
, dest_size
, srcs
);
1287 emit(supports_ints
? nir_op_b2f
: nir_op_fmov
, dest_size
, srcs
);
1289 case ir_unop_f2i
: emit(nir_op_f2i
, dest_size
, srcs
); break;
1290 case ir_unop_f2u
: emit(nir_op_f2u
, dest_size
, srcs
); break;
1291 case ir_unop_f2b
: emit(nir_op_f2b
, dest_size
, srcs
); break;
1292 case ir_unop_i2b
: emit(nir_op_i2b
, dest_size
, srcs
); break;
1293 case ir_unop_b2i
: emit(nir_op_b2i
, dest_size
, srcs
); break;
1296 case ir_unop_bitcast_i2f
:
1297 case ir_unop_bitcast_f2i
:
1298 case ir_unop_bitcast_u2f
:
1299 case ir_unop_bitcast_f2u
:
1300 case ir_unop_subroutine_to_int
:
1302 emit(nir_op_imov
, dest_size
, srcs
);
1305 switch (ir
->operands
[0]->type
->vector_elements
) {
1307 emit(supports_ints
? nir_op_bany2
: nir_op_fany2
,
1311 emit(supports_ints
? nir_op_bany3
: nir_op_fany3
,
1315 emit(supports_ints
? nir_op_bany4
: nir_op_fany4
,
1319 unreachable("not reached");
1322 case ir_unop_trunc
: emit(nir_op_ftrunc
, dest_size
, srcs
); break;
1323 case ir_unop_ceil
: emit(nir_op_fceil
, dest_size
, srcs
); break;
1324 case ir_unop_floor
: emit(nir_op_ffloor
, dest_size
, srcs
); break;
1325 case ir_unop_fract
: emit(nir_op_ffract
, dest_size
, srcs
); break;
1326 case ir_unop_round_even
: emit(nir_op_fround_even
, dest_size
, srcs
); break;
1327 case ir_unop_sin
: emit(nir_op_fsin
, dest_size
, srcs
); break;
1328 case ir_unop_cos
: emit(nir_op_fcos
, dest_size
, srcs
); break;
1329 case ir_unop_dFdx
: emit(nir_op_fddx
, dest_size
, srcs
); break;
1330 case ir_unop_dFdy
: emit(nir_op_fddy
, dest_size
, srcs
); break;
1331 case ir_unop_dFdx_fine
: emit(nir_op_fddx_fine
, dest_size
, srcs
); break;
1332 case ir_unop_dFdy_fine
: emit(nir_op_fddy_fine
, dest_size
, srcs
); break;
1333 case ir_unop_dFdx_coarse
: emit(nir_op_fddx_coarse
, dest_size
, srcs
); break;
1334 case ir_unop_dFdy_coarse
: emit(nir_op_fddy_coarse
, dest_size
, srcs
); break;
1335 case ir_unop_pack_snorm_2x16
:
1336 emit(nir_op_pack_snorm_2x16
, dest_size
, srcs
);
1338 case ir_unop_pack_snorm_4x8
:
1339 emit(nir_op_pack_snorm_4x8
, dest_size
, srcs
);
1341 case ir_unop_pack_unorm_2x16
:
1342 emit(nir_op_pack_unorm_2x16
, dest_size
, srcs
);
1344 case ir_unop_pack_unorm_4x8
:
1345 emit(nir_op_pack_unorm_4x8
, dest_size
, srcs
);
1347 case ir_unop_pack_half_2x16
:
1348 emit(nir_op_pack_half_2x16
, dest_size
, srcs
);
1350 case ir_unop_unpack_snorm_2x16
:
1351 emit(nir_op_unpack_snorm_2x16
, dest_size
, srcs
);
1353 case ir_unop_unpack_snorm_4x8
:
1354 emit(nir_op_unpack_snorm_4x8
, dest_size
, srcs
);
1356 case ir_unop_unpack_unorm_2x16
:
1357 emit(nir_op_unpack_unorm_2x16
, dest_size
, srcs
);
1359 case ir_unop_unpack_unorm_4x8
:
1360 emit(nir_op_unpack_unorm_4x8
, dest_size
, srcs
);
1362 case ir_unop_unpack_half_2x16
:
1363 emit(nir_op_unpack_half_2x16
, dest_size
, srcs
);
1365 case ir_unop_unpack_half_2x16_split_x
:
1366 emit(nir_op_unpack_half_2x16_split_x
, dest_size
, srcs
);
1368 case ir_unop_unpack_half_2x16_split_y
:
1369 emit(nir_op_unpack_half_2x16_split_y
, dest_size
, srcs
);
1371 case ir_unop_bitfield_reverse
:
1372 emit(nir_op_bitfield_reverse
, dest_size
, srcs
);
1374 case ir_unop_bit_count
:
1375 emit(nir_op_bit_count
, dest_size
, srcs
);
1377 case ir_unop_find_msb
:
1379 case GLSL_TYPE_UINT
:
1380 emit(nir_op_ufind_msb
, dest_size
, srcs
);
1383 emit(nir_op_ifind_msb
, dest_size
, srcs
);
1386 unreachable("Invalid type for findMSB()");
1389 case ir_unop_find_lsb
:
1390 emit(nir_op_find_lsb
, dest_size
, srcs
);
1394 switch (ir
->type
->vector_elements
) {
1396 switch (ir
->operands
[0]->type
->vector_elements
) {
1397 case 1: emit(nir_op_fnoise1_1
, dest_size
, srcs
); break;
1398 case 2: emit(nir_op_fnoise1_2
, dest_size
, srcs
); break;
1399 case 3: emit(nir_op_fnoise1_3
, dest_size
, srcs
); break;
1400 case 4: emit(nir_op_fnoise1_4
, dest_size
, srcs
); break;
1401 default: unreachable("not reached");
1405 switch (ir
->operands
[0]->type
->vector_elements
) {
1406 case 1: emit(nir_op_fnoise2_1
, dest_size
, srcs
); break;
1407 case 2: emit(nir_op_fnoise2_2
, dest_size
, srcs
); break;
1408 case 3: emit(nir_op_fnoise2_3
, dest_size
, srcs
); break;
1409 case 4: emit(nir_op_fnoise2_4
, dest_size
, srcs
); break;
1410 default: unreachable("not reached");
1414 switch (ir
->operands
[0]->type
->vector_elements
) {
1415 case 1: emit(nir_op_fnoise3_1
, dest_size
, srcs
); break;
1416 case 2: emit(nir_op_fnoise3_2
, dest_size
, srcs
); break;
1417 case 3: emit(nir_op_fnoise3_3
, dest_size
, srcs
); break;
1418 case 4: emit(nir_op_fnoise3_4
, dest_size
, srcs
); break;
1419 default: unreachable("not reached");
1423 switch (ir
->operands
[0]->type
->vector_elements
) {
1424 case 1: emit(nir_op_fnoise4_1
, dest_size
, srcs
); break;
1425 case 2: emit(nir_op_fnoise4_2
, dest_size
, srcs
); break;
1426 case 3: emit(nir_op_fnoise4_3
, dest_size
, srcs
); break;
1427 case 4: emit(nir_op_fnoise4_4
, dest_size
, srcs
); break;
1428 default: unreachable("not reached");
1432 unreachable("not reached");
1435 case ir_unop_get_buffer_size
: {
1436 nir_intrinsic_instr
*load
= nir_intrinsic_instr_create(
1438 nir_intrinsic_get_buffer_size
);
1439 load
->num_components
= ir
->type
->vector_elements
;
1440 load
->src
[0] = evaluate_rvalue(ir
->operands
[0]);
1441 add_instr(&load
->instr
, ir
->type
->vector_elements
);
1453 case ir_binop_bit_and
:
1454 case ir_binop_bit_or
:
1455 case ir_binop_bit_xor
:
1456 case ir_binop_logic_and
:
1457 case ir_binop_logic_or
:
1458 case ir_binop_logic_xor
:
1459 case ir_binop_lshift
:
1460 case ir_binop_rshift
:
1461 switch (ir
->operation
) {
1463 if (out_type
== GLSL_TYPE_FLOAT
)
1469 if (out_type
== GLSL_TYPE_FLOAT
)
1475 if (out_type
== GLSL_TYPE_FLOAT
)
1481 if (out_type
== GLSL_TYPE_FLOAT
)
1483 else if (out_type
== GLSL_TYPE_INT
)
1489 if (out_type
== GLSL_TYPE_FLOAT
)
1495 if (out_type
== GLSL_TYPE_FLOAT
)
1497 else if (out_type
== GLSL_TYPE_INT
)
1503 if (out_type
== GLSL_TYPE_FLOAT
)
1505 else if (out_type
== GLSL_TYPE_INT
)
1510 case ir_binop_bit_and
:
1513 case ir_binop_bit_or
:
1516 case ir_binop_bit_xor
:
1519 case ir_binop_logic_and
:
1525 case ir_binop_logic_or
:
1531 case ir_binop_logic_xor
:
1537 case ir_binop_lshift
:
1540 case ir_binop_rshift
:
1541 if (out_type
== GLSL_TYPE_INT
)
1551 unreachable("not reached");
1554 instr
= emit(op
, dest_size
, srcs
);
1556 if (ir
->operands
[0]->type
->vector_elements
!= 1 &&
1557 ir
->operands
[1]->type
->vector_elements
== 1) {
1558 for (unsigned i
= 0; i
< ir
->operands
[0]->type
->vector_elements
;
1560 instr
->src
[1].swizzle
[i
] = 0;
1564 if (ir
->operands
[1]->type
->vector_elements
!= 1 &&
1565 ir
->operands
[0]->type
->vector_elements
== 1) {
1566 for (unsigned i
= 0; i
< ir
->operands
[1]->type
->vector_elements
;
1568 instr
->src
[0].swizzle
[i
] = 0;
1573 case ir_binop_imul_high
:
1574 emit(out_type
== GLSL_TYPE_UINT
? nir_op_umul_high
: nir_op_imul_high
,
1577 case ir_binop_carry
: emit(nir_op_uadd_carry
, dest_size
, srcs
); break;
1578 case ir_binop_borrow
: emit(nir_op_usub_borrow
, dest_size
, srcs
); break;
1580 if (supports_ints
) {
1581 if (types
[0] == GLSL_TYPE_FLOAT
)
1582 emit(nir_op_flt
, dest_size
, srcs
);
1583 else if (types
[0] == GLSL_TYPE_INT
)
1584 emit(nir_op_ilt
, dest_size
, srcs
);
1586 emit(nir_op_ult
, dest_size
, srcs
);
1588 emit(nir_op_slt
, dest_size
, srcs
);
1591 case ir_binop_greater
:
1592 if (supports_ints
) {
1593 if (types
[0] == GLSL_TYPE_FLOAT
)
1594 emit(nir_op_flt
, dest_size
, srcs
[1], srcs
[0]);
1595 else if (types
[0] == GLSL_TYPE_INT
)
1596 emit(nir_op_ilt
, dest_size
, srcs
[1], srcs
[0]);
1598 emit(nir_op_ult
, dest_size
, srcs
[1], srcs
[0]);
1600 emit(nir_op_slt
, dest_size
, srcs
[1], srcs
[0]);
1603 case ir_binop_lequal
:
1604 if (supports_ints
) {
1605 if (types
[0] == GLSL_TYPE_FLOAT
)
1606 emit(nir_op_fge
, dest_size
, srcs
[1], srcs
[0]);
1607 else if (types
[0] == GLSL_TYPE_INT
)
1608 emit(nir_op_ige
, dest_size
, srcs
[1], srcs
[0]);
1610 emit(nir_op_uge
, dest_size
, srcs
[1], srcs
[0]);
1612 emit(nir_op_slt
, dest_size
, srcs
[1], srcs
[0]);
1615 case ir_binop_gequal
:
1616 if (supports_ints
) {
1617 if (types
[0] == GLSL_TYPE_FLOAT
)
1618 emit(nir_op_fge
, dest_size
, srcs
);
1619 else if (types
[0] == GLSL_TYPE_INT
)
1620 emit(nir_op_ige
, dest_size
, srcs
);
1622 emit(nir_op_uge
, dest_size
, srcs
);
1624 emit(nir_op_slt
, dest_size
, srcs
);
1627 case ir_binop_equal
:
1628 if (supports_ints
) {
1629 if (types
[0] == GLSL_TYPE_FLOAT
)
1630 emit(nir_op_feq
, dest_size
, srcs
);
1632 emit(nir_op_ieq
, dest_size
, srcs
);
1634 emit(nir_op_seq
, dest_size
, srcs
);
1637 case ir_binop_nequal
:
1638 if (supports_ints
) {
1639 if (types
[0] == GLSL_TYPE_FLOAT
)
1640 emit(nir_op_fne
, dest_size
, srcs
);
1642 emit(nir_op_ine
, dest_size
, srcs
);
1644 emit(nir_op_sne
, dest_size
, srcs
);
1647 case ir_binop_all_equal
:
1648 if (supports_ints
) {
1649 if (types
[0] == GLSL_TYPE_FLOAT
) {
1650 switch (ir
->operands
[0]->type
->vector_elements
) {
1651 case 1: emit(nir_op_feq
, dest_size
, srcs
); break;
1652 case 2: emit(nir_op_ball_fequal2
, dest_size
, srcs
); break;
1653 case 3: emit(nir_op_ball_fequal3
, dest_size
, srcs
); break;
1654 case 4: emit(nir_op_ball_fequal4
, dest_size
, srcs
); break;
1656 unreachable("not reached");
1659 switch (ir
->operands
[0]->type
->vector_elements
) {
1660 case 1: emit(nir_op_ieq
, dest_size
, srcs
); break;
1661 case 2: emit(nir_op_ball_iequal2
, dest_size
, srcs
); break;
1662 case 3: emit(nir_op_ball_iequal3
, dest_size
, srcs
); break;
1663 case 4: emit(nir_op_ball_iequal4
, dest_size
, srcs
); break;
1665 unreachable("not reached");
1669 switch (ir
->operands
[0]->type
->vector_elements
) {
1670 case 1: emit(nir_op_seq
, dest_size
, srcs
); break;
1671 case 2: emit(nir_op_fall_equal2
, dest_size
, srcs
); break;
1672 case 3: emit(nir_op_fall_equal3
, dest_size
, srcs
); break;
1673 case 4: emit(nir_op_fall_equal4
, dest_size
, srcs
); break;
1675 unreachable("not reached");
1679 case ir_binop_any_nequal
:
1680 if (supports_ints
) {
1681 if (types
[0] == GLSL_TYPE_FLOAT
) {
1682 switch (ir
->operands
[0]->type
->vector_elements
) {
1683 case 1: emit(nir_op_fne
, dest_size
, srcs
); break;
1684 case 2: emit(nir_op_bany_fnequal2
, dest_size
, srcs
); break;
1685 case 3: emit(nir_op_bany_fnequal3
, dest_size
, srcs
); break;
1686 case 4: emit(nir_op_bany_fnequal4
, dest_size
, srcs
); break;
1688 unreachable("not reached");
1691 switch (ir
->operands
[0]->type
->vector_elements
) {
1692 case 1: emit(nir_op_ine
, dest_size
, srcs
); break;
1693 case 2: emit(nir_op_bany_inequal2
, dest_size
, srcs
); break;
1694 case 3: emit(nir_op_bany_inequal3
, dest_size
, srcs
); break;
1695 case 4: emit(nir_op_bany_inequal4
, dest_size
, srcs
); break;
1697 unreachable("not reached");
1701 switch (ir
->operands
[0]->type
->vector_elements
) {
1702 case 1: emit(nir_op_sne
, dest_size
, srcs
); break;
1703 case 2: emit(nir_op_fany_nequal2
, dest_size
, srcs
); break;
1704 case 3: emit(nir_op_fany_nequal3
, dest_size
, srcs
); break;
1705 case 4: emit(nir_op_fany_nequal4
, dest_size
, srcs
); break;
1707 unreachable("not reached");
1712 switch (ir
->operands
[0]->type
->vector_elements
) {
1713 case 2: emit(nir_op_fdot2
, dest_size
, srcs
); break;
1714 case 3: emit(nir_op_fdot3
, dest_size
, srcs
); break;
1715 case 4: emit(nir_op_fdot4
, dest_size
, srcs
); break;
1717 unreachable("not reached");
1721 case ir_binop_pack_half_2x16_split
:
1722 emit(nir_op_pack_half_2x16_split
, dest_size
, srcs
);
1724 case ir_binop_bfm
: emit(nir_op_bfm
, dest_size
, srcs
); break;
1725 case ir_binop_ldexp
: emit(nir_op_ldexp
, dest_size
, srcs
); break;
1726 case ir_triop_fma
: emit(nir_op_ffma
, dest_size
, srcs
); break;
1728 instr
= emit(nir_op_flrp
, dest_size
, srcs
);
1729 if (ir
->operands
[0]->type
->vector_elements
!= 1 &&
1730 ir
->operands
[2]->type
->vector_elements
== 1) {
1731 for (unsigned i
= 0; i
< ir
->operands
[0]->type
->vector_elements
;
1733 instr
->src
[2].swizzle
[i
] = 0;
1739 emit(nir_op_bcsel
, dest_size
, srcs
);
1741 emit(nir_op_fcsel
, dest_size
, srcs
);
1744 instr
= emit(nir_op_bfi
, dest_size
, srcs
);
1745 for (unsigned i
= 0; i
< ir
->operands
[1]->type
->vector_elements
; i
++) {
1746 instr
->src
[0].swizzle
[i
] = 0;
1749 case ir_triop_bitfield_extract
:
1750 instr
= emit(out_type
== GLSL_TYPE_INT
? nir_op_ibitfield_extract
:
1751 nir_op_ubitfield_extract
, dest_size
, srcs
);
1752 for (unsigned i
= 0; i
< ir
->operands
[0]->type
->vector_elements
; i
++) {
1753 instr
->src
[1].swizzle
[i
] = 0;
1754 instr
->src
[2].swizzle
[i
] = 0;
1757 case ir_quadop_bitfield_insert
:
1758 instr
= emit(nir_op_bitfield_insert
, dest_size
, srcs
);
1759 for (unsigned i
= 0; i
< ir
->operands
[0]->type
->vector_elements
; i
++) {
1760 instr
->src
[2].swizzle
[i
] = 0;
1761 instr
->src
[3].swizzle
[i
] = 0;
1764 case ir_quadop_vector
:
1765 switch (ir
->type
->vector_elements
) {
1766 case 2: emit(nir_op_vec2
, dest_size
, srcs
); break;
1767 case 3: emit(nir_op_vec3
, dest_size
, srcs
); break;
1768 case 4: emit(nir_op_vec4
, dest_size
, srcs
); break;
1769 default: unreachable("not reached");
1774 unreachable("not reached");
1779 nir_visitor::visit(ir_swizzle
*ir
)
1781 nir_alu_instr
*instr
= emit(supports_ints
? nir_op_imov
: nir_op_fmov
,
1782 ir
->type
->vector_elements
,
1783 evaluate_rvalue(ir
->val
));
1785 unsigned swizzle
[4] = { ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
1786 for (unsigned i
= 0; i
< ir
->type
->vector_elements
; i
++)
1787 instr
->src
[0].swizzle
[i
] = swizzle
[i
];
1791 nir_visitor::visit(ir_texture
*ir
)
1798 num_srcs
= 1; /* coordinate */
1803 op
= (ir
->op
== ir_txb
) ? nir_texop_txb
: nir_texop_txl
;
1804 num_srcs
= 2; /* coordinate, bias/lod */
1808 op
= nir_texop_txd
; /* coordinate, dPdx, dPdy */
1814 if (ir
->lod_info
.lod
!= NULL
)
1815 num_srcs
= 2; /* coordinate, lod */
1817 num_srcs
= 1; /* coordinate */
1821 op
= nir_texop_txf_ms
;
1822 num_srcs
= 2; /* coordinate, sample_index */
1827 if (ir
->lod_info
.lod
!= NULL
)
1828 num_srcs
= 1; /* lod */
1835 num_srcs
= 1; /* coordinate */
1840 num_srcs
= 1; /* coordinate */
1843 case ir_query_levels
:
1844 op
= nir_texop_query_levels
;
1848 case ir_texture_samples
:
1849 op
= nir_texop_texture_samples
;
1854 unreachable("not reached");
1857 if (ir
->projector
!= NULL
)
1859 if (ir
->shadow_comparitor
!= NULL
)
1861 if (ir
->offset
!= NULL
&& ir
->offset
->as_constant() == NULL
)
1864 nir_tex_instr
*instr
= nir_tex_instr_create(this->shader
, num_srcs
);
1867 instr
->sampler_dim
=
1868 (glsl_sampler_dim
) ir
->sampler
->type
->sampler_dimensionality
;
1869 instr
->is_array
= ir
->sampler
->type
->sampler_array
;
1870 instr
->is_shadow
= ir
->sampler
->type
->sampler_shadow
;
1871 if (instr
->is_shadow
)
1872 instr
->is_new_style_shadow
= (ir
->type
->vector_elements
== 1);
1873 switch (ir
->type
->base_type
) {
1874 case GLSL_TYPE_FLOAT
:
1875 instr
->dest_type
= nir_type_float
;
1878 instr
->dest_type
= nir_type_int
;
1880 case GLSL_TYPE_UINT
:
1881 instr
->dest_type
= nir_type_unsigned
;
1884 unreachable("not reached");
1887 instr
->sampler
= evaluate_deref(&instr
->instr
, ir
->sampler
);
1889 unsigned src_number
= 0;
1891 if (ir
->coordinate
!= NULL
) {
1892 instr
->coord_components
= ir
->coordinate
->type
->vector_elements
;
1893 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->coordinate
);
1894 instr
->src
[src_number
].src_type
= nir_tex_src_coord
;
1898 if (ir
->projector
!= NULL
) {
1899 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->projector
);
1900 instr
->src
[src_number
].src_type
= nir_tex_src_projector
;
1904 if (ir
->shadow_comparitor
!= NULL
) {
1905 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->shadow_comparitor
);
1906 instr
->src
[src_number
].src_type
= nir_tex_src_comparitor
;
1910 if (ir
->offset
!= NULL
) {
1911 /* we don't support multiple offsets yet */
1912 assert(ir
->offset
->type
->is_vector() || ir
->offset
->type
->is_scalar());
1914 ir_constant
*const_offset
= ir
->offset
->as_constant();
1915 if (const_offset
!= NULL
) {
1916 for (unsigned i
= 0; i
< const_offset
->type
->vector_elements
; i
++)
1917 instr
->const_offset
[i
] = const_offset
->value
.i
[i
];
1919 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->offset
);
1920 instr
->src
[src_number
].src_type
= nir_tex_src_offset
;
1927 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->lod_info
.bias
);
1928 instr
->src
[src_number
].src_type
= nir_tex_src_bias
;
1935 if (ir
->lod_info
.lod
!= NULL
) {
1936 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->lod_info
.lod
);
1937 instr
->src
[src_number
].src_type
= nir_tex_src_lod
;
1943 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->lod_info
.grad
.dPdx
);
1944 instr
->src
[src_number
].src_type
= nir_tex_src_ddx
;
1946 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->lod_info
.grad
.dPdy
);
1947 instr
->src
[src_number
].src_type
= nir_tex_src_ddy
;
1952 instr
->src
[src_number
].src
= evaluate_rvalue(ir
->lod_info
.sample_index
);
1953 instr
->src
[src_number
].src_type
= nir_tex_src_ms_index
;
1958 instr
->component
= ir
->lod_info
.component
->as_constant()->value
.u
[0];
1965 assert(src_number
== num_srcs
);
1967 add_instr(&instr
->instr
, nir_tex_instr_dest_size(instr
));
1971 nir_visitor::visit(ir_constant
*ir
)
1974 * We don't know if this variable is an an array or struct that gets
1975 * dereferenced, so do the safe thing an make it a variable with a
1976 * constant initializer and return a dereference.
1979 nir_variable
*var
= ralloc(this->shader
, nir_variable
);
1980 var
->name
= ralloc_strdup(var
, "const_temp");
1981 var
->type
= ir
->type
;
1982 var
->data
.mode
= nir_var_local
;
1983 var
->data
.read_only
= true;
1984 var
->constant_initializer
= constant_copy(ir
, var
);
1985 exec_list_push_tail(&this->impl
->locals
, &var
->node
);
1987 this->deref_head
= nir_deref_var_create(this->shader
, var
);
1988 this->deref_tail
= &this->deref_head
->deref
;
1992 nir_visitor::visit(ir_dereference_variable
*ir
)
1994 struct hash_entry
*entry
=
1995 _mesa_hash_table_search(this->var_table
, ir
->var
);
1997 nir_variable
*var
= (nir_variable
*) entry
->data
;
1999 nir_deref_var
*deref
= nir_deref_var_create(this->shader
, var
);
2000 this->deref_head
= deref
;
2001 this->deref_tail
= &deref
->deref
;
2005 nir_visitor::visit(ir_dereference_record
*ir
)
2007 ir
->record
->accept(this);
2009 int field_index
= this->deref_tail
->type
->field_index(ir
->field
);
2010 assert(field_index
>= 0);
2012 nir_deref_struct
*deref
= nir_deref_struct_create(this->deref_tail
, field_index
);
2013 deref
->deref
.type
= ir
->type
;
2014 this->deref_tail
->child
= &deref
->deref
;
2015 this->deref_tail
= &deref
->deref
;
2019 nir_visitor::visit(ir_dereference_array
*ir
)
2021 nir_deref_array
*deref
= nir_deref_array_create(this->shader
);
2022 deref
->deref
.type
= ir
->type
;
2024 ir_constant
*const_index
= ir
->array_index
->as_constant();
2025 if (const_index
!= NULL
) {
2026 deref
->deref_array_type
= nir_deref_array_type_direct
;
2027 deref
->base_offset
= const_index
->value
.u
[0];
2029 deref
->deref_array_type
= nir_deref_array_type_indirect
;
2030 deref
->indirect
= evaluate_rvalue(ir
->array_index
);
2033 ir
->array
->accept(this);
2035 this->deref_tail
->child
= &deref
->deref
;
2036 ralloc_steal(this->deref_tail
, deref
);
2037 this->deref_tail
= &deref
->deref
;
2041 nir_visitor::visit(ir_barrier
*ir
)
2043 nir_intrinsic_instr
*instr
=
2044 nir_intrinsic_instr_create(this->shader
, nir_intrinsic_barrier
);
2045 nir_instr_insert_after_cf_list(this->cf_node_list
, &instr
->instr
);