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_generator.cpp
26 * This file supports generating code from the FS LIR to the actual
27 * native instructions.
31 #include "main/macros.h"
32 #include "brw_context.h"
39 static uint32_t brw_file_from_reg(fs_reg
*reg
)
43 return BRW_GENERAL_REGISTER_FILE
;
45 return BRW_MESSAGE_REGISTER_FILE
;
47 return BRW_IMMEDIATE_VALUE
;
49 unreachable("not reached");
54 brw_reg_from_fs_reg(fs_reg
*reg
)
56 struct brw_reg brw_reg
;
61 if (reg
->stride
== 0) {
62 brw_reg
= brw_vec1_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
63 } else if (reg
->width
< 8) {
64 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
65 brw_reg
= stride(brw_reg
, reg
->width
* reg
->stride
,
66 reg
->width
, reg
->stride
);
68 /* From the Haswell PRM:
70 * VertStride must be used to cross GRF register boundaries. This
71 * rule implies that elements within a 'Width' cannot cross GRF
74 * So, for registers with width > 8, we have to use a width of 8
75 * and trust the compression state to sort out the exec size.
77 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
78 brw_reg
= stride(brw_reg
, 8 * reg
->stride
, 8, reg
->stride
);
81 brw_reg
= retype(brw_reg
, reg
->type
);
82 brw_reg
= byte_offset(brw_reg
, reg
->subreg_offset
);
86 case BRW_REGISTER_TYPE_F
:
87 brw_reg
= brw_imm_f(reg
->fixed_hw_reg
.dw1
.f
);
89 case BRW_REGISTER_TYPE_D
:
90 brw_reg
= brw_imm_d(reg
->fixed_hw_reg
.dw1
.d
);
92 case BRW_REGISTER_TYPE_UD
:
93 brw_reg
= brw_imm_ud(reg
->fixed_hw_reg
.dw1
.ud
);
95 case BRW_REGISTER_TYPE_W
:
96 brw_reg
= brw_imm_w(reg
->fixed_hw_reg
.dw1
.d
);
98 case BRW_REGISTER_TYPE_UW
:
99 brw_reg
= brw_imm_uw(reg
->fixed_hw_reg
.dw1
.ud
);
101 case BRW_REGISTER_TYPE_VF
:
102 brw_reg
= brw_imm_vf(reg
->fixed_hw_reg
.dw1
.ud
);
105 unreachable("not reached");
109 assert(reg
->type
== reg
->fixed_hw_reg
.type
);
110 brw_reg
= reg
->fixed_hw_reg
;
113 /* Probably unused. */
114 brw_reg
= brw_null_reg();
117 unreachable("not reached");
120 brw_reg
= brw_abs(brw_reg
);
122 brw_reg
= negate(brw_reg
);
127 fs_generator::fs_generator(struct brw_context
*brw
,
130 struct brw_stage_prog_data
*prog_data
,
131 struct gl_program
*prog
,
132 bool runtime_check_aads_emit
,
133 const char *stage_abbrev
)
135 : brw(brw
), key(key
),
136 prog_data(prog_data
),
137 prog(prog
), runtime_check_aads_emit(runtime_check_aads_emit
),
138 debug_flag(false), stage_abbrev(stage_abbrev
), mem_ctx(mem_ctx
)
142 p
= rzalloc(mem_ctx
, struct brw_compile
);
143 brw_init_compile(brw
, p
, mem_ctx
);
146 fs_generator::~fs_generator()
150 class ip_record
: public exec_node
{
152 DECLARE_RALLOC_CXX_OPERATORS(ip_record
)
163 fs_generator::patch_discard_jumps_to_fb_writes()
165 if (brw
->gen
< 6 || this->discard_halt_patches
.is_empty())
168 int scale
= brw_jump_scale(brw
);
170 /* There is a somewhat strange undocumented requirement of using
171 * HALT, according to the simulator. If some channel has HALTed to
172 * a particular UIP, then by the end of the program, every channel
173 * must have HALTed to that UIP. Furthermore, the tracking is a
174 * stack, so you can't do the final halt of a UIP after starting
175 * halting to a new UIP.
177 * Symptoms of not emitting this instruction on actual hardware
178 * included GPU hangs and sparkly rendering on the piglit discard
181 brw_inst
*last_halt
= gen6_HALT(p
);
182 brw_inst_set_uip(brw
, last_halt
, 1 * scale
);
183 brw_inst_set_jip(brw
, last_halt
, 1 * scale
);
187 foreach_in_list(ip_record
, patch_ip
, &discard_halt_patches
) {
188 brw_inst
*patch
= &p
->store
[patch_ip
->ip
];
190 assert(brw_inst_opcode(brw
, patch
) == BRW_OPCODE_HALT
);
191 /* HALT takes a half-instruction distance from the pre-incremented IP. */
192 brw_inst_set_uip(brw
, patch
, (ip
- patch_ip
->ip
) * scale
);
195 this->discard_halt_patches
.make_empty();
200 fs_generator::fire_fb_write(fs_inst
*inst
,
201 struct brw_reg payload
,
202 struct brw_reg implied_header
,
205 uint32_t msg_control
;
207 brw_wm_prog_data
*prog_data
= (brw_wm_prog_data
*) this->prog_data
;
210 brw_push_insn_state(p
);
211 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
212 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
213 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
214 brw_MOV(p
, offset(payload
, 1), brw_vec8_grf(1, 0));
215 brw_pop_insn_state(p
);
218 if (inst
->opcode
== FS_OPCODE_REP_FB_WRITE
)
219 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED
;
220 else if (prog_data
->dual_src_blend
)
221 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01
;
222 else if (dispatch_width
== 16)
223 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
;
225 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01
;
227 uint32_t surf_index
=
228 prog_data
->binding_table
.render_target_start
+ inst
->target
;
239 inst
->header_present
);
241 brw_mark_surface_used(&prog_data
->base
, surf_index
);
245 fs_generator::generate_fb_write(fs_inst
*inst
, struct brw_reg payload
)
247 brw_wm_prog_data
*prog_data
= (brw_wm_prog_data
*) this->prog_data
;
248 const brw_wm_prog_key
* const key
= (brw_wm_prog_key
* const) this->key
;
249 struct brw_reg implied_header
;
251 if (brw
->gen
< 8 && !brw
->is_haswell
) {
252 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
255 if (inst
->base_mrf
>= 0)
256 payload
= brw_message_reg(inst
->base_mrf
);
258 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
261 if (inst
->header_present
) {
262 brw_push_insn_state(p
);
263 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
264 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
265 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
266 brw_set_default_flag_reg(p
, 0, 0);
268 /* On HSW, the GPU will use the predicate on SENDC, unless the header is
271 if (prog_data
->uses_kill
) {
272 struct brw_reg pixel_mask
;
275 pixel_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
277 pixel_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
279 brw_MOV(p
, pixel_mask
, brw_flag_reg(0, 1));
283 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
285 retype(payload
, BRW_REGISTER_TYPE_UD
),
286 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
287 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
289 if (inst
->target
> 0 && key
->replicate_alpha
) {
290 /* Set "Source0 Alpha Present to RenderTarget" bit in message
294 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
295 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
296 brw_imm_ud(0x1 << 11));
299 if (inst
->target
> 0) {
300 /* Set the render target index for choosing BLEND_STATE. */
301 brw_MOV(p
, retype(vec1(suboffset(payload
, 2)),
302 BRW_REGISTER_TYPE_UD
),
303 brw_imm_ud(inst
->target
));
306 implied_header
= brw_null_reg();
308 implied_header
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
311 brw_pop_insn_state(p
);
313 implied_header
= brw_null_reg();
316 if (!runtime_check_aads_emit
) {
317 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
319 /* This can only happen in gen < 6 */
320 assert(brw
->gen
< 6);
322 struct brw_reg v1_null_ud
= vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD
));
324 /* Check runtime bit to detect if we have to send AA data or not */
325 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
328 retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD
),
330 brw_inst_set_cond_modifier(brw
, brw_last_inst
, BRW_CONDITIONAL_NZ
);
332 int jmp
= brw_JMPI(p
, brw_imm_ud(0), BRW_PREDICATE_NORMAL
) - p
->store
;
333 brw_inst_set_exec_size(brw
, brw_last_inst
, BRW_EXECUTE_1
);
335 /* Don't send AA data */
336 fire_fb_write(inst
, offset(payload
, 1), implied_header
, inst
->mlen
-1);
338 brw_land_fwd_jump(p
, jmp
);
339 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
344 fs_generator::generate_urb_write(fs_inst
*inst
, struct brw_reg payload
)
348 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
350 brw_set_dest(p
, insn
, brw_null_reg());
351 brw_set_src0(p
, insn
, payload
);
352 brw_set_src1(p
, insn
, brw_imm_d(0));
354 brw_inst_set_sfid(brw
, insn
, BRW_SFID_URB
);
355 brw_inst_set_urb_opcode(brw
, insn
, GEN8_URB_OPCODE_SIMD8_WRITE
);
357 brw_inst_set_mlen(brw
, insn
, inst
->mlen
);
358 brw_inst_set_rlen(brw
, insn
, 0);
359 brw_inst_set_eot(brw
, insn
, inst
->eot
);
360 brw_inst_set_header_present(brw
, insn
, true);
361 brw_inst_set_urb_global_offset(brw
, insn
, inst
->offset
);
365 fs_generator::generate_blorp_fb_write(fs_inst
*inst
)
368 16 /* dispatch_width */,
369 brw_message_reg(inst
->base_mrf
),
370 brw_reg_from_fs_reg(&inst
->src
[0]),
371 BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
,
376 inst
->header_present
);
379 /* Computes the integer pixel x,y values from the origin.
381 * This is the basis of gl_FragCoord computation, but is also used
382 * pre-gen6 for computing the deltas from v0 for computing
386 fs_generator::generate_pixel_xy(struct brw_reg dst
, bool is_x
)
388 struct brw_reg g1_uw
= retype(brw_vec1_grf(1, 0), BRW_REGISTER_TYPE_UW
);
390 struct brw_reg deltas
;
393 src
= stride(suboffset(g1_uw
, 4), 2, 4, 0);
394 deltas
= brw_imm_v(0x10101010);
396 src
= stride(suboffset(g1_uw
, 5), 2, 4, 0);
397 deltas
= brw_imm_v(0x11001100);
400 if (dispatch_width
== 16) {
404 /* We do this SIMD8 or SIMD16, but since the destination is UW we
405 * don't do compression in the SIMD16 case.
407 brw_push_insn_state(p
);
408 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
409 brw_ADD(p
, dst
, src
, deltas
);
410 brw_pop_insn_state(p
);
414 fs_generator::generate_linterp(fs_inst
*inst
,
415 struct brw_reg dst
, struct brw_reg
*src
)
417 struct brw_reg delta_x
= src
[0];
418 struct brw_reg delta_y
= src
[1];
419 struct brw_reg interp
= src
[2];
422 delta_y
.nr
== delta_x
.nr
+ 1 &&
423 (brw
->gen
>= 6 || (delta_x
.nr
& 1) == 0)) {
424 brw_PLN(p
, dst
, interp
, delta_x
);
426 brw_LINE(p
, brw_null_reg(), interp
, delta_x
);
427 brw_MAC(p
, dst
, suboffset(interp
, 1), delta_y
);
432 fs_generator::generate_math_gen6(fs_inst
*inst
,
437 int op
= brw_math_function(inst
->opcode
);
438 bool binop
= src1
.file
!= BRW_ARCHITECTURE_REGISTER_FILE
;
440 if (dispatch_width
== 8) {
441 gen6_math(p
, dst
, op
, src0
, src1
);
442 } else if (dispatch_width
== 16) {
443 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
444 gen6_math(p
, firsthalf(dst
), op
, firsthalf(src0
), firsthalf(src1
));
445 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
446 gen6_math(p
, sechalf(dst
), op
, sechalf(src0
),
447 binop
? sechalf(src1
) : brw_null_reg());
448 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
453 fs_generator::generate_math_gen4(fs_inst
*inst
,
457 int op
= brw_math_function(inst
->opcode
);
459 assert(inst
->mlen
>= 1);
461 if (dispatch_width
== 8) {
465 BRW_MATH_PRECISION_FULL
);
466 } else if (dispatch_width
== 16) {
467 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
468 gen4_math(p
, firsthalf(dst
),
470 inst
->base_mrf
, firsthalf(src
),
471 BRW_MATH_PRECISION_FULL
);
472 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
473 gen4_math(p
, sechalf(dst
),
475 inst
->base_mrf
+ 1, sechalf(src
),
476 BRW_MATH_PRECISION_FULL
);
478 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
483 fs_generator::generate_math_g45(fs_inst
*inst
,
487 if (inst
->opcode
== SHADER_OPCODE_POW
||
488 inst
->opcode
== SHADER_OPCODE_INT_QUOTIENT
||
489 inst
->opcode
== SHADER_OPCODE_INT_REMAINDER
) {
490 generate_math_gen4(inst
, dst
, src
);
494 int op
= brw_math_function(inst
->opcode
);
496 assert(inst
->mlen
>= 1);
501 BRW_MATH_PRECISION_FULL
);
505 fs_generator::generate_tex(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
,
506 struct brw_reg sampler_index
)
511 uint32_t return_format
;
514 case BRW_REGISTER_TYPE_D
:
515 return_format
= BRW_SAMPLER_RETURN_FORMAT_SINT32
;
517 case BRW_REGISTER_TYPE_UD
:
518 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
521 return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
525 switch (inst
->exec_size
) {
527 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
530 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
533 unreachable("Invalid width for texture instruction");
537 switch (inst
->opcode
) {
538 case SHADER_OPCODE_TEX
:
539 if (inst
->shadow_compare
) {
540 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE
;
542 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE
;
546 if (inst
->shadow_compare
) {
547 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE
;
549 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS
;
552 case SHADER_OPCODE_TXL
:
553 if (inst
->shadow_compare
) {
554 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE
;
556 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD
;
559 case SHADER_OPCODE_TXS
:
560 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
;
562 case SHADER_OPCODE_TXD
:
563 if (inst
->shadow_compare
) {
564 /* Gen7.5+. Otherwise, lowered by brw_lower_texture_gradients(). */
565 assert(brw
->gen
>= 8 || brw
->is_haswell
);
566 msg_type
= HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE
;
568 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS
;
571 case SHADER_OPCODE_TXF
:
572 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
574 case SHADER_OPCODE_TXF_CMS
:
576 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS
;
578 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
580 case SHADER_OPCODE_TXF_UMS
:
581 assert(brw
->gen
>= 7);
582 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS
;
584 case SHADER_OPCODE_TXF_MCS
:
585 assert(brw
->gen
>= 7);
586 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS
;
588 case SHADER_OPCODE_LOD
:
589 msg_type
= GEN5_SAMPLER_MESSAGE_LOD
;
591 case SHADER_OPCODE_TG4
:
592 if (inst
->shadow_compare
) {
593 assert(brw
->gen
>= 7);
594 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C
;
596 assert(brw
->gen
>= 6);
597 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4
;
600 case SHADER_OPCODE_TG4_OFFSET
:
601 assert(brw
->gen
>= 7);
602 if (inst
->shadow_compare
) {
603 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C
;
605 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO
;
609 unreachable("not reached");
612 switch (inst
->opcode
) {
613 case SHADER_OPCODE_TEX
:
614 /* Note that G45 and older determines shadow compare and dispatch width
615 * from message length for most messages.
617 assert(dispatch_width
== 8);
618 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE
;
619 if (inst
->shadow_compare
) {
620 assert(inst
->mlen
== 6);
622 assert(inst
->mlen
<= 4);
626 if (inst
->shadow_compare
) {
627 assert(inst
->mlen
== 6);
628 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE
;
630 assert(inst
->mlen
== 9);
631 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS
;
632 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
635 case SHADER_OPCODE_TXL
:
636 if (inst
->shadow_compare
) {
637 assert(inst
->mlen
== 6);
638 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE
;
640 assert(inst
->mlen
== 9);
641 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD
;
642 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
645 case SHADER_OPCODE_TXD
:
646 /* There is no sample_d_c message; comparisons are done manually */
647 assert(inst
->mlen
== 7 || inst
->mlen
== 10);
648 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS
;
650 case SHADER_OPCODE_TXF
:
651 assert(inst
->mlen
== 9);
652 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
653 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
655 case SHADER_OPCODE_TXS
:
656 assert(inst
->mlen
== 3);
657 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_RESINFO
;
658 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
661 unreachable("not reached");
664 assert(msg_type
!= -1);
666 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
671 assert(brw
->gen
< 7 || !inst
->header_present
||
672 src
.file
== BRW_GENERAL_REGISTER_FILE
);
674 assert(sampler_index
.type
== BRW_REGISTER_TYPE_UD
);
676 /* Load the message header if present. If there's a texture offset,
677 * we need to set it up explicitly and load the offset bitfield.
678 * Otherwise, we can use an implied move from g0 to the first message reg.
680 if (inst
->header_present
) {
681 if (brw
->gen
< 6 && !inst
->offset
) {
682 /* Set up an implied move from g0 to the MRF. */
683 src
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
685 struct brw_reg header_reg
;
690 assert(inst
->base_mrf
!= -1);
691 header_reg
= brw_message_reg(inst
->base_mrf
);
694 brw_push_insn_state(p
);
695 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
696 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
697 /* Explicitly set up the message header by copying g0 to the MRF. */
698 brw_MOV(p
, header_reg
, brw_vec8_grf(0, 0));
701 /* Set the offset bits in DWord 2. */
702 brw_MOV(p
, get_element_ud(header_reg
, 2),
703 brw_imm_ud(inst
->offset
));
706 brw_adjust_sampler_state_pointer(p
, header_reg
, sampler_index
);
707 brw_pop_insn_state(p
);
711 uint32_t base_binding_table_index
= (inst
->opcode
== SHADER_OPCODE_TG4
||
712 inst
->opcode
== SHADER_OPCODE_TG4_OFFSET
)
713 ? prog_data
->binding_table
.gather_texture_start
714 : prog_data
->binding_table
.texture_start
;
716 if (sampler_index
.file
== BRW_IMMEDIATE_VALUE
) {
717 uint32_t sampler
= sampler_index
.dw1
.ud
;
720 retype(dst
, BRW_REGISTER_TYPE_UW
),
723 sampler
+ base_binding_table_index
,
728 inst
->header_present
,
732 brw_mark_surface_used(prog_data
, sampler
+ base_binding_table_index
);
734 /* Non-const sampler index */
735 /* Note: this clobbers `dst` as a temporary before emitting the send */
737 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
738 struct brw_reg temp
= vec1(retype(dst
, BRW_REGISTER_TYPE_UD
));
740 struct brw_reg sampler_reg
= vec1(retype(sampler_index
, BRW_REGISTER_TYPE_UD
));
742 brw_push_insn_state(p
);
743 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
744 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
746 /* Some care required: `sampler` and `temp` may alias:
747 * addr = sampler & 0xff
748 * temp = (sampler << 8) & 0xf00
751 brw_ADD(p
, addr
, sampler_reg
, brw_imm_ud(base_binding_table_index
));
752 brw_SHL(p
, temp
, sampler_reg
, brw_imm_ud(8u));
753 brw_AND(p
, temp
, temp
, brw_imm_ud(0x0f00));
754 brw_AND(p
, addr
, addr
, brw_imm_ud(0x0ff));
755 brw_OR(p
, addr
, addr
, temp
);
757 /* a0.0 |= <descriptor> */
758 brw_inst
*insn_or
= brw_next_insn(p
, BRW_OPCODE_OR
);
759 brw_set_sampler_message(p
, insn_or
,
764 inst
->mlen
/* mlen */,
765 inst
->header_present
/* header */,
768 brw_inst_set_exec_size(p
->brw
, insn_or
, BRW_EXECUTE_1
);
769 brw_inst_set_src1_reg_type(p
->brw
, insn_or
, BRW_REGISTER_TYPE_UD
);
770 brw_set_src0(p
, insn_or
, addr
);
771 brw_set_dest(p
, insn_or
, addr
);
774 /* dst = send(offset, a0.0) */
775 brw_inst
*insn_send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
776 brw_set_dest(p
, insn_send
, dst
);
777 brw_set_src0(p
, insn_send
, src
);
778 brw_set_indirect_send_descriptor(p
, insn_send
, BRW_SFID_SAMPLER
, addr
);
780 brw_pop_insn_state(p
);
782 /* visitor knows more than we do about the surface limit required,
783 * so has already done marking.
789 /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
792 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
794 * Ideally, we want to produce:
797 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
798 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
799 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
800 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
801 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
802 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
803 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
804 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
806 * and add another set of two more subspans if in 16-pixel dispatch mode.
808 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
809 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
810 * pair. But the ideal approximation may impose a huge performance cost on
811 * sample_d. On at least Haswell, sample_d instruction does some
812 * optimizations if the same LOD is used for all pixels in the subspan.
814 * For DDY, we need to use ALIGN16 mode since it's capable of doing the
815 * appropriate swizzling.
818 fs_generator::generate_ddx(enum opcode opcode
,
819 struct brw_reg dst
, struct brw_reg src
)
821 unsigned vstride
, width
;
823 if (opcode
== FS_OPCODE_DDX_FINE
) {
824 /* produce accurate derivatives */
825 vstride
= BRW_VERTICAL_STRIDE_2
;
828 /* replicate the derivative at the top-left pixel to other pixels */
829 vstride
= BRW_VERTICAL_STRIDE_4
;
833 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 1,
838 BRW_HORIZONTAL_STRIDE_0
,
839 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
840 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
845 BRW_HORIZONTAL_STRIDE_0
,
846 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
847 brw_ADD(p
, dst
, src0
, negate(src1
));
850 /* The negate_value boolean is used to negate the derivative computation for
851 * FBOs, since they place the origin at the upper left instead of the lower
855 fs_generator::generate_ddy(enum opcode opcode
,
856 struct brw_reg dst
, struct brw_reg src
,
859 if (opcode
== FS_OPCODE_DDY_FINE
) {
860 /* From the Ivy Bridge PRM, volume 4 part 3, section 3.3.9 (Register
861 * Region Restrictions):
863 * In Align16 access mode, SIMD16 is not allowed for DW operations
864 * and SIMD8 is not allowed for DF operations.
866 * In this context, "DW operations" means "operations acting on 32-bit
867 * values", so it includes operations on floats.
869 * Gen4 has a similar restriction. From the i965 PRM, section 11.5.3
870 * (Instruction Compression -> Rules and Restrictions):
872 * A compressed instruction must be in Align1 access mode. Align16
873 * mode instructions cannot be compressed.
875 * Similar text exists in the g45 PRM.
877 * On these platforms, if we're building a SIMD16 shader, we need to
878 * manually unroll to a pair of SIMD8 instructions.
880 bool unroll_to_simd8
=
881 (dispatch_width
== 16 &&
882 (brw
->gen
== 4 || (brw
->gen
== 7 && !brw
->is_haswell
)));
884 /* produce accurate derivatives */
885 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
888 BRW_VERTICAL_STRIDE_4
,
890 BRW_HORIZONTAL_STRIDE_1
,
891 BRW_SWIZZLE_XYXY
, WRITEMASK_XYZW
);
892 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
895 BRW_VERTICAL_STRIDE_4
,
897 BRW_HORIZONTAL_STRIDE_1
,
898 BRW_SWIZZLE_ZWZW
, WRITEMASK_XYZW
);
899 brw_push_insn_state(p
);
900 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
901 if (unroll_to_simd8
) {
902 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
904 brw_ADD(p
, firsthalf(dst
), firsthalf(src1
), negate(firsthalf(src0
)));
905 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
906 brw_ADD(p
, sechalf(dst
), sechalf(src1
), negate(sechalf(src0
)));
908 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), negate(firsthalf(src1
)));
909 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
910 brw_ADD(p
, sechalf(dst
), sechalf(src0
), negate(sechalf(src1
)));
914 brw_ADD(p
, dst
, src1
, negate(src0
));
916 brw_ADD(p
, dst
, src0
, negate(src1
));
918 brw_pop_insn_state(p
);
920 /* replicate the derivative at the top-left pixel to other pixels */
921 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
924 BRW_VERTICAL_STRIDE_4
,
926 BRW_HORIZONTAL_STRIDE_0
,
927 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
928 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 2,
931 BRW_VERTICAL_STRIDE_4
,
933 BRW_HORIZONTAL_STRIDE_0
,
934 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
936 brw_ADD(p
, dst
, src1
, negate(src0
));
938 brw_ADD(p
, dst
, src0
, negate(src1
));
943 fs_generator::generate_discard_jump(fs_inst
*inst
)
945 assert(brw
->gen
>= 6);
947 /* This HALT will be patched up at FB write time to point UIP at the end of
948 * the program, and at brw_uip_jip() JIP will be set to the end of the
949 * current block (or the program).
951 this->discard_halt_patches
.push_tail(new(mem_ctx
) ip_record(p
->nr_insn
));
953 brw_push_insn_state(p
);
954 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
956 brw_pop_insn_state(p
);
960 fs_generator::generate_scratch_write(fs_inst
*inst
, struct brw_reg src
)
962 assert(inst
->mlen
!= 0);
965 brw_uvec_mrf(inst
->exec_size
, (inst
->base_mrf
+ 1), 0),
966 retype(src
, BRW_REGISTER_TYPE_UD
));
967 brw_oword_block_write_scratch(p
, brw_message_reg(inst
->base_mrf
),
968 inst
->exec_size
/ 8, inst
->offset
);
972 fs_generator::generate_scratch_read(fs_inst
*inst
, struct brw_reg dst
)
974 assert(inst
->mlen
!= 0);
976 brw_oword_block_read_scratch(p
, dst
, brw_message_reg(inst
->base_mrf
),
977 inst
->exec_size
/ 8, inst
->offset
);
981 fs_generator::generate_scratch_read_gen7(fs_inst
*inst
, struct brw_reg dst
)
983 gen7_block_read_scratch(p
, dst
, inst
->exec_size
/ 8, inst
->offset
);
987 fs_generator::generate_uniform_pull_constant_load(fs_inst
*inst
,
989 struct brw_reg index
,
990 struct brw_reg offset
)
992 assert(inst
->mlen
!= 0);
994 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
995 index
.type
== BRW_REGISTER_TYPE_UD
);
996 uint32_t surf_index
= index
.dw1
.ud
;
998 assert(offset
.file
== BRW_IMMEDIATE_VALUE
&&
999 offset
.type
== BRW_REGISTER_TYPE_UD
);
1000 uint32_t read_offset
= offset
.dw1
.ud
;
1002 brw_oword_block_read(p
, dst
, brw_message_reg(inst
->base_mrf
),
1003 read_offset
, surf_index
);
1005 brw_mark_surface_used(prog_data
, surf_index
);
1009 fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst
*inst
,
1011 struct brw_reg index
,
1012 struct brw_reg offset
)
1014 assert(inst
->mlen
== 0);
1015 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1017 assert(offset
.file
== BRW_GENERAL_REGISTER_FILE
);
1018 /* Reference just the dword we need, to avoid angering validate_reg(). */
1019 offset
= brw_vec1_grf(offset
.nr
, 0);
1021 /* We use the SIMD4x2 mode because we want to end up with 4 components in
1022 * the destination loaded consecutively from the same offset (which appears
1023 * in the first component, and the rest are ignored).
1025 dst
.width
= BRW_WIDTH_4
;
1027 struct brw_reg src
= offset
;
1028 bool header_present
= false;
1031 if (brw
->gen
>= 9) {
1032 /* Skylake requires a message header in order to use SIMD4x2 mode. */
1033 src
= retype(brw_vec4_grf(offset
.nr
- 1, 0), BRW_REGISTER_TYPE_UD
);
1035 header_present
= true;
1037 brw_push_insn_state(p
);
1038 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1039 brw_MOV(p
, src
, retype(brw_vec4_grf(0, 0), BRW_REGISTER_TYPE_UD
));
1040 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1042 brw_MOV(p
, get_element_ud(src
, 2),
1043 brw_imm_ud(GEN9_SAMPLER_SIMD_MODE_EXTENSION_SIMD4X2
));
1044 brw_pop_insn_state(p
);
1047 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1049 uint32_t surf_index
= index
.dw1
.ud
;
1051 brw_push_insn_state(p
);
1052 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1053 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1054 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1055 brw_pop_insn_state(p
);
1057 brw_set_dest(p
, send
, dst
);
1058 brw_set_src0(p
, send
, src
);
1059 brw_set_sampler_message(p
, send
,
1061 0, /* LD message ignores sampler unit */
1062 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1066 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
1069 brw_mark_surface_used(prog_data
, surf_index
);
1073 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1075 brw_push_insn_state(p
);
1076 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1077 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1079 /* a0.0 = surf_index & 0xff */
1080 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1081 brw_inst_set_exec_size(p
->brw
, insn_and
, BRW_EXECUTE_1
);
1082 brw_set_dest(p
, insn_and
, addr
);
1083 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1084 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1087 /* a0.0 |= <descriptor> */
1088 brw_inst
*insn_or
= brw_next_insn(p
, BRW_OPCODE_OR
);
1089 brw_set_sampler_message(p
, insn_or
,
1092 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1096 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
1098 brw_inst_set_exec_size(p
->brw
, insn_or
, BRW_EXECUTE_1
);
1099 brw_inst_set_src1_reg_type(p
->brw
, insn_or
, BRW_REGISTER_TYPE_UD
);
1100 brw_set_src0(p
, insn_or
, addr
);
1101 brw_set_dest(p
, insn_or
, addr
);
1104 /* dst = send(offset, a0.0) */
1105 brw_inst
*insn_send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1106 brw_set_dest(p
, insn_send
, dst
);
1107 brw_set_src0(p
, insn_send
, src
);
1108 brw_set_indirect_send_descriptor(p
, insn_send
, BRW_SFID_SAMPLER
, addr
);
1110 brw_pop_insn_state(p
);
1112 /* visitor knows more than we do about the surface limit required,
1113 * so has already done marking.
1120 fs_generator::generate_varying_pull_constant_load(fs_inst
*inst
,
1122 struct brw_reg index
,
1123 struct brw_reg offset
)
1125 assert(brw
->gen
< 7); /* Should use the gen7 variant. */
1126 assert(inst
->header_present
);
1129 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1130 index
.type
== BRW_REGISTER_TYPE_UD
);
1131 uint32_t surf_index
= index
.dw1
.ud
;
1133 uint32_t simd_mode
, rlen
, msg_type
;
1134 if (dispatch_width
== 16) {
1135 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1138 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1143 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
1145 /* We always use the SIMD16 message so that we only have to load U, and
1148 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
1149 assert(inst
->mlen
== 3);
1150 assert(inst
->regs_written
== 8);
1152 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1155 struct brw_reg offset_mrf
= retype(brw_message_reg(inst
->base_mrf
+ 1),
1156 BRW_REGISTER_TYPE_D
);
1157 brw_MOV(p
, offset_mrf
, offset
);
1159 struct brw_reg header
= brw_vec8_grf(0, 0);
1160 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
1162 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1163 brw_inst_set_qtr_control(brw
, send
, BRW_COMPRESSION_NONE
);
1164 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1165 brw_set_src0(p
, send
, header
);
1167 brw_inst_set_base_mrf(brw
, send
, inst
->base_mrf
);
1169 /* Our surface is set up as floats, regardless of what actual data is
1172 uint32_t return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
1173 brw_set_sampler_message(p
, send
,
1175 0, /* sampler (unused) */
1179 inst
->header_present
,
1183 brw_mark_surface_used(prog_data
, surf_index
);
1187 fs_generator::generate_varying_pull_constant_load_gen7(fs_inst
*inst
,
1189 struct brw_reg index
,
1190 struct brw_reg offset
)
1192 assert(brw
->gen
>= 7);
1193 /* Varying-offset pull constant loads are treated as a normal expression on
1194 * gen7, so the fact that it's a send message is hidden at the IR level.
1196 assert(!inst
->header_present
);
1197 assert(!inst
->mlen
);
1198 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1200 uint32_t simd_mode
, rlen
, mlen
;
1201 if (dispatch_width
== 16) {
1204 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1208 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1211 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1213 uint32_t surf_index
= index
.dw1
.ud
;
1215 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1216 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1217 brw_set_src0(p
, send
, offset
);
1218 brw_set_sampler_message(p
, send
,
1220 0, /* LD message ignores sampler unit */
1221 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1224 false, /* no header */
1228 brw_mark_surface_used(prog_data
, surf_index
);
1232 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1234 brw_push_insn_state(p
);
1235 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1236 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1238 /* a0.0 = surf_index & 0xff */
1239 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1240 brw_inst_set_exec_size(p
->brw
, insn_and
, BRW_EXECUTE_1
);
1241 brw_set_dest(p
, insn_and
, addr
);
1242 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1243 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1246 /* a0.0 |= <descriptor> */
1247 brw_inst
*insn_or
= brw_next_insn(p
, BRW_OPCODE_OR
);
1248 brw_set_sampler_message(p
, insn_or
,
1251 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1257 brw_inst_set_exec_size(p
->brw
, insn_or
, BRW_EXECUTE_1
);
1258 brw_inst_set_src1_reg_type(p
->brw
, insn_or
, BRW_REGISTER_TYPE_UD
);
1259 brw_set_src0(p
, insn_or
, addr
);
1260 brw_set_dest(p
, insn_or
, addr
);
1263 /* dst = send(offset, a0.0) */
1264 brw_inst
*insn_send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1265 brw_set_dest(p
, insn_send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1266 brw_set_src0(p
, insn_send
, offset
);
1267 brw_set_indirect_send_descriptor(p
, insn_send
, BRW_SFID_SAMPLER
, addr
);
1269 brw_pop_insn_state(p
);
1271 /* visitor knows more than we do about the surface limit required,
1272 * so has already done marking.
1278 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
1279 * into the flags register (f0.0).
1281 * Used only on Gen6 and above.
1284 fs_generator::generate_mov_dispatch_to_flags(fs_inst
*inst
)
1286 struct brw_reg flags
= brw_flag_reg(0, inst
->flag_subreg
);
1287 struct brw_reg dispatch_mask
;
1290 dispatch_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
1292 dispatch_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
1294 brw_push_insn_state(p
);
1295 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1296 brw_MOV(p
, flags
, dispatch_mask
);
1297 brw_pop_insn_state(p
);
1301 fs_generator::generate_pixel_interpolator_query(fs_inst
*inst
,
1304 struct brw_reg msg_data
,
1307 assert(msg_data
.file
== BRW_IMMEDIATE_VALUE
&&
1308 msg_data
.type
== BRW_REGISTER_TYPE_UD
);
1310 brw_pixel_interpolator_query(p
,
1311 retype(dst
, BRW_REGISTER_TYPE_UW
),
1313 inst
->pi_noperspective
,
1317 inst
->regs_written
);
1322 * Sets the first word of a vgrf for gen7+ simd4x2 uniform pull constant
1323 * sampler LD messages.
1325 * We don't want to bake it into the send message's code generation because
1326 * that means we don't get a chance to schedule the instructions.
1329 fs_generator::generate_set_simd4x2_offset(fs_inst
*inst
,
1331 struct brw_reg value
)
1333 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1335 brw_push_insn_state(p
);
1336 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1337 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1338 brw_MOV(p
, retype(brw_vec1_reg(dst
.file
, dst
.nr
, 0), value
.type
), value
);
1339 brw_pop_insn_state(p
);
1342 /* Sets vstride=16, width=8, hstride=2 or vstride=0, width=1, hstride=0
1343 * (when mask is passed as a uniform) of register mask before moving it
1347 fs_generator::generate_set_omask(fs_inst
*inst
,
1349 struct brw_reg mask
)
1352 (mask
.vstride
== BRW_VERTICAL_STRIDE_8
&&
1353 mask
.width
== BRW_WIDTH_8
&&
1354 mask
.hstride
== BRW_HORIZONTAL_STRIDE_1
);
1356 bool stride_0_1_0
= has_scalar_region(mask
);
1358 assert(stride_8_8_1
|| stride_0_1_0
);
1359 assert(dst
.type
== BRW_REGISTER_TYPE_UW
);
1361 if (dispatch_width
== 16)
1363 brw_push_insn_state(p
);
1364 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1365 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1368 brw_MOV(p
, dst
, retype(stride(mask
, 16, 8, 2), dst
.type
));
1369 } else if (stride_0_1_0
) {
1370 brw_MOV(p
, dst
, retype(mask
, dst
.type
));
1372 brw_pop_insn_state(p
);
1375 /* Sets vstride=1, width=4, hstride=0 of register src1 during
1376 * the ADD instruction.
1379 fs_generator::generate_set_sample_id(fs_inst
*inst
,
1381 struct brw_reg src0
,
1382 struct brw_reg src1
)
1384 assert(dst
.type
== BRW_REGISTER_TYPE_D
||
1385 dst
.type
== BRW_REGISTER_TYPE_UD
);
1386 assert(src0
.type
== BRW_REGISTER_TYPE_D
||
1387 src0
.type
== BRW_REGISTER_TYPE_UD
);
1389 brw_push_insn_state(p
);
1390 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1391 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1392 struct brw_reg reg
= retype(stride(src1
, 1, 4, 0), BRW_REGISTER_TYPE_UW
);
1393 if (dispatch_width
== 8) {
1394 brw_ADD(p
, dst
, src0
, reg
);
1395 } else if (dispatch_width
== 16) {
1396 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), reg
);
1397 brw_ADD(p
, sechalf(dst
), sechalf(src0
), suboffset(reg
, 2));
1399 brw_pop_insn_state(p
);
1403 * Change the register's data type from UD to W, doubling the strides in order
1404 * to compensate for halving the data type width.
1406 static struct brw_reg
1407 ud_reg_to_w(struct brw_reg r
)
1409 assert(r
.type
== BRW_REGISTER_TYPE_UD
);
1410 r
.type
= BRW_REGISTER_TYPE_W
;
1412 /* The BRW_*_STRIDE enums are defined so that incrementing the field
1413 * doubles the real stride.
1424 fs_generator::generate_pack_half_2x16_split(fs_inst
*inst
,
1429 assert(brw
->gen
>= 7);
1430 assert(dst
.type
== BRW_REGISTER_TYPE_UD
);
1431 assert(x
.type
== BRW_REGISTER_TYPE_F
);
1432 assert(y
.type
== BRW_REGISTER_TYPE_F
);
1434 /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16:
1436 * Because this instruction does not have a 16-bit floating-point type,
1437 * the destination data type must be Word (W).
1439 * The destination must be DWord-aligned and specify a horizontal stride
1440 * (HorzStride) of 2. The 16-bit result is stored in the lower word of
1441 * each destination channel and the upper word is not modified.
1443 struct brw_reg dst_w
= ud_reg_to_w(dst
);
1445 /* Give each 32-bit channel of dst the form below , where "." means
1449 brw_F32TO16(p
, dst_w
, y
);
1454 brw_SHL(p
, dst
, dst
, brw_imm_ud(16u));
1456 /* And, finally the form of packHalf2x16's output:
1459 brw_F32TO16(p
, dst_w
, x
);
1463 fs_generator::generate_unpack_half_2x16_split(fs_inst
*inst
,
1467 assert(brw
->gen
>= 7);
1468 assert(dst
.type
== BRW_REGISTER_TYPE_F
);
1469 assert(src
.type
== BRW_REGISTER_TYPE_UD
);
1471 /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32:
1473 * Because this instruction does not have a 16-bit floating-point type,
1474 * the source data type must be Word (W). The destination type must be
1477 struct brw_reg src_w
= ud_reg_to_w(src
);
1479 /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
1480 * For the Y case, we wish to access only the upper word; therefore
1481 * a 16-bit subregister offset is needed.
1483 assert(inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
||
1484 inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
);
1485 if (inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
)
1488 brw_F16TO32(p
, dst
, src_w
);
1492 fs_generator::generate_shader_time_add(fs_inst
*inst
,
1493 struct brw_reg payload
,
1494 struct brw_reg offset
,
1495 struct brw_reg value
)
1497 assert(brw
->gen
>= 7);
1498 brw_push_insn_state(p
);
1499 brw_set_default_mask_control(p
, true);
1501 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1502 struct brw_reg payload_offset
= retype(brw_vec1_grf(payload
.nr
, 0),
1504 struct brw_reg payload_value
= retype(brw_vec1_grf(payload
.nr
+ 1, 0),
1507 assert(offset
.file
== BRW_IMMEDIATE_VALUE
);
1508 if (value
.file
== BRW_GENERAL_REGISTER_FILE
) {
1509 value
.width
= BRW_WIDTH_1
;
1510 value
.hstride
= BRW_HORIZONTAL_STRIDE_0
;
1511 value
.vstride
= BRW_VERTICAL_STRIDE_0
;
1513 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1516 /* Trying to deal with setup of the params from the IR is crazy in the FS8
1517 * case, and we don't really care about squeezing every bit of performance
1518 * out of this path, so we just emit the MOVs from here.
1520 brw_MOV(p
, payload_offset
, offset
);
1521 brw_MOV(p
, payload_value
, value
);
1522 brw_shader_time_add(p
, payload
,
1523 prog_data
->binding_table
.shader_time_start
);
1524 brw_pop_insn_state(p
);
1526 brw_mark_surface_used(prog_data
,
1527 prog_data
->binding_table
.shader_time_start
);
1531 fs_generator::generate_untyped_atomic(fs_inst
*inst
, struct brw_reg dst
,
1532 struct brw_reg payload
,
1533 struct brw_reg atomic_op
,
1534 struct brw_reg surf_index
)
1536 assert(atomic_op
.file
== BRW_IMMEDIATE_VALUE
&&
1537 atomic_op
.type
== BRW_REGISTER_TYPE_UD
&&
1538 surf_index
.file
== BRW_IMMEDIATE_VALUE
&&
1539 surf_index
.type
== BRW_REGISTER_TYPE_UD
);
1541 brw_untyped_atomic(p
, dst
, payload
, atomic_op
.dw1
.ud
, surf_index
.dw1
.ud
,
1542 inst
->mlen
, inst
->exec_size
/ 8);
1544 brw_mark_surface_used(prog_data
, surf_index
.dw1
.ud
);
1548 fs_generator::generate_untyped_surface_read(fs_inst
*inst
, struct brw_reg dst
,
1549 struct brw_reg payload
,
1550 struct brw_reg surf_index
)
1552 assert(surf_index
.file
== BRW_IMMEDIATE_VALUE
&&
1553 surf_index
.type
== BRW_REGISTER_TYPE_UD
);
1555 brw_untyped_surface_read(p
, dst
, payload
,
1557 inst
->mlen
, inst
->exec_size
/ 8);
1559 brw_mark_surface_used(prog_data
, surf_index
.dw1
.ud
);
1563 fs_generator::enable_debug(const char *shader_name
)
1566 this->shader_name
= shader_name
;
1570 fs_generator::generate_code(const cfg_t
*cfg
, int dispatch_width
)
1572 /* align to 64 byte boundary. */
1573 while (p
->next_insn_offset
% 64)
1576 this->dispatch_width
= dispatch_width
;
1577 if (dispatch_width
== 16)
1578 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1580 int start_offset
= p
->next_insn_offset
;
1583 struct annotation_info annotation
;
1584 memset(&annotation
, 0, sizeof(annotation
));
1586 foreach_block_and_inst (block
, fs_inst
, inst
, cfg
) {
1587 struct brw_reg src
[3], dst
;
1588 unsigned int last_insn_offset
= p
->next_insn_offset
;
1589 bool multiple_instructions_emitted
= false;
1591 if (unlikely(debug_flag
))
1592 annotate(brw
, &annotation
, cfg
, inst
, p
->next_insn_offset
);
1594 for (unsigned int i
= 0; i
< inst
->sources
; i
++) {
1595 src
[i
] = brw_reg_from_fs_reg(&inst
->src
[i
]);
1597 /* The accumulator result appears to get used for the
1598 * conditional modifier generation. When negating a UD
1599 * value, there is a 33rd bit generated for the sign in the
1600 * accumulator value, so now you can't check, for example,
1601 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
1603 assert(!inst
->conditional_mod
||
1604 inst
->src
[i
].type
!= BRW_REGISTER_TYPE_UD
||
1605 !inst
->src
[i
].negate
);
1607 dst
= brw_reg_from_fs_reg(&inst
->dst
);
1609 brw_set_default_predicate_control(p
, inst
->predicate
);
1610 brw_set_default_predicate_inverse(p
, inst
->predicate_inverse
);
1611 brw_set_default_flag_reg(p
, 0, inst
->flag_subreg
);
1612 brw_set_default_saturate(p
, inst
->saturate
);
1613 brw_set_default_mask_control(p
, inst
->force_writemask_all
);
1614 brw_set_default_acc_write_control(p
, inst
->writes_accumulator
);
1616 switch (inst
->exec_size
) {
1620 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1623 if (inst
->force_sechalf
) {
1624 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1626 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1630 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1633 unreachable(!"Invalid instruction width");
1636 switch (inst
->opcode
) {
1637 case BRW_OPCODE_MOV
:
1638 brw_MOV(p
, dst
, src
[0]);
1640 case BRW_OPCODE_ADD
:
1641 brw_ADD(p
, dst
, src
[0], src
[1]);
1643 case BRW_OPCODE_MUL
:
1644 brw_MUL(p
, dst
, src
[0], src
[1]);
1646 case BRW_OPCODE_AVG
:
1647 brw_AVG(p
, dst
, src
[0], src
[1]);
1649 case BRW_OPCODE_MACH
:
1650 brw_MACH(p
, dst
, src
[0], src
[1]);
1653 case BRW_OPCODE_LINE
:
1654 brw_LINE(p
, dst
, src
[0], src
[1]);
1657 case BRW_OPCODE_MAD
:
1658 assert(brw
->gen
>= 6);
1659 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1660 if (dispatch_width
== 16 && brw
->gen
< 8 && !brw
->is_haswell
) {
1661 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1662 brw_inst
*f
= brw_MAD(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1663 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1664 brw_inst
*s
= brw_MAD(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1665 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1667 if (inst
->conditional_mod
) {
1668 brw_inst_set_cond_modifier(brw
, f
, inst
->conditional_mod
);
1669 brw_inst_set_cond_modifier(brw
, s
, inst
->conditional_mod
);
1670 multiple_instructions_emitted
= true;
1673 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
1675 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1678 case BRW_OPCODE_LRP
:
1679 assert(brw
->gen
>= 6);
1680 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1681 if (dispatch_width
== 16 && brw
->gen
< 8 && !brw
->is_haswell
) {
1682 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1683 brw_inst
*f
= brw_LRP(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1684 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1685 brw_inst
*s
= brw_LRP(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1686 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1688 if (inst
->conditional_mod
) {
1689 brw_inst_set_cond_modifier(brw
, f
, inst
->conditional_mod
);
1690 brw_inst_set_cond_modifier(brw
, s
, inst
->conditional_mod
);
1691 multiple_instructions_emitted
= true;
1694 brw_LRP(p
, dst
, src
[0], src
[1], src
[2]);
1696 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1699 case BRW_OPCODE_FRC
:
1700 brw_FRC(p
, dst
, src
[0]);
1702 case BRW_OPCODE_RNDD
:
1703 brw_RNDD(p
, dst
, src
[0]);
1705 case BRW_OPCODE_RNDE
:
1706 brw_RNDE(p
, dst
, src
[0]);
1708 case BRW_OPCODE_RNDZ
:
1709 brw_RNDZ(p
, dst
, src
[0]);
1712 case BRW_OPCODE_AND
:
1713 brw_AND(p
, dst
, src
[0], src
[1]);
1716 brw_OR(p
, dst
, src
[0], src
[1]);
1718 case BRW_OPCODE_XOR
:
1719 brw_XOR(p
, dst
, src
[0], src
[1]);
1721 case BRW_OPCODE_NOT
:
1722 brw_NOT(p
, dst
, src
[0]);
1724 case BRW_OPCODE_ASR
:
1725 brw_ASR(p
, dst
, src
[0], src
[1]);
1727 case BRW_OPCODE_SHR
:
1728 brw_SHR(p
, dst
, src
[0], src
[1]);
1730 case BRW_OPCODE_SHL
:
1731 brw_SHL(p
, dst
, src
[0], src
[1]);
1733 case BRW_OPCODE_F32TO16
:
1734 assert(brw
->gen
>= 7);
1735 brw_F32TO16(p
, dst
, src
[0]);
1737 case BRW_OPCODE_F16TO32
:
1738 assert(brw
->gen
>= 7);
1739 brw_F16TO32(p
, dst
, src
[0]);
1741 case BRW_OPCODE_CMP
:
1742 /* The Ivybridge/BayTrail WaCMPInstFlagDepClearedEarly workaround says
1743 * that when the destination is a GRF that the dependency-clear bit on
1744 * the flag register is cleared early.
1746 * Suggested workarounds are to disable coissuing CMP instructions
1747 * or to split CMP(16) instructions into two CMP(8) instructions.
1749 * We choose to split into CMP(8) instructions since disabling
1750 * coissuing would affect CMP instructions not otherwise affected by
1753 if (dispatch_width
== 16 && brw
->gen
== 7 && !brw
->is_haswell
) {
1754 if (dst
.file
== BRW_GENERAL_REGISTER_FILE
) {
1755 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1756 brw_CMP(p
, firsthalf(dst
), inst
->conditional_mod
,
1757 firsthalf(src
[0]), firsthalf(src
[1]));
1758 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1759 brw_CMP(p
, sechalf(dst
), inst
->conditional_mod
,
1760 sechalf(src
[0]), sechalf(src
[1]));
1761 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1763 multiple_instructions_emitted
= true;
1764 } else if (dst
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1765 /* For unknown reasons, the aforementioned workaround is not
1766 * sufficient. Overriding the type when the destination is the
1767 * null register is necessary but not sufficient by itself.
1769 assert(dst
.nr
== BRW_ARF_NULL
);
1770 dst
.type
= BRW_REGISTER_TYPE_D
;
1771 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1773 unreachable("not reached");
1776 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1779 case BRW_OPCODE_SEL
:
1780 brw_SEL(p
, dst
, src
[0], src
[1]);
1782 case BRW_OPCODE_BFREV
:
1783 assert(brw
->gen
>= 7);
1784 /* BFREV only supports UD type for src and dst. */
1785 brw_BFREV(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1786 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1788 case BRW_OPCODE_FBH
:
1789 assert(brw
->gen
>= 7);
1790 /* FBH only supports UD type for dst. */
1791 brw_FBH(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1793 case BRW_OPCODE_FBL
:
1794 assert(brw
->gen
>= 7);
1795 /* FBL only supports UD type for dst. */
1796 brw_FBL(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1798 case BRW_OPCODE_CBIT
:
1799 assert(brw
->gen
>= 7);
1800 /* CBIT only supports UD type for dst. */
1801 brw_CBIT(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1803 case BRW_OPCODE_ADDC
:
1804 assert(brw
->gen
>= 7);
1805 brw_ADDC(p
, dst
, src
[0], src
[1]);
1807 case BRW_OPCODE_SUBB
:
1808 assert(brw
->gen
>= 7);
1809 brw_SUBB(p
, dst
, src
[0], src
[1]);
1811 case BRW_OPCODE_MAC
:
1812 brw_MAC(p
, dst
, src
[0], src
[1]);
1815 case BRW_OPCODE_BFE
:
1816 assert(brw
->gen
>= 7);
1817 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1818 if (dispatch_width
== 16 && brw
->gen
< 8 && !brw
->is_haswell
) {
1819 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1820 brw_BFE(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1821 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1822 brw_BFE(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1823 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1825 brw_BFE(p
, dst
, src
[0], src
[1], src
[2]);
1827 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1830 case BRW_OPCODE_BFI1
:
1831 assert(brw
->gen
>= 7);
1832 /* The Haswell WaForceSIMD8ForBFIInstruction workaround says that we
1835 * "Force BFI instructions to be executed always in SIMD8."
1837 if (dispatch_width
== 16 && brw
->is_haswell
) {
1838 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1839 brw_BFI1(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]));
1840 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1841 brw_BFI1(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]));
1842 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1844 brw_BFI1(p
, dst
, src
[0], src
[1]);
1847 case BRW_OPCODE_BFI2
:
1848 assert(brw
->gen
>= 7);
1849 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1850 /* The Haswell WaForceSIMD8ForBFIInstruction workaround says that we
1853 * "Force BFI instructions to be executed always in SIMD8."
1855 * Otherwise we would be able to emit compressed instructions like we
1856 * do for the other three-source instructions.
1858 if (dispatch_width
== 16 && brw
->gen
< 8) {
1859 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1860 brw_BFI2(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1861 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1862 brw_BFI2(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1863 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1865 brw_BFI2(p
, dst
, src
[0], src
[1], src
[2]);
1867 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1871 if (inst
->src
[0].file
!= BAD_FILE
) {
1872 /* The instruction has an embedded compare (only allowed on gen6) */
1873 assert(brw
->gen
== 6);
1874 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
1876 brw_IF(p
, dispatch_width
== 16 ? BRW_EXECUTE_16
: BRW_EXECUTE_8
);
1880 case BRW_OPCODE_ELSE
:
1883 case BRW_OPCODE_ENDIF
:
1888 brw_DO(p
, BRW_EXECUTE_8
);
1891 case BRW_OPCODE_BREAK
:
1893 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
1895 case BRW_OPCODE_CONTINUE
:
1897 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
1900 case BRW_OPCODE_WHILE
:
1905 case SHADER_OPCODE_RCP
:
1906 case SHADER_OPCODE_RSQ
:
1907 case SHADER_OPCODE_SQRT
:
1908 case SHADER_OPCODE_EXP2
:
1909 case SHADER_OPCODE_LOG2
:
1910 case SHADER_OPCODE_SIN
:
1911 case SHADER_OPCODE_COS
:
1912 assert(brw
->gen
< 6 || inst
->mlen
== 0);
1913 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1914 if (brw
->gen
>= 7) {
1915 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0],
1917 } else if (brw
->gen
== 6) {
1918 generate_math_gen6(inst
, dst
, src
[0], brw_null_reg());
1919 } else if (brw
->gen
== 5 || brw
->is_g4x
) {
1920 generate_math_g45(inst
, dst
, src
[0]);
1922 generate_math_gen4(inst
, dst
, src
[0]);
1925 case SHADER_OPCODE_INT_QUOTIENT
:
1926 case SHADER_OPCODE_INT_REMAINDER
:
1927 case SHADER_OPCODE_POW
:
1928 assert(brw
->gen
< 6 || inst
->mlen
== 0);
1929 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1930 if (brw
->gen
>= 7 && inst
->opcode
== SHADER_OPCODE_POW
) {
1931 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0], src
[1]);
1932 } else if (brw
->gen
>= 6) {
1933 generate_math_gen6(inst
, dst
, src
[0], src
[1]);
1935 generate_math_gen4(inst
, dst
, src
[0]);
1938 case FS_OPCODE_PIXEL_X
:
1939 generate_pixel_xy(dst
, true);
1941 case FS_OPCODE_PIXEL_Y
:
1942 generate_pixel_xy(dst
, false);
1944 case FS_OPCODE_CINTERP
:
1945 brw_MOV(p
, dst
, src
[0]);
1947 case FS_OPCODE_LINTERP
:
1948 generate_linterp(inst
, dst
, src
);
1950 case SHADER_OPCODE_TEX
:
1952 case SHADER_OPCODE_TXD
:
1953 case SHADER_OPCODE_TXF
:
1954 case SHADER_OPCODE_TXF_CMS
:
1955 case SHADER_OPCODE_TXF_UMS
:
1956 case SHADER_OPCODE_TXF_MCS
:
1957 case SHADER_OPCODE_TXL
:
1958 case SHADER_OPCODE_TXS
:
1959 case SHADER_OPCODE_LOD
:
1960 case SHADER_OPCODE_TG4
:
1961 case SHADER_OPCODE_TG4_OFFSET
:
1962 generate_tex(inst
, dst
, src
[0], src
[1]);
1964 case FS_OPCODE_DDX_COARSE
:
1965 case FS_OPCODE_DDX_FINE
:
1966 generate_ddx(inst
->opcode
, dst
, src
[0]);
1968 case FS_OPCODE_DDY_COARSE
:
1969 case FS_OPCODE_DDY_FINE
:
1970 assert(src
[1].file
== BRW_IMMEDIATE_VALUE
);
1971 generate_ddy(inst
->opcode
, dst
, src
[0], src
[1].dw1
.ud
);
1974 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
1975 generate_scratch_write(inst
, src
[0]);
1978 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
1979 generate_scratch_read(inst
, dst
);
1982 case SHADER_OPCODE_GEN7_SCRATCH_READ
:
1983 generate_scratch_read_gen7(inst
, dst
);
1986 case SHADER_OPCODE_URB_WRITE_SIMD8
:
1987 generate_urb_write(inst
, src
[0]);
1990 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
:
1991 generate_uniform_pull_constant_load(inst
, dst
, src
[0], src
[1]);
1994 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7
:
1995 generate_uniform_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
1998 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD
:
1999 generate_varying_pull_constant_load(inst
, dst
, src
[0], src
[1]);
2002 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
:
2003 generate_varying_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
2006 case FS_OPCODE_REP_FB_WRITE
:
2007 case FS_OPCODE_FB_WRITE
:
2008 generate_fb_write(inst
, src
[0]);
2011 case FS_OPCODE_BLORP_FB_WRITE
:
2012 generate_blorp_fb_write(inst
);
2015 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS
:
2016 generate_mov_dispatch_to_flags(inst
);
2019 case FS_OPCODE_DISCARD_JUMP
:
2020 generate_discard_jump(inst
);
2023 case SHADER_OPCODE_SHADER_TIME_ADD
:
2024 generate_shader_time_add(inst
, src
[0], src
[1], src
[2]);
2027 case SHADER_OPCODE_UNTYPED_ATOMIC
:
2028 generate_untyped_atomic(inst
, dst
, src
[0], src
[1], src
[2]);
2031 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
2032 generate_untyped_surface_read(inst
, dst
, src
[0], src
[1]);
2035 case FS_OPCODE_SET_SIMD4X2_OFFSET
:
2036 generate_set_simd4x2_offset(inst
, dst
, src
[0]);
2039 case FS_OPCODE_SET_OMASK
:
2040 generate_set_omask(inst
, dst
, src
[0]);
2043 case FS_OPCODE_SET_SAMPLE_ID
:
2044 generate_set_sample_id(inst
, dst
, src
[0], src
[1]);
2047 case FS_OPCODE_PACK_HALF_2x16_SPLIT
:
2048 generate_pack_half_2x16_split(inst
, dst
, src
[0], src
[1]);
2051 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
:
2052 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
:
2053 generate_unpack_half_2x16_split(inst
, dst
, src
[0]);
2056 case FS_OPCODE_PLACEHOLDER_HALT
:
2057 /* This is the place where the final HALT needs to be inserted if
2058 * we've emitted any discards. If not, this will emit no code.
2060 if (!patch_discard_jumps_to_fb_writes()) {
2061 if (unlikely(debug_flag
)) {
2062 annotation
.ann_count
--;
2067 case FS_OPCODE_INTERPOLATE_AT_CENTROID
:
2068 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2069 GEN7_PIXEL_INTERPOLATOR_LOC_CENTROID
);
2072 case FS_OPCODE_INTERPOLATE_AT_SAMPLE
:
2073 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2074 GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE
);
2077 case FS_OPCODE_INTERPOLATE_AT_SHARED_OFFSET
:
2078 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2079 GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET
);
2082 case FS_OPCODE_INTERPOLATE_AT_PER_SLOT_OFFSET
:
2083 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2084 GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET
);
2088 if (inst
->opcode
< (int) ARRAY_SIZE(opcode_descs
)) {
2089 _mesa_problem(ctx
, "Unsupported opcode `%s' in %s",
2090 opcode_descs
[inst
->opcode
].name
, stage_abbrev
);
2092 _mesa_problem(ctx
, "Unsupported opcode %d in %s", inst
->opcode
,
2097 case SHADER_OPCODE_LOAD_PAYLOAD
:
2098 unreachable("Should be lowered by lower_load_payload()");
2101 if (multiple_instructions_emitted
)
2104 if (inst
->no_dd_clear
|| inst
->no_dd_check
|| inst
->conditional_mod
) {
2105 assert(p
->next_insn_offset
== last_insn_offset
+ 16 ||
2106 !"conditional_mod, no_dd_check, or no_dd_clear set for IR "
2107 "emitting more than 1 instruction");
2109 brw_inst
*last
= &p
->store
[last_insn_offset
/ 16];
2111 if (inst
->conditional_mod
)
2112 brw_inst_set_cond_modifier(brw
, last
, inst
->conditional_mod
);
2113 brw_inst_set_no_dd_clear(brw
, last
, inst
->no_dd_clear
);
2114 brw_inst_set_no_dd_check(brw
, last
, inst
->no_dd_check
);
2119 annotation_finalize(&annotation
, p
->next_insn_offset
);
2121 int before_size
= p
->next_insn_offset
- start_offset
;
2122 brw_compact_instructions(p
, start_offset
, annotation
.ann_count
,
2124 int after_size
= p
->next_insn_offset
- start_offset
;
2126 if (unlikely(debug_flag
)) {
2127 fprintf(stderr
, "Native code for %s\n"
2128 "SIMD%d shader: %d instructions. %d loops. Compacted %d to %d"
2129 " bytes (%.0f%%)\n",
2131 dispatch_width
, before_size
/ 16, loop_count
, before_size
, after_size
,
2132 100.0f
* (before_size
- after_size
) / before_size
);
2134 dump_assembly(p
->store
, annotation
.ann_count
, annotation
.ann
, brw
, prog
);
2135 ralloc_free(annotation
.ann
);
2138 static GLuint msg_id
= 0;
2139 _mesa_gl_debug(&brw
->ctx
, &msg_id
,
2140 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2141 MESA_DEBUG_TYPE_OTHER
,
2142 MESA_DEBUG_SEVERITY_NOTIFICATION
,
2143 "%s SIMD%d shader: %d inst, %d loops, "
2144 "compacted %d to %d bytes.\n",
2145 stage_abbrev
, dispatch_width
, before_size
/ 16, loop_count
,
2146 before_size
, after_size
);
2148 return start_offset
;
2152 fs_generator::get_assembly(unsigned int *assembly_size
)
2154 return brw_get_program(p
, assembly_size
);