2 * Copyright © 2010 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 /** @file brw_fs_emit.cpp
26 * This file supports emitting code from the FS LIR to the actual
27 * native instructions.
31 #include "main/macros.h"
32 #include "brw_context.h"
37 #include "brw_fs_cfg.h"
38 #include "glsl/ir_print_visitor.h"
41 fs_visitor::generate_fb_write(fs_inst
*inst
)
44 struct brw_reg implied_header
;
47 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
50 brw_push_insn_state(p
);
51 brw_set_mask_control(p
, BRW_MASK_DISABLE
);
52 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
54 if (inst
->header_present
) {
55 if (intel
->gen
>= 6) {
56 brw_set_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
58 retype(brw_message_reg(inst
->base_mrf
), BRW_REGISTER_TYPE_UD
),
59 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
60 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
62 if (inst
->target
> 0) {
63 /* Set the render target index for choosing BLEND_STATE. */
64 brw_MOV(p
, retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE
,
66 BRW_REGISTER_TYPE_UD
),
67 brw_imm_ud(inst
->target
));
70 implied_header
= brw_null_reg();
72 implied_header
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
75 brw_message_reg(inst
->base_mrf
+ 1),
79 implied_header
= brw_null_reg();
82 if (this->dual_src_output
.file
!= BAD_FILE
)
83 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01
;
84 else if (c
->dispatch_width
== 16)
85 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
;
87 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01
;
89 brw_pop_insn_state(p
);
100 inst
->header_present
);
103 /* Computes the integer pixel x,y values from the origin.
105 * This is the basis of gl_FragCoord computation, but is also used
106 * pre-gen6 for computing the deltas from v0 for computing
110 fs_visitor::generate_pixel_xy(struct brw_reg dst
, bool is_x
)
112 struct brw_reg g1_uw
= retype(brw_vec1_grf(1, 0), BRW_REGISTER_TYPE_UW
);
114 struct brw_reg deltas
;
117 src
= stride(suboffset(g1_uw
, 4), 2, 4, 0);
118 deltas
= brw_imm_v(0x10101010);
120 src
= stride(suboffset(g1_uw
, 5), 2, 4, 0);
121 deltas
= brw_imm_v(0x11001100);
124 if (c
->dispatch_width
== 16) {
128 /* We do this 8 or 16-wide, but since the destination is UW we
129 * don't do compression in the 16-wide case.
131 brw_push_insn_state(p
);
132 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
133 brw_ADD(p
, dst
, src
, deltas
);
134 brw_pop_insn_state(p
);
138 fs_visitor::generate_linterp(fs_inst
*inst
,
139 struct brw_reg dst
, struct brw_reg
*src
)
141 struct brw_reg delta_x
= src
[0];
142 struct brw_reg delta_y
= src
[1];
143 struct brw_reg interp
= src
[2];
146 delta_y
.nr
== delta_x
.nr
+ 1 &&
147 (intel
->gen
>= 6 || (delta_x
.nr
& 1) == 0)) {
148 brw_PLN(p
, dst
, interp
, delta_x
);
150 brw_LINE(p
, brw_null_reg(), interp
, delta_x
);
151 brw_MAC(p
, dst
, suboffset(interp
, 1), delta_y
);
156 fs_visitor::generate_math1_gen7(fs_inst
*inst
,
160 assert(inst
->mlen
== 0);
162 brw_math_function(inst
->opcode
),
163 inst
->saturate
? BRW_MATH_SATURATE_SATURATE
164 : BRW_MATH_SATURATE_NONE
,
166 BRW_MATH_DATA_VECTOR
,
167 BRW_MATH_PRECISION_FULL
);
171 fs_visitor::generate_math2_gen7(fs_inst
*inst
,
176 assert(inst
->mlen
== 0);
177 brw_math2(p
, dst
, brw_math_function(inst
->opcode
), src0
, src1
);
181 fs_visitor::generate_math1_gen6(fs_inst
*inst
,
185 int op
= brw_math_function(inst
->opcode
);
187 assert(inst
->mlen
== 0);
189 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
192 inst
->saturate
? BRW_MATH_SATURATE_SATURATE
:
193 BRW_MATH_SATURATE_NONE
,
195 BRW_MATH_DATA_VECTOR
,
196 BRW_MATH_PRECISION_FULL
);
198 if (c
->dispatch_width
== 16) {
199 brw_set_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
200 brw_math(p
, sechalf(dst
),
202 inst
->saturate
? BRW_MATH_SATURATE_SATURATE
:
203 BRW_MATH_SATURATE_NONE
,
205 BRW_MATH_DATA_VECTOR
,
206 BRW_MATH_PRECISION_FULL
);
207 brw_set_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
212 fs_visitor::generate_math2_gen6(fs_inst
*inst
,
217 int op
= brw_math_function(inst
->opcode
);
219 assert(inst
->mlen
== 0);
221 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
222 brw_math2(p
, dst
, op
, src0
, src1
);
224 if (c
->dispatch_width
== 16) {
225 brw_set_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
226 brw_math2(p
, sechalf(dst
), op
, sechalf(src0
), sechalf(src1
));
227 brw_set_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
232 fs_visitor::generate_math_gen4(fs_inst
*inst
,
236 int op
= brw_math_function(inst
->opcode
);
238 assert(inst
->mlen
>= 1);
240 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
243 inst
->saturate
? BRW_MATH_SATURATE_SATURATE
:
244 BRW_MATH_SATURATE_NONE
,
246 BRW_MATH_DATA_VECTOR
,
247 BRW_MATH_PRECISION_FULL
);
249 if (c
->dispatch_width
== 16) {
250 brw_set_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
251 brw_math(p
, sechalf(dst
),
253 inst
->saturate
? BRW_MATH_SATURATE_SATURATE
:
254 BRW_MATH_SATURATE_NONE
,
255 inst
->base_mrf
+ 1, sechalf(src
),
256 BRW_MATH_DATA_VECTOR
,
257 BRW_MATH_PRECISION_FULL
);
259 brw_set_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
264 fs_visitor::generate_tex(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
)
268 uint32_t simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
269 uint32_t return_format
;
272 case BRW_REGISTER_TYPE_D
:
273 return_format
= BRW_SAMPLER_RETURN_FORMAT_SINT32
;
275 case BRW_REGISTER_TYPE_UD
:
276 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
279 return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
283 if (c
->dispatch_width
== 16)
284 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
286 if (intel
->gen
>= 5) {
287 switch (inst
->opcode
) {
288 case SHADER_OPCODE_TEX
:
289 if (inst
->shadow_compare
) {
290 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE
;
292 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE
;
296 if (inst
->shadow_compare
) {
297 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE
;
299 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS
;
302 case SHADER_OPCODE_TXL
:
303 if (inst
->shadow_compare
) {
304 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE
;
306 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD
;
309 case SHADER_OPCODE_TXS
:
310 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
;
312 case SHADER_OPCODE_TXD
:
313 /* There is no sample_d_c message; comparisons are done manually */
314 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS
;
316 case SHADER_OPCODE_TXF
:
317 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
320 assert(!"not reached");
324 switch (inst
->opcode
) {
325 case SHADER_OPCODE_TEX
:
326 /* Note that G45 and older determines shadow compare and dispatch width
327 * from message length for most messages.
329 assert(c
->dispatch_width
== 8);
330 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE
;
331 if (inst
->shadow_compare
) {
332 assert(inst
->mlen
== 6);
334 assert(inst
->mlen
<= 4);
338 if (inst
->shadow_compare
) {
339 assert(inst
->mlen
== 6);
340 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE
;
342 assert(inst
->mlen
== 9);
343 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS
;
344 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
347 case SHADER_OPCODE_TXL
:
348 if (inst
->shadow_compare
) {
349 assert(inst
->mlen
== 6);
350 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE
;
352 assert(inst
->mlen
== 9);
353 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD
;
354 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
357 case SHADER_OPCODE_TXD
:
358 /* There is no sample_d_c message; comparisons are done manually */
359 assert(inst
->mlen
== 7 || inst
->mlen
== 10);
360 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS
;
362 case SHADER_OPCODE_TXF
:
363 assert(inst
->mlen
== 9);
364 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
365 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
367 case SHADER_OPCODE_TXS
:
368 assert(inst
->mlen
== 3);
369 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_RESINFO
;
370 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
373 assert(!"not reached");
377 assert(msg_type
!= -1);
379 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
385 retype(dst
, BRW_REGISTER_TYPE_UW
),
388 SURF_INDEX_TEXTURE(inst
->sampler
),
394 inst
->header_present
,
400 /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
403 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
405 * and we're trying to produce:
408 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
409 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
410 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
411 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
412 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
413 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
414 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
415 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
417 * and add another set of two more subspans if in 16-pixel dispatch mode.
419 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
420 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
421 * pair. But for DDY, it's harder, as we want to produce the pairs swizzled
422 * between each other. We could probably do it like ddx and swizzle the right
423 * order later, but bail for now and just produce
424 * ((ss0.tl - ss0.bl)x4 (ss1.tl - ss1.bl)x4)
427 fs_visitor::generate_ddx(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
)
429 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 1,
431 BRW_VERTICAL_STRIDE_2
,
433 BRW_HORIZONTAL_STRIDE_0
,
434 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
435 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
437 BRW_VERTICAL_STRIDE_2
,
439 BRW_HORIZONTAL_STRIDE_0
,
440 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
441 brw_ADD(p
, dst
, src0
, negate(src1
));
444 /* The negate_value boolean is used to negate the derivative computation for
445 * FBOs, since they place the origin at the upper left instead of the lower
449 fs_visitor::generate_ddy(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
,
452 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
454 BRW_VERTICAL_STRIDE_4
,
456 BRW_HORIZONTAL_STRIDE_0
,
457 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
458 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 2,
460 BRW_VERTICAL_STRIDE_4
,
462 BRW_HORIZONTAL_STRIDE_0
,
463 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
465 brw_ADD(p
, dst
, src1
, negate(src0
));
467 brw_ADD(p
, dst
, src0
, negate(src1
));
471 fs_visitor::generate_discard(fs_inst
*inst
)
473 struct brw_reg f0
= brw_flag_reg();
475 if (intel
->gen
>= 6) {
476 struct brw_reg g1
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
477 struct brw_reg some_register
;
479 /* As of gen6, we no longer have the mask register to look at,
480 * so life gets a bit more complicated.
483 /* Load the flag register with all ones. */
484 brw_push_insn_state(p
);
485 brw_set_mask_control(p
, BRW_MASK_DISABLE
);
486 brw_MOV(p
, f0
, brw_imm_uw(0xffff));
487 brw_pop_insn_state(p
);
489 /* Do a comparison that should always fail, to produce 0s in the flag
490 * reg where we have active channels.
492 some_register
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
493 brw_CMP(p
, retype(brw_null_reg(), BRW_REGISTER_TYPE_UD
),
494 BRW_CONDITIONAL_NZ
, some_register
, some_register
);
496 /* Undo CMP's whacking of predication*/
497 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
499 brw_push_insn_state(p
);
500 brw_set_mask_control(p
, BRW_MASK_DISABLE
);
501 brw_AND(p
, g1
, f0
, g1
);
502 brw_pop_insn_state(p
);
504 struct brw_reg g0
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
506 brw_push_insn_state(p
);
507 brw_set_mask_control(p
, BRW_MASK_DISABLE
);
508 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
510 /* Unlike the 965, we have the mask reg, so we just need
511 * somewhere to invert that (containing channels to be disabled)
512 * so it can be ANDed with the mask of pixels still to be
513 * written. Use the flag reg for consistency with gen6+.
515 brw_NOT(p
, f0
, brw_mask_reg(1)); /* IMASK */
516 brw_AND(p
, g0
, f0
, g0
);
518 brw_pop_insn_state(p
);
523 fs_visitor::generate_spill(fs_inst
*inst
, struct brw_reg src
)
525 assert(inst
->mlen
!= 0);
528 retype(brw_message_reg(inst
->base_mrf
+ 1), BRW_REGISTER_TYPE_UD
),
529 retype(src
, BRW_REGISTER_TYPE_UD
));
530 brw_oword_block_write_scratch(p
, brw_message_reg(inst
->base_mrf
), 1,
535 fs_visitor::generate_unspill(fs_inst
*inst
, struct brw_reg dst
)
537 assert(inst
->mlen
!= 0);
539 /* Clear any post destination dependencies that would be ignored by
540 * the block read. See the B-Spec for pre-gen5 send instruction.
542 * This could use a better solution, since texture sampling and
543 * math reads could potentially run into it as well -- anywhere
544 * that we have a SEND with a destination that is a register that
545 * was written but not read within the last N instructions (what's
546 * N? unsure). This is rare because of dead code elimination, but
549 if (intel
->gen
== 4 && !intel
->is_g4x
)
550 brw_MOV(p
, brw_null_reg(), dst
);
552 brw_oword_block_read_scratch(p
, dst
, brw_message_reg(inst
->base_mrf
), 1,
555 if (intel
->gen
== 4 && !intel
->is_g4x
) {
556 /* gen4 errata: destination from a send can't be used as a
557 * destination until it's been read. Just read it so we don't
560 brw_MOV(p
, brw_null_reg(), dst
);
565 fs_visitor::generate_pull_constant_load(fs_inst
*inst
, struct brw_reg dst
)
567 assert(inst
->mlen
!= 0);
569 /* Clear any post destination dependencies that would be ignored by
570 * the block read. See the B-Spec for pre-gen5 send instruction.
572 * This could use a better solution, since texture sampling and
573 * math reads could potentially run into it as well -- anywhere
574 * that we have a SEND with a destination that is a register that
575 * was written but not read within the last N instructions (what's
576 * N? unsure). This is rare because of dead code elimination, but
579 if (intel
->gen
== 4 && !intel
->is_g4x
)
580 brw_MOV(p
, brw_null_reg(), dst
);
582 brw_oword_block_read(p
, dst
, brw_message_reg(inst
->base_mrf
),
583 inst
->offset
, SURF_INDEX_FRAG_CONST_BUFFER
);
585 if (intel
->gen
== 4 && !intel
->is_g4x
) {
586 /* gen4 errata: destination from a send can't be used as a
587 * destination until it's been read. Just read it so we don't
590 brw_MOV(p
, brw_null_reg(), dst
);
596 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
597 * into the flags register (f0.0).
599 * Used only on Gen6 and above.
602 fs_visitor::generate_mov_dispatch_to_flags()
604 struct brw_reg f0
= brw_flag_reg();
605 struct brw_reg g1
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
607 assert (intel
->gen
>= 6);
608 brw_push_insn_state(p
);
609 brw_set_mask_control(p
, BRW_MASK_DISABLE
);
611 brw_pop_insn_state(p
);
615 static uint32_t brw_file_from_reg(fs_reg
*reg
)
619 return BRW_ARCHITECTURE_REGISTER_FILE
;
621 return BRW_GENERAL_REGISTER_FILE
;
623 return BRW_MESSAGE_REGISTER_FILE
;
625 return BRW_IMMEDIATE_VALUE
;
627 assert(!"not reached");
628 return BRW_GENERAL_REGISTER_FILE
;
632 static struct brw_reg
633 brw_reg_from_fs_reg(fs_reg
*reg
)
635 struct brw_reg brw_reg
;
641 if (reg
->smear
== -1) {
642 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
644 brw_reg
= brw_vec1_reg(brw_file_from_reg(reg
), reg
->reg
, reg
->smear
);
646 brw_reg
= retype(brw_reg
, reg
->type
);
648 brw_reg
= sechalf(brw_reg
);
652 case BRW_REGISTER_TYPE_F
:
653 brw_reg
= brw_imm_f(reg
->imm
.f
);
655 case BRW_REGISTER_TYPE_D
:
656 brw_reg
= brw_imm_d(reg
->imm
.i
);
658 case BRW_REGISTER_TYPE_UD
:
659 brw_reg
= brw_imm_ud(reg
->imm
.u
);
662 assert(!"not reached");
663 brw_reg
= brw_null_reg();
668 brw_reg
= reg
->fixed_hw_reg
;
671 /* Probably unused. */
672 brw_reg
= brw_null_reg();
675 assert(!"not reached");
676 brw_reg
= brw_null_reg();
679 assert(!"not reached");
680 brw_reg
= brw_null_reg();
684 brw_reg
= brw_abs(brw_reg
);
686 brw_reg
= negate(brw_reg
);
692 fs_visitor::generate_code()
694 int last_native_inst
= p
->nr_insn
;
695 const char *last_annotation_string
= NULL
;
696 ir_instruction
*last_annotation_ir
= NULL
;
698 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
699 printf("Native code for fragment shader %d (%d-wide dispatch):\n",
700 prog
->Name
, c
->dispatch_width
);
704 if (unlikely(INTEL_DEBUG
& DEBUG_WM
))
705 cfg
= new(mem_ctx
) fs_cfg(this);
707 foreach_list(node
, &this->instructions
) {
708 fs_inst
*inst
= (fs_inst
*)node
;
709 struct brw_reg src
[3], dst
;
711 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
712 foreach_list(node
, &cfg
->block_list
) {
713 fs_bblock_link
*link
= (fs_bblock_link
*)node
;
714 fs_bblock
*block
= link
->block
;
716 if (block
->start
== inst
) {
717 printf(" START B%d", block
->block_num
);
718 foreach_list(predecessor_node
, &block
->parents
) {
719 fs_bblock_link
*predecessor_link
=
720 (fs_bblock_link
*)predecessor_node
;
721 fs_bblock
*predecessor_block
= predecessor_link
->block
;
722 printf(" <-B%d", predecessor_block
->block_num
);
728 if (last_annotation_ir
!= inst
->ir
) {
729 last_annotation_ir
= inst
->ir
;
730 if (last_annotation_ir
) {
732 last_annotation_ir
->print();
736 if (last_annotation_string
!= inst
->annotation
) {
737 last_annotation_string
= inst
->annotation
;
738 if (last_annotation_string
)
739 printf(" %s\n", last_annotation_string
);
743 for (unsigned int i
= 0; i
< 3; i
++) {
744 src
[i
] = brw_reg_from_fs_reg(&inst
->src
[i
]);
746 /* The accumulator result appears to get used for the
747 * conditional modifier generation. When negating a UD
748 * value, there is a 33rd bit generated for the sign in the
749 * accumulator value, so now you can't check, for example,
750 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
752 assert(!inst
->conditional_mod
||
753 inst
->src
[i
].type
!= BRW_REGISTER_TYPE_UD
||
754 !inst
->src
[i
].negate
);
756 dst
= brw_reg_from_fs_reg(&inst
->dst
);
758 brw_set_conditionalmod(p
, inst
->conditional_mod
);
759 brw_set_predicate_control(p
, inst
->predicated
);
760 brw_set_predicate_inverse(p
, inst
->predicate_inverse
);
761 brw_set_saturate(p
, inst
->saturate
);
763 if (inst
->force_uncompressed
|| c
->dispatch_width
== 8) {
764 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
765 } else if (inst
->force_sechalf
) {
766 brw_set_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
768 brw_set_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
771 switch (inst
->opcode
) {
773 brw_MOV(p
, dst
, src
[0]);
776 brw_ADD(p
, dst
, src
[0], src
[1]);
779 brw_MUL(p
, dst
, src
[0], src
[1]);
781 case BRW_OPCODE_MACH
:
782 brw_set_acc_write_control(p
, 1);
783 brw_MACH(p
, dst
, src
[0], src
[1]);
784 brw_set_acc_write_control(p
, 0);
788 brw_set_access_mode(p
, BRW_ALIGN_16
);
789 if (c
->dispatch_width
== 16) {
790 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
791 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
792 brw_set_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
793 brw_MAD(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
794 brw_set_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
796 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
798 brw_set_access_mode(p
, BRW_ALIGN_1
);
802 brw_FRC(p
, dst
, src
[0]);
804 case BRW_OPCODE_RNDD
:
805 brw_RNDD(p
, dst
, src
[0]);
807 case BRW_OPCODE_RNDE
:
808 brw_RNDE(p
, dst
, src
[0]);
810 case BRW_OPCODE_RNDZ
:
811 brw_RNDZ(p
, dst
, src
[0]);
815 brw_AND(p
, dst
, src
[0], src
[1]);
818 brw_OR(p
, dst
, src
[0], src
[1]);
821 brw_XOR(p
, dst
, src
[0], src
[1]);
824 brw_NOT(p
, dst
, src
[0]);
827 brw_ASR(p
, dst
, src
[0], src
[1]);
830 brw_SHR(p
, dst
, src
[0], src
[1]);
833 brw_SHL(p
, dst
, src
[0], src
[1]);
837 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
840 brw_SEL(p
, dst
, src
[0], src
[1]);
844 if (inst
->src
[0].file
!= BAD_FILE
) {
845 /* The instruction has an embedded compare (only allowed on gen6) */
846 assert(intel
->gen
== 6);
847 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
849 brw_IF(p
, c
->dispatch_width
== 16 ? BRW_EXECUTE_16
: BRW_EXECUTE_8
);
853 case BRW_OPCODE_ELSE
:
856 case BRW_OPCODE_ENDIF
:
861 brw_DO(p
, BRW_EXECUTE_8
);
864 case BRW_OPCODE_BREAK
:
866 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
868 case BRW_OPCODE_CONTINUE
:
869 /* FINISHME: We need to write the loop instruction support still. */
874 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
877 case BRW_OPCODE_WHILE
:
881 case SHADER_OPCODE_RCP
:
882 case SHADER_OPCODE_RSQ
:
883 case SHADER_OPCODE_SQRT
:
884 case SHADER_OPCODE_EXP2
:
885 case SHADER_OPCODE_LOG2
:
886 case SHADER_OPCODE_SIN
:
887 case SHADER_OPCODE_COS
:
888 if (intel
->gen
>= 7) {
889 generate_math1_gen7(inst
, dst
, src
[0]);
890 } else if (intel
->gen
== 6) {
891 generate_math1_gen6(inst
, dst
, src
[0]);
893 generate_math_gen4(inst
, dst
, src
[0]);
896 case SHADER_OPCODE_INT_QUOTIENT
:
897 case SHADER_OPCODE_INT_REMAINDER
:
898 case SHADER_OPCODE_POW
:
899 if (intel
->gen
>= 7) {
900 generate_math2_gen7(inst
, dst
, src
[0], src
[1]);
901 } else if (intel
->gen
== 6) {
902 generate_math2_gen6(inst
, dst
, src
[0], src
[1]);
904 generate_math_gen4(inst
, dst
, src
[0]);
907 case FS_OPCODE_PIXEL_X
:
908 generate_pixel_xy(dst
, true);
910 case FS_OPCODE_PIXEL_Y
:
911 generate_pixel_xy(dst
, false);
913 case FS_OPCODE_CINTERP
:
914 brw_MOV(p
, dst
, src
[0]);
916 case FS_OPCODE_LINTERP
:
917 generate_linterp(inst
, dst
, src
);
919 case SHADER_OPCODE_TEX
:
921 case SHADER_OPCODE_TXD
:
922 case SHADER_OPCODE_TXF
:
923 case SHADER_OPCODE_TXL
:
924 case SHADER_OPCODE_TXS
:
925 generate_tex(inst
, dst
, src
[0]);
927 case FS_OPCODE_DISCARD
:
928 generate_discard(inst
);
931 generate_ddx(inst
, dst
, src
[0]);
934 /* Make sure fp->UsesDFdy flag got set (otherwise there's no
935 * guarantee that c->key.render_to_fbo is set).
937 assert(fp
->UsesDFdy
);
938 generate_ddy(inst
, dst
, src
[0], c
->key
.render_to_fbo
);
941 case FS_OPCODE_SPILL
:
942 generate_spill(inst
, src
[0]);
945 case FS_OPCODE_UNSPILL
:
946 generate_unspill(inst
, dst
);
949 case FS_OPCODE_PULL_CONSTANT_LOAD
:
950 generate_pull_constant_load(inst
, dst
);
953 case FS_OPCODE_FB_WRITE
:
954 generate_fb_write(inst
);
957 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS
:
958 generate_mov_dispatch_to_flags();
962 if (inst
->opcode
< (int)ARRAY_SIZE(brw_opcodes
)) {
963 _mesa_problem(ctx
, "Unsupported opcode `%s' in FS",
964 brw_opcodes
[inst
->opcode
].name
);
966 _mesa_problem(ctx
, "Unsupported opcode %d in FS", inst
->opcode
);
968 fail("unsupported opcode in FS\n");
971 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
972 for (unsigned int i
= last_native_inst
; i
< p
->nr_insn
; i
++) {
974 printf("0x%08x 0x%08x 0x%08x 0x%08x ",
975 ((uint32_t *)&p
->store
[i
])[3],
976 ((uint32_t *)&p
->store
[i
])[2],
977 ((uint32_t *)&p
->store
[i
])[1],
978 ((uint32_t *)&p
->store
[i
])[0]);
980 brw_disasm(stdout
, &p
->store
[i
], intel
->gen
);
983 foreach_list(node
, &cfg
->block_list
) {
984 fs_bblock_link
*link
= (fs_bblock_link
*)node
;
985 fs_bblock
*block
= link
->block
;
987 if (block
->end
== inst
) {
988 printf(" END B%d", block
->block_num
);
989 foreach_list(successor_node
, &block
->children
) {
990 fs_bblock_link
*successor_link
=
991 (fs_bblock_link
*)successor_node
;
992 fs_bblock
*successor_block
= successor_link
->block
;
993 printf(" ->B%d", successor_block
->block_num
);
1000 last_native_inst
= p
->nr_insn
;
1003 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
1009 /* OK, while the INTEL_DEBUG=wm above is very nice for debugging FS
1010 * emit issues, it doesn't get the jump distances into the output,
1011 * which is often something we want to debug. So this is here in
1012 * case you're doing that.
1015 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
1016 for (unsigned int i
= 0; i
< p
->nr_insn
; i
++) {
1017 printf("0x%08x 0x%08x 0x%08x 0x%08x ",
1018 ((uint32_t *)&p
->store
[i
])[3],
1019 ((uint32_t *)&p
->store
[i
])[2],
1020 ((uint32_t *)&p
->store
[i
])[1],
1021 ((uint32_t *)&p
->store
[i
])[0]);
1022 brw_disasm(stdout
, &p
->store
[i
], intel
->gen
);