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(fs_inst
*inst
, fs_reg
*reg
, unsigned gen
, bool compressed
)
58 struct brw_reg brw_reg
;
62 assert((reg
->nr
& ~BRW_MRF_COMPR4
) < BRW_MAX_MRF(gen
));
65 if (reg
->stride
== 0) {
66 brw_reg
= brw_vec1_reg(brw_file_from_reg(reg
), reg
->nr
, 0);
68 /* From the Haswell PRM:
70 * "VertStride must be used to cross GRF register boundaries. This
71 * rule implies that elements within a 'Width' cannot cross GRF
74 * The maximum width value that could satisfy this restriction is:
76 const unsigned reg_width
= REG_SIZE
/ (reg
->stride
* type_sz(reg
->type
));
78 /* Because the hardware can only split source regions at a whole
79 * multiple of width during decompression (i.e. vertically), clamp
80 * the value obtained above to the physical execution size of a
81 * single decompressed chunk of the instruction:
83 const unsigned phys_width
= compressed
? inst
->exec_size
/ 2 :
86 /* XXX - The equation above is strictly speaking not correct on
87 * hardware that supports unbalanced GRF writes -- On Gen9+
88 * each decompressed chunk of the instruction may have a
89 * different execution size when the number of components
90 * written to each destination GRF is not the same.
92 const unsigned width
= MIN2(reg_width
, phys_width
);
93 brw_reg
= brw_vecn_reg(width
, brw_file_from_reg(reg
), reg
->nr
, 0);
94 brw_reg
= stride(brw_reg
, width
* reg
->stride
, width
, reg
->stride
);
97 brw_reg
= retype(brw_reg
, reg
->type
);
98 brw_reg
= byte_offset(brw_reg
, reg
->offset
);
99 brw_reg
.abs
= reg
->abs
;
100 brw_reg
.negate
= reg
->negate
;
105 assert(reg
->offset
== 0);
106 brw_reg
= reg
->as_brw_reg();
109 /* Probably unused. */
110 brw_reg
= brw_null_reg();
114 unreachable("not reached");
120 fs_generator::fs_generator(const struct brw_compiler
*compiler
, void *log_data
,
123 struct brw_stage_prog_data
*prog_data
,
124 unsigned promoted_constants
,
125 bool runtime_check_aads_emit
,
126 gl_shader_stage stage
)
128 : compiler(compiler
), log_data(log_data
),
129 devinfo(compiler
->devinfo
), key(key
),
130 prog_data(prog_data
),
131 promoted_constants(promoted_constants
),
132 runtime_check_aads_emit(runtime_check_aads_emit
), debug_flag(false),
133 stage(stage
), mem_ctx(mem_ctx
)
135 p
= rzalloc(mem_ctx
, struct brw_codegen
);
136 brw_init_codegen(devinfo
, p
, mem_ctx
);
139 fs_generator::~fs_generator()
143 class ip_record
: public exec_node
{
145 DECLARE_RALLOC_CXX_OPERATORS(ip_record
)
156 fs_generator::patch_discard_jumps_to_fb_writes()
158 if (devinfo
->gen
< 6 || this->discard_halt_patches
.is_empty())
161 int scale
= brw_jump_scale(p
->devinfo
);
163 /* There is a somewhat strange undocumented requirement of using
164 * HALT, according to the simulator. If some channel has HALTed to
165 * a particular UIP, then by the end of the program, every channel
166 * must have HALTed to that UIP. Furthermore, the tracking is a
167 * stack, so you can't do the final halt of a UIP after starting
168 * halting to a new UIP.
170 * Symptoms of not emitting this instruction on actual hardware
171 * included GPU hangs and sparkly rendering on the piglit discard
174 brw_inst
*last_halt
= gen6_HALT(p
);
175 brw_inst_set_uip(p
->devinfo
, last_halt
, 1 * scale
);
176 brw_inst_set_jip(p
->devinfo
, last_halt
, 1 * scale
);
180 foreach_in_list(ip_record
, patch_ip
, &discard_halt_patches
) {
181 brw_inst
*patch
= &p
->store
[patch_ip
->ip
];
183 assert(brw_inst_opcode(p
->devinfo
, patch
) == BRW_OPCODE_HALT
);
184 /* HALT takes a half-instruction distance from the pre-incremented IP. */
185 brw_inst_set_uip(p
->devinfo
, patch
, (ip
- patch_ip
->ip
) * scale
);
188 this->discard_halt_patches
.make_empty();
193 fs_generator::fire_fb_write(fs_inst
*inst
,
194 struct brw_reg payload
,
195 struct brw_reg implied_header
,
198 uint32_t msg_control
;
200 struct brw_wm_prog_data
*prog_data
= brw_wm_prog_data(this->prog_data
);
202 if (devinfo
->gen
< 6) {
203 brw_push_insn_state(p
);
204 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
205 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
206 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
207 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
208 brw_MOV(p
, offset(payload
, 1), brw_vec8_grf(1, 0));
209 brw_pop_insn_state(p
);
212 if (inst
->opcode
== FS_OPCODE_REP_FB_WRITE
)
213 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED
;
214 else if (prog_data
->dual_src_blend
) {
216 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01
;
218 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23
;
219 } else if (inst
->exec_size
== 16)
220 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE
;
222 msg_control
= BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01
;
224 uint32_t surf_index
=
225 prog_data
->binding_table
.render_target_start
+ inst
->target
;
227 bool last_render_target
= inst
->eot
||
228 (prog_data
->dual_src_blend
&& dispatch_width
== 16);
240 inst
->header_size
!= 0);
242 brw_mark_surface_used(&prog_data
->base
, surf_index
);
246 fs_generator::generate_fb_write(fs_inst
*inst
, struct brw_reg payload
)
248 struct brw_wm_prog_data
*prog_data
= brw_wm_prog_data(this->prog_data
);
249 const brw_wm_prog_key
* const key
= (brw_wm_prog_key
* const) this->key
;
250 struct brw_reg implied_header
;
252 if (devinfo
->gen
< 8 && !devinfo
->is_haswell
) {
253 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
256 if (inst
->base_mrf
>= 0)
257 payload
= brw_message_reg(inst
->base_mrf
);
259 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
262 if (inst
->header_size
!= 0) {
263 brw_push_insn_state(p
);
264 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
265 brw_set_default_predicate_control(p
, BRW_PREDICATE_NONE
);
266 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
267 brw_set_default_flag_reg(p
, 0, 0);
269 /* On HSW, the GPU will use the predicate on SENDC, unless the header is
272 if (prog_data
->uses_kill
) {
273 struct brw_reg pixel_mask
;
275 if (devinfo
->gen
>= 6)
276 pixel_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
278 pixel_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
280 brw_MOV(p
, pixel_mask
, brw_flag_reg(0, 1));
283 if (devinfo
->gen
>= 6) {
284 brw_push_insn_state(p
);
285 brw_set_default_exec_size(p
, BRW_EXECUTE_16
);
286 brw_set_default_compression_control(p
, BRW_COMPRESSION_COMPRESSED
);
288 retype(payload
, BRW_REGISTER_TYPE_UD
),
289 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
));
290 brw_pop_insn_state(p
);
292 if (inst
->target
> 0 && key
->replicate_alpha
) {
293 /* Set "Source0 Alpha Present to RenderTarget" bit in message
297 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
298 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
299 brw_imm_ud(0x1 << 11));
302 if (inst
->target
> 0) {
303 /* Set the render target index for choosing BLEND_STATE. */
304 brw_MOV(p
, retype(vec1(suboffset(payload
, 2)),
305 BRW_REGISTER_TYPE_UD
),
306 brw_imm_ud(inst
->target
));
309 /* Set computes stencil to render target */
310 if (prog_data
->computed_stencil
) {
312 vec1(retype(payload
, BRW_REGISTER_TYPE_UD
)),
313 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD
)),
314 brw_imm_ud(0x1 << 14));
317 implied_header
= brw_null_reg();
319 implied_header
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
322 brw_pop_insn_state(p
);
324 implied_header
= brw_null_reg();
327 if (!runtime_check_aads_emit
) {
328 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
330 /* This can only happen in gen < 6 */
331 assert(devinfo
->gen
< 6);
333 struct brw_reg v1_null_ud
= vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD
));
335 /* Check runtime bit to detect if we have to send AA data or not */
336 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
339 retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD
),
341 brw_inst_set_cond_modifier(p
->devinfo
, brw_last_inst
, BRW_CONDITIONAL_NZ
);
343 int jmp
= brw_JMPI(p
, brw_imm_ud(0), BRW_PREDICATE_NORMAL
) - p
->store
;
344 brw_inst_set_exec_size(p
->devinfo
, brw_last_inst
, BRW_EXECUTE_1
);
346 /* Don't send AA data */
347 fire_fb_write(inst
, offset(payload
, 1), implied_header
, inst
->mlen
-1);
349 brw_land_fwd_jump(p
, jmp
);
350 fire_fb_write(inst
, payload
, implied_header
, inst
->mlen
);
355 fs_generator::generate_fb_read(fs_inst
*inst
, struct brw_reg dst
,
356 struct brw_reg payload
)
358 assert(inst
->size_written
% REG_SIZE
== 0);
359 struct brw_wm_prog_data
*prog_data
= brw_wm_prog_data(this->prog_data
);
360 const unsigned surf_index
=
361 prog_data
->binding_table
.render_target_start
+ inst
->target
;
363 gen9_fb_READ(p
, dst
, payload
, surf_index
,
364 inst
->header_size
, inst
->size_written
/ REG_SIZE
,
365 prog_data
->persample_dispatch
);
367 brw_mark_surface_used(&prog_data
->base
, surf_index
);
371 fs_generator::generate_mov_indirect(fs_inst
*inst
,
374 struct brw_reg indirect_byte_offset
)
376 assert(indirect_byte_offset
.type
== BRW_REGISTER_TYPE_UD
);
377 assert(indirect_byte_offset
.file
== BRW_GENERAL_REGISTER_FILE
);
379 unsigned imm_byte_offset
= reg
.nr
* REG_SIZE
+ reg
.subnr
;
381 if (indirect_byte_offset
.file
== BRW_IMMEDIATE_VALUE
) {
382 imm_byte_offset
+= indirect_byte_offset
.ud
;
384 reg
.nr
= imm_byte_offset
/ REG_SIZE
;
385 reg
.subnr
= imm_byte_offset
% REG_SIZE
;
386 brw_MOV(p
, dst
, reg
);
388 /* Prior to Broadwell, there are only 8 address registers. */
389 assert(inst
->exec_size
== 8 || devinfo
->gen
>= 8);
391 /* We use VxH indirect addressing, clobbering a0.0 through a0.7. */
392 struct brw_reg addr
= vec8(brw_address_reg(0));
394 /* The destination stride of an instruction (in bytes) must be greater
395 * than or equal to the size of the rest of the instruction. Since the
396 * address register is of type UW, we can't use a D-type instruction.
397 * In order to get around this, re retype to UW and use a stride.
399 indirect_byte_offset
=
400 retype(spread(indirect_byte_offset
, 2), BRW_REGISTER_TYPE_UW
);
402 /* There are a number of reasons why we don't use the base offset here.
403 * One reason is that the field is only 9 bits which means we can only
404 * use it to access the first 16 GRFs. Also, from the Haswell PRM
405 * section "Register Region Restrictions":
407 * "The lower bits of the AddressImmediate must not overflow to
408 * change the register address. The lower 5 bits of Address
409 * Immediate when added to lower 5 bits of address register gives
410 * the sub-register offset. The upper bits of Address Immediate
411 * when added to upper bits of address register gives the register
412 * address. Any overflow from sub-register offset is dropped."
414 * Since the indirect may cause us to cross a register boundary, this
415 * makes the base offset almost useless. We could try and do something
416 * clever where we use a actual base offset if base_offset % 32 == 0 but
417 * that would mean we were generating different code depending on the
418 * base offset. Instead, for the sake of consistency, we'll just do the
419 * add ourselves. This restriction is only listed in the Haswell PRM
420 * but empirical testing indicates that it applies on all older
421 * generations and is lifted on Broadwell.
423 * In the end, while base_offset is nice to look at in the generated
424 * code, using it saves us 0 instructions and would require quite a bit
425 * of case-by-case work. It's just not worth it.
427 brw_ADD(p
, addr
, indirect_byte_offset
, brw_imm_uw(imm_byte_offset
));
428 struct brw_reg ind_src
= brw_VxH_indirect(0, 0);
430 brw_inst
*mov
= brw_MOV(p
, dst
, retype(ind_src
, reg
.type
));
432 if (devinfo
->gen
== 6 && dst
.file
== BRW_MESSAGE_REGISTER_FILE
&&
433 !inst
->get_next()->is_tail_sentinel() &&
434 ((fs_inst
*)inst
->get_next())->mlen
> 0) {
435 /* From the Sandybridge PRM:
437 * "[Errata: DevSNB(SNB)] If MRF register is updated by any
438 * instruction that “indexed/indirect” source AND is followed by a
439 * send, the instruction requires a “Switch”. This is to avoid
440 * race condition where send may dispatch before MRF is updated."
442 brw_inst_set_thread_control(devinfo
, mov
, BRW_THREAD_SWITCH
);
448 fs_generator::generate_urb_read(fs_inst
*inst
,
450 struct brw_reg header
)
452 assert(inst
->size_written
% REG_SIZE
== 0);
453 assert(header
.file
== BRW_GENERAL_REGISTER_FILE
);
454 assert(header
.type
== BRW_REGISTER_TYPE_UD
);
456 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
457 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UD
));
458 brw_set_src0(p
, send
, header
);
459 brw_set_src1(p
, send
, brw_imm_ud(0u));
461 brw_inst_set_sfid(p
->devinfo
, send
, BRW_SFID_URB
);
462 brw_inst_set_urb_opcode(p
->devinfo
, send
, GEN8_URB_OPCODE_SIMD8_READ
);
464 if (inst
->opcode
== SHADER_OPCODE_URB_READ_SIMD8_PER_SLOT
)
465 brw_inst_set_urb_per_slot_offset(p
->devinfo
, send
, true);
467 brw_inst_set_mlen(p
->devinfo
, send
, inst
->mlen
);
468 brw_inst_set_rlen(p
->devinfo
, send
, inst
->size_written
/ REG_SIZE
);
469 brw_inst_set_header_present(p
->devinfo
, send
, true);
470 brw_inst_set_urb_global_offset(p
->devinfo
, send
, inst
->offset
);
474 fs_generator::generate_urb_write(fs_inst
*inst
, struct brw_reg payload
)
478 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
480 brw_set_dest(p
, insn
, brw_null_reg());
481 brw_set_src0(p
, insn
, payload
);
482 brw_set_src1(p
, insn
, brw_imm_d(0));
484 brw_inst_set_sfid(p
->devinfo
, insn
, BRW_SFID_URB
);
485 brw_inst_set_urb_opcode(p
->devinfo
, insn
, GEN8_URB_OPCODE_SIMD8_WRITE
);
487 if (inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_PER_SLOT
||
488 inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT
)
489 brw_inst_set_urb_per_slot_offset(p
->devinfo
, insn
, true);
491 if (inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_MASKED
||
492 inst
->opcode
== SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT
)
493 brw_inst_set_urb_channel_mask_present(p
->devinfo
, insn
, true);
495 brw_inst_set_mlen(p
->devinfo
, insn
, inst
->mlen
);
496 brw_inst_set_rlen(p
->devinfo
, insn
, 0);
497 brw_inst_set_eot(p
->devinfo
, insn
, inst
->eot
);
498 brw_inst_set_header_present(p
->devinfo
, insn
, true);
499 brw_inst_set_urb_global_offset(p
->devinfo
, insn
, inst
->offset
);
503 fs_generator::generate_cs_terminate(fs_inst
*inst
, struct brw_reg payload
)
505 struct brw_inst
*insn
;
507 insn
= brw_next_insn(p
, BRW_OPCODE_SEND
);
509 brw_set_dest(p
, insn
, retype(brw_null_reg(), BRW_REGISTER_TYPE_UW
));
510 brw_set_src0(p
, insn
, retype(payload
, BRW_REGISTER_TYPE_UW
));
511 brw_set_src1(p
, insn
, brw_imm_d(0));
513 /* Terminate a compute shader by sending a message to the thread spawner.
515 brw_inst_set_sfid(devinfo
, insn
, BRW_SFID_THREAD_SPAWNER
);
516 brw_inst_set_mlen(devinfo
, insn
, 1);
517 brw_inst_set_rlen(devinfo
, insn
, 0);
518 brw_inst_set_eot(devinfo
, insn
, inst
->eot
);
519 brw_inst_set_header_present(devinfo
, insn
, false);
521 brw_inst_set_ts_opcode(devinfo
, insn
, 0); /* Dereference resource */
522 brw_inst_set_ts_request_type(devinfo
, insn
, 0); /* Root thread */
524 /* Note that even though the thread has a URB resource associated with it,
525 * we set the "do not dereference URB" bit, because the URB resource is
526 * managed by the fixed-function unit, so it will free it automatically.
528 brw_inst_set_ts_resource_select(devinfo
, insn
, 1); /* Do not dereference URB */
530 brw_inst_set_mask_control(devinfo
, insn
, BRW_MASK_DISABLE
);
534 fs_generator::generate_barrier(fs_inst
*inst
, struct brw_reg src
)
541 fs_generator::generate_linterp(fs_inst
*inst
,
542 struct brw_reg dst
, struct brw_reg
*src
)
546 * -----------------------------------
547 * | src1+0 | src1+1 | src1+2 | src1+3 |
548 * |-----------------------------------|
549 * |(x0, x1)|(y0, y1)|(x2, x3)|(y2, y3)|
550 * -----------------------------------
552 * but for the LINE/MAC pair, the LINE reads Xs and the MAC reads Ys:
554 * -----------------------------------
555 * | src1+0 | src1+1 | src1+2 | src1+3 |
556 * |-----------------------------------|
557 * |(x0, x1)|(y0, y1)| | | in SIMD8
558 * |-----------------------------------|
559 * |(x0, x1)|(x2, x3)|(y0, y1)|(y2, y3)| in SIMD16
560 * -----------------------------------
562 * See also: emit_interpolation_setup_gen4().
564 struct brw_reg delta_x
= src
[0];
565 struct brw_reg delta_y
= offset(src
[0], inst
->exec_size
/ 8);
566 struct brw_reg interp
= src
[1];
568 if (devinfo
->has_pln
&&
569 (devinfo
->gen
>= 7 || (delta_x
.nr
& 1) == 0)) {
570 brw_PLN(p
, dst
, interp
, delta_x
);
572 brw_LINE(p
, brw_null_reg(), interp
, delta_x
);
573 brw_MAC(p
, dst
, suboffset(interp
, 1), delta_y
);
578 fs_generator::generate_get_buffer_size(fs_inst
*inst
,
581 struct brw_reg surf_index
)
583 assert(devinfo
->gen
>= 7);
584 assert(surf_index
.file
== BRW_IMMEDIATE_VALUE
);
589 switch (inst
->exec_size
) {
591 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
594 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
597 unreachable("Invalid width for texture instruction");
600 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
606 retype(dst
, BRW_REGISTER_TYPE_UW
),
611 GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
,
612 rlen
, /* response length */
614 inst
->header_size
> 0,
616 BRW_SAMPLER_RETURN_FORMAT_SINT32
);
618 brw_mark_surface_used(prog_data
, surf_index
.ud
);
622 fs_generator::generate_tex(fs_inst
*inst
, struct brw_reg dst
, struct brw_reg src
,
623 struct brw_reg surface_index
,
624 struct brw_reg sampler_index
)
626 assert(inst
->size_written
% REG_SIZE
== 0);
629 uint32_t return_format
;
630 bool is_combined_send
= inst
->eot
;
633 case BRW_REGISTER_TYPE_D
:
634 return_format
= BRW_SAMPLER_RETURN_FORMAT_SINT32
;
636 case BRW_REGISTER_TYPE_UD
:
637 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
640 return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
644 /* Stomp the resinfo output type to UINT32. On gens 4-5, the output type
645 * is set as part of the message descriptor. On gen4, the PRM seems to
646 * allow UINT32 and FLOAT32 (i965 PRM, Vol. 4 Section 4.8.1.1), but on
647 * later gens UINT32 is required. Once you hit Sandy Bridge, the bit is
648 * gone from the message descriptor entirely and you just get UINT32 all
649 * the time regasrdless. Since we can really only do non-UINT32 on gen4,
650 * just stomp it to UINT32 all the time.
652 if (inst
->opcode
== SHADER_OPCODE_TXS
)
653 return_format
= BRW_SAMPLER_RETURN_FORMAT_UINT32
;
655 switch (inst
->exec_size
) {
657 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
660 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
663 unreachable("Invalid width for texture instruction");
666 if (devinfo
->gen
>= 5) {
667 switch (inst
->opcode
) {
668 case SHADER_OPCODE_TEX
:
669 if (inst
->shadow_compare
) {
670 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE
;
672 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE
;
676 if (inst
->shadow_compare
) {
677 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE
;
679 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS
;
682 case SHADER_OPCODE_TXL
:
683 if (inst
->shadow_compare
) {
684 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE
;
686 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LOD
;
689 case SHADER_OPCODE_TXL_LZ
:
690 assert(devinfo
->gen
>= 9);
691 if (inst
->shadow_compare
) {
692 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_C_LZ
;
694 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_LZ
;
697 case SHADER_OPCODE_TXS
:
698 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO
;
700 case SHADER_OPCODE_TXD
:
701 if (inst
->shadow_compare
) {
702 /* Gen7.5+. Otherwise, lowered in NIR */
703 assert(devinfo
->gen
>= 8 || devinfo
->is_haswell
);
704 msg_type
= HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE
;
706 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS
;
709 case SHADER_OPCODE_TXF
:
710 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
712 case SHADER_OPCODE_TXF_LZ
:
713 assert(devinfo
->gen
>= 9);
714 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_LD_LZ
;
716 case SHADER_OPCODE_TXF_CMS_W
:
717 assert(devinfo
->gen
>= 9);
718 msg_type
= GEN9_SAMPLER_MESSAGE_SAMPLE_LD2DMS_W
;
720 case SHADER_OPCODE_TXF_CMS
:
721 if (devinfo
->gen
>= 7)
722 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS
;
724 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
726 case SHADER_OPCODE_TXF_UMS
:
727 assert(devinfo
->gen
>= 7);
728 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS
;
730 case SHADER_OPCODE_TXF_MCS
:
731 assert(devinfo
->gen
>= 7);
732 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS
;
734 case SHADER_OPCODE_LOD
:
735 msg_type
= GEN5_SAMPLER_MESSAGE_LOD
;
737 case SHADER_OPCODE_TG4
:
738 if (inst
->shadow_compare
) {
739 assert(devinfo
->gen
>= 7);
740 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C
;
742 assert(devinfo
->gen
>= 6);
743 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4
;
746 case SHADER_OPCODE_TG4_OFFSET
:
747 assert(devinfo
->gen
>= 7);
748 if (inst
->shadow_compare
) {
749 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C
;
751 msg_type
= GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO
;
754 case SHADER_OPCODE_SAMPLEINFO
:
755 msg_type
= GEN6_SAMPLER_MESSAGE_SAMPLE_SAMPLEINFO
;
758 unreachable("not reached");
761 switch (inst
->opcode
) {
762 case SHADER_OPCODE_TEX
:
763 /* Note that G45 and older determines shadow compare and dispatch width
764 * from message length for most messages.
766 if (inst
->exec_size
== 8) {
767 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE
;
768 if (inst
->shadow_compare
) {
769 assert(inst
->mlen
== 6);
771 assert(inst
->mlen
<= 4);
774 if (inst
->shadow_compare
) {
775 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE
;
776 assert(inst
->mlen
== 9);
778 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE
;
779 assert(inst
->mlen
<= 7 && inst
->mlen
% 2 == 1);
784 if (inst
->shadow_compare
) {
785 assert(inst
->exec_size
== 8);
786 assert(inst
->mlen
== 6);
787 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE
;
789 assert(inst
->mlen
== 9);
790 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS
;
791 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
794 case SHADER_OPCODE_TXL
:
795 if (inst
->shadow_compare
) {
796 assert(inst
->exec_size
== 8);
797 assert(inst
->mlen
== 6);
798 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE
;
800 assert(inst
->mlen
== 9);
801 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD
;
802 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
805 case SHADER_OPCODE_TXD
:
806 /* There is no sample_d_c message; comparisons are done manually */
807 assert(inst
->exec_size
== 8);
808 assert(inst
->mlen
== 7 || inst
->mlen
== 10);
809 msg_type
= BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS
;
811 case SHADER_OPCODE_TXF
:
812 assert(inst
->mlen
<= 9 && inst
->mlen
% 2 == 1);
813 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
814 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
816 case SHADER_OPCODE_TXS
:
817 assert(inst
->mlen
== 3);
818 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_RESINFO
;
819 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
822 unreachable("not reached");
825 assert(msg_type
!= -1);
827 if (simd_mode
== BRW_SAMPLER_SIMD_MODE_SIMD16
) {
831 assert(devinfo
->gen
< 7 || inst
->header_size
== 0 ||
832 src
.file
== BRW_GENERAL_REGISTER_FILE
);
834 assert(sampler_index
.type
== BRW_REGISTER_TYPE_UD
);
836 /* Load the message header if present. If there's a texture offset,
837 * we need to set it up explicitly and load the offset bitfield.
838 * Otherwise, we can use an implied move from g0 to the first message reg.
840 if (inst
->header_size
!= 0) {
841 if (devinfo
->gen
< 6 && !inst
->offset
) {
842 /* Set up an implied move from g0 to the MRF. */
843 src
= retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW
);
845 struct brw_reg header_reg
;
847 if (devinfo
->gen
>= 7) {
850 assert(inst
->base_mrf
!= -1);
851 header_reg
= brw_message_reg(inst
->base_mrf
);
854 brw_push_insn_state(p
);
855 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
856 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
857 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
858 /* Explicitly set up the message header by copying g0 to the MRF. */
859 brw_MOV(p
, header_reg
, brw_vec8_grf(0, 0));
862 /* Set the offset bits in DWord 2. */
863 brw_MOV(p
, get_element_ud(header_reg
, 2),
864 brw_imm_ud(inst
->offset
));
865 } else if (stage
!= MESA_SHADER_VERTEX
&&
866 stage
!= MESA_SHADER_FRAGMENT
) {
867 /* The vertex and fragment stages have g0.2 set to 0, so
868 * header0.2 is 0 when g0 is copied. Other stages may not, so we
869 * must set it to 0 to avoid setting undesirable bits in the
872 brw_MOV(p
, get_element_ud(header_reg
, 2), brw_imm_ud(0));
875 brw_adjust_sampler_state_pointer(p
, header_reg
, sampler_index
);
876 brw_pop_insn_state(p
);
880 uint32_t base_binding_table_index
= (inst
->opcode
== SHADER_OPCODE_TG4
||
881 inst
->opcode
== SHADER_OPCODE_TG4_OFFSET
)
882 ? prog_data
->binding_table
.gather_texture_start
883 : prog_data
->binding_table
.texture_start
;
885 if (surface_index
.file
== BRW_IMMEDIATE_VALUE
&&
886 sampler_index
.file
== BRW_IMMEDIATE_VALUE
) {
887 uint32_t surface
= surface_index
.ud
;
888 uint32_t sampler
= sampler_index
.ud
;
891 retype(dst
, BRW_REGISTER_TYPE_UW
),
894 surface
+ base_binding_table_index
,
897 inst
->size_written
/ REG_SIZE
,
899 inst
->header_size
!= 0,
903 brw_mark_surface_used(prog_data
, surface
+ base_binding_table_index
);
905 /* Non-const sampler index */
907 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
908 struct brw_reg surface_reg
= vec1(retype(surface_index
, BRW_REGISTER_TYPE_UD
));
909 struct brw_reg sampler_reg
= vec1(retype(sampler_index
, BRW_REGISTER_TYPE_UD
));
911 brw_push_insn_state(p
);
912 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
913 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
915 if (brw_regs_equal(&surface_reg
, &sampler_reg
)) {
916 brw_MUL(p
, addr
, sampler_reg
, brw_imm_uw(0x101));
918 if (sampler_reg
.file
== BRW_IMMEDIATE_VALUE
) {
919 brw_OR(p
, addr
, surface_reg
, brw_imm_ud(sampler_reg
.ud
<< 8));
921 brw_SHL(p
, addr
, sampler_reg
, brw_imm_ud(8));
922 brw_OR(p
, addr
, addr
, surface_reg
);
925 if (base_binding_table_index
)
926 brw_ADD(p
, addr
, addr
, brw_imm_ud(base_binding_table_index
));
927 brw_AND(p
, addr
, addr
, brw_imm_ud(0xfff));
929 brw_pop_insn_state(p
);
931 /* dst = send(offset, a0.0 | <descriptor>) */
932 brw_inst
*insn
= brw_send_indirect_message(
933 p
, BRW_SFID_SAMPLER
, dst
, src
, addr
);
934 brw_set_sampler_message(p
, insn
,
938 inst
->size_written
/ REG_SIZE
,
939 inst
->mlen
/* mlen */,
940 inst
->header_size
!= 0 /* header */,
944 /* visitor knows more than we do about the surface limit required,
945 * so has already done marking.
949 if (is_combined_send
) {
950 brw_inst_set_eot(p
->devinfo
, brw_last_inst
, true);
951 brw_inst_set_opcode(p
->devinfo
, brw_last_inst
, BRW_OPCODE_SENDC
);
956 /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
959 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
961 * Ideally, we want to produce:
964 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
965 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
966 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
967 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
968 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
969 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
970 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
971 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
973 * and add another set of two more subspans if in 16-pixel dispatch mode.
975 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
976 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
977 * pair. But the ideal approximation may impose a huge performance cost on
978 * sample_d. On at least Haswell, sample_d instruction does some
979 * optimizations if the same LOD is used for all pixels in the subspan.
981 * For DDY, we need to use ALIGN16 mode since it's capable of doing the
982 * appropriate swizzling.
985 fs_generator::generate_ddx(enum opcode opcode
,
986 struct brw_reg dst
, struct brw_reg src
)
988 unsigned vstride
, width
;
990 if (opcode
== FS_OPCODE_DDX_FINE
) {
991 /* produce accurate derivatives */
992 vstride
= BRW_VERTICAL_STRIDE_2
;
995 /* replicate the derivative at the top-left pixel to other pixels */
996 vstride
= BRW_VERTICAL_STRIDE_4
;
1000 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 1,
1001 src
.negate
, src
.abs
,
1002 BRW_REGISTER_TYPE_F
,
1005 BRW_HORIZONTAL_STRIDE_0
,
1006 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1007 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
1008 src
.negate
, src
.abs
,
1009 BRW_REGISTER_TYPE_F
,
1012 BRW_HORIZONTAL_STRIDE_0
,
1013 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1014 brw_ADD(p
, dst
, src0
, negate(src1
));
1017 /* The negate_value boolean is used to negate the derivative computation for
1018 * FBOs, since they place the origin at the upper left instead of the lower
1022 fs_generator::generate_ddy(enum opcode opcode
,
1023 struct brw_reg dst
, struct brw_reg src
)
1025 if (opcode
== FS_OPCODE_DDY_FINE
) {
1026 /* produce accurate derivatives */
1027 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
1028 src
.negate
, src
.abs
,
1029 BRW_REGISTER_TYPE_F
,
1030 BRW_VERTICAL_STRIDE_4
,
1032 BRW_HORIZONTAL_STRIDE_1
,
1033 BRW_SWIZZLE_XYXY
, WRITEMASK_XYZW
);
1034 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 0,
1035 src
.negate
, src
.abs
,
1036 BRW_REGISTER_TYPE_F
,
1037 BRW_VERTICAL_STRIDE_4
,
1039 BRW_HORIZONTAL_STRIDE_1
,
1040 BRW_SWIZZLE_ZWZW
, WRITEMASK_XYZW
);
1041 brw_push_insn_state(p
);
1042 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1043 brw_ADD(p
, dst
, negate(src0
), src1
);
1044 brw_pop_insn_state(p
);
1046 /* replicate the derivative at the top-left pixel to other pixels */
1047 struct brw_reg src0
= brw_reg(src
.file
, src
.nr
, 0,
1048 src
.negate
, src
.abs
,
1049 BRW_REGISTER_TYPE_F
,
1050 BRW_VERTICAL_STRIDE_4
,
1052 BRW_HORIZONTAL_STRIDE_0
,
1053 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1054 struct brw_reg src1
= brw_reg(src
.file
, src
.nr
, 2,
1055 src
.negate
, src
.abs
,
1056 BRW_REGISTER_TYPE_F
,
1057 BRW_VERTICAL_STRIDE_4
,
1059 BRW_HORIZONTAL_STRIDE_0
,
1060 BRW_SWIZZLE_XYZW
, WRITEMASK_XYZW
);
1061 brw_ADD(p
, dst
, negate(src0
), src1
);
1066 fs_generator::generate_discard_jump(fs_inst
*inst
)
1068 assert(devinfo
->gen
>= 6);
1070 /* This HALT will be patched up at FB write time to point UIP at the end of
1071 * the program, and at brw_uip_jip() JIP will be set to the end of the
1072 * current block (or the program).
1074 this->discard_halt_patches
.push_tail(new(mem_ctx
) ip_record(p
->nr_insn
));
1079 fs_generator::generate_scratch_write(fs_inst
*inst
, struct brw_reg src
)
1081 /* The 32-wide messages only respect the first 16-wide half of the channel
1082 * enable signals which are replicated identically for the second group of
1083 * 16 channels, so we cannot use them unless the write is marked
1084 * force_writemask_all.
1086 const unsigned lower_size
= inst
->force_writemask_all
? inst
->exec_size
:
1087 MIN2(16, inst
->exec_size
);
1088 const unsigned block_size
= 4 * lower_size
/ REG_SIZE
;
1089 assert(inst
->mlen
!= 0);
1091 brw_push_insn_state(p
);
1092 brw_set_default_exec_size(p
, cvt(lower_size
) - 1);
1093 brw_set_default_compression(p
, lower_size
> 8);
1095 for (unsigned i
= 0; i
< inst
->exec_size
/ lower_size
; i
++) {
1096 brw_set_default_group(p
, inst
->group
+ lower_size
* i
);
1098 brw_MOV(p
, brw_uvec_mrf(lower_size
, inst
->base_mrf
+ 1, 0),
1099 retype(offset(src
, block_size
* i
), BRW_REGISTER_TYPE_UD
));
1101 brw_oword_block_write_scratch(p
, brw_message_reg(inst
->base_mrf
),
1103 inst
->offset
+ block_size
* REG_SIZE
* i
);
1106 brw_pop_insn_state(p
);
1110 fs_generator::generate_scratch_read(fs_inst
*inst
, struct brw_reg dst
)
1112 assert(inst
->exec_size
<= 16 || inst
->force_writemask_all
);
1113 assert(inst
->mlen
!= 0);
1115 brw_oword_block_read_scratch(p
, dst
, brw_message_reg(inst
->base_mrf
),
1116 inst
->exec_size
/ 8, inst
->offset
);
1120 fs_generator::generate_scratch_read_gen7(fs_inst
*inst
, struct brw_reg dst
)
1122 assert(inst
->exec_size
<= 16 || inst
->force_writemask_all
);
1124 gen7_block_read_scratch(p
, dst
, inst
->exec_size
/ 8, inst
->offset
);
1128 fs_generator::generate_uniform_pull_constant_load(fs_inst
*inst
,
1130 struct brw_reg index
,
1131 struct brw_reg offset
)
1133 assert(type_sz(dst
.type
) == 4);
1134 assert(inst
->mlen
!= 0);
1136 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1137 index
.type
== BRW_REGISTER_TYPE_UD
);
1138 uint32_t surf_index
= index
.ud
;
1140 assert(offset
.file
== BRW_IMMEDIATE_VALUE
&&
1141 offset
.type
== BRW_REGISTER_TYPE_UD
);
1142 uint32_t read_offset
= offset
.ud
;
1144 brw_oword_block_read(p
, dst
, brw_message_reg(inst
->base_mrf
),
1145 read_offset
, surf_index
);
1149 fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst
*inst
,
1151 struct brw_reg index
,
1152 struct brw_reg payload
)
1154 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1155 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1156 assert(type_sz(dst
.type
) == 4);
1158 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1159 const uint32_t surf_index
= index
.ud
;
1161 brw_push_insn_state(p
);
1162 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1163 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1164 brw_pop_insn_state(p
);
1166 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UD
));
1167 brw_set_src0(p
, send
, retype(payload
, BRW_REGISTER_TYPE_UD
));
1168 brw_set_dp_read_message(p
, send
, surf_index
,
1169 BRW_DATAPORT_OWORD_BLOCK_DWORDS(inst
->exec_size
),
1170 GEN7_DATAPORT_DC_OWORD_BLOCK_READ
,
1171 GEN6_SFID_DATAPORT_CONSTANT_CACHE
,
1174 DIV_ROUND_UP(inst
->size_written
, REG_SIZE
));
1177 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1179 brw_push_insn_state(p
);
1180 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1182 /* a0.0 = surf_index & 0xff */
1183 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1184 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1185 brw_set_dest(p
, insn_and
, addr
);
1186 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1187 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1189 /* dst = send(payload, a0.0 | <descriptor>) */
1190 brw_inst
*insn
= brw_send_indirect_message(
1191 p
, GEN6_SFID_DATAPORT_CONSTANT_CACHE
,
1192 retype(dst
, BRW_REGISTER_TYPE_UD
),
1193 retype(payload
, BRW_REGISTER_TYPE_UD
), addr
);
1194 brw_set_dp_read_message(p
, insn
, 0 /* surface */,
1195 BRW_DATAPORT_OWORD_BLOCK_DWORDS(inst
->exec_size
),
1196 GEN7_DATAPORT_DC_OWORD_BLOCK_READ
,
1197 GEN6_SFID_DATAPORT_CONSTANT_CACHE
,
1200 DIV_ROUND_UP(inst
->size_written
, REG_SIZE
));
1202 brw_pop_insn_state(p
);
1207 fs_generator::generate_varying_pull_constant_load_gen4(fs_inst
*inst
,
1209 struct brw_reg index
)
1211 assert(devinfo
->gen
< 7); /* Should use the gen7 variant. */
1212 assert(inst
->header_size
!= 0);
1215 assert(index
.file
== BRW_IMMEDIATE_VALUE
&&
1216 index
.type
== BRW_REGISTER_TYPE_UD
);
1217 uint32_t surf_index
= index
.ud
;
1219 uint32_t simd_mode
, rlen
, msg_type
;
1220 if (inst
->exec_size
== 16) {
1221 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1224 assert(inst
->exec_size
== 8);
1225 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1229 if (devinfo
->gen
>= 5)
1230 msg_type
= GEN5_SAMPLER_MESSAGE_SAMPLE_LD
;
1232 /* We always use the SIMD16 message so that we only have to load U, and
1235 msg_type
= BRW_SAMPLER_MESSAGE_SIMD16_LD
;
1236 assert(inst
->mlen
== 3);
1237 assert(inst
->size_written
== 8 * REG_SIZE
);
1239 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1242 struct brw_reg header
= brw_vec8_grf(0, 0);
1243 gen6_resolve_implied_move(p
, &header
, inst
->base_mrf
);
1245 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1246 brw_inst_set_compression(devinfo
, send
, false);
1247 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1248 brw_set_src0(p
, send
, header
);
1249 if (devinfo
->gen
< 6)
1250 brw_inst_set_base_mrf(p
->devinfo
, send
, inst
->base_mrf
);
1252 /* Our surface is set up as floats, regardless of what actual data is
1255 uint32_t return_format
= BRW_SAMPLER_RETURN_FORMAT_FLOAT32
;
1256 brw_set_sampler_message(p
, send
,
1258 0, /* sampler (unused) */
1262 inst
->header_size
!= 0,
1268 fs_generator::generate_varying_pull_constant_load_gen7(fs_inst
*inst
,
1270 struct brw_reg index
,
1271 struct brw_reg offset
)
1273 assert(devinfo
->gen
>= 7);
1274 /* Varying-offset pull constant loads are treated as a normal expression on
1275 * gen7, so the fact that it's a send message is hidden at the IR level.
1277 assert(inst
->header_size
== 0);
1278 assert(!inst
->mlen
);
1279 assert(index
.type
== BRW_REGISTER_TYPE_UD
);
1281 uint32_t simd_mode
, rlen
, mlen
;
1282 if (inst
->exec_size
== 16) {
1285 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD16
;
1287 assert(inst
->exec_size
== 8);
1290 simd_mode
= BRW_SAMPLER_SIMD_MODE_SIMD8
;
1293 if (index
.file
== BRW_IMMEDIATE_VALUE
) {
1295 uint32_t surf_index
= index
.ud
;
1297 brw_inst
*send
= brw_next_insn(p
, BRW_OPCODE_SEND
);
1298 brw_set_dest(p
, send
, retype(dst
, BRW_REGISTER_TYPE_UW
));
1299 brw_set_src0(p
, send
, offset
);
1300 brw_set_sampler_message(p
, send
,
1302 0, /* LD message ignores sampler unit */
1303 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1306 false, /* no header */
1312 struct brw_reg addr
= vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD
));
1314 brw_push_insn_state(p
);
1315 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1317 /* a0.0 = surf_index & 0xff */
1318 brw_inst
*insn_and
= brw_next_insn(p
, BRW_OPCODE_AND
);
1319 brw_inst_set_exec_size(p
->devinfo
, insn_and
, BRW_EXECUTE_1
);
1320 brw_set_dest(p
, insn_and
, addr
);
1321 brw_set_src0(p
, insn_and
, vec1(retype(index
, BRW_REGISTER_TYPE_UD
)));
1322 brw_set_src1(p
, insn_and
, brw_imm_ud(0x0ff));
1324 brw_pop_insn_state(p
);
1326 /* dst = send(offset, a0.0 | <descriptor>) */
1327 brw_inst
*insn
= brw_send_indirect_message(
1328 p
, BRW_SFID_SAMPLER
, retype(dst
, BRW_REGISTER_TYPE_UW
),
1330 brw_set_sampler_message(p
, insn
,
1333 GEN5_SAMPLER_MESSAGE_SAMPLE_LD
,
1343 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
1344 * into the flags register (f0.0).
1346 * Used only on Gen6 and above.
1349 fs_generator::generate_mov_dispatch_to_flags(fs_inst
*inst
)
1351 struct brw_reg flags
= brw_flag_reg(0, inst
->flag_subreg
);
1352 struct brw_reg dispatch_mask
;
1354 if (devinfo
->gen
>= 6)
1355 dispatch_mask
= retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW
);
1357 dispatch_mask
= retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW
);
1359 brw_push_insn_state(p
);
1360 brw_set_default_mask_control(p
, BRW_MASK_DISABLE
);
1361 brw_MOV(p
, flags
, dispatch_mask
);
1362 brw_pop_insn_state(p
);
1366 fs_generator::generate_pixel_interpolator_query(fs_inst
*inst
,
1369 struct brw_reg msg_data
,
1372 assert(inst
->size_written
% REG_SIZE
== 0);
1373 assert(msg_data
.type
== BRW_REGISTER_TYPE_UD
);
1375 brw_pixel_interpolator_query(p
,
1376 retype(dst
, BRW_REGISTER_TYPE_UW
),
1378 inst
->pi_noperspective
,
1382 inst
->size_written
/ REG_SIZE
);
1385 /* Sets vstride=1, width=4, hstride=0 of register src1 during
1386 * the ADD instruction.
1389 fs_generator::generate_set_sample_id(fs_inst
*inst
,
1391 struct brw_reg src0
,
1392 struct brw_reg src1
)
1394 assert(dst
.type
== BRW_REGISTER_TYPE_D
||
1395 dst
.type
== BRW_REGISTER_TYPE_UD
);
1396 assert(src0
.type
== BRW_REGISTER_TYPE_D
||
1397 src0
.type
== BRW_REGISTER_TYPE_UD
);
1399 struct brw_reg reg
= stride(src1
, 1, 4, 0);
1400 if (devinfo
->gen
>= 8 || inst
->exec_size
== 8) {
1401 brw_ADD(p
, dst
, src0
, reg
);
1402 } else if (inst
->exec_size
== 16) {
1403 brw_push_insn_state(p
);
1404 brw_set_default_exec_size(p
, BRW_EXECUTE_8
);
1405 brw_set_default_compression_control(p
, BRW_COMPRESSION_NONE
);
1406 brw_ADD(p
, firsthalf(dst
), firsthalf(src0
), reg
);
1407 brw_set_default_compression_control(p
, BRW_COMPRESSION_2NDHALF
);
1408 brw_ADD(p
, sechalf(dst
), sechalf(src0
), suboffset(reg
, 2));
1409 brw_pop_insn_state(p
);
1414 fs_generator::generate_pack_half_2x16_split(fs_inst
*inst
,
1419 assert(devinfo
->gen
>= 7);
1420 assert(dst
.type
== BRW_REGISTER_TYPE_UD
);
1421 assert(x
.type
== BRW_REGISTER_TYPE_F
);
1422 assert(y
.type
== BRW_REGISTER_TYPE_F
);
1424 /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16:
1426 * Because this instruction does not have a 16-bit floating-point type,
1427 * the destination data type must be Word (W).
1429 * The destination must be DWord-aligned and specify a horizontal stride
1430 * (HorzStride) of 2. The 16-bit result is stored in the lower word of
1431 * each destination channel and the upper word is not modified.
1433 struct brw_reg dst_w
= spread(retype(dst
, BRW_REGISTER_TYPE_W
), 2);
1435 /* Give each 32-bit channel of dst the form below, where "." means
1439 brw_F32TO16(p
, dst_w
, y
);
1444 brw_SHL(p
, dst
, dst
, brw_imm_ud(16u));
1446 /* And, finally the form of packHalf2x16's output:
1449 brw_F32TO16(p
, dst_w
, x
);
1453 fs_generator::generate_unpack_half_2x16_split(fs_inst
*inst
,
1457 assert(devinfo
->gen
>= 7);
1458 assert(dst
.type
== BRW_REGISTER_TYPE_F
);
1459 assert(src
.type
== BRW_REGISTER_TYPE_UD
);
1461 /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32:
1463 * Because this instruction does not have a 16-bit floating-point type,
1464 * the source data type must be Word (W). The destination type must be
1467 struct brw_reg src_w
= spread(retype(src
, BRW_REGISTER_TYPE_W
), 2);
1469 /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
1470 * For the Y case, we wish to access only the upper word; therefore
1471 * a 16-bit subregister offset is needed.
1473 assert(inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
||
1474 inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
);
1475 if (inst
->opcode
== FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
)
1478 brw_F16TO32(p
, dst
, src_w
);
1482 fs_generator::generate_shader_time_add(fs_inst
*inst
,
1483 struct brw_reg payload
,
1484 struct brw_reg offset
,
1485 struct brw_reg value
)
1487 assert(devinfo
->gen
>= 7);
1488 brw_push_insn_state(p
);
1489 brw_set_default_mask_control(p
, true);
1491 assert(payload
.file
== BRW_GENERAL_REGISTER_FILE
);
1492 struct brw_reg payload_offset
= retype(brw_vec1_grf(payload
.nr
, 0),
1494 struct brw_reg payload_value
= retype(brw_vec1_grf(payload
.nr
+ 1, 0),
1497 assert(offset
.file
== BRW_IMMEDIATE_VALUE
);
1498 if (value
.file
== BRW_GENERAL_REGISTER_FILE
) {
1499 value
.width
= BRW_WIDTH_1
;
1500 value
.hstride
= BRW_HORIZONTAL_STRIDE_0
;
1501 value
.vstride
= BRW_VERTICAL_STRIDE_0
;
1503 assert(value
.file
== BRW_IMMEDIATE_VALUE
);
1506 /* Trying to deal with setup of the params from the IR is crazy in the FS8
1507 * case, and we don't really care about squeezing every bit of performance
1508 * out of this path, so we just emit the MOVs from here.
1510 brw_MOV(p
, payload_offset
, offset
);
1511 brw_MOV(p
, payload_value
, value
);
1512 brw_shader_time_add(p
, payload
,
1513 prog_data
->binding_table
.shader_time_start
);
1514 brw_pop_insn_state(p
);
1516 brw_mark_surface_used(prog_data
,
1517 prog_data
->binding_table
.shader_time_start
);
1521 fs_generator::enable_debug(const char *shader_name
)
1524 this->shader_name
= shader_name
;
1528 fs_generator::generate_code(const cfg_t
*cfg
, int dispatch_width
)
1530 /* align to 64 byte boundary. */
1531 while (p
->next_insn_offset
% 64)
1534 this->dispatch_width
= dispatch_width
;
1536 int start_offset
= p
->next_insn_offset
;
1537 int spill_count
= 0, fill_count
= 0;
1540 struct annotation_info annotation
;
1541 memset(&annotation
, 0, sizeof(annotation
));
1543 foreach_block_and_inst (block
, fs_inst
, inst
, cfg
) {
1544 struct brw_reg src
[3], dst
;
1545 unsigned int last_insn_offset
= p
->next_insn_offset
;
1546 bool multiple_instructions_emitted
= false;
1548 /* From the Broadwell PRM, Volume 7, "3D-Media-GPGPU", in the
1549 * "Register Region Restrictions" section: for BDW, SKL:
1551 * "A POW/FDIV operation must not be followed by an instruction
1552 * that requires two destination registers."
1554 * The documentation is often lacking annotations for Atom parts,
1555 * and empirically this affects CHV as well.
1557 if (devinfo
->gen
>= 8 &&
1559 brw_inst_opcode(devinfo
, brw_last_inst
) == BRW_OPCODE_MATH
&&
1560 brw_inst_math_function(devinfo
, brw_last_inst
) == BRW_MATH_FUNCTION_POW
&&
1561 inst
->dst
.component_size(inst
->exec_size
) > REG_SIZE
) {
1563 last_insn_offset
= p
->next_insn_offset
;
1566 if (unlikely(debug_flag
))
1567 annotate(p
->devinfo
, &annotation
, cfg
, inst
, p
->next_insn_offset
);
1569 /* If the instruction writes to more than one register, it needs to be
1570 * explicitly marked as compressed on Gen <= 5. On Gen >= 6 the
1571 * hardware figures out by itself what the right compression mode is,
1572 * but we still need to know whether the instruction is compressed to
1573 * set up the source register regions appropriately.
1575 * XXX - This is wrong for instructions that write a single register but
1576 * read more than one which should strictly speaking be treated as
1577 * compressed. For instructions that don't write any registers it
1578 * relies on the destination being a null register of the correct
1579 * type and regioning so the instruction is considered compressed
1580 * or not accordingly.
1582 const bool compressed
=
1583 inst
->dst
.component_size(inst
->exec_size
) > REG_SIZE
;
1584 brw_set_default_compression(p
, compressed
);
1585 brw_set_default_group(p
, inst
->group
);
1587 for (unsigned int i
= 0; i
< inst
->sources
; i
++) {
1588 src
[i
] = brw_reg_from_fs_reg(inst
, &inst
->src
[i
], devinfo
->gen
,
1591 /* The accumulator result appears to get used for the
1592 * conditional modifier generation. When negating a UD
1593 * value, there is a 33rd bit generated for the sign in the
1594 * accumulator value, so now you can't check, for example,
1595 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
1597 assert(!inst
->conditional_mod
||
1598 inst
->src
[i
].type
!= BRW_REGISTER_TYPE_UD
||
1599 !inst
->src
[i
].negate
);
1601 dst
= brw_reg_from_fs_reg(inst
, &inst
->dst
, devinfo
->gen
, compressed
);
1603 brw_set_default_access_mode(p
, BRW_ALIGN_1
);
1604 brw_set_default_predicate_control(p
, inst
->predicate
);
1605 brw_set_default_predicate_inverse(p
, inst
->predicate_inverse
);
1606 brw_set_default_flag_reg(p
, 0, inst
->flag_subreg
);
1607 brw_set_default_saturate(p
, inst
->saturate
);
1608 brw_set_default_mask_control(p
, inst
->force_writemask_all
);
1609 brw_set_default_acc_write_control(p
, inst
->writes_accumulator
);
1610 brw_set_default_exec_size(p
, cvt(inst
->exec_size
) - 1);
1612 assert(inst
->force_writemask_all
|| inst
->exec_size
>= 4);
1613 assert(inst
->force_writemask_all
|| inst
->group
% inst
->exec_size
== 0);
1614 assert(inst
->base_mrf
+ inst
->mlen
<= BRW_MAX_MRF(devinfo
->gen
));
1615 assert(inst
->mlen
<= BRW_MAX_MSG_LENGTH
);
1617 switch (inst
->opcode
) {
1618 case BRW_OPCODE_MOV
:
1619 brw_MOV(p
, dst
, src
[0]);
1621 case BRW_OPCODE_ADD
:
1622 brw_ADD(p
, dst
, src
[0], src
[1]);
1624 case BRW_OPCODE_MUL
:
1625 brw_MUL(p
, dst
, src
[0], src
[1]);
1627 case BRW_OPCODE_AVG
:
1628 brw_AVG(p
, dst
, src
[0], src
[1]);
1630 case BRW_OPCODE_MACH
:
1631 brw_MACH(p
, dst
, src
[0], src
[1]);
1634 case BRW_OPCODE_LINE
:
1635 brw_LINE(p
, dst
, src
[0], src
[1]);
1638 case BRW_OPCODE_MAD
:
1639 assert(devinfo
->gen
>= 6);
1640 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1641 brw_MAD(p
, dst
, src
[0], src
[1], src
[2]);
1644 case BRW_OPCODE_LRP
:
1645 assert(devinfo
->gen
>= 6);
1646 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1647 brw_LRP(p
, dst
, src
[0], src
[1], src
[2]);
1650 case BRW_OPCODE_FRC
:
1651 brw_FRC(p
, dst
, src
[0]);
1653 case BRW_OPCODE_RNDD
:
1654 brw_RNDD(p
, dst
, src
[0]);
1656 case BRW_OPCODE_RNDE
:
1657 brw_RNDE(p
, dst
, src
[0]);
1659 case BRW_OPCODE_RNDZ
:
1660 brw_RNDZ(p
, dst
, src
[0]);
1663 case BRW_OPCODE_AND
:
1664 brw_AND(p
, dst
, src
[0], src
[1]);
1667 brw_OR(p
, dst
, src
[0], src
[1]);
1669 case BRW_OPCODE_XOR
:
1670 brw_XOR(p
, dst
, src
[0], src
[1]);
1672 case BRW_OPCODE_NOT
:
1673 brw_NOT(p
, dst
, src
[0]);
1675 case BRW_OPCODE_ASR
:
1676 brw_ASR(p
, dst
, src
[0], src
[1]);
1678 case BRW_OPCODE_SHR
:
1679 brw_SHR(p
, dst
, src
[0], src
[1]);
1681 case BRW_OPCODE_SHL
:
1682 brw_SHL(p
, dst
, src
[0], src
[1]);
1684 case BRW_OPCODE_F32TO16
:
1685 assert(devinfo
->gen
>= 7);
1686 brw_F32TO16(p
, dst
, src
[0]);
1688 case BRW_OPCODE_F16TO32
:
1689 assert(devinfo
->gen
>= 7);
1690 brw_F16TO32(p
, dst
, src
[0]);
1692 case BRW_OPCODE_CMP
:
1693 if (inst
->exec_size
>= 16 && devinfo
->gen
== 7 && !devinfo
->is_haswell
&&
1694 dst
.file
== BRW_ARCHITECTURE_REGISTER_FILE
) {
1695 /* For unknown reasons the WaCMPInstFlagDepClearedEarly workaround
1696 * implemented in the compiler is not sufficient. Overriding the
1697 * type when the destination is the null register is necessary but
1698 * not sufficient by itself.
1700 assert(dst
.nr
== BRW_ARF_NULL
);
1701 dst
.type
= BRW_REGISTER_TYPE_D
;
1703 brw_CMP(p
, dst
, inst
->conditional_mod
, src
[0], src
[1]);
1705 case BRW_OPCODE_SEL
:
1706 brw_SEL(p
, dst
, src
[0], src
[1]);
1708 case BRW_OPCODE_BFREV
:
1709 assert(devinfo
->gen
>= 7);
1710 /* BFREV only supports UD type for src and dst. */
1711 brw_BFREV(p
, retype(dst
, BRW_REGISTER_TYPE_UD
),
1712 retype(src
[0], BRW_REGISTER_TYPE_UD
));
1714 case BRW_OPCODE_FBH
:
1715 assert(devinfo
->gen
>= 7);
1716 /* FBH only supports UD type for dst. */
1717 brw_FBH(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1719 case BRW_OPCODE_FBL
:
1720 assert(devinfo
->gen
>= 7);
1721 /* FBL only supports UD type for dst. */
1722 brw_FBL(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1724 case BRW_OPCODE_LZD
:
1725 brw_LZD(p
, dst
, src
[0]);
1727 case BRW_OPCODE_CBIT
:
1728 assert(devinfo
->gen
>= 7);
1729 /* CBIT only supports UD type for dst. */
1730 brw_CBIT(p
, retype(dst
, BRW_REGISTER_TYPE_UD
), src
[0]);
1732 case BRW_OPCODE_ADDC
:
1733 assert(devinfo
->gen
>= 7);
1734 brw_ADDC(p
, dst
, src
[0], src
[1]);
1736 case BRW_OPCODE_SUBB
:
1737 assert(devinfo
->gen
>= 7);
1738 brw_SUBB(p
, dst
, src
[0], src
[1]);
1740 case BRW_OPCODE_MAC
:
1741 brw_MAC(p
, dst
, src
[0], src
[1]);
1744 case BRW_OPCODE_BFE
:
1745 assert(devinfo
->gen
>= 7);
1746 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1747 brw_BFE(p
, dst
, src
[0], src
[1], src
[2]);
1750 case BRW_OPCODE_BFI1
:
1751 assert(devinfo
->gen
>= 7);
1752 brw_BFI1(p
, dst
, src
[0], src
[1]);
1754 case BRW_OPCODE_BFI2
:
1755 assert(devinfo
->gen
>= 7);
1756 brw_set_default_access_mode(p
, BRW_ALIGN_16
);
1757 brw_BFI2(p
, dst
, src
[0], src
[1], src
[2]);
1761 if (inst
->src
[0].file
!= BAD_FILE
) {
1762 /* The instruction has an embedded compare (only allowed on gen6) */
1763 assert(devinfo
->gen
== 6);
1764 gen6_IF(p
, inst
->conditional_mod
, src
[0], src
[1]);
1766 brw_IF(p
, brw_inst_exec_size(devinfo
, p
->current
));
1770 case BRW_OPCODE_ELSE
:
1773 case BRW_OPCODE_ENDIF
:
1778 brw_DO(p
, brw_inst_exec_size(devinfo
, p
->current
));
1781 case BRW_OPCODE_BREAK
:
1784 case BRW_OPCODE_CONTINUE
:
1788 case BRW_OPCODE_WHILE
:
1793 case SHADER_OPCODE_RCP
:
1794 case SHADER_OPCODE_RSQ
:
1795 case SHADER_OPCODE_SQRT
:
1796 case SHADER_OPCODE_EXP2
:
1797 case SHADER_OPCODE_LOG2
:
1798 case SHADER_OPCODE_SIN
:
1799 case SHADER_OPCODE_COS
:
1800 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1801 if (devinfo
->gen
>= 6) {
1802 assert(inst
->mlen
== 0);
1803 assert(devinfo
->gen
>= 7 || inst
->exec_size
== 8);
1804 gen6_math(p
, dst
, brw_math_function(inst
->opcode
),
1805 src
[0], brw_null_reg());
1807 assert(inst
->mlen
>= 1);
1808 assert(devinfo
->gen
== 5 || devinfo
->is_g4x
|| inst
->exec_size
== 8);
1810 brw_math_function(inst
->opcode
),
1811 inst
->base_mrf
, src
[0],
1812 BRW_MATH_PRECISION_FULL
);
1815 case SHADER_OPCODE_INT_QUOTIENT
:
1816 case SHADER_OPCODE_INT_REMAINDER
:
1817 case SHADER_OPCODE_POW
:
1818 assert(inst
->conditional_mod
== BRW_CONDITIONAL_NONE
);
1819 if (devinfo
->gen
>= 6) {
1820 assert(inst
->mlen
== 0);
1821 assert((devinfo
->gen
>= 7 && inst
->opcode
== SHADER_OPCODE_POW
) ||
1822 inst
->exec_size
== 8);
1823 gen6_math(p
, dst
, brw_math_function(inst
->opcode
), src
[0], src
[1]);
1825 assert(inst
->mlen
>= 1);
1826 assert(inst
->exec_size
== 8);
1827 gen4_math(p
, dst
, brw_math_function(inst
->opcode
),
1828 inst
->base_mrf
, src
[0],
1829 BRW_MATH_PRECISION_FULL
);
1832 case FS_OPCODE_CINTERP
:
1833 brw_MOV(p
, dst
, src
[0]);
1835 case FS_OPCODE_LINTERP
:
1836 generate_linterp(inst
, dst
, src
);
1838 case FS_OPCODE_PIXEL_X
:
1839 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1840 src
[0].subnr
= 0 * type_sz(src
[0].type
);
1841 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1843 case FS_OPCODE_PIXEL_Y
:
1844 assert(src
[0].type
== BRW_REGISTER_TYPE_UW
);
1845 src
[0].subnr
= 4 * type_sz(src
[0].type
);
1846 brw_MOV(p
, dst
, stride(src
[0], 8, 4, 1));
1848 case FS_OPCODE_GET_BUFFER_SIZE
:
1849 generate_get_buffer_size(inst
, dst
, src
[0], src
[1]);
1851 case SHADER_OPCODE_TEX
:
1853 case SHADER_OPCODE_TXD
:
1854 case SHADER_OPCODE_TXF
:
1855 case SHADER_OPCODE_TXF_LZ
:
1856 case SHADER_OPCODE_TXF_CMS
:
1857 case SHADER_OPCODE_TXF_CMS_W
:
1858 case SHADER_OPCODE_TXF_UMS
:
1859 case SHADER_OPCODE_TXF_MCS
:
1860 case SHADER_OPCODE_TXL
:
1861 case SHADER_OPCODE_TXL_LZ
:
1862 case SHADER_OPCODE_TXS
:
1863 case SHADER_OPCODE_LOD
:
1864 case SHADER_OPCODE_TG4
:
1865 case SHADER_OPCODE_TG4_OFFSET
:
1866 case SHADER_OPCODE_SAMPLEINFO
:
1867 generate_tex(inst
, dst
, src
[0], src
[1], src
[2]);
1869 case FS_OPCODE_DDX_COARSE
:
1870 case FS_OPCODE_DDX_FINE
:
1871 generate_ddx(inst
->opcode
, dst
, src
[0]);
1873 case FS_OPCODE_DDY_COARSE
:
1874 case FS_OPCODE_DDY_FINE
:
1875 generate_ddy(inst
->opcode
, dst
, src
[0]);
1878 case SHADER_OPCODE_GEN4_SCRATCH_WRITE
:
1879 generate_scratch_write(inst
, src
[0]);
1883 case SHADER_OPCODE_GEN4_SCRATCH_READ
:
1884 generate_scratch_read(inst
, dst
);
1888 case SHADER_OPCODE_GEN7_SCRATCH_READ
:
1889 generate_scratch_read_gen7(inst
, dst
);
1893 case SHADER_OPCODE_MOV_INDIRECT
:
1894 generate_mov_indirect(inst
, dst
, src
[0], src
[1]);
1897 case SHADER_OPCODE_URB_READ_SIMD8
:
1898 case SHADER_OPCODE_URB_READ_SIMD8_PER_SLOT
:
1899 generate_urb_read(inst
, dst
, src
[0]);
1902 case SHADER_OPCODE_URB_WRITE_SIMD8
:
1903 case SHADER_OPCODE_URB_WRITE_SIMD8_PER_SLOT
:
1904 case SHADER_OPCODE_URB_WRITE_SIMD8_MASKED
:
1905 case SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT
:
1906 generate_urb_write(inst
, src
[0]);
1909 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD
:
1910 assert(inst
->force_writemask_all
);
1911 generate_uniform_pull_constant_load(inst
, dst
, src
[0], src
[1]);
1914 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7
:
1915 assert(inst
->force_writemask_all
);
1916 generate_uniform_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
1919 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN4
:
1920 generate_varying_pull_constant_load_gen4(inst
, dst
, src
[0]);
1923 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7
:
1924 generate_varying_pull_constant_load_gen7(inst
, dst
, src
[0], src
[1]);
1927 case FS_OPCODE_REP_FB_WRITE
:
1928 case FS_OPCODE_FB_WRITE
:
1929 generate_fb_write(inst
, src
[0]);
1932 case FS_OPCODE_FB_READ
:
1933 generate_fb_read(inst
, dst
, src
[0]);
1936 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS
:
1937 generate_mov_dispatch_to_flags(inst
);
1940 case FS_OPCODE_DISCARD_JUMP
:
1941 generate_discard_jump(inst
);
1944 case SHADER_OPCODE_SHADER_TIME_ADD
:
1945 generate_shader_time_add(inst
, src
[0], src
[1], src
[2]);
1948 case SHADER_OPCODE_UNTYPED_ATOMIC
:
1949 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
1950 brw_untyped_atomic(p
, dst
, src
[0], src
[1], src
[2].ud
,
1951 inst
->mlen
, !inst
->dst
.is_null());
1954 case SHADER_OPCODE_UNTYPED_SURFACE_READ
:
1955 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
1956 brw_untyped_surface_read(p
, dst
, src
[0], src
[1],
1957 inst
->mlen
, src
[2].ud
);
1960 case SHADER_OPCODE_UNTYPED_SURFACE_WRITE
:
1961 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
1962 brw_untyped_surface_write(p
, src
[0], src
[1],
1963 inst
->mlen
, src
[2].ud
);
1966 case SHADER_OPCODE_TYPED_ATOMIC
:
1967 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
1968 brw_typed_atomic(p
, dst
, src
[0], src
[1],
1969 src
[2].ud
, inst
->mlen
, !inst
->dst
.is_null());
1972 case SHADER_OPCODE_TYPED_SURFACE_READ
:
1973 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
1974 brw_typed_surface_read(p
, dst
, src
[0], src
[1],
1975 inst
->mlen
, src
[2].ud
);
1978 case SHADER_OPCODE_TYPED_SURFACE_WRITE
:
1979 assert(src
[2].file
== BRW_IMMEDIATE_VALUE
);
1980 brw_typed_surface_write(p
, src
[0], src
[1], inst
->mlen
, src
[2].ud
);
1983 case SHADER_OPCODE_MEMORY_FENCE
:
1984 brw_memory_fence(p
, dst
);
1987 case SHADER_OPCODE_FIND_LIVE_CHANNEL
: {
1988 const struct brw_reg mask
=
1989 brw_stage_has_packed_dispatch(devinfo
, stage
,
1990 prog_data
) ? brw_imm_ud(~0u) :
1991 stage
== MESA_SHADER_FRAGMENT
? brw_vmask_reg() :
1993 brw_find_live_channel(p
, dst
, mask
);
1997 case SHADER_OPCODE_BROADCAST
:
1998 assert(inst
->force_writemask_all
);
1999 brw_broadcast(p
, dst
, src
[0], src
[1]);
2002 case FS_OPCODE_SET_SAMPLE_ID
:
2003 generate_set_sample_id(inst
, dst
, src
[0], src
[1]);
2006 case FS_OPCODE_PACK_HALF_2x16_SPLIT
:
2007 generate_pack_half_2x16_split(inst
, dst
, src
[0], src
[1]);
2010 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X
:
2011 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y
:
2012 generate_unpack_half_2x16_split(inst
, dst
, src
[0]);
2015 case FS_OPCODE_PLACEHOLDER_HALT
:
2016 /* This is the place where the final HALT needs to be inserted if
2017 * we've emitted any discards. If not, this will emit no code.
2019 if (!patch_discard_jumps_to_fb_writes()) {
2020 if (unlikely(debug_flag
)) {
2021 annotation
.ann_count
--;
2026 case FS_OPCODE_INTERPOLATE_AT_SAMPLE
:
2027 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2028 GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE
);
2031 case FS_OPCODE_INTERPOLATE_AT_SHARED_OFFSET
:
2032 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2033 GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET
);
2036 case FS_OPCODE_INTERPOLATE_AT_PER_SLOT_OFFSET
:
2037 generate_pixel_interpolator_query(inst
, dst
, src
[0], src
[1],
2038 GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET
);
2041 case CS_OPCODE_CS_TERMINATE
:
2042 generate_cs_terminate(inst
, src
[0]);
2045 case SHADER_OPCODE_BARRIER
:
2046 generate_barrier(inst
, src
[0]);
2049 case BRW_OPCODE_DIM
:
2050 assert(devinfo
->is_haswell
);
2051 assert(src
[0].type
== BRW_REGISTER_TYPE_DF
);
2052 assert(dst
.type
== BRW_REGISTER_TYPE_DF
);
2053 brw_DIM(p
, dst
, retype(src
[0], BRW_REGISTER_TYPE_F
));
2057 unreachable("Unsupported opcode");
2059 case SHADER_OPCODE_LOAD_PAYLOAD
:
2060 unreachable("Should be lowered by lower_load_payload()");
2063 if (multiple_instructions_emitted
)
2066 if (inst
->no_dd_clear
|| inst
->no_dd_check
|| inst
->conditional_mod
) {
2067 assert(p
->next_insn_offset
== last_insn_offset
+ 16 ||
2068 !"conditional_mod, no_dd_check, or no_dd_clear set for IR "
2069 "emitting more than 1 instruction");
2071 brw_inst
*last
= &p
->store
[last_insn_offset
/ 16];
2073 if (inst
->conditional_mod
)
2074 brw_inst_set_cond_modifier(p
->devinfo
, last
, inst
->conditional_mod
);
2075 brw_inst_set_no_dd_clear(p
->devinfo
, last
, inst
->no_dd_clear
);
2076 brw_inst_set_no_dd_check(p
->devinfo
, last
, inst
->no_dd_check
);
2080 brw_set_uip_jip(p
, start_offset
);
2081 annotation_finalize(&annotation
, p
->next_insn_offset
);
2084 bool validated
= brw_validate_instructions(p
, start_offset
, &annotation
);
2086 if (unlikely(debug_flag
))
2087 brw_validate_instructions(p
, start_offset
, &annotation
);
2090 int before_size
= p
->next_insn_offset
- start_offset
;
2091 brw_compact_instructions(p
, start_offset
, annotation
.ann_count
,
2093 int after_size
= p
->next_insn_offset
- start_offset
;
2095 if (unlikely(debug_flag
)) {
2096 fprintf(stderr
, "Native code for %s\n"
2097 "SIMD%d shader: %d instructions. %d loops. %u cycles. %d:%d spills:fills. Promoted %u constants. Compacted %d to %d"
2098 " bytes (%.0f%%)\n",
2099 shader_name
, dispatch_width
, before_size
/ 16, loop_count
, cfg
->cycle_count
,
2100 spill_count
, fill_count
, promoted_constants
, before_size
, after_size
,
2101 100.0f
* (before_size
- after_size
) / before_size
);
2103 dump_assembly(p
->store
, annotation
.ann_count
, annotation
.ann
,
2105 ralloc_free(annotation
.mem_ctx
);
2109 compiler
->shader_debug_log(log_data
,
2110 "%s SIMD%d shader: %d inst, %d loops, %u cycles, "
2111 "%d:%d spills:fills, Promoted %u constants, "
2112 "compacted %d to %d bytes.",
2113 _mesa_shader_stage_to_abbrev(stage
),
2114 dispatch_width
, before_size
/ 16,
2115 loop_count
, cfg
->cycle_count
, spill_count
,
2116 fill_count
, promoted_constants
, before_size
,
2119 return start_offset
;
2123 fs_generator::get_assembly(unsigned int *assembly_size
)
2125 return brw_get_program(p
, assembly_size
);