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.
30 #include "main/macros.h"
31 #include "brw_context.h"
36 static uint32_t brw_file_from_reg(fs_reg
*reg
)
40 return BRW_GENERAL_REGISTER_FILE
;
42 return BRW_MESSAGE_REGISTER_FILE
;
44 return BRW_IMMEDIATE_VALUE
;
46 unreachable("not reached");
51 brw_reg_from_fs_reg(fs_reg
*reg
)
53 struct brw_reg brw_reg
;
58 if (reg
->stride
== 0) {
59 brw_reg
= brw_vec1_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
60 } else if (reg
->width
< 8) {
61 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
62 brw_reg
= stride(brw_reg
, reg
->width
* reg
->stride
,
63 reg
->width
, reg
->stride
);
65 /* From the Haswell PRM:
67 * VertStride must be used to cross GRF register boundaries. This
68 * rule implies that elements within a 'Width' cannot cross GRF
71 * So, for registers with width > 8, we have to use a width of 8
72 * and trust the compression state to sort out the exec size.
74 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
75 brw_reg
= stride(brw_reg
, 8 * reg
->stride
, 8, reg
->stride
);
78 brw_reg
= retype(brw_reg
, reg
->type
);
79 brw_reg
= byte_offset(brw_reg
, reg
->subreg_offset
);
83 case BRW_REGISTER_TYPE_F
:
84 brw_reg
= brw_imm_f(reg
->fixed_hw_reg
.dw1
.f
);
86 case BRW_REGISTER_TYPE_D
:
87 brw_reg
= brw_imm_d(reg
->fixed_hw_reg
.dw1
.d
);
89 case BRW_REGISTER_TYPE_UD
:
90 brw_reg
= brw_imm_ud(reg
->fixed_hw_reg
.dw1
.ud
);
92 case BRW_REGISTER_TYPE_W
:
93 brw_reg
= brw_imm_w(reg
->fixed_hw_reg
.dw1
.d
);
95 case BRW_REGISTER_TYPE_UW
:
96 brw_reg
= brw_imm_uw(reg
->fixed_hw_reg
.dw1
.ud
);
98 case BRW_REGISTER_TYPE_VF
:
99 brw_reg
= brw_imm_vf(reg
->fixed_hw_reg
.dw1
.ud
);
102 unreachable("not reached");
106 assert(reg
->type
== reg
->fixed_hw_reg
.type
);
107 brw_reg
= reg
->fixed_hw_reg
;
110 /* Probably unused. */
111 brw_reg
= brw_null_reg();
114 unreachable("not reached");
117 brw_reg
= brw_abs(brw_reg
);
119 brw_reg
= negate(brw_reg
);
124 fs_generator::fs_generator(struct brw_context
*brw
,
127 struct brw_stage_prog_data
*prog_data
,
128 struct gl_program
*prog
,
129 unsigned promoted_constants
,
130 bool runtime_check_aads_emit
,
131 const char *stage_abbrev
)
133 : brw(brw
), key(key
),
134 prog_data(prog_data
),
135 prog(prog
), promoted_constants(promoted_constants
),
136 runtime_check_aads_emit(runtime_check_aads_emit
), debug_flag(false),
137 stage_abbrev(stage_abbrev
), mem_ctx(mem_ctx
)
141 p
= rzalloc(mem_ctx
, struct brw_compile
);
142 brw_init_compile(brw
->intelScreen
->devinfo
, p
, mem_ctx
);
145 fs_generator::~fs_generator()
149 class ip_record
: public exec_node
{
151 DECLARE_RALLOC_CXX_OPERATORS(ip_record
)
162 fs_generator::patch_discard_jumps_to_fb_writes()
164 if (brw
->gen
< 6 || this->discard_halt_patches
.is_empty())
167 int scale
= brw_jump_scale(p
->devinfo
);
169 /* There is a somewhat strange undocumented requirement of using
170 * HALT, according to the simulator. If some channel has HALTed to
171 * a particular UIP, then by the end of the program, every channel
172 * must have HALTed to that UIP. Furthermore, the tracking is a
173 * stack, so you can't do the final halt of a UIP after starting
174 * halting to a new UIP.
176 * Symptoms of not emitting this instruction on actual hardware
177 * included GPU hangs and sparkly rendering on the piglit discard
180 brw_inst
*last_halt
= gen6_HALT(p
);
181 brw_inst_set_uip(p
->devinfo
, last_halt
, 1 * scale
);
182 brw_inst_set_jip(p
->devinfo
, last_halt
, 1 * scale
);
186 foreach_in_list(ip_record
, patch_ip
, &discard_halt_patches
) {
187 brw_inst
*patch
= &p
->store
[patch_ip
->ip
];
189 assert(brw_inst_opcode(p
->devinfo
, patch
) == BRW_OPCODE_HALT
);
190 /* HALT takes a half-instruction distance from the pre-incremented IP. */
191 brw_inst_set_uip(p
->devinfo
, patch
, (ip
- patch_ip
->ip
) * scale
);
194 this->discard_halt_patches
.make_empty();
199 fs_generator::fire_fb_write(fs_inst
*inst
,
200 struct brw_reg payload
,
201 struct brw_reg implied_header
,
204 uint32_t msg_control
;
206 brw_wm_prog_data
*prog_data
= (brw_wm_prog_data
*) this->prog_data
;
209 brw_push_insn_state(p
);
210 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
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 if (dispatch_width
== 8 || !inst
->eot
)
222 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01
;
224 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23
;
225 } else if (dispatch_width
== 16)
226 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
;
228 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01
;
230 uint32_t surf_index
=
231 prog_data
->binding_table
.render_target_start
+ inst
->target
;
233 bool last_render_target
= inst
->eot
||
234 (prog_data
->dual_src_blend
&& dispatch_width
== 16);
247 inst
->header_present
);
249 brw_mark_surface_used(&prog_data
->base
, surf_index
);
253 fs_generator::generate_fb_write(fs_inst
*inst
, struct brw_reg payload
)
255 brw_wm_prog_data
*prog_data
= (brw_wm_prog_data
*) this->prog_data
;
256 const brw_wm_prog_key
* const key
= (brw_wm_prog_key
* const) this->key
;
257 struct brw_reg implied_header
;
259 if (brw
->gen
< 8 && !brw
->is_haswell
) {
260 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
263 if (inst
->base_mrf
>= 0)
264 payload
= brw_message_reg(inst
->base_mrf
);
266 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
269 if (inst
->header_present
) {
270 brw_push_insn_state(p
);
271 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
272 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
273 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
274 brw_set_default_flag_reg(p
, 0, 0);
276 /* On HSW, the GPU will use the predicate on SENDC, unless the header is
279 if (prog_data
->uses_kill
) {
280 struct brw_reg pixel_mask
;
283 pixel_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
285 pixel_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
287 brw_MOV(p
, pixel_mask
, brw_flag_reg(0, 1));
291 brw_push_insn_state(p
);
292 brw_set_default_exec_size(p
, BRW_EXECUTE_16
);
293 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
295 retype(payload
, BRW_REGISTER_TYPE_UD
),
296 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
297 brw_pop_insn_state(p
);
299 if (inst
->target
> 0 && key
->replicate_alpha
) {
300 /* Set "Source0 Alpha Present to RenderTarget" bit in message
304 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
305 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
306 brw_imm_ud(0x1 << 11));
309 if (inst
->target
> 0) {
310 /* Set the render target index for choosing BLEND_STATE. */
311 brw_MOV(p
, retype(vec1(suboffset(payload
, 2)),
312 BRW_REGISTER_TYPE_UD
),
313 brw_imm_ud(inst
->target
));
316 implied_header
= brw_null_reg();
318 implied_header
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
321 brw_pop_insn_state(p
);
323 implied_header
= brw_null_reg();
326 if (!runtime_check_aads_emit
) {
327 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
329 /* This can only happen in gen < 6 */
330 assert(brw
->gen
< 6);
332 struct brw_reg v1_null_ud
= vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD
));
334 /* Check runtime bit to detect if we have to send AA data or not */
335 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
338 retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD
),
340 brw_inst_set_cond_modifier(p
->devinfo
, brw_last_inst
, BRW_CONDITIONAL_NZ
);
342 int jmp
= brw_JMPI(p
, brw_imm_ud(0), BRW_PREDICATE_NORMAL
) - p
->store
;
343 brw_inst_set_exec_size(p
->devinfo
, brw_last_inst
, BRW_EXECUTE_1
);
345 /* Don't send AA data */
346 fire_fb_write(inst
, offset(payload
, 1), implied_header
, inst
->mlen
-1);
348 brw_land_fwd_jump(p
, jmp
);
349 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
354 fs_generator::generate_urb_write(fs_inst
*inst
, struct brw_reg payload
)
358 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
360 brw_set_dest(p
, insn
, brw_null_reg());
361 brw_set_src0(p
, insn
, payload
);
362 brw_set_src1(p
, insn
, brw_imm_d(0));
364 brw_inst_set_sfid(p
->devinfo
, insn
, BRW_SFID_URB
);
365 brw_inst_set_urb_opcode(p
->devinfo
, insn
, GEN8_URB_OPCODE_SIMD8_WRITE
);
367 brw_inst_set_mlen(p
->devinfo
, insn
, inst
->mlen
);
368 brw_inst_set_rlen(p
->devinfo
, insn
, 0);
369 brw_inst_set_eot(p
->devinfo
, insn
, inst
->eot
);
370 brw_inst_set_header_present(p
->devinfo
, insn
, true);
371 brw_inst_set_urb_global_offset(p
->devinfo
, insn
, inst
->offset
);
375 fs_generator::generate_blorp_fb_write(fs_inst
*inst
)
378 16 /* dispatch_width */,
379 brw_message_reg(inst
->base_mrf
),
380 brw_reg_from_fs_reg(&inst
->src
[0]),
381 BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
,
387 inst
->header_present
);
391 fs_generator::generate_linterp(fs_inst
*inst
,
392 struct brw_reg dst
, struct brw_reg
*src
)
396 * -----------------------------------
397 * | src1+0 | src1+1 | src1+2 | src1+3 |
398 * |-----------------------------------|
399 * |(x0, x1)|(y0, y1)|(x2, x3)|(y2, y3)|
400 * -----------------------------------
402 * but for the LINE/MAC pair, the LINE reads Xs and the MAC reads Ys:
404 * -----------------------------------
405 * | src1+0 | src1+1 | src1+2 | src1+3 |
406 * |-----------------------------------|
407 * |(x0, x1)|(y0, y1)| | | in SIMD8
408 * |-----------------------------------|
409 * |(x0, x1)|(x2, x3)|(y0, y1)|(y2, y3)| in SIMD16
410 * -----------------------------------
412 * See also: emit_interpolation_setup_gen4().
414 struct brw_reg delta_x
= src
[0];
415 struct brw_reg delta_y
= offset(src
[0], dispatch_width
/ 8);
416 struct brw_reg interp
= src
[1];
419 (brw
->gen
>= 7 || (delta_x
.nr
& 1) == 0)) {
420 brw_PLN(p
, dst
, interp
, delta_x
);
422 brw_LINE(p
, brw_null_reg(), interp
, delta_x
);
423 brw_MAC(p
, dst
, suboffset(interp
, 1), delta_y
);
428 fs_generator::generate_math_gen6(fs_inst
*inst
,
433 int op
= brw_math_function(inst
->opcode
);
434 bool binop
= src1
.file
!= BRW_ARCHITECTURE_REGISTER_FILE
;
436 if (dispatch_width
== 8) {
437 gen6_math(p
, dst
, op
, src0
, src1
);
438 } else if (dispatch_width
== 16) {
439 brw_push_insn_state(p
);
440 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
441 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
442 gen6_math(p
, firsthalf(dst
), op
, firsthalf(src0
), firsthalf(src1
));
443 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
444 gen6_math(p
, sechalf(dst
), op
, sechalf(src0
),
445 binop
? sechalf(src1
) : brw_null_reg());
446 brw_pop_insn_state(p
);
451 fs_generator::generate_math_gen4(fs_inst
*inst
,
455 int op
= brw_math_function(inst
->opcode
);
457 assert(inst
->mlen
>= 1);
459 if (dispatch_width
== 8) {
463 BRW_MATH_PRECISION_FULL
);
464 } else if (dispatch_width
== 16) {
465 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
466 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
467 gen4_math(p
, firsthalf(dst
),
469 inst
->base_mrf
, firsthalf(src
),
470 BRW_MATH_PRECISION_FULL
);
471 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
472 gen4_math(p
, sechalf(dst
),
474 inst
->base_mrf
+ 1, sechalf(src
),
475 BRW_MATH_PRECISION_FULL
);
477 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
482 fs_generator::generate_math_g45(fs_inst
*inst
,
486 if (inst
->opcode
== SHADER_OPCODE_POW
||
487 inst
->opcode
== SHADER_OPCODE_INT_QUOTIENT
||
488 inst
->opcode
== SHADER_OPCODE_INT_REMAINDER
) {
489 generate_math_gen4(inst
, dst
, src
);
493 int op
= brw_math_function(inst
->opcode
);
495 assert(inst
->mlen
>= 1);
500 BRW_MATH_PRECISION_FULL
);
504 fs_generator::generate_tex(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
,
505 struct brw_reg sampler_index
)
510 uint32_t return_format
;
511 bool is_combined_send
= inst
->eot
;
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 if (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);
625 if (inst
->shadow_compare
) {
626 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE
;
627 assert(inst
->mlen
== 9);
629 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE
;
630 assert(inst
->mlen
<= 7 && inst
->mlen
% 2 == 1);
635 if (inst
->shadow_compare
) {
636 assert(dispatch_width
== 8);
637 assert(inst
->mlen
== 6);
638 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE
;
640 assert(inst
->mlen
== 9);
641 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS
;
642 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
645 case SHADER_OPCODE_TXL
:
646 if (inst
->shadow_compare
) {
647 assert(dispatch_width
== 8);
648 assert(inst
->mlen
== 6);
649 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE
;
651 assert(inst
->mlen
== 9);
652 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD
;
653 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
656 case SHADER_OPCODE_TXD
:
657 /* There is no sample_d_c message; comparisons are done manually */
658 assert(dispatch_width
== 8);
659 assert(inst
->mlen
== 7 || inst
->mlen
== 10);
660 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS
;
662 case SHADER_OPCODE_TXF
:
663 assert(inst
->mlen
<= 9 && inst
->mlen
% 2 == 1);
664 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
665 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
667 case SHADER_OPCODE_TXS
:
668 assert(inst
->mlen
== 3);
669 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_RESINFO
;
670 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
673 unreachable("not reached");
676 assert(msg_type
!= -1);
678 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
683 if (is_combined_send
) {
684 assert(brw
->gen
>= 9 || brw
->is_cherryview
);
688 assert(brw
->gen
< 7 || !inst
->header_present
||
689 src
.file
== BRW_GENERAL_REGISTER_FILE
);
691 assert(sampler_index
.type
== BRW_REGISTER_TYPE_UD
);
693 /* Load the message header if present. If there's a texture offset,
694 * we need to set it up explicitly and load the offset bitfield.
695 * Otherwise, we can use an implied move from g0 to the first message reg.
697 if (inst
->header_present
) {
698 if (brw
->gen
< 6 && !inst
->offset
) {
699 /* Set up an implied move from g0 to the MRF. */
700 src
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
702 struct brw_reg header_reg
;
707 assert(inst
->base_mrf
!= -1);
708 header_reg
= brw_message_reg(inst
->base_mrf
);
711 brw_push_insn_state(p
);
712 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
713 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
714 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
715 /* Explicitly set up the message header by copying g0 to the MRF. */
716 brw_MOV(p
, header_reg
, brw_vec8_grf(0, 0));
719 /* Set the offset bits in DWord 2. */
720 brw_MOV(p
, get_element_ud(header_reg
, 2),
721 brw_imm_ud(inst
->offset
));
724 brw_adjust_sampler_state_pointer(p
, header_reg
, sampler_index
);
725 brw_pop_insn_state(p
);
729 uint32_t base_binding_table_index
= (inst
->opcode
== SHADER_OPCODE_TG4
||
730 inst
->opcode
== SHADER_OPCODE_TG4_OFFSET
)
731 ? prog_data
->binding_table
.gather_texture_start
732 : prog_data
->binding_table
.texture_start
;
734 if (sampler_index
.file
== BRW_IMMEDIATE_VALUE
) {
735 uint32_t sampler
= sampler_index
.dw1
.ud
;
738 retype(dst
, BRW_REGISTER_TYPE_UW
),
741 sampler
+ base_binding_table_index
,
746 inst
->header_present
,
750 brw_mark_surface_used(prog_data
, sampler
+ base_binding_table_index
);
752 /* Non-const sampler index */
753 /* Note: this clobbers `dst` as a temporary before emitting the send */
755 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
756 struct brw_reg temp
= vec1(retype(dst
, BRW_REGISTER_TYPE_UD
));
758 struct brw_reg sampler_reg
= vec1(retype(sampler_index
, BRW_REGISTER_TYPE_UD
));
760 brw_push_insn_state(p
);
761 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
762 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
764 /* Some care required: `sampler` and `temp` may alias:
765 * addr = sampler & 0xff
766 * temp = (sampler << 8) & 0xf00
769 brw_ADD(p
, addr
, sampler_reg
, brw_imm_ud(base_binding_table_index
));
770 brw_SHL(p
, temp
, sampler_reg
, brw_imm_ud(8u));
771 brw_AND(p
, temp
, temp
, brw_imm_ud(0x0f00));
772 brw_AND(p
, addr
, addr
, brw_imm_ud(0x0ff));
773 brw_OR(p
, addr
, addr
, temp
);
775 brw_pop_insn_state(p
);
777 /* dst = send(offset, a0.0 | <descriptor>) */
778 brw_inst
*insn
= brw_send_indirect_message(
779 p
, BRW_SFID_SAMPLER
, dst
, src
, addr
);
780 brw_set_sampler_message(p
, insn
,
785 inst
->mlen
/* mlen */,
786 inst
->header_present
/* header */,
790 /* visitor knows more than we do about the surface limit required,
791 * so has already done marking.
795 if (is_combined_send
) {
796 brw_inst_set_eot(p
->devinfo
, brw_last_inst
, true);
797 brw_inst_set_opcode(p
->devinfo
, brw_last_inst
, BRW_OPCODE_SENDC
);
802 /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
805 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
807 * Ideally, we want to produce:
810 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
811 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
812 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
813 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
814 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
815 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
816 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
817 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
819 * and add another set of two more subspans if in 16-pixel dispatch mode.
821 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
822 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
823 * pair. But the ideal approximation may impose a huge performance cost on
824 * sample_d. On at least Haswell, sample_d instruction does some
825 * optimizations if the same LOD is used for all pixels in the subspan.
827 * For DDY, we need to use ALIGN16 mode since it's capable of doing the
828 * appropriate swizzling.
831 fs_generator::generate_ddx(enum opcode opcode
,
832 struct brw_reg dst
, struct brw_reg src
)
834 unsigned vstride
, width
;
836 if (opcode
== FS_OPCODE_DDX_FINE
) {
837 /* produce accurate derivatives */
838 vstride
= BRW_VERTICAL_STRIDE_2
;
841 /* replicate the derivative at the top-left pixel to other pixels */
842 vstride
= BRW_VERTICAL_STRIDE_4
;
846 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 1,
851 BRW_HORIZONTAL_STRIDE_0
,
852 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
853 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
858 BRW_HORIZONTAL_STRIDE_0
,
859 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
860 brw_ADD(p
, dst
, src0
, negate(src1
));
863 /* The negate_value boolean is used to negate the derivative computation for
864 * FBOs, since they place the origin at the upper left instead of the lower
868 fs_generator::generate_ddy(enum opcode opcode
,
869 struct brw_reg dst
, struct brw_reg src
,
872 if (opcode
== FS_OPCODE_DDY_FINE
) {
873 /* From the Ivy Bridge PRM, volume 4 part 3, section 3.3.9 (Register
874 * Region Restrictions):
876 * In Align16 access mode, SIMD16 is not allowed for DW operations
877 * and SIMD8 is not allowed for DF operations.
879 * In this context, "DW operations" means "operations acting on 32-bit
880 * values", so it includes operations on floats.
882 * Gen4 has a similar restriction. From the i965 PRM, section 11.5.3
883 * (Instruction Compression -> Rules and Restrictions):
885 * A compressed instruction must be in Align1 access mode. Align16
886 * mode instructions cannot be compressed.
888 * Similar text exists in the g45 PRM.
890 * On these platforms, if we're building a SIMD16 shader, we need to
891 * manually unroll to a pair of SIMD8 instructions.
893 bool unroll_to_simd8
=
894 (dispatch_width
== 16 &&
895 (brw
->gen
== 4 || (brw
->gen
== 7 && !brw
->is_haswell
)));
897 /* produce accurate derivatives */
898 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
901 BRW_VERTICAL_STRIDE_4
,
903 BRW_HORIZONTAL_STRIDE_1
,
904 BRW_SWIZZLE_XYXY
, WRITEMASK_XYZW
);
905 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
908 BRW_VERTICAL_STRIDE_4
,
910 BRW_HORIZONTAL_STRIDE_1
,
911 BRW_SWIZZLE_ZWZW
, WRITEMASK_XYZW
);
912 brw_push_insn_state(p
);
913 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
914 if (unroll_to_simd8
) {
915 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
917 brw_ADD(p
, firsthalf(dst
), firsthalf(src1
), negate(firsthalf(src0
)));
918 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
919 brw_ADD(p
, sechalf(dst
), sechalf(src1
), negate(sechalf(src0
)));
921 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), negate(firsthalf(src1
)));
922 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
923 brw_ADD(p
, sechalf(dst
), sechalf(src0
), negate(sechalf(src1
)));
927 brw_ADD(p
, dst
, src1
, negate(src0
));
929 brw_ADD(p
, dst
, src0
, negate(src1
));
931 brw_pop_insn_state(p
);
933 /* replicate the derivative at the top-left pixel to other pixels */
934 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
937 BRW_VERTICAL_STRIDE_4
,
939 BRW_HORIZONTAL_STRIDE_0
,
940 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
941 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 2,
944 BRW_VERTICAL_STRIDE_4
,
946 BRW_HORIZONTAL_STRIDE_0
,
947 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
949 brw_ADD(p
, dst
, src1
, negate(src0
));
951 brw_ADD(p
, dst
, src0
, negate(src1
));
956 fs_generator::generate_discard_jump(fs_inst
*inst
)
958 assert(brw
->gen
>= 6);
960 /* This HALT will be patched up at FB write time to point UIP at the end of
961 * the program, and at brw_uip_jip() JIP will be set to the end of the
962 * current block (or the program).
964 this->discard_halt_patches
.push_tail(new(mem_ctx
) ip_record(p
->nr_insn
));
966 brw_push_insn_state(p
);
967 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
969 brw_pop_insn_state(p
);
973 fs_generator::generate_scratch_write(fs_inst
*inst
, struct brw_reg src
)
975 assert(inst
->mlen
!= 0);
978 brw_uvec_mrf(inst
->exec_size
, (inst
->base_mrf
+ 1), 0),
979 retype(src
, BRW_REGISTER_TYPE_UD
));
980 brw_oword_block_write_scratch(p
, brw_message_reg(inst
->base_mrf
),
981 inst
->exec_size
/ 8, inst
->offset
);
985 fs_generator::generate_scratch_read(fs_inst
*inst
, struct brw_reg dst
)
987 assert(inst
->mlen
!= 0);
989 brw_oword_block_read_scratch(p
, dst
, brw_message_reg(inst
->base_mrf
),
990 inst
->exec_size
/ 8, inst
->offset
);
994 fs_generator::generate_scratch_read_gen7(fs_inst
*inst
, struct brw_reg dst
)
996 gen7_block_read_scratch(p
, dst
, inst
->exec_size
/ 8, inst
->offset
);
1000 fs_generator::generate_uniform_pull_constant_load(fs_inst
*inst
,
1002 struct brw_reg index
,
1003 struct brw_reg offset
)
1005 assert(inst
->mlen
!= 0);
1007 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1008 index
.type
== BRW_REGISTER_TYPE_UD
);
1009 uint32_t surf_index
= index
.dw1
.ud
;
1011 assert(offset
.file
== BRW_IMMEDIATE_VALUE
&&
1012 offset
.type
== BRW_REGISTER_TYPE_UD
);
1013 uint32_t read_offset
= offset
.dw1
.ud
;
1015 brw_oword_block_read(p
, dst
, brw_message_reg(inst
->base_mrf
),
1016 read_offset
, surf_index
);
1018 brw_mark_surface_used(prog_data
, surf_index
);
1022 fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst
*inst
,
1024 struct brw_reg index
,
1025 struct brw_reg offset
)
1027 assert(inst
->mlen
== 0);
1028 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1030 assert(offset
.file
== BRW_GENERAL_REGISTER_FILE
);
1031 /* Reference just the dword we need, to avoid angering validate_reg(). */
1032 offset
= brw_vec1_grf(offset
.nr
, 0);
1034 /* We use the SIMD4x2 mode because we want to end up with 4 components in
1035 * the destination loaded consecutively from the same offset (which appears
1036 * in the first component, and the rest are ignored).
1038 dst
.width
= BRW_WIDTH_4
;
1040 struct brw_reg src
= offset
;
1041 bool header_present
= false;
1044 if (brw
->gen
>= 9) {
1045 /* Skylake requires a message header in order to use SIMD4x2 mode. */
1046 src
= retype(brw_vec4_grf(offset
.nr
- 1, 0), BRW_REGISTER_TYPE_UD
);
1048 header_present
= true;
1050 brw_push_insn_state(p
);
1051 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1052 brw_MOV(p
, vec8(src
), retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
1053 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1055 brw_MOV(p
, get_element_ud(src
, 2),
1056 brw_imm_ud(GEN9_SAMPLER_SIMD_MODE_EXTENSION_SIMD4X2
));
1057 brw_pop_insn_state(p
);
1060 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1062 uint32_t surf_index
= index
.dw1
.ud
;
1064 brw_push_insn_state(p
);
1065 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1066 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1067 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1068 brw_pop_insn_state(p
);
1070 brw_set_dest(p
, send
, dst
);
1071 brw_set_src0(p
, send
, src
);
1072 brw_set_sampler_message(p
, send
,
1074 0, /* LD message ignores sampler unit */
1075 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1079 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
1082 brw_mark_surface_used(prog_data
, surf_index
);
1086 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1088 brw_push_insn_state(p
);
1089 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1090 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1092 /* a0.0 = surf_index & 0xff */
1093 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1094 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1095 brw_set_dest(p
, insn_and
, addr
);
1096 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1097 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1099 /* dst = send(payload, a0.0 | <descriptor>) */
1100 brw_inst
*insn
= brw_send_indirect_message(
1101 p
, BRW_SFID_SAMPLER
, dst
, src
, addr
);
1102 brw_set_sampler_message(p
, insn
,
1104 0, /* LD message ignores sampler unit */
1105 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1109 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
1112 brw_pop_insn_state(p
);
1114 /* visitor knows more than we do about the surface limit required,
1115 * so has already done marking.
1122 fs_generator::generate_varying_pull_constant_load(fs_inst
*inst
,
1124 struct brw_reg index
,
1125 struct brw_reg offset
)
1127 assert(brw
->gen
< 7); /* Should use the gen7 variant. */
1128 assert(inst
->header_present
);
1131 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1132 index
.type
== BRW_REGISTER_TYPE_UD
);
1133 uint32_t surf_index
= index
.dw1
.ud
;
1135 uint32_t simd_mode
, rlen
, msg_type
;
1136 if (dispatch_width
== 16) {
1137 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1140 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1145 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
1147 /* We always use the SIMD16 message so that we only have to load U, and
1150 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
1151 assert(inst
->mlen
== 3);
1152 assert(inst
->regs_written
== 8);
1154 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1157 struct brw_reg offset_mrf
= retype(brw_message_reg(inst
->base_mrf
+ 1),
1158 BRW_REGISTER_TYPE_D
);
1159 brw_MOV(p
, offset_mrf
, offset
);
1161 struct brw_reg header
= brw_vec8_grf(0, 0);
1162 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
1164 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1165 brw_inst_set_qtr_control(p
->devinfo
, send
, BRW_COMPRESSION_NONE
);
1166 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1167 brw_set_src0(p
, send
, header
);
1169 brw_inst_set_base_mrf(p
->devinfo
, send
, inst
->base_mrf
);
1171 /* Our surface is set up as floats, regardless of what actual data is
1174 uint32_t return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
1175 brw_set_sampler_message(p
, send
,
1177 0, /* sampler (unused) */
1181 inst
->header_present
,
1185 brw_mark_surface_used(prog_data
, surf_index
);
1189 fs_generator::generate_varying_pull_constant_load_gen7(fs_inst
*inst
,
1191 struct brw_reg index
,
1192 struct brw_reg offset
)
1194 assert(brw
->gen
>= 7);
1195 /* Varying-offset pull constant loads are treated as a normal expression on
1196 * gen7, so the fact that it's a send message is hidden at the IR level.
1198 assert(!inst
->header_present
);
1199 assert(!inst
->mlen
);
1200 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1202 uint32_t simd_mode
, rlen
, mlen
;
1203 if (dispatch_width
== 16) {
1206 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1210 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1213 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1215 uint32_t surf_index
= index
.dw1
.ud
;
1217 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1218 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1219 brw_set_src0(p
, send
, offset
);
1220 brw_set_sampler_message(p
, send
,
1222 0, /* LD message ignores sampler unit */
1223 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1226 false, /* no header */
1230 brw_mark_surface_used(prog_data
, surf_index
);
1234 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1236 brw_push_insn_state(p
);
1237 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1238 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1240 /* a0.0 = surf_index & 0xff */
1241 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1242 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1243 brw_set_dest(p
, insn_and
, addr
);
1244 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1245 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1247 brw_pop_insn_state(p
);
1249 /* dst = send(offset, a0.0 | <descriptor>) */
1250 brw_inst
*insn
= brw_send_indirect_message(
1251 p
, BRW_SFID_SAMPLER
, retype(dst
, BRW_REGISTER_TYPE_UW
),
1253 brw_set_sampler_message(p
, insn
,
1256 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1263 /* visitor knows more than we do about the surface limit required,
1264 * so has already done marking.
1270 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
1271 * into the flags register (f0.0).
1273 * Used only on Gen6 and above.
1276 fs_generator::generate_mov_dispatch_to_flags(fs_inst
*inst
)
1278 struct brw_reg flags
= brw_flag_reg(0, inst
->flag_subreg
);
1279 struct brw_reg dispatch_mask
;
1282 dispatch_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
1284 dispatch_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
1286 brw_push_insn_state(p
);
1287 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1288 brw_MOV(p
, flags
, dispatch_mask
);
1289 brw_pop_insn_state(p
);
1293 fs_generator::generate_pixel_interpolator_query(fs_inst
*inst
,
1296 struct brw_reg msg_data
,
1299 assert(msg_data
.file
== BRW_IMMEDIATE_VALUE
&&
1300 msg_data
.type
== BRW_REGISTER_TYPE_UD
);
1302 brw_pixel_interpolator_query(p
,
1303 retype(dst
, BRW_REGISTER_TYPE_UW
),
1305 inst
->pi_noperspective
,
1309 inst
->regs_written
);
1314 * Sets the first word of a vgrf for gen7+ simd4x2 uniform pull constant
1315 * sampler LD messages.
1317 * We don't want to bake it into the send message's code generation because
1318 * that means we don't get a chance to schedule the instructions.
1321 fs_generator::generate_set_simd4x2_offset(fs_inst
*inst
,
1323 struct brw_reg value
)
1325 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1327 brw_push_insn_state(p
);
1328 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1329 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1330 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1331 brw_MOV(p
, retype(brw_vec1_reg(dst
.file
, dst
.nr
, 0), value
.type
), value
);
1332 brw_pop_insn_state(p
);
1335 /* Sets vstride=16, width=8, hstride=2 or vstride=0, width=1, hstride=0
1336 * (when mask is passed as a uniform) of register mask before moving it
1340 fs_generator::generate_set_omask(fs_inst
*inst
,
1342 struct brw_reg mask
)
1345 (mask
.vstride
== BRW_VERTICAL_STRIDE_8
&&
1346 mask
.width
== BRW_WIDTH_8
&&
1347 mask
.hstride
== BRW_HORIZONTAL_STRIDE_1
);
1349 bool stride_0_1_0
= has_scalar_region(mask
);
1351 assert(stride_8_8_1
|| stride_0_1_0
);
1352 assert(dst
.type
== BRW_REGISTER_TYPE_UW
);
1354 brw_push_insn_state(p
);
1355 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1356 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1359 brw_MOV(p
, dst
, retype(stride(mask
, 16, 8, 2), dst
.type
));
1360 } else if (stride_0_1_0
) {
1361 brw_MOV(p
, dst
, retype(mask
, dst
.type
));
1363 brw_pop_insn_state(p
);
1366 /* Sets vstride=1, width=4, hstride=0 of register src1 during
1367 * the ADD instruction.
1370 fs_generator::generate_set_sample_id(fs_inst
*inst
,
1372 struct brw_reg src0
,
1373 struct brw_reg src1
)
1375 assert(dst
.type
== BRW_REGISTER_TYPE_D
||
1376 dst
.type
== BRW_REGISTER_TYPE_UD
);
1377 assert(src0
.type
== BRW_REGISTER_TYPE_D
||
1378 src0
.type
== BRW_REGISTER_TYPE_UD
);
1380 brw_push_insn_state(p
);
1381 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1382 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1383 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1384 struct brw_reg reg
= retype(stride(src1
, 1, 4, 0), BRW_REGISTER_TYPE_UW
);
1385 if (dispatch_width
== 8) {
1386 brw_ADD(p
, dst
, src0
, reg
);
1387 } else if (dispatch_width
== 16) {
1388 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), reg
);
1389 brw_ADD(p
, sechalf(dst
), sechalf(src0
), suboffset(reg
, 2));
1391 brw_pop_insn_state(p
);
1395 fs_generator::generate_pack_half_2x16_split(fs_inst
*inst
,
1400 assert(brw
->gen
>= 7);
1401 assert(dst
.type
== BRW_REGISTER_TYPE_UD
);
1402 assert(x
.type
== BRW_REGISTER_TYPE_F
);
1403 assert(y
.type
== BRW_REGISTER_TYPE_F
);
1405 /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16:
1407 * Because this instruction does not have a 16-bit floating-point type,
1408 * the destination data type must be Word (W).
1410 * The destination must be DWord-aligned and specify a horizontal stride
1411 * (HorzStride) of 2. The 16-bit result is stored in the lower word of
1412 * each destination channel and the upper word is not modified.
1414 struct brw_reg dst_w
= spread(retype(dst
, BRW_REGISTER_TYPE_W
), 2);
1416 /* Give each 32-bit channel of dst the form below, where "." means
1420 brw_F32TO16(p
, dst_w
, y
);
1425 brw_SHL(p
, dst
, dst
, brw_imm_ud(16u));
1427 /* And, finally the form of packHalf2x16's output:
1430 brw_F32TO16(p
, dst_w
, x
);
1434 fs_generator::generate_unpack_half_2x16_split(fs_inst
*inst
,
1438 assert(brw
->gen
>= 7);
1439 assert(dst
.type
== BRW_REGISTER_TYPE_F
);
1440 assert(src
.type
== BRW_REGISTER_TYPE_UD
);
1442 /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32:
1444 * Because this instruction does not have a 16-bit floating-point type,
1445 * the source data type must be Word (W). The destination type must be
1448 struct brw_reg src_w
= spread(retype(src
, BRW_REGISTER_TYPE_W
), 2);
1450 /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
1451 * For the Y case, we wish to access only the upper word; therefore
1452 * a 16-bit subregister offset is needed.
1454 assert(inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
||
1455 inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
);
1456 if (inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
)
1459 brw_F16TO32(p
, dst
, src_w
);
1463 fs_generator::generate_shader_time_add(fs_inst
*inst
,
1464 struct brw_reg payload
,
1465 struct brw_reg offset
,
1466 struct brw_reg value
)
1468 assert(brw
->gen
>= 7);
1469 brw_push_insn_state(p
);
1470 brw_set_default_mask_control(p
, true);
1472 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1473 struct brw_reg payload_offset
= retype(brw_vec1_grf(payload
.nr
, 0),
1475 struct brw_reg payload_value
= retype(brw_vec1_grf(payload
.nr
+ 1, 0),
1478 assert(offset
.file
== BRW_IMMEDIATE_VALUE
);
1479 if (value
.file
== BRW_GENERAL_REGISTER_FILE
) {
1480 value
.width
= BRW_WIDTH_1
;
1481 value
.hstride
= BRW_HORIZONTAL_STRIDE_0
;
1482 value
.vstride
= BRW_VERTICAL_STRIDE_0
;
1484 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1487 /* Trying to deal with setup of the params from the IR is crazy in the FS8
1488 * case, and we don't really care about squeezing every bit of performance
1489 * out of this path, so we just emit the MOVs from here.
1491 brw_MOV(p
, payload_offset
, offset
);
1492 brw_MOV(p
, payload_value
, value
);
1493 brw_shader_time_add(p
, payload
,
1494 prog_data
->binding_table
.shader_time_start
);
1495 brw_pop_insn_state(p
);
1497 brw_mark_surface_used(prog_data
,
1498 prog_data
->binding_table
.shader_time_start
);
1502 fs_generator::generate_untyped_atomic(fs_inst
*inst
, struct brw_reg dst
,
1503 struct brw_reg payload
,
1504 struct brw_reg atomic_op
,
1505 struct brw_reg surf_index
)
1507 assert(atomic_op
.file
== BRW_IMMEDIATE_VALUE
&&
1508 atomic_op
.type
== BRW_REGISTER_TYPE_UD
&&
1509 surf_index
.file
== BRW_IMMEDIATE_VALUE
&&
1510 surf_index
.type
== BRW_REGISTER_TYPE_UD
);
1512 brw_untyped_atomic(p
, dst
, payload
,
1513 atomic_op
.dw1
.ud
, surf_index
.dw1
.ud
,
1516 brw_mark_surface_used(prog_data
, surf_index
.dw1
.ud
);
1520 fs_generator::generate_untyped_surface_read(fs_inst
*inst
, struct brw_reg dst
,
1521 struct brw_reg payload
,
1522 struct brw_reg surf_index
)
1524 assert(surf_index
.file
== BRW_IMMEDIATE_VALUE
&&
1525 surf_index
.type
== BRW_REGISTER_TYPE_UD
);
1527 brw_untyped_surface_read(p
, dst
, payload
, surf_index
.dw1
.ud
, inst
->mlen
, 1);
1529 brw_mark_surface_used(prog_data
, surf_index
.dw1
.ud
);
1533 fs_generator::enable_debug(const char *shader_name
)
1536 this->shader_name
= shader_name
;
1540 * Some hardware doesn't support SIMD16 instructions with 3 sources.
1543 brw_supports_simd16_3src(const struct brw_context
*brw
)
1545 /* WaDisableSIMD16On3SrcInstr: 3-source instructions don't work in SIMD16
1546 * on a few steppings of Skylake.
1549 return brw
->revision
!= 2 && brw
->revision
!= 3 && brw
->revision
!= -1;
1551 return brw
->is_haswell
|| brw
->gen
>= 8;
1555 fs_generator::generate_code(const cfg_t
*cfg
, int dispatch_width
)
1557 /* align to 64 byte boundary. */
1558 while (p
->next_insn_offset
% 64)
1561 this->dispatch_width
= dispatch_width
;
1562 if (dispatch_width
== 16)
1563 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1565 int start_offset
= p
->next_insn_offset
;
1566 int spill_count
= 0, fill_count
= 0;
1569 struct annotation_info annotation
;
1570 memset(&annotation
, 0, sizeof(annotation
));
1572 foreach_block_and_inst (block
, fs_inst
, inst
, cfg
) {
1573 struct brw_reg src
[3], dst
;
1574 unsigned int last_insn_offset
= p
->next_insn_offset
;
1575 bool multiple_instructions_emitted
= false;
1577 if (unlikely(debug_flag
))
1578 annotate(brw
, &annotation
, cfg
, inst
, p
->next_insn_offset
);
1580 for (unsigned int i
= 0; i
< inst
->sources
; i
++) {
1581 src
[i
] = brw_reg_from_fs_reg(&inst
->src
[i
]);
1583 /* The accumulator result appears to get used for the
1584 * conditional modifier generation. When negating a UD
1585 * value, there is a 33rd bit generated for the sign in the
1586 * accumulator value, so now you can't check, for example,
1587 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
1589 assert(!inst
->conditional_mod
||
1590 inst
->src
[i
].type
!= BRW_REGISTER_TYPE_UD
||
1591 !inst
->src
[i
].negate
);
1593 dst
= brw_reg_from_fs_reg(&inst
->dst
);
1595 brw_set_default_predicate_control(p
, inst
->predicate
);
1596 brw_set_default_predicate_inverse(p
, inst
->predicate_inverse
);
1597 brw_set_default_flag_reg(p
, 0, inst
->flag_subreg
);
1598 brw_set_default_saturate(p
, inst
->saturate
);
1599 brw_set_default_mask_control(p
, inst
->force_writemask_all
);
1600 brw_set_default_acc_write_control(p
, inst
->writes_accumulator
);
1601 brw_set_default_exec_size(p
, cvt(inst
->exec_size
) - 1);
1603 switch (inst
->exec_size
) {
1607 assert(inst
->force_writemask_all
);
1608 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1611 if (inst
->force_sechalf
) {
1612 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1614 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1619 if (type_sz(inst
->dst
.type
) < sizeof(float))
1620 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1622 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1625 unreachable("Invalid instruction width");
1628 switch (inst
->opcode
) {
1629 case BRW_OPCODE_MOV
:
1630 brw_MOV(p
, dst
, src
[0]);
1632 case BRW_OPCODE_ADD
:
1633 brw_ADD(p
, dst
, src
[0], src
[1]);
1635 case BRW_OPCODE_MUL
:
1636 brw_MUL(p
, dst
, src
[0], src
[1]);
1638 case BRW_OPCODE_AVG
:
1639 brw_AVG(p
, dst
, src
[0], src
[1]);
1641 case BRW_OPCODE_MACH
:
1642 brw_MACH(p
, dst
, src
[0], src
[1]);
1645 case BRW_OPCODE_LINE
:
1646 brw_LINE(p
, dst
, src
[0], src
[1]);
1649 case BRW_OPCODE_MAD
:
1650 assert(brw
->gen
>= 6);
1651 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1652 if (dispatch_width
== 16 && !brw_supports_simd16_3src(brw
)) {
1653 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1654 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1655 brw_inst
*f
= brw_MAD(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1656 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1657 brw_inst
*s
= brw_MAD(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1658 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1660 if (inst
->conditional_mod
) {
1661 brw_inst_set_cond_modifier(p
->devinfo
, f
, inst
->conditional_mod
);
1662 brw_inst_set_cond_modifier(p
->devinfo
, s
, inst
->conditional_mod
);
1663 multiple_instructions_emitted
= true;
1666 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
1668 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1671 case BRW_OPCODE_LRP
:
1672 assert(brw
->gen
>= 6);
1673 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1674 if (dispatch_width
== 16 && !brw_supports_simd16_3src(brw
)) {
1675 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1676 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1677 brw_inst
*f
= brw_LRP(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1678 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1679 brw_inst
*s
= brw_LRP(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1680 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1682 if (inst
->conditional_mod
) {
1683 brw_inst_set_cond_modifier(p
->devinfo
, f
, inst
->conditional_mod
);
1684 brw_inst_set_cond_modifier(p
->devinfo
, s
, inst
->conditional_mod
);
1685 multiple_instructions_emitted
= true;
1688 brw_LRP(p
, dst
, src
[0], src
[1], src
[2]);
1690 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1693 case BRW_OPCODE_FRC
:
1694 brw_FRC(p
, dst
, src
[0]);
1696 case BRW_OPCODE_RNDD
:
1697 brw_RNDD(p
, dst
, src
[0]);
1699 case BRW_OPCODE_RNDE
:
1700 brw_RNDE(p
, dst
, src
[0]);
1702 case BRW_OPCODE_RNDZ
:
1703 brw_RNDZ(p
, dst
, src
[0]);
1706 case BRW_OPCODE_AND
:
1707 brw_AND(p
, dst
, src
[0], src
[1]);
1710 brw_OR(p
, dst
, src
[0], src
[1]);
1712 case BRW_OPCODE_XOR
:
1713 brw_XOR(p
, dst
, src
[0], src
[1]);
1715 case BRW_OPCODE_NOT
:
1716 brw_NOT(p
, dst
, src
[0]);
1718 case BRW_OPCODE_ASR
:
1719 brw_ASR(p
, dst
, src
[0], src
[1]);
1721 case BRW_OPCODE_SHR
:
1722 brw_SHR(p
, dst
, src
[0], src
[1]);
1724 case BRW_OPCODE_SHL
:
1725 brw_SHL(p
, dst
, src
[0], src
[1]);
1727 case BRW_OPCODE_F32TO16
:
1728 assert(brw
->gen
>= 7);
1729 brw_F32TO16(p
, dst
, src
[0]);
1731 case BRW_OPCODE_F16TO32
:
1732 assert(brw
->gen
>= 7);
1733 brw_F16TO32(p
, dst
, src
[0]);
1735 case BRW_OPCODE_CMP
:
1736 /* The Ivybridge/BayTrail WaCMPInstFlagDepClearedEarly workaround says
1737 * that when the destination is a GRF that the dependency-clear bit on
1738 * the flag register is cleared early.
1740 * Suggested workarounds are to disable coissuing CMP instructions
1741 * or to split CMP(16) instructions into two CMP(8) instructions.
1743 * We choose to split into CMP(8) instructions since disabling
1744 * coissuing would affect CMP instructions not otherwise affected by
1747 if (dispatch_width
== 16 && brw
->gen
== 7 && !brw
->is_haswell
) {
1748 if (dst
.file
== BRW_GENERAL_REGISTER_FILE
) {
1749 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1750 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1751 brw_CMP(p
, firsthalf(dst
), inst
->conditional_mod
,
1752 firsthalf(src
[0]), firsthalf(src
[1]));
1753 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1754 brw_CMP(p
, sechalf(dst
), inst
->conditional_mod
,
1755 sechalf(src
[0]), sechalf(src
[1]));
1756 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1758 multiple_instructions_emitted
= true;
1759 } else if (dst
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1760 /* For unknown reasons, the aforementioned workaround is not
1761 * sufficient. Overriding the type when the destination is the
1762 * null register is necessary but not sufficient by itself.
1764 assert(dst
.nr
== BRW_ARF_NULL
);
1765 dst
.type
= BRW_REGISTER_TYPE_D
;
1766 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1768 unreachable("not reached");
1771 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1774 case BRW_OPCODE_SEL
:
1775 brw_SEL(p
, dst
, src
[0], src
[1]);
1777 case BRW_OPCODE_BFREV
:
1778 assert(brw
->gen
>= 7);
1779 /* BFREV only supports UD type for src and dst. */
1780 brw_BFREV(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1781 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1783 case BRW_OPCODE_FBH
:
1784 assert(brw
->gen
>= 7);
1785 /* FBH only supports UD type for dst. */
1786 brw_FBH(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1788 case BRW_OPCODE_FBL
:
1789 assert(brw
->gen
>= 7);
1790 /* FBL only supports UD type for dst. */
1791 brw_FBL(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1793 case BRW_OPCODE_CBIT
:
1794 assert(brw
->gen
>= 7);
1795 /* CBIT only supports UD type for dst. */
1796 brw_CBIT(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1798 case BRW_OPCODE_ADDC
:
1799 assert(brw
->gen
>= 7);
1800 brw_ADDC(p
, dst
, src
[0], src
[1]);
1802 case BRW_OPCODE_SUBB
:
1803 assert(brw
->gen
>= 7);
1804 brw_SUBB(p
, dst
, src
[0], src
[1]);
1806 case BRW_OPCODE_MAC
:
1807 brw_MAC(p
, dst
, src
[0], src
[1]);
1810 case BRW_OPCODE_BFE
:
1811 assert(brw
->gen
>= 7);
1812 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1813 if (dispatch_width
== 16 && !brw_supports_simd16_3src(brw
)) {
1814 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1815 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1816 brw_BFE(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1817 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1818 brw_BFE(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1819 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1821 brw_BFE(p
, dst
, src
[0], src
[1], src
[2]);
1823 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1826 case BRW_OPCODE_BFI1
:
1827 assert(brw
->gen
>= 7);
1828 /* The Haswell WaForceSIMD8ForBFIInstruction workaround says that we
1831 * "Force BFI instructions to be executed always in SIMD8."
1833 if (dispatch_width
== 16 && brw
->is_haswell
) {
1834 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1835 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1836 brw_BFI1(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]));
1837 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1838 brw_BFI1(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]));
1839 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1841 brw_BFI1(p
, dst
, src
[0], src
[1]);
1844 case BRW_OPCODE_BFI2
:
1845 assert(brw
->gen
>= 7);
1846 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1847 /* The Haswell WaForceSIMD8ForBFIInstruction workaround says that we
1850 * "Force BFI instructions to be executed always in SIMD8."
1852 * Otherwise we would be able to emit compressed instructions like we
1853 * do for the other three-source instructions.
1855 if (dispatch_width
== 16 &&
1856 (brw
->is_haswell
|| !brw_supports_simd16_3src(brw
))) {
1857 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1858 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1859 brw_BFI2(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1860 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1861 brw_BFI2(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1862 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1864 brw_BFI2(p
, dst
, src
[0], src
[1], src
[2]);
1866 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1870 if (inst
->src
[0].file
!= BAD_FILE
) {
1871 /* The instruction has an embedded compare (only allowed on gen6) */
1872 assert(brw
->gen
== 6);
1873 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
1875 brw_IF(p
, dispatch_width
== 16 ? BRW_EXECUTE_16
: BRW_EXECUTE_8
);
1879 case BRW_OPCODE_ELSE
:
1882 case BRW_OPCODE_ENDIF
:
1887 brw_DO(p
, BRW_EXECUTE_8
);
1890 case BRW_OPCODE_BREAK
:
1892 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
1894 case BRW_OPCODE_CONTINUE
:
1896 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
1899 case BRW_OPCODE_WHILE
:
1904 case SHADER_OPCODE_RCP
:
1905 case SHADER_OPCODE_RSQ
:
1906 case SHADER_OPCODE_SQRT
:
1907 case SHADER_OPCODE_EXP2
:
1908 case SHADER_OPCODE_LOG2
:
1909 case SHADER_OPCODE_SIN
:
1910 case SHADER_OPCODE_COS
:
1911 assert(brw
->gen
< 6 || inst
->mlen
== 0);
1912 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1913 if (brw
->gen
>= 7) {
1914 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0],
1916 } else if (brw
->gen
== 6) {
1917 generate_math_gen6(inst
, dst
, src
[0], brw_null_reg());
1918 } else if (brw
->gen
== 5 || brw
->is_g4x
) {
1919 generate_math_g45(inst
, dst
, src
[0]);
1921 generate_math_gen4(inst
, dst
, src
[0]);
1924 case SHADER_OPCODE_INT_QUOTIENT
:
1925 case SHADER_OPCODE_INT_REMAINDER
:
1926 case SHADER_OPCODE_POW
:
1927 assert(brw
->gen
< 6 || inst
->mlen
== 0);
1928 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1929 if (brw
->gen
>= 7 && inst
->opcode
== SHADER_OPCODE_POW
) {
1930 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0], src
[1]);
1931 } else if (brw
->gen
>= 6) {
1932 generate_math_gen6(inst
, dst
, src
[0], src
[1]);
1934 generate_math_gen4(inst
, dst
, src
[0]);
1937 case FS_OPCODE_CINTERP
:
1938 brw_MOV(p
, dst
, src
[0]);
1940 case FS_OPCODE_LINTERP
:
1941 generate_linterp(inst
, dst
, src
);
1943 case FS_OPCODE_PIXEL_X
:
1944 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1945 src
[0].subnr
= 0 * type_sz(src
[0].type
);
1946 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1948 case FS_OPCODE_PIXEL_Y
:
1949 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1950 src
[0].subnr
= 4 * type_sz(src
[0].type
);
1951 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1953 case SHADER_OPCODE_TEX
:
1955 case SHADER_OPCODE_TXD
:
1956 case SHADER_OPCODE_TXF
:
1957 case SHADER_OPCODE_TXF_CMS
:
1958 case SHADER_OPCODE_TXF_UMS
:
1959 case SHADER_OPCODE_TXF_MCS
:
1960 case SHADER_OPCODE_TXL
:
1961 case SHADER_OPCODE_TXS
:
1962 case SHADER_OPCODE_LOD
:
1963 case SHADER_OPCODE_TG4
:
1964 case SHADER_OPCODE_TG4_OFFSET
:
1965 generate_tex(inst
, dst
, src
[0], src
[1]);
1967 case FS_OPCODE_DDX_COARSE
:
1968 case FS_OPCODE_DDX_FINE
:
1969 generate_ddx(inst
->opcode
, dst
, src
[0]);
1971 case FS_OPCODE_DDY_COARSE
:
1972 case FS_OPCODE_DDY_FINE
:
1973 assert(src
[1].file
== BRW_IMMEDIATE_VALUE
);
1974 generate_ddy(inst
->opcode
, dst
, src
[0], src
[1].dw1
.ud
);
1977 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
1978 generate_scratch_write(inst
, src
[0]);
1982 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
1983 generate_scratch_read(inst
, dst
);
1987 case SHADER_OPCODE_GEN7_SCRATCH_READ
:
1988 generate_scratch_read_gen7(inst
, dst
);
1992 case SHADER_OPCODE_URB_WRITE_SIMD8
:
1993 generate_urb_write(inst
, src
[0]);
1996 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
:
1997 generate_uniform_pull_constant_load(inst
, dst
, src
[0], src
[1]);
2000 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7
:
2001 generate_uniform_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
2004 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD
:
2005 generate_varying_pull_constant_load(inst
, dst
, src
[0], src
[1]);
2008 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
:
2009 generate_varying_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
2012 case FS_OPCODE_REP_FB_WRITE
:
2013 case FS_OPCODE_FB_WRITE
:
2014 generate_fb_write(inst
, src
[0]);
2017 case FS_OPCODE_BLORP_FB_WRITE
:
2018 generate_blorp_fb_write(inst
);
2021 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS
:
2022 generate_mov_dispatch_to_flags(inst
);
2025 case FS_OPCODE_DISCARD_JUMP
:
2026 generate_discard_jump(inst
);
2029 case SHADER_OPCODE_SHADER_TIME_ADD
:
2030 generate_shader_time_add(inst
, src
[0], src
[1], src
[2]);
2033 case SHADER_OPCODE_UNTYPED_ATOMIC
:
2034 generate_untyped_atomic(inst
, dst
, src
[0], src
[1], src
[2]);
2037 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
2038 generate_untyped_surface_read(inst
, dst
, src
[0], src
[1]);
2041 case FS_OPCODE_SET_SIMD4X2_OFFSET
:
2042 generate_set_simd4x2_offset(inst
, dst
, src
[0]);
2045 case FS_OPCODE_SET_OMASK
:
2046 generate_set_omask(inst
, dst
, src
[0]);
2049 case FS_OPCODE_SET_SAMPLE_ID
:
2050 generate_set_sample_id(inst
, dst
, src
[0], src
[1]);
2053 case FS_OPCODE_PACK_HALF_2x16_SPLIT
:
2054 generate_pack_half_2x16_split(inst
, dst
, src
[0], src
[1]);
2057 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
:
2058 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
:
2059 generate_unpack_half_2x16_split(inst
, dst
, src
[0]);
2062 case FS_OPCODE_PLACEHOLDER_HALT
:
2063 /* This is the place where the final HALT needs to be inserted if
2064 * we've emitted any discards. If not, this will emit no code.
2066 if (!patch_discard_jumps_to_fb_writes()) {
2067 if (unlikely(debug_flag
)) {
2068 annotation
.ann_count
--;
2073 case FS_OPCODE_INTERPOLATE_AT_CENTROID
:
2074 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2075 GEN7_PIXEL_INTERPOLATOR_LOC_CENTROID
);
2078 case FS_OPCODE_INTERPOLATE_AT_SAMPLE
:
2079 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2080 GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE
);
2083 case FS_OPCODE_INTERPOLATE_AT_SHARED_OFFSET
:
2084 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2085 GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET
);
2088 case FS_OPCODE_INTERPOLATE_AT_PER_SLOT_OFFSET
:
2089 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2090 GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET
);
2094 if (inst
->opcode
< (int) ARRAY_SIZE(opcode_descs
)) {
2095 _mesa_problem(ctx
, "Unsupported opcode `%s' in %s",
2096 opcode_descs
[inst
->opcode
].name
, stage_abbrev
);
2098 _mesa_problem(ctx
, "Unsupported opcode %d in %s", inst
->opcode
,
2103 case SHADER_OPCODE_LOAD_PAYLOAD
:
2104 unreachable("Should be lowered by lower_load_payload()");
2107 if (multiple_instructions_emitted
)
2110 if (inst
->no_dd_clear
|| inst
->no_dd_check
|| inst
->conditional_mod
) {
2111 assert(p
->next_insn_offset
== last_insn_offset
+ 16 ||
2112 !"conditional_mod, no_dd_check, or no_dd_clear set for IR "
2113 "emitting more than 1 instruction");
2115 brw_inst
*last
= &p
->store
[last_insn_offset
/ 16];
2117 if (inst
->conditional_mod
)
2118 brw_inst_set_cond_modifier(p
->devinfo
, last
, inst
->conditional_mod
);
2119 brw_inst_set_no_dd_clear(p
->devinfo
, last
, inst
->no_dd_clear
);
2120 brw_inst_set_no_dd_check(p
->devinfo
, last
, inst
->no_dd_check
);
2125 annotation_finalize(&annotation
, p
->next_insn_offset
);
2127 int before_size
= p
->next_insn_offset
- start_offset
;
2128 brw_compact_instructions(p
, start_offset
, annotation
.ann_count
,
2130 int after_size
= p
->next_insn_offset
- start_offset
;
2132 if (unlikely(debug_flag
)) {
2133 fprintf(stderr
, "Native code for %s\n"
2134 "SIMD%d shader: %d instructions. %d loops. %d:%d spills:fills. Promoted %u constants. Compacted %d to %d"
2135 " bytes (%.0f%%)\n",
2136 shader_name
, dispatch_width
, before_size
/ 16, loop_count
,
2137 spill_count
, fill_count
, promoted_constants
, before_size
, after_size
,
2138 100.0f
* (before_size
- after_size
) / before_size
);
2140 dump_assembly(p
->store
, annotation
.ann_count
, annotation
.ann
, brw
, prog
);
2141 ralloc_free(annotation
.ann
);
2144 static GLuint msg_id
= 0;
2145 _mesa_gl_debug(&brw
->ctx
, &msg_id
,
2146 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2147 MESA_DEBUG_TYPE_OTHER
,
2148 MESA_DEBUG_SEVERITY_NOTIFICATION
,
2149 "%s SIMD%d shader: %d inst, %d loops, %d:%d spills:fills, "
2150 "Promoted %u constants, compacted %d to %d bytes.\n",
2151 stage_abbrev
, dispatch_width
, before_size
/ 16, loop_count
,
2152 spill_count
, fill_count
, promoted_constants
, before_size
, after_size
);
2154 return start_offset
;
2158 fs_generator::get_assembly(unsigned int *assembly_size
)
2160 return brw_get_program(p
, assembly_size
);