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.
34 static enum brw_reg_file
35 brw_file_from_reg(fs_reg
*reg
)
39 return BRW_ARCHITECTURE_REGISTER_FILE
;
42 return BRW_GENERAL_REGISTER_FILE
;
44 return BRW_MESSAGE_REGISTER_FILE
;
46 return BRW_IMMEDIATE_VALUE
;
50 unreachable("not reached");
52 return BRW_ARCHITECTURE_REGISTER_FILE
;
56 brw_reg_from_fs_reg(const struct gen_device_info
*devinfo
, fs_inst
*inst
,
57 fs_reg
*reg
, bool compressed
)
59 struct brw_reg brw_reg
;
63 assert((reg
->nr
& ~BRW_MRF_COMPR4
) < BRW_MAX_MRF(devinfo
->gen
));
66 if (reg
->stride
== 0) {
67 brw_reg
= brw_vec1_reg(brw_file_from_reg(reg
), reg
->nr
, 0);
69 /* From the Haswell PRM:
71 * "VertStride must be used to cross GRF register boundaries. This
72 * rule implies that elements within a 'Width' cannot cross GRF
75 * The maximum width value that could satisfy this restriction is:
77 const unsigned reg_width
= REG_SIZE
/ (reg
->stride
* type_sz(reg
->type
));
79 /* Because the hardware can only split source regions at a whole
80 * multiple of width during decompression (i.e. vertically), clamp
81 * the value obtained above to the physical execution size of a
82 * single decompressed chunk of the instruction:
84 const unsigned phys_width
= compressed
? inst
->exec_size
/ 2 :
87 /* XXX - The equation above is strictly speaking not correct on
88 * hardware that supports unbalanced GRF writes -- On Gen9+
89 * each decompressed chunk of the instruction may have a
90 * different execution size when the number of components
91 * written to each destination GRF is not the same.
93 const unsigned width
= MIN2(reg_width
, phys_width
);
94 brw_reg
= brw_vecn_reg(width
, brw_file_from_reg(reg
), reg
->nr
, 0);
95 brw_reg
= stride(brw_reg
, width
* reg
->stride
, width
, reg
->stride
);
97 if (devinfo
->gen
== 7 && !devinfo
->is_haswell
) {
98 /* From the IvyBridge PRM (EU Changes by Processor Generation, page 13):
99 * "Each DF (Double Float) operand uses an element size of 4 rather
100 * than 8 and all regioning parameters are twice what the values
101 * would be based on the true element size: ExecSize, Width,
102 * HorzStride, and VertStride. Each DF operand uses a pair of
103 * channels and all masking and swizzing should be adjusted
106 * From the IvyBridge PRM (Special Requirements for Handling Double
107 * Precision Data Types, page 71):
108 * "In Align1 mode, all regioning parameters like stride, execution
109 * size, and width must use the syntax of a pair of packed
110 * floats. The offsets for these data types must be 64-bit
111 * aligned. The execution size and regioning parameters are in terms
114 * Summarized: when handling DF-typed arguments, ExecSize,
115 * VertStride, and Width must be doubled.
117 * It applies to BayTrail too.
119 if (type_sz(reg
->type
) == 8) {
121 if (brw_reg
.vstride
> 0)
123 assert(brw_reg
.hstride
== BRW_HORIZONTAL_STRIDE_1
);
126 /* When converting from DF->F, we set the destination stride to 2
127 * because each d2f conversion implicitly writes 2 floats, being
128 * the first one the converted value. IVB/BYT actually writes two
129 * F components per SIMD channel, and every other component is
130 * filled with garbage.
132 if (reg
== &inst
->dst
&& get_exec_type_size(inst
) == 8 &&
133 type_sz(inst
->dst
.type
) < 8) {
134 assert(brw_reg
.hstride
> BRW_HORIZONTAL_STRIDE_1
);
140 brw_reg
= retype(brw_reg
, reg
->type
);
141 brw_reg
= byte_offset(brw_reg
, reg
->offset
);
142 brw_reg
.abs
= reg
->abs
;
143 brw_reg
.negate
= reg
->negate
;
148 assert(reg
->offset
== 0);
149 brw_reg
= reg
->as_brw_reg();
152 /* Probably unused. */
153 brw_reg
= brw_null_reg();
157 unreachable("not reached");
160 /* On HSW+, scalar DF sources can be accessed using the normal <0,1,0>
161 * region, but on IVB and BYT DF regions must be programmed in terms of
162 * floats. A <0,2,1> region accomplishes this.
164 if (devinfo
->gen
== 7 && !devinfo
->is_haswell
&&
165 type_sz(reg
->type
) == 8 &&
166 brw_reg
.vstride
== BRW_VERTICAL_STRIDE_0
&&
167 brw_reg
.width
== BRW_WIDTH_1
&&
168 brw_reg
.hstride
== BRW_HORIZONTAL_STRIDE_0
) {
169 brw_reg
.width
= BRW_WIDTH_2
;
170 brw_reg
.hstride
= BRW_HORIZONTAL_STRIDE_1
;
176 fs_generator::fs_generator(const struct brw_compiler
*compiler
, void *log_data
,
179 struct brw_stage_prog_data
*prog_data
,
180 unsigned promoted_constants
,
181 bool runtime_check_aads_emit
,
182 gl_shader_stage stage
)
184 : compiler(compiler
), log_data(log_data
),
185 devinfo(compiler
->devinfo
), key(key
),
186 prog_data(prog_data
),
187 promoted_constants(promoted_constants
),
188 runtime_check_aads_emit(runtime_check_aads_emit
), debug_flag(false),
189 stage(stage
), mem_ctx(mem_ctx
)
191 p
= rzalloc(mem_ctx
, struct brw_codegen
);
192 brw_init_codegen(devinfo
, p
, mem_ctx
);
195 fs_generator::~fs_generator()
199 class ip_record
: public exec_node
{
201 DECLARE_RALLOC_CXX_OPERATORS(ip_record
)
212 fs_generator::patch_discard_jumps_to_fb_writes()
214 if (devinfo
->gen
< 6 || this->discard_halt_patches
.is_empty())
217 int scale
= brw_jump_scale(p
->devinfo
);
219 /* There is a somewhat strange undocumented requirement of using
220 * HALT, according to the simulator. If some channel has HALTed to
221 * a particular UIP, then by the end of the program, every channel
222 * must have HALTed to that UIP. Furthermore, the tracking is a
223 * stack, so you can't do the final halt of a UIP after starting
224 * halting to a new UIP.
226 * Symptoms of not emitting this instruction on actual hardware
227 * included GPU hangs and sparkly rendering on the piglit discard
230 brw_inst
*last_halt
= gen6_HALT(p
);
231 brw_inst_set_uip(p
->devinfo
, last_halt
, 1 * scale
);
232 brw_inst_set_jip(p
->devinfo
, last_halt
, 1 * scale
);
236 foreach_in_list(ip_record
, patch_ip
, &discard_halt_patches
) {
237 brw_inst
*patch
= &p
->store
[patch_ip
->ip
];
239 assert(brw_inst_opcode(p
->devinfo
, patch
) == BRW_OPCODE_HALT
);
240 /* HALT takes a half-instruction distance from the pre-incremented IP. */
241 brw_inst_set_uip(p
->devinfo
, patch
, (ip
- patch_ip
->ip
) * scale
);
244 this->discard_halt_patches
.make_empty();
249 fs_generator::fire_fb_write(fs_inst
*inst
,
250 struct brw_reg payload
,
251 struct brw_reg implied_header
,
254 uint32_t msg_control
;
256 struct brw_wm_prog_data
*prog_data
= brw_wm_prog_data(this->prog_data
);
258 if (devinfo
->gen
< 6) {
259 brw_push_insn_state(p
);
260 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
261 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
262 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
263 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
264 brw_MOV(p
, offset(payload
, 1), brw_vec8_grf(1, 0));
265 brw_pop_insn_state(p
);
268 if (inst
->opcode
== FS_OPCODE_REP_FB_WRITE
)
269 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED
;
270 else if (prog_data
->dual_src_blend
) {
272 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01
;
274 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23
;
275 } else if (inst
->exec_size
== 16)
276 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
;
278 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01
;
280 /* We assume render targets start at 0, because headerless FB write
281 * messages set "Render Target Index" to 0. Using a different binding
282 * table index would make it impossible to use headerless messages.
284 assert(prog_data
->binding_table
.render_target_start
== 0);
286 const uint32_t surf_index
= inst
->target
;
288 bool last_render_target
= inst
->eot
||
289 (prog_data
->dual_src_blend
&& dispatch_width
== 16);
301 inst
->header_size
!= 0);
303 brw_mark_surface_used(&prog_data
->base
, surf_index
);
307 fs_generator::generate_fb_write(fs_inst
*inst
, struct brw_reg payload
)
309 struct brw_wm_prog_data
*prog_data
= brw_wm_prog_data(this->prog_data
);
310 const brw_wm_prog_key
* const key
= (brw_wm_prog_key
* const) this->key
;
311 struct brw_reg implied_header
;
313 if (devinfo
->gen
< 8 && !devinfo
->is_haswell
) {
314 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
317 if (inst
->base_mrf
>= 0)
318 payload
= brw_message_reg(inst
->base_mrf
);
320 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
323 if (inst
->header_size
!= 0) {
324 brw_push_insn_state(p
);
325 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
326 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
327 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
328 brw_set_default_flag_reg(p
, 0, 0);
330 /* On HSW, the GPU will use the predicate on SENDC, unless the header is
333 if (prog_data
->uses_kill
) {
334 struct brw_reg pixel_mask
;
336 if (devinfo
->gen
>= 6)
337 pixel_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
339 pixel_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
341 brw_MOV(p
, pixel_mask
, brw_flag_reg(0, 1));
344 if (devinfo
->gen
>= 6) {
345 brw_push_insn_state(p
);
346 brw_set_default_exec_size(p
, BRW_EXECUTE_16
);
347 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
349 retype(payload
, BRW_REGISTER_TYPE_UD
),
350 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
351 brw_pop_insn_state(p
);
353 if (inst
->target
> 0 && key
->replicate_alpha
) {
354 /* Set "Source0 Alpha Present to RenderTarget" bit in message
358 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
359 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
360 brw_imm_ud(0x1 << 11));
363 if (inst
->target
> 0) {
364 /* Set the render target index for choosing BLEND_STATE. */
365 brw_MOV(p
, retype(vec1(suboffset(payload
, 2)),
366 BRW_REGISTER_TYPE_UD
),
367 brw_imm_ud(inst
->target
));
370 /* Set computes stencil to render target */
371 if (prog_data
->computed_stencil
) {
373 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
374 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
375 brw_imm_ud(0x1 << 14));
378 implied_header
= brw_null_reg();
380 implied_header
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
383 brw_pop_insn_state(p
);
385 implied_header
= brw_null_reg();
388 if (!runtime_check_aads_emit
) {
389 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
391 /* This can only happen in gen < 6 */
392 assert(devinfo
->gen
< 6);
394 struct brw_reg v1_null_ud
= vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD
));
396 /* Check runtime bit to detect if we have to send AA data or not */
397 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
400 retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD
),
402 brw_inst_set_cond_modifier(p
->devinfo
, brw_last_inst
, BRW_CONDITIONAL_NZ
);
404 int jmp
= brw_JMPI(p
, brw_imm_ud(0), BRW_PREDICATE_NORMAL
) - p
->store
;
405 brw_inst_set_exec_size(p
->devinfo
, brw_last_inst
, BRW_EXECUTE_1
);
407 /* Don't send AA data */
408 fire_fb_write(inst
, offset(payload
, 1), implied_header
, inst
->mlen
-1);
410 brw_land_fwd_jump(p
, jmp
);
411 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
416 fs_generator::generate_fb_read(fs_inst
*inst
, struct brw_reg dst
,
417 struct brw_reg payload
)
419 assert(inst
->size_written
% REG_SIZE
== 0);
420 struct brw_wm_prog_data
*prog_data
= brw_wm_prog_data(this->prog_data
);
421 const unsigned surf_index
=
422 prog_data
->binding_table
.render_target_start
+ inst
->target
;
424 gen9_fb_READ(p
, dst
, payload
, surf_index
,
425 inst
->header_size
, inst
->size_written
/ REG_SIZE
,
426 prog_data
->persample_dispatch
);
428 brw_mark_surface_used(&prog_data
->base
, surf_index
);
432 fs_generator::generate_mov_indirect(fs_inst
*inst
,
435 struct brw_reg indirect_byte_offset
)
437 assert(indirect_byte_offset
.type
== BRW_REGISTER_TYPE_UD
);
438 assert(indirect_byte_offset
.file
== BRW_GENERAL_REGISTER_FILE
);
440 unsigned imm_byte_offset
= reg
.nr
* REG_SIZE
+ reg
.subnr
;
442 if (indirect_byte_offset
.file
== BRW_IMMEDIATE_VALUE
) {
443 imm_byte_offset
+= indirect_byte_offset
.ud
;
445 reg
.nr
= imm_byte_offset
/ REG_SIZE
;
446 reg
.subnr
= imm_byte_offset
% REG_SIZE
;
447 brw_MOV(p
, dst
, reg
);
449 /* Prior to Broadwell, there are only 8 address registers. */
450 assert(inst
->exec_size
<= 8 || devinfo
->gen
>= 8);
452 /* We use VxH indirect addressing, clobbering a0.0 through a0.7. */
453 struct brw_reg addr
= vec8(brw_address_reg(0));
455 /* The destination stride of an instruction (in bytes) must be greater
456 * than or equal to the size of the rest of the instruction. Since the
457 * address register is of type UW, we can't use a D-type instruction.
458 * In order to get around this, re retype to UW and use a stride.
460 indirect_byte_offset
=
461 retype(spread(indirect_byte_offset
, 2), BRW_REGISTER_TYPE_UW
);
463 /* There are a number of reasons why we don't use the base offset here.
464 * One reason is that the field is only 9 bits which means we can only
465 * use it to access the first 16 GRFs. Also, from the Haswell PRM
466 * section "Register Region Restrictions":
468 * "The lower bits of the AddressImmediate must not overflow to
469 * change the register address. The lower 5 bits of Address
470 * Immediate when added to lower 5 bits of address register gives
471 * the sub-register offset. The upper bits of Address Immediate
472 * when added to upper bits of address register gives the register
473 * address. Any overflow from sub-register offset is dropped."
475 * Since the indirect may cause us to cross a register boundary, this
476 * makes the base offset almost useless. We could try and do something
477 * clever where we use a actual base offset if base_offset % 32 == 0 but
478 * that would mean we were generating different code depending on the
479 * base offset. Instead, for the sake of consistency, we'll just do the
480 * add ourselves. This restriction is only listed in the Haswell PRM
481 * but empirical testing indicates that it applies on all older
482 * generations and is lifted on Broadwell.
484 * In the end, while base_offset is nice to look at in the generated
485 * code, using it saves us 0 instructions and would require quite a bit
486 * of case-by-case work. It's just not worth it.
488 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
|| type_sz(reg
.type
) < 8) {
489 brw_ADD(p
, addr
, indirect_byte_offset
, brw_imm_uw(imm_byte_offset
));
491 /* IVB reads two address register components per channel for
492 * indirectly addressed 64-bit sources, so we need to initialize
493 * adjacent address components to consecutive dwords of the source
494 * region by emitting two separate ADD instructions. Found
497 assert(inst
->exec_size
<= 4);
498 brw_push_insn_state(p
);
499 brw_set_default_exec_size(p
, cvt(inst
->exec_size
) - 1);
501 brw_ADD(p
, spread(addr
, 2), indirect_byte_offset
,
502 brw_imm_uw(imm_byte_offset
));
503 brw_inst_set_no_dd_clear(devinfo
, brw_last_inst
, true);
505 brw_ADD(p
, spread(suboffset(addr
, 1), 2), indirect_byte_offset
,
506 brw_imm_uw(imm_byte_offset
+ 4));
507 brw_inst_set_no_dd_check(devinfo
, brw_last_inst
, true);
509 brw_pop_insn_state(p
);
512 struct brw_reg ind_src
= brw_VxH_indirect(0, 0);
514 brw_inst
*mov
= brw_MOV(p
, dst
, retype(ind_src
, reg
.type
));
516 if (devinfo
->gen
== 6 && dst
.file
== BRW_MESSAGE_REGISTER_FILE
&&
517 !inst
->get_next()->is_tail_sentinel() &&
518 ((fs_inst
*)inst
->get_next())->mlen
> 0) {
519 /* From the Sandybridge PRM:
521 * "[Errata: DevSNB(SNB)] If MRF register is updated by any
522 * instruction that “indexed/indirect” source AND is followed by a
523 * send, the instruction requires a “Switch”. This is to avoid
524 * race condition where send may dispatch before MRF is updated."
526 brw_inst_set_thread_control(devinfo
, mov
, BRW_THREAD_SWITCH
);
532 fs_generator::generate_urb_read(fs_inst
*inst
,
534 struct brw_reg header
)
536 assert(inst
->size_written
% REG_SIZE
== 0);
537 assert(header
.file
== BRW_GENERAL_REGISTER_FILE
);
538 assert(header
.type
== BRW_REGISTER_TYPE_UD
);
540 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
541 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UD
));
542 brw_set_src0(p
, send
, header
);
543 brw_set_src1(p
, send
, brw_imm_ud(0u));
545 brw_inst_set_sfid(p
->devinfo
, send
, BRW_SFID_URB
);
546 brw_inst_set_urb_opcode(p
->devinfo
, send
, GEN8_URB_OPCODE_SIMD8_READ
);
548 if (inst
->opcode
== SHADER_OPCODE_URB_READ_SIMD8_PER_SLOT
)
549 brw_inst_set_urb_per_slot_offset(p
->devinfo
, send
, true);
551 brw_inst_set_mlen(p
->devinfo
, send
, inst
->mlen
);
552 brw_inst_set_rlen(p
->devinfo
, send
, inst
->size_written
/ REG_SIZE
);
553 brw_inst_set_header_present(p
->devinfo
, send
, true);
554 brw_inst_set_urb_global_offset(p
->devinfo
, send
, inst
->offset
);
558 fs_generator::generate_urb_write(fs_inst
*inst
, struct brw_reg payload
)
562 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
564 brw_set_dest(p
, insn
, brw_null_reg());
565 brw_set_src0(p
, insn
, payload
);
566 brw_set_src1(p
, insn
, brw_imm_d(0));
568 brw_inst_set_sfid(p
->devinfo
, insn
, BRW_SFID_URB
);
569 brw_inst_set_urb_opcode(p
->devinfo
, insn
, GEN8_URB_OPCODE_SIMD8_WRITE
);
571 if (inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_PER_SLOT
||
572 inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT
)
573 brw_inst_set_urb_per_slot_offset(p
->devinfo
, insn
, true);
575 if (inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_MASKED
||
576 inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT
)
577 brw_inst_set_urb_channel_mask_present(p
->devinfo
, insn
, true);
579 brw_inst_set_mlen(p
->devinfo
, insn
, inst
->mlen
);
580 brw_inst_set_rlen(p
->devinfo
, insn
, 0);
581 brw_inst_set_eot(p
->devinfo
, insn
, inst
->eot
);
582 brw_inst_set_header_present(p
->devinfo
, insn
, true);
583 brw_inst_set_urb_global_offset(p
->devinfo
, insn
, inst
->offset
);
587 fs_generator::generate_cs_terminate(fs_inst
*inst
, struct brw_reg payload
)
589 struct brw_inst
*insn
;
591 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
593 brw_set_dest(p
, insn
, retype(brw_null_reg(), BRW_REGISTER_TYPE_UW
));
594 brw_set_src0(p
, insn
, retype(payload
, BRW_REGISTER_TYPE_UW
));
595 brw_set_src1(p
, insn
, brw_imm_d(0));
597 /* Terminate a compute shader by sending a message to the thread spawner.
599 brw_inst_set_sfid(devinfo
, insn
, BRW_SFID_THREAD_SPAWNER
);
600 brw_inst_set_mlen(devinfo
, insn
, 1);
601 brw_inst_set_rlen(devinfo
, insn
, 0);
602 brw_inst_set_eot(devinfo
, insn
, inst
->eot
);
603 brw_inst_set_header_present(devinfo
, insn
, false);
605 brw_inst_set_ts_opcode(devinfo
, insn
, 0); /* Dereference resource */
606 brw_inst_set_ts_request_type(devinfo
, insn
, 0); /* Root thread */
608 /* Note that even though the thread has a URB resource associated with it,
609 * we set the "do not dereference URB" bit, because the URB resource is
610 * managed by the fixed-function unit, so it will free it automatically.
612 brw_inst_set_ts_resource_select(devinfo
, insn
, 1); /* Do not dereference URB */
614 brw_inst_set_mask_control(devinfo
, insn
, BRW_MASK_DISABLE
);
618 fs_generator::generate_barrier(fs_inst
*inst
, struct brw_reg src
)
625 fs_generator::generate_linterp(fs_inst
*inst
,
626 struct brw_reg dst
, struct brw_reg
*src
)
630 * -----------------------------------
631 * | src1+0 | src1+1 | src1+2 | src1+3 |
632 * |-----------------------------------|
633 * |(x0, x1)|(y0, y1)|(x2, x3)|(y2, y3)|
634 * -----------------------------------
636 * but for the LINE/MAC pair, the LINE reads Xs and the MAC reads Ys:
638 * -----------------------------------
639 * | src1+0 | src1+1 | src1+2 | src1+3 |
640 * |-----------------------------------|
641 * |(x0, x1)|(y0, y1)| | | in SIMD8
642 * |-----------------------------------|
643 * |(x0, x1)|(x2, x3)|(y0, y1)|(y2, y3)| in SIMD16
644 * -----------------------------------
646 * See also: emit_interpolation_setup_gen4().
648 struct brw_reg delta_x
= src
[0];
649 struct brw_reg delta_y
= offset(src
[0], inst
->exec_size
/ 8);
650 struct brw_reg interp
= src
[1];
652 if (devinfo
->has_pln
&&
653 (devinfo
->gen
>= 7 || (delta_x
.nr
& 1) == 0)) {
654 brw_PLN(p
, dst
, interp
, delta_x
);
656 brw_LINE(p
, brw_null_reg(), interp
, delta_x
);
657 brw_MAC(p
, dst
, suboffset(interp
, 1), delta_y
);
662 fs_generator::generate_get_buffer_size(fs_inst
*inst
,
665 struct brw_reg surf_index
)
667 assert(devinfo
->gen
>= 7);
668 assert(surf_index
.file
== BRW_IMMEDIATE_VALUE
);
673 switch (inst
->exec_size
) {
675 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
678 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
681 unreachable("Invalid width for texture instruction");
684 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
690 retype(dst
, BRW_REGISTER_TYPE_UW
),
695 GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
,
696 rlen
, /* response length */
698 inst
->header_size
> 0,
700 BRW_SAMPLER_RETURN_FORMAT_SINT32
);
702 brw_mark_surface_used(prog_data
, surf_index
.ud
);
706 fs_generator::generate_tex(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
,
707 struct brw_reg surface_index
,
708 struct brw_reg sampler_index
)
710 assert(inst
->size_written
% REG_SIZE
== 0);
713 uint32_t return_format
;
714 bool is_combined_send
= inst
->eot
;
717 case BRW_REGISTER_TYPE_D
:
718 return_format
= BRW_SAMPLER_RETURN_FORMAT_SINT32
;
720 case BRW_REGISTER_TYPE_UD
:
721 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
724 return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
728 /* Stomp the resinfo output type to UINT32. On gens 4-5, the output type
729 * is set as part of the message descriptor. On gen4, the PRM seems to
730 * allow UINT32 and FLOAT32 (i965 PRM, Vol. 4 Section 4.8.1.1), but on
731 * later gens UINT32 is required. Once you hit Sandy Bridge, the bit is
732 * gone from the message descriptor entirely and you just get UINT32 all
733 * the time regasrdless. Since we can really only do non-UINT32 on gen4,
734 * just stomp it to UINT32 all the time.
736 if (inst
->opcode
== SHADER_OPCODE_TXS
)
737 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
739 switch (inst
->exec_size
) {
741 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
744 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
747 unreachable("Invalid width for texture instruction");
750 if (devinfo
->gen
>= 5) {
751 switch (inst
->opcode
) {
752 case SHADER_OPCODE_TEX
:
753 if (inst
->shadow_compare
) {
754 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE
;
756 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE
;
760 if (inst
->shadow_compare
) {
761 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE
;
763 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS
;
766 case SHADER_OPCODE_TXL
:
767 if (inst
->shadow_compare
) {
768 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE
;
770 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD
;
773 case SHADER_OPCODE_TXL_LZ
:
774 assert(devinfo
->gen
>= 9);
775 if (inst
->shadow_compare
) {
776 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_C_LZ
;
778 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_LZ
;
781 case SHADER_OPCODE_TXS
:
782 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
;
784 case SHADER_OPCODE_TXD
:
785 if (inst
->shadow_compare
) {
786 /* Gen7.5+. Otherwise, lowered in NIR */
787 assert(devinfo
->gen
>= 8 || devinfo
->is_haswell
);
788 msg_type
= HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE
;
790 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS
;
793 case SHADER_OPCODE_TXF
:
794 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
796 case SHADER_OPCODE_TXF_LZ
:
797 assert(devinfo
->gen
>= 9);
798 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_LD_LZ
;
800 case SHADER_OPCODE_TXF_CMS_W
:
801 assert(devinfo
->gen
>= 9);
802 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_LD2DMS_W
;
804 case SHADER_OPCODE_TXF_CMS
:
805 if (devinfo
->gen
>= 7)
806 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS
;
808 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
810 case SHADER_OPCODE_TXF_UMS
:
811 assert(devinfo
->gen
>= 7);
812 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS
;
814 case SHADER_OPCODE_TXF_MCS
:
815 assert(devinfo
->gen
>= 7);
816 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS
;
818 case SHADER_OPCODE_LOD
:
819 msg_type
= GEN5_SAMPLER_MESSAGE_LOD
;
821 case SHADER_OPCODE_TG4
:
822 if (inst
->shadow_compare
) {
823 assert(devinfo
->gen
>= 7);
824 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C
;
826 assert(devinfo
->gen
>= 6);
827 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4
;
830 case SHADER_OPCODE_TG4_OFFSET
:
831 assert(devinfo
->gen
>= 7);
832 if (inst
->shadow_compare
) {
833 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C
;
835 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO
;
838 case SHADER_OPCODE_SAMPLEINFO
:
839 msg_type
= GEN6_SAMPLER_MESSAGE_SAMPLE_SAMPLEINFO
;
842 unreachable("not reached");
845 switch (inst
->opcode
) {
846 case SHADER_OPCODE_TEX
:
847 /* Note that G45 and older determines shadow compare and dispatch width
848 * from message length for most messages.
850 if (inst
->exec_size
== 8) {
851 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE
;
852 if (inst
->shadow_compare
) {
853 assert(inst
->mlen
== 6);
855 assert(inst
->mlen
<= 4);
858 if (inst
->shadow_compare
) {
859 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE
;
860 assert(inst
->mlen
== 9);
862 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE
;
863 assert(inst
->mlen
<= 7 && inst
->mlen
% 2 == 1);
868 if (inst
->shadow_compare
) {
869 assert(inst
->exec_size
== 8);
870 assert(inst
->mlen
== 6);
871 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE
;
873 assert(inst
->mlen
== 9);
874 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS
;
875 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
878 case SHADER_OPCODE_TXL
:
879 if (inst
->shadow_compare
) {
880 assert(inst
->exec_size
== 8);
881 assert(inst
->mlen
== 6);
882 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE
;
884 assert(inst
->mlen
== 9);
885 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD
;
886 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
889 case SHADER_OPCODE_TXD
:
890 /* There is no sample_d_c message; comparisons are done manually */
891 assert(inst
->exec_size
== 8);
892 assert(inst
->mlen
== 7 || inst
->mlen
== 10);
893 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS
;
895 case SHADER_OPCODE_TXF
:
896 assert(inst
->mlen
<= 9 && inst
->mlen
% 2 == 1);
897 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
898 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
900 case SHADER_OPCODE_TXS
:
901 assert(inst
->mlen
== 3);
902 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_RESINFO
;
903 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
906 unreachable("not reached");
909 assert(msg_type
!= -1);
911 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
915 assert(devinfo
->gen
< 7 || inst
->header_size
== 0 ||
916 src
.file
== BRW_GENERAL_REGISTER_FILE
);
918 assert(sampler_index
.type
== BRW_REGISTER_TYPE_UD
);
920 /* Load the message header if present. If there's a texture offset,
921 * we need to set it up explicitly and load the offset bitfield.
922 * Otherwise, we can use an implied move from g0 to the first message reg.
924 if (inst
->header_size
!= 0) {
925 if (devinfo
->gen
< 6 && !inst
->offset
) {
926 /* Set up an implied move from g0 to the MRF. */
927 src
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
929 struct brw_reg header_reg
;
931 if (devinfo
->gen
>= 7) {
934 assert(inst
->base_mrf
!= -1);
935 header_reg
= brw_message_reg(inst
->base_mrf
);
938 brw_push_insn_state(p
);
939 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
940 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
941 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
942 /* Explicitly set up the message header by copying g0 to the MRF. */
943 brw_MOV(p
, header_reg
, brw_vec8_grf(0, 0));
946 /* Set the offset bits in DWord 2. */
947 brw_MOV(p
, get_element_ud(header_reg
, 2),
948 brw_imm_ud(inst
->offset
));
949 } else if (stage
!= MESA_SHADER_VERTEX
&&
950 stage
!= MESA_SHADER_FRAGMENT
) {
951 /* The vertex and fragment stages have g0.2 set to 0, so
952 * header0.2 is 0 when g0 is copied. Other stages may not, so we
953 * must set it to 0 to avoid setting undesirable bits in the
956 brw_MOV(p
, get_element_ud(header_reg
, 2), brw_imm_ud(0));
959 brw_adjust_sampler_state_pointer(p
, header_reg
, sampler_index
);
960 brw_pop_insn_state(p
);
964 uint32_t base_binding_table_index
= (inst
->opcode
== SHADER_OPCODE_TG4
||
965 inst
->opcode
== SHADER_OPCODE_TG4_OFFSET
)
966 ? prog_data
->binding_table
.gather_texture_start
967 : prog_data
->binding_table
.texture_start
;
969 if (surface_index
.file
== BRW_IMMEDIATE_VALUE
&&
970 sampler_index
.file
== BRW_IMMEDIATE_VALUE
) {
971 uint32_t surface
= surface_index
.ud
;
972 uint32_t sampler
= sampler_index
.ud
;
975 retype(dst
, BRW_REGISTER_TYPE_UW
),
978 surface
+ base_binding_table_index
,
981 inst
->size_written
/ REG_SIZE
,
983 inst
->header_size
!= 0,
987 brw_mark_surface_used(prog_data
, surface
+ base_binding_table_index
);
989 /* Non-const sampler index */
991 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
992 struct brw_reg surface_reg
= vec1(retype(surface_index
, BRW_REGISTER_TYPE_UD
));
993 struct brw_reg sampler_reg
= vec1(retype(sampler_index
, BRW_REGISTER_TYPE_UD
));
995 brw_push_insn_state(p
);
996 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
997 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
999 if (brw_regs_equal(&surface_reg
, &sampler_reg
)) {
1000 brw_MUL(p
, addr
, sampler_reg
, brw_imm_uw(0x101));
1002 if (sampler_reg
.file
== BRW_IMMEDIATE_VALUE
) {
1003 brw_OR(p
, addr
, surface_reg
, brw_imm_ud(sampler_reg
.ud
<< 8));
1005 brw_SHL(p
, addr
, sampler_reg
, brw_imm_ud(8));
1006 brw_OR(p
, addr
, addr
, surface_reg
);
1009 if (base_binding_table_index
)
1010 brw_ADD(p
, addr
, addr
, brw_imm_ud(base_binding_table_index
));
1011 brw_AND(p
, addr
, addr
, brw_imm_ud(0xfff));
1013 brw_pop_insn_state(p
);
1015 /* dst = send(offset, a0.0 | <descriptor>) */
1016 brw_inst
*insn
= brw_send_indirect_message(
1017 p
, BRW_SFID_SAMPLER
, dst
, src
, addr
);
1018 brw_set_sampler_message(p
, insn
,
1022 inst
->size_written
/ REG_SIZE
,
1023 inst
->mlen
/* mlen */,
1024 inst
->header_size
!= 0 /* header */,
1028 /* visitor knows more than we do about the surface limit required,
1029 * so has already done marking.
1033 if (is_combined_send
) {
1034 brw_inst_set_eot(p
->devinfo
, brw_last_inst
, true);
1035 brw_inst_set_opcode(p
->devinfo
, brw_last_inst
, BRW_OPCODE_SENDC
);
1040 /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
1043 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
1045 * Ideally, we want to produce:
1048 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
1049 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
1050 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
1051 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
1052 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
1053 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
1054 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
1055 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
1057 * and add another set of two more subspans if in 16-pixel dispatch mode.
1059 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
1060 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
1061 * pair. But the ideal approximation may impose a huge performance cost on
1062 * sample_d. On at least Haswell, sample_d instruction does some
1063 * optimizations if the same LOD is used for all pixels in the subspan.
1065 * For DDY, we need to use ALIGN16 mode since it's capable of doing the
1066 * appropriate swizzling.
1069 fs_generator::generate_ddx(enum opcode opcode
,
1070 struct brw_reg dst
, struct brw_reg src
)
1072 unsigned vstride
, width
;
1074 if (opcode
== FS_OPCODE_DDX_FINE
) {
1075 /* produce accurate derivatives */
1076 vstride
= BRW_VERTICAL_STRIDE_2
;
1077 width
= BRW_WIDTH_2
;
1079 /* replicate the derivative at the top-left pixel to other pixels */
1080 vstride
= BRW_VERTICAL_STRIDE_4
;
1081 width
= BRW_WIDTH_4
;
1084 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 1,
1085 src
.negate
, src
.abs
,
1086 BRW_REGISTER_TYPE_F
,
1089 BRW_HORIZONTAL_STRIDE_0
,
1090 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1091 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
1092 src
.negate
, src
.abs
,
1093 BRW_REGISTER_TYPE_F
,
1096 BRW_HORIZONTAL_STRIDE_0
,
1097 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1098 brw_ADD(p
, dst
, src0
, negate(src1
));
1101 /* The negate_value boolean is used to negate the derivative computation for
1102 * FBOs, since they place the origin at the upper left instead of the lower
1106 fs_generator::generate_ddy(enum opcode opcode
,
1107 struct brw_reg dst
, struct brw_reg src
)
1109 if (opcode
== FS_OPCODE_DDY_FINE
) {
1110 /* produce accurate derivatives */
1111 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
1112 src
.negate
, src
.abs
,
1113 BRW_REGISTER_TYPE_F
,
1114 BRW_VERTICAL_STRIDE_4
,
1116 BRW_HORIZONTAL_STRIDE_1
,
1117 BRW_SWIZZLE_XYXY
, WRITEMASK_XYZW
);
1118 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
1119 src
.negate
, src
.abs
,
1120 BRW_REGISTER_TYPE_F
,
1121 BRW_VERTICAL_STRIDE_4
,
1123 BRW_HORIZONTAL_STRIDE_1
,
1124 BRW_SWIZZLE_ZWZW
, WRITEMASK_XYZW
);
1125 brw_push_insn_state(p
);
1126 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1127 brw_ADD(p
, dst
, negate(src0
), src1
);
1128 brw_pop_insn_state(p
);
1130 /* replicate the derivative at the top-left pixel to other pixels */
1131 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
1132 src
.negate
, src
.abs
,
1133 BRW_REGISTER_TYPE_F
,
1134 BRW_VERTICAL_STRIDE_4
,
1136 BRW_HORIZONTAL_STRIDE_0
,
1137 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1138 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 2,
1139 src
.negate
, src
.abs
,
1140 BRW_REGISTER_TYPE_F
,
1141 BRW_VERTICAL_STRIDE_4
,
1143 BRW_HORIZONTAL_STRIDE_0
,
1144 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1145 brw_ADD(p
, dst
, negate(src0
), src1
);
1150 fs_generator::generate_discard_jump(fs_inst
*inst
)
1152 assert(devinfo
->gen
>= 6);
1154 /* This HALT will be patched up at FB write time to point UIP at the end of
1155 * the program, and at brw_uip_jip() JIP will be set to the end of the
1156 * current block (or the program).
1158 this->discard_halt_patches
.push_tail(new(mem_ctx
) ip_record(p
->nr_insn
));
1163 fs_generator::generate_scratch_write(fs_inst
*inst
, struct brw_reg src
)
1165 /* The 32-wide messages only respect the first 16-wide half of the channel
1166 * enable signals which are replicated identically for the second group of
1167 * 16 channels, so we cannot use them unless the write is marked
1168 * force_writemask_all.
1170 const unsigned lower_size
= inst
->force_writemask_all
? inst
->exec_size
:
1171 MIN2(16, inst
->exec_size
);
1172 const unsigned block_size
= 4 * lower_size
/ REG_SIZE
;
1173 assert(inst
->mlen
!= 0);
1175 brw_push_insn_state(p
);
1176 brw_set_default_exec_size(p
, cvt(lower_size
) - 1);
1177 brw_set_default_compression(p
, lower_size
> 8);
1179 for (unsigned i
= 0; i
< inst
->exec_size
/ lower_size
; i
++) {
1180 brw_set_default_group(p
, inst
->group
+ lower_size
* i
);
1182 brw_MOV(p
, brw_uvec_mrf(lower_size
, inst
->base_mrf
+ 1, 0),
1183 retype(offset(src
, block_size
* i
), BRW_REGISTER_TYPE_UD
));
1185 brw_oword_block_write_scratch(p
, brw_message_reg(inst
->base_mrf
),
1187 inst
->offset
+ block_size
* REG_SIZE
* i
);
1190 brw_pop_insn_state(p
);
1194 fs_generator::generate_scratch_read(fs_inst
*inst
, struct brw_reg dst
)
1196 assert(inst
->exec_size
<= 16 || inst
->force_writemask_all
);
1197 assert(inst
->mlen
!= 0);
1199 brw_oword_block_read_scratch(p
, dst
, brw_message_reg(inst
->base_mrf
),
1200 inst
->exec_size
/ 8, inst
->offset
);
1204 fs_generator::generate_scratch_read_gen7(fs_inst
*inst
, struct brw_reg dst
)
1206 assert(inst
->exec_size
<= 16 || inst
->force_writemask_all
);
1208 gen7_block_read_scratch(p
, dst
, inst
->exec_size
/ 8, inst
->offset
);
1212 fs_generator::generate_uniform_pull_constant_load(fs_inst
*inst
,
1214 struct brw_reg index
,
1215 struct brw_reg offset
)
1217 assert(type_sz(dst
.type
) == 4);
1218 assert(inst
->mlen
!= 0);
1220 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1221 index
.type
== BRW_REGISTER_TYPE_UD
);
1222 uint32_t surf_index
= index
.ud
;
1224 assert(offset
.file
== BRW_IMMEDIATE_VALUE
&&
1225 offset
.type
== BRW_REGISTER_TYPE_UD
);
1226 uint32_t read_offset
= offset
.ud
;
1228 brw_oword_block_read(p
, dst
, brw_message_reg(inst
->base_mrf
),
1229 read_offset
, surf_index
);
1233 fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst
*inst
,
1235 struct brw_reg index
,
1236 struct brw_reg payload
)
1238 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1239 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1240 assert(type_sz(dst
.type
) == 4);
1242 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1243 const uint32_t surf_index
= index
.ud
;
1245 brw_push_insn_state(p
);
1246 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1247 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1248 brw_pop_insn_state(p
);
1250 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UD
));
1251 brw_set_src0(p
, send
, retype(payload
, BRW_REGISTER_TYPE_UD
));
1252 brw_set_dp_read_message(p
, send
, surf_index
,
1253 BRW_DATAPORT_OWORD_BLOCK_DWORDS(inst
->exec_size
),
1254 GEN7_DATAPORT_DC_OWORD_BLOCK_READ
,
1255 GEN6_SFID_DATAPORT_CONSTANT_CACHE
,
1258 DIV_ROUND_UP(inst
->size_written
, REG_SIZE
));
1261 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1263 brw_push_insn_state(p
);
1264 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1266 /* a0.0 = surf_index & 0xff */
1267 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1268 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1269 brw_set_dest(p
, insn_and
, addr
);
1270 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1271 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1273 /* dst = send(payload, a0.0 | <descriptor>) */
1274 brw_inst
*insn
= brw_send_indirect_message(
1275 p
, GEN6_SFID_DATAPORT_CONSTANT_CACHE
,
1276 retype(dst
, BRW_REGISTER_TYPE_UD
),
1277 retype(payload
, BRW_REGISTER_TYPE_UD
), addr
);
1278 brw_set_dp_read_message(p
, insn
, 0 /* surface */,
1279 BRW_DATAPORT_OWORD_BLOCK_DWORDS(inst
->exec_size
),
1280 GEN7_DATAPORT_DC_OWORD_BLOCK_READ
,
1281 GEN6_SFID_DATAPORT_CONSTANT_CACHE
,
1284 DIV_ROUND_UP(inst
->size_written
, REG_SIZE
));
1286 brw_pop_insn_state(p
);
1291 fs_generator::generate_varying_pull_constant_load_gen4(fs_inst
*inst
,
1293 struct brw_reg index
)
1295 assert(devinfo
->gen
< 7); /* Should use the gen7 variant. */
1296 assert(inst
->header_size
!= 0);
1299 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1300 index
.type
== BRW_REGISTER_TYPE_UD
);
1301 uint32_t surf_index
= index
.ud
;
1303 uint32_t simd_mode
, rlen
, msg_type
;
1304 if (inst
->exec_size
== 16) {
1305 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1308 assert(inst
->exec_size
== 8);
1309 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1313 if (devinfo
->gen
>= 5)
1314 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
1316 /* We always use the SIMD16 message so that we only have to load U, and
1319 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
1320 assert(inst
->mlen
== 3);
1321 assert(inst
->size_written
== 8 * REG_SIZE
);
1323 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1326 struct brw_reg header
= brw_vec8_grf(0, 0);
1327 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
1329 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1330 brw_inst_set_compression(devinfo
, send
, false);
1331 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1332 brw_set_src0(p
, send
, header
);
1333 if (devinfo
->gen
< 6)
1334 brw_inst_set_base_mrf(p
->devinfo
, send
, inst
->base_mrf
);
1336 /* Our surface is set up as floats, regardless of what actual data is
1339 uint32_t return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
1340 brw_set_sampler_message(p
, send
,
1342 0, /* sampler (unused) */
1346 inst
->header_size
!= 0,
1352 fs_generator::generate_varying_pull_constant_load_gen7(fs_inst
*inst
,
1354 struct brw_reg index
,
1355 struct brw_reg offset
)
1357 assert(devinfo
->gen
>= 7);
1358 /* Varying-offset pull constant loads are treated as a normal expression on
1359 * gen7, so the fact that it's a send message is hidden at the IR level.
1361 assert(inst
->header_size
== 0);
1362 assert(!inst
->mlen
);
1363 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1365 uint32_t simd_mode
, rlen
, mlen
;
1366 if (inst
->exec_size
== 16) {
1369 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1371 assert(inst
->exec_size
== 8);
1374 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1377 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1379 uint32_t surf_index
= index
.ud
;
1381 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1382 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1383 brw_set_src0(p
, send
, offset
);
1384 brw_set_sampler_message(p
, send
,
1386 0, /* LD message ignores sampler unit */
1387 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1390 false, /* no header */
1396 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1398 brw_push_insn_state(p
);
1399 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1401 /* a0.0 = surf_index & 0xff */
1402 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1403 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1404 brw_set_dest(p
, insn_and
, addr
);
1405 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1406 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1408 brw_pop_insn_state(p
);
1410 /* dst = send(offset, a0.0 | <descriptor>) */
1411 brw_inst
*insn
= brw_send_indirect_message(
1412 p
, BRW_SFID_SAMPLER
, retype(dst
, BRW_REGISTER_TYPE_UW
),
1414 brw_set_sampler_message(p
, insn
,
1417 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1427 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
1428 * into the flags register (f0.0).
1430 * Used only on Gen6 and above.
1433 fs_generator::generate_mov_dispatch_to_flags(fs_inst
*inst
)
1435 struct brw_reg flags
= brw_flag_reg(0, inst
->flag_subreg
);
1436 struct brw_reg dispatch_mask
;
1438 if (devinfo
->gen
>= 6)
1439 dispatch_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
1441 dispatch_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
1443 brw_push_insn_state(p
);
1444 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1445 brw_MOV(p
, flags
, dispatch_mask
);
1446 brw_pop_insn_state(p
);
1450 fs_generator::generate_pixel_interpolator_query(fs_inst
*inst
,
1453 struct brw_reg msg_data
,
1456 assert(inst
->size_written
% REG_SIZE
== 0);
1457 assert(msg_data
.type
== BRW_REGISTER_TYPE_UD
);
1459 brw_pixel_interpolator_query(p
,
1460 retype(dst
, BRW_REGISTER_TYPE_UW
),
1462 inst
->pi_noperspective
,
1466 inst
->size_written
/ REG_SIZE
);
1469 /* Sets vstride=1, width=4, hstride=0 of register src1 during
1470 * the ADD instruction.
1473 fs_generator::generate_set_sample_id(fs_inst
*inst
,
1475 struct brw_reg src0
,
1476 struct brw_reg src1
)
1478 assert(dst
.type
== BRW_REGISTER_TYPE_D
||
1479 dst
.type
== BRW_REGISTER_TYPE_UD
);
1480 assert(src0
.type
== BRW_REGISTER_TYPE_D
||
1481 src0
.type
== BRW_REGISTER_TYPE_UD
);
1483 struct brw_reg reg
= stride(src1
, 1, 4, 0);
1484 if (devinfo
->gen
>= 8 || inst
->exec_size
== 8) {
1485 brw_ADD(p
, dst
, src0
, reg
);
1486 } else if (inst
->exec_size
== 16) {
1487 brw_push_insn_state(p
);
1488 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1489 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1490 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), reg
);
1491 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1492 brw_ADD(p
, sechalf(dst
), sechalf(src0
), suboffset(reg
, 2));
1493 brw_pop_insn_state(p
);
1498 fs_generator::generate_pack_half_2x16_split(fs_inst
*inst
,
1503 assert(devinfo
->gen
>= 7);
1504 assert(dst
.type
== BRW_REGISTER_TYPE_UD
);
1505 assert(x
.type
== BRW_REGISTER_TYPE_F
);
1506 assert(y
.type
== BRW_REGISTER_TYPE_F
);
1508 /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16:
1510 * Because this instruction does not have a 16-bit floating-point type,
1511 * the destination data type must be Word (W).
1513 * The destination must be DWord-aligned and specify a horizontal stride
1514 * (HorzStride) of 2. The 16-bit result is stored in the lower word of
1515 * each destination channel and the upper word is not modified.
1517 struct brw_reg dst_w
= spread(retype(dst
, BRW_REGISTER_TYPE_W
), 2);
1519 /* Give each 32-bit channel of dst the form below, where "." means
1523 brw_F32TO16(p
, dst_w
, y
);
1528 brw_SHL(p
, dst
, dst
, brw_imm_ud(16u));
1530 /* And, finally the form of packHalf2x16's output:
1533 brw_F32TO16(p
, dst_w
, x
);
1537 fs_generator::generate_unpack_half_2x16_split(fs_inst
*inst
,
1541 assert(devinfo
->gen
>= 7);
1542 assert(dst
.type
== BRW_REGISTER_TYPE_F
);
1543 assert(src
.type
== BRW_REGISTER_TYPE_UD
);
1545 /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32:
1547 * Because this instruction does not have a 16-bit floating-point type,
1548 * the source data type must be Word (W). The destination type must be
1551 struct brw_reg src_w
= spread(retype(src
, BRW_REGISTER_TYPE_W
), 2);
1553 /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
1554 * For the Y case, we wish to access only the upper word; therefore
1555 * a 16-bit subregister offset is needed.
1557 assert(inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
||
1558 inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
);
1559 if (inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
)
1562 brw_F16TO32(p
, dst
, src_w
);
1566 fs_generator::generate_shader_time_add(fs_inst
*inst
,
1567 struct brw_reg payload
,
1568 struct brw_reg offset
,
1569 struct brw_reg value
)
1571 assert(devinfo
->gen
>= 7);
1572 brw_push_insn_state(p
);
1573 brw_set_default_mask_control(p
, true);
1575 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1576 struct brw_reg payload_offset
= retype(brw_vec1_grf(payload
.nr
, 0),
1578 struct brw_reg payload_value
= retype(brw_vec1_grf(payload
.nr
+ 1, 0),
1581 assert(offset
.file
== BRW_IMMEDIATE_VALUE
);
1582 if (value
.file
== BRW_GENERAL_REGISTER_FILE
) {
1583 value
.width
= BRW_WIDTH_1
;
1584 value
.hstride
= BRW_HORIZONTAL_STRIDE_0
;
1585 value
.vstride
= BRW_VERTICAL_STRIDE_0
;
1587 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1590 /* Trying to deal with setup of the params from the IR is crazy in the FS8
1591 * case, and we don't really care about squeezing every bit of performance
1592 * out of this path, so we just emit the MOVs from here.
1594 brw_MOV(p
, payload_offset
, offset
);
1595 brw_MOV(p
, payload_value
, value
);
1596 brw_shader_time_add(p
, payload
,
1597 prog_data
->binding_table
.shader_time_start
);
1598 brw_pop_insn_state(p
);
1600 brw_mark_surface_used(prog_data
,
1601 prog_data
->binding_table
.shader_time_start
);
1605 fs_generator::enable_debug(const char *shader_name
)
1608 this->shader_name
= shader_name
;
1612 fs_generator::generate_code(const cfg_t
*cfg
, int dispatch_width
)
1614 /* align to 64 byte boundary. */
1615 while (p
->next_insn_offset
% 64)
1618 this->dispatch_width
= dispatch_width
;
1620 int start_offset
= p
->next_insn_offset
;
1621 int spill_count
= 0, fill_count
= 0;
1624 struct annotation_info annotation
;
1625 memset(&annotation
, 0, sizeof(annotation
));
1627 foreach_block_and_inst (block
, fs_inst
, inst
, cfg
) {
1628 struct brw_reg src
[3], dst
;
1629 unsigned int last_insn_offset
= p
->next_insn_offset
;
1630 bool multiple_instructions_emitted
= false;
1632 /* From the Broadwell PRM, Volume 7, "3D-Media-GPGPU", in the
1633 * "Register Region Restrictions" section: for BDW, SKL:
1635 * "A POW/FDIV operation must not be followed by an instruction
1636 * that requires two destination registers."
1638 * The documentation is often lacking annotations for Atom parts,
1639 * and empirically this affects CHV as well.
1641 if (devinfo
->gen
>= 8 &&
1643 brw_inst_opcode(devinfo
, brw_last_inst
) == BRW_OPCODE_MATH
&&
1644 brw_inst_math_function(devinfo
, brw_last_inst
) == BRW_MATH_FUNCTION_POW
&&
1645 inst
->dst
.component_size(inst
->exec_size
) > REG_SIZE
) {
1647 last_insn_offset
= p
->next_insn_offset
;
1650 if (unlikely(debug_flag
))
1651 annotate(p
->devinfo
, &annotation
, cfg
, inst
, p
->next_insn_offset
);
1653 /* If the instruction writes to more than one register, it needs to be
1654 * explicitly marked as compressed on Gen <= 5. On Gen >= 6 the
1655 * hardware figures out by itself what the right compression mode is,
1656 * but we still need to know whether the instruction is compressed to
1657 * set up the source register regions appropriately.
1659 * XXX - This is wrong for instructions that write a single register but
1660 * read more than one which should strictly speaking be treated as
1661 * compressed. For instructions that don't write any registers it
1662 * relies on the destination being a null register of the correct
1663 * type and regioning so the instruction is considered compressed
1664 * or not accordingly.
1666 const bool compressed
=
1667 inst
->dst
.component_size(inst
->exec_size
) > REG_SIZE
;
1668 brw_set_default_compression(p
, compressed
);
1669 brw_set_default_group(p
, inst
->group
);
1671 for (unsigned int i
= 0; i
< inst
->sources
; i
++) {
1672 src
[i
] = brw_reg_from_fs_reg(devinfo
, inst
,
1673 &inst
->src
[i
], compressed
);
1674 /* The accumulator result appears to get used for the
1675 * conditional modifier generation. When negating a UD
1676 * value, there is a 33rd bit generated for the sign in the
1677 * accumulator value, so now you can't check, for example,
1678 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
1680 assert(!inst
->conditional_mod
||
1681 inst
->src
[i
].type
!= BRW_REGISTER_TYPE_UD
||
1682 !inst
->src
[i
].negate
);
1684 dst
= brw_reg_from_fs_reg(devinfo
, inst
,
1685 &inst
->dst
, compressed
);
1687 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1688 brw_set_default_predicate_control(p
, inst
->predicate
);
1689 brw_set_default_predicate_inverse(p
, inst
->predicate_inverse
);
1690 brw_set_default_flag_reg(p
, 0, inst
->flag_subreg
);
1691 brw_set_default_saturate(p
, inst
->saturate
);
1692 brw_set_default_mask_control(p
, inst
->force_writemask_all
);
1693 brw_set_default_acc_write_control(p
, inst
->writes_accumulator
);
1695 unsigned exec_size
= inst
->exec_size
;
1696 if (devinfo
->gen
== 7 && !devinfo
->is_haswell
&&
1697 (get_exec_type_size(inst
) == 8 || type_sz(inst
->dst
.type
) == 8)) {
1701 brw_set_default_exec_size(p
, cvt(exec_size
) - 1);
1703 assert(inst
->force_writemask_all
|| inst
->exec_size
>= 4);
1704 assert(inst
->force_writemask_all
|| inst
->group
% inst
->exec_size
== 0);
1705 assert(inst
->base_mrf
+ inst
->mlen
<= BRW_MAX_MRF(devinfo
->gen
));
1706 assert(inst
->mlen
<= BRW_MAX_MSG_LENGTH
);
1708 switch (inst
->opcode
) {
1709 case BRW_OPCODE_MOV
:
1710 brw_MOV(p
, dst
, src
[0]);
1712 case BRW_OPCODE_ADD
:
1713 brw_ADD(p
, dst
, src
[0], src
[1]);
1715 case BRW_OPCODE_MUL
:
1716 brw_MUL(p
, dst
, src
[0], src
[1]);
1718 case BRW_OPCODE_AVG
:
1719 brw_AVG(p
, dst
, src
[0], src
[1]);
1721 case BRW_OPCODE_MACH
:
1722 brw_MACH(p
, dst
, src
[0], src
[1]);
1725 case BRW_OPCODE_LINE
:
1726 brw_LINE(p
, dst
, src
[0], src
[1]);
1729 case BRW_OPCODE_MAD
:
1730 assert(devinfo
->gen
>= 6);
1731 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1732 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
1735 case BRW_OPCODE_LRP
:
1736 assert(devinfo
->gen
>= 6);
1737 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1738 brw_LRP(p
, dst
, src
[0], src
[1], src
[2]);
1741 case BRW_OPCODE_FRC
:
1742 brw_FRC(p
, dst
, src
[0]);
1744 case BRW_OPCODE_RNDD
:
1745 brw_RNDD(p
, dst
, src
[0]);
1747 case BRW_OPCODE_RNDE
:
1748 brw_RNDE(p
, dst
, src
[0]);
1750 case BRW_OPCODE_RNDZ
:
1751 brw_RNDZ(p
, dst
, src
[0]);
1754 case BRW_OPCODE_AND
:
1755 brw_AND(p
, dst
, src
[0], src
[1]);
1758 brw_OR(p
, dst
, src
[0], src
[1]);
1760 case BRW_OPCODE_XOR
:
1761 brw_XOR(p
, dst
, src
[0], src
[1]);
1763 case BRW_OPCODE_NOT
:
1764 brw_NOT(p
, dst
, src
[0]);
1766 case BRW_OPCODE_ASR
:
1767 brw_ASR(p
, dst
, src
[0], src
[1]);
1769 case BRW_OPCODE_SHR
:
1770 brw_SHR(p
, dst
, src
[0], src
[1]);
1772 case BRW_OPCODE_SHL
:
1773 brw_SHL(p
, dst
, src
[0], src
[1]);
1775 case BRW_OPCODE_F32TO16
:
1776 assert(devinfo
->gen
>= 7);
1777 brw_F32TO16(p
, dst
, src
[0]);
1779 case BRW_OPCODE_F16TO32
:
1780 assert(devinfo
->gen
>= 7);
1781 brw_F16TO32(p
, dst
, src
[0]);
1783 case BRW_OPCODE_CMP
:
1784 if (inst
->exec_size
>= 16 && devinfo
->gen
== 7 && !devinfo
->is_haswell
&&
1785 dst
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1786 /* For unknown reasons the WaCMPInstFlagDepClearedEarly workaround
1787 * implemented in the compiler is not sufficient. Overriding the
1788 * type when the destination is the null register is necessary but
1789 * not sufficient by itself.
1791 assert(dst
.nr
== BRW_ARF_NULL
);
1792 dst
.type
= BRW_REGISTER_TYPE_D
;
1794 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1796 case BRW_OPCODE_SEL
:
1797 brw_SEL(p
, dst
, src
[0], src
[1]);
1799 case BRW_OPCODE_BFREV
:
1800 assert(devinfo
->gen
>= 7);
1801 brw_BFREV(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1802 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1804 case BRW_OPCODE_FBH
:
1805 assert(devinfo
->gen
>= 7);
1806 brw_FBH(p
, retype(dst
, src
[0].type
), src
[0]);
1808 case BRW_OPCODE_FBL
:
1809 assert(devinfo
->gen
>= 7);
1810 brw_FBL(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1811 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1813 case BRW_OPCODE_LZD
:
1814 brw_LZD(p
, dst
, src
[0]);
1816 case BRW_OPCODE_CBIT
:
1817 assert(devinfo
->gen
>= 7);
1818 brw_CBIT(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1819 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1821 case BRW_OPCODE_ADDC
:
1822 assert(devinfo
->gen
>= 7);
1823 brw_ADDC(p
, dst
, src
[0], src
[1]);
1825 case BRW_OPCODE_SUBB
:
1826 assert(devinfo
->gen
>= 7);
1827 brw_SUBB(p
, dst
, src
[0], src
[1]);
1829 case BRW_OPCODE_MAC
:
1830 brw_MAC(p
, dst
, src
[0], src
[1]);
1833 case BRW_OPCODE_BFE
:
1834 assert(devinfo
->gen
>= 7);
1835 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1836 brw_BFE(p
, dst
, src
[0], src
[1], src
[2]);
1839 case BRW_OPCODE_BFI1
:
1840 assert(devinfo
->gen
>= 7);
1841 brw_BFI1(p
, dst
, src
[0], src
[1]);
1843 case BRW_OPCODE_BFI2
:
1844 assert(devinfo
->gen
>= 7);
1845 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1846 brw_BFI2(p
, dst
, src
[0], src
[1], src
[2]);
1850 if (inst
->src
[0].file
!= BAD_FILE
) {
1851 /* The instruction has an embedded compare (only allowed on gen6) */
1852 assert(devinfo
->gen
== 6);
1853 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
1855 brw_IF(p
, brw_inst_exec_size(devinfo
, p
->current
));
1859 case BRW_OPCODE_ELSE
:
1862 case BRW_OPCODE_ENDIF
:
1867 brw_DO(p
, brw_inst_exec_size(devinfo
, p
->current
));
1870 case BRW_OPCODE_BREAK
:
1873 case BRW_OPCODE_CONTINUE
:
1877 case BRW_OPCODE_WHILE
:
1882 case SHADER_OPCODE_RCP
:
1883 case SHADER_OPCODE_RSQ
:
1884 case SHADER_OPCODE_SQRT
:
1885 case SHADER_OPCODE_EXP2
:
1886 case SHADER_OPCODE_LOG2
:
1887 case SHADER_OPCODE_SIN
:
1888 case SHADER_OPCODE_COS
:
1889 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1890 if (devinfo
->gen
>= 6) {
1891 assert(inst
->mlen
== 0);
1892 assert(devinfo
->gen
>= 7 || inst
->exec_size
== 8);
1893 gen6_math(p
, dst
, brw_math_function(inst
->opcode
),
1894 src
[0], brw_null_reg());
1896 assert(inst
->mlen
>= 1);
1897 assert(devinfo
->gen
== 5 || devinfo
->is_g4x
|| inst
->exec_size
== 8);
1899 brw_math_function(inst
->opcode
),
1900 inst
->base_mrf
, src
[0],
1901 BRW_MATH_PRECISION_FULL
);
1904 case SHADER_OPCODE_INT_QUOTIENT
:
1905 case SHADER_OPCODE_INT_REMAINDER
:
1906 case SHADER_OPCODE_POW
:
1907 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1908 if (devinfo
->gen
>= 6) {
1909 assert(inst
->mlen
== 0);
1910 assert((devinfo
->gen
>= 7 && inst
->opcode
== SHADER_OPCODE_POW
) ||
1911 inst
->exec_size
== 8);
1912 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0], src
[1]);
1914 assert(inst
->mlen
>= 1);
1915 assert(inst
->exec_size
== 8);
1916 gen4_math(p
, dst
, brw_math_function(inst
->opcode
),
1917 inst
->base_mrf
, src
[0],
1918 BRW_MATH_PRECISION_FULL
);
1921 case FS_OPCODE_CINTERP
:
1922 brw_MOV(p
, dst
, src
[0]);
1924 case FS_OPCODE_LINTERP
:
1925 generate_linterp(inst
, dst
, src
);
1927 case FS_OPCODE_PIXEL_X
:
1928 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1929 src
[0].subnr
= 0 * type_sz(src
[0].type
);
1930 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1932 case FS_OPCODE_PIXEL_Y
:
1933 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1934 src
[0].subnr
= 4 * type_sz(src
[0].type
);
1935 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1937 case FS_OPCODE_GET_BUFFER_SIZE
:
1938 generate_get_buffer_size(inst
, dst
, src
[0], src
[1]);
1940 case SHADER_OPCODE_TEX
:
1942 case SHADER_OPCODE_TXD
:
1943 case SHADER_OPCODE_TXF
:
1944 case SHADER_OPCODE_TXF_LZ
:
1945 case SHADER_OPCODE_TXF_CMS
:
1946 case SHADER_OPCODE_TXF_CMS_W
:
1947 case SHADER_OPCODE_TXF_UMS
:
1948 case SHADER_OPCODE_TXF_MCS
:
1949 case SHADER_OPCODE_TXL
:
1950 case SHADER_OPCODE_TXL_LZ
:
1951 case SHADER_OPCODE_TXS
:
1952 case SHADER_OPCODE_LOD
:
1953 case SHADER_OPCODE_TG4
:
1954 case SHADER_OPCODE_TG4_OFFSET
:
1955 case SHADER_OPCODE_SAMPLEINFO
:
1956 generate_tex(inst
, dst
, src
[0], src
[1], src
[2]);
1958 case FS_OPCODE_DDX_COARSE
:
1959 case FS_OPCODE_DDX_FINE
:
1960 generate_ddx(inst
->opcode
, dst
, src
[0]);
1962 case FS_OPCODE_DDY_COARSE
:
1963 case FS_OPCODE_DDY_FINE
:
1964 generate_ddy(inst
->opcode
, dst
, src
[0]);
1967 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
1968 generate_scratch_write(inst
, src
[0]);
1972 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
1973 generate_scratch_read(inst
, dst
);
1977 case SHADER_OPCODE_GEN7_SCRATCH_READ
:
1978 generate_scratch_read_gen7(inst
, dst
);
1982 case SHADER_OPCODE_MOV_INDIRECT
:
1983 generate_mov_indirect(inst
, dst
, src
[0], src
[1]);
1986 case SHADER_OPCODE_URB_READ_SIMD8
:
1987 case SHADER_OPCODE_URB_READ_SIMD8_PER_SLOT
:
1988 generate_urb_read(inst
, dst
, src
[0]);
1991 case SHADER_OPCODE_URB_WRITE_SIMD8
:
1992 case SHADER_OPCODE_URB_WRITE_SIMD8_PER_SLOT
:
1993 case SHADER_OPCODE_URB_WRITE_SIMD8_MASKED
:
1994 case SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT
:
1995 generate_urb_write(inst
, src
[0]);
1998 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
:
1999 assert(inst
->force_writemask_all
);
2000 generate_uniform_pull_constant_load(inst
, dst
, src
[0], src
[1]);
2003 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7
:
2004 assert(inst
->force_writemask_all
);
2005 generate_uniform_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
2008 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN4
:
2009 generate_varying_pull_constant_load_gen4(inst
, dst
, src
[0]);
2012 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
:
2013 generate_varying_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
2016 case FS_OPCODE_REP_FB_WRITE
:
2017 case FS_OPCODE_FB_WRITE
:
2018 generate_fb_write(inst
, src
[0]);
2021 case FS_OPCODE_FB_READ
:
2022 generate_fb_read(inst
, dst
, src
[0]);
2025 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS
:
2026 generate_mov_dispatch_to_flags(inst
);
2029 case FS_OPCODE_DISCARD_JUMP
:
2030 generate_discard_jump(inst
);
2033 case SHADER_OPCODE_SHADER_TIME_ADD
:
2034 generate_shader_time_add(inst
, src
[0], src
[1], src
[2]);
2037 case SHADER_OPCODE_UNTYPED_ATOMIC
:
2038 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2039 brw_untyped_atomic(p
, dst
, src
[0], src
[1], src
[2].ud
,
2040 inst
->mlen
, !inst
->dst
.is_null());
2043 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
2044 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2045 brw_untyped_surface_read(p
, dst
, src
[0], src
[1],
2046 inst
->mlen
, src
[2].ud
);
2049 case SHADER_OPCODE_UNTYPED_SURFACE_WRITE
:
2050 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2051 brw_untyped_surface_write(p
, src
[0], src
[1],
2052 inst
->mlen
, src
[2].ud
);
2055 case SHADER_OPCODE_TYPED_ATOMIC
:
2056 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2057 brw_typed_atomic(p
, dst
, src
[0], src
[1],
2058 src
[2].ud
, inst
->mlen
, !inst
->dst
.is_null());
2061 case SHADER_OPCODE_TYPED_SURFACE_READ
:
2062 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2063 brw_typed_surface_read(p
, dst
, src
[0], src
[1],
2064 inst
->mlen
, src
[2].ud
);
2067 case SHADER_OPCODE_TYPED_SURFACE_WRITE
:
2068 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
2069 brw_typed_surface_write(p
, src
[0], src
[1], inst
->mlen
, src
[2].ud
);
2072 case SHADER_OPCODE_MEMORY_FENCE
:
2073 brw_memory_fence(p
, dst
);
2076 case SHADER_OPCODE_FIND_LIVE_CHANNEL
: {
2077 const struct brw_reg mask
=
2078 brw_stage_has_packed_dispatch(devinfo
, stage
,
2079 prog_data
) ? brw_imm_ud(~0u) :
2080 stage
== MESA_SHADER_FRAGMENT
? brw_vmask_reg() :
2082 brw_find_live_channel(p
, dst
, mask
);
2086 case SHADER_OPCODE_BROADCAST
:
2087 assert(inst
->force_writemask_all
);
2088 brw_broadcast(p
, dst
, src
[0], src
[1]);
2091 case FS_OPCODE_SET_SAMPLE_ID
:
2092 generate_set_sample_id(inst
, dst
, src
[0], src
[1]);
2095 case FS_OPCODE_PACK_HALF_2x16_SPLIT
:
2096 generate_pack_half_2x16_split(inst
, dst
, src
[0], src
[1]);
2099 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
:
2100 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
:
2101 generate_unpack_half_2x16_split(inst
, dst
, src
[0]);
2104 case FS_OPCODE_PLACEHOLDER_HALT
:
2105 /* This is the place where the final HALT needs to be inserted if
2106 * we've emitted any discards. If not, this will emit no code.
2108 if (!patch_discard_jumps_to_fb_writes()) {
2109 if (unlikely(debug_flag
)) {
2110 annotation
.ann_count
--;
2115 case FS_OPCODE_INTERPOLATE_AT_SAMPLE
:
2116 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2117 GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE
);
2120 case FS_OPCODE_INTERPOLATE_AT_SHARED_OFFSET
:
2121 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2122 GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET
);
2125 case FS_OPCODE_INTERPOLATE_AT_PER_SLOT_OFFSET
:
2126 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2127 GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET
);
2130 case CS_OPCODE_CS_TERMINATE
:
2131 generate_cs_terminate(inst
, src
[0]);
2134 case SHADER_OPCODE_BARRIER
:
2135 generate_barrier(inst
, src
[0]);
2138 case BRW_OPCODE_DIM
:
2139 assert(devinfo
->is_haswell
);
2140 assert(src
[0].type
== BRW_REGISTER_TYPE_DF
);
2141 assert(dst
.type
== BRW_REGISTER_TYPE_DF
);
2142 brw_DIM(p
, dst
, retype(src
[0], BRW_REGISTER_TYPE_F
));
2146 unreachable("Unsupported opcode");
2148 case SHADER_OPCODE_LOAD_PAYLOAD
:
2149 unreachable("Should be lowered by lower_load_payload()");
2152 if (multiple_instructions_emitted
)
2155 if (inst
->no_dd_clear
|| inst
->no_dd_check
|| inst
->conditional_mod
) {
2156 assert(p
->next_insn_offset
== last_insn_offset
+ 16 ||
2157 !"conditional_mod, no_dd_check, or no_dd_clear set for IR "
2158 "emitting more than 1 instruction");
2160 brw_inst
*last
= &p
->store
[last_insn_offset
/ 16];
2162 if (inst
->conditional_mod
)
2163 brw_inst_set_cond_modifier(p
->devinfo
, last
, inst
->conditional_mod
);
2164 brw_inst_set_no_dd_clear(p
->devinfo
, last
, inst
->no_dd_clear
);
2165 brw_inst_set_no_dd_check(p
->devinfo
, last
, inst
->no_dd_check
);
2169 brw_set_uip_jip(p
, start_offset
);
2170 annotation_finalize(&annotation
, p
->next_insn_offset
);
2173 bool validated
= brw_validate_instructions(devinfo
, p
->store
,
2175 p
->next_insn_offset
,
2178 if (unlikely(debug_flag
))
2179 brw_validate_instructions(devinfo
, p
->store
,
2181 p
->next_insn_offset
,
2185 int before_size
= p
->next_insn_offset
- start_offset
;
2186 brw_compact_instructions(p
, start_offset
, annotation
.ann_count
,
2188 int after_size
= p
->next_insn_offset
- start_offset
;
2190 if (unlikely(debug_flag
)) {
2191 fprintf(stderr
, "Native code for %s\n"
2192 "SIMD%d shader: %d instructions. %d loops. %u cycles. %d:%d spills:fills. Promoted %u constants. Compacted %d to %d"
2193 " bytes (%.0f%%)\n",
2194 shader_name
, dispatch_width
, before_size
/ 16, loop_count
, cfg
->cycle_count
,
2195 spill_count
, fill_count
, promoted_constants
, before_size
, after_size
,
2196 100.0f
* (before_size
- after_size
) / before_size
);
2198 dump_assembly(p
->store
, annotation
.ann_count
, annotation
.ann
,
2200 ralloc_free(annotation
.mem_ctx
);
2204 compiler
->shader_debug_log(log_data
,
2205 "%s SIMD%d shader: %d inst, %d loops, %u cycles, "
2206 "%d:%d spills:fills, Promoted %u constants, "
2207 "compacted %d to %d bytes.",
2208 _mesa_shader_stage_to_abbrev(stage
),
2209 dispatch_width
, before_size
/ 16,
2210 loop_count
, cfg
->cycle_count
, spill_count
,
2211 fill_count
, promoted_constants
, before_size
,
2214 return start_offset
;
2218 fs_generator::get_assembly(unsigned int *assembly_size
)
2220 return brw_get_program(p
, assembly_size
);