2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_formats.h"
25 #include "r600_opcodes.h"
26 #include "r600_shader.h"
29 #include "sb/sb_public.h"
31 #include "pipe/p_shader_tokens.h"
32 #include "tgsi/tgsi_info.h"
33 #include "tgsi/tgsi_parse.h"
34 #include "tgsi/tgsi_scan.h"
35 #include "tgsi/tgsi_dump.h"
36 #include "util/u_bitcast.h"
37 #include "util/u_memory.h"
38 #include "util/u_math.h"
43 Why CAYMAN got loops for lots of instructions is explained here.
45 -These 8xx t-slot only ops are implemented in all vector slots.
46 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
47 These 8xx t-slot only opcodes become vector ops, with all four
48 slots expecting the arguments on sources a and b. Result is
49 broadcast to all channels.
50 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT, MUL_64
51 These 8xx t-slot only opcodes become vector ops in the z, y, and
53 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
54 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
57 The w slot may have an independent co-issued operation, or if the
58 result is required to be in the w slot, the opcode above may be
59 issued in the w slot as well.
60 The compiler must issue the source argument to slots z, y, and x
63 /* Contents of r0 on entry to various shaders
69 GS - r0.xyw, r1.xyz = per-vertex offsets
75 .w = tess factor base.
77 TES - .x = TessCoord.x
79 - .z = RelPatchID (??)
82 PS - face_gpr.z = SampleMask
85 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
86 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
87 struct r600_pipe_shader
*pipeshader
,
88 union r600_shader_key key
);
90 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
91 int size
, unsigned comp_mask
) {
96 if (ps
->num_arrays
== ps
->max_arrays
) {
98 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
99 sizeof(struct r600_shader_array
));
102 int n
= ps
->num_arrays
;
105 ps
->arrays
[n
].comp_mask
= comp_mask
;
106 ps
->arrays
[n
].gpr_start
= start_gpr
;
107 ps
->arrays
[n
].gpr_count
= size
;
110 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
114 fprintf(stderr
, "STREAMOUT\n");
115 for (i
= 0; i
< so
->num_outputs
; i
++) {
116 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
117 so
->output
[i
].start_component
;
118 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
120 so
->output
[i
].stream
,
121 so
->output
[i
].output_buffer
,
122 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
123 so
->output
[i
].register_index
,
128 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
132 static int store_shader(struct pipe_context
*ctx
,
133 struct r600_pipe_shader
*shader
)
135 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 if (shader
->bo
== NULL
) {
139 shader
->bo
= (struct r600_resource
*)
140 pipe_buffer_create(ctx
->screen
, 0, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
141 if (shader
->bo
== NULL
) {
144 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
145 if (R600_BIG_ENDIAN
) {
146 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
147 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
150 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
152 rctx
->b
.ws
->buffer_unmap(shader
->bo
->buf
);
158 int r600_pipe_shader_create(struct pipe_context
*ctx
,
159 struct r600_pipe_shader
*shader
,
160 union r600_shader_key key
)
162 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
163 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
165 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
,
166 tgsi_get_processor_type(sel
->tokens
));
167 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
168 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
169 unsigned export_shader
;
171 shader
->shader
.bc
.isa
= rctx
->isa
;
174 fprintf(stderr
, "--------------------------------------------------------------\n");
175 tgsi_dump(sel
->tokens
, 0);
177 if (sel
->so
.num_outputs
) {
178 r600_dump_streamout(&sel
->so
);
181 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
183 R600_ERR("translation from TGSI failed !\n");
186 if (shader
->shader
.processor_type
== PIPE_SHADER_VERTEX
) {
187 /* only disable for vertex shaders in tess paths */
191 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_CTRL
);
192 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_EVAL
);
193 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_COMPUTE
);
195 /* disable SB for shaders using doubles */
196 use_sb
&= !shader
->shader
.uses_doubles
;
198 use_sb
&= !shader
->shader
.uses_atomics
;
199 use_sb
&= !shader
->shader
.uses_images
;
201 /* Check if the bytecode has already been built. */
202 if (!shader
->shader
.bc
.bytecode
) {
203 r
= r600_bytecode_build(&shader
->shader
.bc
);
205 R600_ERR("building bytecode failed !\n");
210 if (dump
&& !sb_disasm
) {
211 fprintf(stderr
, "--------------------------------------------------------------\n");
212 r600_bytecode_disasm(&shader
->shader
.bc
);
213 fprintf(stderr
, "______________________________________________________________\n");
214 } else if ((dump
&& sb_disasm
) || use_sb
) {
215 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
218 R600_ERR("r600_sb_bytecode_process failed !\n");
223 if (shader
->gs_copy_shader
) {
226 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
227 &shader
->gs_copy_shader
->shader
, dump
, 0);
232 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
236 /* Store the shader in a buffer. */
237 if ((r
= store_shader(ctx
, shader
)))
241 switch (shader
->shader
.processor_type
) {
242 case PIPE_SHADER_TESS_CTRL
:
243 evergreen_update_hs_state(ctx
, shader
);
245 case PIPE_SHADER_TESS_EVAL
:
247 evergreen_update_es_state(ctx
, shader
);
249 evergreen_update_vs_state(ctx
, shader
);
251 case PIPE_SHADER_GEOMETRY
:
252 if (rctx
->b
.chip_class
>= EVERGREEN
) {
253 evergreen_update_gs_state(ctx
, shader
);
254 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
256 r600_update_gs_state(ctx
, shader
);
257 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
260 case PIPE_SHADER_VERTEX
:
261 export_shader
= key
.vs
.as_es
;
262 if (rctx
->b
.chip_class
>= EVERGREEN
) {
264 evergreen_update_ls_state(ctx
, shader
);
265 else if (key
.vs
.as_es
)
266 evergreen_update_es_state(ctx
, shader
);
268 evergreen_update_vs_state(ctx
, shader
);
271 r600_update_es_state(ctx
, shader
);
273 r600_update_vs_state(ctx
, shader
);
276 case PIPE_SHADER_FRAGMENT
:
277 if (rctx
->b
.chip_class
>= EVERGREEN
) {
278 evergreen_update_ps_state(ctx
, shader
);
280 r600_update_ps_state(ctx
, shader
);
283 case PIPE_SHADER_COMPUTE
:
284 evergreen_update_ls_state(ctx
, shader
);
293 r600_pipe_shader_destroy(ctx
, shader
);
297 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
299 r600_resource_reference(&shader
->bo
, NULL
);
300 r600_bytecode_clear(&shader
->shader
.bc
);
301 r600_release_command_buffer(&shader
->command_buffer
);
305 * tgsi -> r600 shader
307 struct r600_shader_tgsi_instruction
;
309 struct r600_shader_src
{
316 boolean kc_rel
; /* true if cache bank is indexed */
325 struct r600_shader_ctx
{
326 struct tgsi_shader_info info
;
327 struct tgsi_parse_context parse
;
328 const struct tgsi_token
*tokens
;
330 unsigned file_offset
[TGSI_FILE_COUNT
];
332 const struct r600_shader_tgsi_instruction
*inst_info
;
333 struct r600_bytecode
*bc
;
334 struct r600_shader
*shader
;
335 struct r600_shader_src src
[4];
338 uint32_t max_driver_temp_used
;
339 /* needed for evergreen interpolation */
340 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
341 /* evergreen/cayman also store sample mask in face register */
343 /* sample id is .w component stored in fixed point position register */
344 int fixed_pt_position_gpr
;
346 boolean clip_vertex_write
;
348 unsigned edgeflag_output
;
349 int cs_block_size_reg
;
350 int cs_grid_size_reg
;
351 bool cs_block_size_loaded
, cs_grid_size_loaded
;
353 int next_ring_offset
;
354 int gs_out_ring_offset
;
356 struct r600_shader
*gs_for_vs
;
357 int gs_export_gpr_tregs
[4];
358 int gs_rotated_input
[2];
359 const struct pipe_stream_output_info
*gs_stream_output_info
;
360 unsigned enabled_stream_buffers_mask
;
361 unsigned tess_input_info
; /* temp with tess input offsets */
362 unsigned tess_output_info
; /* temp with tess input offsets */
363 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
364 bool thread_id_gpr_loaded
;
367 struct r600_shader_tgsi_instruction
{
369 int (*process
)(struct r600_shader_ctx
*ctx
);
372 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
373 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
374 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
375 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
376 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
377 static int tgsi_else(struct r600_shader_ctx
*ctx
);
378 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
379 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
380 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
381 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
382 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
383 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
384 unsigned int dst_reg
);
385 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
386 const struct r600_shader_src
*shader_src
,
388 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
389 unsigned dst_reg
, unsigned mask
);
391 static int tgsi_last_instruction(unsigned writemask
)
395 for (i
= 0; i
< 4; i
++) {
396 if (writemask
& (1 << i
)) {
403 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
405 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
408 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
409 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
413 if (i
->Instruction
.Label
) {
414 R600_ERR("label unsupported\n");
418 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
419 if (i
->Src
[j
].Register
.Dimension
) {
420 switch (i
->Src
[j
].Register
.File
) {
421 case TGSI_FILE_CONSTANT
:
422 case TGSI_FILE_HW_ATOMIC
:
424 case TGSI_FILE_INPUT
:
425 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
426 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
427 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
429 case TGSI_FILE_OUTPUT
:
430 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
433 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
434 i
->Src
[j
].Register
.File
,
435 i
->Src
[j
].Register
.Dimension
);
440 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
441 if (i
->Dst
[j
].Register
.Dimension
) {
442 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
444 R600_ERR("unsupported dst (dimension)\n");
451 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
453 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
454 interpolate
== TGSI_INTERPOLATE_LINEAR
||
455 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
457 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
461 case TGSI_INTERPOLATE_LOC_CENTER
:
464 case TGSI_INTERPOLATE_LOC_CENTROID
:
467 case TGSI_INTERPOLATE_LOC_SAMPLE
:
472 return is_linear
* 3 + loc
;
478 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
481 int i
= eg_get_interpolator_index(
482 ctx
->shader
->input
[input
].interpolate
,
483 ctx
->shader
->input
[input
].interpolate_location
);
485 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
488 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
491 struct r600_bytecode_alu alu
;
492 int gpr
= 0, base_chan
= 0;
493 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
495 /* work out gpr and base_chan from index */
497 base_chan
= (2 * (ij_index
% 2)) + 1;
499 for (i
= 0; i
< 8; i
++) {
500 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
503 alu
.op
= ALU_OP2_INTERP_ZW
;
505 alu
.op
= ALU_OP2_INTERP_XY
;
507 if ((i
> 1) && (i
< 6)) {
508 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
512 alu
.dst
.chan
= i
% 4;
514 alu
.src
[0].sel
= gpr
;
515 alu
.src
[0].chan
= (base_chan
- (i
% 2));
517 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
519 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
522 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
529 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
532 struct r600_bytecode_alu alu
;
534 for (i
= 0; i
< 4; i
++) {
535 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
537 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
539 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
544 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
549 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
557 * Special export handling in shaders
559 * shader export ARRAY_BASE for EXPORT_POS:
562 * 62, 63 are clip distance vectors
564 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
565 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
566 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
567 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
568 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
569 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
570 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
571 * exclusive from render target index)
572 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
575 * shader export ARRAY_BASE for EXPORT_PIXEL:
577 * 61 computed Z vector
579 * The use of the values exported in the computed Z vector are controlled
580 * by DB_SHADER_CONTROL:
581 * Z_EXPORT_ENABLE - Z as a float in RED
582 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
583 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
584 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
585 * DB_SOURCE_FORMAT - export control restrictions
590 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
591 static int r600_spi_sid(struct r600_shader_io
* io
)
593 int index
, name
= io
->name
;
595 /* These params are handled differently, they don't need
596 * semantic indices, so we'll use 0 for them.
598 if (name
== TGSI_SEMANTIC_POSITION
||
599 name
== TGSI_SEMANTIC_PSIZE
||
600 name
== TGSI_SEMANTIC_EDGEFLAG
||
601 name
== TGSI_SEMANTIC_FACE
||
602 name
== TGSI_SEMANTIC_SAMPLEMASK
)
605 if (name
== TGSI_SEMANTIC_GENERIC
) {
606 /* For generic params simply use sid from tgsi */
609 /* For non-generic params - pack name and sid into 8 bits */
610 index
= 0x80 | (name
<<3) | (io
->sid
);
613 /* Make sure that all really used indices have nonzero value, so
614 * we can just compare it to 0 later instead of comparing the name
615 * with different values to detect special cases. */
622 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
623 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
625 switch (semantic_name
) {
626 case TGSI_SEMANTIC_POSITION
:
628 case TGSI_SEMANTIC_PSIZE
:
630 case TGSI_SEMANTIC_CLIPDIST
:
633 case TGSI_SEMANTIC_GENERIC
:
635 return 4 + index
- 9;
637 /* same explanation as in the default statement,
638 * the only user hitting this is st/nine.
642 /* patch indices are completely separate and thus start from 0 */
643 case TGSI_SEMANTIC_TESSOUTER
:
645 case TGSI_SEMANTIC_TESSINNER
:
647 case TGSI_SEMANTIC_PATCH
:
651 /* Don't fail here. The result of this function is only used
652 * for LS, TCS, TES, and GS, where legacy GL semantics can't
653 * occur, but this function is called for all vertex shaders
654 * before it's known whether LS will be compiled or not.
660 /* turn input into interpolate on EG */
661 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
665 if (ctx
->shader
->input
[index
].spi_sid
) {
666 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
667 if (ctx
->shader
->input
[index
].interpolate
> 0) {
668 evergreen_interp_assign_ij_index(ctx
, index
);
669 r
= evergreen_interp_alu(ctx
, index
);
671 r
= evergreen_interp_flat(ctx
, index
);
677 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
679 struct r600_bytecode_alu alu
;
681 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
682 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
684 for (i
= 0; i
< 4; i
++) {
685 memset(&alu
, 0, sizeof(alu
));
686 alu
.op
= ALU_OP3_CNDGT
;
689 alu
.dst
.sel
= gpr_front
;
690 alu
.src
[0].sel
= ctx
->face_gpr
;
691 alu
.src
[1].sel
= gpr_front
;
692 alu
.src
[2].sel
= gpr_back
;
699 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
706 /* execute a single slot ALU calculation */
707 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
708 int dst_sel
, int dst_chan
,
709 int src0_sel
, unsigned src0_chan_val
,
710 int src1_sel
, unsigned src1_chan_val
)
712 struct r600_bytecode_alu alu
;
715 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
716 for (i
= 0; i
< 4; i
++) {
717 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
719 alu
.src
[0].sel
= src0_sel
;
720 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
721 alu
.src
[0].value
= src0_chan_val
;
723 alu
.src
[0].chan
= src0_chan_val
;
724 alu
.src
[1].sel
= src1_sel
;
725 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
726 alu
.src
[1].value
= src1_chan_val
;
728 alu
.src
[1].chan
= src1_chan_val
;
729 alu
.dst
.sel
= dst_sel
;
731 alu
.dst
.write
= i
== dst_chan
;
733 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
740 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
742 alu
.src
[0].sel
= src0_sel
;
743 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
744 alu
.src
[0].value
= src0_chan_val
;
746 alu
.src
[0].chan
= src0_chan_val
;
747 alu
.src
[1].sel
= src1_sel
;
748 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
749 alu
.src
[1].value
= src1_chan_val
;
751 alu
.src
[1].chan
= src1_chan_val
;
752 alu
.dst
.sel
= dst_sel
;
753 alu
.dst
.chan
= dst_chan
;
756 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
762 /* execute a single slot ALU calculation */
763 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
764 int dst_sel
, int dst_chan
,
765 int src0_sel
, unsigned src0_chan_val
,
766 int src1_sel
, unsigned src1_chan_val
,
767 int src2_sel
, unsigned src2_chan_val
)
769 struct r600_bytecode_alu alu
;
772 /* validate this for other ops */
773 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
);
774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
776 alu
.src
[0].sel
= src0_sel
;
777 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
778 alu
.src
[0].value
= src0_chan_val
;
780 alu
.src
[0].chan
= src0_chan_val
;
781 alu
.src
[1].sel
= src1_sel
;
782 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
783 alu
.src
[1].value
= src1_chan_val
;
785 alu
.src
[1].chan
= src1_chan_val
;
786 alu
.src
[2].sel
= src2_sel
;
787 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
788 alu
.src
[2].value
= src2_chan_val
;
790 alu
.src
[2].chan
= src2_chan_val
;
791 alu
.dst
.sel
= dst_sel
;
792 alu
.dst
.chan
= dst_chan
;
795 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
801 /* put it in temp_reg.x */
802 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
804 int temp_reg
, bool is_patch_var
)
808 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
810 Dimension - patch0_offset (input_vals.z),
811 Non-dim - patch0_data_offset (input_vals.w)
813 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
815 ctx
->tess_output_info
, 0,
817 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
823 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
825 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
828 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
830 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
833 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
836 i
= ctx
->shader
->noutput
++;
837 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
838 ctx
->shader
->output
[i
].sid
= 0;
839 ctx
->shader
->output
[i
].gpr
= 0;
840 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
841 ctx
->shader
->output
[i
].write_mask
= 0x4;
842 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
847 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
849 struct r600_bytecode_alu alu
;
852 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
853 alu
.op
= ctx
->inst_info
->op
;
856 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
862 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
864 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
865 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
867 switch (d
->Declaration
.File
) {
868 case TGSI_FILE_INPUT
:
869 for (j
= 0; j
< count
; j
++) {
870 i
= ctx
->shader
->ninput
+ j
;
871 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
872 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
873 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
874 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
875 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
876 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
877 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
878 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
879 switch (ctx
->shader
->input
[i
].name
) {
880 case TGSI_SEMANTIC_FACE
:
881 if (ctx
->face_gpr
!= -1)
882 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
884 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
886 case TGSI_SEMANTIC_COLOR
:
889 case TGSI_SEMANTIC_POSITION
:
890 ctx
->fragcoord_input
= i
;
892 case TGSI_SEMANTIC_PRIMID
:
893 /* set this for now */
894 ctx
->shader
->gs_prim_id_input
= true;
895 ctx
->shader
->ps_prim_id_input
= i
;
898 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
899 if ((r
= evergreen_interp_input(ctx
, i
)))
902 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
903 /* FIXME probably skip inputs if they aren't passed in the ring */
904 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
905 ctx
->next_ring_offset
+= 16;
906 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
907 ctx
->shader
->gs_prim_id_input
= true;
910 ctx
->shader
->ninput
+= count
;
912 case TGSI_FILE_OUTPUT
:
913 for (j
= 0; j
< count
; j
++) {
914 i
= ctx
->shader
->noutput
+ j
;
915 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
916 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
917 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
918 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
919 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
920 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
921 if (ctx
->type
== PIPE_SHADER_VERTEX
||
922 ctx
->type
== PIPE_SHADER_GEOMETRY
||
923 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
924 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
925 switch (d
->Semantic
.Name
) {
926 case TGSI_SEMANTIC_CLIPDIST
:
928 case TGSI_SEMANTIC_PSIZE
:
929 ctx
->shader
->vs_out_misc_write
= 1;
930 ctx
->shader
->vs_out_point_size
= 1;
932 case TGSI_SEMANTIC_EDGEFLAG
:
933 ctx
->shader
->vs_out_misc_write
= 1;
934 ctx
->shader
->vs_out_edgeflag
= 1;
935 ctx
->edgeflag_output
= i
;
937 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
938 ctx
->shader
->vs_out_misc_write
= 1;
939 ctx
->shader
->vs_out_viewport
= 1;
941 case TGSI_SEMANTIC_LAYER
:
942 ctx
->shader
->vs_out_misc_write
= 1;
943 ctx
->shader
->vs_out_layer
= 1;
945 case TGSI_SEMANTIC_CLIPVERTEX
:
946 ctx
->clip_vertex_write
= TRUE
;
950 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
951 ctx
->gs_out_ring_offset
+= 16;
953 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
954 switch (d
->Semantic
.Name
) {
955 case TGSI_SEMANTIC_COLOR
:
956 ctx
->shader
->nr_ps_max_color_exports
++;
961 ctx
->shader
->noutput
+= count
;
963 case TGSI_FILE_TEMPORARY
:
964 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
965 if (d
->Array
.ArrayID
) {
966 r600_add_gpr_array(ctx
->shader
,
967 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
969 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
974 case TGSI_FILE_CONSTANT
:
975 case TGSI_FILE_SAMPLER
:
976 case TGSI_FILE_SAMPLER_VIEW
:
977 case TGSI_FILE_ADDRESS
:
978 case TGSI_FILE_BUFFER
:
979 case TGSI_FILE_IMAGE
:
980 case TGSI_FILE_MEMORY
:
983 case TGSI_FILE_HW_ATOMIC
:
984 i
= ctx
->shader
->nhwatomic_ranges
;
985 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
986 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
987 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
988 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
989 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
990 ctx
->shader
->nhwatomic_ranges
++;
991 ctx
->shader
->nhwatomic
+= count
;
994 case TGSI_FILE_SYSTEM_VALUE
:
995 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
996 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
997 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
998 break; /* Already handled from allocate_system_value_inputs */
999 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
1001 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1003 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1005 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1006 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1007 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1008 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1009 unsigned temp_reg
= r600_get_temp(ctx
);
1011 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1015 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1018 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1022 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
1024 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1028 for (i
= 0; i
< 2; i
++) {
1029 struct r600_bytecode_alu alu
;
1030 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1031 alu
.op
= ALU_OP1_MOV
;
1033 alu
.src
[0].chan
= 0 + i
;
1035 alu
.dst
.chan
= 0 + i
;
1037 alu
.last
= (i
== 1) ? 1 : 0;
1038 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1041 /* ADD r1.z, 1.0f, -r0.x */
1042 struct r600_bytecode_alu alu
;
1043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1044 alu
.op
= ALU_OP2_ADD
;
1045 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1047 alu
.src
[1].chan
= 0;
1053 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1056 /* ADD r1.z, r1.z, -r1.y */
1057 alu
.op
= ALU_OP2_ADD
;
1059 alu
.src
[0].chan
= 2;
1061 alu
.src
[1].chan
= 1;
1067 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1073 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1079 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1081 struct tgsi_parse_context parse
;
1085 unsigned name
, alternate_name
;
1087 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1089 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1094 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1098 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1099 while (!tgsi_parse_end_of_tokens(&parse
)) {
1100 tgsi_parse_token(&parse
);
1102 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1103 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1104 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1105 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1106 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1108 int interpolate
, location
, k
;
1110 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1111 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1112 inputs
[1].enabled
= true; /* needs SAMPLEID */
1113 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1114 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1115 /* Needs sample positions, currently those are always available */
1117 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1120 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1121 k
= eg_get_interpolator_index(interpolate
, location
);
1123 ctx
->eg_interpolators
[k
].enabled
= true;
1125 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1126 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1127 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1128 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1129 if (d
->Semantic
.Name
== inputs
[k
].name
||
1130 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1131 inputs
[k
].enabled
= true;
1138 tgsi_parse_free(&parse
);
1140 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1141 boolean enabled
= inputs
[i
].enabled
;
1142 int *reg
= inputs
[i
].reg
;
1143 unsigned name
= inputs
[i
].name
;
1146 int gpr
= gpr_offset
+ num_regs
++;
1147 ctx
->shader
->nsys_inputs
++;
1149 // add to inputs, allocate a gpr
1150 k
= ctx
->shader
->ninput
++;
1151 ctx
->shader
->input
[k
].name
= name
;
1152 ctx
->shader
->input
[k
].sid
= 0;
1153 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1154 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1155 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1159 return gpr_offset
+ num_regs
;
1163 * for evergreen we need to scan the shader to find the number of GPRs we need to
1164 * reserve for interpolation and system values
1166 * we need to know if we are going to emit
1167 * any sample or centroid inputs
1168 * if perspective and linear are required
1170 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1174 struct tgsi_parse_context parse
;
1176 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1178 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1180 /* skip position/face/mask/sampleid */
1181 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1182 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1183 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1184 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1187 k
= eg_get_interpolator_index(
1188 ctx
->info
.input_interpolate
[i
],
1189 ctx
->info
.input_interpolate_loc
[i
]);
1191 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1194 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1198 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1199 while (!tgsi_parse_end_of_tokens(&parse
)) {
1200 tgsi_parse_token(&parse
);
1202 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1203 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1204 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1205 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1206 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1208 int interpolate
, location
, k
;
1210 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1211 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1212 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1213 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1215 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1218 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1219 k
= eg_get_interpolator_index(interpolate
, location
);
1221 ctx
->eg_interpolators
[k
].enabled
= true;
1226 tgsi_parse_free(&parse
);
1228 /* assign gpr to each interpolator according to priority */
1230 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1231 if (ctx
->eg_interpolators
[i
].enabled
) {
1232 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1237 /* XXX PULL MODEL and LINE STIPPLE */
1239 num_baryc
= (num_baryc
+ 1) >> 1;
1240 return allocate_system_value_inputs(ctx
, num_baryc
);
1243 /* sample_id_sel == NULL means fetch for current sample */
1244 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1246 struct r600_bytecode_vtx vtx
;
1249 assert(ctx
->fixed_pt_position_gpr
!= -1);
1251 t1
= r600_get_temp(ctx
);
1253 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1254 vtx
.op
= FETCH_OP_VFETCH
;
1255 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1256 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1257 if (sample_id
== NULL
) {
1258 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1262 struct r600_bytecode_alu alu
;
1264 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1265 alu
.op
= ALU_OP1_MOV
;
1266 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1277 vtx
.mega_fetch_count
= 16;
1283 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1284 vtx
.num_format_all
= 2;
1285 vtx
.format_comp_all
= 1;
1286 vtx
.use_const_fields
= 0;
1288 vtx
.endian
= r600_endian_swap(32);
1289 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1291 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1298 static int load_block_grid_size(struct r600_shader_ctx
*ctx
, bool load_block
)
1300 struct r600_bytecode_vtx vtx
;
1303 if (ctx
->cs_block_size_loaded
)
1304 return ctx
->cs_block_size_reg
;
1305 if (ctx
->cs_grid_size_loaded
)
1306 return ctx
->cs_grid_size_reg
;
1308 t1
= load_block
? ctx
->cs_block_size_reg
: ctx
->cs_grid_size_reg
;
1309 struct r600_bytecode_alu alu
;
1310 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1311 alu
.op
= ALU_OP1_MOV
;
1312 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1320 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1321 vtx
.op
= FETCH_OP_VFETCH
;
1322 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1323 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1327 vtx
.mega_fetch_count
= 16;
1333 vtx
.data_format
= FMT_32_32_32_32
;
1334 vtx
.num_format_all
= 1;
1335 vtx
.format_comp_all
= 0;
1336 vtx
.use_const_fields
= 0;
1337 vtx
.offset
= load_block
? 0 : 16; // first element is size of buffer
1338 vtx
.endian
= r600_endian_swap(32);
1339 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1341 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1346 ctx
->cs_block_size_loaded
= true;
1348 ctx
->cs_grid_size_loaded
= true;
1352 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1353 const struct tgsi_full_src_register
*tgsi_src
,
1354 struct r600_shader_src
*r600_src
)
1356 memset(r600_src
, 0, sizeof(*r600_src
));
1357 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1358 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1359 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1360 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1361 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1362 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1364 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1366 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1367 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1368 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1370 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1371 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1372 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1375 index
= tgsi_src
->Register
.Index
;
1376 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1377 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1378 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1379 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1380 r600_src
->swizzle
[0] = 2; // Z value
1381 r600_src
->swizzle
[1] = 2;
1382 r600_src
->swizzle
[2] = 2;
1383 r600_src
->swizzle
[3] = 2;
1384 r600_src
->sel
= ctx
->face_gpr
;
1385 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1386 r600_src
->swizzle
[0] = 3; // W value
1387 r600_src
->swizzle
[1] = 3;
1388 r600_src
->swizzle
[2] = 3;
1389 r600_src
->swizzle
[3] = 3;
1390 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1391 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1392 r600_src
->swizzle
[0] = 0;
1393 r600_src
->swizzle
[1] = 1;
1394 r600_src
->swizzle
[2] = 4;
1395 r600_src
->swizzle
[3] = 4;
1396 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1397 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1398 r600_src
->swizzle
[0] = 3;
1399 r600_src
->swizzle
[1] = 3;
1400 r600_src
->swizzle
[2] = 3;
1401 r600_src
->swizzle
[3] = 3;
1403 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1404 r600_src
->swizzle
[0] = 0;
1405 r600_src
->swizzle
[1] = 0;
1406 r600_src
->swizzle
[2] = 0;
1407 r600_src
->swizzle
[3] = 0;
1409 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_THREAD_ID
) {
1411 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_ID
) {
1413 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1414 r600_src
->swizzle
[0] = 3;
1415 r600_src
->swizzle
[1] = 3;
1416 r600_src
->swizzle
[2] = 3;
1417 r600_src
->swizzle
[3] = 3;
1419 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1420 r600_src
->swizzle
[0] = 2;
1421 r600_src
->swizzle
[1] = 2;
1422 r600_src
->swizzle
[2] = 2;
1423 r600_src
->swizzle
[3] = 2;
1425 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1427 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1429 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1431 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1432 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1433 r600_src
->sel
= ctx
->tess_input_info
;
1434 r600_src
->swizzle
[0] = 2;
1435 r600_src
->swizzle
[1] = 2;
1436 r600_src
->swizzle
[2] = 2;
1437 r600_src
->swizzle
[3] = 2;
1439 r600_src
->sel
= ctx
->tess_input_info
;
1440 r600_src
->swizzle
[0] = 3;
1441 r600_src
->swizzle
[1] = 3;
1442 r600_src
->swizzle
[2] = 3;
1443 r600_src
->swizzle
[3] = 3;
1445 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1447 r600_src
->swizzle
[0] = 0;
1448 r600_src
->swizzle
[1] = 0;
1449 r600_src
->swizzle
[2] = 0;
1450 r600_src
->swizzle
[3] = 0;
1451 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1453 r600_src
->swizzle
[0] = 3;
1454 r600_src
->swizzle
[1] = 3;
1455 r600_src
->swizzle
[2] = 3;
1456 r600_src
->swizzle
[3] = 3;
1457 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_GRID_SIZE
) {
1458 r600_src
->sel
= load_block_grid_size(ctx
, false);
1459 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_SIZE
) {
1460 r600_src
->sel
= load_block_grid_size(ctx
, true);
1463 if (tgsi_src
->Register
.Indirect
)
1464 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1465 r600_src
->sel
= tgsi_src
->Register
.Index
;
1466 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1468 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1469 if (tgsi_src
->Register
.Dimension
) {
1470 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1471 if (tgsi_src
->Dimension
.Indirect
) {
1472 r600_src
->kc_rel
= 1;
1478 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1479 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1480 unsigned int dst_reg
)
1482 struct r600_bytecode_vtx vtx
;
1483 unsigned int ar_reg
;
1487 struct r600_bytecode_alu alu
;
1489 memset(&alu
, 0, sizeof(alu
));
1491 alu
.op
= ALU_OP2_ADD_INT
;
1492 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1493 alu
.src
[0].chan
= ar_chan
;
1495 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1496 alu
.src
[1].value
= offset
;
1498 alu
.dst
.sel
= dst_reg
;
1499 alu
.dst
.chan
= ar_chan
;
1503 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1508 ar_reg
= ctx
->bc
->ar_reg
;
1511 memset(&vtx
, 0, sizeof(vtx
));
1512 vtx
.buffer_id
= cb_idx
;
1513 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1514 vtx
.src_gpr
= ar_reg
;
1515 vtx
.src_sel_x
= ar_chan
;
1516 vtx
.mega_fetch_count
= 16;
1517 vtx
.dst_gpr
= dst_reg
;
1518 vtx
.dst_sel_x
= 0; /* SEL_X */
1519 vtx
.dst_sel_y
= 1; /* SEL_Y */
1520 vtx
.dst_sel_z
= 2; /* SEL_Z */
1521 vtx
.dst_sel_w
= 3; /* SEL_W */
1522 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1523 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1524 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1525 vtx
.endian
= r600_endian_swap(32);
1526 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1528 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1534 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1536 struct r600_bytecode_vtx vtx
;
1538 unsigned index
= src
->Register
.Index
;
1539 unsigned vtx_id
= src
->Dimension
.Index
;
1540 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1541 int offset_chan
= vtx_id
% 3;
1544 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1545 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1547 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1550 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1551 t2
= r600_get_temp(ctx
);
1553 if (src
->Dimension
.Indirect
) {
1555 struct r600_bytecode_alu alu
;
1558 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1559 if (src
->DimIndirect
.Index
> 0) {
1560 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1568 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1569 at least this is what fglrx seems to do. */
1570 for (i
= 0; i
< 3; i
++) {
1571 treg
[i
] = r600_get_temp(ctx
);
1573 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1575 for (i
= 0; i
< 3; i
++) {
1576 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1577 alu
.op
= ALU_OP1_MOV
;
1578 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1579 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1580 alu
.dst
.sel
= treg
[i
];
1584 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1588 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1589 alu
.op
= ALU_OP1_MOV
;
1590 alu
.src
[0].sel
= treg
[0];
1595 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1602 if (src
->Register
.Indirect
) {
1604 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1606 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1608 /* pull the value from index_reg */
1609 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1612 V_SQ_ALU_SRC_LITERAL
, first
);
1615 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1618 V_SQ_ALU_SRC_LITERAL
, 4,
1619 offset_reg
, offset_chan
);
1624 index
= src
->Register
.Index
- first
;
1627 memset(&vtx
, 0, sizeof(vtx
));
1628 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1629 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1630 vtx
.src_gpr
= offset_reg
;
1631 vtx
.src_sel_x
= offset_chan
;
1632 vtx
.offset
= index
* 16; /*bytes*/
1633 vtx
.mega_fetch_count
= 16;
1634 vtx
.dst_gpr
= dst_reg
;
1635 vtx
.dst_sel_x
= 0; /* SEL_X */
1636 vtx
.dst_sel_y
= 1; /* SEL_Y */
1637 vtx
.dst_sel_z
= 2; /* SEL_Z */
1638 vtx
.dst_sel_w
= 3; /* SEL_W */
1639 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1640 vtx
.use_const_fields
= 1;
1642 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1645 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1651 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1653 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1656 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1657 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1659 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1660 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1661 /* primitive id is in R0.z */
1662 ctx
->src
[i
].sel
= 0;
1663 ctx
->src
[i
].swizzle
[0] = 2;
1666 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1667 int treg
= r600_get_temp(ctx
);
1669 fetch_gs_input(ctx
, src
, treg
);
1670 ctx
->src
[i
].sel
= treg
;
1671 ctx
->src
[i
].rel
= 0;
1678 /* Tessellation shaders pass outputs to the next shader using LDS.
1680 * LS outputs = TCS(HS) inputs
1681 * TCS(HS) outputs = TES(DS) inputs
1683 * The LDS layout is:
1684 * - TCS inputs for patch 0
1685 * - TCS inputs for patch 1
1686 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1688 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1689 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1690 * - TCS outputs for patch 1
1691 * - Per-patch TCS outputs for patch 1
1692 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1693 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1696 * All three shaders VS(LS), TCS, TES share the same LDS space.
1698 /* this will return with the dw address in temp_reg.x */
1699 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1700 const struct tgsi_full_dst_register
*dst
,
1701 const struct tgsi_full_src_register
*src
,
1702 int stride_bytes_reg
, int stride_bytes_chan
)
1704 struct tgsi_full_dst_register reg
;
1705 ubyte
*name
, *index
, *array_first
;
1708 struct tgsi_shader_info
*info
= &ctx
->info
;
1709 /* Set the register description. The address computation is the same
1710 * for sources and destinations. */
1712 reg
.Register
.File
= src
->Register
.File
;
1713 reg
.Register
.Index
= src
->Register
.Index
;
1714 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1715 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1716 reg
.Indirect
= src
->Indirect
;
1717 reg
.Dimension
= src
->Dimension
;
1718 reg
.DimIndirect
= src
->DimIndirect
;
1722 /* If the register is 2-dimensional (e.g. an array of vertices
1723 * in a primitive), calculate the base address of the vertex. */
1724 if (reg
.Register
.Dimension
) {
1726 if (reg
.Dimension
.Indirect
) {
1728 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1730 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1731 /* pull the value from index_reg */
1735 sel
= V_SQ_ALU_SRC_LITERAL
;
1736 chan
= reg
.Dimension
.Index
;
1739 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1741 stride_bytes_reg
, stride_bytes_chan
,
1748 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1749 name
= info
->input_semantic_name
;
1750 index
= info
->input_semantic_index
;
1751 array_first
= info
->input_array_first
;
1752 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1753 name
= info
->output_semantic_name
;
1754 index
= info
->output_semantic_index
;
1755 array_first
= info
->output_array_first
;
1760 if (reg
.Register
.Indirect
) {
1763 /* Add the relative address of the element. */
1764 if (reg
.Indirect
.ArrayID
)
1765 first
= array_first
[reg
.Indirect
.ArrayID
];
1767 first
= reg
.Register
.Index
;
1769 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1771 /* pull the value from index_reg */
1772 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1774 V_SQ_ALU_SRC_LITERAL
, 16,
1780 param
= r600_get_lds_unique_index(name
[first
],
1784 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1785 index
[reg
.Register
.Index
]);
1788 /* add to base_addr - passed in temp_reg.x */
1790 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1793 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1801 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1802 unsigned dst_reg
, unsigned mask
)
1804 struct r600_bytecode_alu alu
;
1807 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1808 ctx
->bc
->force_add_cf
= 1;
1810 lasti
= tgsi_last_instruction(mask
);
1811 for (i
= 1; i
<= lasti
; i
++) {
1812 if (!(mask
& (1 << i
)))
1815 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1818 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1822 for (i
= 0; i
<= lasti
; i
++) {
1823 if (!(mask
& (1 << i
)))
1826 /* emit an LDS_READ_RET */
1827 memset(&alu
, 0, sizeof(alu
));
1828 alu
.op
= LDS_OP1_LDS_READ_RET
;
1829 alu
.src
[0].sel
= temp_reg
;
1830 alu
.src
[0].chan
= i
;
1831 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1832 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1834 alu
.is_lds_idx_op
= true;
1836 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1840 for (i
= 0; i
<= lasti
; i
++) {
1841 if (!(mask
& (1 << i
)))
1844 /* then read from LDS_OQ_A_POP */
1845 memset(&alu
, 0, sizeof(alu
));
1847 alu
.op
= ALU_OP1_MOV
;
1848 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1849 alu
.src
[0].chan
= 0;
1850 alu
.dst
.sel
= dst_reg
;
1854 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1861 static int fetch_mask(struct tgsi_src_register
*reg
)
1864 mask
|= 1 << reg
->SwizzleX
;
1865 mask
|= 1 << reg
->SwizzleY
;
1866 mask
|= 1 << reg
->SwizzleZ
;
1867 mask
|= 1 << reg
->SwizzleW
;
1871 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1874 unsigned temp_reg
= r600_get_temp(ctx
);
1876 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1877 src
->Register
.Dimension
? false : true);
1881 /* the base address is now in temp.x */
1882 r
= r600_get_byte_address(ctx
, temp_reg
,
1883 NULL
, src
, ctx
->tess_output_info
, 1);
1887 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1893 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1896 unsigned temp_reg
= r600_get_temp(ctx
);
1898 /* t.x = ips * r0.y */
1899 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1901 ctx
->tess_input_info
, 0,
1907 /* the base address is now in temp.x */
1908 r
= r600_get_byte_address(ctx
, temp_reg
,
1909 NULL
, src
, ctx
->tess_input_info
, 1);
1913 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1919 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1922 unsigned temp_reg
= r600_get_temp(ctx
);
1924 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1925 src
->Register
.Dimension
? false : true);
1928 /* the base address is now in temp.x */
1929 r
= r600_get_byte_address(ctx
, temp_reg
,
1931 ctx
->tess_output_info
, 1);
1935 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1941 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1943 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1946 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1947 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1949 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1950 int treg
= r600_get_temp(ctx
);
1951 fetch_tes_input(ctx
, src
, treg
);
1952 ctx
->src
[i
].sel
= treg
;
1953 ctx
->src
[i
].rel
= 0;
1955 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1956 int treg
= r600_get_temp(ctx
);
1957 fetch_tcs_input(ctx
, src
, treg
);
1958 ctx
->src
[i
].sel
= treg
;
1959 ctx
->src
[i
].rel
= 0;
1961 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1962 int treg
= r600_get_temp(ctx
);
1963 fetch_tcs_output(ctx
, src
, treg
);
1964 ctx
->src
[i
].sel
= treg
;
1965 ctx
->src
[i
].rel
= 0;
1971 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1973 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1974 struct r600_bytecode_alu alu
;
1975 int i
, j
, k
, nconst
, r
;
1977 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1978 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1981 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1983 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1984 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1988 if (ctx
->src
[i
].rel
) {
1989 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1990 int treg
= r600_get_temp(ctx
);
1991 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1994 ctx
->src
[i
].kc_bank
= 0;
1995 ctx
->src
[i
].kc_rel
= 0;
1996 ctx
->src
[i
].sel
= treg
;
1997 ctx
->src
[i
].rel
= 0;
2000 int treg
= r600_get_temp(ctx
);
2001 for (k
= 0; k
< 4; k
++) {
2002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2003 alu
.op
= ALU_OP1_MOV
;
2004 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2005 alu
.src
[0].chan
= k
;
2006 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
2007 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
2008 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
2014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2018 ctx
->src
[i
].sel
= treg
;
2026 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
2027 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
2029 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2030 struct r600_bytecode_alu alu
;
2031 int i
, j
, k
, nliteral
, r
;
2033 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2034 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2038 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2039 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2040 int treg
= r600_get_temp(ctx
);
2041 for (k
= 0; k
< 4; k
++) {
2042 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2043 alu
.op
= ALU_OP1_MOV
;
2044 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2045 alu
.src
[0].chan
= k
;
2046 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2052 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2056 ctx
->src
[i
].sel
= treg
;
2063 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2065 int i
, r
, count
= ctx
->shader
->ninput
;
2067 for (i
= 0; i
< count
; i
++) {
2068 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2069 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2077 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2078 int stream
, unsigned *stream_item_size UNUSED
)
2080 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2081 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2085 /* Sanity checking. */
2086 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2087 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2091 for (i
= 0; i
< so
->num_outputs
; i
++) {
2092 if (so
->output
[i
].output_buffer
>= 4) {
2093 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2094 so
->output
[i
].output_buffer
);
2100 /* Initialize locations where the outputs are stored. */
2101 for (i
= 0; i
< so
->num_outputs
; i
++) {
2103 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2104 start_comp
[i
] = so
->output
[i
].start_component
;
2105 /* Lower outputs with dst_offset < start_component.
2107 * We can only output 4D vectors with a write mask, e.g. we can
2108 * only output the W component at offset 3, etc. If we want
2109 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2110 * to move it to X and output X. */
2111 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2112 unsigned tmp
= r600_get_temp(ctx
);
2114 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2115 struct r600_bytecode_alu alu
;
2116 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2117 alu
.op
= ALU_OP1_MOV
;
2118 alu
.src
[0].sel
= so_gpr
[i
];
2119 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2124 if (j
== so
->output
[i
].num_components
- 1)
2126 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2135 /* Write outputs to buffers. */
2136 for (i
= 0; i
< so
->num_outputs
; i
++) {
2137 struct r600_bytecode_output output
;
2139 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2142 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2143 output
.gpr
= so_gpr
[i
];
2144 output
.elem_size
= so
->output
[i
].num_components
- 1;
2145 if (output
.elem_size
== 2)
2146 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2147 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2148 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2149 output
.burst_count
= 1;
2150 /* array_size is an upper limit for the burst_count
2151 * with MEM_STREAM instructions */
2152 output
.array_size
= 0xFFF;
2153 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2155 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2156 switch (so
->output
[i
].output_buffer
) {
2158 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2161 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2164 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2167 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2170 output
.op
+= so
->output
[i
].stream
* 4;
2171 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2172 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2174 switch (so
->output
[i
].output_buffer
) {
2176 output
.op
= CF_OP_MEM_STREAM0
;
2179 output
.op
= CF_OP_MEM_STREAM1
;
2182 output
.op
= CF_OP_MEM_STREAM2
;
2185 output
.op
= CF_OP_MEM_STREAM3
;
2188 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2190 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2199 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2201 struct r600_bytecode_alu alu
;
2204 if (!ctx
->shader
->vs_out_edgeflag
)
2207 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2209 /* clamp(x, 0, 1) */
2210 memset(&alu
, 0, sizeof(alu
));
2211 alu
.op
= ALU_OP1_MOV
;
2212 alu
.src
[0].sel
= reg
;
2217 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2219 memset(&alu
, 0, sizeof(alu
));
2220 alu
.op
= ALU_OP1_FLT_TO_INT
;
2221 alu
.src
[0].sel
= reg
;
2225 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2228 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2229 struct r600_pipe_shader
*gs
,
2230 struct pipe_stream_output_info
*so
)
2232 struct r600_shader_ctx ctx
= {};
2233 struct r600_shader
*gs_shader
= &gs
->shader
;
2234 struct r600_pipe_shader
*cshader
;
2235 unsigned ocnt
= gs_shader
->noutput
;
2236 struct r600_bytecode_alu alu
;
2237 struct r600_bytecode_vtx vtx
;
2238 struct r600_bytecode_output output
;
2239 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2240 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2241 int next_clip_pos
= 61, next_param
= 0;
2244 bool only_ring_0
= true;
2245 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2249 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2250 sizeof(struct r600_shader_io
));
2252 cshader
->shader
.noutput
= ocnt
;
2254 ctx
.shader
= &cshader
->shader
;
2255 ctx
.bc
= &ctx
.shader
->bc
;
2256 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2258 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2259 rctx
->screen
->has_compressed_msaa_texturing
);
2261 ctx
.bc
->isa
= rctx
->isa
;
2264 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2266 /* R0.x = R0.x & 0x3fffffff */
2267 memset(&alu
, 0, sizeof(alu
));
2268 alu
.op
= ALU_OP2_AND_INT
;
2269 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2270 alu
.src
[1].value
= 0x3fffffff;
2272 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2274 /* R0.y = R0.x >> 30 */
2275 memset(&alu
, 0, sizeof(alu
));
2276 alu
.op
= ALU_OP2_LSHR_INT
;
2277 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2278 alu
.src
[1].value
= 0x1e;
2282 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2284 /* fetch vertex data from GSVS ring */
2285 for (i
= 0; i
< ocnt
; ++i
) {
2286 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2289 out
->ring_offset
= i
* 16;
2291 memset(&vtx
, 0, sizeof(vtx
));
2292 vtx
.op
= FETCH_OP_VFETCH
;
2293 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2294 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2295 vtx
.mega_fetch_count
= 16;
2296 vtx
.offset
= out
->ring_offset
;
2297 vtx
.dst_gpr
= out
->gpr
;
2303 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2304 vtx
.use_const_fields
= 1;
2306 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2309 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2311 ctx
.temp_reg
= i
+ 1;
2312 for (ring
= 3; ring
>= 0; --ring
) {
2313 bool enabled
= false;
2314 for (i
= 0; i
< so
->num_outputs
; i
++) {
2315 if (so
->output
[i
].stream
== ring
) {
2318 only_ring_0
= false;
2322 if (ring
!= 0 && !enabled
) {
2323 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2328 // Patch up jump label
2329 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2330 cf_pop
= ctx
.bc
->cf_last
;
2332 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2333 cf_jump
->pop_count
= 1;
2334 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2335 cf_pop
->pop_count
= 1;
2338 /* PRED_SETE_INT __, R0.y, ring */
2339 memset(&alu
, 0, sizeof(alu
));
2340 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2341 alu
.src
[0].chan
= 1;
2342 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2343 alu
.src
[1].value
= ring
;
2344 alu
.execute_mask
= 1;
2345 alu
.update_pred
= 1;
2347 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2349 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2350 cf_jump
= ctx
.bc
->cf_last
;
2353 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2354 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2357 /* bc adds nops - copy it */
2358 if (ctx
.bc
->chip_class
== R600
) {
2359 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2360 alu
.op
= ALU_OP0_NOP
;
2362 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2364 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2367 /* export vertex data */
2368 /* XXX factor out common code with r600_shader_from_tgsi ? */
2369 for (i
= 0; i
< ocnt
; ++i
) {
2370 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2371 bool instream0
= true;
2372 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2375 for (j
= 0; j
< so
->num_outputs
; j
++) {
2376 if (so
->output
[j
].register_index
== i
) {
2377 if (so
->output
[j
].stream
== 0)
2379 if (so
->output
[j
].stream
> 0)
2385 memset(&output
, 0, sizeof(output
));
2386 output
.gpr
= out
->gpr
;
2387 output
.elem_size
= 3;
2388 output
.swizzle_x
= 0;
2389 output
.swizzle_y
= 1;
2390 output
.swizzle_z
= 2;
2391 output
.swizzle_w
= 3;
2392 output
.burst_count
= 1;
2393 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2394 output
.op
= CF_OP_EXPORT
;
2395 switch (out
->name
) {
2396 case TGSI_SEMANTIC_POSITION
:
2397 output
.array_base
= 60;
2398 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2401 case TGSI_SEMANTIC_PSIZE
:
2402 output
.array_base
= 61;
2403 if (next_clip_pos
== 61)
2405 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2406 output
.swizzle_y
= 7;
2407 output
.swizzle_z
= 7;
2408 output
.swizzle_w
= 7;
2409 ctx
.shader
->vs_out_misc_write
= 1;
2410 ctx
.shader
->vs_out_point_size
= 1;
2412 case TGSI_SEMANTIC_LAYER
:
2414 /* duplicate it as PARAM to pass to the pixel shader */
2415 output
.array_base
= next_param
++;
2416 r600_bytecode_add_output(ctx
.bc
, &output
);
2417 last_exp_param
= ctx
.bc
->cf_last
;
2419 output
.array_base
= 61;
2420 if (next_clip_pos
== 61)
2422 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2423 output
.swizzle_x
= 7;
2424 output
.swizzle_y
= 7;
2425 output
.swizzle_z
= 0;
2426 output
.swizzle_w
= 7;
2427 ctx
.shader
->vs_out_misc_write
= 1;
2428 ctx
.shader
->vs_out_layer
= 1;
2430 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2432 /* duplicate it as PARAM to pass to the pixel shader */
2433 output
.array_base
= next_param
++;
2434 r600_bytecode_add_output(ctx
.bc
, &output
);
2435 last_exp_param
= ctx
.bc
->cf_last
;
2437 output
.array_base
= 61;
2438 if (next_clip_pos
== 61)
2440 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2441 ctx
.shader
->vs_out_misc_write
= 1;
2442 ctx
.shader
->vs_out_viewport
= 1;
2443 output
.swizzle_x
= 7;
2444 output
.swizzle_y
= 7;
2445 output
.swizzle_z
= 7;
2446 output
.swizzle_w
= 0;
2448 case TGSI_SEMANTIC_CLIPDIST
:
2449 /* spi_sid is 0 for clipdistance outputs that were generated
2450 * for clipvertex - we don't need to pass them to PS */
2451 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2452 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2453 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2455 /* duplicate it as PARAM to pass to the pixel shader */
2456 output
.array_base
= next_param
++;
2457 r600_bytecode_add_output(ctx
.bc
, &output
);
2458 last_exp_param
= ctx
.bc
->cf_last
;
2460 output
.array_base
= next_clip_pos
++;
2461 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2463 case TGSI_SEMANTIC_FOG
:
2464 output
.swizzle_y
= 4; /* 0 */
2465 output
.swizzle_z
= 4; /* 0 */
2466 output
.swizzle_w
= 5; /* 1 */
2469 output
.array_base
= next_param
++;
2472 r600_bytecode_add_output(ctx
.bc
, &output
);
2473 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2474 last_exp_param
= ctx
.bc
->cf_last
;
2476 last_exp_pos
= ctx
.bc
->cf_last
;
2479 if (!last_exp_pos
) {
2480 memset(&output
, 0, sizeof(output
));
2482 output
.elem_size
= 3;
2483 output
.swizzle_x
= 7;
2484 output
.swizzle_y
= 7;
2485 output
.swizzle_z
= 7;
2486 output
.swizzle_w
= 7;
2487 output
.burst_count
= 1;
2489 output
.op
= CF_OP_EXPORT
;
2490 output
.array_base
= 60;
2491 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2492 r600_bytecode_add_output(ctx
.bc
, &output
);
2493 last_exp_pos
= ctx
.bc
->cf_last
;
2496 if (!last_exp_param
) {
2497 memset(&output
, 0, sizeof(output
));
2499 output
.elem_size
= 3;
2500 output
.swizzle_x
= 7;
2501 output
.swizzle_y
= 7;
2502 output
.swizzle_z
= 7;
2503 output
.swizzle_w
= 7;
2504 output
.burst_count
= 1;
2506 output
.op
= CF_OP_EXPORT
;
2507 output
.array_base
= next_param
++;
2508 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2509 r600_bytecode_add_output(ctx
.bc
, &output
);
2510 last_exp_param
= ctx
.bc
->cf_last
;
2513 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2514 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2516 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2517 cf_pop
= ctx
.bc
->cf_last
;
2519 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2520 cf_jump
->pop_count
= 1;
2521 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2522 cf_pop
->pop_count
= 1;
2524 if (ctx
.bc
->chip_class
== CAYMAN
)
2525 cm_bytecode_add_cf_end(ctx
.bc
);
2527 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2528 ctx
.bc
->cf_last
->end_of_program
= 1;
2531 gs
->gs_copy_shader
= cshader
;
2532 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2536 return r600_bytecode_build(ctx
.bc
);
2539 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2542 struct r600_bytecode_alu alu
;
2545 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2546 alu
.op
= ALU_OP2_ADD_INT
;
2547 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2548 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2549 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2550 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2553 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2560 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2562 struct r600_bytecode_output output
;
2565 int effective_stream
= stream
== -1 ? 0 : stream
;
2568 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2569 if (ctx
->gs_for_vs
) {
2570 /* for ES we need to lookup corresponding ring offset expected by GS
2571 * (map this output to GS input by name and sid) */
2572 /* FIXME precompute offsets */
2574 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2575 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2576 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2577 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2578 ring_offset
= in
->ring_offset
;
2581 if (ring_offset
== -1)
2584 ring_offset
= idx
* 16;
2588 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2590 /* next_ring_offset after parsing input decls contains total size of
2591 * single vertex data, gs_next_vertex - current vertex index */
2593 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2595 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2596 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2597 output
.elem_size
= 3;
2598 output
.comp_mask
= 0xF;
2599 output
.burst_count
= 1;
2602 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2604 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2609 output
.op
= CF_OP_MEM_RING
; break;
2611 output
.op
= CF_OP_MEM_RING1
; break;
2613 output
.op
= CF_OP_MEM_RING2
; break;
2615 output
.op
= CF_OP_MEM_RING3
; break;
2619 output
.array_base
= ring_offset
>> 2; /* in dwords */
2620 output
.array_size
= 0xfff;
2621 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2623 output
.array_base
= ring_offset
>> 2; /* in dwords */
2624 r600_bytecode_add_output(ctx
->bc
, &output
);
2627 ++ctx
->gs_next_vertex
;
2632 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2635 struct r600_bytecode_vtx vtx
;
2636 int temp_val
= ctx
->temp_reg
;
2637 /* need to store the TCS output somewhere */
2638 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2640 V_SQ_ALU_SRC_LITERAL
, 0,
2645 /* used by VS/TCS */
2646 if (ctx
->tess_input_info
) {
2647 /* fetch tcs input values into resv space */
2648 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2649 vtx
.op
= FETCH_OP_VFETCH
;
2650 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2651 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2652 vtx
.mega_fetch_count
= 16;
2653 vtx
.data_format
= FMT_32_32_32_32
;
2654 vtx
.num_format_all
= 2;
2655 vtx
.format_comp_all
= 1;
2656 vtx
.use_const_fields
= 0;
2657 vtx
.endian
= r600_endian_swap(32);
2658 vtx
.srf_mode_all
= 1;
2660 vtx
.dst_gpr
= ctx
->tess_input_info
;
2665 vtx
.src_gpr
= temp_val
;
2668 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2673 /* used by TCS/TES */
2674 if (ctx
->tess_output_info
) {
2675 /* fetch tcs output values into resv space */
2676 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2677 vtx
.op
= FETCH_OP_VFETCH
;
2678 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2679 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2680 vtx
.mega_fetch_count
= 16;
2681 vtx
.data_format
= FMT_32_32_32_32
;
2682 vtx
.num_format_all
= 2;
2683 vtx
.format_comp_all
= 1;
2684 vtx
.use_const_fields
= 0;
2685 vtx
.endian
= r600_endian_swap(32);
2686 vtx
.srf_mode_all
= 1;
2688 vtx
.dst_gpr
= ctx
->tess_output_info
;
2693 vtx
.src_gpr
= temp_val
;
2696 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2703 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2709 /* fetch tcs input values into input_vals */
2710 ctx
->tess_input_info
= r600_get_temp(ctx
);
2711 ctx
->tess_output_info
= 0;
2712 r
= r600_fetch_tess_io_info(ctx
);
2716 temp_reg
= r600_get_temp(ctx
);
2717 /* dst reg contains LDS address stride * idx */
2718 /* MUL vertexID, vertex_dw_stride */
2719 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2721 ctx
->tess_input_info
, 1,
2722 0, 1); /* rel id in r0.y? */
2726 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2727 struct r600_bytecode_alu alu
;
2728 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2731 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2734 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2739 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2741 temp_reg
, param
? 1 : 0,
2742 V_SQ_ALU_SRC_LITERAL
, 8);
2747 for (j
= 0; j
< 2; j
++) {
2748 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2749 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2750 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2751 alu
.src
[0].sel
= temp_reg
;
2752 alu
.src
[0].chan
= chan
;
2753 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2754 alu
.src
[1].chan
= j
* 2;
2755 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2756 alu
.src
[2].chan
= (j
* 2) + 1;
2760 alu
.is_lds_idx_op
= true;
2761 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2769 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2771 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2772 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2774 int temp_reg
= r600_get_temp(ctx
);
2775 struct r600_bytecode_alu alu
;
2776 unsigned write_mask
= dst
->Register
.WriteMask
;
2778 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2781 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2785 /* the base address is now in temp.x */
2786 r
= r600_get_byte_address(ctx
, temp_reg
,
2787 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2792 lasti
= tgsi_last_instruction(write_mask
);
2793 for (i
= 1; i
<= lasti
; i
++) {
2795 if (!(write_mask
& (1 << i
)))
2797 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2800 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2805 for (i
= 0; i
<= lasti
; i
++) {
2806 if (!(write_mask
& (1 << i
)))
2809 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2810 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2811 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2812 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2813 alu
.src
[0].sel
= temp_reg
;
2814 alu
.src
[0].chan
= i
;
2816 alu
.src
[1].sel
= dst
->Register
.Index
;
2817 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2818 alu
.src
[1].chan
= i
;
2820 alu
.src
[2].sel
= dst
->Register
.Index
;
2821 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2822 alu
.src
[2].chan
= i
+ 1;
2826 alu
.is_lds_idx_op
= true;
2827 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2833 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2834 alu
.op
= LDS_OP2_LDS_WRITE
;
2835 alu
.src
[0].sel
= temp_reg
;
2836 alu
.src
[0].chan
= i
;
2838 alu
.src
[1].sel
= dst
->Register
.Index
;
2839 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2840 alu
.src
[1].chan
= i
;
2842 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2845 alu
.is_lds_idx_op
= true;
2846 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2853 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2854 int output_idx
, int nc
)
2857 unsigned temp_reg
= r600_get_temp(ctx
);
2858 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2859 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2862 param
= r600_get_lds_unique_index(name
, 0);
2863 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2867 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2870 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2874 do_lds_fetch_values(ctx
, temp_reg
, dreg
, ((1u << nc
) - 1));
2878 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2880 int stride
, outer_comps
, inner_comps
;
2881 int tessinner_idx
= -1, tessouter_idx
= -1;
2884 int temp_reg
= r600_get_temp(ctx
);
2885 int treg
[3] = {-1, -1, -1};
2886 struct r600_bytecode_alu alu
;
2887 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2889 /* only execute factor emission for invocation 0 */
2890 /* PRED_SETE_INT __, R0.x, 0 */
2891 memset(&alu
, 0, sizeof(alu
));
2892 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2893 alu
.src
[0].chan
= 2;
2894 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2895 alu
.execute_mask
= 1;
2896 alu
.update_pred
= 1;
2898 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2900 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2901 cf_jump
= ctx
->bc
->cf_last
;
2903 treg
[0] = r600_get_temp(ctx
);
2904 switch (ctx
->shader
->tcs_prim_mode
) {
2905 case PIPE_PRIM_LINES
:
2906 stride
= 8; /* 2 dwords, 1 vec2 store */
2910 case PIPE_PRIM_TRIANGLES
:
2911 stride
= 16; /* 4 dwords, 1 vec4 store */
2914 treg
[1] = r600_get_temp(ctx
);
2916 case PIPE_PRIM_QUADS
:
2917 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2920 treg
[1] = r600_get_temp(ctx
);
2921 treg
[2] = r600_get_temp(ctx
);
2928 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2929 /* TF_WRITE takes index in R.x, value in R.y */
2930 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
2931 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
2933 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
2937 if (tessouter_idx
== -1)
2940 if (tessinner_idx
== -1 && inner_comps
)
2943 if (tessouter_idx
!= -1) {
2944 r
= r600_tess_factor_read(ctx
, tessouter_idx
, outer_comps
);
2949 if (tessinner_idx
!= -1) {
2950 r
= r600_tess_factor_read(ctx
, tessinner_idx
, inner_comps
);
2955 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2956 /* r.x = relpatchid(r0.y) * tf_stride */
2958 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2959 /* add incoming r0.w to it: t.x = t.x + r0.w */
2960 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2963 V_SQ_ALU_SRC_LITERAL
, stride
,
2968 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2969 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2970 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2972 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
2975 else if (out_comp
== 0)
2979 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2980 treg
[i
/ 2], (2 * (i
% 2)),
2982 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2985 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2986 treg
[i
/ 2], 1 + (2 * (i
%2)),
2987 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
2992 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2993 struct r600_bytecode_gds gds
;
2995 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
2996 gds
.src_gpr
= treg
[i
/ 2];
2997 gds
.src_sel_x
= 2 * (i
% 2);
2998 gds
.src_sel_y
= 1 + (2 * (i
% 2));
3004 gds
.op
= FETCH_OP_TF_WRITE
;
3005 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
3010 // Patch up jump label
3011 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
3012 cf_pop
= ctx
->bc
->cf_last
;
3014 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
3015 cf_jump
->pop_count
= 1;
3016 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
3017 cf_pop
->pop_count
= 1;
3023 * We have to work out the thread ID for load and atomic
3024 * operations, which store the returned value to an index
3025 * in an intermediate buffer.
3026 * The index is calculated by taking the thread id,
3027 * calculated from the MBCNT instructions.
3028 * Then the shader engine ID is multiplied by 256,
3029 * and the wave id is added.
3030 * Then the result is multipled by 64 and thread id is
3033 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
3035 struct r600_bytecode_alu alu
;
3038 if (ctx
->thread_id_gpr_loaded
)
3041 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3042 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
3043 alu
.dst
.sel
= ctx
->temp_reg
;
3045 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3046 alu
.src
[0].value
= 0xffffffff;
3048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3053 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3054 alu
.dst
.sel
= ctx
->temp_reg
;
3056 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3057 alu
.src
[0].value
= 0xffffffff;
3059 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3064 alu
.op
= ALU_OP3_MULADD_UINT24
;
3065 alu
.dst
.sel
= ctx
->temp_reg
;
3067 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3068 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3069 alu
.src
[1].value
= 256;
3070 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3078 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3079 ctx
->thread_id_gpr
, 1,
3081 V_SQ_ALU_SRC_LITERAL
, 0x40,
3085 ctx
->thread_id_gpr_loaded
= true;
3089 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3090 struct r600_pipe_shader
*pipeshader
,
3091 union r600_shader_key key
)
3093 struct r600_screen
*rscreen
= rctx
->screen
;
3094 struct r600_shader
*shader
= &pipeshader
->shader
;
3095 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3096 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3097 struct tgsi_full_immediate
*immediate
;
3098 struct r600_shader_ctx ctx
;
3099 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3100 unsigned output_done
, noutput
;
3104 int next_param_base
= 0, next_clip_base
;
3105 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3107 bool ring_outputs
= false;
3108 bool lds_outputs
= false;
3109 bool lds_inputs
= false;
3110 bool pos_emitted
= false;
3112 ctx
.bc
= &shader
->bc
;
3113 ctx
.shader
= shader
;
3115 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3116 rscreen
->has_compressed_msaa_texturing
);
3117 ctx
.tokens
= tokens
;
3118 tgsi_scan_shader(tokens
, &ctx
.info
);
3119 shader
->indirect_files
= ctx
.info
.indirect_files
;
3121 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3122 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3123 shader
->nsys_inputs
= 0;
3125 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3126 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3127 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3128 tgsi_parse_init(&ctx
.parse
, tokens
);
3129 ctx
.type
= ctx
.info
.processor
;
3130 shader
->processor_type
= ctx
.type
;
3131 ctx
.bc
->type
= shader
->processor_type
;
3134 case PIPE_SHADER_VERTEX
:
3135 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3136 shader
->vs_as_es
= key
.vs
.as_es
;
3137 shader
->vs_as_ls
= key
.vs
.as_ls
;
3138 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3139 if (shader
->vs_as_es
)
3140 ring_outputs
= true;
3141 if (shader
->vs_as_ls
)
3144 case PIPE_SHADER_GEOMETRY
:
3145 ring_outputs
= true;
3146 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3147 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3149 case PIPE_SHADER_TESS_CTRL
:
3150 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3151 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3155 case PIPE_SHADER_TESS_EVAL
:
3156 shader
->tes_as_es
= key
.tes
.as_es
;
3157 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3159 if (shader
->tes_as_es
)
3160 ring_outputs
= true;
3162 case PIPE_SHADER_FRAGMENT
:
3163 shader
->two_side
= key
.ps
.color_two_side
;
3164 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3165 shader
->rat_base
= key
.ps
.nr_cbufs
;
3166 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3168 case PIPE_SHADER_COMPUTE
:
3169 shader
->rat_base
= 0;
3170 shader
->image_size_const_offset
= 0;
3176 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3177 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3179 ctx
.gs_for_vs
= NULL
;
3182 ctx
.next_ring_offset
= 0;
3183 ctx
.gs_out_ring_offset
= 0;
3184 ctx
.gs_next_vertex
= 0;
3185 ctx
.gs_stream_output_info
= &so
;
3188 ctx
.fixed_pt_position_gpr
= -1;
3189 ctx
.fragcoord_input
= -1;
3190 ctx
.colors_used
= 0;
3191 ctx
.clip_vertex_write
= 0;
3192 ctx
.thread_id_gpr_loaded
= false;
3194 ctx
.cs_block_size_reg
= -1;
3195 ctx
.cs_grid_size_reg
= -1;
3196 ctx
.cs_block_size_loaded
= false;
3197 ctx
.cs_grid_size_loaded
= false;
3199 shader
->nr_ps_color_exports
= 0;
3200 shader
->nr_ps_max_color_exports
= 0;
3203 /* register allocations */
3204 /* Values [0,127] correspond to GPR[0..127].
3205 * Values [128,159] correspond to constant buffer bank 0
3206 * Values [160,191] correspond to constant buffer bank 1
3207 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3208 * Values [256,287] correspond to constant buffer bank 2 (EG)
3209 * Values [288,319] correspond to constant buffer bank 3 (EG)
3210 * Other special values are shown in the list below.
3211 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3212 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3213 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3214 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3215 * 248 SQ_ALU_SRC_0: special constant 0.0.
3216 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3217 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3218 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3219 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3220 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3221 * 254 SQ_ALU_SRC_PV: previous vector result.
3222 * 255 SQ_ALU_SRC_PS: previous scalar result.
3224 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3225 ctx
.file_offset
[i
] = 0;
3228 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3230 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3231 if (ctx
.info
.num_inputs
)
3232 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3234 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3235 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3236 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3238 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3240 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3241 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3242 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3244 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3245 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3246 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3247 bool add_tesscoord
= false, add_tess_inout
= false;
3248 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3249 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3250 /* if we have tesscoord save one reg */
3251 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3252 add_tesscoord
= true;
3253 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3254 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3255 add_tess_inout
= true;
3257 if (add_tesscoord
|| add_tess_inout
)
3258 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3260 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3262 if (ctx
.type
== PIPE_SHADER_COMPUTE
) {
3263 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3264 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3265 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_GRID_SIZE
)
3266 ctx
.cs_grid_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3267 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_BLOCK_SIZE
)
3268 ctx
.cs_block_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3272 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3273 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3274 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3275 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3276 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3278 /* Outside the GPR range. This will be translated to one of the
3279 * kcache banks later. */
3280 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3282 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3283 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3284 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3285 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3286 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3288 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3289 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3290 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3291 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3292 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3293 ctx
.tess_input_info
= 0;
3294 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3295 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3296 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3297 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3298 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3299 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3300 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3301 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3302 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3303 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3304 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3307 ctx
.gs_rotated_input
[0] = 0;
3308 ctx
.gs_rotated_input
[1] = 1;
3311 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3314 if (shader
->uses_images
) {
3315 ctx
.thread_id_gpr
= ctx
.temp_reg
++;
3316 ctx
.thread_id_gpr_loaded
= false;
3319 shader
->max_arrays
= 0;
3320 shader
->num_arrays
= 0;
3321 if (indirect_gprs
) {
3323 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3324 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3325 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3326 ctx
.file_offset
[TGSI_FILE_INPUT
],
3329 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3330 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3331 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3332 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3338 ctx
.literals
= NULL
;
3339 ctx
.max_driver_temp_used
= 0;
3341 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3342 ctx
.info
.colors_written
== 1;
3343 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3344 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3346 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3347 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3348 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3349 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3350 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3351 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3352 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3355 if (shader
->vs_as_gs_a
)
3356 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3358 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3359 r600_fetch_tess_io_info(&ctx
);
3361 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3362 tgsi_parse_token(&ctx
.parse
);
3363 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3364 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3365 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3366 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3367 if(ctx
.literals
== NULL
) {
3371 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3372 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3373 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3374 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3377 case TGSI_TOKEN_TYPE_DECLARATION
:
3378 r
= tgsi_declaration(&ctx
);
3382 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3383 case TGSI_TOKEN_TYPE_PROPERTY
:
3386 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3392 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3393 shader
->ring_item_sizes
[1] = 0;
3394 shader
->ring_item_sizes
[2] = 0;
3395 shader
->ring_item_sizes
[3] = 0;
3397 /* Process two side if needed */
3398 if (shader
->two_side
&& ctx
.colors_used
) {
3399 int i
, count
= ctx
.shader
->ninput
;
3400 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3402 /* additional inputs will be allocated right after the existing inputs,
3403 * we won't need them after the color selection, so we don't need to
3404 * reserve these gprs for the rest of the shader code and to adjust
3405 * output offsets etc. */
3406 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3407 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3409 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3410 if (ctx
.face_gpr
== -1) {
3411 i
= ctx
.shader
->ninput
++;
3412 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3413 ctx
.shader
->input
[i
].spi_sid
= 0;
3414 ctx
.shader
->input
[i
].gpr
= gpr
++;
3415 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3418 for (i
= 0; i
< count
; i
++) {
3419 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3420 int ni
= ctx
.shader
->ninput
++;
3421 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3422 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3423 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3424 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3425 // TGSI to LLVM needs to know the lds position of inputs.
3426 // Non LLVM path computes it later (in process_twoside_color)
3427 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3428 ctx
.shader
->input
[i
].back_color_input
= ni
;
3429 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3430 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3437 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3438 shader
->nr_ps_max_color_exports
= 8;
3440 if (ctx
.fragcoord_input
>= 0) {
3441 if (ctx
.bc
->chip_class
== CAYMAN
) {
3442 for (j
= 0 ; j
< 4; j
++) {
3443 struct r600_bytecode_alu alu
;
3444 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3445 alu
.op
= ALU_OP1_RECIP_IEEE
;
3446 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3447 alu
.src
[0].chan
= 3;
3449 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3451 alu
.dst
.write
= (j
== 3);
3453 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3457 struct r600_bytecode_alu alu
;
3458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3459 alu
.op
= ALU_OP1_RECIP_IEEE
;
3460 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3461 alu
.src
[0].chan
= 3;
3463 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3467 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3472 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3473 struct r600_bytecode_alu alu
;
3476 /* GS thread with no output workaround - emit a cut at start of GS */
3477 if (ctx
.bc
->chip_class
== R600
)
3478 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3480 for (j
= 0; j
< 4; j
++) {
3481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3482 alu
.op
= ALU_OP1_MOV
;
3483 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3484 alu
.src
[0].value
= 0;
3485 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3488 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3493 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3494 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3495 ctx
.gs_rotated_input
[0], 2,
3497 V_SQ_ALU_SRC_LITERAL
, 1);
3501 for (i
= 0; i
< 6; i
++) {
3502 int rotated
= (i
+ 4) % 6;
3503 int offset_reg
= i
/ 3;
3504 int offset_chan
= i
% 3;
3505 int rotated_offset_reg
= rotated
/ 3;
3506 int rotated_offset_chan
= rotated
% 3;
3508 if (offset_reg
== 0 && offset_chan
== 2)
3510 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3511 rotated_offset_chan
= 3;
3513 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3514 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3515 ctx
.gs_rotated_input
[0], 2,
3516 offset_reg
, offset_chan
,
3517 rotated_offset_reg
, rotated_offset_chan
);
3524 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3525 r600_fetch_tess_io_info(&ctx
);
3527 if (shader
->two_side
&& ctx
.colors_used
) {
3528 if ((r
= process_twoside_color_inputs(&ctx
)))
3532 tgsi_parse_init(&ctx
.parse
, tokens
);
3533 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3534 tgsi_parse_token(&ctx
.parse
);
3535 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3536 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3537 r
= tgsi_is_supported(&ctx
);
3540 ctx
.max_driver_temp_used
= 0;
3541 /* reserve first tmp for everyone */
3542 r600_get_temp(&ctx
);
3544 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3545 if ((r
= tgsi_split_constant(&ctx
)))
3547 if ((r
= tgsi_split_literal_constant(&ctx
)))
3549 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3550 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3552 } else if (lds_inputs
) {
3553 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3556 if (ctx
.bc
->chip_class
== CAYMAN
)
3557 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3558 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3559 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3561 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3562 r
= ctx
.inst_info
->process(&ctx
);
3566 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3567 r
= r600_store_tcs_output(&ctx
);
3577 /* Reset the temporary register counter. */
3578 ctx
.max_driver_temp_used
= 0;
3580 noutput
= shader
->noutput
;
3582 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3583 unsigned clipdist_temp
[2];
3585 clipdist_temp
[0] = r600_get_temp(&ctx
);
3586 clipdist_temp
[1] = r600_get_temp(&ctx
);
3588 /* need to convert a clipvertex write into clipdistance writes and not export
3589 the clip vertex anymore */
3591 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3592 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3593 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3595 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3596 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3599 /* reset spi_sid for clipvertex output to avoid confusing spi */
3600 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3602 shader
->clip_dist_write
= 0xFF;
3603 shader
->cc_dist_mask
= 0xFF;
3605 for (i
= 0; i
< 8; i
++) {
3609 for (j
= 0; j
< 4; j
++) {
3610 struct r600_bytecode_alu alu
;
3611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3612 alu
.op
= ALU_OP2_DOT4
;
3613 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3614 alu
.src
[0].chan
= j
;
3616 alu
.src
[1].sel
= 512 + i
;
3617 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3618 alu
.src
[1].chan
= j
;
3620 alu
.dst
.sel
= clipdist_temp
[oreg
];
3622 alu
.dst
.write
= (j
== ochan
);
3625 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3632 /* Add stream outputs. */
3633 if (so
.num_outputs
) {
3635 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3637 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3640 emit_streamout(&ctx
, &so
, -1, NULL
);
3642 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3643 convert_edgeflag_to_int(&ctx
);
3645 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3646 r600_emit_tess_factor(&ctx
);
3649 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3650 if (ctx
.shader
->noutput
)
3651 emit_lds_vs_writes(&ctx
);
3653 } else if (ring_outputs
) {
3654 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3655 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3656 ctx
.gs_export_gpr_tregs
[1] = -1;
3657 ctx
.gs_export_gpr_tregs
[2] = -1;
3658 ctx
.gs_export_gpr_tregs
[3] = -1;
3660 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3664 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3666 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3667 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3668 output
[j
].gpr
= shader
->output
[i
].gpr
;
3669 output
[j
].elem_size
= 3;
3670 output
[j
].swizzle_x
= 0;
3671 output
[j
].swizzle_y
= 1;
3672 output
[j
].swizzle_z
= 2;
3673 output
[j
].swizzle_w
= 3;
3674 output
[j
].burst_count
= 1;
3675 output
[j
].type
= 0xffffffff;
3676 output
[j
].op
= CF_OP_EXPORT
;
3678 case PIPE_SHADER_VERTEX
:
3679 case PIPE_SHADER_TESS_EVAL
:
3680 switch (shader
->output
[i
].name
) {
3681 case TGSI_SEMANTIC_POSITION
:
3682 output
[j
].array_base
= 60;
3683 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3687 case TGSI_SEMANTIC_PSIZE
:
3688 output
[j
].array_base
= 61;
3689 output
[j
].swizzle_y
= 7;
3690 output
[j
].swizzle_z
= 7;
3691 output
[j
].swizzle_w
= 7;
3692 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3695 case TGSI_SEMANTIC_EDGEFLAG
:
3696 output
[j
].array_base
= 61;
3697 output
[j
].swizzle_x
= 7;
3698 output
[j
].swizzle_y
= 0;
3699 output
[j
].swizzle_z
= 7;
3700 output
[j
].swizzle_w
= 7;
3701 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3704 case TGSI_SEMANTIC_LAYER
:
3705 /* spi_sid is 0 for outputs that are
3706 * not consumed by PS */
3707 if (shader
->output
[i
].spi_sid
) {
3708 output
[j
].array_base
= next_param_base
++;
3709 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3711 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3713 output
[j
].array_base
= 61;
3714 output
[j
].swizzle_x
= 7;
3715 output
[j
].swizzle_y
= 7;
3716 output
[j
].swizzle_z
= 0;
3717 output
[j
].swizzle_w
= 7;
3718 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3721 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3722 /* spi_sid is 0 for outputs that are
3723 * not consumed by PS */
3724 if (shader
->output
[i
].spi_sid
) {
3725 output
[j
].array_base
= next_param_base
++;
3726 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3728 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3730 output
[j
].array_base
= 61;
3731 output
[j
].swizzle_x
= 7;
3732 output
[j
].swizzle_y
= 7;
3733 output
[j
].swizzle_z
= 7;
3734 output
[j
].swizzle_w
= 0;
3735 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3738 case TGSI_SEMANTIC_CLIPVERTEX
:
3741 case TGSI_SEMANTIC_CLIPDIST
:
3742 output
[j
].array_base
= next_clip_base
++;
3743 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3745 /* spi_sid is 0 for clipdistance outputs that were generated
3746 * for clipvertex - we don't need to pass them to PS */
3747 if (shader
->output
[i
].spi_sid
) {
3749 /* duplicate it as PARAM to pass to the pixel shader */
3750 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3751 output
[j
].array_base
= next_param_base
++;
3752 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3755 case TGSI_SEMANTIC_FOG
:
3756 output
[j
].swizzle_y
= 4; /* 0 */
3757 output
[j
].swizzle_z
= 4; /* 0 */
3758 output
[j
].swizzle_w
= 5; /* 1 */
3760 case TGSI_SEMANTIC_PRIMID
:
3761 output
[j
].swizzle_x
= 2;
3762 output
[j
].swizzle_y
= 4; /* 0 */
3763 output
[j
].swizzle_z
= 4; /* 0 */
3764 output
[j
].swizzle_w
= 4; /* 0 */
3769 case PIPE_SHADER_FRAGMENT
:
3770 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3771 /* never export more colors than the number of CBs */
3772 if (shader
->output
[i
].sid
>= max_color_exports
) {
3777 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3778 output
[j
].array_base
= shader
->output
[i
].sid
;
3779 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3780 shader
->nr_ps_color_exports
++;
3781 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3782 for (k
= 1; k
< max_color_exports
; k
++) {
3784 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3785 output
[j
].gpr
= shader
->output
[i
].gpr
;
3786 output
[j
].elem_size
= 3;
3787 output
[j
].swizzle_x
= 0;
3788 output
[j
].swizzle_y
= 1;
3789 output
[j
].swizzle_z
= 2;
3790 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3791 output
[j
].burst_count
= 1;
3792 output
[j
].array_base
= k
;
3793 output
[j
].op
= CF_OP_EXPORT
;
3794 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3795 shader
->nr_ps_color_exports
++;
3798 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3799 output
[j
].array_base
= 61;
3800 output
[j
].swizzle_x
= 2;
3801 output
[j
].swizzle_y
= 7;
3802 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3803 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3804 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3805 output
[j
].array_base
= 61;
3806 output
[j
].swizzle_x
= 7;
3807 output
[j
].swizzle_y
= 1;
3808 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3809 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3810 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3811 output
[j
].array_base
= 61;
3812 output
[j
].swizzle_x
= 7;
3813 output
[j
].swizzle_y
= 7;
3814 output
[j
].swizzle_z
= 0;
3815 output
[j
].swizzle_w
= 7;
3816 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3818 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3823 case PIPE_SHADER_TESS_CTRL
:
3826 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3831 if (output
[j
].type
== 0xffffffff) {
3832 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3833 output
[j
].array_base
= next_param_base
++;
3837 /* add fake position export */
3838 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3839 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3841 output
[j
].elem_size
= 3;
3842 output
[j
].swizzle_x
= 7;
3843 output
[j
].swizzle_y
= 7;
3844 output
[j
].swizzle_z
= 7;
3845 output
[j
].swizzle_w
= 7;
3846 output
[j
].burst_count
= 1;
3847 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3848 output
[j
].array_base
= 60;
3849 output
[j
].op
= CF_OP_EXPORT
;
3853 /* add fake param output for vertex shader if no param is exported */
3854 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3855 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3857 output
[j
].elem_size
= 3;
3858 output
[j
].swizzle_x
= 7;
3859 output
[j
].swizzle_y
= 7;
3860 output
[j
].swizzle_z
= 7;
3861 output
[j
].swizzle_w
= 7;
3862 output
[j
].burst_count
= 1;
3863 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3864 output
[j
].array_base
= 0;
3865 output
[j
].op
= CF_OP_EXPORT
;
3869 /* add fake pixel export */
3870 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3871 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3873 output
[j
].elem_size
= 3;
3874 output
[j
].swizzle_x
= 7;
3875 output
[j
].swizzle_y
= 7;
3876 output
[j
].swizzle_z
= 7;
3877 output
[j
].swizzle_w
= 7;
3878 output
[j
].burst_count
= 1;
3879 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3880 output
[j
].array_base
= 0;
3881 output
[j
].op
= CF_OP_EXPORT
;
3883 shader
->nr_ps_color_exports
++;
3888 /* set export done on last export of each type */
3889 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
3890 if (!(output_done
& (1 << output
[k
].type
))) {
3891 output_done
|= (1 << output
[k
].type
);
3892 output
[k
].op
= CF_OP_EXPORT_DONE
;
3895 /* add output to bytecode */
3896 for (i
= 0; i
< noutput
; i
++) {
3897 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3903 /* add program end */
3904 if (ctx
.bc
->chip_class
== CAYMAN
)
3905 cm_bytecode_add_cf_end(ctx
.bc
);
3907 const struct cf_op_info
*last
= NULL
;
3909 if (ctx
.bc
->cf_last
)
3910 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3912 /* alu clause instructions don't have EOP bit, so add NOP */
3913 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
3914 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3916 ctx
.bc
->cf_last
->end_of_program
= 1;
3919 /* check GPR limit - we have 124 = 128 - 4
3920 * (4 are reserved as alu clause temporary registers) */
3921 if (ctx
.bc
->ngpr
> 124) {
3922 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3927 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3928 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3933 tgsi_parse_free(&ctx
.parse
);
3937 tgsi_parse_free(&ctx
.parse
);
3941 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3943 const unsigned tgsi_opcode
=
3944 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3945 R600_ERR("%s tgsi opcode unsupported\n",
3946 tgsi_get_opcode_name(tgsi_opcode
));
3950 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
3955 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3956 const struct r600_shader_src
*shader_src
,
3959 bc_src
->sel
= shader_src
->sel
;
3960 bc_src
->chan
= shader_src
->swizzle
[chan
];
3961 bc_src
->neg
= shader_src
->neg
;
3962 bc_src
->abs
= shader_src
->abs
;
3963 bc_src
->rel
= shader_src
->rel
;
3964 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3965 bc_src
->kc_bank
= shader_src
->kc_bank
;
3966 bc_src
->kc_rel
= shader_src
->kc_rel
;
3969 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3975 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3977 bc_src
->neg
= !bc_src
->neg
;
3980 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3981 const struct tgsi_full_dst_register
*tgsi_dst
,
3983 struct r600_bytecode_alu_dst
*r600_dst
)
3985 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3987 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
3988 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
3989 r600_dst
->chan
= swizzle
;
3990 r600_dst
->write
= 1;
3991 if (inst
->Instruction
.Saturate
) {
3992 r600_dst
->clamp
= 1;
3994 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
3995 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
3999 if (tgsi_dst
->Register
.Indirect
)
4000 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4004 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4006 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4007 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4008 struct r600_bytecode_alu alu
;
4009 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4011 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4014 switch (write_mask
) {
4016 if (swizzle_x
== 2) {
4023 if (swizzle_x
== 2) {
4032 if (swizzle_x
== 0) {
4039 if (swizzle_x
== 0) {
4050 lasti
= tgsi_last_instruction(write_mask
);
4051 for (i
= 0; i
<= lasti
; i
++) {
4053 if (!(write_mask
& (1 << i
)))
4056 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4059 if (use_tmp
|| dest_temp
) {
4060 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4064 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4066 if (i
== 1 || i
== 3)
4069 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4071 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4072 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4073 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4075 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4076 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4079 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4080 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4083 /* handle some special cases */
4084 if (i
== 1 || i
== 3) {
4085 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4086 case TGSI_OPCODE_DABS
:
4087 r600_bytecode_src_set_abs(&alu
.src
[0]);
4096 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4102 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4104 lasti
= tgsi_last_instruction(write_mask
);
4105 /* move result from temp to dst */
4106 for (i
= 0; i
<= lasti
; i
++) {
4107 if (!(write_mask
& (1 << i
)))
4110 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4111 alu
.op
= ALU_OP1_MOV
;
4114 alu
.dst
.sel
= dest_temp
;
4118 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4119 alu
.src
[0].sel
= ctx
->temp_reg
;
4120 alu
.src
[0].chan
= use_tmp
- 1;
4121 alu
.last
= (i
== lasti
);
4123 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4131 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4133 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4134 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4135 /* confirm writemasking */
4136 if ((write_mask
& 0x3) != 0x3 &&
4137 (write_mask
& 0xc) != 0xc) {
4138 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4141 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4144 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4146 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4149 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4151 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4154 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4156 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4157 struct r600_bytecode_alu alu
;
4160 int tmp
= r600_get_temp(ctx
);
4162 for (i
= 0; i
< lasti
+ 1; i
++) {
4164 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4165 alu
.op
= ctx
->inst_info
->op
;
4166 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4167 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4170 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4171 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4180 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4187 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4189 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4190 struct r600_bytecode_alu alu
;
4191 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4192 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4193 /* use temp register if trans_only and more than one dst component */
4194 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4195 unsigned op
= ctx
->inst_info
->op
;
4197 if (op
== ALU_OP2_MUL_IEEE
&&
4198 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4201 for (i
= 0; i
<= lasti
; i
++) {
4202 if (!(write_mask
& (1 << i
)))
4205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4207 alu
.dst
.sel
= ctx
->temp_reg
;
4211 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4215 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4216 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4219 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4220 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4222 if (i
== lasti
|| trans_only
) {
4225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4231 /* move result from temp to dst */
4232 for (i
= 0; i
<= lasti
; i
++) {
4233 if (!(write_mask
& (1 << i
)))
4236 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4237 alu
.op
= ALU_OP1_MOV
;
4238 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4239 alu
.src
[0].sel
= ctx
->temp_reg
;
4240 alu
.src
[0].chan
= i
;
4241 alu
.last
= (i
== lasti
);
4243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4251 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4253 return tgsi_op2_s(ctx
, 0, 0);
4256 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4258 return tgsi_op2_s(ctx
, 1, 0);
4261 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4263 return tgsi_op2_s(ctx
, 0, 1);
4266 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4268 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4269 struct r600_bytecode_alu alu
;
4271 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4273 for (i
= 0; i
< lasti
+ 1; i
++) {
4275 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4278 alu
.op
= ctx
->inst_info
->op
;
4280 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4282 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4284 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4289 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4297 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4299 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4300 struct r600_bytecode_alu alu
;
4302 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4304 for (i
= 0; i
< lasti
+ 1; i
++) {
4306 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4309 alu
.op
= ALU_OP1_MOV
;
4311 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4313 if (i
== 1 || i
== 3)
4314 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4315 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4320 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4328 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4330 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4331 struct r600_bytecode_alu alu
;
4332 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4335 for (i
= 0; i
<= 3; i
++) {
4336 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4337 alu
.op
= ctx
->inst_info
->op
;
4339 alu
.dst
.sel
= ctx
->temp_reg
;
4342 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4343 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4349 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4354 /* Replicate significand result across channels. */
4355 for (i
= 0; i
<= 3; i
++) {
4356 if (!(write_mask
& (1 << i
)))
4359 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4360 alu
.op
= ALU_OP1_MOV
;
4361 alu
.src
[0].chan
= (i
& 1) + 2;
4362 alu
.src
[0].sel
= ctx
->temp_reg
;
4364 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4367 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4372 for (i
= 0; i
<= 3; i
++) {
4373 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4374 /* MOV third channels to writemask dst1 */
4375 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4376 alu
.op
= ALU_OP1_MOV
;
4377 alu
.src
[0].chan
= 1;
4378 alu
.src
[0].sel
= ctx
->temp_reg
;
4380 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4382 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4392 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4394 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4395 struct r600_bytecode_alu alu
;
4397 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4399 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4400 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4402 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4404 alu
.op
= ctx
->inst_info
->op
;
4406 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4407 alu
.dst
.sel
= ctx
->temp_reg
;
4412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4417 for (i
= 0; i
<= lasti
; i
++) {
4418 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4419 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4421 alu
.src
[0].chan
= i
/2;
4423 alu
.src
[0].sel
= ctx
->temp_reg
;
4425 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4426 alu
.src
[0].value
= 0x0;
4428 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4429 alu
.last
= i
== lasti
;
4431 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4439 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4441 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4442 struct r600_bytecode_alu alu
;
4444 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4445 int treg
= r600_get_temp(ctx
);
4446 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4447 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4449 /* do a 64->32 into a temp register */
4450 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4454 for (i
= 0; i
<= lasti
; i
++) {
4455 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4457 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4458 alu
.op
= ctx
->inst_info
->op
;
4460 alu
.src
[0].chan
= i
;
4461 alu
.src
[0].sel
= treg
;
4462 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4463 alu
.last
= (i
== lasti
);
4465 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4473 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4476 struct r600_shader_src
*src
,
4479 struct r600_bytecode_alu alu
;
4480 const int last_slot
= 3;
4483 /* these have to write the result to X/Y by the looks of it */
4484 for (int i
= 0 ; i
< last_slot
; i
++) {
4485 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4488 r600_bytecode_src(&alu
.src
[0], src
, 1);
4489 r600_bytecode_src(&alu
.src
[1], src
, 0);
4492 r600_bytecode_src_set_abs(&alu
.src
[1]);
4494 alu
.dst
.sel
= dst_reg
;
4496 alu
.dst
.write
= (i
== 0 || i
== 1);
4498 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4500 r
= r600_bytecode_add_alu(bc
, &alu
);
4508 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4510 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4512 struct r600_bytecode_alu alu
;
4513 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4514 int t1
= ctx
->temp_reg
;
4516 /* should only be one src regs */
4517 assert(inst
->Instruction
.NumSrcRegs
== 1);
4519 /* only support one double at a time */
4520 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4521 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4523 r
= cayman_emit_unary_double_raw(
4524 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4526 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4527 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4531 for (i
= 0 ; i
<= lasti
; i
++) {
4532 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4534 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4535 alu
.op
= ALU_OP1_MOV
;
4536 alu
.src
[0].sel
= t1
;
4537 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4538 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4549 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4551 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4553 struct r600_bytecode_alu alu
;
4554 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4556 for (i
= 0 ; i
< last_slot
; i
++) {
4557 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4558 alu
.op
= ctx
->inst_info
->op
;
4559 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4560 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4562 /* RSQ should take the absolute value of src */
4563 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4564 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4567 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4568 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4570 if (i
== last_slot
- 1)
4572 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4579 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4581 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4583 struct r600_bytecode_alu alu
;
4584 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4585 int t1
= ctx
->temp_reg
;
4587 for (k
= 0; k
<= lasti
; k
++) {
4588 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4591 for (i
= 0 ; i
< 4; i
++) {
4592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4593 alu
.op
= ctx
->inst_info
->op
;
4594 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4595 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4599 alu
.dst
.write
= (i
== k
);
4602 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4608 for (i
= 0 ; i
<= lasti
; i
++) {
4609 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4612 alu
.op
= ALU_OP1_MOV
;
4613 alu
.src
[0].sel
= t1
;
4614 alu
.src
[0].chan
= i
;
4615 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4628 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4630 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4632 struct r600_bytecode_alu alu
;
4633 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4634 int t1
= ctx
->temp_reg
;
4636 /* t1 would get overwritten below if we actually tried to
4637 * multiply two pairs of doubles at a time. */
4638 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4639 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4641 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4643 for (i
= 0; i
< 4; i
++) {
4644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4645 alu
.op
= ctx
->inst_info
->op
;
4646 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4647 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4654 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4659 for (i
= 0; i
<= lasti
; i
++) {
4660 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4662 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4663 alu
.op
= ALU_OP1_MOV
;
4664 alu
.src
[0].sel
= t1
;
4665 alu
.src
[0].chan
= i
;
4666 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4670 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4679 * Emit RECIP_64 + MUL_64 to implement division.
4681 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4683 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4685 struct r600_bytecode_alu alu
;
4686 int t1
= ctx
->temp_reg
;
4689 /* Only support one double at a time. This is the same constraint as
4690 * in DMUL lowering. */
4691 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4692 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4694 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4696 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4700 for (int i
= 0; i
< 4; i
++) {
4701 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4702 alu
.op
= ALU_OP2_MUL_64
;
4704 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4706 alu
.src
[1].sel
= t1
;
4707 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4714 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4719 for (int i
= 0; i
< 2; i
++) {
4720 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4721 alu
.op
= ALU_OP1_MOV
;
4722 alu
.src
[0].sel
= t1
;
4723 alu
.src
[0].chan
= i
;
4724 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4728 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4736 * r600 - trunc to -PI..PI range
4737 * r700 - normalize by dividing by 2PI
4740 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4743 struct r600_bytecode_alu alu
;
4745 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4746 alu
.op
= ALU_OP3_MULADD
;
4750 alu
.dst
.sel
= ctx
->temp_reg
;
4753 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4755 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4756 alu
.src
[1].chan
= 0;
4757 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4758 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4759 alu
.src
[2].chan
= 0;
4761 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4765 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4766 alu
.op
= ALU_OP1_FRACT
;
4769 alu
.dst
.sel
= ctx
->temp_reg
;
4772 alu
.src
[0].sel
= ctx
->temp_reg
;
4773 alu
.src
[0].chan
= 0;
4775 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4779 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4780 alu
.op
= ALU_OP3_MULADD
;
4784 alu
.dst
.sel
= ctx
->temp_reg
;
4787 alu
.src
[0].sel
= ctx
->temp_reg
;
4788 alu
.src
[0].chan
= 0;
4790 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4791 alu
.src
[1].chan
= 0;
4792 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4793 alu
.src
[2].chan
= 0;
4795 if (ctx
->bc
->chip_class
== R600
) {
4796 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4797 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4799 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4800 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4805 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4811 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4813 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4814 struct r600_bytecode_alu alu
;
4815 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4818 r
= tgsi_setup_trig(ctx
);
4823 for (i
= 0; i
< last_slot
; i
++) {
4824 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4825 alu
.op
= ctx
->inst_info
->op
;
4828 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4829 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4831 alu
.src
[0].sel
= ctx
->temp_reg
;
4832 alu
.src
[0].chan
= 0;
4833 if (i
== last_slot
- 1)
4835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4842 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4844 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4845 struct r600_bytecode_alu alu
;
4847 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4849 r
= tgsi_setup_trig(ctx
);
4853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4854 alu
.op
= ctx
->inst_info
->op
;
4856 alu
.dst
.sel
= ctx
->temp_reg
;
4859 alu
.src
[0].sel
= ctx
->temp_reg
;
4860 alu
.src
[0].chan
= 0;
4862 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4866 /* replicate result */
4867 for (i
= 0; i
< lasti
+ 1; i
++) {
4868 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4872 alu
.op
= ALU_OP1_MOV
;
4874 alu
.src
[0].sel
= ctx
->temp_reg
;
4875 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4878 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4885 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4887 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4888 struct r600_bytecode_alu alu
;
4891 for (i
= 0; i
< 4; i
++) {
4892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4893 alu
.op
= ctx
->inst_info
->op
;
4897 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4899 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4900 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4903 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4908 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4913 /* kill must be last in ALU */
4914 ctx
->bc
->force_add_cf
= 1;
4915 ctx
->shader
->uses_kill
= TRUE
;
4919 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4921 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4922 struct r600_bytecode_alu alu
;
4925 /* tmp.x = max(src.y, 0.0) */
4926 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4927 alu
.op
= ALU_OP2_MAX
;
4928 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4929 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4930 alu
.src
[1].chan
= 1;
4932 alu
.dst
.sel
= ctx
->temp_reg
;
4937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4941 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4947 if (ctx
->bc
->chip_class
== CAYMAN
) {
4948 for (i
= 0; i
< 3; i
++) {
4949 /* tmp.z = log(tmp.x) */
4950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4951 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4952 alu
.src
[0].sel
= ctx
->temp_reg
;
4953 alu
.src
[0].chan
= 0;
4954 alu
.dst
.sel
= ctx
->temp_reg
;
4962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4967 /* tmp.z = log(tmp.x) */
4968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4969 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4970 alu
.src
[0].sel
= ctx
->temp_reg
;
4971 alu
.src
[0].chan
= 0;
4972 alu
.dst
.sel
= ctx
->temp_reg
;
4976 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4981 chan
= alu
.dst
.chan
;
4984 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
4985 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4986 alu
.op
= ALU_OP3_MUL_LIT
;
4987 alu
.src
[0].sel
= sel
;
4988 alu
.src
[0].chan
= chan
;
4989 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
4990 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
4991 alu
.dst
.sel
= ctx
->temp_reg
;
4996 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5000 if (ctx
->bc
->chip_class
== CAYMAN
) {
5001 for (i
= 0; i
< 3; i
++) {
5002 /* dst.z = exp(tmp.x) */
5003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5004 alu
.op
= ALU_OP1_EXP_IEEE
;
5005 alu
.src
[0].sel
= ctx
->temp_reg
;
5006 alu
.src
[0].chan
= 0;
5007 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5018 /* dst.z = exp(tmp.x) */
5019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5020 alu
.op
= ALU_OP1_EXP_IEEE
;
5021 alu
.src
[0].sel
= ctx
->temp_reg
;
5022 alu
.src
[0].chan
= 0;
5023 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5025 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5033 alu
.op
= ALU_OP1_MOV
;
5034 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5035 alu
.src
[0].chan
= 0;
5036 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5037 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5042 /* dst.y = max(src.x, 0.0) */
5043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5044 alu
.op
= ALU_OP2_MAX
;
5045 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5046 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5047 alu
.src
[1].chan
= 0;
5048 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5049 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5056 alu
.op
= ALU_OP1_MOV
;
5057 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5058 alu
.src
[0].chan
= 0;
5059 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5060 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5069 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5071 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5072 struct r600_bytecode_alu alu
;
5075 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5077 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5079 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5080 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5081 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5083 alu
.dst
.sel
= ctx
->temp_reg
;
5086 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5089 /* replicate result */
5090 return tgsi_helper_tempx_replicate(ctx
);
5093 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5095 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5096 struct r600_bytecode_alu alu
;
5099 for (i
= 0; i
< 4; i
++) {
5100 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5101 alu
.src
[0].sel
= ctx
->temp_reg
;
5102 alu
.op
= ALU_OP1_MOV
;
5104 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5105 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5108 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5115 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5117 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5118 struct r600_bytecode_alu alu
;
5121 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5122 alu
.op
= ctx
->inst_info
->op
;
5123 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5124 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5126 alu
.dst
.sel
= ctx
->temp_reg
;
5129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5132 /* replicate result */
5133 return tgsi_helper_tempx_replicate(ctx
);
5136 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5138 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5140 struct r600_bytecode_alu alu
;
5141 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5143 for (i
= 0; i
< 3; i
++) {
5144 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5145 alu
.op
= ALU_OP1_LOG_IEEE
;
5146 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5147 alu
.dst
.sel
= ctx
->temp_reg
;
5152 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5158 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5159 alu
.op
= ALU_OP2_MUL
;
5160 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5161 alu
.src
[1].sel
= ctx
->temp_reg
;
5162 alu
.dst
.sel
= ctx
->temp_reg
;
5165 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5169 for (i
= 0; i
< last_slot
; i
++) {
5170 /* POW(a,b) = EXP2(b * LOG2(a))*/
5171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5172 alu
.op
= ALU_OP1_EXP_IEEE
;
5173 alu
.src
[0].sel
= ctx
->temp_reg
;
5175 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5176 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5177 if (i
== last_slot
- 1)
5179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5186 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5188 struct r600_bytecode_alu alu
;
5192 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5193 alu
.op
= ALU_OP1_LOG_IEEE
;
5194 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5195 alu
.dst
.sel
= ctx
->temp_reg
;
5198 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5203 alu
.op
= ALU_OP2_MUL
;
5204 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5205 alu
.src
[1].sel
= ctx
->temp_reg
;
5206 alu
.dst
.sel
= ctx
->temp_reg
;
5209 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5212 /* POW(a,b) = EXP2(b * LOG2(a))*/
5213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5214 alu
.op
= ALU_OP1_EXP_IEEE
;
5215 alu
.src
[0].sel
= ctx
->temp_reg
;
5216 alu
.dst
.sel
= ctx
->temp_reg
;
5219 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5222 return tgsi_helper_tempx_replicate(ctx
);
5225 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5227 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5228 struct r600_bytecode_alu alu
;
5230 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5231 int tmp0
= ctx
->temp_reg
;
5232 int tmp1
= r600_get_temp(ctx
);
5233 int tmp2
= r600_get_temp(ctx
);
5234 int tmp3
= r600_get_temp(ctx
);
5237 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5239 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5240 * 2. tmp0.z = lo (tmp0.x * src2)
5241 * 3. tmp0.w = -tmp0.z
5242 * 4. tmp0.y = hi (tmp0.x * src2)
5243 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5244 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5245 * 7. tmp1.x = tmp0.x - tmp0.w
5246 * 8. tmp1.y = tmp0.x + tmp0.w
5247 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5248 * 10. tmp0.z = hi(tmp0.x * src1) = q
5249 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5251 * 12. tmp0.w = src1 - tmp0.y = r
5252 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5253 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5257 * 15. tmp1.z = tmp0.z + 1 = q + 1
5258 * 16. tmp1.w = tmp0.z - 1 = q - 1
5262 * 15. tmp1.z = tmp0.w - src2 = r - src2
5263 * 16. tmp1.w = tmp0.w + src2 = r + src2
5267 * 17. tmp1.x = tmp1.x & tmp1.y
5269 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5270 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5272 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5273 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5277 * Same as unsigned, using abs values of the operands,
5278 * and fixing the sign of the result in the end.
5281 for (i
= 0; i
< 4; i
++) {
5282 if (!(write_mask
& (1<<i
)))
5287 /* tmp2.x = -src0 */
5288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5289 alu
.op
= ALU_OP2_SUB_INT
;
5295 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5297 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5300 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5303 /* tmp2.y = -src1 */
5304 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5305 alu
.op
= ALU_OP2_SUB_INT
;
5311 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5313 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5316 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5319 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5320 /* it will be a sign of the quotient */
5323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5324 alu
.op
= ALU_OP2_XOR_INT
;
5330 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5331 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5334 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5338 /* tmp2.x = |src0| */
5339 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5340 alu
.op
= ALU_OP3_CNDGE_INT
;
5347 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5348 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5349 alu
.src
[2].sel
= tmp2
;
5350 alu
.src
[2].chan
= 0;
5353 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5356 /* tmp2.y = |src1| */
5357 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5358 alu
.op
= ALU_OP3_CNDGE_INT
;
5365 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5366 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5367 alu
.src
[2].sel
= tmp2
;
5368 alu
.src
[2].chan
= 1;
5371 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5376 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5377 if (ctx
->bc
->chip_class
== CAYMAN
) {
5378 /* tmp3.x = u2f(src2) */
5379 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5380 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5387 alu
.src
[0].sel
= tmp2
;
5388 alu
.src
[0].chan
= 1;
5390 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5394 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5397 /* tmp0.x = recip(tmp3.x) */
5398 for (j
= 0 ; j
< 3; j
++) {
5399 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5400 alu
.op
= ALU_OP1_RECIP_IEEE
;
5404 alu
.dst
.write
= (j
== 0);
5406 alu
.src
[0].sel
= tmp3
;
5407 alu
.src
[0].chan
= 0;
5411 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5415 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5416 alu
.op
= ALU_OP2_MUL
;
5418 alu
.src
[0].sel
= tmp0
;
5419 alu
.src
[0].chan
= 0;
5421 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5422 alu
.src
[1].value
= 0x4f800000;
5427 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5431 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5432 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5438 alu
.src
[0].sel
= tmp3
;
5439 alu
.src
[0].chan
= 0;
5442 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5446 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5447 alu
.op
= ALU_OP1_RECIP_UINT
;
5454 alu
.src
[0].sel
= tmp2
;
5455 alu
.src
[0].chan
= 1;
5457 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5461 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5465 /* 2. tmp0.z = lo (tmp0.x * src2) */
5466 if (ctx
->bc
->chip_class
== CAYMAN
) {
5467 for (j
= 0 ; j
< 4; j
++) {
5468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5469 alu
.op
= ALU_OP2_MULLO_UINT
;
5473 alu
.dst
.write
= (j
== 2);
5475 alu
.src
[0].sel
= tmp0
;
5476 alu
.src
[0].chan
= 0;
5478 alu
.src
[1].sel
= tmp2
;
5479 alu
.src
[1].chan
= 1;
5481 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5484 alu
.last
= (j
== 3);
5485 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5489 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5490 alu
.op
= ALU_OP2_MULLO_UINT
;
5496 alu
.src
[0].sel
= tmp0
;
5497 alu
.src
[0].chan
= 0;
5499 alu
.src
[1].sel
= tmp2
;
5500 alu
.src
[1].chan
= 1;
5502 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5506 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5510 /* 3. tmp0.w = -tmp0.z */
5511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5512 alu
.op
= ALU_OP2_SUB_INT
;
5518 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5519 alu
.src
[1].sel
= tmp0
;
5520 alu
.src
[1].chan
= 2;
5523 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5526 /* 4. tmp0.y = hi (tmp0.x * src2) */
5527 if (ctx
->bc
->chip_class
== CAYMAN
) {
5528 for (j
= 0 ; j
< 4; j
++) {
5529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5530 alu
.op
= ALU_OP2_MULHI_UINT
;
5534 alu
.dst
.write
= (j
== 1);
5536 alu
.src
[0].sel
= tmp0
;
5537 alu
.src
[0].chan
= 0;
5540 alu
.src
[1].sel
= tmp2
;
5541 alu
.src
[1].chan
= 1;
5543 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5545 alu
.last
= (j
== 3);
5546 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5550 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5551 alu
.op
= ALU_OP2_MULHI_UINT
;
5557 alu
.src
[0].sel
= tmp0
;
5558 alu
.src
[0].chan
= 0;
5561 alu
.src
[1].sel
= tmp2
;
5562 alu
.src
[1].chan
= 1;
5564 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5568 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5572 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5573 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5574 alu
.op
= ALU_OP3_CNDE_INT
;
5581 alu
.src
[0].sel
= tmp0
;
5582 alu
.src
[0].chan
= 1;
5583 alu
.src
[1].sel
= tmp0
;
5584 alu
.src
[1].chan
= 3;
5585 alu
.src
[2].sel
= tmp0
;
5586 alu
.src
[2].chan
= 2;
5589 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5592 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5593 if (ctx
->bc
->chip_class
== CAYMAN
) {
5594 for (j
= 0 ; j
< 4; j
++) {
5595 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5596 alu
.op
= ALU_OP2_MULHI_UINT
;
5600 alu
.dst
.write
= (j
== 3);
5602 alu
.src
[0].sel
= tmp0
;
5603 alu
.src
[0].chan
= 2;
5605 alu
.src
[1].sel
= tmp0
;
5606 alu
.src
[1].chan
= 0;
5608 alu
.last
= (j
== 3);
5609 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5613 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5614 alu
.op
= ALU_OP2_MULHI_UINT
;
5620 alu
.src
[0].sel
= tmp0
;
5621 alu
.src
[0].chan
= 2;
5623 alu
.src
[1].sel
= tmp0
;
5624 alu
.src
[1].chan
= 0;
5627 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5631 /* 7. tmp1.x = tmp0.x - tmp0.w */
5632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5633 alu
.op
= ALU_OP2_SUB_INT
;
5639 alu
.src
[0].sel
= tmp0
;
5640 alu
.src
[0].chan
= 0;
5641 alu
.src
[1].sel
= tmp0
;
5642 alu
.src
[1].chan
= 3;
5645 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5648 /* 8. tmp1.y = tmp0.x + tmp0.w */
5649 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5650 alu
.op
= ALU_OP2_ADD_INT
;
5656 alu
.src
[0].sel
= tmp0
;
5657 alu
.src
[0].chan
= 0;
5658 alu
.src
[1].sel
= tmp0
;
5659 alu
.src
[1].chan
= 3;
5662 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5665 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5667 alu
.op
= ALU_OP3_CNDE_INT
;
5674 alu
.src
[0].sel
= tmp0
;
5675 alu
.src
[0].chan
= 1;
5676 alu
.src
[1].sel
= tmp1
;
5677 alu
.src
[1].chan
= 1;
5678 alu
.src
[2].sel
= tmp1
;
5679 alu
.src
[2].chan
= 0;
5682 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5685 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5686 if (ctx
->bc
->chip_class
== CAYMAN
) {
5687 for (j
= 0 ; j
< 4; j
++) {
5688 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5689 alu
.op
= ALU_OP2_MULHI_UINT
;
5693 alu
.dst
.write
= (j
== 2);
5695 alu
.src
[0].sel
= tmp0
;
5696 alu
.src
[0].chan
= 0;
5699 alu
.src
[1].sel
= tmp2
;
5700 alu
.src
[1].chan
= 0;
5702 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5705 alu
.last
= (j
== 3);
5706 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5710 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5711 alu
.op
= ALU_OP2_MULHI_UINT
;
5717 alu
.src
[0].sel
= tmp0
;
5718 alu
.src
[0].chan
= 0;
5721 alu
.src
[1].sel
= tmp2
;
5722 alu
.src
[1].chan
= 0;
5724 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5728 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5732 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5733 if (ctx
->bc
->chip_class
== CAYMAN
) {
5734 for (j
= 0 ; j
< 4; j
++) {
5735 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5736 alu
.op
= ALU_OP2_MULLO_UINT
;
5740 alu
.dst
.write
= (j
== 1);
5743 alu
.src
[0].sel
= tmp2
;
5744 alu
.src
[0].chan
= 1;
5746 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5749 alu
.src
[1].sel
= tmp0
;
5750 alu
.src
[1].chan
= 2;
5752 alu
.last
= (j
== 3);
5753 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5758 alu
.op
= ALU_OP2_MULLO_UINT
;
5765 alu
.src
[0].sel
= tmp2
;
5766 alu
.src
[0].chan
= 1;
5768 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5771 alu
.src
[1].sel
= tmp0
;
5772 alu
.src
[1].chan
= 2;
5775 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5779 /* 12. tmp0.w = src1 - tmp0.y = r */
5780 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5781 alu
.op
= ALU_OP2_SUB_INT
;
5788 alu
.src
[0].sel
= tmp2
;
5789 alu
.src
[0].chan
= 0;
5791 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5794 alu
.src
[1].sel
= tmp0
;
5795 alu
.src
[1].chan
= 1;
5798 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5801 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5802 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5803 alu
.op
= ALU_OP2_SETGE_UINT
;
5809 alu
.src
[0].sel
= tmp0
;
5810 alu
.src
[0].chan
= 3;
5812 alu
.src
[1].sel
= tmp2
;
5813 alu
.src
[1].chan
= 1;
5815 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5819 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5822 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5823 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5824 alu
.op
= ALU_OP2_SETGE_UINT
;
5831 alu
.src
[0].sel
= tmp2
;
5832 alu
.src
[0].chan
= 0;
5834 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5837 alu
.src
[1].sel
= tmp0
;
5838 alu
.src
[1].chan
= 1;
5841 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5844 if (mod
) { /* UMOD */
5846 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5847 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5848 alu
.op
= ALU_OP2_SUB_INT
;
5854 alu
.src
[0].sel
= tmp0
;
5855 alu
.src
[0].chan
= 3;
5858 alu
.src
[1].sel
= tmp2
;
5859 alu
.src
[1].chan
= 1;
5861 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5865 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5868 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5870 alu
.op
= ALU_OP2_ADD_INT
;
5876 alu
.src
[0].sel
= tmp0
;
5877 alu
.src
[0].chan
= 3;
5879 alu
.src
[1].sel
= tmp2
;
5880 alu
.src
[1].chan
= 1;
5882 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5886 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5891 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5893 alu
.op
= ALU_OP2_ADD_INT
;
5899 alu
.src
[0].sel
= tmp0
;
5900 alu
.src
[0].chan
= 2;
5901 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5904 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5907 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5909 alu
.op
= ALU_OP2_ADD_INT
;
5915 alu
.src
[0].sel
= tmp0
;
5916 alu
.src
[0].chan
= 2;
5917 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5920 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5925 /* 17. tmp1.x = tmp1.x & tmp1.y */
5926 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5927 alu
.op
= ALU_OP2_AND_INT
;
5933 alu
.src
[0].sel
= tmp1
;
5934 alu
.src
[0].chan
= 0;
5935 alu
.src
[1].sel
= tmp1
;
5936 alu
.src
[1].chan
= 1;
5939 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5942 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5943 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5945 alu
.op
= ALU_OP3_CNDE_INT
;
5952 alu
.src
[0].sel
= tmp1
;
5953 alu
.src
[0].chan
= 0;
5954 alu
.src
[1].sel
= tmp0
;
5955 alu
.src
[1].chan
= mod
? 3 : 2;
5956 alu
.src
[2].sel
= tmp1
;
5957 alu
.src
[2].chan
= 2;
5960 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5963 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5964 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5965 alu
.op
= ALU_OP3_CNDE_INT
;
5973 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5976 alu
.src
[0].sel
= tmp1
;
5977 alu
.src
[0].chan
= 1;
5978 alu
.src
[1].sel
= tmp1
;
5979 alu
.src
[1].chan
= 3;
5980 alu
.src
[2].sel
= tmp0
;
5981 alu
.src
[2].chan
= 2;
5984 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5989 /* fix the sign of the result */
5993 /* tmp0.x = -tmp0.z */
5994 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5995 alu
.op
= ALU_OP2_SUB_INT
;
6001 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6002 alu
.src
[1].sel
= tmp0
;
6003 alu
.src
[1].chan
= 2;
6006 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6009 /* sign of the remainder is the same as the sign of src0 */
6010 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6012 alu
.op
= ALU_OP3_CNDGE_INT
;
6015 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6017 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6018 alu
.src
[1].sel
= tmp0
;
6019 alu
.src
[1].chan
= 2;
6020 alu
.src
[2].sel
= tmp0
;
6021 alu
.src
[2].chan
= 0;
6024 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6029 /* tmp0.x = -tmp0.z */
6030 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6031 alu
.op
= ALU_OP2_SUB_INT
;
6037 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6038 alu
.src
[1].sel
= tmp0
;
6039 alu
.src
[1].chan
= 2;
6042 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6045 /* fix the quotient sign (same as the sign of src0*src1) */
6046 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6047 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6048 alu
.op
= ALU_OP3_CNDGE_INT
;
6051 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6053 alu
.src
[0].sel
= tmp2
;
6054 alu
.src
[0].chan
= 2;
6055 alu
.src
[1].sel
= tmp0
;
6056 alu
.src
[1].chan
= 2;
6057 alu
.src
[2].sel
= tmp0
;
6058 alu
.src
[2].chan
= 0;
6061 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6069 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6071 return tgsi_divmod(ctx
, 0, 0);
6074 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6076 return tgsi_divmod(ctx
, 1, 0);
6079 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6081 return tgsi_divmod(ctx
, 0, 1);
6084 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6086 return tgsi_divmod(ctx
, 1, 1);
6090 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6092 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6093 struct r600_bytecode_alu alu
;
6095 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6096 int last_inst
= tgsi_last_instruction(write_mask
);
6098 for (i
= 0; i
< 4; i
++) {
6099 if (!(write_mask
& (1<<i
)))
6102 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6103 alu
.op
= ALU_OP1_TRUNC
;
6105 alu
.dst
.sel
= ctx
->temp_reg
;
6109 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6112 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6117 for (i
= 0; i
< 4; i
++) {
6118 if (!(write_mask
& (1<<i
)))
6121 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6122 alu
.op
= ctx
->inst_info
->op
;
6124 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6126 alu
.src
[0].sel
= ctx
->temp_reg
;
6127 alu
.src
[0].chan
= i
;
6129 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6139 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6141 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6142 struct r600_bytecode_alu alu
;
6144 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6145 int last_inst
= tgsi_last_instruction(write_mask
);
6148 for (i
= 0; i
< 4; i
++) {
6149 if (!(write_mask
& (1<<i
)))
6152 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6153 alu
.op
= ALU_OP2_SUB_INT
;
6155 alu
.dst
.sel
= ctx
->temp_reg
;
6159 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6160 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6164 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6169 /* dst = (src >= 0 ? src : tmp) */
6170 for (i
= 0; i
< 4; i
++) {
6171 if (!(write_mask
& (1<<i
)))
6174 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6175 alu
.op
= ALU_OP3_CNDGE_INT
;
6179 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6181 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6182 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6183 alu
.src
[2].sel
= ctx
->temp_reg
;
6184 alu
.src
[2].chan
= i
;
6188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6195 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6197 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6198 struct r600_bytecode_alu alu
;
6200 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6201 int last_inst
= tgsi_last_instruction(write_mask
);
6203 /* tmp = (src >= 0 ? src : -1) */
6204 for (i
= 0; i
< 4; i
++) {
6205 if (!(write_mask
& (1<<i
)))
6208 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6209 alu
.op
= ALU_OP3_CNDGE_INT
;
6212 alu
.dst
.sel
= ctx
->temp_reg
;
6216 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6217 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6218 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6227 /* dst = (tmp > 0 ? 1 : tmp) */
6228 for (i
= 0; i
< 4; i
++) {
6229 if (!(write_mask
& (1<<i
)))
6232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6233 alu
.op
= ALU_OP3_CNDGT_INT
;
6237 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6239 alu
.src
[0].sel
= ctx
->temp_reg
;
6240 alu
.src
[0].chan
= i
;
6242 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6244 alu
.src
[2].sel
= ctx
->temp_reg
;
6245 alu
.src
[2].chan
= i
;
6249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6258 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6260 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6261 struct r600_bytecode_alu alu
;
6264 /* tmp = (src > 0 ? 1 : src) */
6265 for (i
= 0; i
< 4; i
++) {
6266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6267 alu
.op
= ALU_OP3_CNDGT
;
6270 alu
.dst
.sel
= ctx
->temp_reg
;
6273 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6274 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6275 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6279 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6284 /* dst = (-tmp > 0 ? -1 : tmp) */
6285 for (i
= 0; i
< 4; i
++) {
6286 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6287 alu
.op
= ALU_OP3_CNDGT
;
6289 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6291 alu
.src
[0].sel
= ctx
->temp_reg
;
6292 alu
.src
[0].chan
= i
;
6295 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6298 alu
.src
[2].sel
= ctx
->temp_reg
;
6299 alu
.src
[2].chan
= i
;
6303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6310 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6312 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6313 struct r600_bytecode_alu alu
;
6316 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6317 int last_inst
= tgsi_last_instruction(write_mask
);
6319 t1
= r600_get_temp(ctx
);
6321 for (i
= 0; i
< 4; i
++) {
6322 if (!(write_mask
& (1<<i
)))
6325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6326 alu
.op
= ALU_OP2_SETGE_INT
;
6327 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6328 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6329 alu
.src
[1].value
= 32;
6330 alu
.dst
.sel
= ctx
->temp_reg
;
6333 alu
.last
= i
== last_inst
;
6334 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6339 for (i
= 0; i
< 4; i
++) {
6340 if (!(write_mask
& (1<<i
)))
6343 /* create mask tmp */
6344 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6345 alu
.op
= ALU_OP2_BFM_INT
;
6349 alu
.last
= i
== last_inst
;
6351 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6352 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6354 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6359 t2
= r600_get_temp(ctx
);
6361 for (i
= 0; i
< 4; i
++) {
6362 if (!(write_mask
& (1<<i
)))
6365 /* shift insert left */
6366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6367 alu
.op
= ALU_OP2_LSHL_INT
;
6371 alu
.last
= i
== last_inst
;
6373 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6374 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6376 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6381 for (i
= 0; i
< 4; i
++) {
6382 if (!(write_mask
& (1<<i
)))
6385 /* actual bitfield insert */
6386 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6387 alu
.op
= ALU_OP3_BFI_INT
;
6389 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6392 alu
.last
= i
== last_inst
;
6394 alu
.src
[0].sel
= t1
;
6395 alu
.src
[0].chan
= i
;
6396 alu
.src
[1].sel
= t2
;
6397 alu
.src
[1].chan
= i
;
6398 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6400 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6405 for (i
= 0; i
< 4; i
++) {
6406 if (!(write_mask
& (1<<i
)))
6408 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6409 alu
.op
= ALU_OP3_CNDE_INT
;
6411 alu
.src
[0].sel
= ctx
->temp_reg
;
6412 alu
.src
[0].chan
= i
;
6413 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6415 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6417 alu
.src
[1].sel
= alu
.dst
.sel
;
6418 alu
.src
[1].chan
= i
;
6420 alu
.last
= i
== last_inst
;
6421 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6428 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6430 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6431 struct r600_bytecode_alu alu
;
6434 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6435 int last_inst
= tgsi_last_instruction(write_mask
);
6437 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6438 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6442 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6443 for (i
= 0; i
< 4; i
++) {
6444 if (!(write_mask
& (1<<i
)))
6447 /* t1 = FFBH_INT / FFBH_UINT */
6448 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6449 alu
.op
= ctx
->inst_info
->op
;
6453 alu
.last
= i
== last_inst
;
6455 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6457 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6462 t2
= r600_get_temp(ctx
);
6464 for (i
= 0; i
< 4; i
++) {
6465 if (!(write_mask
& (1<<i
)))
6469 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6470 alu
.op
= ALU_OP2_SUB_INT
;
6474 alu
.last
= i
== last_inst
;
6476 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6477 alu
.src
[0].value
= 31;
6478 alu
.src
[1].sel
= t1
;
6479 alu
.src
[1].chan
= i
;
6481 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6486 for (i
= 0; i
< 4; i
++) {
6487 if (!(write_mask
& (1<<i
)))
6490 /* result = t1 >= 0 ? t2 : t1 */
6491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6492 alu
.op
= ALU_OP3_CNDGE_INT
;
6494 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6497 alu
.last
= i
== last_inst
;
6499 alu
.src
[0].sel
= t1
;
6500 alu
.src
[0].chan
= i
;
6501 alu
.src
[1].sel
= t2
;
6502 alu
.src
[1].chan
= i
;
6503 alu
.src
[2].sel
= t1
;
6504 alu
.src
[2].chan
= i
;
6506 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6514 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6516 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6517 struct r600_bytecode_alu alu
;
6518 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6520 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6522 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6524 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6525 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6526 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6527 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6530 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6533 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6536 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6537 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6539 /* NOTE: currently offset is not perspective correct */
6540 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6541 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6542 int sample_gpr
= -1;
6543 int gradientsH
, gradientsV
;
6544 struct r600_bytecode_tex tex
;
6546 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6547 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6550 gradientsH
= r600_get_temp(ctx
);
6551 gradientsV
= r600_get_temp(ctx
);
6552 for (i
= 0; i
< 2; i
++) {
6553 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6554 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6555 tex
.src_gpr
= interp_gpr
;
6556 tex
.src_sel_x
= interp_base_chan
+ 0;
6557 tex
.src_sel_y
= interp_base_chan
+ 1;
6560 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6565 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6567 tex
.resource_id
= tex
.sampler_id
;
6568 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6573 for (i
= 0; i
< 2; i
++) {
6574 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6575 alu
.op
= ALU_OP3_MULADD
;
6577 alu
.src
[0].sel
= gradientsH
;
6578 alu
.src
[0].chan
= i
;
6579 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6580 alu
.src
[1].sel
= sample_gpr
;
6581 alu
.src
[1].chan
= 2;
6584 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6586 alu
.src
[2].sel
= interp_gpr
;
6587 alu
.src
[2].chan
= interp_base_chan
+ i
;
6588 alu
.dst
.sel
= ctx
->temp_reg
;
6592 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6597 for (i
= 0; i
< 2; i
++) {
6598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6599 alu
.op
= ALU_OP3_MULADD
;
6601 alu
.src
[0].sel
= gradientsV
;
6602 alu
.src
[0].chan
= i
;
6603 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6604 alu
.src
[1].sel
= sample_gpr
;
6605 alu
.src
[1].chan
= 3;
6608 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6610 alu
.src
[2].sel
= ctx
->temp_reg
;
6611 alu
.src
[2].chan
= i
;
6612 alu
.dst
.sel
= ctx
->temp_reg
;
6616 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6622 tmp
= r600_get_temp(ctx
);
6623 for (i
= 0; i
< 8; i
++) {
6624 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6625 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6628 if ((i
> 1 && i
< 6)) {
6634 alu
.dst
.chan
= i
% 4;
6636 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6637 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6638 alu
.src
[0].sel
= ctx
->temp_reg
;
6639 alu
.src
[0].chan
= 1 - (i
% 2);
6641 alu
.src
[0].sel
= interp_gpr
;
6642 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6644 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6645 alu
.src
[1].chan
= 0;
6647 alu
.last
= i
% 4 == 3;
6648 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6650 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6655 // INTERP can't swizzle dst
6656 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6657 for (i
= 0; i
<= lasti
; i
++) {
6658 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6661 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6662 alu
.op
= ALU_OP1_MOV
;
6663 alu
.src
[0].sel
= tmp
;
6664 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6665 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6667 alu
.last
= i
== lasti
;
6668 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6677 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6679 struct r600_bytecode_alu alu
;
6682 for (i
= 0; i
< 4; i
++) {
6683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6684 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6685 alu
.op
= ALU_OP0_NOP
;
6688 alu
.op
= ALU_OP1_MOV
;
6689 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6690 alu
.src
[0].sel
= ctx
->temp_reg
;
6691 alu
.src
[0].chan
= i
;
6696 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6703 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6704 unsigned temp
, int chan
,
6705 struct r600_bytecode_alu_src
*bc_src
,
6706 const struct r600_shader_src
*shader_src
)
6708 struct r600_bytecode_alu alu
;
6711 r600_bytecode_src(bc_src
, shader_src
, chan
);
6713 /* op3 operands don't support abs modifier */
6715 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6716 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6717 alu
.op
= ALU_OP1_MOV
;
6719 alu
.dst
.chan
= chan
;
6722 alu
.src
[0] = *bc_src
;
6723 alu
.last
= true; // sufficient?
6724 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6728 memset(bc_src
, 0, sizeof(*bc_src
));
6730 bc_src
->chan
= chan
;
6735 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
6737 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6738 struct r600_bytecode_alu alu
;
6740 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6742 unsigned op
= ctx
->inst_info
->op
;
6744 if (op
== ALU_OP3_MULADD_IEEE
&&
6745 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6746 op
= ALU_OP3_MULADD
;
6748 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6750 if (ctx
->src
[j
].abs
)
6751 temp_regs
[j
] = r600_get_temp(ctx
);
6753 for (i
= 0; i
< lasti
+ 1; i
++) {
6754 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6759 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6760 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6766 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6776 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6783 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6785 return tgsi_op3_dst(ctx
, -1);
6788 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6790 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6791 struct r600_bytecode_alu alu
;
6793 unsigned op
= ctx
->inst_info
->op
;
6794 if (op
== ALU_OP2_DOT4_IEEE
&&
6795 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6798 for (i
= 0; i
< 4; i
++) {
6799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6801 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6802 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6805 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6807 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6808 /* handle some special cases */
6809 switch (inst
->Instruction
.Opcode
) {
6810 case TGSI_OPCODE_DP2
:
6812 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6813 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6816 case TGSI_OPCODE_DP3
:
6818 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6819 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6828 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6835 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6838 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6839 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6840 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6841 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6842 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6843 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6846 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6849 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6850 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6853 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6855 struct r600_bytecode_vtx vtx
;
6856 struct r600_bytecode_alu alu
;
6857 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6859 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6860 int sampler_index_mode
= inst
->Src
[1].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6862 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6863 if (src_requires_loading
) {
6864 for (i
= 0; i
< 4; i
++) {
6865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6866 alu
.op
= ALU_OP1_MOV
;
6867 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6868 alu
.dst
.sel
= ctx
->temp_reg
;
6873 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6877 src_gpr
= ctx
->temp_reg
;
6880 memset(&vtx
, 0, sizeof(vtx
));
6881 vtx
.op
= FETCH_OP_VFETCH
;
6882 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6883 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6884 vtx
.src_gpr
= src_gpr
;
6885 vtx
.mega_fetch_count
= 16;
6886 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6887 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6888 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6889 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6890 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6891 vtx
.use_const_fields
= 1;
6892 vtx
.buffer_index_mode
= sampler_index_mode
;
6894 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6897 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6900 for (i
= 0; i
< 4; i
++) {
6901 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6902 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6905 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6906 alu
.op
= ALU_OP2_AND_INT
;
6909 alu
.dst
.sel
= vtx
.dst_gpr
;
6912 alu
.src
[0].sel
= vtx
.dst_gpr
;
6913 alu
.src
[0].chan
= i
;
6915 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6916 alu
.src
[1].sel
+= (id
* 2);
6917 alu
.src
[1].chan
= i
% 4;
6918 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6922 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6927 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6929 alu
.op
= ALU_OP2_OR_INT
;
6932 alu
.dst
.sel
= vtx
.dst_gpr
;
6935 alu
.src
[0].sel
= vtx
.dst_gpr
;
6936 alu
.src
[0].chan
= 3;
6938 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6939 alu
.src
[1].chan
= 0;
6940 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6950 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
)
6952 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6954 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
6955 int sampler_index_mode
= inst
->Src
[reg_idx
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6957 if (ctx
->bc
->chip_class
< EVERGREEN
) {
6958 struct r600_bytecode_alu alu
;
6959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6960 alu
.op
= ALU_OP1_MOV
;
6961 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6962 /* r600 we have them at channel 2 of the second dword */
6963 alu
.src
[0].sel
+= (id
* 2) + 1;
6964 alu
.src
[0].chan
= 1;
6965 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6966 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6968 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6973 struct r600_bytecode_vtx vtx
;
6974 memset(&vtx
, 0, sizeof(vtx
));
6975 vtx
.op
= FETCH_OP_GDS_MIN_UINT
; /* aka GET_BUFFER_RESINFO */
6976 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6977 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6979 vtx
.mega_fetch_count
= 16; /* no idea here really... */
6980 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6981 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6982 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 4 : 7; /* SEL_Y */
6983 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 4 : 7; /* SEL_Z */
6984 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 4 : 7; /* SEL_W */
6985 vtx
.data_format
= FMT_32_32_32_32
;
6986 vtx
.buffer_index_mode
= sampler_index_mode
;
6988 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
6995 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6997 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6998 struct r600_bytecode_tex tex
;
6999 struct r600_bytecode_alu alu
;
7003 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7004 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7005 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7006 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7008 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7009 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7010 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7012 /* Texture fetch instructions can only use gprs as source.
7013 * Also they cannot negate the source or take the absolute value */
7014 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7015 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7016 read_compressed_msaa
|| txf_add_offsets
;
7018 boolean src_loaded
= FALSE
;
7019 unsigned sampler_src_reg
= 1;
7020 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7021 boolean has_txq_cube_array_z
= false;
7022 unsigned sampler_index_mode
;
7024 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7025 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7026 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7027 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7028 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7029 has_txq_cube_array_z
= true;
7032 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7033 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7034 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7035 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7036 sampler_src_reg
= 2;
7038 /* TGSI moves the sampler to src reg 3 for TXD */
7039 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7040 sampler_src_reg
= 3;
7042 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7044 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7046 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7047 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7048 if (ctx
->bc
->chip_class
< EVERGREEN
)
7049 ctx
->shader
->uses_tex_buffers
= true;
7050 return r600_do_buffer_txq(ctx
, 1, 0);
7052 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7053 if (ctx
->bc
->chip_class
< EVERGREEN
)
7054 ctx
->shader
->uses_tex_buffers
= true;
7055 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7059 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7061 /* Add perspective divide */
7062 if (ctx
->bc
->chip_class
== CAYMAN
) {
7064 for (i
= 0; i
< 3; i
++) {
7065 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7066 alu
.op
= ALU_OP1_RECIP_IEEE
;
7067 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7069 alu
.dst
.sel
= ctx
->temp_reg
;
7075 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7083 alu
.op
= ALU_OP1_RECIP_IEEE
;
7084 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7086 alu
.dst
.sel
= ctx
->temp_reg
;
7087 alu
.dst
.chan
= out_chan
;
7090 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7095 for (i
= 0; i
< 3; i
++) {
7096 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7097 alu
.op
= ALU_OP2_MUL
;
7098 alu
.src
[0].sel
= ctx
->temp_reg
;
7099 alu
.src
[0].chan
= out_chan
;
7100 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7101 alu
.dst
.sel
= ctx
->temp_reg
;
7104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7108 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7109 alu
.op
= ALU_OP1_MOV
;
7110 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7111 alu
.src
[0].chan
= 0;
7112 alu
.dst
.sel
= ctx
->temp_reg
;
7116 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7120 src_gpr
= ctx
->temp_reg
;
7124 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7125 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7126 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7127 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7128 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7130 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7131 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7133 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7134 for (i
= 0; i
< 4; i
++) {
7135 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7136 alu
.op
= ALU_OP2_CUBE
;
7137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7138 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7139 alu
.dst
.sel
= ctx
->temp_reg
;
7144 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7149 /* tmp1.z = RCP_e(|tmp1.z|) */
7150 if (ctx
->bc
->chip_class
== CAYMAN
) {
7151 for (i
= 0; i
< 3; i
++) {
7152 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7153 alu
.op
= ALU_OP1_RECIP_IEEE
;
7154 alu
.src
[0].sel
= ctx
->temp_reg
;
7155 alu
.src
[0].chan
= 2;
7157 alu
.dst
.sel
= ctx
->temp_reg
;
7163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7168 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7169 alu
.op
= ALU_OP1_RECIP_IEEE
;
7170 alu
.src
[0].sel
= ctx
->temp_reg
;
7171 alu
.src
[0].chan
= 2;
7173 alu
.dst
.sel
= ctx
->temp_reg
;
7177 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7182 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7183 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7184 * muladd has no writemask, have to use another temp
7186 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7187 alu
.op
= ALU_OP3_MULADD
;
7190 alu
.src
[0].sel
= ctx
->temp_reg
;
7191 alu
.src
[0].chan
= 0;
7192 alu
.src
[1].sel
= ctx
->temp_reg
;
7193 alu
.src
[1].chan
= 2;
7195 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7196 alu
.src
[2].chan
= 0;
7197 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7199 alu
.dst
.sel
= ctx
->temp_reg
;
7203 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7208 alu
.op
= ALU_OP3_MULADD
;
7211 alu
.src
[0].sel
= ctx
->temp_reg
;
7212 alu
.src
[0].chan
= 1;
7213 alu
.src
[1].sel
= ctx
->temp_reg
;
7214 alu
.src
[1].chan
= 2;
7216 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7217 alu
.src
[2].chan
= 0;
7218 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7220 alu
.dst
.sel
= ctx
->temp_reg
;
7225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7228 /* write initial compare value into Z component
7229 - W src 0 for shadow cube
7230 - X src 1 for shadow cube array */
7231 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7232 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7234 alu
.op
= ALU_OP1_MOV
;
7235 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7236 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7238 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7239 alu
.dst
.sel
= ctx
->temp_reg
;
7243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7248 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7249 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7250 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7251 int mytmp
= r600_get_temp(ctx
);
7252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7253 alu
.op
= ALU_OP1_MOV
;
7254 alu
.src
[0].sel
= ctx
->temp_reg
;
7255 alu
.src
[0].chan
= 3;
7256 alu
.dst
.sel
= mytmp
;
7260 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7264 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7266 alu
.op
= ALU_OP3_MULADD
;
7268 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7269 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7270 alu
.src
[1].chan
= 0;
7271 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7272 alu
.src
[2].sel
= mytmp
;
7273 alu
.src
[2].chan
= 0;
7274 alu
.dst
.sel
= ctx
->temp_reg
;
7278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7281 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7282 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7283 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7284 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7285 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7286 tex
.src_gpr
= r600_get_temp(ctx
);
7291 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7292 tex
.coord_type_x
= 1;
7293 tex
.coord_type_y
= 1;
7294 tex
.coord_type_z
= 1;
7295 tex
.coord_type_w
= 1;
7296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7297 alu
.op
= ALU_OP1_MOV
;
7298 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7299 alu
.dst
.sel
= tex
.src_gpr
;
7303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7307 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7314 /* for cube forms of lod and bias we need to route things */
7315 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7316 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7317 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7318 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7319 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7320 alu
.op
= ALU_OP1_MOV
;
7321 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7322 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7323 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7325 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7326 alu
.dst
.sel
= ctx
->temp_reg
;
7330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7336 src_gpr
= ctx
->temp_reg
;
7339 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7340 int temp_h
= 0, temp_v
= 0;
7343 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7344 if (src_loaded
== TRUE
)
7348 for (i
= start_val
; i
< 3; i
++) {
7349 int treg
= r600_get_temp(ctx
);
7358 for (j
= 0; j
< 4; j
++) {
7359 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7360 alu
.op
= ALU_OP1_MOV
;
7361 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7367 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7372 for (i
= 1; i
< 3; i
++) {
7373 /* set gradients h/v */
7374 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7375 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7376 FETCH_OP_SET_GRADIENTS_V
;
7377 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7378 tex
.sampler_index_mode
= sampler_index_mode
;
7379 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7380 tex
.resource_index_mode
= sampler_index_mode
;
7382 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7388 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7389 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7390 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7391 tex
.coord_type_x
= 1;
7392 tex
.coord_type_y
= 1;
7393 tex
.coord_type_z
= 1;
7394 tex
.coord_type_w
= 1;
7396 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7402 if (src_requires_loading
&& !src_loaded
) {
7403 for (i
= 0; i
< 4; i
++) {
7404 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7405 alu
.op
= ALU_OP1_MOV
;
7406 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7407 alu
.dst
.sel
= ctx
->temp_reg
;
7412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7417 src_gpr
= ctx
->temp_reg
;
7420 /* get offset values */
7421 if (inst
->Texture
.NumOffsets
) {
7422 assert(inst
->Texture
.NumOffsets
== 1);
7424 /* The texture offset feature doesn't work with the TXF instruction
7425 * and must be emulated by adding the offset to the texture coordinates. */
7426 if (txf_add_offsets
) {
7427 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7429 switch (inst
->Texture
.Texture
) {
7430 case TGSI_TEXTURE_3D
:
7431 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7432 alu
.op
= ALU_OP2_ADD_INT
;
7433 alu
.src
[0].sel
= src_gpr
;
7434 alu
.src
[0].chan
= 2;
7435 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7436 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7437 alu
.dst
.sel
= src_gpr
;
7441 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7446 case TGSI_TEXTURE_2D
:
7447 case TGSI_TEXTURE_SHADOW2D
:
7448 case TGSI_TEXTURE_RECT
:
7449 case TGSI_TEXTURE_SHADOWRECT
:
7450 case TGSI_TEXTURE_2D_ARRAY
:
7451 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7452 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7453 alu
.op
= ALU_OP2_ADD_INT
;
7454 alu
.src
[0].sel
= src_gpr
;
7455 alu
.src
[0].chan
= 1;
7456 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7457 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7458 alu
.dst
.sel
= src_gpr
;
7462 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7467 case TGSI_TEXTURE_1D
:
7468 case TGSI_TEXTURE_SHADOW1D
:
7469 case TGSI_TEXTURE_1D_ARRAY
:
7470 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7472 alu
.op
= ALU_OP2_ADD_INT
;
7473 alu
.src
[0].sel
= src_gpr
;
7474 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7475 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7476 alu
.dst
.sel
= src_gpr
;
7479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7483 /* texture offsets do not apply to other texture targets */
7486 switch (inst
->Texture
.Texture
) {
7487 case TGSI_TEXTURE_3D
:
7488 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7490 case TGSI_TEXTURE_2D
:
7491 case TGSI_TEXTURE_SHADOW2D
:
7492 case TGSI_TEXTURE_RECT
:
7493 case TGSI_TEXTURE_SHADOWRECT
:
7494 case TGSI_TEXTURE_2D_ARRAY
:
7495 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7496 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7498 case TGSI_TEXTURE_1D
:
7499 case TGSI_TEXTURE_SHADOW1D
:
7500 case TGSI_TEXTURE_1D_ARRAY
:
7501 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7502 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7507 /* Obtain the sample index for reading a compressed MSAA color texture.
7508 * To read the FMASK, we use the ldfptr instruction, which tells us
7509 * where the samples are stored.
7510 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7511 * which is the identity mapping. Each nibble says which physical sample
7512 * should be fetched to get that sample.
7514 * Assume src.z contains the sample index. It should be modified like this:
7515 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7516 * Then fetch the texel with src.
7518 if (read_compressed_msaa
) {
7519 unsigned sample_chan
= 3;
7520 unsigned temp
= r600_get_temp(ctx
);
7523 /* temp.w = ldfptr() */
7524 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7525 tex
.op
= FETCH_OP_LD
;
7526 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7527 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7528 tex
.sampler_index_mode
= sampler_index_mode
;
7529 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7530 tex
.resource_index_mode
= sampler_index_mode
;
7531 tex
.src_gpr
= src_gpr
;
7533 tex
.dst_sel_x
= 7; /* mask out these components */
7536 tex
.dst_sel_w
= 0; /* store X */
7541 tex
.offset_x
= offset_x
;
7542 tex
.offset_y
= offset_y
;
7543 tex
.offset_z
= offset_z
;
7544 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7548 /* temp.x = sample_index*4 */
7549 if (ctx
->bc
->chip_class
== CAYMAN
) {
7550 for (i
= 0 ; i
< 4; i
++) {
7551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7552 alu
.op
= ALU_OP2_MULLO_INT
;
7553 alu
.src
[0].sel
= src_gpr
;
7554 alu
.src
[0].chan
= sample_chan
;
7555 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7556 alu
.src
[1].value
= 4;
7559 alu
.dst
.write
= i
== 0;
7562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7568 alu
.op
= ALU_OP2_MULLO_INT
;
7569 alu
.src
[0].sel
= src_gpr
;
7570 alu
.src
[0].chan
= sample_chan
;
7571 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7572 alu
.src
[1].value
= 4;
7577 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7582 /* sample_index = temp.w >> temp.x */
7583 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7584 alu
.op
= ALU_OP2_LSHR_INT
;
7585 alu
.src
[0].sel
= temp
;
7586 alu
.src
[0].chan
= 3;
7587 alu
.src
[1].sel
= temp
;
7588 alu
.src
[1].chan
= 0;
7589 alu
.dst
.sel
= src_gpr
;
7590 alu
.dst
.chan
= sample_chan
;
7593 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7597 /* sample_index & 0xF */
7598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7599 alu
.op
= ALU_OP2_AND_INT
;
7600 alu
.src
[0].sel
= src_gpr
;
7601 alu
.src
[0].chan
= sample_chan
;
7602 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7603 alu
.src
[1].value
= 0xF;
7604 alu
.dst
.sel
= src_gpr
;
7605 alu
.dst
.chan
= sample_chan
;
7608 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7612 /* visualize the FMASK */
7613 for (i
= 0; i
< 4; i
++) {
7614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7615 alu
.op
= ALU_OP1_INT_TO_FLT
;
7616 alu
.src
[0].sel
= src_gpr
;
7617 alu
.src
[0].chan
= sample_chan
;
7618 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7622 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7630 /* does this shader want a num layers from TXQ for a cube array? */
7631 if (has_txq_cube_array_z
) {
7632 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7634 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7635 alu
.op
= ALU_OP1_MOV
;
7637 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7638 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7639 /* with eg each dword is number of cubes */
7640 alu
.src
[0].sel
+= id
/ 4;
7641 alu
.src
[0].chan
= id
% 4;
7643 /* r600 we have them at channel 2 of the second dword */
7644 alu
.src
[0].sel
+= (id
* 2) + 1;
7645 alu
.src
[0].chan
= 2;
7647 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7648 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7650 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7653 /* disable writemask from texture instruction */
7654 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7657 opcode
= ctx
->inst_info
->op
;
7658 if (opcode
== FETCH_OP_GATHER4
&&
7659 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7660 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7661 opcode
= FETCH_OP_GATHER4_O
;
7663 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7664 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7665 encoded in the instruction are ignored. */
7666 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7667 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7668 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7669 tex
.sampler_index_mode
= sampler_index_mode
;
7670 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7671 tex
.resource_index_mode
= sampler_index_mode
;
7673 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7674 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7675 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7676 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7684 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7689 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7690 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7691 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7692 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7693 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7694 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7695 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7697 case FETCH_OP_SAMPLE
:
7698 opcode
= FETCH_OP_SAMPLE_C
;
7700 case FETCH_OP_SAMPLE_L
:
7701 opcode
= FETCH_OP_SAMPLE_C_L
;
7703 case FETCH_OP_SAMPLE_LB
:
7704 opcode
= FETCH_OP_SAMPLE_C_LB
;
7706 case FETCH_OP_SAMPLE_G
:
7707 opcode
= FETCH_OP_SAMPLE_C_G
;
7709 /* Texture gather variants */
7710 case FETCH_OP_GATHER4
:
7711 opcode
= FETCH_OP_GATHER4_C
;
7713 case FETCH_OP_GATHER4_O
:
7714 opcode
= FETCH_OP_GATHER4_C_O
;
7719 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7722 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7723 tex
.sampler_index_mode
= sampler_index_mode
;
7724 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7725 tex
.resource_index_mode
= sampler_index_mode
;
7726 tex
.src_gpr
= src_gpr
;
7727 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7729 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7730 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7731 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7734 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7735 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7736 tex
.inst_mod
= texture_component_select
;
7738 if (ctx
->bc
->chip_class
== CAYMAN
) {
7739 /* GATHER4 result order is different from TGSI TG4 */
7740 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7741 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7742 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7743 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7745 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7746 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7747 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7748 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7751 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7752 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7753 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7757 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7764 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7765 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7766 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7767 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7771 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7776 } else if (src_loaded
) {
7782 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7783 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7784 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7785 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7786 tex
.src_rel
= ctx
->src
[0].rel
;
7789 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7790 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7791 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7792 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7796 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7799 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7800 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7801 tex
.coord_type_x
= 1;
7802 tex
.coord_type_y
= 1;
7804 tex
.coord_type_z
= 1;
7805 tex
.coord_type_w
= 1;
7807 tex
.offset_x
= offset_x
;
7808 tex
.offset_y
= offset_y
;
7809 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7810 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7811 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7815 tex
.offset_z
= offset_z
;
7818 /* Put the depth for comparison in W.
7819 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7820 * Some instructions expect the depth in Z. */
7821 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7822 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7823 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7824 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7825 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7826 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7827 tex
.src_sel_w
= tex
.src_sel_z
;
7830 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7831 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7832 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7833 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7834 /* the array index is read from Y */
7835 tex
.coord_type_y
= 0;
7837 /* the array index is read from Z */
7838 tex
.coord_type_z
= 0;
7839 tex
.src_sel_z
= tex
.src_sel_y
;
7841 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7842 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7843 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7844 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7845 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7846 /* the array index is read from Z */
7847 tex
.coord_type_z
= 0;
7849 /* mask unused source components */
7850 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7851 switch (inst
->Texture
.Texture
) {
7852 case TGSI_TEXTURE_2D
:
7853 case TGSI_TEXTURE_RECT
:
7857 case TGSI_TEXTURE_1D_ARRAY
:
7861 case TGSI_TEXTURE_1D
:
7869 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7873 /* add shadow ambient support - gallium doesn't do it yet */
7877 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7878 struct tgsi_full_src_register
*src
)
7882 if (src
->Register
.Indirect
) {
7883 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7884 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7885 return ctx
->shader
->atomics
[i
].hw_idx
;
7888 uint32_t index
= src
->Register
.Index
;
7889 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7890 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
7892 if (index
> ctx
->shader
->atomics
[i
].end
)
7894 if (index
< ctx
->shader
->atomics
[i
].start
)
7896 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7897 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7904 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
7905 int *uav_id_p
, int *uav_index_mode_p
)
7907 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7908 int uav_id
, uav_index_mode
= 0;
7910 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7912 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7914 if (inst
->Src
[0].Register
.Indirect
) {
7916 struct r600_bytecode_alu alu
;
7917 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7918 alu
.op
= ALU_OP2_LSHL_INT
;
7919 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
7920 alu
.src
[0].chan
= 0;
7921 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7922 alu
.src
[1].value
= 2;
7923 alu
.dst
.sel
= ctx
->temp_reg
;
7927 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7931 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
7934 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
7940 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
7942 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
7948 *uav_index_mode_p
= uav_index_mode
;
7952 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
7954 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7956 struct r600_bytecode_gds gds
;
7958 int uav_index_mode
= 0;
7959 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7961 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
7965 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7966 gds
.op
= FETCH_OP_GDS_READ_RET
;
7967 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7968 gds
.uav_id
= is_cm
? 0 : uav_id
;
7969 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
7970 gds
.src_gpr
= ctx
->temp_reg
;
7971 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
7979 gds
.alloc_consume
= !is_cm
;
7980 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7984 ctx
->bc
->cf_last
->vpm
= 1;
7988 /* this fixes up 1D arrays properly */
7989 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
7991 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7993 struct r600_bytecode_alu alu
;
7994 int temp_reg
= r600_get_temp(ctx
);
7996 for (i
= 0; i
< 4; i
++) {
7997 bool def_val
= true, write_zero
= false;
7998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7999 alu
.op
= ALU_OP1_MOV
;
8000 alu
.dst
.sel
= temp_reg
;
8003 switch (inst
->Memory
.Texture
) {
8004 case TGSI_TEXTURE_BUFFER
:
8005 case TGSI_TEXTURE_1D
:
8006 if (i
== 1 || i
== 2 || i
== 3) {
8010 case TGSI_TEXTURE_1D_ARRAY
:
8011 if (i
== 1 || i
== 3)
8014 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8018 case TGSI_TEXTURE_2D
:
8019 if (i
== 2 || i
== 3)
8029 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8030 alu
.src
[0].value
= 0;
8031 } else if (def_val
) {
8032 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8042 *idx_gpr
= temp_reg
;
8046 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8049 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8051 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8052 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8053 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8055 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8060 struct r600_bytecode_alu alu
;
8061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8062 alu
.op
= ALU_OP2_LSHR_INT
;
8063 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8064 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8065 alu
.src
[1].value
= 2;
8066 alu
.dst
.sel
= temp_reg
;
8069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8076 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8078 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8079 /* have to work out the offset into the RAT immediate return buffer */
8080 struct r600_bytecode_vtx vtx
;
8081 struct r600_bytecode_cf
*cf
;
8083 int temp_reg
= r600_get_temp(ctx
);
8084 unsigned rat_index_mode
;
8087 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8088 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8090 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8093 ctx
->bc
->cf_last
->barrier
= 1;
8094 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8095 vtx
.op
= FETCH_OP_VFETCH
;
8096 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8097 vtx
.buffer_index_mode
= rat_index_mode
;
8098 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8099 vtx
.src_gpr
= temp_reg
;
8101 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8102 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8103 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8104 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8105 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8106 vtx
.num_format_all
= 1;
8107 vtx
.format_comp_all
= 1;
8108 vtx
.srf_mode_all
= 0;
8110 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8111 vtx
.data_format
= FMT_32_32_32_32
;
8112 vtx
.use_const_fields
= 0;
8113 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8114 vtx
.data_format
= FMT_32_32_32
;
8115 vtx
.use_const_fields
= 0;
8116 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8117 vtx
.data_format
= FMT_32_32
;
8118 vtx
.use_const_fields
= 0;
8120 vtx
.data_format
= FMT_32
;
8121 vtx
.use_const_fields
= 0;
8124 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8127 cf
= ctx
->bc
->cf_last
;
8132 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8134 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8135 /* have to work out the offset into the RAT immediate return buffer */
8136 struct r600_bytecode_vtx vtx
;
8137 struct r600_bytecode_cf
*cf
;
8140 unsigned format
, num_format
, format_comp
, endian
;
8141 const struct util_format_description
*desc
;
8142 unsigned rat_index_mode
;
8143 unsigned immed_base
;
8145 r
= load_thread_id_gpr(ctx
);
8149 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8151 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8152 r
= load_index_src(ctx
, 1, &idx_gpr
);
8157 egcm_load_index_reg(ctx
->bc
, 1, false);
8159 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8160 cf
= ctx
->bc
->cf_last
;
8162 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8163 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8164 cf
->rat
.index_mode
= rat_index_mode
;
8165 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8166 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8167 cf
->output
.index_gpr
= idx_gpr
;
8168 cf
->output
.comp_mask
= 0xf;
8169 cf
->output
.burst_count
= 1;
8173 cf
->output
.elem_size
= 0;
8175 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8176 cf
= ctx
->bc
->cf_last
;
8179 desc
= util_format_description(inst
->Memory
.Format
);
8180 r600_vertex_data_type(inst
->Memory
.Format
,
8181 &format
, &num_format
, &format_comp
, &endian
);
8182 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8183 vtx
.op
= FETCH_OP_VFETCH
;
8184 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8185 vtx
.buffer_index_mode
= rat_index_mode
;
8186 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8187 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8189 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8190 vtx
.dst_sel_x
= desc
->swizzle
[0];
8191 vtx
.dst_sel_y
= desc
->swizzle
[1];
8192 vtx
.dst_sel_z
= desc
->swizzle
[2];
8193 vtx
.dst_sel_w
= desc
->swizzle
[3];
8194 vtx
.srf_mode_all
= 1;
8195 vtx
.data_format
= format
;
8196 vtx
.num_format_all
= num_format
;
8197 vtx
.format_comp_all
= format_comp
;
8198 vtx
.endian
= endian
;
8200 vtx
.mega_fetch_count
= 3;
8201 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8204 cf
= ctx
->bc
->cf_last
;
8209 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8211 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8212 struct r600_bytecode_alu alu
;
8214 int temp_reg
= r600_get_temp(ctx
);
8216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8217 alu
.op
= ALU_OP1_MOV
;
8218 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8219 alu
.dst
.sel
= temp_reg
;
8222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8226 r
= do_lds_fetch_values(ctx
, temp_reg
,
8227 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8233 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8235 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8236 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8237 return tgsi_load_rat(ctx
);
8238 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8239 return tgsi_load_gds(ctx
);
8240 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8241 return tgsi_load_buffer(ctx
);
8242 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8243 return tgsi_load_lds(ctx
);
8247 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8249 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8250 struct r600_bytecode_cf
*cf
;
8252 unsigned rat_index_mode
;
8254 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8256 r
= load_buffer_coord(ctx
, 0, treg2
);
8260 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8262 egcm_load_index_reg(ctx
->bc
, 1, false);
8264 for (i
= 0; i
<= 3; i
++) {
8265 struct r600_bytecode_alu alu
;
8266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8267 alu
.op
= ALU_OP1_MOV
;
8268 alu
.dst
.sel
= temp_reg
;
8270 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8271 alu
.last
= (i
== 3);
8273 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8278 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8279 for (i
= 0; i
<= lasti
; i
++) {
8280 struct r600_bytecode_alu alu
;
8281 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8284 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8287 V_SQ_ALU_SRC_LITERAL
, i
);
8291 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8292 alu
.op
= ALU_OP1_MOV
;
8293 alu
.dst
.sel
= ctx
->temp_reg
;
8296 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8299 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8303 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8304 cf
= ctx
->bc
->cf_last
;
8306 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8307 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8308 cf
->rat
.index_mode
= rat_index_mode
;
8309 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8310 cf
->output
.gpr
= ctx
->temp_reg
;
8311 cf
->output
.index_gpr
= temp_reg
;
8312 cf
->output
.comp_mask
= 1;
8313 cf
->output
.burst_count
= 1;
8316 cf
->output
.elem_size
= 0;
8321 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8323 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8324 struct r600_bytecode_cf
*cf
;
8325 bool src_requires_loading
= false;
8326 int val_gpr
, idx_gpr
;
8328 unsigned rat_index_mode
;
8330 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8332 r
= load_index_src(ctx
, 0, &idx_gpr
);
8336 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8337 src_requires_loading
= true;
8339 if (src_requires_loading
) {
8340 struct r600_bytecode_alu alu
;
8341 for (i
= 0; i
< 4; i
++) {
8342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8343 alu
.op
= ALU_OP1_MOV
;
8344 alu
.dst
.sel
= ctx
->temp_reg
;
8347 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8355 val_gpr
= ctx
->temp_reg
;
8357 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8359 egcm_load_index_reg(ctx
->bc
, 1, false);
8361 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8362 cf
= ctx
->bc
->cf_last
;
8364 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8365 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8366 cf
->rat
.index_mode
= rat_index_mode
;
8367 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8368 cf
->output
.gpr
= val_gpr
;
8369 cf
->output
.index_gpr
= idx_gpr
;
8370 cf
->output
.comp_mask
= 0xf;
8371 cf
->output
.burst_count
= 1;
8374 cf
->output
.elem_size
= 0;
8378 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8380 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8381 struct r600_bytecode_alu alu
;
8383 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8384 int temp_reg
= r600_get_temp(ctx
);
8387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8388 alu
.op
= ALU_OP1_MOV
;
8389 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8390 alu
.dst
.sel
= temp_reg
;
8393 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8397 lasti
= tgsi_last_instruction(write_mask
);
8398 for (i
= 1; i
<= lasti
; i
++) {
8399 if (!(write_mask
& (1 << i
)))
8401 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8404 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8408 for (i
= 0; i
<= lasti
; i
++) {
8409 if (!(write_mask
& (1 << i
)))
8412 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8413 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8414 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8415 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8417 alu
.src
[0].sel
= temp_reg
;
8418 alu
.src
[0].chan
= i
;
8419 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8420 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8422 alu
.is_lds_idx_op
= true;
8424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8430 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8431 alu
.op
= LDS_OP2_LDS_WRITE
;
8433 alu
.src
[0].sel
= temp_reg
;
8434 alu
.src
[0].chan
= i
;
8435 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8438 alu
.is_lds_idx_op
= true;
8440 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8447 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8449 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8450 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8451 return tgsi_store_buffer_rat(ctx
);
8452 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8453 return tgsi_store_lds(ctx
);
8455 return tgsi_store_rat(ctx
);
8458 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8460 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8461 /* have to work out the offset into the RAT immediate return buffer */
8462 struct r600_bytecode_alu alu
;
8463 struct r600_bytecode_vtx vtx
;
8464 struct r600_bytecode_cf
*cf
;
8467 unsigned format
, num_format
, format_comp
, endian
;
8468 const struct util_format_description
*desc
;
8469 unsigned rat_index_mode
;
8470 unsigned immed_base
;
8473 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8474 rat_base
= ctx
->shader
->rat_base
;
8476 r
= load_thread_id_gpr(ctx
);
8480 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8481 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8482 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8484 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8487 idx_gpr
= ctx
->temp_reg
;
8489 r
= load_index_src(ctx
, 1, &idx_gpr
);
8494 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8496 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8497 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8498 alu
.op
= ALU_OP1_MOV
;
8499 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8502 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8508 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8509 alu
.op
= ALU_OP1_MOV
;
8510 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8511 if (ctx
->bc
->chip_class
== CAYMAN
)
8516 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8518 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8522 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8523 alu
.op
= ALU_OP1_MOV
;
8524 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8527 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8529 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8535 egcm_load_index_reg(ctx
->bc
, 1, false);
8536 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8537 cf
= ctx
->bc
->cf_last
;
8539 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
8540 cf
->rat
.inst
= ctx
->inst_info
->op
;
8541 cf
->rat
.index_mode
= rat_index_mode
;
8542 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8543 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8544 cf
->output
.index_gpr
= idx_gpr
;
8545 cf
->output
.comp_mask
= 0xf;
8546 cf
->output
.burst_count
= 1;
8550 cf
->output
.elem_size
= 0;
8551 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8552 cf
= ctx
->bc
->cf_last
;
8556 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8557 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
8558 desc
= util_format_description(inst
->Memory
.Format
);
8559 r600_vertex_data_type(inst
->Memory
.Format
,
8560 &format
, &num_format
, &format_comp
, &endian
);
8561 vtx
.dst_sel_x
= desc
->swizzle
[0];
8569 vtx
.op
= FETCH_OP_VFETCH
;
8570 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8571 vtx
.buffer_index_mode
= rat_index_mode
;
8572 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8573 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8575 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8579 vtx
.use_const_fields
= 0;
8580 vtx
.srf_mode_all
= 1;
8581 vtx
.data_format
= format
;
8582 vtx
.num_format_all
= num_format
;
8583 vtx
.format_comp_all
= format_comp
;
8584 vtx
.endian
= endian
;
8586 vtx
.mega_fetch_count
= 0xf;
8587 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8590 cf
= ctx
->bc
->cf_last
;
8596 static int get_gds_op(int opcode
)
8599 case TGSI_OPCODE_ATOMUADD
:
8600 return FETCH_OP_GDS_ADD_RET
;
8601 case TGSI_OPCODE_ATOMAND
:
8602 return FETCH_OP_GDS_AND_RET
;
8603 case TGSI_OPCODE_ATOMOR
:
8604 return FETCH_OP_GDS_OR_RET
;
8605 case TGSI_OPCODE_ATOMXOR
:
8606 return FETCH_OP_GDS_XOR_RET
;
8607 case TGSI_OPCODE_ATOMUMIN
:
8608 return FETCH_OP_GDS_MIN_UINT_RET
;
8609 case TGSI_OPCODE_ATOMUMAX
:
8610 return FETCH_OP_GDS_MAX_UINT_RET
;
8611 case TGSI_OPCODE_ATOMXCHG
:
8612 return FETCH_OP_GDS_XCHG_RET
;
8613 case TGSI_OPCODE_ATOMCAS
:
8614 return FETCH_OP_GDS_CMP_XCHG_RET
;
8620 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8622 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8623 struct r600_bytecode_gds gds
;
8624 struct r600_bytecode_alu alu
;
8625 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8628 int uav_index_mode
= 0;
8629 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8632 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8636 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8640 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8641 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8642 int abs_value
= abs(value
);
8643 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8644 gds_op
= FETCH_OP_GDS_SUB_RET
;
8645 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8646 alu
.op
= ALU_OP1_MOV
;
8647 alu
.dst
.sel
= ctx
->temp_reg
;
8648 alu
.dst
.chan
= is_cm
? 1 : 0;
8649 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8650 alu
.src
[0].value
= abs_value
;
8653 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8657 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8658 alu
.op
= ALU_OP1_MOV
;
8659 alu
.dst
.sel
= ctx
->temp_reg
;
8660 alu
.dst
.chan
= is_cm
? 1 : 0;
8661 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8664 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8670 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8672 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8673 gds
.uav_id
= is_cm
? 0 : uav_id
;
8674 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8675 gds
.src_gpr
= ctx
->temp_reg
;
8677 gds
.src_sel_x
= is_cm
? 0 : 4;
8678 gds
.src_sel_y
= is_cm
? 1 : 0;
8684 gds
.alloc_consume
= !is_cm
;
8686 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8689 ctx
->bc
->cf_last
->vpm
= 1;
8693 static int get_lds_op(int opcode
)
8696 case TGSI_OPCODE_ATOMUADD
:
8697 return LDS_OP2_LDS_ADD_RET
;
8698 case TGSI_OPCODE_ATOMAND
:
8699 return LDS_OP2_LDS_AND_RET
;
8700 case TGSI_OPCODE_ATOMOR
:
8701 return LDS_OP2_LDS_OR_RET
;
8702 case TGSI_OPCODE_ATOMXOR
:
8703 return LDS_OP2_LDS_XOR_RET
;
8704 case TGSI_OPCODE_ATOMUMIN
:
8705 return LDS_OP2_LDS_MIN_UINT_RET
;
8706 case TGSI_OPCODE_ATOMUMAX
:
8707 return LDS_OP2_LDS_MAX_UINT_RET
;
8708 case TGSI_OPCODE_ATOMIMIN
:
8709 return LDS_OP2_LDS_MIN_INT_RET
;
8710 case TGSI_OPCODE_ATOMIMAX
:
8711 return LDS_OP2_LDS_MAX_INT_RET
;
8712 case TGSI_OPCODE_ATOMXCHG
:
8713 return LDS_OP2_LDS_XCHG_RET
;
8714 case TGSI_OPCODE_ATOMCAS
:
8715 return LDS_OP3_LDS_CMP_XCHG_RET
;
8721 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
8723 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8724 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
8727 struct r600_bytecode_alu alu
;
8728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8730 alu
.is_lds_idx_op
= true;
8732 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8733 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
8734 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
8735 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
8737 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
8738 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8742 /* then read from LDS_OQ_A_POP */
8743 memset(&alu
, 0, sizeof(alu
));
8745 alu
.op
= ALU_OP1_MOV
;
8746 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
8747 alu
.src
[0].chan
= 0;
8748 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
8751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8758 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
8760 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8761 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8762 return tgsi_atomic_op_rat(ctx
);
8763 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8764 return tgsi_atomic_op_gds(ctx
);
8765 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8766 return tgsi_atomic_op_rat(ctx
);
8767 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8768 return tgsi_atomic_op_lds(ctx
);
8772 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
8774 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8775 unsigned sampler_index_mode
;
8776 struct r600_bytecode_tex tex
;
8778 boolean has_txq_cube_array_z
= false;
8780 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
8781 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
8782 if (ctx
->bc
->chip_class
< EVERGREEN
)
8783 ctx
->shader
->uses_tex_buffers
= true;
8784 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
);
8787 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
8788 inst
->Dst
[0].Register
.WriteMask
& 4) {
8789 ctx
->shader
->has_txq_cube_array_z_comp
= true;
8790 has_txq_cube_array_z
= true;
8793 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8794 if (sampler_index_mode
)
8795 egcm_load_index_reg(ctx
->bc
, 1, false);
8798 /* does this shader want a num layers from TXQ for a cube array? */
8799 if (has_txq_cube_array_z
) {
8800 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
8801 struct r600_bytecode_alu alu
;
8803 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8804 alu
.op
= ALU_OP1_MOV
;
8806 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8807 /* with eg each dword is either number of cubes */
8808 alu
.src
[0].sel
+= id
/ 4;
8809 alu
.src
[0].chan
= id
% 4;
8810 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8811 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8813 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8816 /* disable writemask from texture instruction */
8817 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8819 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8820 tex
.op
= ctx
->inst_info
->op
;
8821 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
8822 tex
.sampler_index_mode
= sampler_index_mode
;
8823 tex
.resource_id
= tex
.sampler_id
;
8824 tex
.resource_index_mode
= sampler_index_mode
;
8829 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8830 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8831 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8832 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8833 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8834 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8841 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
8843 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8844 struct r600_bytecode_alu alu
;
8845 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8846 unsigned i
, temp_regs
[2];
8849 /* optimize if it's just an equal balance */
8850 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
8851 for (i
= 0; i
< lasti
+ 1; i
++) {
8852 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8856 alu
.op
= ALU_OP2_ADD
;
8857 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8858 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8860 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8865 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8873 for (i
= 0; i
< lasti
+ 1; i
++) {
8874 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8878 alu
.op
= ALU_OP2_ADD
;
8879 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8880 alu
.src
[0].chan
= 0;
8881 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
8882 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
8883 alu
.dst
.sel
= ctx
->temp_reg
;
8889 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8894 /* (1 - src0) * src2 */
8895 for (i
= 0; i
< lasti
+ 1; i
++) {
8896 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8900 alu
.op
= ALU_OP2_MUL
;
8901 alu
.src
[0].sel
= ctx
->temp_reg
;
8902 alu
.src
[0].chan
= i
;
8903 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8904 alu
.dst
.sel
= ctx
->temp_reg
;
8910 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8915 /* src0 * src1 + (1 - src0) * src2 */
8916 if (ctx
->src
[0].abs
)
8917 temp_regs
[0] = r600_get_temp(ctx
);
8920 if (ctx
->src
[1].abs
)
8921 temp_regs
[1] = r600_get_temp(ctx
);
8925 for (i
= 0; i
< lasti
+ 1; i
++) {
8926 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8929 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8930 alu
.op
= ALU_OP3_MULADD
;
8932 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8935 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
8938 alu
.src
[2].sel
= ctx
->temp_reg
;
8939 alu
.src
[2].chan
= i
;
8941 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8946 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8953 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
8955 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8956 struct r600_bytecode_alu alu
;
8958 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8962 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
8964 ctx
->src
[0].abs
= 0;
8965 ctx
->src
[0].neg
= 0;
8970 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
8972 if (ctx
->src
[j
].abs
)
8973 temp_regs
[j
] = r600_get_temp(ctx
);
8976 for (i
= 0; i
< lasti
+ 1; i
++) {
8977 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8982 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8985 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
8988 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
8991 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8997 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9004 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9006 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9007 struct r600_bytecode_alu alu
;
9009 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9011 for (i
= 0; i
< lasti
+ 1; i
++) {
9012 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9016 alu
.op
= ALU_OP3_CNDE_INT
;
9017 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9018 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9019 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9020 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9033 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9035 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9036 struct r600_bytecode_alu alu
;
9040 /* result.x = 2^floor(src); */
9041 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9042 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9044 alu
.op
= ALU_OP1_FLOOR
;
9045 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9047 alu
.dst
.sel
= ctx
->temp_reg
;
9051 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9055 if (ctx
->bc
->chip_class
== CAYMAN
) {
9056 for (i
= 0; i
< 3; i
++) {
9057 alu
.op
= ALU_OP1_EXP_IEEE
;
9058 alu
.src
[0].sel
= ctx
->temp_reg
;
9059 alu
.src
[0].chan
= 0;
9061 alu
.dst
.sel
= ctx
->temp_reg
;
9063 alu
.dst
.write
= i
== 0;
9065 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9070 alu
.op
= ALU_OP1_EXP_IEEE
;
9071 alu
.src
[0].sel
= ctx
->temp_reg
;
9072 alu
.src
[0].chan
= 0;
9074 alu
.dst
.sel
= ctx
->temp_reg
;
9078 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9084 /* result.y = tmp - floor(tmp); */
9085 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9086 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9088 alu
.op
= ALU_OP1_FRACT
;
9089 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9091 alu
.dst
.sel
= ctx
->temp_reg
;
9093 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9102 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9107 /* result.z = RoughApprox2ToX(tmp);*/
9108 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9109 if (ctx
->bc
->chip_class
== CAYMAN
) {
9110 for (i
= 0; i
< 3; i
++) {
9111 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9112 alu
.op
= ALU_OP1_EXP_IEEE
;
9113 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9115 alu
.dst
.sel
= ctx
->temp_reg
;
9122 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9127 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9128 alu
.op
= ALU_OP1_EXP_IEEE
;
9129 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9131 alu
.dst
.sel
= ctx
->temp_reg
;
9137 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9143 /* result.w = 1.0;*/
9144 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9147 alu
.op
= ALU_OP1_MOV
;
9148 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9149 alu
.src
[0].chan
= 0;
9151 alu
.dst
.sel
= ctx
->temp_reg
;
9155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9159 return tgsi_helper_copy(ctx
, inst
);
9162 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9164 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9165 struct r600_bytecode_alu alu
;
9169 /* result.x = floor(log2(|src|)); */
9170 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9171 if (ctx
->bc
->chip_class
== CAYMAN
) {
9172 for (i
= 0; i
< 3; i
++) {
9173 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9175 alu
.op
= ALU_OP1_LOG_IEEE
;
9176 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9177 r600_bytecode_src_set_abs(&alu
.src
[0]);
9179 alu
.dst
.sel
= ctx
->temp_reg
;
9185 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9193 alu
.op
= ALU_OP1_LOG_IEEE
;
9194 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9195 r600_bytecode_src_set_abs(&alu
.src
[0]);
9197 alu
.dst
.sel
= ctx
->temp_reg
;
9201 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9206 alu
.op
= ALU_OP1_FLOOR
;
9207 alu
.src
[0].sel
= ctx
->temp_reg
;
9208 alu
.src
[0].chan
= 0;
9210 alu
.dst
.sel
= ctx
->temp_reg
;
9215 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9220 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9221 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9223 if (ctx
->bc
->chip_class
== CAYMAN
) {
9224 for (i
= 0; i
< 3; i
++) {
9225 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9227 alu
.op
= ALU_OP1_LOG_IEEE
;
9228 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9229 r600_bytecode_src_set_abs(&alu
.src
[0]);
9231 alu
.dst
.sel
= ctx
->temp_reg
;
9238 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9243 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9245 alu
.op
= ALU_OP1_LOG_IEEE
;
9246 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9247 r600_bytecode_src_set_abs(&alu
.src
[0]);
9249 alu
.dst
.sel
= ctx
->temp_reg
;
9254 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9259 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9261 alu
.op
= ALU_OP1_FLOOR
;
9262 alu
.src
[0].sel
= ctx
->temp_reg
;
9263 alu
.src
[0].chan
= 1;
9265 alu
.dst
.sel
= ctx
->temp_reg
;
9270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9274 if (ctx
->bc
->chip_class
== CAYMAN
) {
9275 for (i
= 0; i
< 3; i
++) {
9276 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9277 alu
.op
= ALU_OP1_EXP_IEEE
;
9278 alu
.src
[0].sel
= ctx
->temp_reg
;
9279 alu
.src
[0].chan
= 1;
9281 alu
.dst
.sel
= ctx
->temp_reg
;
9288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9293 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9294 alu
.op
= ALU_OP1_EXP_IEEE
;
9295 alu
.src
[0].sel
= ctx
->temp_reg
;
9296 alu
.src
[0].chan
= 1;
9298 alu
.dst
.sel
= ctx
->temp_reg
;
9303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9308 if (ctx
->bc
->chip_class
== CAYMAN
) {
9309 for (i
= 0; i
< 3; i
++) {
9310 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9311 alu
.op
= ALU_OP1_RECIP_IEEE
;
9312 alu
.src
[0].sel
= ctx
->temp_reg
;
9313 alu
.src
[0].chan
= 1;
9315 alu
.dst
.sel
= ctx
->temp_reg
;
9322 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9327 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9328 alu
.op
= ALU_OP1_RECIP_IEEE
;
9329 alu
.src
[0].sel
= ctx
->temp_reg
;
9330 alu
.src
[0].chan
= 1;
9332 alu
.dst
.sel
= ctx
->temp_reg
;
9337 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9344 alu
.op
= ALU_OP2_MUL
;
9346 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9347 r600_bytecode_src_set_abs(&alu
.src
[0]);
9349 alu
.src
[1].sel
= ctx
->temp_reg
;
9350 alu
.src
[1].chan
= 1;
9352 alu
.dst
.sel
= ctx
->temp_reg
;
9357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9362 /* result.z = log2(|src|);*/
9363 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9364 if (ctx
->bc
->chip_class
== CAYMAN
) {
9365 for (i
= 0; i
< 3; i
++) {
9366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9368 alu
.op
= ALU_OP1_LOG_IEEE
;
9369 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9370 r600_bytecode_src_set_abs(&alu
.src
[0]);
9372 alu
.dst
.sel
= ctx
->temp_reg
;
9379 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9386 alu
.op
= ALU_OP1_LOG_IEEE
;
9387 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9388 r600_bytecode_src_set_abs(&alu
.src
[0]);
9390 alu
.dst
.sel
= ctx
->temp_reg
;
9395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9401 /* result.w = 1.0; */
9402 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9405 alu
.op
= ALU_OP1_MOV
;
9406 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9407 alu
.src
[0].chan
= 0;
9409 alu
.dst
.sel
= ctx
->temp_reg
;
9414 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9419 return tgsi_helper_copy(ctx
, inst
);
9422 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9424 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9425 struct r600_bytecode_alu alu
;
9427 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9428 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9430 assert(inst
->Dst
[0].Register
.Index
< 3);
9431 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9433 switch (inst
->Instruction
.Opcode
) {
9434 case TGSI_OPCODE_ARL
:
9435 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9437 case TGSI_OPCODE_ARR
:
9438 alu
.op
= ALU_OP1_FLT_TO_INT
;
9440 case TGSI_OPCODE_UARL
:
9441 alu
.op
= ALU_OP1_MOV
;
9448 for (i
= 0; i
<= lasti
; ++i
) {
9449 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9451 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9452 alu
.last
= i
== lasti
;
9456 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9461 if (inst
->Dst
[0].Register
.Index
> 0)
9462 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
9464 ctx
->bc
->ar_loaded
= 0;
9468 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
9470 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9471 struct r600_bytecode_alu alu
;
9473 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9475 switch (inst
->Instruction
.Opcode
) {
9476 case TGSI_OPCODE_ARL
:
9477 memset(&alu
, 0, sizeof(alu
));
9478 alu
.op
= ALU_OP1_FLOOR
;
9479 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9481 for (i
= 0; i
<= lasti
; ++i
) {
9482 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9484 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9485 alu
.last
= i
== lasti
;
9486 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9491 memset(&alu
, 0, sizeof(alu
));
9492 alu
.op
= ALU_OP1_FLT_TO_INT
;
9493 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
9494 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9496 /* FLT_TO_INT is trans-only on r600/r700 */
9498 for (i
= 0; i
<= lasti
; ++i
) {
9500 alu
.src
[0].chan
= i
;
9501 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9505 case TGSI_OPCODE_ARR
:
9506 memset(&alu
, 0, sizeof(alu
));
9507 alu
.op
= ALU_OP1_FLT_TO_INT
;
9508 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9510 /* FLT_TO_INT is trans-only on r600/r700 */
9512 for (i
= 0; i
<= lasti
; ++i
) {
9513 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9515 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9516 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9521 case TGSI_OPCODE_UARL
:
9522 memset(&alu
, 0, sizeof(alu
));
9523 alu
.op
= ALU_OP1_MOV
;
9524 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9526 for (i
= 0; i
<= lasti
; ++i
) {
9527 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9529 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9530 alu
.last
= i
== lasti
;
9531 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9541 ctx
->bc
->ar_loaded
= 0;
9545 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9547 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9548 struct r600_bytecode_alu alu
;
9551 for (i
= 0; i
< 4; i
++) {
9552 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9554 alu
.op
= ALU_OP2_MUL
;
9555 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9557 if (i
== 0 || i
== 3) {
9558 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9560 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9563 if (i
== 0 || i
== 2) {
9564 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9566 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9570 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9577 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
9579 struct r600_bytecode_alu alu
;
9582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9584 alu
.execute_mask
= 1;
9585 alu
.update_pred
= 1;
9587 alu
.dst
.sel
= ctx
->temp_reg
;
9591 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9592 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9593 alu
.src
[1].chan
= 0;
9597 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9603 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9605 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9609 if (ctx
->bc
->cf_last
) {
9610 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9612 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9617 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9618 ctx
->bc
->force_add_cf
= 1;
9619 } else if (alu_pop
== 2) {
9620 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9621 ctx
->bc
->force_add_cf
= 1;
9628 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9629 ctx
->bc
->cf_last
->pop_count
= pops
;
9630 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9636 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9639 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9643 unsigned entry_size
= stack
->entry_size
;
9645 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9646 elements
+= stack
->push
;
9648 switch (ctx
->bc
->chip_class
) {
9651 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9652 * the stack must be reserved to hold the current active/continue
9654 if (reason
== FC_PUSH_VPM
) {
9660 /* r9xx: any stack operation on empty stack consumes 2 additional
9665 /* FIXME: do the two elements added above cover the cases for the
9669 /* r8xx+: 2 extra elements are not always required, but one extra
9670 * element must be added for each of the following cases:
9671 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9673 * (Currently we don't use ALU_ELSE_AFTER.)
9674 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9675 * PUSH instruction executed.
9677 * NOTE: it seems we also need to reserve additional element in some
9678 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9679 * then STACK_SIZE should be 2 instead of 1 */
9680 if (reason
== FC_PUSH_VPM
) {
9690 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9691 * for all chips, so we use 4 in the final formula, not the real entry_size
9695 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9697 if (entries
> stack
->max_entries
)
9698 stack
->max_entries
= entries
;
9701 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9705 --ctx
->bc
->stack
.push
;
9706 assert(ctx
->bc
->stack
.push
>= 0);
9709 --ctx
->bc
->stack
.push_wqm
;
9710 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9713 --ctx
->bc
->stack
.loop
;
9714 assert(ctx
->bc
->stack
.loop
>= 0);
9722 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
9726 ++ctx
->bc
->stack
.push
;
9729 ++ctx
->bc
->stack
.push_wqm
;
9731 ++ctx
->bc
->stack
.loop
;
9737 callstack_update_max_depth(ctx
, reason
);
9740 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
9742 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
9744 sp
->mid
= realloc((void *)sp
->mid
,
9745 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
9746 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
9750 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
9752 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
9753 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
9754 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
9758 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
9760 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
9770 static int emit_return(struct r600_shader_ctx
*ctx
)
9772 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
9776 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
9779 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
9780 ctx
->bc
->cf_last
->pop_count
= pops
;
9781 /* XXX work out offset */
9785 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
9790 static void emit_testflag(struct r600_shader_ctx
*ctx
)
9795 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
9798 emit_jump_to_offset(ctx
, 1, 4);
9799 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
9800 pops(ctx
, ifidx
+ 1);
9804 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
9808 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9809 ctx
->bc
->cf_last
->pop_count
= 1;
9811 fc_set_mid(ctx
, fc_sp
);
9817 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
9819 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
9821 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
9822 * LOOP_STARTxxx for nested loops may put the branch stack into a state
9823 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
9824 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
9825 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
9826 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
9827 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9828 alu_type
= CF_OP_ALU
;
9831 emit_logic_pred(ctx
, opcode
, alu_type
);
9833 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
9835 fc_pushlevel(ctx
, FC_IF
);
9837 callstack_push(ctx
, FC_PUSH_VPM
);
9841 static int tgsi_if(struct r600_shader_ctx
*ctx
)
9843 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
9846 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
9848 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
9851 static int tgsi_else(struct r600_shader_ctx
*ctx
)
9853 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
9854 ctx
->bc
->cf_last
->pop_count
= 1;
9856 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
9857 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
9861 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
9864 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
9865 R600_ERR("if/endif unbalanced in shader\n");
9869 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
9870 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9871 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
9873 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9877 callstack_pop(ctx
, FC_PUSH_VPM
);
9881 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
9883 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
9884 * limited to 4096 iterations, like the other LOOP_* instructions. */
9885 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
9887 fc_pushlevel(ctx
, FC_LOOP
);
9889 /* check stack depth */
9890 callstack_push(ctx
, FC_LOOP
);
9894 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
9898 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
9900 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
9901 R600_ERR("loop/endloop in shader code are not paired.\n");
9905 /* fixup loop pointers - from r600isa
9906 LOOP END points to CF after LOOP START,
9907 LOOP START point to CF after LOOP END
9908 BRK/CONT point to LOOP END CF
9910 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
9912 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9914 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
9915 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
9917 /* XXX add LOOPRET support */
9919 callstack_pop(ctx
, FC_LOOP
);
9923 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
9927 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
9929 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
9934 R600_ERR("Break not inside loop/endloop pair\n");
9938 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9940 fc_set_mid(ctx
, fscp
- 1);
9945 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
9947 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9948 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
9951 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9952 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
9954 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9956 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
9957 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9958 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
9963 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
9965 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9966 struct r600_bytecode_alu alu
;
9968 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9971 for (i
= 0; i
< lasti
+ 1; i
++) {
9972 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9975 if (ctx
->bc
->chip_class
== CAYMAN
) {
9976 for (j
= 0 ; j
< 4; j
++) {
9977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9979 alu
.op
= ALU_OP2_MULLO_UINT
;
9980 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
9981 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
9984 alu
.dst
.sel
= ctx
->temp_reg
;
9985 alu
.dst
.write
= (j
== i
);
9988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9993 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9996 alu
.dst
.sel
= ctx
->temp_reg
;
9999 alu
.op
= ALU_OP2_MULLO_UINT
;
10000 for (j
= 0; j
< 2; j
++) {
10001 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10005 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10012 for (i
= 0; i
< lasti
+ 1; i
++) {
10013 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10016 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10017 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10019 alu
.op
= ALU_OP2_ADD_INT
;
10021 alu
.src
[0].sel
= ctx
->temp_reg
;
10022 alu
.src
[0].chan
= i
;
10024 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10035 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10037 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10038 struct r600_bytecode_alu alu
;
10040 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10042 /* temp.xy = f32_to_f16(src) */
10043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10044 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10046 alu
.dst
.sel
= ctx
->temp_reg
;
10048 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10049 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10053 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10055 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10059 /* dst.x = temp.y * 0x10000 + temp.x */
10060 for (i
= 0; i
< lasti
+ 1; i
++) {
10061 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10065 alu
.op
= ALU_OP3_MULADD_UINT24
;
10067 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10068 alu
.last
= i
== lasti
;
10069 alu
.src
[0].sel
= ctx
->temp_reg
;
10070 alu
.src
[0].chan
= 1;
10071 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10072 alu
.src
[1].value
= 0x10000;
10073 alu
.src
[2].sel
= ctx
->temp_reg
;
10074 alu
.src
[2].chan
= 0;
10075 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10083 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10085 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10086 struct r600_bytecode_alu alu
;
10088 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10090 /* temp.x = src.x */
10091 /* note: no need to mask out the high bits */
10092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10093 alu
.op
= ALU_OP1_MOV
;
10095 alu
.dst
.sel
= ctx
->temp_reg
;
10097 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10098 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10102 /* temp.y = src.x >> 16 */
10103 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10104 alu
.op
= ALU_OP2_LSHR_INT
;
10106 alu
.dst
.sel
= ctx
->temp_reg
;
10108 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10109 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10110 alu
.src
[1].value
= 16;
10112 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10116 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10117 for (i
= 0; i
< lasti
+ 1; i
++) {
10118 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10121 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10122 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10123 alu
.src
[0].sel
= ctx
->temp_reg
;
10124 alu
.src
[0].chan
= i
% 2;
10125 alu
.last
= i
== lasti
;
10126 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10134 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10136 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10137 struct r600_bytecode_alu alu
;
10138 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10142 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10143 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10144 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10145 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10146 dst
= r600_get_temp(ctx
);
10148 r
= tgsi_op3_dst(ctx
, dst
);
10152 for (i
= 0; i
< lasti
+ 1; i
++) {
10153 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10154 alu
.op
= ALU_OP2_SETGE_INT
;
10155 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10156 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10157 alu
.src
[1].value
= 32;
10158 alu
.dst
.sel
= ctx
->temp_reg
;
10163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10168 for (i
= 0; i
< lasti
+ 1; i
++) {
10169 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10170 alu
.op
= ALU_OP3_CNDE_INT
;
10172 alu
.src
[0].sel
= ctx
->temp_reg
;
10173 alu
.src
[0].chan
= i
;
10175 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10177 alu
.src
[1].sel
= dst
;
10179 alu
.src
[1].sel
= alu
.dst
.sel
;
10180 alu
.src
[1].chan
= i
;
10181 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10185 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10193 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
10194 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10195 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10196 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10198 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10200 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10201 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10202 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10203 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10204 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10205 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10206 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10207 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10208 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
10209 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10210 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10211 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10212 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10213 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10214 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10215 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10216 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10217 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10218 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10219 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10220 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10221 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10222 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10223 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10224 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
10225 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
10226 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
10227 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10228 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10229 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10230 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10231 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10232 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
10233 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10234 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10235 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10236 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10237 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10238 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10239 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10240 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10241 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10242 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10243 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10244 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
10245 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10246 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10247 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10248 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10249 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10250 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10251 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10252 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10253 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10254 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10255 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10256 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10257 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10258 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10259 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10260 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10261 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10262 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10263 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10264 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10265 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10266 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10267 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10268 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10269 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10270 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10271 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10272 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10273 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10274 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10275 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10276 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10277 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
10278 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10279 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10280 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
10281 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10282 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10283 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
10284 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10285 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10286 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10287 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10288 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10289 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10290 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10291 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10292 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10293 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10294 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10295 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10296 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10297 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10298 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10299 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10300 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10301 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10302 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10303 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10304 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10305 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10306 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10307 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10308 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10309 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10310 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10311 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10312 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10313 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10314 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10315 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
10316 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10317 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10318 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10319 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10320 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10321 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
10322 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10323 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
10324 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
10325 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10326 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10327 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10328 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10329 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10330 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10331 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
10332 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10333 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10334 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
10335 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10336 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
10337 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10338 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10339 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10340 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10341 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10342 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10343 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10344 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10345 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10346 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10347 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10348 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10349 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10350 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10351 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10352 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10353 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
10354 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10355 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10356 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10357 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10358 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10359 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10360 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10361 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10362 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10363 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10364 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10365 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10366 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10367 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10368 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10369 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10370 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10371 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10372 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10373 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10374 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10375 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10376 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10377 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10378 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
10379 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
10380 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
10381 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
10382 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10383 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
10384 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
10385 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
10386 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
10387 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
10388 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10389 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10390 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10391 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10394 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
10395 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10396 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10397 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10398 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10399 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10400 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10401 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10402 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10403 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10404 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10405 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10406 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10407 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10408 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10409 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10410 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10411 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10412 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10413 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10414 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10415 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10416 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10417 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10418 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10419 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10420 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10421 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10422 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
10423 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
10424 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
10425 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10426 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10427 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10428 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10429 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10430 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
10431 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10432 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10433 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10434 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10435 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10436 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10437 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10438 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10439 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10440 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10441 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10442 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
10443 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10444 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10445 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10446 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10447 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10448 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10449 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10450 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10451 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10452 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10453 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10454 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10455 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10456 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10457 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10458 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10459 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10460 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10461 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10462 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10463 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10464 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10465 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10466 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10467 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10468 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10469 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10470 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10471 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10472 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10473 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10474 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10475 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10476 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10477 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
10478 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10479 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10480 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10481 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10482 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10483 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10484 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10485 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10486 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10487 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10488 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10489 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10490 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10491 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10492 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10493 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10494 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10495 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10496 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10497 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10498 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10499 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10500 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10501 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10502 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10503 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10504 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10505 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10506 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10507 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10508 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10509 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10510 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10511 /* Refer below for TGSI_OPCODE_DFMA */
10512 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
10513 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10514 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10515 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10516 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10517 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10518 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10519 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10520 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
10521 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
10522 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10523 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10524 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10525 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10526 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10527 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10528 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
10529 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10530 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10531 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10532 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10533 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10534 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10535 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10536 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10537 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10538 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10539 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10540 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10541 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10542 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10543 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10544 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10545 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10546 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10547 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10548 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10549 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10550 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10551 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10552 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10553 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10554 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10555 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10556 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10557 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10558 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10559 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10560 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10561 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10562 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10563 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10564 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10565 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10566 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10567 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10568 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10569 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10570 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10571 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10572 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10573 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10574 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10575 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10576 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10577 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10578 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10579 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10580 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10581 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10582 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10583 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10584 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10585 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10586 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10587 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10588 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10589 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10590 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10591 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10592 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10593 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10594 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10595 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10596 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10597 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10598 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10599 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10600 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10601 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10602 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10603 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10604 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10605 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10606 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10607 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10608 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10609 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10610 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10611 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10612 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10613 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10616 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
10617 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10618 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10619 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10620 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
10621 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
10622 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10623 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10624 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10625 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10626 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10627 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10628 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10629 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10630 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10631 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10632 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10633 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10634 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10635 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10636 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
10637 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10638 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10639 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10640 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10641 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10642 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10643 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10644 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
10645 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
10646 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
10647 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10648 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10649 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10650 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10651 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10652 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
10653 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10654 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10655 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10656 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10657 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10658 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10659 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10660 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10661 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10662 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10663 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10664 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
10665 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10666 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10667 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10668 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10669 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10670 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10671 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10672 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10673 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10674 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10675 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10676 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10677 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10678 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10679 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10680 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10681 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10682 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10683 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10684 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10685 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10686 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10687 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10688 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10689 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10690 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10691 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10692 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10693 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10694 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10695 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10696 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10697 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10698 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10699 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
10700 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10701 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10702 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10703 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10704 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10705 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10706 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10707 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10708 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10709 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10710 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10711 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10712 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10713 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10714 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10715 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10716 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10717 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10718 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10719 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10720 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10721 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10722 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10723 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10724 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10725 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10726 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10727 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10728 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10729 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10730 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10731 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10732 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10733 /* Refer below for TGSI_OPCODE_DFMA */
10734 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
10735 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10736 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10737 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10738 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10739 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10740 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10741 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10742 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
10743 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
10744 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10745 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10746 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10747 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10748 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10749 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10750 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
10751 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10752 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10753 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10754 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10755 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10756 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10757 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10758 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10759 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10760 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10761 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10762 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10763 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10764 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10765 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10766 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10767 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10768 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10769 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10770 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10771 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10772 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10773 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10774 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10775 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10776 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10777 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10778 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10779 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10780 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10781 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10782 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10783 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10784 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10785 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10786 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10787 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10788 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10789 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10790 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10791 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10792 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10793 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10794 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10795 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
10796 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
10797 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10798 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10799 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10800 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10801 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10802 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10803 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10804 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10805 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10806 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10807 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10808 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10809 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10810 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10811 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10812 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10813 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10814 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10815 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10816 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10817 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10818 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10819 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10820 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10821 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10822 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10823 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10824 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10825 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10826 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10827 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10828 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10829 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10830 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10831 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10832 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10833 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10834 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10835 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},