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_inst
*inst
, fs_reg
*reg
)
53 struct brw_reg brw_reg
;
57 assert((reg
->reg
& ~(1 << 7)) < BRW_MAX_MRF
);
60 if (reg
->stride
== 0) {
61 brw_reg
= brw_vec1_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
62 } else if (inst
->exec_size
< 8) {
63 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
64 brw_reg
= stride(brw_reg
, inst
->exec_size
* reg
->stride
,
65 inst
->exec_size
, reg
->stride
);
67 /* From the Haswell PRM:
69 * VertStride must be used to cross GRF register boundaries. This
70 * rule implies that elements within a 'Width' cannot cross GRF
73 * So, for registers with width > 8, we have to use a width of 8
74 * and trust the compression state to sort out the exec size.
76 brw_reg
= brw_vec8_reg(brw_file_from_reg(reg
), reg
->reg
, 0);
77 brw_reg
= stride(brw_reg
, 8 * reg
->stride
, 8, reg
->stride
);
80 brw_reg
= retype(brw_reg
, reg
->type
);
81 brw_reg
= byte_offset(brw_reg
, reg
->subreg_offset
);
84 assert(reg
->stride
== ((reg
->type
== BRW_REGISTER_TYPE_V
||
85 reg
->type
== BRW_REGISTER_TYPE_UV
||
86 reg
->type
== BRW_REGISTER_TYPE_VF
) ? 1 : 0));
89 case BRW_REGISTER_TYPE_F
:
90 brw_reg
= brw_imm_f(reg
->fixed_hw_reg
.dw1
.f
);
92 case BRW_REGISTER_TYPE_D
:
93 brw_reg
= brw_imm_d(reg
->fixed_hw_reg
.dw1
.d
);
95 case BRW_REGISTER_TYPE_UD
:
96 brw_reg
= brw_imm_ud(reg
->fixed_hw_reg
.dw1
.ud
);
98 case BRW_REGISTER_TYPE_W
:
99 brw_reg
= brw_imm_w(reg
->fixed_hw_reg
.dw1
.d
);
101 case BRW_REGISTER_TYPE_UW
:
102 brw_reg
= brw_imm_uw(reg
->fixed_hw_reg
.dw1
.ud
);
104 case BRW_REGISTER_TYPE_VF
:
105 brw_reg
= brw_imm_vf(reg
->fixed_hw_reg
.dw1
.ud
);
108 unreachable("not reached");
112 assert(reg
->type
== reg
->fixed_hw_reg
.type
);
113 brw_reg
= reg
->fixed_hw_reg
;
116 /* Probably unused. */
117 brw_reg
= brw_null_reg();
120 unreachable("not reached");
123 brw_reg
= brw_abs(brw_reg
);
125 brw_reg
= negate(brw_reg
);
130 fs_generator::fs_generator(const struct brw_compiler
*compiler
, void *log_data
,
133 struct brw_stage_prog_data
*prog_data
,
134 struct gl_program
*prog
,
135 unsigned promoted_constants
,
136 bool runtime_check_aads_emit
,
137 const char *stage_abbrev
)
139 : compiler(compiler
), log_data(log_data
),
140 devinfo(compiler
->devinfo
), key(key
),
141 prog_data(prog_data
),
142 prog(prog
), promoted_constants(promoted_constants
),
143 runtime_check_aads_emit(runtime_check_aads_emit
), debug_flag(false),
144 stage_abbrev(stage_abbrev
), mem_ctx(mem_ctx
)
146 p
= rzalloc(mem_ctx
, struct brw_codegen
);
147 brw_init_codegen(devinfo
, p
, mem_ctx
);
150 fs_generator::~fs_generator()
154 class ip_record
: public exec_node
{
156 DECLARE_RALLOC_CXX_OPERATORS(ip_record
)
167 fs_generator::patch_discard_jumps_to_fb_writes()
169 if (devinfo
->gen
< 6 || this->discard_halt_patches
.is_empty())
172 int scale
= brw_jump_scale(p
->devinfo
);
174 /* There is a somewhat strange undocumented requirement of using
175 * HALT, according to the simulator. If some channel has HALTed to
176 * a particular UIP, then by the end of the program, every channel
177 * must have HALTed to that UIP. Furthermore, the tracking is a
178 * stack, so you can't do the final halt of a UIP after starting
179 * halting to a new UIP.
181 * Symptoms of not emitting this instruction on actual hardware
182 * included GPU hangs and sparkly rendering on the piglit discard
185 brw_inst
*last_halt
= gen6_HALT(p
);
186 brw_inst_set_uip(p
->devinfo
, last_halt
, 1 * scale
);
187 brw_inst_set_jip(p
->devinfo
, last_halt
, 1 * scale
);
191 foreach_in_list(ip_record
, patch_ip
, &discard_halt_patches
) {
192 brw_inst
*patch
= &p
->store
[patch_ip
->ip
];
194 assert(brw_inst_opcode(p
->devinfo
, patch
) == BRW_OPCODE_HALT
);
195 /* HALT takes a half-instruction distance from the pre-incremented IP. */
196 brw_inst_set_uip(p
->devinfo
, patch
, (ip
- patch_ip
->ip
) * scale
);
199 this->discard_halt_patches
.make_empty();
204 fs_generator::fire_fb_write(fs_inst
*inst
,
205 struct brw_reg payload
,
206 struct brw_reg implied_header
,
209 uint32_t msg_control
;
211 brw_wm_prog_data
*prog_data
= (brw_wm_prog_data
*) this->prog_data
;
213 if (devinfo
->gen
< 6) {
214 brw_push_insn_state(p
);
215 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
216 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
217 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
218 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
219 brw_MOV(p
, offset(payload
, 1), brw_vec8_grf(1, 0));
220 brw_pop_insn_state(p
);
223 if (inst
->opcode
== FS_OPCODE_REP_FB_WRITE
)
224 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED
;
225 else if (prog_data
->dual_src_blend
) {
226 if (!inst
->force_sechalf
)
227 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01
;
229 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23
;
230 } else if (inst
->exec_size
== 16)
231 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
;
233 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01
;
235 uint32_t surf_index
=
236 prog_data
->binding_table
.render_target_start
+ inst
->target
;
238 bool last_render_target
= inst
->eot
||
239 (prog_data
->dual_src_blend
&& dispatch_width
== 16);
252 inst
->header_size
!= 0);
254 brw_mark_surface_used(&prog_data
->base
, surf_index
);
258 fs_generator::generate_fb_write(fs_inst
*inst
, struct brw_reg payload
)
260 brw_wm_prog_data
*prog_data
= (brw_wm_prog_data
*) this->prog_data
;
261 const brw_wm_prog_key
* const key
= (brw_wm_prog_key
* const) this->key
;
262 struct brw_reg implied_header
;
264 if (devinfo
->gen
< 8 && !devinfo
->is_haswell
) {
265 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
268 if (inst
->base_mrf
>= 0)
269 payload
= brw_message_reg(inst
->base_mrf
);
271 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
274 if (inst
->header_size
!= 0) {
275 brw_push_insn_state(p
);
276 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
277 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
278 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
279 brw_set_default_flag_reg(p
, 0, 0);
281 /* On HSW, the GPU will use the predicate on SENDC, unless the header is
284 if (prog_data
->uses_kill
) {
285 struct brw_reg pixel_mask
;
287 if (devinfo
->gen
>= 6)
288 pixel_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
290 pixel_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
292 brw_MOV(p
, pixel_mask
, brw_flag_reg(0, 1));
295 if (devinfo
->gen
>= 6) {
296 brw_push_insn_state(p
);
297 brw_set_default_exec_size(p
, BRW_EXECUTE_16
);
298 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
300 retype(payload
, BRW_REGISTER_TYPE_UD
),
301 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
302 brw_pop_insn_state(p
);
304 if (inst
->target
> 0 && key
->replicate_alpha
) {
305 /* Set "Source0 Alpha Present to RenderTarget" bit in message
309 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
310 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
311 brw_imm_ud(0x1 << 11));
314 if (inst
->target
> 0) {
315 /* Set the render target index for choosing BLEND_STATE. */
316 brw_MOV(p
, retype(vec1(suboffset(payload
, 2)),
317 BRW_REGISTER_TYPE_UD
),
318 brw_imm_ud(inst
->target
));
321 implied_header
= brw_null_reg();
323 implied_header
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
326 brw_pop_insn_state(p
);
328 implied_header
= brw_null_reg();
331 if (!runtime_check_aads_emit
) {
332 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
334 /* This can only happen in gen < 6 */
335 assert(devinfo
->gen
< 6);
337 struct brw_reg v1_null_ud
= vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD
));
339 /* Check runtime bit to detect if we have to send AA data or not */
340 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
343 retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD
),
345 brw_inst_set_cond_modifier(p
->devinfo
, brw_last_inst
, BRW_CONDITIONAL_NZ
);
347 int jmp
= brw_JMPI(p
, brw_imm_ud(0), BRW_PREDICATE_NORMAL
) - p
->store
;
348 brw_inst_set_exec_size(p
->devinfo
, brw_last_inst
, BRW_EXECUTE_1
);
350 /* Don't send AA data */
351 fire_fb_write(inst
, offset(payload
, 1), implied_header
, inst
->mlen
-1);
353 brw_land_fwd_jump(p
, jmp
);
354 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
359 fs_generator::generate_urb_write(fs_inst
*inst
, struct brw_reg payload
)
363 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
365 brw_set_dest(p
, insn
, brw_null_reg());
366 brw_set_src0(p
, insn
, payload
);
367 brw_set_src1(p
, insn
, brw_imm_d(0));
369 brw_inst_set_sfid(p
->devinfo
, insn
, BRW_SFID_URB
);
370 brw_inst_set_urb_opcode(p
->devinfo
, insn
, GEN8_URB_OPCODE_SIMD8_WRITE
);
372 brw_inst_set_mlen(p
->devinfo
, insn
, inst
->mlen
);
373 brw_inst_set_rlen(p
->devinfo
, insn
, 0);
374 brw_inst_set_eot(p
->devinfo
, insn
, inst
->eot
);
375 brw_inst_set_header_present(p
->devinfo
, insn
, true);
376 brw_inst_set_urb_global_offset(p
->devinfo
, insn
, inst
->offset
);
380 fs_generator::generate_cs_terminate(fs_inst
*inst
, struct brw_reg payload
)
382 struct brw_inst
*insn
;
384 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
386 brw_set_dest(p
, insn
, brw_null_reg());
387 brw_set_src0(p
, insn
, payload
);
388 brw_set_src1(p
, insn
, brw_imm_d(0));
390 /* Terminate a compute shader by sending a message to the thread spawner.
392 brw_inst_set_sfid(devinfo
, insn
, BRW_SFID_THREAD_SPAWNER
);
393 brw_inst_set_mlen(devinfo
, insn
, 1);
394 brw_inst_set_rlen(devinfo
, insn
, 0);
395 brw_inst_set_eot(devinfo
, insn
, inst
->eot
);
396 brw_inst_set_header_present(devinfo
, insn
, false);
398 brw_inst_set_ts_opcode(devinfo
, insn
, 0); /* Dereference resource */
399 brw_inst_set_ts_request_type(devinfo
, insn
, 0); /* Root thread */
401 /* Note that even though the thread has a URB resource associated with it,
402 * we set the "do not dereference URB" bit, because the URB resource is
403 * managed by the fixed-function unit, so it will free it automatically.
405 brw_inst_set_ts_resource_select(devinfo
, insn
, 1); /* Do not dereference URB */
407 brw_inst_set_mask_control(devinfo
, insn
, BRW_MASK_DISABLE
);
411 fs_generator::generate_barrier(fs_inst
*inst
, struct brw_reg src
)
418 fs_generator::generate_blorp_fb_write(fs_inst
*inst
)
421 16 /* dispatch_width */,
422 brw_message_reg(inst
->base_mrf
),
423 brw_reg_from_fs_reg(inst
, &inst
->src
[0]),
424 BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
,
430 inst
->header_size
!= 0);
434 fs_generator::generate_linterp(fs_inst
*inst
,
435 struct brw_reg dst
, struct brw_reg
*src
)
439 * -----------------------------------
440 * | src1+0 | src1+1 | src1+2 | src1+3 |
441 * |-----------------------------------|
442 * |(x0, x1)|(y0, y1)|(x2, x3)|(y2, y3)|
443 * -----------------------------------
445 * but for the LINE/MAC pair, the LINE reads Xs and the MAC reads Ys:
447 * -----------------------------------
448 * | src1+0 | src1+1 | src1+2 | src1+3 |
449 * |-----------------------------------|
450 * |(x0, x1)|(y0, y1)| | | in SIMD8
451 * |-----------------------------------|
452 * |(x0, x1)|(x2, x3)|(y0, y1)|(y2, y3)| in SIMD16
453 * -----------------------------------
455 * See also: emit_interpolation_setup_gen4().
457 struct brw_reg delta_x
= src
[0];
458 struct brw_reg delta_y
= offset(src
[0], dispatch_width
/ 8);
459 struct brw_reg interp
= src
[1];
461 if (devinfo
->has_pln
&&
462 (devinfo
->gen
>= 7 || (delta_x
.nr
& 1) == 0)) {
463 brw_PLN(p
, dst
, interp
, delta_x
);
465 brw_LINE(p
, brw_null_reg(), interp
, delta_x
);
466 brw_MAC(p
, dst
, suboffset(interp
, 1), delta_y
);
471 fs_generator::generate_math_gen6(fs_inst
*inst
,
476 int op
= brw_math_function(inst
->opcode
);
477 bool binop
= src1
.file
!= BRW_ARCHITECTURE_REGISTER_FILE
;
479 if (dispatch_width
== 8) {
480 gen6_math(p
, dst
, op
, src0
, src1
);
481 } else if (dispatch_width
== 16) {
482 brw_push_insn_state(p
);
483 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
484 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
485 gen6_math(p
, firsthalf(dst
), op
, firsthalf(src0
), firsthalf(src1
));
486 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
487 gen6_math(p
, sechalf(dst
), op
, sechalf(src0
),
488 binop
? sechalf(src1
) : brw_null_reg());
489 brw_pop_insn_state(p
);
494 fs_generator::generate_math_gen4(fs_inst
*inst
,
498 int op
= brw_math_function(inst
->opcode
);
500 assert(inst
->mlen
>= 1);
502 if (dispatch_width
== 8) {
506 BRW_MATH_PRECISION_FULL
);
507 } else if (dispatch_width
== 16) {
508 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
509 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
510 gen4_math(p
, firsthalf(dst
),
512 inst
->base_mrf
, firsthalf(src
),
513 BRW_MATH_PRECISION_FULL
);
514 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
515 gen4_math(p
, sechalf(dst
),
517 inst
->base_mrf
+ 1, sechalf(src
),
518 BRW_MATH_PRECISION_FULL
);
520 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
525 fs_generator::generate_math_g45(fs_inst
*inst
,
529 if (inst
->opcode
== SHADER_OPCODE_POW
||
530 inst
->opcode
== SHADER_OPCODE_INT_QUOTIENT
||
531 inst
->opcode
== SHADER_OPCODE_INT_REMAINDER
) {
532 generate_math_gen4(inst
, dst
, src
);
536 int op
= brw_math_function(inst
->opcode
);
538 assert(inst
->mlen
>= 1);
543 BRW_MATH_PRECISION_FULL
);
547 fs_generator::generate_tex(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
,
548 struct brw_reg sampler_index
)
553 uint32_t return_format
;
554 bool is_combined_send
= inst
->eot
;
557 case BRW_REGISTER_TYPE_D
:
558 return_format
= BRW_SAMPLER_RETURN_FORMAT_SINT32
;
560 case BRW_REGISTER_TYPE_UD
:
561 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
564 return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
568 switch (inst
->exec_size
) {
570 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
573 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
576 unreachable("Invalid width for texture instruction");
579 if (devinfo
->gen
>= 5) {
580 switch (inst
->opcode
) {
581 case SHADER_OPCODE_TEX
:
582 if (inst
->shadow_compare
) {
583 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE
;
585 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE
;
589 if (inst
->shadow_compare
) {
590 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE
;
592 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS
;
595 case SHADER_OPCODE_TXL
:
596 if (inst
->shadow_compare
) {
597 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE
;
599 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD
;
602 case SHADER_OPCODE_TXS
:
603 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
;
605 case SHADER_OPCODE_TXD
:
606 if (inst
->shadow_compare
) {
607 /* Gen7.5+. Otherwise, lowered by brw_lower_texture_gradients(). */
608 assert(devinfo
->gen
>= 8 || devinfo
->is_haswell
);
609 msg_type
= HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE
;
611 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS
;
614 case SHADER_OPCODE_TXF
:
615 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
617 case SHADER_OPCODE_TXF_CMS
:
618 if (devinfo
->gen
>= 7)
619 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS
;
621 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
623 case SHADER_OPCODE_TXF_UMS
:
624 assert(devinfo
->gen
>= 7);
625 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS
;
627 case SHADER_OPCODE_TXF_MCS
:
628 assert(devinfo
->gen
>= 7);
629 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS
;
631 case SHADER_OPCODE_LOD
:
632 msg_type
= GEN5_SAMPLER_MESSAGE_LOD
;
634 case SHADER_OPCODE_TG4
:
635 if (inst
->shadow_compare
) {
636 assert(devinfo
->gen
>= 7);
637 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C
;
639 assert(devinfo
->gen
>= 6);
640 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4
;
643 case SHADER_OPCODE_TG4_OFFSET
:
644 assert(devinfo
->gen
>= 7);
645 if (inst
->shadow_compare
) {
646 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C
;
648 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO
;
651 case SHADER_OPCODE_SAMPLEINFO
:
652 msg_type
= GEN6_SAMPLER_MESSAGE_SAMPLE_SAMPLEINFO
;
655 unreachable("not reached");
658 switch (inst
->opcode
) {
659 case SHADER_OPCODE_TEX
:
660 /* Note that G45 and older determines shadow compare and dispatch width
661 * from message length for most messages.
663 if (inst
->exec_size
== 8) {
664 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE
;
665 if (inst
->shadow_compare
) {
666 assert(inst
->mlen
== 6);
668 assert(inst
->mlen
<= 4);
671 if (inst
->shadow_compare
) {
672 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE
;
673 assert(inst
->mlen
== 9);
675 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE
;
676 assert(inst
->mlen
<= 7 && inst
->mlen
% 2 == 1);
681 if (inst
->shadow_compare
) {
682 assert(inst
->exec_size
== 8);
683 assert(inst
->mlen
== 6);
684 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE
;
686 assert(inst
->mlen
== 9);
687 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS
;
688 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
691 case SHADER_OPCODE_TXL
:
692 if (inst
->shadow_compare
) {
693 assert(inst
->exec_size
== 8);
694 assert(inst
->mlen
== 6);
695 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE
;
697 assert(inst
->mlen
== 9);
698 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD
;
699 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
702 case SHADER_OPCODE_TXD
:
703 /* There is no sample_d_c message; comparisons are done manually */
704 assert(inst
->exec_size
== 8);
705 assert(inst
->mlen
== 7 || inst
->mlen
== 10);
706 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS
;
708 case SHADER_OPCODE_TXF
:
709 assert(inst
->mlen
<= 9 && inst
->mlen
% 2 == 1);
710 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
711 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
713 case SHADER_OPCODE_TXS
:
714 assert(inst
->mlen
== 3);
715 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_RESINFO
;
716 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
719 unreachable("not reached");
722 assert(msg_type
!= -1);
724 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
729 if (is_combined_send
) {
730 assert(devinfo
->gen
>= 9 || devinfo
->is_cherryview
);
734 assert(devinfo
->gen
< 7 || inst
->header_size
== 0 ||
735 src
.file
== BRW_GENERAL_REGISTER_FILE
);
737 assert(sampler_index
.type
== BRW_REGISTER_TYPE_UD
);
739 /* Load the message header if present. If there's a texture offset,
740 * we need to set it up explicitly and load the offset bitfield.
741 * Otherwise, we can use an implied move from g0 to the first message reg.
743 if (inst
->header_size
!= 0) {
744 if (devinfo
->gen
< 6 && !inst
->offset
) {
745 /* Set up an implied move from g0 to the MRF. */
746 src
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
748 struct brw_reg header_reg
;
750 if (devinfo
->gen
>= 7) {
753 assert(inst
->base_mrf
!= -1);
754 header_reg
= brw_message_reg(inst
->base_mrf
);
757 brw_push_insn_state(p
);
758 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
759 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
760 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
761 /* Explicitly set up the message header by copying g0 to the MRF. */
762 brw_MOV(p
, header_reg
, brw_vec8_grf(0, 0));
765 /* Set the offset bits in DWord 2. */
766 brw_MOV(p
, get_element_ud(header_reg
, 2),
767 brw_imm_ud(inst
->offset
));
770 brw_adjust_sampler_state_pointer(p
, header_reg
, sampler_index
);
771 brw_pop_insn_state(p
);
775 uint32_t base_binding_table_index
= (inst
->opcode
== SHADER_OPCODE_TG4
||
776 inst
->opcode
== SHADER_OPCODE_TG4_OFFSET
)
777 ? prog_data
->binding_table
.gather_texture_start
778 : prog_data
->binding_table
.texture_start
;
780 if (sampler_index
.file
== BRW_IMMEDIATE_VALUE
) {
781 uint32_t sampler
= sampler_index
.dw1
.ud
;
784 retype(dst
, BRW_REGISTER_TYPE_UW
),
787 sampler
+ base_binding_table_index
,
792 inst
->header_size
!= 0,
796 brw_mark_surface_used(prog_data
, sampler
+ base_binding_table_index
);
798 /* Non-const sampler index */
800 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
801 struct brw_reg sampler_reg
= vec1(retype(sampler_index
, BRW_REGISTER_TYPE_UD
));
803 brw_push_insn_state(p
);
804 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
805 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
807 /* addr = ((sampler * 0x101) + base_binding_table_index) & 0xfff */
808 brw_MUL(p
, addr
, sampler_reg
, brw_imm_uw(0x101));
809 if (base_binding_table_index
)
810 brw_ADD(p
, addr
, addr
, brw_imm_ud(base_binding_table_index
));
811 brw_AND(p
, addr
, addr
, brw_imm_ud(0xfff));
813 brw_pop_insn_state(p
);
815 /* dst = send(offset, a0.0 | <descriptor>) */
816 brw_inst
*insn
= brw_send_indirect_message(
817 p
, BRW_SFID_SAMPLER
, dst
, src
, addr
);
818 brw_set_sampler_message(p
, insn
,
823 inst
->mlen
/* mlen */,
824 inst
->header_size
!= 0 /* header */,
828 /* visitor knows more than we do about the surface limit required,
829 * so has already done marking.
833 if (is_combined_send
) {
834 brw_inst_set_eot(p
->devinfo
, brw_last_inst
, true);
835 brw_inst_set_opcode(p
->devinfo
, brw_last_inst
, BRW_OPCODE_SENDC
);
840 /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
843 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
845 * Ideally, we want to produce:
848 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
849 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
850 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
851 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
852 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
853 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
854 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
855 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
857 * and add another set of two more subspans if in 16-pixel dispatch mode.
859 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
860 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
861 * pair. But the ideal approximation may impose a huge performance cost on
862 * sample_d. On at least Haswell, sample_d instruction does some
863 * optimizations if the same LOD is used for all pixels in the subspan.
865 * For DDY, we need to use ALIGN16 mode since it's capable of doing the
866 * appropriate swizzling.
869 fs_generator::generate_ddx(enum opcode opcode
,
870 struct brw_reg dst
, struct brw_reg src
)
872 unsigned vstride
, width
;
874 if (opcode
== FS_OPCODE_DDX_FINE
) {
875 /* produce accurate derivatives */
876 vstride
= BRW_VERTICAL_STRIDE_2
;
879 /* replicate the derivative at the top-left pixel to other pixels */
880 vstride
= BRW_VERTICAL_STRIDE_4
;
884 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 1,
889 BRW_HORIZONTAL_STRIDE_0
,
890 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
891 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
896 BRW_HORIZONTAL_STRIDE_0
,
897 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
898 brw_ADD(p
, dst
, src0
, negate(src1
));
901 /* The negate_value boolean is used to negate the derivative computation for
902 * FBOs, since they place the origin at the upper left instead of the lower
906 fs_generator::generate_ddy(enum opcode opcode
,
907 struct brw_reg dst
, struct brw_reg src
,
910 if (opcode
== FS_OPCODE_DDY_FINE
) {
911 /* From the Ivy Bridge PRM, volume 4 part 3, section 3.3.9 (Register
912 * Region Restrictions):
914 * In Align16 access mode, SIMD16 is not allowed for DW operations
915 * and SIMD8 is not allowed for DF operations.
917 * In this context, "DW operations" means "operations acting on 32-bit
918 * values", so it includes operations on floats.
920 * Gen4 has a similar restriction. From the i965 PRM, section 11.5.3
921 * (Instruction Compression -> Rules and Restrictions):
923 * A compressed instruction must be in Align1 access mode. Align16
924 * mode instructions cannot be compressed.
926 * Similar text exists in the g45 PRM.
928 * On these platforms, if we're building a SIMD16 shader, we need to
929 * manually unroll to a pair of SIMD8 instructions.
931 bool unroll_to_simd8
=
932 (dispatch_width
== 16 &&
933 (devinfo
->gen
== 4 || (devinfo
->gen
== 7 && !devinfo
->is_haswell
)));
935 /* produce accurate derivatives */
936 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
939 BRW_VERTICAL_STRIDE_4
,
941 BRW_HORIZONTAL_STRIDE_1
,
942 BRW_SWIZZLE_XYXY
, WRITEMASK_XYZW
);
943 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
946 BRW_VERTICAL_STRIDE_4
,
948 BRW_HORIZONTAL_STRIDE_1
,
949 BRW_SWIZZLE_ZWZW
, WRITEMASK_XYZW
);
950 brw_push_insn_state(p
);
951 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
952 if (unroll_to_simd8
) {
953 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
954 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
956 brw_ADD(p
, firsthalf(dst
), firsthalf(src1
), negate(firsthalf(src0
)));
957 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
958 brw_ADD(p
, sechalf(dst
), sechalf(src1
), negate(sechalf(src0
)));
960 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), negate(firsthalf(src1
)));
961 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
962 brw_ADD(p
, sechalf(dst
), sechalf(src0
), negate(sechalf(src1
)));
966 brw_ADD(p
, dst
, src1
, negate(src0
));
968 brw_ADD(p
, dst
, src0
, negate(src1
));
970 brw_pop_insn_state(p
);
972 /* replicate the derivative at the top-left pixel to other pixels */
973 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
976 BRW_VERTICAL_STRIDE_4
,
978 BRW_HORIZONTAL_STRIDE_0
,
979 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
980 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 2,
983 BRW_VERTICAL_STRIDE_4
,
985 BRW_HORIZONTAL_STRIDE_0
,
986 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
988 brw_ADD(p
, dst
, src1
, negate(src0
));
990 brw_ADD(p
, dst
, src0
, negate(src1
));
995 fs_generator::generate_discard_jump(fs_inst
*inst
)
997 assert(devinfo
->gen
>= 6);
999 /* This HALT will be patched up at FB write time to point UIP at the end of
1000 * the program, and at brw_uip_jip() JIP will be set to the end of the
1001 * current block (or the program).
1003 this->discard_halt_patches
.push_tail(new(mem_ctx
) ip_record(p
->nr_insn
));
1005 brw_push_insn_state(p
);
1006 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1008 brw_pop_insn_state(p
);
1012 fs_generator::generate_scratch_write(fs_inst
*inst
, struct brw_reg src
)
1014 assert(inst
->mlen
!= 0);
1017 brw_uvec_mrf(inst
->exec_size
, (inst
->base_mrf
+ 1), 0),
1018 retype(src
, BRW_REGISTER_TYPE_UD
));
1019 brw_oword_block_write_scratch(p
, brw_message_reg(inst
->base_mrf
),
1020 inst
->exec_size
/ 8, inst
->offset
);
1024 fs_generator::generate_scratch_read(fs_inst
*inst
, struct brw_reg dst
)
1026 assert(inst
->mlen
!= 0);
1028 brw_oword_block_read_scratch(p
, dst
, brw_message_reg(inst
->base_mrf
),
1029 inst
->exec_size
/ 8, inst
->offset
);
1033 fs_generator::generate_scratch_read_gen7(fs_inst
*inst
, struct brw_reg dst
)
1035 gen7_block_read_scratch(p
, dst
, inst
->exec_size
/ 8, inst
->offset
);
1039 fs_generator::generate_uniform_pull_constant_load(fs_inst
*inst
,
1041 struct brw_reg index
,
1042 struct brw_reg offset
)
1044 assert(inst
->mlen
!= 0);
1046 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1047 index
.type
== BRW_REGISTER_TYPE_UD
);
1048 uint32_t surf_index
= index
.dw1
.ud
;
1050 assert(offset
.file
== BRW_IMMEDIATE_VALUE
&&
1051 offset
.type
== BRW_REGISTER_TYPE_UD
);
1052 uint32_t read_offset
= offset
.dw1
.ud
;
1054 brw_oword_block_read(p
, dst
, brw_message_reg(inst
->base_mrf
),
1055 read_offset
, surf_index
);
1057 brw_mark_surface_used(prog_data
, surf_index
);
1061 fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst
*inst
,
1063 struct brw_reg index
,
1064 struct brw_reg offset
)
1066 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1068 assert(offset
.file
== BRW_GENERAL_REGISTER_FILE
);
1069 /* Reference just the dword we need, to avoid angering validate_reg(). */
1070 offset
= brw_vec1_grf(offset
.nr
, 0);
1072 /* We use the SIMD4x2 mode because we want to end up with 4 components in
1073 * the destination loaded consecutively from the same offset (which appears
1074 * in the first component, and the rest are ignored).
1076 dst
.width
= BRW_WIDTH_4
;
1078 struct brw_reg src
= offset
;
1079 bool header_present
= false;
1081 if (devinfo
->gen
>= 9) {
1082 /* Skylake requires a message header in order to use SIMD4x2 mode. */
1083 src
= retype(brw_vec4_grf(offset
.nr
, 0), BRW_REGISTER_TYPE_UD
);
1084 header_present
= true;
1086 brw_push_insn_state(p
);
1087 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1088 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1089 brw_MOV(p
, vec8(src
), retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
1090 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1092 brw_MOV(p
, get_element_ud(src
, 2),
1093 brw_imm_ud(GEN9_SAMPLER_SIMD_MODE_EXTENSION_SIMD4X2
));
1094 brw_pop_insn_state(p
);
1097 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1099 uint32_t surf_index
= index
.dw1
.ud
;
1101 brw_push_insn_state(p
);
1102 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1103 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1104 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1105 brw_pop_insn_state(p
);
1107 brw_set_dest(p
, send
, dst
);
1108 brw_set_src0(p
, send
, src
);
1109 brw_set_sampler_message(p
, send
,
1111 0, /* LD message ignores sampler unit */
1112 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1116 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
1119 brw_mark_surface_used(prog_data
, surf_index
);
1123 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1125 brw_push_insn_state(p
);
1126 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1127 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1129 /* a0.0 = surf_index & 0xff */
1130 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1131 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1132 brw_set_dest(p
, insn_and
, addr
);
1133 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1134 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1136 /* dst = send(payload, a0.0 | <descriptor>) */
1137 brw_inst
*insn
= brw_send_indirect_message(
1138 p
, BRW_SFID_SAMPLER
, dst
, src
, addr
);
1139 brw_set_sampler_message(p
, insn
,
1141 0, /* LD message ignores sampler unit */
1142 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1146 BRW_SAMPLER_SIMD_MODE_SIMD4X2
,
1149 brw_pop_insn_state(p
);
1151 /* visitor knows more than we do about the surface limit required,
1152 * so has already done marking.
1159 fs_generator::generate_varying_pull_constant_load(fs_inst
*inst
,
1161 struct brw_reg index
,
1162 struct brw_reg offset
)
1164 assert(devinfo
->gen
< 7); /* Should use the gen7 variant. */
1165 assert(inst
->header_size
!= 0);
1168 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1169 index
.type
== BRW_REGISTER_TYPE_UD
);
1170 uint32_t surf_index
= index
.dw1
.ud
;
1172 uint32_t simd_mode
, rlen
, msg_type
;
1173 if (dispatch_width
== 16) {
1174 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1177 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1181 if (devinfo
->gen
>= 5)
1182 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
1184 /* We always use the SIMD16 message so that we only have to load U, and
1187 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
1188 assert(inst
->mlen
== 3);
1189 assert(inst
->regs_written
== 8);
1191 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1194 struct brw_reg offset_mrf
= retype(brw_message_reg(inst
->base_mrf
+ 1),
1195 BRW_REGISTER_TYPE_D
);
1196 brw_MOV(p
, offset_mrf
, offset
);
1198 struct brw_reg header
= brw_vec8_grf(0, 0);
1199 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
1201 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1202 brw_inst_set_qtr_control(p
->devinfo
, send
, BRW_COMPRESSION_NONE
);
1203 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1204 brw_set_src0(p
, send
, header
);
1205 if (devinfo
->gen
< 6)
1206 brw_inst_set_base_mrf(p
->devinfo
, send
, inst
->base_mrf
);
1208 /* Our surface is set up as floats, regardless of what actual data is
1211 uint32_t return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
1212 brw_set_sampler_message(p
, send
,
1214 0, /* sampler (unused) */
1218 inst
->header_size
!= 0,
1222 brw_mark_surface_used(prog_data
, surf_index
);
1226 fs_generator::generate_varying_pull_constant_load_gen7(fs_inst
*inst
,
1228 struct brw_reg index
,
1229 struct brw_reg offset
)
1231 assert(devinfo
->gen
>= 7);
1232 /* Varying-offset pull constant loads are treated as a normal expression on
1233 * gen7, so the fact that it's a send message is hidden at the IR level.
1235 assert(inst
->header_size
== 0);
1236 assert(!inst
->mlen
);
1237 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1239 uint32_t simd_mode
, rlen
, mlen
;
1240 if (dispatch_width
== 16) {
1243 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1247 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1250 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1252 uint32_t surf_index
= index
.dw1
.ud
;
1254 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1255 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1256 brw_set_src0(p
, send
, offset
);
1257 brw_set_sampler_message(p
, send
,
1259 0, /* LD message ignores sampler unit */
1260 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1263 false, /* no header */
1267 brw_mark_surface_used(prog_data
, surf_index
);
1271 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1273 brw_push_insn_state(p
);
1274 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1275 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1277 /* a0.0 = surf_index & 0xff */
1278 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1279 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1280 brw_set_dest(p
, insn_and
, addr
);
1281 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1282 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1284 brw_pop_insn_state(p
);
1286 /* dst = send(offset, a0.0 | <descriptor>) */
1287 brw_inst
*insn
= brw_send_indirect_message(
1288 p
, BRW_SFID_SAMPLER
, retype(dst
, BRW_REGISTER_TYPE_UW
),
1290 brw_set_sampler_message(p
, insn
,
1293 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1300 /* visitor knows more than we do about the surface limit required,
1301 * so has already done marking.
1307 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
1308 * into the flags register (f0.0).
1310 * Used only on Gen6 and above.
1313 fs_generator::generate_mov_dispatch_to_flags(fs_inst
*inst
)
1315 struct brw_reg flags
= brw_flag_reg(0, inst
->flag_subreg
);
1316 struct brw_reg dispatch_mask
;
1318 if (devinfo
->gen
>= 6)
1319 dispatch_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
1321 dispatch_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
1323 brw_push_insn_state(p
);
1324 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1325 brw_MOV(p
, flags
, dispatch_mask
);
1326 brw_pop_insn_state(p
);
1330 fs_generator::generate_pixel_interpolator_query(fs_inst
*inst
,
1333 struct brw_reg msg_data
,
1336 assert(msg_data
.file
== BRW_IMMEDIATE_VALUE
&&
1337 msg_data
.type
== BRW_REGISTER_TYPE_UD
);
1339 brw_pixel_interpolator_query(p
,
1340 retype(dst
, BRW_REGISTER_TYPE_UW
),
1342 inst
->pi_noperspective
,
1346 inst
->regs_written
);
1351 * Sets the first word of a vgrf for gen7+ simd4x2 uniform pull constant
1352 * sampler LD messages.
1354 * We don't want to bake it into the send message's code generation because
1355 * that means we don't get a chance to schedule the instructions.
1358 fs_generator::generate_set_simd4x2_offset(fs_inst
*inst
,
1360 struct brw_reg value
)
1362 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1364 brw_push_insn_state(p
);
1365 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1366 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1367 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1368 brw_MOV(p
, retype(brw_vec1_reg(dst
.file
, dst
.nr
, 0), value
.type
), value
);
1369 brw_pop_insn_state(p
);
1372 /* Sets vstride=1, width=4, hstride=0 of register src1 during
1373 * the ADD instruction.
1376 fs_generator::generate_set_sample_id(fs_inst
*inst
,
1378 struct brw_reg src0
,
1379 struct brw_reg src1
)
1381 assert(dst
.type
== BRW_REGISTER_TYPE_D
||
1382 dst
.type
== BRW_REGISTER_TYPE_UD
);
1383 assert(src0
.type
== BRW_REGISTER_TYPE_D
||
1384 src0
.type
== BRW_REGISTER_TYPE_UD
);
1386 brw_push_insn_state(p
);
1387 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1388 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1389 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1390 struct brw_reg reg
= retype(stride(src1
, 1, 4, 0), BRW_REGISTER_TYPE_UW
);
1391 if (dispatch_width
== 8) {
1392 brw_ADD(p
, dst
, src0
, reg
);
1393 } else if (dispatch_width
== 16) {
1394 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), reg
);
1395 brw_ADD(p
, sechalf(dst
), sechalf(src0
), suboffset(reg
, 2));
1397 brw_pop_insn_state(p
);
1401 fs_generator::generate_pack_half_2x16_split(fs_inst
*inst
,
1406 assert(devinfo
->gen
>= 7);
1407 assert(dst
.type
== BRW_REGISTER_TYPE_UD
);
1408 assert(x
.type
== BRW_REGISTER_TYPE_F
);
1409 assert(y
.type
== BRW_REGISTER_TYPE_F
);
1411 /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16:
1413 * Because this instruction does not have a 16-bit floating-point type,
1414 * the destination data type must be Word (W).
1416 * The destination must be DWord-aligned and specify a horizontal stride
1417 * (HorzStride) of 2. The 16-bit result is stored in the lower word of
1418 * each destination channel and the upper word is not modified.
1420 struct brw_reg dst_w
= spread(retype(dst
, BRW_REGISTER_TYPE_W
), 2);
1422 /* Give each 32-bit channel of dst the form below, where "." means
1426 brw_F32TO16(p
, dst_w
, y
);
1431 brw_SHL(p
, dst
, dst
, brw_imm_ud(16u));
1433 /* And, finally the form of packHalf2x16's output:
1436 brw_F32TO16(p
, dst_w
, x
);
1440 fs_generator::generate_unpack_half_2x16_split(fs_inst
*inst
,
1444 assert(devinfo
->gen
>= 7);
1445 assert(dst
.type
== BRW_REGISTER_TYPE_F
);
1446 assert(src
.type
== BRW_REGISTER_TYPE_UD
);
1448 /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32:
1450 * Because this instruction does not have a 16-bit floating-point type,
1451 * the source data type must be Word (W). The destination type must be
1454 struct brw_reg src_w
= spread(retype(src
, BRW_REGISTER_TYPE_W
), 2);
1456 /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
1457 * For the Y case, we wish to access only the upper word; therefore
1458 * a 16-bit subregister offset is needed.
1460 assert(inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
||
1461 inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
);
1462 if (inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
)
1465 brw_F16TO32(p
, dst
, src_w
);
1469 fs_generator::generate_shader_time_add(fs_inst
*inst
,
1470 struct brw_reg payload
,
1471 struct brw_reg offset
,
1472 struct brw_reg value
)
1474 assert(devinfo
->gen
>= 7);
1475 brw_push_insn_state(p
);
1476 brw_set_default_mask_control(p
, true);
1478 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1479 struct brw_reg payload_offset
= retype(brw_vec1_grf(payload
.nr
, 0),
1481 struct brw_reg payload_value
= retype(brw_vec1_grf(payload
.nr
+ 1, 0),
1484 assert(offset
.file
== BRW_IMMEDIATE_VALUE
);
1485 if (value
.file
== BRW_GENERAL_REGISTER_FILE
) {
1486 value
.width
= BRW_WIDTH_1
;
1487 value
.hstride
= BRW_HORIZONTAL_STRIDE_0
;
1488 value
.vstride
= BRW_VERTICAL_STRIDE_0
;
1490 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1493 /* Trying to deal with setup of the params from the IR is crazy in the FS8
1494 * case, and we don't really care about squeezing every bit of performance
1495 * out of this path, so we just emit the MOVs from here.
1497 brw_MOV(p
, payload_offset
, offset
);
1498 brw_MOV(p
, payload_value
, value
);
1499 brw_shader_time_add(p
, payload
,
1500 prog_data
->binding_table
.shader_time_start
);
1501 brw_pop_insn_state(p
);
1503 brw_mark_surface_used(prog_data
,
1504 prog_data
->binding_table
.shader_time_start
);
1508 fs_generator::enable_debug(const char *shader_name
)
1511 this->shader_name
= shader_name
;
1515 fs_generator::generate_code(const cfg_t
*cfg
, int dispatch_width
)
1517 /* align to 64 byte boundary. */
1518 while (p
->next_insn_offset
% 64)
1521 this->dispatch_width
= dispatch_width
;
1522 if (dispatch_width
== 16)
1523 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1525 int start_offset
= p
->next_insn_offset
;
1526 int spill_count
= 0, fill_count
= 0;
1529 struct annotation_info annotation
;
1530 memset(&annotation
, 0, sizeof(annotation
));
1532 foreach_block_and_inst (block
, fs_inst
, inst
, cfg
) {
1533 struct brw_reg src
[3], dst
;
1534 unsigned int last_insn_offset
= p
->next_insn_offset
;
1535 bool multiple_instructions_emitted
= false;
1537 if (unlikely(debug_flag
))
1538 annotate(p
->devinfo
, &annotation
, cfg
, inst
, p
->next_insn_offset
);
1540 for (unsigned int i
= 0; i
< inst
->sources
; i
++) {
1541 src
[i
] = brw_reg_from_fs_reg(inst
, &inst
->src
[i
]);
1543 /* The accumulator result appears to get used for the
1544 * conditional modifier generation. When negating a UD
1545 * value, there is a 33rd bit generated for the sign in the
1546 * accumulator value, so now you can't check, for example,
1547 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
1549 assert(!inst
->conditional_mod
||
1550 inst
->src
[i
].type
!= BRW_REGISTER_TYPE_UD
||
1551 !inst
->src
[i
].negate
);
1553 dst
= brw_reg_from_fs_reg(inst
, &inst
->dst
);
1555 brw_set_default_predicate_control(p
, inst
->predicate
);
1556 brw_set_default_predicate_inverse(p
, inst
->predicate_inverse
);
1557 brw_set_default_flag_reg(p
, 0, inst
->flag_subreg
);
1558 brw_set_default_saturate(p
, inst
->saturate
);
1559 brw_set_default_mask_control(p
, inst
->force_writemask_all
);
1560 brw_set_default_acc_write_control(p
, inst
->writes_accumulator
);
1561 brw_set_default_exec_size(p
, cvt(inst
->exec_size
) - 1);
1563 assert(inst
->base_mrf
+ inst
->mlen
<= BRW_MAX_MRF
);
1564 assert(inst
->mlen
<= BRW_MAX_MSG_LENGTH
);
1566 switch (inst
->exec_size
) {
1570 assert(inst
->force_writemask_all
);
1571 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1574 if (inst
->force_sechalf
) {
1575 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1577 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1582 /* If the instruction writes to more than one register, it needs to
1583 * be a "compressed" instruction on Gen <= 5.
1585 if (inst
->dst
.component_size(inst
->exec_size
) > REG_SIZE
)
1586 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1588 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1591 unreachable("Invalid instruction width");
1594 switch (inst
->opcode
) {
1595 case BRW_OPCODE_MOV
:
1596 brw_MOV(p
, dst
, src
[0]);
1598 case BRW_OPCODE_ADD
:
1599 brw_ADD(p
, dst
, src
[0], src
[1]);
1601 case BRW_OPCODE_MUL
:
1602 brw_MUL(p
, dst
, src
[0], src
[1]);
1604 case BRW_OPCODE_AVG
:
1605 brw_AVG(p
, dst
, src
[0], src
[1]);
1607 case BRW_OPCODE_MACH
:
1608 brw_MACH(p
, dst
, src
[0], src
[1]);
1611 case BRW_OPCODE_LINE
:
1612 brw_LINE(p
, dst
, src
[0], src
[1]);
1615 case BRW_OPCODE_MAD
:
1616 assert(devinfo
->gen
>= 6);
1617 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1618 if (dispatch_width
== 16 && !devinfo
->supports_simd16_3src
) {
1619 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1620 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1621 brw_inst
*f
= brw_MAD(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1622 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1623 brw_inst
*s
= brw_MAD(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1624 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1626 if (inst
->conditional_mod
) {
1627 brw_inst_set_cond_modifier(p
->devinfo
, f
, inst
->conditional_mod
);
1628 brw_inst_set_cond_modifier(p
->devinfo
, s
, inst
->conditional_mod
);
1629 multiple_instructions_emitted
= true;
1632 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
1634 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1637 case BRW_OPCODE_LRP
:
1638 assert(devinfo
->gen
>= 6);
1639 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1640 if (dispatch_width
== 16 && !devinfo
->supports_simd16_3src
) {
1641 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1642 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1643 brw_inst
*f
= brw_LRP(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1644 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1645 brw_inst
*s
= brw_LRP(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1646 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1648 if (inst
->conditional_mod
) {
1649 brw_inst_set_cond_modifier(p
->devinfo
, f
, inst
->conditional_mod
);
1650 brw_inst_set_cond_modifier(p
->devinfo
, s
, inst
->conditional_mod
);
1651 multiple_instructions_emitted
= true;
1654 brw_LRP(p
, dst
, src
[0], src
[1], src
[2]);
1656 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1659 case BRW_OPCODE_FRC
:
1660 brw_FRC(p
, dst
, src
[0]);
1662 case BRW_OPCODE_RNDD
:
1663 brw_RNDD(p
, dst
, src
[0]);
1665 case BRW_OPCODE_RNDE
:
1666 brw_RNDE(p
, dst
, src
[0]);
1668 case BRW_OPCODE_RNDZ
:
1669 brw_RNDZ(p
, dst
, src
[0]);
1672 case BRW_OPCODE_AND
:
1673 brw_AND(p
, dst
, src
[0], src
[1]);
1676 brw_OR(p
, dst
, src
[0], src
[1]);
1678 case BRW_OPCODE_XOR
:
1679 brw_XOR(p
, dst
, src
[0], src
[1]);
1681 case BRW_OPCODE_NOT
:
1682 brw_NOT(p
, dst
, src
[0]);
1684 case BRW_OPCODE_ASR
:
1685 brw_ASR(p
, dst
, src
[0], src
[1]);
1687 case BRW_OPCODE_SHR
:
1688 brw_SHR(p
, dst
, src
[0], src
[1]);
1690 case BRW_OPCODE_SHL
:
1691 brw_SHL(p
, dst
, src
[0], src
[1]);
1693 case BRW_OPCODE_F32TO16
:
1694 assert(devinfo
->gen
>= 7);
1695 brw_F32TO16(p
, dst
, src
[0]);
1697 case BRW_OPCODE_F16TO32
:
1698 assert(devinfo
->gen
>= 7);
1699 brw_F16TO32(p
, dst
, src
[0]);
1701 case BRW_OPCODE_CMP
:
1702 /* The Ivybridge/BayTrail WaCMPInstFlagDepClearedEarly workaround says
1703 * that when the destination is a GRF that the dependency-clear bit on
1704 * the flag register is cleared early.
1706 * Suggested workarounds are to disable coissuing CMP instructions
1707 * or to split CMP(16) instructions into two CMP(8) instructions.
1709 * We choose to split into CMP(8) instructions since disabling
1710 * coissuing would affect CMP instructions not otherwise affected by
1713 if (dispatch_width
== 16 && devinfo
->gen
== 7 && !devinfo
->is_haswell
) {
1714 if (dst
.file
== BRW_GENERAL_REGISTER_FILE
) {
1715 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1716 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1717 brw_CMP(p
, firsthalf(dst
), inst
->conditional_mod
,
1718 firsthalf(src
[0]), firsthalf(src
[1]));
1719 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1720 brw_CMP(p
, sechalf(dst
), inst
->conditional_mod
,
1721 sechalf(src
[0]), sechalf(src
[1]));
1722 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1724 multiple_instructions_emitted
= true;
1725 } else if (dst
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1726 /* For unknown reasons, the aforementioned workaround is not
1727 * sufficient. Overriding the type when the destination is the
1728 * null register is necessary but not sufficient by itself.
1730 assert(dst
.nr
== BRW_ARF_NULL
);
1731 dst
.type
= BRW_REGISTER_TYPE_D
;
1732 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1734 unreachable("not reached");
1737 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1740 case BRW_OPCODE_SEL
:
1741 brw_SEL(p
, dst
, src
[0], src
[1]);
1743 case BRW_OPCODE_BFREV
:
1744 assert(devinfo
->gen
>= 7);
1745 /* BFREV only supports UD type for src and dst. */
1746 brw_BFREV(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1747 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1749 case BRW_OPCODE_FBH
:
1750 assert(devinfo
->gen
>= 7);
1751 /* FBH only supports UD type for dst. */
1752 brw_FBH(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1754 case BRW_OPCODE_FBL
:
1755 assert(devinfo
->gen
>= 7);
1756 /* FBL only supports UD type for dst. */
1757 brw_FBL(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1759 case BRW_OPCODE_CBIT
:
1760 assert(devinfo
->gen
>= 7);
1761 /* CBIT only supports UD type for dst. */
1762 brw_CBIT(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1764 case BRW_OPCODE_ADDC
:
1765 assert(devinfo
->gen
>= 7);
1766 brw_ADDC(p
, dst
, src
[0], src
[1]);
1768 case BRW_OPCODE_SUBB
:
1769 assert(devinfo
->gen
>= 7);
1770 brw_SUBB(p
, dst
, src
[0], src
[1]);
1772 case BRW_OPCODE_MAC
:
1773 brw_MAC(p
, dst
, src
[0], src
[1]);
1776 case BRW_OPCODE_BFE
:
1777 assert(devinfo
->gen
>= 7);
1778 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1779 if (dispatch_width
== 16 && !devinfo
->supports_simd16_3src
) {
1780 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1781 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1782 brw_BFE(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1783 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1784 brw_BFE(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1785 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1787 brw_BFE(p
, dst
, src
[0], src
[1], src
[2]);
1789 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1792 case BRW_OPCODE_BFI1
:
1793 assert(devinfo
->gen
>= 7);
1794 /* The Haswell WaForceSIMD8ForBFIInstruction workaround says that we
1797 * "Force BFI instructions to be executed always in SIMD8."
1799 if (dispatch_width
== 16 && devinfo
->is_haswell
) {
1800 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1801 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1802 brw_BFI1(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]));
1803 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1804 brw_BFI1(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]));
1805 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1807 brw_BFI1(p
, dst
, src
[0], src
[1]);
1810 case BRW_OPCODE_BFI2
:
1811 assert(devinfo
->gen
>= 7);
1812 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1813 /* The Haswell WaForceSIMD8ForBFIInstruction workaround says that we
1816 * "Force BFI instructions to be executed always in SIMD8."
1818 * Otherwise we would be able to emit compressed instructions like we
1819 * do for the other three-source instructions.
1821 if (dispatch_width
== 16 &&
1822 (devinfo
->is_haswell
|| !devinfo
->supports_simd16_3src
)) {
1823 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1824 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1825 brw_BFI2(p
, firsthalf(dst
), firsthalf(src
[0]), firsthalf(src
[1]), firsthalf(src
[2]));
1826 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1827 brw_BFI2(p
, sechalf(dst
), sechalf(src
[0]), sechalf(src
[1]), sechalf(src
[2]));
1828 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
1830 brw_BFI2(p
, dst
, src
[0], src
[1], src
[2]);
1832 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1836 if (inst
->src
[0].file
!= BAD_FILE
) {
1837 /* The instruction has an embedded compare (only allowed on gen6) */
1838 assert(devinfo
->gen
== 6);
1839 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
1841 brw_IF(p
, dispatch_width
== 16 ? BRW_EXECUTE_16
: BRW_EXECUTE_8
);
1845 case BRW_OPCODE_ELSE
:
1848 case BRW_OPCODE_ENDIF
:
1853 brw_DO(p
, dispatch_width
== 16 ? BRW_EXECUTE_16
: BRW_EXECUTE_8
);
1856 case BRW_OPCODE_BREAK
:
1858 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
1860 case BRW_OPCODE_CONTINUE
:
1862 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
1865 case BRW_OPCODE_WHILE
:
1870 case SHADER_OPCODE_RCP
:
1871 case SHADER_OPCODE_RSQ
:
1872 case SHADER_OPCODE_SQRT
:
1873 case SHADER_OPCODE_EXP2
:
1874 case SHADER_OPCODE_LOG2
:
1875 case SHADER_OPCODE_SIN
:
1876 case SHADER_OPCODE_COS
:
1877 assert(devinfo
->gen
< 6 || inst
->mlen
== 0);
1878 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1879 if (devinfo
->gen
>= 7) {
1880 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0],
1882 } else if (devinfo
->gen
== 6) {
1883 generate_math_gen6(inst
, dst
, src
[0], brw_null_reg());
1884 } else if (devinfo
->gen
== 5 || devinfo
->is_g4x
) {
1885 generate_math_g45(inst
, dst
, src
[0]);
1887 generate_math_gen4(inst
, dst
, src
[0]);
1890 case SHADER_OPCODE_INT_QUOTIENT
:
1891 case SHADER_OPCODE_INT_REMAINDER
:
1892 case SHADER_OPCODE_POW
:
1893 assert(devinfo
->gen
< 6 || inst
->mlen
== 0);
1894 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1895 if (devinfo
->gen
>= 7 && inst
->opcode
== SHADER_OPCODE_POW
) {
1896 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0], src
[1]);
1897 } else if (devinfo
->gen
>= 6) {
1898 generate_math_gen6(inst
, dst
, src
[0], src
[1]);
1900 generate_math_gen4(inst
, dst
, src
[0]);
1903 case FS_OPCODE_CINTERP
:
1904 brw_MOV(p
, dst
, src
[0]);
1906 case FS_OPCODE_LINTERP
:
1907 generate_linterp(inst
, dst
, src
);
1909 case FS_OPCODE_PIXEL_X
:
1910 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1911 src
[0].subnr
= 0 * type_sz(src
[0].type
);
1912 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1914 case FS_OPCODE_PIXEL_Y
:
1915 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1916 src
[0].subnr
= 4 * type_sz(src
[0].type
);
1917 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1919 case SHADER_OPCODE_TEX
:
1921 case SHADER_OPCODE_TXD
:
1922 case SHADER_OPCODE_TXF
:
1923 case SHADER_OPCODE_TXF_CMS
:
1924 case SHADER_OPCODE_TXF_UMS
:
1925 case SHADER_OPCODE_TXF_MCS
:
1926 case SHADER_OPCODE_TXL
:
1927 case SHADER_OPCODE_TXS
:
1928 case SHADER_OPCODE_LOD
:
1929 case SHADER_OPCODE_TG4
:
1930 case SHADER_OPCODE_TG4_OFFSET
:
1931 case SHADER_OPCODE_SAMPLEINFO
:
1932 generate_tex(inst
, dst
, src
[0], src
[1]);
1934 case FS_OPCODE_DDX_COARSE
:
1935 case FS_OPCODE_DDX_FINE
:
1936 generate_ddx(inst
->opcode
, dst
, src
[0]);
1938 case FS_OPCODE_DDY_COARSE
:
1939 case FS_OPCODE_DDY_FINE
:
1940 assert(src
[1].file
== BRW_IMMEDIATE_VALUE
);
1941 generate_ddy(inst
->opcode
, dst
, src
[0], src
[1].dw1
.ud
);
1944 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
1945 generate_scratch_write(inst
, src
[0]);
1949 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
1950 generate_scratch_read(inst
, dst
);
1954 case SHADER_OPCODE_GEN7_SCRATCH_READ
:
1955 generate_scratch_read_gen7(inst
, dst
);
1959 case SHADER_OPCODE_URB_WRITE_SIMD8
:
1960 generate_urb_write(inst
, src
[0]);
1963 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
:
1964 generate_uniform_pull_constant_load(inst
, dst
, src
[0], src
[1]);
1967 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7
:
1968 generate_uniform_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
1971 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD
:
1972 generate_varying_pull_constant_load(inst
, dst
, src
[0], src
[1]);
1975 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
:
1976 generate_varying_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
1979 case FS_OPCODE_REP_FB_WRITE
:
1980 case FS_OPCODE_FB_WRITE
:
1981 generate_fb_write(inst
, src
[0]);
1984 case FS_OPCODE_BLORP_FB_WRITE
:
1985 generate_blorp_fb_write(inst
);
1988 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS
:
1989 generate_mov_dispatch_to_flags(inst
);
1992 case FS_OPCODE_DISCARD_JUMP
:
1993 generate_discard_jump(inst
);
1996 case SHADER_OPCODE_SHADER_TIME_ADD
:
1997 generate_shader_time_add(inst
, src
[0], src
[1], src
[2]);
2000 case SHADER_OPCODE_UNTYPED_ATOMIC
:
2001 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2002 brw_untyped_atomic(p
, dst
, src
[0], src
[1], src
[2].dw1
.ud
,
2003 inst
->mlen
, !inst
->dst
.is_null());
2006 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
2007 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2008 brw_untyped_surface_read(p
, dst
, src
[0], src
[1],
2009 inst
->mlen
, src
[2].dw1
.ud
);
2012 case SHADER_OPCODE_UNTYPED_SURFACE_WRITE
:
2013 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2014 brw_untyped_surface_write(p
, src
[0], src
[1],
2015 inst
->mlen
, src
[2].dw1
.ud
);
2018 case SHADER_OPCODE_TYPED_ATOMIC
:
2019 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2020 brw_typed_atomic(p
, dst
, src
[0], src
[1],
2021 src
[2].dw1
.ud
, inst
->mlen
, !inst
->dst
.is_null());
2024 case SHADER_OPCODE_TYPED_SURFACE_READ
:
2025 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2026 brw_typed_surface_read(p
, dst
, src
[0], src
[1],
2027 inst
->mlen
, src
[2].dw1
.ud
);
2030 case SHADER_OPCODE_TYPED_SURFACE_WRITE
:
2031 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2032 brw_typed_surface_write(p
, src
[0], src
[1], inst
->mlen
, src
[2].dw1
.ud
);
2035 case SHADER_OPCODE_MEMORY_FENCE
:
2036 brw_memory_fence(p
, dst
);
2039 case FS_OPCODE_SET_SIMD4X2_OFFSET
:
2040 generate_set_simd4x2_offset(inst
, dst
, src
[0]);
2043 case SHADER_OPCODE_FIND_LIVE_CHANNEL
:
2044 brw_find_live_channel(p
, dst
);
2047 case SHADER_OPCODE_BROADCAST
:
2048 brw_broadcast(p
, dst
, src
[0], src
[1]);
2051 case FS_OPCODE_SET_SAMPLE_ID
:
2052 generate_set_sample_id(inst
, dst
, src
[0], src
[1]);
2055 case FS_OPCODE_PACK_HALF_2x16_SPLIT
:
2056 generate_pack_half_2x16_split(inst
, dst
, src
[0], src
[1]);
2059 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
:
2060 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
:
2061 generate_unpack_half_2x16_split(inst
, dst
, src
[0]);
2064 case FS_OPCODE_PLACEHOLDER_HALT
:
2065 /* This is the place where the final HALT needs to be inserted if
2066 * we've emitted any discards. If not, this will emit no code.
2068 if (!patch_discard_jumps_to_fb_writes()) {
2069 if (unlikely(debug_flag
)) {
2070 annotation
.ann_count
--;
2075 case FS_OPCODE_INTERPOLATE_AT_CENTROID
:
2076 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2077 GEN7_PIXEL_INTERPOLATOR_LOC_CENTROID
);
2080 case FS_OPCODE_INTERPOLATE_AT_SAMPLE
:
2081 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2082 GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE
);
2085 case FS_OPCODE_INTERPOLATE_AT_SHARED_OFFSET
:
2086 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2087 GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET
);
2090 case FS_OPCODE_INTERPOLATE_AT_PER_SLOT_OFFSET
:
2091 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2092 GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET
);
2095 case CS_OPCODE_CS_TERMINATE
:
2096 generate_cs_terminate(inst
, src
[0]);
2099 case SHADER_OPCODE_BARRIER
:
2100 generate_barrier(inst
, src
[0]);
2104 unreachable("Unsupported opcode");
2106 case SHADER_OPCODE_LOAD_PAYLOAD
:
2107 unreachable("Should be lowered by lower_load_payload()");
2110 if (multiple_instructions_emitted
)
2113 if (inst
->no_dd_clear
|| inst
->no_dd_check
|| inst
->conditional_mod
) {
2114 assert(p
->next_insn_offset
== last_insn_offset
+ 16 ||
2115 !"conditional_mod, no_dd_check, or no_dd_clear set for IR "
2116 "emitting more than 1 instruction");
2118 brw_inst
*last
= &p
->store
[last_insn_offset
/ 16];
2120 if (inst
->conditional_mod
)
2121 brw_inst_set_cond_modifier(p
->devinfo
, last
, inst
->conditional_mod
);
2122 brw_inst_set_no_dd_clear(p
->devinfo
, last
, inst
->no_dd_clear
);
2123 brw_inst_set_no_dd_check(p
->devinfo
, last
, inst
->no_dd_check
);
2128 annotation_finalize(&annotation
, p
->next_insn_offset
);
2130 int before_size
= p
->next_insn_offset
- start_offset
;
2131 brw_compact_instructions(p
, start_offset
, annotation
.ann_count
,
2133 int after_size
= p
->next_insn_offset
- start_offset
;
2135 if (unlikely(debug_flag
)) {
2136 fprintf(stderr
, "Native code for %s\n"
2137 "SIMD%d shader: %d instructions. %d loops. %d:%d spills:fills. Promoted %u constants. Compacted %d to %d"
2138 " bytes (%.0f%%)\n",
2139 shader_name
, dispatch_width
, before_size
/ 16, loop_count
,
2140 spill_count
, fill_count
, promoted_constants
, before_size
, after_size
,
2141 100.0f
* (before_size
- after_size
) / before_size
);
2143 dump_assembly(p
->store
, annotation
.ann_count
, annotation
.ann
,
2145 ralloc_free(annotation
.ann
);
2148 compiler
->shader_debug_log(log_data
,
2149 "%s SIMD%d shader: %d inst, %d loops, "
2150 "%d:%d spills:fills, Promoted %u constants, "
2151 "compacted %d to %d bytes.\n",
2152 stage_abbrev
, dispatch_width
, before_size
/ 16,
2153 loop_count
, spill_count
, fill_count
,
2154 promoted_constants
, before_size
, after_size
);
2156 return start_offset
;
2160 fs_generator::get_assembly(unsigned int *assembly_size
)
2162 return brw_get_program(p
, assembly_size
);