1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "glsl/ir_print_visitor.h"
35 vec4_visitor::setup_attributes(int payload_reg
)
38 int attribute_map
[VERT_ATTRIB_MAX
+ 1];
41 for (int i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
42 if (prog_data
->inputs_read
& BITFIELD64_BIT(i
)) {
43 attribute_map
[i
] = payload_reg
+ nr_attributes
;
48 /* VertexID is stored by the VF as the last vertex element, but we
49 * don't represent it with a flag in inputs_read, so we call it
52 if (prog_data
->uses_vertexid
) {
53 attribute_map
[VERT_ATTRIB_MAX
] = payload_reg
+ nr_attributes
;
57 foreach_list(node
, &this->instructions
) {
58 vec4_instruction
*inst
= (vec4_instruction
*)node
;
60 /* We have to support ATTR as a destination for GL_FIXED fixup. */
61 if (inst
->dst
.file
== ATTR
) {
62 int grf
= attribute_map
[inst
->dst
.reg
+ inst
->dst
.reg_offset
];
64 struct brw_reg reg
= brw_vec8_grf(grf
, 0);
65 reg
.dw1
.bits
.writemask
= inst
->dst
.writemask
;
67 inst
->dst
.file
= HW_REG
;
68 inst
->dst
.fixed_hw_reg
= reg
;
71 for (int i
= 0; i
< 3; i
++) {
72 if (inst
->src
[i
].file
!= ATTR
)
75 int grf
= attribute_map
[inst
->src
[i
].reg
+ inst
->src
[i
].reg_offset
];
77 struct brw_reg reg
= brw_vec8_grf(grf
, 0);
78 reg
.dw1
.bits
.swizzle
= inst
->src
[i
].swizzle
;
79 reg
.type
= inst
->src
[i
].type
;
82 if (inst
->src
[i
].negate
)
85 inst
->src
[i
].file
= HW_REG
;
86 inst
->src
[i
].fixed_hw_reg
= reg
;
90 /* The BSpec says we always have to read at least one thing from
91 * the VF, and it appears that the hardware wedges otherwise.
93 if (nr_attributes
== 0)
96 prog_data
->urb_read_length
= (nr_attributes
+ 1) / 2;
98 return payload_reg
+ nr_attributes
;
102 vec4_visitor::setup_uniforms(int reg
)
104 /* The pre-gen6 VS requires that some push constants get loaded no
105 * matter what, or the GPU would hang.
107 if (intel
->gen
< 6 && this->uniforms
== 0) {
108 this->uniform_vector_size
[this->uniforms
] = 1;
110 for (unsigned int i
= 0; i
< 4; i
++) {
111 unsigned int slot
= this->uniforms
* 4 + i
;
112 static float zero
= 0.0;
113 c
->prog_data
.param
[slot
] = &zero
;
119 reg
+= ALIGN(uniforms
, 2) / 2;
122 c
->prog_data
.nr_params
= this->uniforms
* 4;
124 c
->prog_data
.curb_read_length
= reg
- 1;
125 c
->prog_data
.uses_new_param_layout
= true;
131 vec4_visitor::setup_payload(void)
135 /* The payload always contains important data in g0, which contains
136 * the URB handles that are passed on to the URB write at the end
137 * of the thread. So, we always start push constants at g1.
141 reg
= setup_uniforms(reg
);
143 reg
= setup_attributes(reg
);
145 this->first_non_payload_grf
= reg
;
149 vec4_instruction::get_dst(void)
151 struct brw_reg brw_reg
;
155 brw_reg
= brw_vec8_grf(dst
.reg
+ dst
.reg_offset
, 0);
156 brw_reg
= retype(brw_reg
, dst
.type
);
157 brw_reg
.dw1
.bits
.writemask
= dst
.writemask
;
161 brw_reg
= brw_message_reg(dst
.reg
+ dst
.reg_offset
);
162 brw_reg
= retype(brw_reg
, dst
.type
);
163 brw_reg
.dw1
.bits
.writemask
= dst
.writemask
;
167 brw_reg
= dst
.fixed_hw_reg
;
171 brw_reg
= brw_null_reg();
175 assert(!"not reached");
176 brw_reg
= brw_null_reg();
183 vec4_instruction::get_src(int i
)
185 struct brw_reg brw_reg
;
187 switch (src
[i
].file
) {
189 brw_reg
= brw_vec8_grf(src
[i
].reg
+ src
[i
].reg_offset
, 0);
190 brw_reg
= retype(brw_reg
, src
[i
].type
);
191 brw_reg
.dw1
.bits
.swizzle
= src
[i
].swizzle
;
193 brw_reg
= brw_abs(brw_reg
);
195 brw_reg
= negate(brw_reg
);
199 switch (src
[i
].type
) {
200 case BRW_REGISTER_TYPE_F
:
201 brw_reg
= brw_imm_f(src
[i
].imm
.f
);
203 case BRW_REGISTER_TYPE_D
:
204 brw_reg
= brw_imm_d(src
[i
].imm
.i
);
206 case BRW_REGISTER_TYPE_UD
:
207 brw_reg
= brw_imm_ud(src
[i
].imm
.u
);
210 assert(!"not reached");
211 brw_reg
= brw_null_reg();
217 brw_reg
= stride(brw_vec4_grf(1 + (src
[i
].reg
+ src
[i
].reg_offset
) / 2,
218 ((src
[i
].reg
+ src
[i
].reg_offset
) % 2) * 4),
220 brw_reg
= retype(brw_reg
, src
[i
].type
);
221 brw_reg
.dw1
.bits
.swizzle
= src
[i
].swizzle
;
223 brw_reg
= brw_abs(brw_reg
);
225 brw_reg
= negate(brw_reg
);
227 /* This should have been moved to pull constants. */
228 assert(!src
[i
].reladdr
);
232 brw_reg
= src
[i
].fixed_hw_reg
;
236 /* Probably unused. */
237 brw_reg
= brw_null_reg();
241 assert(!"not reached");
242 brw_reg
= brw_null_reg();
250 vec4_visitor::generate_math1_gen4(vec4_instruction
*inst
,
256 brw_math_function(inst
->opcode
),
257 BRW_MATH_SATURATE_NONE
,
260 BRW_MATH_DATA_VECTOR
,
261 BRW_MATH_PRECISION_FULL
);
265 check_gen6_math_src_arg(struct brw_reg src
)
267 /* Source swizzles are ignored. */
270 assert(src
.dw1
.bits
.swizzle
== BRW_SWIZZLE_XYZW
);
274 vec4_visitor::generate_math1_gen6(vec4_instruction
*inst
,
278 /* Can't do writemask because math can't be align16. */
279 assert(dst
.dw1
.bits
.writemask
== WRITEMASK_XYZW
);
280 check_gen6_math_src_arg(src
);
282 brw_set_access_mode(p
, BRW_ALIGN_1
);
285 brw_math_function(inst
->opcode
),
286 BRW_MATH_SATURATE_NONE
,
289 BRW_MATH_DATA_SCALAR
,
290 BRW_MATH_PRECISION_FULL
);
291 brw_set_access_mode(p
, BRW_ALIGN_16
);
295 vec4_visitor::generate_math2_gen7(vec4_instruction
*inst
,
302 brw_math_function(inst
->opcode
),
307 vec4_visitor::generate_math2_gen6(vec4_instruction
*inst
,
312 /* Can't do writemask because math can't be align16. */
313 assert(dst
.dw1
.bits
.writemask
== WRITEMASK_XYZW
);
314 /* Source swizzles are ignored. */
315 check_gen6_math_src_arg(src0
);
316 check_gen6_math_src_arg(src1
);
318 brw_set_access_mode(p
, BRW_ALIGN_1
);
321 brw_math_function(inst
->opcode
),
323 brw_set_access_mode(p
, BRW_ALIGN_16
);
327 vec4_visitor::generate_math2_gen4(vec4_instruction
*inst
,
332 /* From the Ironlake PRM, Volume 4, Part 1, Section 6.1.13
335 * "Operand0[7]. For the INT DIV functions, this operand is the
338 * "Operand1[7]. For the INT DIV functions, this operand is the
341 bool is_int_div
= inst
->opcode
!= SHADER_OPCODE_POW
;
342 struct brw_reg
&op0
= is_int_div
? src1
: src0
;
343 struct brw_reg
&op1
= is_int_div
? src0
: src1
;
345 brw_MOV(p
, retype(brw_message_reg(inst
->base_mrf
+ 1), op1
.type
), op1
);
349 brw_math_function(inst
->opcode
),
350 BRW_MATH_SATURATE_NONE
,
353 BRW_MATH_DATA_VECTOR
,
354 BRW_MATH_PRECISION_FULL
);
358 vec4_visitor::generate_tex(vec4_instruction
*inst
,
364 if (intel
->gen
>= 5) {
365 switch (inst
->opcode
) {
366 case SHADER_OPCODE_TEX
:
367 case SHADER_OPCODE_TXL
:
368 if (inst
->shadow_compare
) {
369 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE
;
371 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD
;
374 case SHADER_OPCODE_TXD
:
375 /* There is no sample_d_c message; comparisons are done manually. */
376 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS
;
378 case SHADER_OPCODE_TXF
:
379 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
381 case SHADER_OPCODE_TXS
:
382 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
;
385 assert(!"should not get here: invalid VS texture opcode");
389 switch (inst
->opcode
) {
390 case SHADER_OPCODE_TEX
:
391 case SHADER_OPCODE_TXL
:
392 if (inst
->shadow_compare
) {
393 msg_type
= BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD_COMPARE
;
394 assert(inst
->mlen
== 3);
396 msg_type
= BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD
;
397 assert(inst
->mlen
== 2);
400 case SHADER_OPCODE_TXD
:
401 /* There is no sample_d_c message; comparisons are done manually. */
402 msg_type
= BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS
;
403 assert(inst
->mlen
== 4);
405 case SHADER_OPCODE_TXF
:
406 msg_type
= BRW_SAMPLER_MESSAGE_SIMD4X2_LD
;
407 assert(inst
->mlen
== 2);
409 case SHADER_OPCODE_TXS
:
410 msg_type
= BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO
;
411 assert(inst
->mlen
== 2);
414 assert(!"should not get here: invalid VS texture opcode");
419 assert(msg_type
!= -1);
421 if (inst
->header_present
) {
422 /* Set up an implied move from g0 to the MRF. */
423 src
= brw_vec8_grf(0, 0);
426 uint32_t return_format
;
429 case BRW_REGISTER_TYPE_D
:
430 return_format
= BRW_SAMPLER_RETURN_FORMAT_SINT32
;
432 case BRW_REGISTER_TYPE_UD
:
433 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
436 return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
444 SURF_INDEX_TEXTURE(inst
->sampler
),
448 1, /* response length */
450 inst
->header_present
,
451 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
456 vec4_visitor::generate_urb_write(vec4_instruction
*inst
)
459 brw_null_reg(), /* dest */
460 inst
->base_mrf
, /* starting mrf reg nr */
461 brw_vec8_grf(0, 0), /* src */
462 false, /* allocate */
465 0, /* response len */
467 inst
->eot
, /* writes complete */
468 inst
->offset
, /* urb destination offset */
469 BRW_URB_SWIZZLE_INTERLEAVE
);
473 vec4_visitor::generate_oword_dual_block_offsets(struct brw_reg m1
,
474 struct brw_reg index
)
476 int second_vertex_offset
;
479 second_vertex_offset
= 1;
481 second_vertex_offset
= 16;
483 m1
= retype(m1
, BRW_REGISTER_TYPE_D
);
485 /* Set up M1 (message payload). Only the block offsets in M1.0 and
486 * M1.4 are used, and the rest are ignored.
488 struct brw_reg m1_0
= suboffset(vec1(m1
), 0);
489 struct brw_reg m1_4
= suboffset(vec1(m1
), 4);
490 struct brw_reg index_0
= suboffset(vec1(index
), 0);
491 struct brw_reg index_4
= suboffset(vec1(index
), 4);
493 brw_push_insn_state(p
);
494 brw_set_mask_control(p
, BRW_MASK_DISABLE
);
495 brw_set_access_mode(p
, BRW_ALIGN_1
);
497 brw_MOV(p
, m1_0
, index_0
);
499 brw_set_predicate_inverse(p
, true);
500 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
501 index_4
.dw1
.ud
+= second_vertex_offset
;
502 brw_MOV(p
, m1_4
, index_4
);
504 brw_ADD(p
, m1_4
, index_4
, brw_imm_d(second_vertex_offset
));
507 brw_pop_insn_state(p
);
511 vec4_visitor::generate_scratch_read(vec4_instruction
*inst
,
513 struct brw_reg index
)
515 struct brw_reg header
= brw_vec8_grf(0, 0);
517 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
519 generate_oword_dual_block_offsets(brw_message_reg(inst
->base_mrf
+ 1),
525 msg_type
= GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ
;
526 else if (intel
->gen
== 5 || intel
->is_g4x
)
527 msg_type
= G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ
;
529 msg_type
= BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ
;
531 /* Each of the 8 channel enables is considered for whether each
534 struct brw_instruction
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
535 brw_set_dest(p
, send
, dst
);
536 brw_set_src0(p
, send
, header
);
538 send
->header
.destreg__conditionalmod
= inst
->base_mrf
;
539 brw_set_dp_read_message(p
, send
,
540 255, /* binding table index: stateless access */
541 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD
,
543 BRW_DATAPORT_READ_TARGET_RENDER_CACHE
,
549 vec4_visitor::generate_scratch_write(vec4_instruction
*inst
,
552 struct brw_reg index
)
554 struct brw_reg header
= brw_vec8_grf(0, 0);
557 /* If the instruction is predicated, we'll predicate the send, not
560 brw_set_predicate_control(p
, false);
562 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
564 generate_oword_dual_block_offsets(brw_message_reg(inst
->base_mrf
+ 1),
568 retype(brw_message_reg(inst
->base_mrf
+ 2), BRW_REGISTER_TYPE_D
),
569 retype(src
, BRW_REGISTER_TYPE_D
));
574 msg_type
= GEN7_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE
;
575 else if (intel
->gen
== 6)
576 msg_type
= GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE
;
578 msg_type
= BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE
;
580 brw_set_predicate_control(p
, inst
->predicate
);
582 /* Pre-gen6, we have to specify write commits to ensure ordering
583 * between reads and writes within a thread. Afterwards, that's
584 * guaranteed and write commits only matter for inter-thread
587 if (intel
->gen
>= 6) {
588 write_commit
= false;
590 /* The visitor set up our destination register to be g0. This
591 * means that when the next read comes along, we will end up
592 * reading from g0 and causing a block on the write commit. For
593 * write-after-read, we are relying on the value of the previous
594 * read being used (and thus blocking on completion) before our
595 * write is executed. This means we have to be careful in
596 * instruction scheduling to not violate this assumption.
601 /* Each of the 8 channel enables is considered for whether each
604 struct brw_instruction
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
605 brw_set_dest(p
, send
, dst
);
606 brw_set_src0(p
, send
, header
);
608 send
->header
.destreg__conditionalmod
= inst
->base_mrf
;
609 brw_set_dp_write_message(p
, send
,
610 255, /* binding table index: stateless access */
611 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD
,
614 true, /* header present */
615 false, /* not a render target write */
616 write_commit
, /* rlen */
622 vec4_visitor::generate_pull_constant_load(vec4_instruction
*inst
,
624 struct brw_reg index
)
626 struct brw_reg header
= brw_vec8_grf(0, 0);
628 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
630 brw_MOV(p
, retype(brw_message_reg(inst
->base_mrf
+ 1), BRW_REGISTER_TYPE_D
),
636 msg_type
= GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ
;
637 else if (intel
->gen
== 5 || intel
->is_g4x
)
638 msg_type
= G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ
;
640 msg_type
= BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ
;
642 /* Each of the 8 channel enables is considered for whether each
645 struct brw_instruction
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
646 brw_set_dest(p
, send
, dst
);
647 brw_set_src0(p
, send
, header
);
649 send
->header
.destreg__conditionalmod
= inst
->base_mrf
;
650 brw_set_dp_read_message(p
, send
,
651 SURF_INDEX_VERT_CONST_BUFFER
,
652 BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD
,
654 BRW_DATAPORT_READ_TARGET_DATA_CACHE
,
660 vec4_visitor::generate_vs_instruction(vec4_instruction
*instruction
,
664 vec4_instruction
*inst
= (vec4_instruction
*)instruction
;
666 switch (inst
->opcode
) {
667 case SHADER_OPCODE_RCP
:
668 case SHADER_OPCODE_RSQ
:
669 case SHADER_OPCODE_SQRT
:
670 case SHADER_OPCODE_EXP2
:
671 case SHADER_OPCODE_LOG2
:
672 case SHADER_OPCODE_SIN
:
673 case SHADER_OPCODE_COS
:
674 if (intel
->gen
== 6) {
675 generate_math1_gen6(inst
, dst
, src
[0]);
677 /* Also works for Gen7. */
678 generate_math1_gen4(inst
, dst
, src
[0]);
682 case SHADER_OPCODE_POW
:
683 case SHADER_OPCODE_INT_QUOTIENT
:
684 case SHADER_OPCODE_INT_REMAINDER
:
685 if (intel
->gen
>= 7) {
686 generate_math2_gen7(inst
, dst
, src
[0], src
[1]);
687 } else if (intel
->gen
== 6) {
688 generate_math2_gen6(inst
, dst
, src
[0], src
[1]);
690 generate_math2_gen4(inst
, dst
, src
[0], src
[1]);
694 case SHADER_OPCODE_TEX
:
695 case SHADER_OPCODE_TXD
:
696 case SHADER_OPCODE_TXF
:
697 case SHADER_OPCODE_TXL
:
698 case SHADER_OPCODE_TXS
:
699 generate_tex(inst
, dst
, src
[0]);
702 case VS_OPCODE_URB_WRITE
:
703 generate_urb_write(inst
);
706 case VS_OPCODE_SCRATCH_READ
:
707 generate_scratch_read(inst
, dst
, src
[0]);
710 case VS_OPCODE_SCRATCH_WRITE
:
711 generate_scratch_write(inst
, dst
, src
[0], src
[1]);
714 case VS_OPCODE_PULL_CONSTANT_LOAD
:
715 generate_pull_constant_load(inst
, dst
, src
[0]);
719 if (inst
->opcode
< (int)ARRAY_SIZE(brw_opcodes
)) {
720 fail("unsupported opcode in `%s' in VS\n",
721 brw_opcodes
[inst
->opcode
].name
);
723 fail("Unsupported opcode %d in VS", inst
->opcode
);
731 if (c
->key
.userclip_active
&& !c
->key
.uses_clip_distance
)
732 setup_uniform_clipplane_values();
734 /* Generate VS IR for main(). (the visitor only descends into
735 * functions called "main").
737 visit_instructions(shader
->ir
);
741 /* Before any optimization, push array accesses out to scratch
742 * space where we need them to be. This pass may allocate new
743 * virtual GRFs, so we want to do it early. It also makes sure
744 * that we have reladdr computations available for CSE, since we'll
745 * often do repeated subexpressions for those.
747 move_grf_array_access_to_scratch();
748 move_uniform_array_access_to_pull_constants();
749 pack_uniform_registers();
750 move_push_constants_to_pull_constants();
755 progress
= dead_code_eliminate() || progress
;
756 progress
= opt_copy_propagation() || progress
;
757 progress
= opt_algebraic() || progress
;
758 progress
= opt_compute_to_mrf() || progress
;
771 brw_set_access_mode(p
, BRW_ALIGN_16
);
779 vec4_visitor::generate_code()
781 int last_native_inst
= 0;
782 const char *last_annotation_string
= NULL
;
783 ir_instruction
*last_annotation_ir
= NULL
;
785 int loop_stack_array_size
= 16;
786 int loop_stack_depth
= 0;
787 brw_instruction
**loop_stack
=
788 rzalloc_array(this->mem_ctx
, brw_instruction
*, loop_stack_array_size
);
789 int *if_depth_in_loop
=
790 rzalloc_array(this->mem_ctx
, int, loop_stack_array_size
);
793 if (unlikely(INTEL_DEBUG
& DEBUG_VS
)) {
794 printf("Native code for vertex shader %d:\n", prog
->Name
);
797 foreach_list(node
, &this->instructions
) {
798 vec4_instruction
*inst
= (vec4_instruction
*)node
;
799 struct brw_reg src
[3], dst
;
801 if (unlikely(INTEL_DEBUG
& DEBUG_VS
)) {
802 if (last_annotation_ir
!= inst
->ir
) {
803 last_annotation_ir
= inst
->ir
;
804 if (last_annotation_ir
) {
806 last_annotation_ir
->print();
810 if (last_annotation_string
!= inst
->annotation
) {
811 last_annotation_string
= inst
->annotation
;
812 if (last_annotation_string
)
813 printf(" %s\n", last_annotation_string
);
817 for (unsigned int i
= 0; i
< 3; i
++) {
818 src
[i
] = inst
->get_src(i
);
820 dst
= inst
->get_dst();
822 brw_set_conditionalmod(p
, inst
->conditional_mod
);
823 brw_set_predicate_control(p
, inst
->predicate
);
824 brw_set_predicate_inverse(p
, inst
->predicate_inverse
);
825 brw_set_saturate(p
, inst
->saturate
);
827 switch (inst
->opcode
) {
829 brw_MOV(p
, dst
, src
[0]);
832 brw_ADD(p
, dst
, src
[0], src
[1]);
835 brw_MUL(p
, dst
, src
[0], src
[1]);
837 case BRW_OPCODE_MACH
:
838 brw_set_acc_write_control(p
, 1);
839 brw_MACH(p
, dst
, src
[0], src
[1]);
840 brw_set_acc_write_control(p
, 0);
844 brw_FRC(p
, dst
, src
[0]);
846 case BRW_OPCODE_RNDD
:
847 brw_RNDD(p
, dst
, src
[0]);
849 case BRW_OPCODE_RNDE
:
850 brw_RNDE(p
, dst
, src
[0]);
852 case BRW_OPCODE_RNDZ
:
853 brw_RNDZ(p
, dst
, src
[0]);
857 brw_AND(p
, dst
, src
[0], src
[1]);
860 brw_OR(p
, dst
, src
[0], src
[1]);
863 brw_XOR(p
, dst
, src
[0], src
[1]);
866 brw_NOT(p
, dst
, src
[0]);
869 brw_ASR(p
, dst
, src
[0], src
[1]);
872 brw_SHR(p
, dst
, src
[0], src
[1]);
875 brw_SHL(p
, dst
, src
[0], src
[1]);
879 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
882 brw_SEL(p
, dst
, src
[0], src
[1]);
886 brw_DP4(p
, dst
, src
[0], src
[1]);
890 brw_DP3(p
, dst
, src
[0], src
[1]);
894 brw_DP2(p
, dst
, src
[0], src
[1]);
898 if (inst
->src
[0].file
!= BAD_FILE
) {
899 /* The instruction has an embedded compare (only allowed on gen6) */
900 assert(intel
->gen
== 6);
901 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
903 struct brw_instruction
*brw_inst
= brw_IF(p
, BRW_EXECUTE_8
);
904 brw_inst
->header
.predicate_control
= inst
->predicate
;
906 if_depth_in_loop
[loop_stack_depth
]++;
909 case BRW_OPCODE_ELSE
:
912 case BRW_OPCODE_ENDIF
:
914 if_depth_in_loop
[loop_stack_depth
]--;
918 loop_stack
[loop_stack_depth
++] = brw_DO(p
, BRW_EXECUTE_8
);
919 if (loop_stack_array_size
<= loop_stack_depth
) {
920 loop_stack_array_size
*= 2;
921 loop_stack
= reralloc(this->mem_ctx
, loop_stack
, brw_instruction
*,
922 loop_stack_array_size
);
923 if_depth_in_loop
= reralloc(this->mem_ctx
, if_depth_in_loop
, int,
924 loop_stack_array_size
);
926 if_depth_in_loop
[loop_stack_depth
] = 0;
929 case BRW_OPCODE_BREAK
:
930 brw_BREAK(p
, if_depth_in_loop
[loop_stack_depth
]);
931 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
933 case BRW_OPCODE_CONTINUE
:
934 /* FINISHME: We need to write the loop instruction support still. */
936 gen6_CONT(p
, loop_stack
[loop_stack_depth
- 1]);
938 brw_CONT(p
, if_depth_in_loop
[loop_stack_depth
]);
939 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
942 case BRW_OPCODE_WHILE
: {
943 struct brw_instruction
*inst0
, *inst1
;
949 assert(loop_stack_depth
> 0);
951 inst0
= inst1
= brw_WHILE(p
, loop_stack
[loop_stack_depth
]);
952 if (intel
->gen
< 6) {
953 /* patch all the BREAK/CONT instructions from last BGNLOOP */
954 while (inst0
> loop_stack
[loop_stack_depth
]) {
956 if (inst0
->header
.opcode
== BRW_OPCODE_BREAK
&&
957 inst0
->bits3
.if_else
.jump_count
== 0) {
958 inst0
->bits3
.if_else
.jump_count
= br
* (inst1
- inst0
+ 1);
960 else if (inst0
->header
.opcode
== BRW_OPCODE_CONTINUE
&&
961 inst0
->bits3
.if_else
.jump_count
== 0) {
962 inst0
->bits3
.if_else
.jump_count
= br
* (inst1
- inst0
);
970 generate_vs_instruction(inst
, dst
, src
);
974 if (unlikely(INTEL_DEBUG
& DEBUG_VS
)) {
975 for (unsigned int i
= last_native_inst
; i
< p
->nr_insn
; i
++) {
977 printf("0x%08x 0x%08x 0x%08x 0x%08x ",
978 ((uint32_t *)&p
->store
[i
])[3],
979 ((uint32_t *)&p
->store
[i
])[2],
980 ((uint32_t *)&p
->store
[i
])[1],
981 ((uint32_t *)&p
->store
[i
])[0]);
983 brw_disasm(stdout
, &p
->store
[i
], intel
->gen
);
987 last_native_inst
= p
->nr_insn
;
990 if (unlikely(INTEL_DEBUG
& DEBUG_VS
)) {
994 ralloc_free(loop_stack
);
995 ralloc_free(if_depth_in_loop
);
999 /* OK, while the INTEL_DEBUG=vs above is very nice for debugging VS
1000 * emit issues, it doesn't get the jump distances into the output,
1001 * which is often something we want to debug. So this is here in
1002 * case you're doing that.
1005 if (unlikely(INTEL_DEBUG
& DEBUG_VS
)) {
1006 for (unsigned int i
= 0; i
< p
->nr_insn
; i
++) {
1007 printf("0x%08x 0x%08x 0x%08x 0x%08x ",
1008 ((uint32_t *)&p
->store
[i
])[3],
1009 ((uint32_t *)&p
->store
[i
])[2],
1010 ((uint32_t *)&p
->store
[i
])[1],
1011 ((uint32_t *)&p
->store
[i
])[0]);
1012 brw_disasm(stdout
, &p
->store
[i
], intel
->gen
);
1021 brw_vs_emit(struct gl_shader_program
*prog
, struct brw_vs_compile
*c
)
1026 struct brw_shader
*shader
=
1027 (brw_shader
*) prog
->_LinkedShaders
[MESA_SHADER_VERTEX
];
1031 if (unlikely(INTEL_DEBUG
& DEBUG_VS
)) {
1032 printf("GLSL IR for native vertex shader %d:\n", prog
->Name
);
1033 _mesa_print_ir(shader
->ir
, NULL
);
1037 vec4_visitor
v(c
, prog
, shader
);
1039 prog
->LinkStatus
= false;
1040 ralloc_strcat(&prog
->InfoLog
, v
.fail_msg
);
1049 } /* namespace brw */