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_llvm.h"
25 #include "r600_formats.h"
26 #include "r600_opcodes.h"
27 #include "r600_shader.h"
30 #include "sb/sb_public.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "tgsi/tgsi_info.h"
34 #include "tgsi/tgsi_parse.h"
35 #include "tgsi/tgsi_scan.h"
36 #include "tgsi/tgsi_dump.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 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
64 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
65 struct r600_pipe_shader
*pipeshader
,
66 union r600_shader_key key
);
69 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
70 int size
, unsigned comp_mask
) {
75 if (ps
->num_arrays
== ps
->max_arrays
) {
77 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
78 sizeof(struct r600_shader_array
));
81 int n
= ps
->num_arrays
;
84 ps
->arrays
[n
].comp_mask
= comp_mask
;
85 ps
->arrays
[n
].gpr_start
= start_gpr
;
86 ps
->arrays
[n
].gpr_count
= size
;
89 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
93 fprintf(stderr
, "STREAMOUT\n");
94 for (i
= 0; i
< so
->num_outputs
; i
++) {
95 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
96 so
->output
[i
].start_component
;
97 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
100 so
->output
[i
].output_buffer
,
101 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
102 so
->output
[i
].register_index
,
107 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
111 static int store_shader(struct pipe_context
*ctx
,
112 struct r600_pipe_shader
*shader
)
114 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
117 if (shader
->bo
== NULL
) {
118 shader
->bo
= (struct r600_resource
*)
119 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
120 if (shader
->bo
== NULL
) {
123 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
124 if (R600_BIG_ENDIAN
) {
125 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
126 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
129 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
131 rctx
->b
.ws
->buffer_unmap(shader
->bo
->cs_buf
);
137 int r600_pipe_shader_create(struct pipe_context
*ctx
,
138 struct r600_pipe_shader
*shader
,
139 union r600_shader_key key
)
141 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
142 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
144 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
, sel
->tokens
);
145 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
146 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
147 unsigned export_shader
;
149 shader
->shader
.bc
.isa
= rctx
->isa
;
152 fprintf(stderr
, "--------------------------------------------------------------\n");
153 tgsi_dump(sel
->tokens
, 0);
155 if (sel
->so
.num_outputs
) {
156 r600_dump_streamout(&sel
->so
);
159 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
161 R600_ERR("translation from TGSI failed !\n");
164 if (shader
->shader
.processor_type
== TGSI_PROCESSOR_VERTEX
) {
165 /* only disable for vertex shaders in tess paths */
169 use_sb
&= (shader
->shader
.processor_type
!= TGSI_PROCESSOR_TESS_CTRL
);
170 use_sb
&= (shader
->shader
.processor_type
!= TGSI_PROCESSOR_TESS_EVAL
);
172 /* disable SB for shaders using doubles */
173 use_sb
&= !shader
->shader
.uses_doubles
;
175 /* Check if the bytecode has already been built. When using the llvm
176 * backend, r600_shader_from_tgsi() will take care of building the
179 if (!shader
->shader
.bc
.bytecode
) {
180 r
= r600_bytecode_build(&shader
->shader
.bc
);
182 R600_ERR("building bytecode failed !\n");
187 if (dump
&& !sb_disasm
) {
188 fprintf(stderr
, "--------------------------------------------------------------\n");
189 r600_bytecode_disasm(&shader
->shader
.bc
);
190 fprintf(stderr
, "______________________________________________________________\n");
191 } else if ((dump
&& sb_disasm
) || use_sb
) {
192 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
195 R600_ERR("r600_sb_bytecode_process failed !\n");
200 if (shader
->gs_copy_shader
) {
203 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
204 &shader
->gs_copy_shader
->shader
, dump
, 0);
209 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
213 /* Store the shader in a buffer. */
214 if ((r
= store_shader(ctx
, shader
)))
218 switch (shader
->shader
.processor_type
) {
219 case TGSI_PROCESSOR_TESS_CTRL
:
220 evergreen_update_hs_state(ctx
, shader
);
222 case TGSI_PROCESSOR_TESS_EVAL
:
224 evergreen_update_es_state(ctx
, shader
);
226 evergreen_update_vs_state(ctx
, shader
);
228 case TGSI_PROCESSOR_GEOMETRY
:
229 if (rctx
->b
.chip_class
>= EVERGREEN
) {
230 evergreen_update_gs_state(ctx
, shader
);
231 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
233 r600_update_gs_state(ctx
, shader
);
234 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
237 case TGSI_PROCESSOR_VERTEX
:
238 export_shader
= key
.vs
.as_es
;
239 if (rctx
->b
.chip_class
>= EVERGREEN
) {
241 evergreen_update_ls_state(ctx
, shader
);
242 else if (key
.vs
.as_es
)
243 evergreen_update_es_state(ctx
, shader
);
245 evergreen_update_vs_state(ctx
, shader
);
248 r600_update_es_state(ctx
, shader
);
250 r600_update_vs_state(ctx
, shader
);
253 case TGSI_PROCESSOR_FRAGMENT
:
254 if (rctx
->b
.chip_class
>= EVERGREEN
) {
255 evergreen_update_ps_state(ctx
, shader
);
257 r600_update_ps_state(ctx
, shader
);
267 r600_pipe_shader_destroy(ctx
, shader
);
271 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
273 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
274 r600_bytecode_clear(&shader
->shader
.bc
);
275 r600_release_command_buffer(&shader
->command_buffer
);
279 * tgsi -> r600 shader
281 struct r600_shader_tgsi_instruction
;
283 struct r600_shader_src
{
290 boolean kc_rel
; /* true if cache bank is indexed */
299 struct r600_shader_ctx
{
300 struct tgsi_shader_info info
;
301 struct tgsi_parse_context parse
;
302 const struct tgsi_token
*tokens
;
304 unsigned file_offset
[TGSI_FILE_COUNT
];
306 const struct r600_shader_tgsi_instruction
*inst_info
;
307 struct r600_bytecode
*bc
;
308 struct r600_shader
*shader
;
309 struct r600_shader_src src
[4];
312 uint32_t max_driver_temp_used
;
314 /* needed for evergreen interpolation */
315 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
316 /* evergreen/cayman also store sample mask in face register */
318 /* sample id is .w component stored in fixed point position register */
319 int fixed_pt_position_gpr
;
321 boolean clip_vertex_write
;
323 unsigned edgeflag_output
;
326 int next_ring_offset
;
327 int gs_out_ring_offset
;
329 struct r600_shader
*gs_for_vs
;
330 int gs_export_gpr_tregs
[4];
331 const struct pipe_stream_output_info
*gs_stream_output_info
;
332 unsigned enabled_stream_buffers_mask
;
335 struct r600_shader_tgsi_instruction
{
337 int (*process
)(struct r600_shader_ctx
*ctx
);
340 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
341 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
342 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
343 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
344 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
345 static int tgsi_else(struct r600_shader_ctx
*ctx
);
346 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
347 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
348 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
349 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
350 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
351 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
352 unsigned int dst_reg
);
353 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
354 const struct r600_shader_src
*shader_src
,
357 static int tgsi_last_instruction(unsigned writemask
)
361 for (i
= 0; i
< 4; i
++) {
362 if (writemask
& (1 << i
)) {
369 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
371 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
374 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
375 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
378 if (i
->Instruction
.Predicate
) {
379 R600_ERR("predicate unsupported\n");
383 if (i
->Instruction
.Label
) {
384 R600_ERR("label unsupported\n");
388 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
389 if (i
->Src
[j
].Register
.Dimension
) {
390 switch (i
->Src
[j
].Register
.File
) {
391 case TGSI_FILE_CONSTANT
:
393 case TGSI_FILE_INPUT
:
394 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
)
397 R600_ERR("unsupported src %d (dimension %d)\n", j
,
398 i
->Src
[j
].Register
.Dimension
);
403 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
404 if (i
->Dst
[j
].Register
.Dimension
) {
405 R600_ERR("unsupported dst (dimension)\n");
412 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
414 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
415 interpolate
== TGSI_INTERPOLATE_LINEAR
||
416 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
418 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
422 case TGSI_INTERPOLATE_LOC_CENTER
:
425 case TGSI_INTERPOLATE_LOC_CENTROID
:
428 case TGSI_INTERPOLATE_LOC_SAMPLE
:
433 return is_linear
* 3 + loc
;
439 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
442 int i
= eg_get_interpolator_index(
443 ctx
->shader
->input
[input
].interpolate
,
444 ctx
->shader
->input
[input
].interpolate_location
);
446 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
449 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
452 struct r600_bytecode_alu alu
;
453 int gpr
= 0, base_chan
= 0;
454 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
456 /* work out gpr and base_chan from index */
458 base_chan
= (2 * (ij_index
% 2)) + 1;
460 for (i
= 0; i
< 8; i
++) {
461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
464 alu
.op
= ALU_OP2_INTERP_ZW
;
466 alu
.op
= ALU_OP2_INTERP_XY
;
468 if ((i
> 1) && (i
< 6)) {
469 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
473 alu
.dst
.chan
= i
% 4;
475 alu
.src
[0].sel
= gpr
;
476 alu
.src
[0].chan
= (base_chan
- (i
% 2));
478 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
480 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
483 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
490 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
493 struct r600_bytecode_alu alu
;
495 for (i
= 0; i
< 4; i
++) {
496 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
498 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
500 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
505 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
510 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
518 * Special export handling in shaders
520 * shader export ARRAY_BASE for EXPORT_POS:
523 * 62, 63 are clip distance vectors
525 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
526 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
527 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
528 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
529 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
530 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
531 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
532 * exclusive from render target index)
533 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
536 * shader export ARRAY_BASE for EXPORT_PIXEL:
538 * 61 computed Z vector
540 * The use of the values exported in the computed Z vector are controlled
541 * by DB_SHADER_CONTROL:
542 * Z_EXPORT_ENABLE - Z as a float in RED
543 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
544 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
545 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
546 * DB_SOURCE_FORMAT - export control restrictions
551 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
552 static int r600_spi_sid(struct r600_shader_io
* io
)
554 int index
, name
= io
->name
;
556 /* These params are handled differently, they don't need
557 * semantic indices, so we'll use 0 for them.
559 if (name
== TGSI_SEMANTIC_POSITION
||
560 name
== TGSI_SEMANTIC_PSIZE
||
561 name
== TGSI_SEMANTIC_EDGEFLAG
||
562 name
== TGSI_SEMANTIC_FACE
||
563 name
== TGSI_SEMANTIC_SAMPLEMASK
)
566 if (name
== TGSI_SEMANTIC_GENERIC
) {
567 /* For generic params simply use sid from tgsi */
570 /* For non-generic params - pack name and sid into 8 bits */
571 index
= 0x80 | (name
<<3) | (io
->sid
);
574 /* Make sure that all really used indices have nonzero value, so
575 * we can just compare it to 0 later instead of comparing the name
576 * with different values to detect special cases. */
583 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
584 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
586 switch (semantic_name
) {
587 case TGSI_SEMANTIC_POSITION
:
589 case TGSI_SEMANTIC_PSIZE
:
591 case TGSI_SEMANTIC_CLIPDIST
:
594 case TGSI_SEMANTIC_GENERIC
:
596 return 4 + index
- 9;
598 /* same explanation as in the default statement,
599 * the only user hitting this is st/nine.
603 /* patch indices are completely separate and thus start from 0 */
604 case TGSI_SEMANTIC_TESSOUTER
:
606 case TGSI_SEMANTIC_TESSINNER
:
608 case TGSI_SEMANTIC_PATCH
:
612 /* Don't fail here. The result of this function is only used
613 * for LS, TCS, TES, and GS, where legacy GL semantics can't
614 * occur, but this function is called for all vertex shaders
615 * before it's known whether LS will be compiled or not.
621 /* turn input into interpolate on EG */
622 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
626 if (ctx
->shader
->input
[index
].spi_sid
) {
627 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
628 if (ctx
->shader
->input
[index
].interpolate
> 0) {
629 evergreen_interp_assign_ij_index(ctx
, index
);
631 r
= evergreen_interp_alu(ctx
, index
);
634 r
= evergreen_interp_flat(ctx
, index
);
640 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
642 struct r600_bytecode_alu alu
;
644 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
645 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
647 for (i
= 0; i
< 4; i
++) {
648 memset(&alu
, 0, sizeof(alu
));
649 alu
.op
= ALU_OP3_CNDGT
;
652 alu
.dst
.sel
= gpr_front
;
653 alu
.src
[0].sel
= ctx
->face_gpr
;
654 alu
.src
[1].sel
= gpr_front
;
655 alu
.src
[2].sel
= gpr_back
;
662 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
669 /* execute a single slot ALU calculation */
670 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
671 int dst_sel
, int dst_chan
,
672 int src0_sel
, unsigned src0_chan_val
,
673 int src1_sel
, unsigned src1_chan_val
)
675 struct r600_bytecode_alu alu
;
678 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
679 for (i
= 0; i
< 4; i
++) {
680 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
682 alu
.src
[0].sel
= src0_sel
;
683 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
684 alu
.src
[0].value
= src0_chan_val
;
686 alu
.src
[0].chan
= src0_chan_val
;
687 alu
.src
[1].sel
= src1_sel
;
688 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
689 alu
.src
[1].value
= src1_chan_val
;
691 alu
.src
[1].chan
= src1_chan_val
;
692 alu
.dst
.sel
= dst_sel
;
694 alu
.dst
.write
= i
== dst_chan
;
696 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
703 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
705 alu
.src
[0].sel
= src0_sel
;
706 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
707 alu
.src
[0].value
= src0_chan_val
;
709 alu
.src
[0].chan
= src0_chan_val
;
710 alu
.src
[1].sel
= src1_sel
;
711 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
712 alu
.src
[1].value
= src1_chan_val
;
714 alu
.src
[1].chan
= src1_chan_val
;
715 alu
.dst
.sel
= dst_sel
;
716 alu
.dst
.chan
= dst_chan
;
719 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
725 /* execute a single slot ALU calculation */
726 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
727 int dst_sel
, int dst_chan
,
728 int src0_sel
, unsigned src0_chan_val
,
729 int src1_sel
, unsigned src1_chan_val
,
730 int src2_sel
, unsigned src2_chan_val
)
732 struct r600_bytecode_alu alu
;
735 /* validate this for other ops */
736 assert(op
== ALU_OP3_MULADD_UINT24
);
737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
739 alu
.src
[0].sel
= src0_sel
;
740 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
741 alu
.src
[0].value
= src0_chan_val
;
743 alu
.src
[0].chan
= src0_chan_val
;
744 alu
.src
[1].sel
= src1_sel
;
745 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
746 alu
.src
[1].value
= src1_chan_val
;
748 alu
.src
[1].chan
= src1_chan_val
;
749 alu
.src
[2].sel
= src2_sel
;
750 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
751 alu
.src
[2].value
= src2_chan_val
;
753 alu
.src
[2].chan
= src2_chan_val
;
754 alu
.dst
.sel
= dst_sel
;
755 alu
.dst
.chan
= dst_chan
;
758 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
764 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
766 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
769 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
771 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
774 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
777 i
= ctx
->shader
->noutput
++;
778 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
779 ctx
->shader
->output
[i
].sid
= 0;
780 ctx
->shader
->output
[i
].gpr
= 0;
781 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
782 ctx
->shader
->output
[i
].write_mask
= 0x4;
783 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
788 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
790 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
791 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
793 switch (d
->Declaration
.File
) {
794 case TGSI_FILE_INPUT
:
795 for (j
= 0; j
< count
; j
++) {
796 i
= ctx
->shader
->ninput
+ j
;
797 assert(i
< Elements(ctx
->shader
->input
));
798 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
799 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
800 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
801 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
802 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
803 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
804 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
805 switch (ctx
->shader
->input
[i
].name
) {
806 case TGSI_SEMANTIC_FACE
:
807 if (ctx
->face_gpr
!= -1)
808 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
810 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
812 case TGSI_SEMANTIC_COLOR
:
815 case TGSI_SEMANTIC_POSITION
:
816 ctx
->fragcoord_input
= i
;
818 case TGSI_SEMANTIC_PRIMID
:
819 /* set this for now */
820 ctx
->shader
->gs_prim_id_input
= true;
821 ctx
->shader
->ps_prim_id_input
= i
;
824 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
825 if ((r
= evergreen_interp_input(ctx
, i
)))
828 } else if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
829 /* FIXME probably skip inputs if they aren't passed in the ring */
830 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
831 ctx
->next_ring_offset
+= 16;
832 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
833 ctx
->shader
->gs_prim_id_input
= true;
836 ctx
->shader
->ninput
+= count
;
838 case TGSI_FILE_OUTPUT
:
839 for (j
= 0; j
< count
; j
++) {
840 i
= ctx
->shader
->noutput
+ j
;
841 assert(i
< Elements(ctx
->shader
->output
));
842 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
843 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
844 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
845 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
846 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
847 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
||
848 ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
849 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
850 switch (d
->Semantic
.Name
) {
851 case TGSI_SEMANTIC_CLIPDIST
:
852 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<<
853 ((d
->Semantic
.Index
+ j
) << 2);
855 case TGSI_SEMANTIC_PSIZE
:
856 ctx
->shader
->vs_out_misc_write
= 1;
857 ctx
->shader
->vs_out_point_size
= 1;
859 case TGSI_SEMANTIC_EDGEFLAG
:
860 ctx
->shader
->vs_out_misc_write
= 1;
861 ctx
->shader
->vs_out_edgeflag
= 1;
862 ctx
->edgeflag_output
= i
;
864 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
865 ctx
->shader
->vs_out_misc_write
= 1;
866 ctx
->shader
->vs_out_viewport
= 1;
868 case TGSI_SEMANTIC_LAYER
:
869 ctx
->shader
->vs_out_misc_write
= 1;
870 ctx
->shader
->vs_out_layer
= 1;
872 case TGSI_SEMANTIC_CLIPVERTEX
:
873 ctx
->clip_vertex_write
= TRUE
;
877 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
878 ctx
->gs_out_ring_offset
+= 16;
880 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
881 switch (d
->Semantic
.Name
) {
882 case TGSI_SEMANTIC_COLOR
:
883 ctx
->shader
->nr_ps_max_color_exports
++;
888 ctx
->shader
->noutput
+= count
;
890 case TGSI_FILE_TEMPORARY
:
891 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
892 if (d
->Array
.ArrayID
) {
893 r600_add_gpr_array(ctx
->shader
,
894 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
896 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
901 case TGSI_FILE_CONSTANT
:
902 case TGSI_FILE_SAMPLER
:
903 case TGSI_FILE_SAMPLER_VIEW
:
904 case TGSI_FILE_ADDRESS
:
907 case TGSI_FILE_SYSTEM_VALUE
:
908 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
909 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
910 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
911 break; /* Already handled from allocate_system_value_inputs */
912 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
913 if (!ctx
->native_integers
) {
914 struct r600_bytecode_alu alu
;
915 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
917 alu
.op
= ALU_OP1_INT_TO_FLT
;
926 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
930 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
932 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
935 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
941 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
943 struct tgsi_parse_context parse
;
947 unsigned name
, alternate_name
;
949 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
951 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
953 int i
, k
, num_regs
= 0;
955 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
959 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
960 while (!tgsi_parse_end_of_tokens(&parse
)) {
961 tgsi_parse_token(&parse
);
963 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
964 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
965 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
966 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
967 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
969 int interpolate
, location
, k
;
971 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
972 location
= TGSI_INTERPOLATE_LOC_CENTER
;
973 inputs
[1].enabled
= true; /* needs SAMPLEID */
974 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
975 location
= TGSI_INTERPOLATE_LOC_CENTER
;
976 /* Needs sample positions, currently those are always available */
978 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
981 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
982 k
= eg_get_interpolator_index(interpolate
, location
);
983 ctx
->eg_interpolators
[k
].enabled
= true;
985 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
986 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
987 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
988 for (k
= 0; k
< Elements(inputs
); k
++) {
989 if (d
->Semantic
.Name
== inputs
[k
].name
||
990 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
991 inputs
[k
].enabled
= true;
998 tgsi_parse_free(&parse
);
1000 for (i
= 0; i
< Elements(inputs
); i
++) {
1001 boolean enabled
= inputs
[i
].enabled
;
1002 int *reg
= inputs
[i
].reg
;
1003 unsigned name
= inputs
[i
].name
;
1006 int gpr
= gpr_offset
+ num_regs
++;
1008 // add to inputs, allocate a gpr
1009 k
= ctx
->shader
->ninput
++;
1010 ctx
->shader
->input
[k
].name
= name
;
1011 ctx
->shader
->input
[k
].sid
= 0;
1012 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1013 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1014 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1018 return gpr_offset
+ num_regs
;
1022 * for evergreen we need to scan the shader to find the number of GPRs we need to
1023 * reserve for interpolation and system values
1025 * we need to know if we are going to emit
1026 * any sample or centroid inputs
1027 * if perspective and linear are required
1029 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1033 struct tgsi_parse_context parse
;
1035 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1037 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1039 /* skip position/face/mask/sampleid */
1040 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1041 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1042 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1043 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1046 k
= eg_get_interpolator_index(
1047 ctx
->info
.input_interpolate
[i
],
1048 ctx
->info
.input_interpolate_loc
[i
]);
1050 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1053 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1057 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1058 while (!tgsi_parse_end_of_tokens(&parse
)) {
1059 tgsi_parse_token(&parse
);
1061 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1062 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1063 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1064 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1065 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1067 int interpolate
, location
, k
;
1069 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1070 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1071 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1072 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1074 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1077 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1078 k
= eg_get_interpolator_index(interpolate
, location
);
1079 ctx
->eg_interpolators
[k
].enabled
= true;
1084 tgsi_parse_free(&parse
);
1086 /* assign gpr to each interpolator according to priority */
1088 for (i
= 0; i
< Elements(ctx
->eg_interpolators
); i
++) {
1089 if (ctx
->eg_interpolators
[i
].enabled
) {
1090 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1095 /* XXX PULL MODEL and LINE STIPPLE */
1097 num_baryc
= (num_baryc
+ 1) >> 1;
1098 return allocate_system_value_inputs(ctx
, num_baryc
);
1101 /* sample_id_sel == NULL means fetch for current sample */
1102 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1104 struct r600_bytecode_vtx vtx
;
1107 assert(ctx
->fixed_pt_position_gpr
!= -1);
1109 t1
= r600_get_temp(ctx
);
1111 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1112 vtx
.op
= FETCH_OP_VFETCH
;
1113 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1114 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1115 if (sample_id
== NULL
) {
1116 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1120 struct r600_bytecode_alu alu
;
1122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1123 alu
.op
= ALU_OP1_MOV
;
1124 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1128 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1135 vtx
.mega_fetch_count
= 16;
1141 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1142 vtx
.num_format_all
= 2;
1143 vtx
.format_comp_all
= 1;
1144 vtx
.use_const_fields
= 0;
1145 vtx
.offset
= 1; // first element is size of buffer
1146 vtx
.endian
= r600_endian_swap(32);
1147 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1149 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1156 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1157 const struct tgsi_full_src_register
*tgsi_src
,
1158 struct r600_shader_src
*r600_src
)
1160 memset(r600_src
, 0, sizeof(*r600_src
));
1161 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1162 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1163 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1164 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1165 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1166 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1168 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1170 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1171 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1172 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1174 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1175 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1176 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1179 index
= tgsi_src
->Register
.Index
;
1180 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1181 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1182 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1183 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1184 r600_src
->swizzle
[0] = 2; // Z value
1185 r600_src
->swizzle
[1] = 2;
1186 r600_src
->swizzle
[2] = 2;
1187 r600_src
->swizzle
[3] = 2;
1188 r600_src
->sel
= ctx
->face_gpr
;
1189 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1190 r600_src
->swizzle
[0] = 3; // W value
1191 r600_src
->swizzle
[1] = 3;
1192 r600_src
->swizzle
[2] = 3;
1193 r600_src
->swizzle
[3] = 3;
1194 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1195 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1196 r600_src
->swizzle
[0] = 0;
1197 r600_src
->swizzle
[1] = 1;
1198 r600_src
->swizzle
[2] = 4;
1199 r600_src
->swizzle
[3] = 4;
1200 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1201 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1202 r600_src
->swizzle
[0] = 3;
1203 r600_src
->swizzle
[1] = 3;
1204 r600_src
->swizzle
[2] = 3;
1205 r600_src
->swizzle
[3] = 3;
1207 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1208 r600_src
->swizzle
[0] = 0;
1209 r600_src
->swizzle
[1] = 0;
1210 r600_src
->swizzle
[2] = 0;
1211 r600_src
->swizzle
[3] = 0;
1213 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1214 r600_src
->swizzle
[0] = 3;
1215 r600_src
->swizzle
[1] = 3;
1216 r600_src
->swizzle
[2] = 3;
1217 r600_src
->swizzle
[3] = 3;
1221 if (tgsi_src
->Register
.Indirect
)
1222 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1223 r600_src
->sel
= tgsi_src
->Register
.Index
;
1224 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1226 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1227 if (tgsi_src
->Register
.Dimension
) {
1228 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1229 if (tgsi_src
->Dimension
.Indirect
) {
1230 r600_src
->kc_rel
= 1;
1236 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1237 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1238 unsigned int dst_reg
)
1240 struct r600_bytecode_vtx vtx
;
1241 unsigned int ar_reg
;
1245 struct r600_bytecode_alu alu
;
1247 memset(&alu
, 0, sizeof(alu
));
1249 alu
.op
= ALU_OP2_ADD_INT
;
1250 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1251 alu
.src
[0].chan
= ar_chan
;
1253 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1254 alu
.src
[1].value
= offset
;
1256 alu
.dst
.sel
= dst_reg
;
1257 alu
.dst
.chan
= ar_chan
;
1261 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1266 ar_reg
= ctx
->bc
->ar_reg
;
1269 memset(&vtx
, 0, sizeof(vtx
));
1270 vtx
.buffer_id
= cb_idx
;
1271 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1272 vtx
.src_gpr
= ar_reg
;
1273 vtx
.src_sel_x
= ar_chan
;
1274 vtx
.mega_fetch_count
= 16;
1275 vtx
.dst_gpr
= dst_reg
;
1276 vtx
.dst_sel_x
= 0; /* SEL_X */
1277 vtx
.dst_sel_y
= 1; /* SEL_Y */
1278 vtx
.dst_sel_z
= 2; /* SEL_Z */
1279 vtx
.dst_sel_w
= 3; /* SEL_W */
1280 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1281 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1282 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1283 vtx
.endian
= r600_endian_swap(32);
1284 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1286 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1292 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1294 struct r600_bytecode_vtx vtx
;
1296 unsigned index
= src
->Register
.Index
;
1297 unsigned vtx_id
= src
->Dimension
.Index
;
1298 int offset_reg
= vtx_id
/ 3;
1299 int offset_chan
= vtx_id
% 3;
1301 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1302 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1304 if (offset_reg
== 0 && offset_chan
== 2)
1307 if (src
->Dimension
.Indirect
) {
1310 struct r600_bytecode_alu alu
;
1313 /* you have got to be shitting me -
1314 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1315 at least this is what fglrx seems to do. */
1316 for (i
= 0; i
< 3; i
++) {
1317 treg
[i
] = r600_get_temp(ctx
);
1319 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1321 t2
= r600_get_temp(ctx
);
1322 for (i
= 0; i
< 3; i
++) {
1323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1324 alu
.op
= ALU_OP1_MOV
;
1326 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1327 alu
.dst
.sel
= treg
[i
];
1331 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1335 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1336 alu
.op
= ALU_OP1_MOV
;
1337 alu
.src
[0].sel
= treg
[0];
1342 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1349 memset(&vtx
, 0, sizeof(vtx
));
1350 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1351 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1352 vtx
.src_gpr
= offset_reg
;
1353 vtx
.src_sel_x
= offset_chan
;
1354 vtx
.offset
= index
* 16; /*bytes*/
1355 vtx
.mega_fetch_count
= 16;
1356 vtx
.dst_gpr
= dst_reg
;
1357 vtx
.dst_sel_x
= 0; /* SEL_X */
1358 vtx
.dst_sel_y
= 1; /* SEL_Y */
1359 vtx
.dst_sel_z
= 2; /* SEL_Z */
1360 vtx
.dst_sel_w
= 3; /* SEL_W */
1361 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1362 vtx
.use_const_fields
= 1;
1364 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1367 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1373 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1375 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1378 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1379 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1381 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1382 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1383 /* primitive id is in R0.z */
1384 ctx
->src
[i
].sel
= 0;
1385 ctx
->src
[i
].swizzle
[0] = 2;
1388 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1389 int treg
= r600_get_temp(ctx
);
1391 fetch_gs_input(ctx
, src
, treg
);
1392 ctx
->src
[i
].sel
= treg
;
1398 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1400 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1401 struct r600_bytecode_alu alu
;
1402 int i
, j
, k
, nconst
, r
;
1404 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1405 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1408 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1410 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1411 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1415 if (ctx
->src
[i
].rel
) {
1416 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1417 int treg
= r600_get_temp(ctx
);
1418 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1421 ctx
->src
[i
].kc_bank
= 0;
1422 ctx
->src
[i
].kc_rel
= 0;
1423 ctx
->src
[i
].sel
= treg
;
1424 ctx
->src
[i
].rel
= 0;
1427 int treg
= r600_get_temp(ctx
);
1428 for (k
= 0; k
< 4; k
++) {
1429 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1430 alu
.op
= ALU_OP1_MOV
;
1431 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1432 alu
.src
[0].chan
= k
;
1433 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1434 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1435 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1441 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1445 ctx
->src
[i
].sel
= treg
;
1453 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1454 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1456 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1457 struct r600_bytecode_alu alu
;
1458 int i
, j
, k
, nliteral
, r
;
1460 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1461 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1465 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1466 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1467 int treg
= r600_get_temp(ctx
);
1468 for (k
= 0; k
< 4; k
++) {
1469 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1470 alu
.op
= ALU_OP1_MOV
;
1471 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1472 alu
.src
[0].chan
= k
;
1473 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1483 ctx
->src
[i
].sel
= treg
;
1490 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1492 int i
, r
, count
= ctx
->shader
->ninput
;
1494 for (i
= 0; i
< count
; i
++) {
1495 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1496 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1504 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
1505 int stream
, unsigned *stream_item_size
)
1507 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1508 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
1511 /* Sanity checking. */
1512 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
1513 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
1517 for (i
= 0; i
< so
->num_outputs
; i
++) {
1518 if (so
->output
[i
].output_buffer
>= 4) {
1519 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1520 so
->output
[i
].output_buffer
);
1526 /* Initialize locations where the outputs are stored. */
1527 for (i
= 0; i
< so
->num_outputs
; i
++) {
1529 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
1530 start_comp
[i
] = so
->output
[i
].start_component
;
1531 /* Lower outputs with dst_offset < start_component.
1533 * We can only output 4D vectors with a write mask, e.g. we can
1534 * only output the W component at offset 3, etc. If we want
1535 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1536 * to move it to X and output X. */
1537 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
1538 unsigned tmp
= r600_get_temp(ctx
);
1540 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
1541 struct r600_bytecode_alu alu
;
1542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1543 alu
.op
= ALU_OP1_MOV
;
1544 alu
.src
[0].sel
= so_gpr
[i
];
1545 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
1550 if (j
== so
->output
[i
].num_components
- 1)
1552 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1561 /* Write outputs to buffers. */
1562 for (i
= 0; i
< so
->num_outputs
; i
++) {
1563 struct r600_bytecode_output output
;
1565 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
1568 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1569 output
.gpr
= so_gpr
[i
];
1570 output
.elem_size
= so
->output
[i
].num_components
- 1;
1571 if (output
.elem_size
== 2)
1572 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
1573 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
1574 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1575 output
.burst_count
= 1;
1576 /* array_size is an upper limit for the burst_count
1577 * with MEM_STREAM instructions */
1578 output
.array_size
= 0xFFF;
1579 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
1581 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1582 switch (so
->output
[i
].output_buffer
) {
1584 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1587 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1590 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1593 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1596 output
.op
+= so
->output
[i
].stream
* 4;
1597 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
1598 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
1600 switch (so
->output
[i
].output_buffer
) {
1602 output
.op
= CF_OP_MEM_STREAM0
;
1605 output
.op
= CF_OP_MEM_STREAM1
;
1608 output
.op
= CF_OP_MEM_STREAM2
;
1611 output
.op
= CF_OP_MEM_STREAM3
;
1614 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
1616 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
1625 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
1627 struct r600_bytecode_alu alu
;
1630 if (!ctx
->shader
->vs_out_edgeflag
)
1633 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
1635 /* clamp(x, 0, 1) */
1636 memset(&alu
, 0, sizeof(alu
));
1637 alu
.op
= ALU_OP1_MOV
;
1638 alu
.src
[0].sel
= reg
;
1643 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1645 memset(&alu
, 0, sizeof(alu
));
1646 alu
.op
= ALU_OP1_FLT_TO_INT
;
1647 alu
.src
[0].sel
= reg
;
1651 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1654 static int generate_gs_copy_shader(struct r600_context
*rctx
,
1655 struct r600_pipe_shader
*gs
,
1656 struct pipe_stream_output_info
*so
)
1658 struct r600_shader_ctx ctx
= {};
1659 struct r600_shader
*gs_shader
= &gs
->shader
;
1660 struct r600_pipe_shader
*cshader
;
1661 int ocnt
= gs_shader
->noutput
;
1662 struct r600_bytecode_alu alu
;
1663 struct r600_bytecode_vtx vtx
;
1664 struct r600_bytecode_output output
;
1665 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
1666 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
1667 int i
, j
, next_clip_pos
= 61, next_param
= 0;
1670 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
1674 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
1675 sizeof(struct r600_shader_io
));
1677 cshader
->shader
.noutput
= ocnt
;
1679 ctx
.shader
= &cshader
->shader
;
1680 ctx
.bc
= &ctx
.shader
->bc
;
1681 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
1683 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
1684 rctx
->screen
->has_compressed_msaa_texturing
);
1686 ctx
.bc
->isa
= rctx
->isa
;
1689 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
1691 /* R0.x = R0.x & 0x3fffffff */
1692 memset(&alu
, 0, sizeof(alu
));
1693 alu
.op
= ALU_OP2_AND_INT
;
1694 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1695 alu
.src
[1].value
= 0x3fffffff;
1697 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1699 /* R0.y = R0.x >> 30 */
1700 memset(&alu
, 0, sizeof(alu
));
1701 alu
.op
= ALU_OP2_LSHR_INT
;
1702 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1703 alu
.src
[1].value
= 0x1e;
1707 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1709 /* fetch vertex data from GSVS ring */
1710 for (i
= 0; i
< ocnt
; ++i
) {
1711 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1714 out
->ring_offset
= i
* 16;
1716 memset(&vtx
, 0, sizeof(vtx
));
1717 vtx
.op
= FETCH_OP_VFETCH
;
1718 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1719 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1720 vtx
.mega_fetch_count
= 16;
1721 vtx
.offset
= out
->ring_offset
;
1722 vtx
.dst_gpr
= out
->gpr
;
1728 if (rctx
->b
.chip_class
>= EVERGREEN
) {
1729 vtx
.use_const_fields
= 1;
1731 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1734 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
1736 ctx
.temp_reg
= i
+ 1;
1737 for (ring
= 3; ring
>= 0; --ring
) {
1738 bool enabled
= false;
1739 for (i
= 0; i
< so
->num_outputs
; i
++) {
1740 if (so
->output
[i
].stream
== ring
) {
1745 if (ring
!= 0 && !enabled
) {
1746 cshader
->shader
.ring_item_sizes
[ring
] = 0;
1751 // Patch up jump label
1752 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1753 cf_pop
= ctx
.bc
->cf_last
;
1755 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1756 cf_jump
->pop_count
= 1;
1757 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1758 cf_pop
->pop_count
= 1;
1761 /* PRED_SETE_INT __, R0.y, ring */
1762 memset(&alu
, 0, sizeof(alu
));
1763 alu
.op
= ALU_OP2_PRED_SETE_INT
;
1764 alu
.src
[0].chan
= 1;
1765 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1766 alu
.src
[1].value
= ring
;
1767 alu
.execute_mask
= 1;
1768 alu
.update_pred
= 1;
1770 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
1772 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
1773 cf_jump
= ctx
.bc
->cf_last
;
1776 emit_streamout(&ctx
, so
, ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
1777 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
1780 /* bc adds nops - copy it */
1781 if (ctx
.bc
->chip_class
== R600
) {
1782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1783 alu
.op
= ALU_OP0_NOP
;
1785 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1787 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1790 /* export vertex data */
1791 /* XXX factor out common code with r600_shader_from_tgsi ? */
1792 for (i
= 0; i
< ocnt
; ++i
) {
1793 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1794 bool instream0
= true;
1795 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
1798 for (j
= 0; j
< so
->num_outputs
; j
++) {
1799 if (so
->output
[j
].register_index
== i
) {
1800 if (so
->output
[j
].stream
== 0)
1802 if (so
->output
[j
].stream
> 0)
1808 memset(&output
, 0, sizeof(output
));
1809 output
.gpr
= out
->gpr
;
1810 output
.elem_size
= 3;
1811 output
.swizzle_x
= 0;
1812 output
.swizzle_y
= 1;
1813 output
.swizzle_z
= 2;
1814 output
.swizzle_w
= 3;
1815 output
.burst_count
= 1;
1816 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1817 output
.op
= CF_OP_EXPORT
;
1818 switch (out
->name
) {
1819 case TGSI_SEMANTIC_POSITION
:
1820 output
.array_base
= 60;
1821 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1824 case TGSI_SEMANTIC_PSIZE
:
1825 output
.array_base
= 61;
1826 if (next_clip_pos
== 61)
1828 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1829 output
.swizzle_y
= 7;
1830 output
.swizzle_z
= 7;
1831 output
.swizzle_w
= 7;
1832 ctx
.shader
->vs_out_misc_write
= 1;
1833 ctx
.shader
->vs_out_point_size
= 1;
1835 case TGSI_SEMANTIC_LAYER
:
1837 /* duplicate it as PARAM to pass to the pixel shader */
1838 output
.array_base
= next_param
++;
1839 r600_bytecode_add_output(ctx
.bc
, &output
);
1840 last_exp_param
= ctx
.bc
->cf_last
;
1842 output
.array_base
= 61;
1843 if (next_clip_pos
== 61)
1845 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1846 output
.swizzle_x
= 7;
1847 output
.swizzle_y
= 7;
1848 output
.swizzle_z
= 0;
1849 output
.swizzle_w
= 7;
1850 ctx
.shader
->vs_out_misc_write
= 1;
1851 ctx
.shader
->vs_out_layer
= 1;
1853 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
1855 /* duplicate it as PARAM to pass to the pixel shader */
1856 output
.array_base
= next_param
++;
1857 r600_bytecode_add_output(ctx
.bc
, &output
);
1858 last_exp_param
= ctx
.bc
->cf_last
;
1860 output
.array_base
= 61;
1861 if (next_clip_pos
== 61)
1863 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1864 ctx
.shader
->vs_out_misc_write
= 1;
1865 ctx
.shader
->vs_out_viewport
= 1;
1866 output
.swizzle_x
= 7;
1867 output
.swizzle_y
= 7;
1868 output
.swizzle_z
= 7;
1869 output
.swizzle_w
= 0;
1871 case TGSI_SEMANTIC_CLIPDIST
:
1872 /* spi_sid is 0 for clipdistance outputs that were generated
1873 * for clipvertex - we don't need to pass them to PS */
1874 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
1876 /* duplicate it as PARAM to pass to the pixel shader */
1877 output
.array_base
= next_param
++;
1878 r600_bytecode_add_output(ctx
.bc
, &output
);
1879 last_exp_param
= ctx
.bc
->cf_last
;
1881 output
.array_base
= next_clip_pos
++;
1882 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1884 case TGSI_SEMANTIC_FOG
:
1885 output
.swizzle_y
= 4; /* 0 */
1886 output
.swizzle_z
= 4; /* 0 */
1887 output
.swizzle_w
= 5; /* 1 */
1890 output
.array_base
= next_param
++;
1893 r600_bytecode_add_output(ctx
.bc
, &output
);
1894 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
1895 last_exp_param
= ctx
.bc
->cf_last
;
1897 last_exp_pos
= ctx
.bc
->cf_last
;
1900 if (!last_exp_pos
) {
1901 memset(&output
, 0, sizeof(output
));
1903 output
.elem_size
= 3;
1904 output
.swizzle_x
= 7;
1905 output
.swizzle_y
= 7;
1906 output
.swizzle_z
= 7;
1907 output
.swizzle_w
= 7;
1908 output
.burst_count
= 1;
1910 output
.op
= CF_OP_EXPORT
;
1911 output
.array_base
= 60;
1912 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1913 r600_bytecode_add_output(ctx
.bc
, &output
);
1914 last_exp_pos
= ctx
.bc
->cf_last
;
1917 if (!last_exp_param
) {
1918 memset(&output
, 0, sizeof(output
));
1920 output
.elem_size
= 3;
1921 output
.swizzle_x
= 7;
1922 output
.swizzle_y
= 7;
1923 output
.swizzle_z
= 7;
1924 output
.swizzle_w
= 7;
1925 output
.burst_count
= 1;
1927 output
.op
= CF_OP_EXPORT
;
1928 output
.array_base
= next_param
++;
1929 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1930 r600_bytecode_add_output(ctx
.bc
, &output
);
1931 last_exp_param
= ctx
.bc
->cf_last
;
1934 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
1935 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
1937 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1938 cf_pop
= ctx
.bc
->cf_last
;
1940 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1941 cf_jump
->pop_count
= 1;
1942 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1943 cf_pop
->pop_count
= 1;
1945 if (ctx
.bc
->chip_class
== CAYMAN
)
1946 cm_bytecode_add_cf_end(ctx
.bc
);
1948 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1949 ctx
.bc
->cf_last
->end_of_program
= 1;
1952 gs
->gs_copy_shader
= cshader
;
1953 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
1957 return r600_bytecode_build(ctx
.bc
);
1960 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
1963 struct r600_bytecode_alu alu
;
1966 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1967 alu
.op
= ALU_OP2_ADD_INT
;
1968 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
1969 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1970 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
1971 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
1974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1981 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
)
1983 struct r600_bytecode_output output
;
1984 int i
, k
, ring_offset
;
1985 int effective_stream
= stream
== -1 ? 0 : stream
;
1988 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
1989 if (ctx
->gs_for_vs
) {
1990 /* for ES we need to lookup corresponding ring offset expected by GS
1991 * (map this output to GS input by name and sid) */
1992 /* FIXME precompute offsets */
1994 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
1995 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
1996 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
1997 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
1998 ring_offset
= in
->ring_offset
;
2001 if (ring_offset
== -1)
2004 ring_offset
= idx
* 16;
2008 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2010 /* next_ring_offset after parsing input decls contains total size of
2011 * single vertex data, gs_next_vertex - current vertex index */
2013 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2015 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2016 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2017 output
.elem_size
= 3;
2018 output
.comp_mask
= 0xF;
2019 output
.burst_count
= 1;
2022 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2024 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2029 output
.op
= CF_OP_MEM_RING
; break;
2031 output
.op
= CF_OP_MEM_RING1
; break;
2033 output
.op
= CF_OP_MEM_RING2
; break;
2035 output
.op
= CF_OP_MEM_RING3
; break;
2039 output
.array_base
= ring_offset
>> 2; /* in dwords */
2040 output
.array_size
= 0xfff;
2041 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2043 output
.array_base
= ring_offset
>> 2; /* in dwords */
2044 r600_bytecode_add_output(ctx
->bc
, &output
);
2047 ++ctx
->gs_next_vertex
;
2051 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
2052 struct r600_pipe_shader
*pipeshader
,
2053 union r600_shader_key key
)
2055 struct r600_screen
*rscreen
= rctx
->screen
;
2056 struct r600_shader
*shader
= &pipeshader
->shader
;
2057 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
2058 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
2059 struct tgsi_full_immediate
*immediate
;
2060 struct r600_shader_ctx ctx
;
2061 struct r600_bytecode_output output
[32];
2062 unsigned output_done
, noutput
;
2065 int next_param_base
= 0, next_clip_base
;
2066 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
2067 /* Declarations used by llvm code */
2068 bool use_llvm
= false;
2070 bool ring_outputs
= false;
2071 bool pos_emitted
= false;
2073 #ifdef R600_USE_LLVM
2074 use_llvm
= rscreen
->b
.debug_flags
& DBG_LLVM
;
2076 ctx
.bc
= &shader
->bc
;
2077 ctx
.shader
= shader
;
2078 ctx
.native_integers
= true;
2081 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
2082 rscreen
->has_compressed_msaa_texturing
);
2083 ctx
.tokens
= tokens
;
2084 tgsi_scan_shader(tokens
, &ctx
.info
);
2085 shader
->indirect_files
= ctx
.info
.indirect_files
;
2087 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
2089 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
2090 tgsi_parse_init(&ctx
.parse
, tokens
);
2091 ctx
.type
= ctx
.info
.processor
;
2092 shader
->processor_type
= ctx
.type
;
2093 ctx
.bc
->type
= shader
->processor_type
;
2096 case TGSI_PROCESSOR_VERTEX
:
2097 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
2098 shader
->vs_as_es
= key
.vs
.as_es
;
2099 shader
->vs_as_ls
= key
.vs
.as_ls
;
2100 if (shader
->vs_as_es
)
2101 ring_outputs
= true;
2103 case TGSI_PROCESSOR_GEOMETRY
:
2104 ring_outputs
= true;
2106 case TGSI_PROCESSOR_TESS_CTRL
:
2107 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
2109 case TGSI_PROCESSOR_TESS_EVAL
:
2110 shader
->tes_as_es
= key
.tes
.as_es
;
2111 if (shader
->tes_as_es
)
2112 ring_outputs
= true;
2114 case TGSI_PROCESSOR_FRAGMENT
:
2115 shader
->two_side
= key
.ps
.color_two_side
;
2121 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
2122 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
2124 ctx
.gs_for_vs
= NULL
;
2127 ctx
.next_ring_offset
= 0;
2128 ctx
.gs_out_ring_offset
= 0;
2129 ctx
.gs_next_vertex
= 0;
2130 ctx
.gs_stream_output_info
= &so
;
2133 ctx
.fixed_pt_position_gpr
= -1;
2134 ctx
.fragcoord_input
= -1;
2135 ctx
.colors_used
= 0;
2136 ctx
.clip_vertex_write
= 0;
2138 shader
->nr_ps_color_exports
= 0;
2139 shader
->nr_ps_max_color_exports
= 0;
2142 /* register allocations */
2143 /* Values [0,127] correspond to GPR[0..127].
2144 * Values [128,159] correspond to constant buffer bank 0
2145 * Values [160,191] correspond to constant buffer bank 1
2146 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
2147 * Values [256,287] correspond to constant buffer bank 2 (EG)
2148 * Values [288,319] correspond to constant buffer bank 3 (EG)
2149 * Other special values are shown in the list below.
2150 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
2151 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
2152 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
2153 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
2154 * 248 SQ_ALU_SRC_0: special constant 0.0.
2155 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
2156 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
2157 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
2158 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
2159 * 253 SQ_ALU_SRC_LITERAL: literal constant.
2160 * 254 SQ_ALU_SRC_PV: previous vector result.
2161 * 255 SQ_ALU_SRC_PS: previous scalar result.
2163 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
2164 ctx
.file_offset
[i
] = 0;
2167 #ifdef R600_USE_LLVM
2168 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
2169 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
2170 "indirect adressing. Falling back to TGSI "
2175 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
2176 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
2178 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
2181 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
) {
2182 if (ctx
.bc
->chip_class
>= EVERGREEN
)
2183 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
2185 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
2187 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2188 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
2189 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
2191 ctx
.use_llvm
= use_llvm
;
2194 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
2195 ctx
.file_offset
[TGSI_FILE_INPUT
];
2197 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
2198 ctx
.file_offset
[TGSI_FILE_INPUT
] +
2199 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
2201 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
2202 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
2204 /* Outside the GPR range. This will be translated to one of the
2205 * kcache banks later. */
2206 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
2208 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
2209 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
2210 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
2211 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
2212 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
2214 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2215 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
2216 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
2217 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
2218 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
2219 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
2221 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
2224 shader
->max_arrays
= 0;
2225 shader
->num_arrays
= 0;
2226 if (indirect_gprs
) {
2228 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
2229 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
2230 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
2231 ctx
.file_offset
[TGSI_FILE_INPUT
],
2234 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
2235 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
2236 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
2237 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
2243 ctx
.literals
= NULL
;
2245 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
];
2246 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
2247 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
2249 if (shader
->vs_as_gs_a
)
2250 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
2252 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
2253 tgsi_parse_token(&ctx
.parse
);
2254 switch (ctx
.parse
.FullToken
.Token
.Type
) {
2255 case TGSI_TOKEN_TYPE_IMMEDIATE
:
2256 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
2257 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
2258 if(ctx
.literals
== NULL
) {
2262 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
2263 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
2264 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
2265 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
2268 case TGSI_TOKEN_TYPE_DECLARATION
:
2269 r
= tgsi_declaration(&ctx
);
2273 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2274 case TGSI_TOKEN_TYPE_PROPERTY
:
2277 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
2283 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
2284 shader
->ring_item_sizes
[1] = 0;
2285 shader
->ring_item_sizes
[2] = 0;
2286 shader
->ring_item_sizes
[3] = 0;
2288 /* Process two side if needed */
2289 if (shader
->two_side
&& ctx
.colors_used
) {
2290 int i
, count
= ctx
.shader
->ninput
;
2291 unsigned next_lds_loc
= ctx
.shader
->nlds
;
2293 /* additional inputs will be allocated right after the existing inputs,
2294 * we won't need them after the color selection, so we don't need to
2295 * reserve these gprs for the rest of the shader code and to adjust
2296 * output offsets etc. */
2297 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
2298 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
2300 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
2301 if (ctx
.face_gpr
== -1) {
2302 i
= ctx
.shader
->ninput
++;
2303 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
2304 ctx
.shader
->input
[i
].spi_sid
= 0;
2305 ctx
.shader
->input
[i
].gpr
= gpr
++;
2306 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
2309 for (i
= 0; i
< count
; i
++) {
2310 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2311 int ni
= ctx
.shader
->ninput
++;
2312 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
2313 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
2314 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
2315 ctx
.shader
->input
[ni
].gpr
= gpr
++;
2316 // TGSI to LLVM needs to know the lds position of inputs.
2317 // Non LLVM path computes it later (in process_twoside_color)
2318 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
2319 ctx
.shader
->input
[i
].back_color_input
= ni
;
2320 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
2321 if ((r
= evergreen_interp_input(&ctx
, ni
)))
2328 /* LLVM backend setup */
2329 #ifdef R600_USE_LLVM
2331 struct radeon_llvm_context radeon_llvm_ctx
;
2333 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
2334 boolean use_kill
= false;
2336 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
2337 radeon_llvm_ctx
.type
= ctx
.type
;
2338 radeon_llvm_ctx
.two_side
= shader
->two_side
;
2339 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
2340 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
2341 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
2342 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
2343 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
2344 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
2345 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
2346 radeon_llvm_ctx
.stream_outputs
= &so
;
2347 radeon_llvm_ctx
.alpha_to_one
= key
.ps
.alpha_to_one
;
2348 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
2349 ctx
.bc
->has_compressed_msaa_texturing
;
2350 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
2351 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
2352 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
2354 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
2355 radeon_llvm_dispose(&radeon_llvm_ctx
);
2357 fprintf(stderr
, "R600 LLVM backend failed to compile "
2358 "shader. Falling back to TGSI\n");
2360 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
2361 ctx
.file_offset
[TGSI_FILE_INPUT
];
2364 ctx
.shader
->uses_kill
= use_kill
;
2365 radeon_llvm_dispose(&radeon_llvm_ctx
);
2368 /* End of LLVM backend setup */
2370 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
2371 shader
->nr_ps_max_color_exports
= 8;
2374 if (ctx
.fragcoord_input
>= 0) {
2375 if (ctx
.bc
->chip_class
== CAYMAN
) {
2376 for (j
= 0 ; j
< 4; j
++) {
2377 struct r600_bytecode_alu alu
;
2378 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2379 alu
.op
= ALU_OP1_RECIP_IEEE
;
2380 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2381 alu
.src
[0].chan
= 3;
2383 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2385 alu
.dst
.write
= (j
== 3);
2387 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
2391 struct r600_bytecode_alu alu
;
2392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2393 alu
.op
= ALU_OP1_RECIP_IEEE
;
2394 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2395 alu
.src
[0].chan
= 3;
2397 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2401 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
2406 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2407 struct r600_bytecode_alu alu
;
2410 /* GS thread with no output workaround - emit a cut at start of GS */
2411 if (ctx
.bc
->chip_class
== R600
)
2412 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
2414 for (j
= 0; j
< 4; j
++) {
2415 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2416 alu
.op
= ALU_OP1_MOV
;
2417 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2418 alu
.src
[0].value
= 0;
2419 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
2422 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
2427 if (shader
->two_side
&& ctx
.colors_used
) {
2428 if ((r
= process_twoside_color_inputs(&ctx
)))
2432 tgsi_parse_init(&ctx
.parse
, tokens
);
2433 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
2434 tgsi_parse_token(&ctx
.parse
);
2435 switch (ctx
.parse
.FullToken
.Token
.Type
) {
2436 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2437 r
= tgsi_is_supported(&ctx
);
2440 ctx
.max_driver_temp_used
= 0;
2441 /* reserve first tmp for everyone */
2442 r600_get_temp(&ctx
);
2444 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
2445 if ((r
= tgsi_split_constant(&ctx
)))
2447 if ((r
= tgsi_split_literal_constant(&ctx
)))
2449 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
)
2450 if ((r
= tgsi_split_gs_inputs(&ctx
)))
2452 if (ctx
.bc
->chip_class
== CAYMAN
)
2453 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
2454 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
2455 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
2457 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
2458 r
= ctx
.inst_info
->process(&ctx
);
2468 /* Reset the temporary register counter. */
2469 ctx
.max_driver_temp_used
= 0;
2471 noutput
= shader
->noutput
;
2473 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
2474 unsigned clipdist_temp
[2];
2476 clipdist_temp
[0] = r600_get_temp(&ctx
);
2477 clipdist_temp
[1] = r600_get_temp(&ctx
);
2479 /* need to convert a clipvertex write into clipdistance writes and not export
2480 the clip vertex anymore */
2482 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
2483 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
2484 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
2486 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
2487 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
2490 /* reset spi_sid for clipvertex output to avoid confusing spi */
2491 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
2493 shader
->clip_dist_write
= 0xFF;
2495 for (i
= 0; i
< 8; i
++) {
2499 for (j
= 0; j
< 4; j
++) {
2500 struct r600_bytecode_alu alu
;
2501 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2502 alu
.op
= ALU_OP2_DOT4
;
2503 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
2504 alu
.src
[0].chan
= j
;
2506 alu
.src
[1].sel
= 512 + i
;
2507 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
2508 alu
.src
[1].chan
= j
;
2510 alu
.dst
.sel
= clipdist_temp
[oreg
];
2512 alu
.dst
.write
= (j
== ochan
);
2516 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
2523 /* Add stream outputs. */
2524 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
&&
2525 so
.num_outputs
&& !use_llvm
)
2526 emit_streamout(&ctx
, &so
, -1, NULL
);
2528 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2529 convert_edgeflag_to_int(&ctx
);
2532 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
2533 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
2534 ctx
.gs_export_gpr_tregs
[1] = -1;
2535 ctx
.gs_export_gpr_tregs
[2] = -1;
2536 ctx
.gs_export_gpr_tregs
[3] = -1;
2538 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
2542 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
2544 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
2545 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2546 output
[j
].gpr
= shader
->output
[i
].gpr
;
2547 output
[j
].elem_size
= 3;
2548 output
[j
].swizzle_x
= 0;
2549 output
[j
].swizzle_y
= 1;
2550 output
[j
].swizzle_z
= 2;
2551 output
[j
].swizzle_w
= 3;
2552 output
[j
].burst_count
= 1;
2553 output
[j
].type
= -1;
2554 output
[j
].op
= CF_OP_EXPORT
;
2556 case TGSI_PROCESSOR_VERTEX
:
2557 switch (shader
->output
[i
].name
) {
2558 case TGSI_SEMANTIC_POSITION
:
2559 output
[j
].array_base
= 60;
2560 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2564 case TGSI_SEMANTIC_PSIZE
:
2565 output
[j
].array_base
= 61;
2566 output
[j
].swizzle_y
= 7;
2567 output
[j
].swizzle_z
= 7;
2568 output
[j
].swizzle_w
= 7;
2569 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2572 case TGSI_SEMANTIC_EDGEFLAG
:
2573 output
[j
].array_base
= 61;
2574 output
[j
].swizzle_x
= 7;
2575 output
[j
].swizzle_y
= 0;
2576 output
[j
].swizzle_z
= 7;
2577 output
[j
].swizzle_w
= 7;
2578 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2581 case TGSI_SEMANTIC_LAYER
:
2582 /* spi_sid is 0 for outputs that are
2583 * not consumed by PS */
2584 if (shader
->output
[i
].spi_sid
) {
2585 output
[j
].array_base
= next_param_base
++;
2586 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2588 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2590 output
[j
].array_base
= 61;
2591 output
[j
].swizzle_x
= 7;
2592 output
[j
].swizzle_y
= 7;
2593 output
[j
].swizzle_z
= 0;
2594 output
[j
].swizzle_w
= 7;
2595 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2598 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2599 /* spi_sid is 0 for outputs that are
2600 * not consumed by PS */
2601 if (shader
->output
[i
].spi_sid
) {
2602 output
[j
].array_base
= next_param_base
++;
2603 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2605 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2607 output
[j
].array_base
= 61;
2608 output
[j
].swizzle_x
= 7;
2609 output
[j
].swizzle_y
= 7;
2610 output
[j
].swizzle_z
= 7;
2611 output
[j
].swizzle_w
= 0;
2612 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2615 case TGSI_SEMANTIC_CLIPVERTEX
:
2618 case TGSI_SEMANTIC_CLIPDIST
:
2619 output
[j
].array_base
= next_clip_base
++;
2620 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2622 /* spi_sid is 0 for clipdistance outputs that were generated
2623 * for clipvertex - we don't need to pass them to PS */
2624 if (shader
->output
[i
].spi_sid
) {
2626 /* duplicate it as PARAM to pass to the pixel shader */
2627 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2628 output
[j
].array_base
= next_param_base
++;
2629 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2632 case TGSI_SEMANTIC_FOG
:
2633 output
[j
].swizzle_y
= 4; /* 0 */
2634 output
[j
].swizzle_z
= 4; /* 0 */
2635 output
[j
].swizzle_w
= 5; /* 1 */
2637 case TGSI_SEMANTIC_PRIMID
:
2638 output
[j
].swizzle_x
= 2;
2639 output
[j
].swizzle_y
= 4; /* 0 */
2640 output
[j
].swizzle_z
= 4; /* 0 */
2641 output
[j
].swizzle_w
= 4; /* 0 */
2646 case TGSI_PROCESSOR_FRAGMENT
:
2647 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2648 /* never export more colors than the number of CBs */
2649 if (shader
->output
[i
].sid
>= max_color_exports
) {
2654 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
2655 output
[j
].array_base
= shader
->output
[i
].sid
;
2656 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2657 shader
->nr_ps_color_exports
++;
2658 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
2659 for (k
= 1; k
< max_color_exports
; k
++) {
2661 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2662 output
[j
].gpr
= shader
->output
[i
].gpr
;
2663 output
[j
].elem_size
= 3;
2664 output
[j
].swizzle_x
= 0;
2665 output
[j
].swizzle_y
= 1;
2666 output
[j
].swizzle_z
= 2;
2667 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
2668 output
[j
].burst_count
= 1;
2669 output
[j
].array_base
= k
;
2670 output
[j
].op
= CF_OP_EXPORT
;
2671 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2672 shader
->nr_ps_color_exports
++;
2675 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
2676 output
[j
].array_base
= 61;
2677 output
[j
].swizzle_x
= 2;
2678 output
[j
].swizzle_y
= 7;
2679 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2680 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2681 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
2682 output
[j
].array_base
= 61;
2683 output
[j
].swizzle_x
= 7;
2684 output
[j
].swizzle_y
= 1;
2685 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2686 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2687 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
2688 output
[j
].array_base
= 61;
2689 output
[j
].swizzle_x
= 7;
2690 output
[j
].swizzle_y
= 7;
2691 output
[j
].swizzle_z
= 0;
2692 output
[j
].swizzle_w
= 7;
2693 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2695 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
2701 R600_ERR("unsupported processor type %d\n", ctx
.type
);
2706 if (output
[j
].type
==-1) {
2707 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2708 output
[j
].array_base
= next_param_base
++;
2712 /* add fake position export */
2713 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& pos_emitted
== false) {
2714 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2716 output
[j
].elem_size
= 3;
2717 output
[j
].swizzle_x
= 7;
2718 output
[j
].swizzle_y
= 7;
2719 output
[j
].swizzle_z
= 7;
2720 output
[j
].swizzle_w
= 7;
2721 output
[j
].burst_count
= 1;
2722 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2723 output
[j
].array_base
= 60;
2724 output
[j
].op
= CF_OP_EXPORT
;
2728 /* add fake param output for vertex shader if no param is exported */
2729 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
2730 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2732 output
[j
].elem_size
= 3;
2733 output
[j
].swizzle_x
= 7;
2734 output
[j
].swizzle_y
= 7;
2735 output
[j
].swizzle_z
= 7;
2736 output
[j
].swizzle_w
= 7;
2737 output
[j
].burst_count
= 1;
2738 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2739 output
[j
].array_base
= 0;
2740 output
[j
].op
= CF_OP_EXPORT
;
2744 /* add fake pixel export */
2745 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
2746 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2748 output
[j
].elem_size
= 3;
2749 output
[j
].swizzle_x
= 7;
2750 output
[j
].swizzle_y
= 7;
2751 output
[j
].swizzle_z
= 7;
2752 output
[j
].swizzle_w
= 7;
2753 output
[j
].burst_count
= 1;
2754 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2755 output
[j
].array_base
= 0;
2756 output
[j
].op
= CF_OP_EXPORT
;
2758 shader
->nr_ps_color_exports
++;
2763 /* set export done on last export of each type */
2764 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
2765 if (!(output_done
& (1 << output
[i
].type
))) {
2766 output_done
|= (1 << output
[i
].type
);
2767 output
[i
].op
= CF_OP_EXPORT_DONE
;
2770 /* add output to bytecode */
2772 for (i
= 0; i
< noutput
; i
++) {
2773 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
2780 /* add program end */
2782 if (ctx
.bc
->chip_class
== CAYMAN
)
2783 cm_bytecode_add_cf_end(ctx
.bc
);
2785 const struct cf_op_info
*last
= NULL
;
2787 if (ctx
.bc
->cf_last
)
2788 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
2790 /* alu clause instructions don't have EOP bit, so add NOP */
2791 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
)
2792 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2794 ctx
.bc
->cf_last
->end_of_program
= 1;
2798 /* check GPR limit - we have 124 = 128 - 4
2799 * (4 are reserved as alu clause temporary registers) */
2800 if (ctx
.bc
->ngpr
> 124) {
2801 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
2806 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2807 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
2812 tgsi_parse_free(&ctx
.parse
);
2816 tgsi_parse_free(&ctx
.parse
);
2820 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
2822 const unsigned tgsi_opcode
=
2823 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
2824 R600_ERR("%s tgsi opcode unsupported\n",
2825 tgsi_get_opcode_name(tgsi_opcode
));
2829 static int tgsi_end(struct r600_shader_ctx
*ctx
)
2834 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
2835 const struct r600_shader_src
*shader_src
,
2838 bc_src
->sel
= shader_src
->sel
;
2839 bc_src
->chan
= shader_src
->swizzle
[chan
];
2840 bc_src
->neg
= shader_src
->neg
;
2841 bc_src
->abs
= shader_src
->abs
;
2842 bc_src
->rel
= shader_src
->rel
;
2843 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
2844 bc_src
->kc_bank
= shader_src
->kc_bank
;
2845 bc_src
->kc_rel
= shader_src
->kc_rel
;
2848 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2854 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2856 bc_src
->neg
= !bc_src
->neg
;
2859 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2860 const struct tgsi_full_dst_register
*tgsi_dst
,
2862 struct r600_bytecode_alu_dst
*r600_dst
)
2864 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2866 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2867 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2868 r600_dst
->chan
= swizzle
;
2869 r600_dst
->write
= 1;
2870 if (tgsi_dst
->Register
.Indirect
)
2871 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2872 if (inst
->Instruction
.Saturate
) {
2873 r600_dst
->clamp
= 1;
2877 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
)
2879 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2880 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2881 struct r600_bytecode_alu alu
;
2882 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2886 switch (write_mask
) {
2904 lasti
= tgsi_last_instruction(write_mask
);
2905 for (i
= 0; i
<= lasti
; i
++) {
2907 if (!(write_mask
& (1 << i
)))
2910 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2913 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2915 alu
.dst
.sel
= ctx
->temp_reg
;
2919 if (i
== 1 || i
== 3)
2922 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2924 alu
.op
= ctx
->inst_info
->op
;
2925 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
2926 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2928 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2929 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
2932 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
2933 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
2936 /* handle some special cases */
2937 if (i
== 1 || i
== 3) {
2938 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
2939 case TGSI_OPCODE_SUB
:
2940 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2942 case TGSI_OPCODE_DABS
:
2943 r600_bytecode_src_set_abs(&alu
.src
[0]);
2952 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2958 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2960 /* move result from temp to dst */
2961 for (i
= 0; i
<= lasti
; i
++) {
2962 if (!(write_mask
& (1 << i
)))
2965 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2966 alu
.op
= ALU_OP1_MOV
;
2967 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2968 alu
.src
[0].sel
= ctx
->temp_reg
;
2969 alu
.src
[0].chan
= use_tmp
- 1;
2970 alu
.last
= (i
== lasti
);
2972 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2980 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
2982 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2983 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2984 /* confirm writemasking */
2985 if ((write_mask
& 0x3) != 0x3 &&
2986 (write_mask
& 0xc) != 0xc) {
2987 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
2990 return tgsi_op2_64_params(ctx
, false, false);
2993 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
2995 return tgsi_op2_64_params(ctx
, true, false);
2998 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
3000 return tgsi_op2_64_params(ctx
, true, true);
3003 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
3005 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3006 struct r600_bytecode_alu alu
;
3009 int tmp
= r600_get_temp(ctx
);
3011 for (i
= 0; i
< lasti
+ 1; i
++) {
3013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3014 alu
.op
= ctx
->inst_info
->op
;
3015 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3016 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
3019 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
3020 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3029 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3036 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
3038 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3039 struct r600_bytecode_alu alu
;
3040 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3041 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3042 /* use temp register if trans_only and more than one dst component */
3043 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
3045 for (i
= 0; i
<= lasti
; i
++) {
3046 if (!(write_mask
& (1 << i
)))
3049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3051 alu
.dst
.sel
= ctx
->temp_reg
;
3055 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3057 alu
.op
= ctx
->inst_info
->op
;
3059 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3060 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3063 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3064 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3066 /* handle some special cases */
3067 switch (inst
->Instruction
.Opcode
) {
3068 case TGSI_OPCODE_SUB
:
3069 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
3071 case TGSI_OPCODE_ABS
:
3072 r600_bytecode_src_set_abs(&alu
.src
[0]);
3077 if (i
== lasti
|| trans_only
) {
3080 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3086 /* move result from temp to dst */
3087 for (i
= 0; i
<= lasti
; i
++) {
3088 if (!(write_mask
& (1 << i
)))
3091 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3092 alu
.op
= ALU_OP1_MOV
;
3093 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3094 alu
.src
[0].sel
= ctx
->temp_reg
;
3095 alu
.src
[0].chan
= i
;
3096 alu
.last
= (i
== lasti
);
3098 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3106 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
3108 return tgsi_op2_s(ctx
, 0, 0);
3111 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
3113 return tgsi_op2_s(ctx
, 1, 0);
3116 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
3118 return tgsi_op2_s(ctx
, 0, 1);
3121 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
3123 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3124 struct r600_bytecode_alu alu
;
3126 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3128 for (i
= 0; i
< lasti
+ 1; i
++) {
3130 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3133 alu
.op
= ctx
->inst_info
->op
;
3135 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3137 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3139 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3144 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3152 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
3154 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3155 struct r600_bytecode_alu alu
;
3157 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3159 for (i
= 0; i
< lasti
+ 1; i
++) {
3161 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3163 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3164 alu
.op
= ALU_OP1_MOV
;
3166 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3168 if (i
== 1 || i
== 3)
3169 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
3170 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3183 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
3185 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3186 struct r600_bytecode_alu alu
;
3187 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3189 int firsti
= write_mask
== 0xc ? 2 : 0;
3191 for (i
= 0; i
<= 3; i
++) {
3192 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3193 alu
.op
= ctx
->inst_info
->op
;
3195 alu
.dst
.sel
= ctx
->temp_reg
;
3198 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3199 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
3205 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3210 /* MOV first two channels to writemask dst0 */
3211 for (i
= 0; i
<= 1; i
++) {
3212 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3213 alu
.op
= ALU_OP1_MOV
;
3214 alu
.src
[0].chan
= i
+ 2;
3215 alu
.src
[0].sel
= ctx
->temp_reg
;
3217 tgsi_dst(ctx
, &inst
->Dst
[0], firsti
+ i
, &alu
.dst
);
3218 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> (firsti
+ i
)) & 1;
3220 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3225 for (i
= 0; i
<= 3; i
++) {
3226 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
3227 /* MOV third channels to writemask dst1 */
3228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3229 alu
.op
= ALU_OP1_MOV
;
3230 alu
.src
[0].chan
= 1;
3231 alu
.src
[0].sel
= ctx
->temp_reg
;
3233 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
3235 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3245 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
3247 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3248 struct r600_bytecode_alu alu
;
3250 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3252 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
3253 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
3255 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
3256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3257 alu
.op
= ctx
->inst_info
->op
;
3259 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3260 alu
.dst
.sel
= ctx
->temp_reg
;
3265 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3270 for (i
= 0; i
<= lasti
; i
++) {
3271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3272 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
3274 alu
.src
[0].chan
= i
/2;
3276 alu
.src
[0].sel
= ctx
->temp_reg
;
3278 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3279 alu
.src
[0].value
= 0x0;
3281 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3282 alu
.last
= i
== lasti
;
3284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3292 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
3294 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3295 struct r600_bytecode_alu alu
;
3297 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3299 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
3300 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
3302 for (i
= 0; i
<= lasti
; i
++) {
3303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3304 alu
.op
= ALU_OP1_FLT64_TO_FLT32
;
3306 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], fp64_switch(i
));
3308 alu
.dst
.sel
= ctx
->temp_reg
;
3309 alu
.dst
.write
= i
%2 == 0;
3310 alu
.last
= i
== lasti
;
3312 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3317 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
3318 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3319 alu
.op
= ctx
->inst_info
->op
;
3321 alu
.src
[0].chan
= i
*2;
3322 alu
.src
[0].sel
= ctx
->temp_reg
;
3323 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3326 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3334 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
3336 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3338 struct r600_bytecode_alu alu
;
3340 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3341 int t1
= ctx
->temp_reg
;
3343 /* these have to write the result to X/Y by the looks of it */
3344 for (i
= 0 ; i
< last_slot
; i
++) {
3345 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3346 alu
.op
= ctx
->inst_info
->op
;
3348 /* should only be one src regs */
3349 assert (inst
->Instruction
.NumSrcRegs
== 1);
3351 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
3352 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 0);
3354 /* RSQ should take the absolute value of src */
3355 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
3356 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
) {
3357 r600_bytecode_src_set_abs(&alu
.src
[1]);
3361 alu
.dst
.write
= (i
== 0 || i
== 1);
3363 if (ctx
->bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
3365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3370 for (i
= 0 ; i
<= lasti
; i
++) {
3371 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3373 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3374 alu
.op
= ALU_OP1_MOV
;
3375 alu
.src
[0].sel
= t1
;
3376 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
3377 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3381 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3388 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
3390 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3392 struct r600_bytecode_alu alu
;
3393 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
3395 for (i
= 0 ; i
< last_slot
; i
++) {
3396 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3397 alu
.op
= ctx
->inst_info
->op
;
3398 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3399 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
3401 /* RSQ should take the absolute value of src */
3402 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
3403 r600_bytecode_src_set_abs(&alu
.src
[j
]);
3406 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3407 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3409 if (i
== last_slot
- 1)
3411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3418 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
3420 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3422 struct r600_bytecode_alu alu
;
3423 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3424 int t1
= ctx
->temp_reg
;
3426 for (k
= 0; k
<= lasti
; k
++) {
3427 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
3430 for (i
= 0 ; i
< 4; i
++) {
3431 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3432 alu
.op
= ctx
->inst_info
->op
;
3433 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3434 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
3438 alu
.dst
.write
= (i
== k
);
3441 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3447 for (i
= 0 ; i
<= lasti
; i
++) {
3448 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3450 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3451 alu
.op
= ALU_OP1_MOV
;
3452 alu
.src
[0].sel
= t1
;
3453 alu
.src
[0].chan
= i
;
3454 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3458 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3467 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
3469 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3471 struct r600_bytecode_alu alu
;
3472 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3473 int t1
= ctx
->temp_reg
;
3475 for (k
= 0; k
< 2; k
++) {
3476 if (!(inst
->Dst
[0].Register
.WriteMask
& (0x3 << (k
* 2))))
3479 for (i
= 0; i
< 4; i
++) {
3480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3481 alu
.op
= ctx
->inst_info
->op
;
3482 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3483 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));;
3490 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3496 for (i
= 0; i
<= lasti
; i
++) {
3497 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3499 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3500 alu
.op
= ALU_OP1_MOV
;
3501 alu
.src
[0].sel
= t1
;
3502 alu
.src
[0].chan
= i
;
3503 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3507 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3516 * r600 - trunc to -PI..PI range
3517 * r700 - normalize by dividing by 2PI
3520 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
3522 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
3523 static float double_pi
= 3.1415926535 * 2;
3524 static float neg_pi
= -3.1415926535;
3527 struct r600_bytecode_alu alu
;
3529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3530 alu
.op
= ALU_OP3_MULADD
;
3534 alu
.dst
.sel
= ctx
->temp_reg
;
3537 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3539 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3540 alu
.src
[1].chan
= 0;
3541 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
3542 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
3543 alu
.src
[2].chan
= 0;
3545 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3550 alu
.op
= ALU_OP1_FRACT
;
3553 alu
.dst
.sel
= ctx
->temp_reg
;
3556 alu
.src
[0].sel
= ctx
->temp_reg
;
3557 alu
.src
[0].chan
= 0;
3559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3563 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3564 alu
.op
= ALU_OP3_MULADD
;
3568 alu
.dst
.sel
= ctx
->temp_reg
;
3571 alu
.src
[0].sel
= ctx
->temp_reg
;
3572 alu
.src
[0].chan
= 0;
3574 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3575 alu
.src
[1].chan
= 0;
3576 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
3577 alu
.src
[2].chan
= 0;
3579 if (ctx
->bc
->chip_class
== R600
) {
3580 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
3581 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
3583 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3584 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
3589 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3595 static int cayman_trig(struct r600_shader_ctx
*ctx
)
3597 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3598 struct r600_bytecode_alu alu
;
3599 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
3602 r
= tgsi_setup_trig(ctx
);
3607 for (i
= 0; i
< last_slot
; i
++) {
3608 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3609 alu
.op
= ctx
->inst_info
->op
;
3612 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3613 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3615 alu
.src
[0].sel
= ctx
->temp_reg
;
3616 alu
.src
[0].chan
= 0;
3617 if (i
== last_slot
- 1)
3619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3626 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
3628 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3629 struct r600_bytecode_alu alu
;
3631 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3633 r
= tgsi_setup_trig(ctx
);
3637 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3638 alu
.op
= ctx
->inst_info
->op
;
3640 alu
.dst
.sel
= ctx
->temp_reg
;
3643 alu
.src
[0].sel
= ctx
->temp_reg
;
3644 alu
.src
[0].chan
= 0;
3646 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3650 /* replicate result */
3651 for (i
= 0; i
< lasti
+ 1; i
++) {
3652 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3655 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3656 alu
.op
= ALU_OP1_MOV
;
3658 alu
.src
[0].sel
= ctx
->temp_reg
;
3659 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3662 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3669 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
3671 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3672 struct r600_bytecode_alu alu
;
3675 /* We'll only need the trig stuff if we are going to write to the
3676 * X or Y components of the destination vector.
3678 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
3679 r
= tgsi_setup_trig(ctx
);
3685 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3686 if (ctx
->bc
->chip_class
== CAYMAN
) {
3687 for (i
= 0 ; i
< 3; i
++) {
3688 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3689 alu
.op
= ALU_OP1_COS
;
3690 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3696 alu
.src
[0].sel
= ctx
->temp_reg
;
3697 alu
.src
[0].chan
= 0;
3700 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3706 alu
.op
= ALU_OP1_COS
;
3707 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3709 alu
.src
[0].sel
= ctx
->temp_reg
;
3710 alu
.src
[0].chan
= 0;
3712 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3719 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3720 if (ctx
->bc
->chip_class
== CAYMAN
) {
3721 for (i
= 0 ; i
< 3; i
++) {
3722 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3723 alu
.op
= ALU_OP1_SIN
;
3724 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3729 alu
.src
[0].sel
= ctx
->temp_reg
;
3730 alu
.src
[0].chan
= 0;
3733 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3739 alu
.op
= ALU_OP1_SIN
;
3740 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
3742 alu
.src
[0].sel
= ctx
->temp_reg
;
3743 alu
.src
[0].chan
= 0;
3745 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3752 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3753 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3755 alu
.op
= ALU_OP1_MOV
;
3757 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
3759 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3760 alu
.src
[0].chan
= 0;
3764 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3770 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3771 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3773 alu
.op
= ALU_OP1_MOV
;
3775 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
3777 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3778 alu
.src
[0].chan
= 0;
3782 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3790 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
3792 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3793 struct r600_bytecode_alu alu
;
3796 for (i
= 0; i
< 4; i
++) {
3797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3798 alu
.op
= ctx
->inst_info
->op
;
3802 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3804 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
3805 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3808 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3813 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3818 /* kill must be last in ALU */
3819 ctx
->bc
->force_add_cf
= 1;
3820 ctx
->shader
->uses_kill
= TRUE
;
3824 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
3826 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3827 struct r600_bytecode_alu alu
;
3830 /* tmp.x = max(src.y, 0.0) */
3831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3832 alu
.op
= ALU_OP2_MAX
;
3833 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
3834 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
3835 alu
.src
[1].chan
= 1;
3837 alu
.dst
.sel
= ctx
->temp_reg
;
3842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3846 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
3852 if (ctx
->bc
->chip_class
== CAYMAN
) {
3853 for (i
= 0; i
< 3; i
++) {
3854 /* tmp.z = log(tmp.x) */
3855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3856 alu
.op
= ALU_OP1_LOG_CLAMPED
;
3857 alu
.src
[0].sel
= ctx
->temp_reg
;
3858 alu
.src
[0].chan
= 0;
3859 alu
.dst
.sel
= ctx
->temp_reg
;
3867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3872 /* tmp.z = log(tmp.x) */
3873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3874 alu
.op
= ALU_OP1_LOG_CLAMPED
;
3875 alu
.src
[0].sel
= ctx
->temp_reg
;
3876 alu
.src
[0].chan
= 0;
3877 alu
.dst
.sel
= ctx
->temp_reg
;
3881 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3886 chan
= alu
.dst
.chan
;
3889 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
3890 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3891 alu
.op
= ALU_OP3_MUL_LIT
;
3892 alu
.src
[0].sel
= sel
;
3893 alu
.src
[0].chan
= chan
;
3894 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
3895 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
3896 alu
.dst
.sel
= ctx
->temp_reg
;
3901 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3905 if (ctx
->bc
->chip_class
== CAYMAN
) {
3906 for (i
= 0; i
< 3; i
++) {
3907 /* dst.z = exp(tmp.x) */
3908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3909 alu
.op
= ALU_OP1_EXP_IEEE
;
3910 alu
.src
[0].sel
= ctx
->temp_reg
;
3911 alu
.src
[0].chan
= 0;
3912 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3918 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3923 /* dst.z = exp(tmp.x) */
3924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3925 alu
.op
= ALU_OP1_EXP_IEEE
;
3926 alu
.src
[0].sel
= ctx
->temp_reg
;
3927 alu
.src
[0].chan
= 0;
3928 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
3930 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3937 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3938 alu
.op
= ALU_OP1_MOV
;
3939 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
3940 alu
.src
[0].chan
= 0;
3941 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3942 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
3943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3947 /* dst.y = max(src.x, 0.0) */
3948 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3949 alu
.op
= ALU_OP2_MAX
;
3950 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3951 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
3952 alu
.src
[1].chan
= 0;
3953 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
3954 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
3955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3961 alu
.op
= ALU_OP1_MOV
;
3962 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3963 alu
.src
[0].chan
= 0;
3964 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
3965 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
3967 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3974 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
3976 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3977 struct r600_bytecode_alu alu
;
3980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3983 * For state trackers other than OpenGL, we'll want to use
3984 * _RECIPSQRT_IEEE instead.
3986 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
3988 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
3989 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
3990 r600_bytecode_src_set_abs(&alu
.src
[i
]);
3992 alu
.dst
.sel
= ctx
->temp_reg
;
3995 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3998 /* replicate result */
3999 return tgsi_helper_tempx_replicate(ctx
);
4002 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
4004 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4005 struct r600_bytecode_alu alu
;
4008 for (i
= 0; i
< 4; i
++) {
4009 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4010 alu
.src
[0].sel
= ctx
->temp_reg
;
4011 alu
.op
= ALU_OP1_MOV
;
4013 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4014 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4017 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4024 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
4026 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4027 struct r600_bytecode_alu alu
;
4030 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4031 alu
.op
= ctx
->inst_info
->op
;
4032 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4033 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4035 alu
.dst
.sel
= ctx
->temp_reg
;
4038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4041 /* replicate result */
4042 return tgsi_helper_tempx_replicate(ctx
);
4045 static int cayman_pow(struct r600_shader_ctx
*ctx
)
4047 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4049 struct r600_bytecode_alu alu
;
4050 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4052 for (i
= 0; i
< 3; i
++) {
4053 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4054 alu
.op
= ALU_OP1_LOG_IEEE
;
4055 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4056 alu
.dst
.sel
= ctx
->temp_reg
;
4061 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4067 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4068 alu
.op
= ALU_OP2_MUL
;
4069 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4070 alu
.src
[1].sel
= ctx
->temp_reg
;
4071 alu
.dst
.sel
= ctx
->temp_reg
;
4074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4078 for (i
= 0; i
< last_slot
; i
++) {
4079 /* POW(a,b) = EXP2(b * LOG2(a))*/
4080 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4081 alu
.op
= ALU_OP1_EXP_IEEE
;
4082 alu
.src
[0].sel
= ctx
->temp_reg
;
4084 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4085 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4086 if (i
== last_slot
- 1)
4088 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4095 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
4097 struct r600_bytecode_alu alu
;
4101 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4102 alu
.op
= ALU_OP1_LOG_IEEE
;
4103 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4104 alu
.dst
.sel
= ctx
->temp_reg
;
4107 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4111 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4112 alu
.op
= ALU_OP2_MUL
;
4113 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4114 alu
.src
[1].sel
= ctx
->temp_reg
;
4115 alu
.dst
.sel
= ctx
->temp_reg
;
4118 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4121 /* POW(a,b) = EXP2(b * LOG2(a))*/
4122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4123 alu
.op
= ALU_OP1_EXP_IEEE
;
4124 alu
.src
[0].sel
= ctx
->temp_reg
;
4125 alu
.dst
.sel
= ctx
->temp_reg
;
4128 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4131 return tgsi_helper_tempx_replicate(ctx
);
4134 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
4136 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4137 struct r600_bytecode_alu alu
;
4139 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4140 int tmp0
= ctx
->temp_reg
;
4141 int tmp1
= r600_get_temp(ctx
);
4142 int tmp2
= r600_get_temp(ctx
);
4143 int tmp3
= r600_get_temp(ctx
);
4146 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
4148 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
4149 * 2. tmp0.z = lo (tmp0.x * src2)
4150 * 3. tmp0.w = -tmp0.z
4151 * 4. tmp0.y = hi (tmp0.x * src2)
4152 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
4153 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
4154 * 7. tmp1.x = tmp0.x - tmp0.w
4155 * 8. tmp1.y = tmp0.x + tmp0.w
4156 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
4157 * 10. tmp0.z = hi(tmp0.x * src1) = q
4158 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
4160 * 12. tmp0.w = src1 - tmp0.y = r
4161 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
4162 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
4166 * 15. tmp1.z = tmp0.z + 1 = q + 1
4167 * 16. tmp1.w = tmp0.z - 1 = q - 1
4171 * 15. tmp1.z = tmp0.w - src2 = r - src2
4172 * 16. tmp1.w = tmp0.w + src2 = r + src2
4176 * 17. tmp1.x = tmp1.x & tmp1.y
4178 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
4179 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
4181 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
4182 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
4186 * Same as unsigned, using abs values of the operands,
4187 * and fixing the sign of the result in the end.
4190 for (i
= 0; i
< 4; i
++) {
4191 if (!(write_mask
& (1<<i
)))
4196 /* tmp2.x = -src0 */
4197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4198 alu
.op
= ALU_OP2_SUB_INT
;
4204 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4206 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4209 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4212 /* tmp2.y = -src1 */
4213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4214 alu
.op
= ALU_OP2_SUB_INT
;
4220 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4222 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4225 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4228 /* tmp2.z sign bit is set if src0 and src2 signs are different */
4229 /* it will be a sign of the quotient */
4232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4233 alu
.op
= ALU_OP2_XOR_INT
;
4239 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4240 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4243 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4247 /* tmp2.x = |src0| */
4248 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4249 alu
.op
= ALU_OP3_CNDGE_INT
;
4256 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4257 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4258 alu
.src
[2].sel
= tmp2
;
4259 alu
.src
[2].chan
= 0;
4262 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4265 /* tmp2.y = |src1| */
4266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4267 alu
.op
= ALU_OP3_CNDGE_INT
;
4274 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4275 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4276 alu
.src
[2].sel
= tmp2
;
4277 alu
.src
[2].chan
= 1;
4280 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4285 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
4286 if (ctx
->bc
->chip_class
== CAYMAN
) {
4287 /* tmp3.x = u2f(src2) */
4288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4289 alu
.op
= ALU_OP1_UINT_TO_FLT
;
4296 alu
.src
[0].sel
= tmp2
;
4297 alu
.src
[0].chan
= 1;
4299 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4303 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4306 /* tmp0.x = recip(tmp3.x) */
4307 for (j
= 0 ; j
< 3; j
++) {
4308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4309 alu
.op
= ALU_OP1_RECIP_IEEE
;
4313 alu
.dst
.write
= (j
== 0);
4315 alu
.src
[0].sel
= tmp3
;
4316 alu
.src
[0].chan
= 0;
4320 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4324 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4325 alu
.op
= ALU_OP2_MUL
;
4327 alu
.src
[0].sel
= tmp0
;
4328 alu
.src
[0].chan
= 0;
4330 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4331 alu
.src
[1].value
= 0x4f800000;
4336 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4341 alu
.op
= ALU_OP1_FLT_TO_UINT
;
4347 alu
.src
[0].sel
= tmp3
;
4348 alu
.src
[0].chan
= 0;
4351 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4356 alu
.op
= ALU_OP1_RECIP_UINT
;
4363 alu
.src
[0].sel
= tmp2
;
4364 alu
.src
[0].chan
= 1;
4366 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4370 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4374 /* 2. tmp0.z = lo (tmp0.x * src2) */
4375 if (ctx
->bc
->chip_class
== CAYMAN
) {
4376 for (j
= 0 ; j
< 4; j
++) {
4377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4378 alu
.op
= ALU_OP2_MULLO_UINT
;
4382 alu
.dst
.write
= (j
== 2);
4384 alu
.src
[0].sel
= tmp0
;
4385 alu
.src
[0].chan
= 0;
4387 alu
.src
[1].sel
= tmp2
;
4388 alu
.src
[1].chan
= 1;
4390 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4393 alu
.last
= (j
== 3);
4394 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4398 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4399 alu
.op
= ALU_OP2_MULLO_UINT
;
4405 alu
.src
[0].sel
= tmp0
;
4406 alu
.src
[0].chan
= 0;
4408 alu
.src
[1].sel
= tmp2
;
4409 alu
.src
[1].chan
= 1;
4411 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4415 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4419 /* 3. tmp0.w = -tmp0.z */
4420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4421 alu
.op
= ALU_OP2_SUB_INT
;
4427 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4428 alu
.src
[1].sel
= tmp0
;
4429 alu
.src
[1].chan
= 2;
4432 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4435 /* 4. tmp0.y = hi (tmp0.x * src2) */
4436 if (ctx
->bc
->chip_class
== CAYMAN
) {
4437 for (j
= 0 ; j
< 4; j
++) {
4438 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4439 alu
.op
= ALU_OP2_MULHI_UINT
;
4443 alu
.dst
.write
= (j
== 1);
4445 alu
.src
[0].sel
= tmp0
;
4446 alu
.src
[0].chan
= 0;
4449 alu
.src
[1].sel
= tmp2
;
4450 alu
.src
[1].chan
= 1;
4452 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4454 alu
.last
= (j
== 3);
4455 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4459 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4460 alu
.op
= ALU_OP2_MULHI_UINT
;
4466 alu
.src
[0].sel
= tmp0
;
4467 alu
.src
[0].chan
= 0;
4470 alu
.src
[1].sel
= tmp2
;
4471 alu
.src
[1].chan
= 1;
4473 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4477 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4481 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
4482 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4483 alu
.op
= ALU_OP3_CNDE_INT
;
4490 alu
.src
[0].sel
= tmp0
;
4491 alu
.src
[0].chan
= 1;
4492 alu
.src
[1].sel
= tmp0
;
4493 alu
.src
[1].chan
= 3;
4494 alu
.src
[2].sel
= tmp0
;
4495 alu
.src
[2].chan
= 2;
4498 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4501 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
4502 if (ctx
->bc
->chip_class
== CAYMAN
) {
4503 for (j
= 0 ; j
< 4; j
++) {
4504 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4505 alu
.op
= ALU_OP2_MULHI_UINT
;
4509 alu
.dst
.write
= (j
== 3);
4511 alu
.src
[0].sel
= tmp0
;
4512 alu
.src
[0].chan
= 2;
4514 alu
.src
[1].sel
= tmp0
;
4515 alu
.src
[1].chan
= 0;
4517 alu
.last
= (j
== 3);
4518 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4522 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4523 alu
.op
= ALU_OP2_MULHI_UINT
;
4529 alu
.src
[0].sel
= tmp0
;
4530 alu
.src
[0].chan
= 2;
4532 alu
.src
[1].sel
= tmp0
;
4533 alu
.src
[1].chan
= 0;
4536 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4540 /* 7. tmp1.x = tmp0.x - tmp0.w */
4541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4542 alu
.op
= ALU_OP2_SUB_INT
;
4548 alu
.src
[0].sel
= tmp0
;
4549 alu
.src
[0].chan
= 0;
4550 alu
.src
[1].sel
= tmp0
;
4551 alu
.src
[1].chan
= 3;
4554 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4557 /* 8. tmp1.y = tmp0.x + tmp0.w */
4558 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4559 alu
.op
= ALU_OP2_ADD_INT
;
4565 alu
.src
[0].sel
= tmp0
;
4566 alu
.src
[0].chan
= 0;
4567 alu
.src
[1].sel
= tmp0
;
4568 alu
.src
[1].chan
= 3;
4571 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4574 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
4575 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4576 alu
.op
= ALU_OP3_CNDE_INT
;
4583 alu
.src
[0].sel
= tmp0
;
4584 alu
.src
[0].chan
= 1;
4585 alu
.src
[1].sel
= tmp1
;
4586 alu
.src
[1].chan
= 1;
4587 alu
.src
[2].sel
= tmp1
;
4588 alu
.src
[2].chan
= 0;
4591 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4594 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
4595 if (ctx
->bc
->chip_class
== CAYMAN
) {
4596 for (j
= 0 ; j
< 4; j
++) {
4597 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4598 alu
.op
= ALU_OP2_MULHI_UINT
;
4602 alu
.dst
.write
= (j
== 2);
4604 alu
.src
[0].sel
= tmp0
;
4605 alu
.src
[0].chan
= 0;
4608 alu
.src
[1].sel
= tmp2
;
4609 alu
.src
[1].chan
= 0;
4611 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4614 alu
.last
= (j
== 3);
4615 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4619 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4620 alu
.op
= ALU_OP2_MULHI_UINT
;
4626 alu
.src
[0].sel
= tmp0
;
4627 alu
.src
[0].chan
= 0;
4630 alu
.src
[1].sel
= tmp2
;
4631 alu
.src
[1].chan
= 0;
4633 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4637 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4641 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
4642 if (ctx
->bc
->chip_class
== CAYMAN
) {
4643 for (j
= 0 ; j
< 4; j
++) {
4644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4645 alu
.op
= ALU_OP2_MULLO_UINT
;
4649 alu
.dst
.write
= (j
== 1);
4652 alu
.src
[0].sel
= tmp2
;
4653 alu
.src
[0].chan
= 1;
4655 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4658 alu
.src
[1].sel
= tmp0
;
4659 alu
.src
[1].chan
= 2;
4661 alu
.last
= (j
== 3);
4662 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4667 alu
.op
= ALU_OP2_MULLO_UINT
;
4674 alu
.src
[0].sel
= tmp2
;
4675 alu
.src
[0].chan
= 1;
4677 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4680 alu
.src
[1].sel
= tmp0
;
4681 alu
.src
[1].chan
= 2;
4684 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4688 /* 12. tmp0.w = src1 - tmp0.y = r */
4689 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4690 alu
.op
= ALU_OP2_SUB_INT
;
4697 alu
.src
[0].sel
= tmp2
;
4698 alu
.src
[0].chan
= 0;
4700 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4703 alu
.src
[1].sel
= tmp0
;
4704 alu
.src
[1].chan
= 1;
4707 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4710 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
4711 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4712 alu
.op
= ALU_OP2_SETGE_UINT
;
4718 alu
.src
[0].sel
= tmp0
;
4719 alu
.src
[0].chan
= 3;
4721 alu
.src
[1].sel
= tmp2
;
4722 alu
.src
[1].chan
= 1;
4724 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4728 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4731 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
4732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4733 alu
.op
= ALU_OP2_SETGE_UINT
;
4740 alu
.src
[0].sel
= tmp2
;
4741 alu
.src
[0].chan
= 0;
4743 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4746 alu
.src
[1].sel
= tmp0
;
4747 alu
.src
[1].chan
= 1;
4750 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4753 if (mod
) { /* UMOD */
4755 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
4756 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4757 alu
.op
= ALU_OP2_SUB_INT
;
4763 alu
.src
[0].sel
= tmp0
;
4764 alu
.src
[0].chan
= 3;
4767 alu
.src
[1].sel
= tmp2
;
4768 alu
.src
[1].chan
= 1;
4770 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4774 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4777 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
4778 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4779 alu
.op
= ALU_OP2_ADD_INT
;
4785 alu
.src
[0].sel
= tmp0
;
4786 alu
.src
[0].chan
= 3;
4788 alu
.src
[1].sel
= tmp2
;
4789 alu
.src
[1].chan
= 1;
4791 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4795 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4800 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
4801 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4802 alu
.op
= ALU_OP2_ADD_INT
;
4808 alu
.src
[0].sel
= tmp0
;
4809 alu
.src
[0].chan
= 2;
4810 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
4813 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4816 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
4817 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4818 alu
.op
= ALU_OP2_ADD_INT
;
4824 alu
.src
[0].sel
= tmp0
;
4825 alu
.src
[0].chan
= 2;
4826 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
4829 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4834 /* 17. tmp1.x = tmp1.x & tmp1.y */
4835 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4836 alu
.op
= ALU_OP2_AND_INT
;
4842 alu
.src
[0].sel
= tmp1
;
4843 alu
.src
[0].chan
= 0;
4844 alu
.src
[1].sel
= tmp1
;
4845 alu
.src
[1].chan
= 1;
4848 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4851 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
4852 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
4853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4854 alu
.op
= ALU_OP3_CNDE_INT
;
4861 alu
.src
[0].sel
= tmp1
;
4862 alu
.src
[0].chan
= 0;
4863 alu
.src
[1].sel
= tmp0
;
4864 alu
.src
[1].chan
= mod
? 3 : 2;
4865 alu
.src
[2].sel
= tmp1
;
4866 alu
.src
[2].chan
= 2;
4869 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4872 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
4873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4874 alu
.op
= ALU_OP3_CNDE_INT
;
4882 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4885 alu
.src
[0].sel
= tmp1
;
4886 alu
.src
[0].chan
= 1;
4887 alu
.src
[1].sel
= tmp1
;
4888 alu
.src
[1].chan
= 3;
4889 alu
.src
[2].sel
= tmp0
;
4890 alu
.src
[2].chan
= 2;
4893 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4898 /* fix the sign of the result */
4902 /* tmp0.x = -tmp0.z */
4903 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4904 alu
.op
= ALU_OP2_SUB_INT
;
4910 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4911 alu
.src
[1].sel
= tmp0
;
4912 alu
.src
[1].chan
= 2;
4915 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4918 /* sign of the remainder is the same as the sign of src0 */
4919 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
4920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4921 alu
.op
= ALU_OP3_CNDGE_INT
;
4924 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4926 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4927 alu
.src
[1].sel
= tmp0
;
4928 alu
.src
[1].chan
= 2;
4929 alu
.src
[2].sel
= tmp0
;
4930 alu
.src
[2].chan
= 0;
4933 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4938 /* tmp0.x = -tmp0.z */
4939 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4940 alu
.op
= ALU_OP2_SUB_INT
;
4946 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4947 alu
.src
[1].sel
= tmp0
;
4948 alu
.src
[1].chan
= 2;
4951 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4954 /* fix the quotient sign (same as the sign of src0*src1) */
4955 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
4956 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4957 alu
.op
= ALU_OP3_CNDGE_INT
;
4960 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4962 alu
.src
[0].sel
= tmp2
;
4963 alu
.src
[0].chan
= 2;
4964 alu
.src
[1].sel
= tmp0
;
4965 alu
.src
[1].chan
= 2;
4966 alu
.src
[2].sel
= tmp0
;
4967 alu
.src
[2].chan
= 0;
4970 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4978 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
4980 return tgsi_divmod(ctx
, 0, 0);
4983 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
4985 return tgsi_divmod(ctx
, 1, 0);
4988 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
4990 return tgsi_divmod(ctx
, 0, 1);
4993 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
4995 return tgsi_divmod(ctx
, 1, 1);
4999 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
5001 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5002 struct r600_bytecode_alu alu
;
5004 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5005 int last_inst
= tgsi_last_instruction(write_mask
);
5007 for (i
= 0; i
< 4; i
++) {
5008 if (!(write_mask
& (1<<i
)))
5011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5012 alu
.op
= ALU_OP1_TRUNC
;
5014 alu
.dst
.sel
= ctx
->temp_reg
;
5018 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5021 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5026 for (i
= 0; i
< 4; i
++) {
5027 if (!(write_mask
& (1<<i
)))
5030 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5031 alu
.op
= ctx
->inst_info
->op
;
5033 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5035 alu
.src
[0].sel
= ctx
->temp_reg
;
5036 alu
.src
[0].chan
= i
;
5038 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
5040 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5048 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
5050 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5051 struct r600_bytecode_alu alu
;
5053 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5054 int last_inst
= tgsi_last_instruction(write_mask
);
5057 for (i
= 0; i
< 4; i
++) {
5058 if (!(write_mask
& (1<<i
)))
5061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5062 alu
.op
= ALU_OP2_SUB_INT
;
5064 alu
.dst
.sel
= ctx
->temp_reg
;
5068 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5069 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5078 /* dst = (src >= 0 ? src : tmp) */
5079 for (i
= 0; i
< 4; i
++) {
5080 if (!(write_mask
& (1<<i
)))
5083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5084 alu
.op
= ALU_OP3_CNDGE_INT
;
5088 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5090 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5091 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5092 alu
.src
[2].sel
= ctx
->temp_reg
;
5093 alu
.src
[2].chan
= i
;
5097 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5104 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
5106 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5107 struct r600_bytecode_alu alu
;
5109 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5110 int last_inst
= tgsi_last_instruction(write_mask
);
5112 /* tmp = (src >= 0 ? src : -1) */
5113 for (i
= 0; i
< 4; i
++) {
5114 if (!(write_mask
& (1<<i
)))
5117 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5118 alu
.op
= ALU_OP3_CNDGE_INT
;
5121 alu
.dst
.sel
= ctx
->temp_reg
;
5125 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5126 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5127 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
5131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5136 /* dst = (tmp > 0 ? 1 : tmp) */
5137 for (i
= 0; i
< 4; i
++) {
5138 if (!(write_mask
& (1<<i
)))
5141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5142 alu
.op
= ALU_OP3_CNDGT_INT
;
5146 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5148 alu
.src
[0].sel
= ctx
->temp_reg
;
5149 alu
.src
[0].chan
= i
;
5151 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5153 alu
.src
[2].sel
= ctx
->temp_reg
;
5154 alu
.src
[2].chan
= i
;
5158 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5167 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
5169 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5170 struct r600_bytecode_alu alu
;
5173 /* tmp = (src > 0 ? 1 : src) */
5174 for (i
= 0; i
< 4; i
++) {
5175 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5176 alu
.op
= ALU_OP3_CNDGT
;
5179 alu
.dst
.sel
= ctx
->temp_reg
;
5182 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5183 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5184 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
5188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5193 /* dst = (-tmp > 0 ? -1 : tmp) */
5194 for (i
= 0; i
< 4; i
++) {
5195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5196 alu
.op
= ALU_OP3_CNDGT
;
5198 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5200 alu
.src
[0].sel
= ctx
->temp_reg
;
5201 alu
.src
[0].chan
= i
;
5204 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5207 alu
.src
[2].sel
= ctx
->temp_reg
;
5208 alu
.src
[2].chan
= i
;
5212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5219 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
5221 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5222 struct r600_bytecode_alu alu
;
5225 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5226 int last_inst
= tgsi_last_instruction(write_mask
);
5230 for (i
= 0; i
< 4; i
++) {
5231 if (!(write_mask
& (1<<i
)))
5234 /* create mask tmp */
5235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5236 alu
.op
= ALU_OP2_BFM_INT
;
5240 alu
.last
= i
== last_inst
;
5242 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
5243 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5245 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5250 t2
= r600_get_temp(ctx
);
5252 for (i
= 0; i
< 4; i
++) {
5253 if (!(write_mask
& (1<<i
)))
5256 /* shift insert left */
5257 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5258 alu
.op
= ALU_OP2_LSHL_INT
;
5262 alu
.last
= i
== last_inst
;
5264 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5265 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5267 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5272 for (i
= 0; i
< 4; i
++) {
5273 if (!(write_mask
& (1<<i
)))
5276 /* actual bitfield insert */
5277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5278 alu
.op
= ALU_OP3_BFI_INT
;
5280 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5283 alu
.last
= i
== last_inst
;
5285 alu
.src
[0].sel
= t1
;
5286 alu
.src
[0].chan
= i
;
5287 alu
.src
[1].sel
= t2
;
5288 alu
.src
[1].chan
= i
;
5289 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
5291 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5299 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
5301 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5302 struct r600_bytecode_alu alu
;
5305 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5306 int last_inst
= tgsi_last_instruction(write_mask
);
5308 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
5309 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
5313 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
5314 for (i
= 0; i
< 4; i
++) {
5315 if (!(write_mask
& (1<<i
)))
5318 /* t1 = FFBH_INT / FFBH_UINT */
5319 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5320 alu
.op
= ctx
->inst_info
->op
;
5324 alu
.last
= i
== last_inst
;
5326 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5328 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5333 t2
= r600_get_temp(ctx
);
5335 for (i
= 0; i
< 4; i
++) {
5336 if (!(write_mask
& (1<<i
)))
5340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5341 alu
.op
= ALU_OP2_SUB_INT
;
5345 alu
.last
= i
== last_inst
;
5347 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
5348 alu
.src
[0].value
= 31;
5349 alu
.src
[1].sel
= t1
;
5350 alu
.src
[1].chan
= i
;
5352 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5357 for (i
= 0; i
< 4; i
++) {
5358 if (!(write_mask
& (1<<i
)))
5361 /* result = t1 >= 0 ? t2 : t1 */
5362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5363 alu
.op
= ALU_OP3_CNDGE_INT
;
5365 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5368 alu
.last
= i
== last_inst
;
5370 alu
.src
[0].sel
= t1
;
5371 alu
.src
[0].chan
= i
;
5372 alu
.src
[1].sel
= t2
;
5373 alu
.src
[1].chan
= i
;
5374 alu
.src
[2].sel
= t1
;
5375 alu
.src
[2].chan
= i
;
5377 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5385 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
5387 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5388 struct r600_bytecode_alu alu
;
5389 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
5393 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
5395 input
= inst
->Src
[0].Register
.Index
;
5397 /* Interpolators have been marked for use already by allocate_system_value_inputs */
5398 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
5399 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5400 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
5403 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
5406 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
5409 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
5410 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
5412 /* NOTE: currently offset is not perspective correct */
5413 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
5414 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5415 int sample_gpr
= -1;
5416 int gradientsH
, gradientsV
;
5417 struct r600_bytecode_tex tex
;
5419 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5420 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
5423 gradientsH
= r600_get_temp(ctx
);
5424 gradientsV
= r600_get_temp(ctx
);
5425 for (i
= 0; i
< 2; i
++) {
5426 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
5427 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
5428 tex
.src_gpr
= interp_gpr
;
5429 tex
.src_sel_x
= interp_base_chan
+ 0;
5430 tex
.src_sel_y
= interp_base_chan
+ 1;
5433 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
5438 tex
.inst_mod
= 1; // Use per pixel gradient calculation
5440 tex
.resource_id
= tex
.sampler_id
;
5441 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
5446 for (i
= 0; i
< 2; i
++) {
5447 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5448 alu
.op
= ALU_OP3_MULADD
;
5450 alu
.src
[0].sel
= gradientsH
;
5451 alu
.src
[0].chan
= i
;
5452 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5453 alu
.src
[1].sel
= sample_gpr
;
5454 alu
.src
[1].chan
= 2;
5457 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
5459 alu
.src
[2].sel
= interp_gpr
;
5460 alu
.src
[2].chan
= interp_base_chan
+ i
;
5461 alu
.dst
.sel
= ctx
->temp_reg
;
5465 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5470 for (i
= 0; i
< 2; i
++) {
5471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5472 alu
.op
= ALU_OP3_MULADD
;
5474 alu
.src
[0].sel
= gradientsV
;
5475 alu
.src
[0].chan
= i
;
5476 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5477 alu
.src
[1].sel
= sample_gpr
;
5478 alu
.src
[1].chan
= 3;
5481 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
5483 alu
.src
[2].sel
= ctx
->temp_reg
;
5484 alu
.src
[2].chan
= i
;
5485 alu
.dst
.sel
= ctx
->temp_reg
;
5489 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5495 tmp
= r600_get_temp(ctx
);
5496 for (i
= 0; i
< 8; i
++) {
5497 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5498 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
5501 if ((i
> 1 && i
< 6)) {
5507 alu
.dst
.chan
= i
% 4;
5509 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
5510 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5511 alu
.src
[0].sel
= ctx
->temp_reg
;
5512 alu
.src
[0].chan
= 1 - (i
% 2);
5514 alu
.src
[0].sel
= interp_gpr
;
5515 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
5517 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
5518 alu
.src
[1].chan
= 0;
5520 alu
.last
= i
% 4 == 3;
5521 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
5523 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5528 // INTERP can't swizzle dst
5529 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5530 for (i
= 0; i
<= lasti
; i
++) {
5531 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5534 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5535 alu
.op
= ALU_OP1_MOV
;
5536 alu
.src
[0].sel
= tmp
;
5537 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
5538 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5540 alu
.last
= i
== lasti
;
5541 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5550 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
5552 struct r600_bytecode_alu alu
;
5555 for (i
= 0; i
< 4; i
++) {
5556 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5557 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
5558 alu
.op
= ALU_OP0_NOP
;
5561 alu
.op
= ALU_OP1_MOV
;
5562 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5563 alu
.src
[0].sel
= ctx
->temp_reg
;
5564 alu
.src
[0].chan
= i
;
5569 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5576 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
5577 unsigned temp
, int chan
,
5578 struct r600_bytecode_alu_src
*bc_src
,
5579 const struct r600_shader_src
*shader_src
)
5581 struct r600_bytecode_alu alu
;
5584 r600_bytecode_src(bc_src
, shader_src
, chan
);
5586 /* op3 operands don't support abs modifier */
5588 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
5589 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5590 alu
.op
= ALU_OP1_MOV
;
5592 alu
.dst
.chan
= chan
;
5595 alu
.src
[0] = *bc_src
;
5596 alu
.last
= true; // sufficient?
5597 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5601 memset(bc_src
, 0, sizeof(*bc_src
));
5603 bc_src
->chan
= chan
;
5608 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
5610 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5611 struct r600_bytecode_alu alu
;
5613 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5616 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5618 if (ctx
->src
[j
].abs
)
5619 temp_regs
[j
] = r600_get_temp(ctx
);
5621 for (i
= 0; i
< lasti
+ 1; i
++) {
5622 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5625 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5626 alu
.op
= ctx
->inst_info
->op
;
5627 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5628 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
5633 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5647 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
5649 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5650 struct r600_bytecode_alu alu
;
5653 for (i
= 0; i
< 4; i
++) {
5654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5655 alu
.op
= ctx
->inst_info
->op
;
5656 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5657 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5660 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5662 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5663 /* handle some special cases */
5664 switch (inst
->Instruction
.Opcode
) {
5665 case TGSI_OPCODE_DP2
:
5667 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5668 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
5671 case TGSI_OPCODE_DP3
:
5673 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5674 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
5677 case TGSI_OPCODE_DPH
:
5679 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5680 alu
.src
[0].chan
= 0;
5690 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5697 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
5700 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5701 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
5702 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
5703 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
5704 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
5705 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== TGSI_PROCESSOR_GEOMETRY
);
5708 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
5711 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5712 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
5715 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
5717 struct r600_bytecode_vtx vtx
;
5718 struct r600_bytecode_alu alu
;
5719 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5721 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
5723 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
5724 if (src_requires_loading
) {
5725 for (i
= 0; i
< 4; i
++) {
5726 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5727 alu
.op
= ALU_OP1_MOV
;
5728 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5729 alu
.dst
.sel
= ctx
->temp_reg
;
5734 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5738 src_gpr
= ctx
->temp_reg
;
5741 memset(&vtx
, 0, sizeof(vtx
));
5742 vtx
.op
= FETCH_OP_VFETCH
;
5743 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
5744 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
5745 vtx
.src_gpr
= src_gpr
;
5746 vtx
.mega_fetch_count
= 16;
5747 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
5748 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
5749 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
5750 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
5751 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
5752 vtx
.use_const_fields
= 1;
5754 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
5757 if (ctx
->bc
->chip_class
>= EVERGREEN
)
5760 for (i
= 0; i
< 4; i
++) {
5761 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5762 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5765 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5766 alu
.op
= ALU_OP2_AND_INT
;
5769 alu
.dst
.sel
= vtx
.dst_gpr
;
5772 alu
.src
[0].sel
= vtx
.dst_gpr
;
5773 alu
.src
[0].chan
= i
;
5775 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
5776 alu
.src
[1].sel
+= (id
* 2);
5777 alu
.src
[1].chan
= i
% 4;
5778 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
5782 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5787 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
5788 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5789 alu
.op
= ALU_OP2_OR_INT
;
5792 alu
.dst
.sel
= vtx
.dst_gpr
;
5795 alu
.src
[0].sel
= vtx
.dst_gpr
;
5796 alu
.src
[0].chan
= 3;
5798 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
5799 alu
.src
[1].chan
= 0;
5800 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
5803 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5810 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
5812 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5813 struct r600_bytecode_alu alu
;
5815 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
5817 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5818 alu
.op
= ALU_OP1_MOV
;
5819 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
5820 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
5821 /* channel 0 or 2 of each word */
5822 alu
.src
[0].sel
+= (id
/ 2);
5823 alu
.src
[0].chan
= (id
% 2) * 2;
5825 /* r600 we have them at channel 2 of the second dword */
5826 alu
.src
[0].sel
+= (id
* 2) + 1;
5827 alu
.src
[0].chan
= 1;
5829 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
5830 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5832 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5838 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
5840 static float one_point_five
= 1.5f
;
5841 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5842 struct r600_bytecode_tex tex
;
5843 struct r600_bytecode_alu alu
;
5847 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
5848 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
5849 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
5850 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
5852 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
5853 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
5854 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
5856 /* Texture fetch instructions can only use gprs as source.
5857 * Also they cannot negate the source or take the absolute value */
5858 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
5859 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
5860 tgsi_tex_src_requires_loading(ctx
, 0)) ||
5861 read_compressed_msaa
|| txf_add_offsets
;
5863 boolean src_loaded
= FALSE
;
5864 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
5865 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
5866 boolean has_txq_cube_array_z
= false;
5867 unsigned sampler_index_mode
;
5869 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
5870 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5871 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
5872 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
5873 ctx
->shader
->has_txq_cube_array_z_comp
= true;
5874 has_txq_cube_array_z
= true;
5877 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
5878 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
5879 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
5880 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
5881 sampler_src_reg
= 2;
5883 /* TGSI moves the sampler to src reg 3 for TXD */
5884 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
5885 sampler_src_reg
= 3;
5887 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
5889 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
5891 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
5892 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
5893 ctx
->shader
->uses_tex_buffers
= true;
5894 return r600_do_buffer_txq(ctx
);
5896 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
5897 if (ctx
->bc
->chip_class
< EVERGREEN
)
5898 ctx
->shader
->uses_tex_buffers
= true;
5899 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
5903 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
5905 /* Add perspective divide */
5906 if (ctx
->bc
->chip_class
== CAYMAN
) {
5908 for (i
= 0; i
< 3; i
++) {
5909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5910 alu
.op
= ALU_OP1_RECIP_IEEE
;
5911 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5913 alu
.dst
.sel
= ctx
->temp_reg
;
5919 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5926 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5927 alu
.op
= ALU_OP1_RECIP_IEEE
;
5928 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5930 alu
.dst
.sel
= ctx
->temp_reg
;
5931 alu
.dst
.chan
= out_chan
;
5934 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5939 for (i
= 0; i
< 3; i
++) {
5940 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5941 alu
.op
= ALU_OP2_MUL
;
5942 alu
.src
[0].sel
= ctx
->temp_reg
;
5943 alu
.src
[0].chan
= out_chan
;
5944 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5945 alu
.dst
.sel
= ctx
->temp_reg
;
5948 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5953 alu
.op
= ALU_OP1_MOV
;
5954 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5955 alu
.src
[0].chan
= 0;
5956 alu
.dst
.sel
= ctx
->temp_reg
;
5960 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5964 src_gpr
= ctx
->temp_reg
;
5968 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
5969 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5970 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5971 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
5972 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
5973 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
5975 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
5976 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
5978 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
5979 for (i
= 0; i
< 4; i
++) {
5980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5981 alu
.op
= ALU_OP2_CUBE
;
5982 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5983 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
5984 alu
.dst
.sel
= ctx
->temp_reg
;
5989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5994 /* tmp1.z = RCP_e(|tmp1.z|) */
5995 if (ctx
->bc
->chip_class
== CAYMAN
) {
5996 for (i
= 0; i
< 3; i
++) {
5997 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5998 alu
.op
= ALU_OP1_RECIP_IEEE
;
5999 alu
.src
[0].sel
= ctx
->temp_reg
;
6000 alu
.src
[0].chan
= 2;
6002 alu
.dst
.sel
= ctx
->temp_reg
;
6008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6014 alu
.op
= ALU_OP1_RECIP_IEEE
;
6015 alu
.src
[0].sel
= ctx
->temp_reg
;
6016 alu
.src
[0].chan
= 2;
6018 alu
.dst
.sel
= ctx
->temp_reg
;
6022 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6027 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
6028 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
6029 * muladd has no writemask, have to use another temp
6031 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6032 alu
.op
= ALU_OP3_MULADD
;
6035 alu
.src
[0].sel
= ctx
->temp_reg
;
6036 alu
.src
[0].chan
= 0;
6037 alu
.src
[1].sel
= ctx
->temp_reg
;
6038 alu
.src
[1].chan
= 2;
6040 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
6041 alu
.src
[2].chan
= 0;
6042 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
6044 alu
.dst
.sel
= ctx
->temp_reg
;
6048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6053 alu
.op
= ALU_OP3_MULADD
;
6056 alu
.src
[0].sel
= ctx
->temp_reg
;
6057 alu
.src
[0].chan
= 1;
6058 alu
.src
[1].sel
= ctx
->temp_reg
;
6059 alu
.src
[1].chan
= 2;
6061 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
6062 alu
.src
[2].chan
= 0;
6063 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
6065 alu
.dst
.sel
= ctx
->temp_reg
;
6070 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6073 /* write initial compare value into Z component
6074 - W src 0 for shadow cube
6075 - X src 1 for shadow cube array */
6076 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6077 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6079 alu
.op
= ALU_OP1_MOV
;
6080 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
6081 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
6083 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6084 alu
.dst
.sel
= ctx
->temp_reg
;
6088 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6093 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6094 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6095 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6096 int mytmp
= r600_get_temp(ctx
);
6097 static const float eight
= 8.0f
;
6098 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6099 alu
.op
= ALU_OP1_MOV
;
6100 alu
.src
[0].sel
= ctx
->temp_reg
;
6101 alu
.src
[0].chan
= 3;
6102 alu
.dst
.sel
= mytmp
;
6106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6110 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
6111 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6112 alu
.op
= ALU_OP3_MULADD
;
6114 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6115 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6116 alu
.src
[1].chan
= 0;
6117 alu
.src
[1].value
= *(uint32_t *)&eight
;
6118 alu
.src
[2].sel
= mytmp
;
6119 alu
.src
[2].chan
= 0;
6120 alu
.dst
.sel
= ctx
->temp_reg
;
6124 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6127 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
6128 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6129 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
6130 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6131 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6132 tex
.src_gpr
= r600_get_temp(ctx
);
6137 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
6138 tex
.coord_type_x
= 1;
6139 tex
.coord_type_y
= 1;
6140 tex
.coord_type_z
= 1;
6141 tex
.coord_type_w
= 1;
6142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6143 alu
.op
= ALU_OP1_MOV
;
6144 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6145 alu
.dst
.sel
= tex
.src_gpr
;
6149 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6153 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6160 /* for cube forms of lod and bias we need to route things */
6161 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
6162 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
6163 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6164 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
6165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6166 alu
.op
= ALU_OP1_MOV
;
6167 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6168 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
6169 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
6171 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6172 alu
.dst
.sel
= ctx
->temp_reg
;
6176 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6182 src_gpr
= ctx
->temp_reg
;
6185 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
6186 int temp_h
= 0, temp_v
= 0;
6189 /* if we've already loaded the src (i.e. CUBE don't reload it). */
6190 if (src_loaded
== TRUE
)
6194 for (i
= start_val
; i
< 3; i
++) {
6195 int treg
= r600_get_temp(ctx
);
6204 for (j
= 0; j
< 4; j
++) {
6205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6206 alu
.op
= ALU_OP1_MOV
;
6207 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
6213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6218 for (i
= 1; i
< 3; i
++) {
6219 /* set gradients h/v */
6220 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6221 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
6222 FETCH_OP_SET_GRADIENTS_V
;
6223 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6224 tex
.sampler_index_mode
= sampler_index_mode
;
6225 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6226 tex
.resource_index_mode
= sampler_index_mode
;
6228 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
6234 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
6235 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
6236 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
6237 tex
.coord_type_x
= 1;
6238 tex
.coord_type_y
= 1;
6239 tex
.coord_type_z
= 1;
6240 tex
.coord_type_w
= 1;
6242 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6248 if (src_requires_loading
&& !src_loaded
) {
6249 for (i
= 0; i
< 4; i
++) {
6250 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6251 alu
.op
= ALU_OP1_MOV
;
6252 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6253 alu
.dst
.sel
= ctx
->temp_reg
;
6258 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6263 src_gpr
= ctx
->temp_reg
;
6266 /* get offset values */
6267 if (inst
->Texture
.NumOffsets
) {
6268 assert(inst
->Texture
.NumOffsets
== 1);
6270 /* The texture offset feature doesn't work with the TXF instruction
6271 * and must be emulated by adding the offset to the texture coordinates. */
6272 if (txf_add_offsets
) {
6273 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
6275 switch (inst
->Texture
.Texture
) {
6276 case TGSI_TEXTURE_3D
:
6277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6278 alu
.op
= ALU_OP2_ADD_INT
;
6279 alu
.src
[0].sel
= src_gpr
;
6280 alu
.src
[0].chan
= 2;
6281 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6282 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
6283 alu
.dst
.sel
= src_gpr
;
6287 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6292 case TGSI_TEXTURE_2D
:
6293 case TGSI_TEXTURE_SHADOW2D
:
6294 case TGSI_TEXTURE_RECT
:
6295 case TGSI_TEXTURE_SHADOWRECT
:
6296 case TGSI_TEXTURE_2D_ARRAY
:
6297 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
6298 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6299 alu
.op
= ALU_OP2_ADD_INT
;
6300 alu
.src
[0].sel
= src_gpr
;
6301 alu
.src
[0].chan
= 1;
6302 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6303 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
6304 alu
.dst
.sel
= src_gpr
;
6308 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6313 case TGSI_TEXTURE_1D
:
6314 case TGSI_TEXTURE_SHADOW1D
:
6315 case TGSI_TEXTURE_1D_ARRAY
:
6316 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
6317 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6318 alu
.op
= ALU_OP2_ADD_INT
;
6319 alu
.src
[0].sel
= src_gpr
;
6320 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6321 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
6322 alu
.dst
.sel
= src_gpr
;
6325 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6329 /* texture offsets do not apply to other texture targets */
6332 switch (inst
->Texture
.Texture
) {
6333 case TGSI_TEXTURE_3D
:
6334 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
6336 case TGSI_TEXTURE_2D
:
6337 case TGSI_TEXTURE_SHADOW2D
:
6338 case TGSI_TEXTURE_RECT
:
6339 case TGSI_TEXTURE_SHADOWRECT
:
6340 case TGSI_TEXTURE_2D_ARRAY
:
6341 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
6342 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
6344 case TGSI_TEXTURE_1D
:
6345 case TGSI_TEXTURE_SHADOW1D
:
6346 case TGSI_TEXTURE_1D_ARRAY
:
6347 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
6348 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
6353 /* Obtain the sample index for reading a compressed MSAA color texture.
6354 * To read the FMASK, we use the ldfptr instruction, which tells us
6355 * where the samples are stored.
6356 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
6357 * which is the identity mapping. Each nibble says which physical sample
6358 * should be fetched to get that sample.
6360 * Assume src.z contains the sample index. It should be modified like this:
6361 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
6362 * Then fetch the texel with src.
6364 if (read_compressed_msaa
) {
6365 unsigned sample_chan
= 3;
6366 unsigned temp
= r600_get_temp(ctx
);
6369 /* temp.w = ldfptr() */
6370 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6371 tex
.op
= FETCH_OP_LD
;
6372 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
6373 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6374 tex
.sampler_index_mode
= sampler_index_mode
;
6375 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6376 tex
.resource_index_mode
= sampler_index_mode
;
6377 tex
.src_gpr
= src_gpr
;
6379 tex
.dst_sel_x
= 7; /* mask out these components */
6382 tex
.dst_sel_w
= 0; /* store X */
6387 tex
.offset_x
= offset_x
;
6388 tex
.offset_y
= offset_y
;
6389 tex
.offset_z
= offset_z
;
6390 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6394 /* temp.x = sample_index*4 */
6395 if (ctx
->bc
->chip_class
== CAYMAN
) {
6396 for (i
= 0 ; i
< 4; i
++) {
6397 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6398 alu
.op
= ALU_OP2_MULLO_INT
;
6399 alu
.src
[0].sel
= src_gpr
;
6400 alu
.src
[0].chan
= sample_chan
;
6401 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6402 alu
.src
[1].value
= 4;
6405 alu
.dst
.write
= i
== 0;
6408 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6413 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6414 alu
.op
= ALU_OP2_MULLO_INT
;
6415 alu
.src
[0].sel
= src_gpr
;
6416 alu
.src
[0].chan
= sample_chan
;
6417 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6418 alu
.src
[1].value
= 4;
6423 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6428 /* sample_index = temp.w >> temp.x */
6429 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6430 alu
.op
= ALU_OP2_LSHR_INT
;
6431 alu
.src
[0].sel
= temp
;
6432 alu
.src
[0].chan
= 3;
6433 alu
.src
[1].sel
= temp
;
6434 alu
.src
[1].chan
= 0;
6435 alu
.dst
.sel
= src_gpr
;
6436 alu
.dst
.chan
= sample_chan
;
6439 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6443 /* sample_index & 0xF */
6444 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6445 alu
.op
= ALU_OP2_AND_INT
;
6446 alu
.src
[0].sel
= src_gpr
;
6447 alu
.src
[0].chan
= sample_chan
;
6448 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6449 alu
.src
[1].value
= 0xF;
6450 alu
.dst
.sel
= src_gpr
;
6451 alu
.dst
.chan
= sample_chan
;
6454 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6458 /* visualize the FMASK */
6459 for (i
= 0; i
< 4; i
++) {
6460 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6461 alu
.op
= ALU_OP1_INT_TO_FLT
;
6462 alu
.src
[0].sel
= src_gpr
;
6463 alu
.src
[0].chan
= sample_chan
;
6464 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6476 /* does this shader want a num layers from TXQ for a cube array? */
6477 if (has_txq_cube_array_z
) {
6478 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6481 alu
.op
= ALU_OP1_MOV
;
6483 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6484 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6485 /* channel 1 or 3 of each word */
6486 alu
.src
[0].sel
+= (id
/ 2);
6487 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
6489 /* r600 we have them at channel 2 of the second dword */
6490 alu
.src
[0].sel
+= (id
* 2) + 1;
6491 alu
.src
[0].chan
= 2;
6493 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6494 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
6496 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6499 /* disable writemask from texture instruction */
6500 inst
->Dst
[0].Register
.WriteMask
&= ~4;
6503 opcode
= ctx
->inst_info
->op
;
6504 if (opcode
== FETCH_OP_GATHER4
&&
6505 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
6506 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
6507 opcode
= FETCH_OP_GATHER4_O
;
6509 /* GATHER4_O/GATHER4_C_O use offset values loaded by
6510 SET_TEXTURE_OFFSETS instruction. The immediate offset values
6511 encoded in the instruction are ignored. */
6512 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6513 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
6514 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6515 tex
.sampler_index_mode
= sampler_index_mode
;
6516 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6517 tex
.resource_index_mode
= sampler_index_mode
;
6519 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
6520 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
6521 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
6522 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
6530 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6535 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
6536 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
6537 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
6538 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6539 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
6540 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
6541 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6543 case FETCH_OP_SAMPLE
:
6544 opcode
= FETCH_OP_SAMPLE_C
;
6546 case FETCH_OP_SAMPLE_L
:
6547 opcode
= FETCH_OP_SAMPLE_C_L
;
6549 case FETCH_OP_SAMPLE_LB
:
6550 opcode
= FETCH_OP_SAMPLE_C_LB
;
6552 case FETCH_OP_SAMPLE_G
:
6553 opcode
= FETCH_OP_SAMPLE_C_G
;
6555 /* Texture gather variants */
6556 case FETCH_OP_GATHER4
:
6557 opcode
= FETCH_OP_GATHER4_C
;
6559 case FETCH_OP_GATHER4_O
:
6560 opcode
= FETCH_OP_GATHER4_C_O
;
6565 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6568 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6569 tex
.sampler_index_mode
= sampler_index_mode
;
6570 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6571 tex
.resource_index_mode
= sampler_index_mode
;
6572 tex
.src_gpr
= src_gpr
;
6573 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6575 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
6576 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
6577 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
6580 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
6581 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
6582 tex
.inst_mod
= texture_component_select
;
6584 if (ctx
->bc
->chip_class
== CAYMAN
) {
6585 /* GATHER4 result order is different from TGSI TG4 */
6586 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
6587 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
6588 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
6589 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
6591 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
6592 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
6593 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
6594 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
6597 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
6598 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
6599 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
6603 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
6610 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
6611 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
6612 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
6613 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
6617 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
||
6618 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
6623 } else if (src_loaded
) {
6629 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
6630 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
6631 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
6632 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
6633 tex
.src_rel
= ctx
->src
[0].rel
;
6636 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
6637 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6638 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6639 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6643 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
6646 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
6647 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
6648 tex
.coord_type_x
= 1;
6649 tex
.coord_type_y
= 1;
6651 tex
.coord_type_z
= 1;
6652 tex
.coord_type_w
= 1;
6654 tex
.offset_x
= offset_x
;
6655 tex
.offset_y
= offset_y
;
6656 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
6657 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
6658 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
6662 tex
.offset_z
= offset_z
;
6665 /* Put the depth for comparison in W.
6666 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
6667 * Some instructions expect the depth in Z. */
6668 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
6669 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
6670 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
6671 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
6672 opcode
!= FETCH_OP_SAMPLE_C_L
&&
6673 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
6674 tex
.src_sel_w
= tex
.src_sel_z
;
6677 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
6678 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
6679 if (opcode
== FETCH_OP_SAMPLE_C_L
||
6680 opcode
== FETCH_OP_SAMPLE_C_LB
) {
6681 /* the array index is read from Y */
6682 tex
.coord_type_y
= 0;
6684 /* the array index is read from Z */
6685 tex
.coord_type_z
= 0;
6686 tex
.src_sel_z
= tex
.src_sel_y
;
6688 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
6689 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
6690 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6691 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
6692 (ctx
->bc
->chip_class
>= EVERGREEN
)))
6693 /* the array index is read from Z */
6694 tex
.coord_type_z
= 0;
6696 /* mask unused source components */
6697 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
6698 switch (inst
->Texture
.Texture
) {
6699 case TGSI_TEXTURE_2D
:
6700 case TGSI_TEXTURE_RECT
:
6704 case TGSI_TEXTURE_1D_ARRAY
:
6708 case TGSI_TEXTURE_1D
:
6716 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6720 /* add shadow ambient support - gallium doesn't do it yet */
6724 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
6726 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6727 struct r600_bytecode_alu alu
;
6728 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6729 unsigned i
, temp_regs
[2];
6732 /* optimize if it's just an equal balance */
6733 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
6734 for (i
= 0; i
< lasti
+ 1; i
++) {
6735 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6739 alu
.op
= ALU_OP2_ADD
;
6740 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6741 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6743 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6756 for (i
= 0; i
< lasti
+ 1; i
++) {
6757 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6761 alu
.op
= ALU_OP2_ADD
;
6762 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6763 alu
.src
[0].chan
= 0;
6764 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6765 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
6766 alu
.dst
.sel
= ctx
->temp_reg
;
6772 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6777 /* (1 - src0) * src2 */
6778 for (i
= 0; i
< lasti
+ 1; i
++) {
6779 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6783 alu
.op
= ALU_OP2_MUL
;
6784 alu
.src
[0].sel
= ctx
->temp_reg
;
6785 alu
.src
[0].chan
= i
;
6786 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6787 alu
.dst
.sel
= ctx
->temp_reg
;
6793 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6798 /* src0 * src1 + (1 - src0) * src2 */
6799 if (ctx
->src
[0].abs
)
6800 temp_regs
[0] = r600_get_temp(ctx
);
6803 if (ctx
->src
[1].abs
)
6804 temp_regs
[1] = r600_get_temp(ctx
);
6808 for (i
= 0; i
< lasti
+ 1; i
++) {
6809 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6812 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6813 alu
.op
= ALU_OP3_MULADD
;
6815 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
6818 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
6821 alu
.src
[2].sel
= ctx
->temp_reg
;
6822 alu
.src
[2].chan
= i
;
6824 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6829 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6836 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
6838 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6839 struct r600_bytecode_alu alu
;
6841 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6844 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6846 if (ctx
->src
[j
].abs
)
6847 temp_regs
[j
] = r600_get_temp(ctx
);
6850 for (i
= 0; i
< lasti
+ 1; i
++) {
6851 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6854 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6855 alu
.op
= ALU_OP3_CNDGE
;
6856 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
6859 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
6862 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
6865 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6878 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
6880 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6881 struct r600_bytecode_alu alu
;
6883 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6885 for (i
= 0; i
< lasti
+ 1; i
++) {
6886 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6890 alu
.op
= ALU_OP3_CNDE_INT
;
6891 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6892 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6893 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6894 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6907 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
6909 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6910 static const unsigned int src0_swizzle
[] = {2, 0, 1};
6911 static const unsigned int src1_swizzle
[] = {1, 2, 0};
6912 struct r600_bytecode_alu alu
;
6913 uint32_t use_temp
= 0;
6916 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
6919 for (i
= 0; i
< 4; i
++) {
6920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6921 alu
.op
= ALU_OP2_MUL
;
6923 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
6924 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
6926 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6927 alu
.src
[0].chan
= i
;
6928 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6929 alu
.src
[1].chan
= i
;
6932 alu
.dst
.sel
= ctx
->temp_reg
;
6938 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6943 for (i
= 0; i
< 4; i
++) {
6944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6945 alu
.op
= ALU_OP3_MULADD
;
6948 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
6949 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
6951 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6952 alu
.src
[0].chan
= i
;
6953 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6954 alu
.src
[1].chan
= i
;
6957 alu
.src
[2].sel
= ctx
->temp_reg
;
6959 alu
.src
[2].chan
= i
;
6962 alu
.dst
.sel
= ctx
->temp_reg
;
6964 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6970 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6975 return tgsi_helper_copy(ctx
, inst
);
6979 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
6981 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6982 struct r600_bytecode_alu alu
;
6986 /* result.x = 2^floor(src); */
6987 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
6988 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6990 alu
.op
= ALU_OP1_FLOOR
;
6991 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6993 alu
.dst
.sel
= ctx
->temp_reg
;
6997 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7001 if (ctx
->bc
->chip_class
== CAYMAN
) {
7002 for (i
= 0; i
< 3; i
++) {
7003 alu
.op
= ALU_OP1_EXP_IEEE
;
7004 alu
.src
[0].sel
= ctx
->temp_reg
;
7005 alu
.src
[0].chan
= 0;
7007 alu
.dst
.sel
= ctx
->temp_reg
;
7009 alu
.dst
.write
= i
== 0;
7011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7016 alu
.op
= ALU_OP1_EXP_IEEE
;
7017 alu
.src
[0].sel
= ctx
->temp_reg
;
7018 alu
.src
[0].chan
= 0;
7020 alu
.dst
.sel
= ctx
->temp_reg
;
7024 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7030 /* result.y = tmp - floor(tmp); */
7031 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
7032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7034 alu
.op
= ALU_OP1_FRACT
;
7035 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7037 alu
.dst
.sel
= ctx
->temp_reg
;
7039 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7053 /* result.z = RoughApprox2ToX(tmp);*/
7054 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
7055 if (ctx
->bc
->chip_class
== CAYMAN
) {
7056 for (i
= 0; i
< 3; i
++) {
7057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7058 alu
.op
= ALU_OP1_EXP_IEEE
;
7059 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7061 alu
.dst
.sel
= ctx
->temp_reg
;
7068 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7074 alu
.op
= ALU_OP1_EXP_IEEE
;
7075 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7077 alu
.dst
.sel
= ctx
->temp_reg
;
7083 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7089 /* result.w = 1.0;*/
7090 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
7091 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7093 alu
.op
= ALU_OP1_MOV
;
7094 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7095 alu
.src
[0].chan
= 0;
7097 alu
.dst
.sel
= ctx
->temp_reg
;
7101 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7105 return tgsi_helper_copy(ctx
, inst
);
7108 static int tgsi_log(struct r600_shader_ctx
*ctx
)
7110 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7111 struct r600_bytecode_alu alu
;
7115 /* result.x = floor(log2(|src|)); */
7116 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
7117 if (ctx
->bc
->chip_class
== CAYMAN
) {
7118 for (i
= 0; i
< 3; i
++) {
7119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7121 alu
.op
= ALU_OP1_LOG_IEEE
;
7122 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7123 r600_bytecode_src_set_abs(&alu
.src
[0]);
7125 alu
.dst
.sel
= ctx
->temp_reg
;
7131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7137 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7139 alu
.op
= ALU_OP1_LOG_IEEE
;
7140 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7141 r600_bytecode_src_set_abs(&alu
.src
[0]);
7143 alu
.dst
.sel
= ctx
->temp_reg
;
7147 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7152 alu
.op
= ALU_OP1_FLOOR
;
7153 alu
.src
[0].sel
= ctx
->temp_reg
;
7154 alu
.src
[0].chan
= 0;
7156 alu
.dst
.sel
= ctx
->temp_reg
;
7161 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7166 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
7167 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
7169 if (ctx
->bc
->chip_class
== CAYMAN
) {
7170 for (i
= 0; i
< 3; i
++) {
7171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7173 alu
.op
= ALU_OP1_LOG_IEEE
;
7174 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7175 r600_bytecode_src_set_abs(&alu
.src
[0]);
7177 alu
.dst
.sel
= ctx
->temp_reg
;
7184 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7189 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7191 alu
.op
= ALU_OP1_LOG_IEEE
;
7192 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7193 r600_bytecode_src_set_abs(&alu
.src
[0]);
7195 alu
.dst
.sel
= ctx
->temp_reg
;
7200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7207 alu
.op
= ALU_OP1_FLOOR
;
7208 alu
.src
[0].sel
= ctx
->temp_reg
;
7209 alu
.src
[0].chan
= 1;
7211 alu
.dst
.sel
= ctx
->temp_reg
;
7216 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7220 if (ctx
->bc
->chip_class
== CAYMAN
) {
7221 for (i
= 0; i
< 3; i
++) {
7222 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7223 alu
.op
= ALU_OP1_EXP_IEEE
;
7224 alu
.src
[0].sel
= ctx
->temp_reg
;
7225 alu
.src
[0].chan
= 1;
7227 alu
.dst
.sel
= ctx
->temp_reg
;
7234 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7240 alu
.op
= ALU_OP1_EXP_IEEE
;
7241 alu
.src
[0].sel
= ctx
->temp_reg
;
7242 alu
.src
[0].chan
= 1;
7244 alu
.dst
.sel
= ctx
->temp_reg
;
7249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7254 if (ctx
->bc
->chip_class
== CAYMAN
) {
7255 for (i
= 0; i
< 3; i
++) {
7256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7257 alu
.op
= ALU_OP1_RECIP_IEEE
;
7258 alu
.src
[0].sel
= ctx
->temp_reg
;
7259 alu
.src
[0].chan
= 1;
7261 alu
.dst
.sel
= ctx
->temp_reg
;
7268 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7273 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7274 alu
.op
= ALU_OP1_RECIP_IEEE
;
7275 alu
.src
[0].sel
= ctx
->temp_reg
;
7276 alu
.src
[0].chan
= 1;
7278 alu
.dst
.sel
= ctx
->temp_reg
;
7283 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7290 alu
.op
= ALU_OP2_MUL
;
7292 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7293 r600_bytecode_src_set_abs(&alu
.src
[0]);
7295 alu
.src
[1].sel
= ctx
->temp_reg
;
7296 alu
.src
[1].chan
= 1;
7298 alu
.dst
.sel
= ctx
->temp_reg
;
7303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7308 /* result.z = log2(|src|);*/
7309 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
7310 if (ctx
->bc
->chip_class
== CAYMAN
) {
7311 for (i
= 0; i
< 3; i
++) {
7312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7314 alu
.op
= ALU_OP1_LOG_IEEE
;
7315 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7316 r600_bytecode_src_set_abs(&alu
.src
[0]);
7318 alu
.dst
.sel
= ctx
->temp_reg
;
7325 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7330 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7332 alu
.op
= ALU_OP1_LOG_IEEE
;
7333 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7334 r600_bytecode_src_set_abs(&alu
.src
[0]);
7336 alu
.dst
.sel
= ctx
->temp_reg
;
7341 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7347 /* result.w = 1.0; */
7348 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
7349 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7351 alu
.op
= ALU_OP1_MOV
;
7352 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7353 alu
.src
[0].chan
= 0;
7355 alu
.dst
.sel
= ctx
->temp_reg
;
7360 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7365 return tgsi_helper_copy(ctx
, inst
);
7368 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
7370 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7371 struct r600_bytecode_alu alu
;
7373 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7374 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
7376 assert(inst
->Dst
[0].Register
.Index
< 3);
7377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7379 switch (inst
->Instruction
.Opcode
) {
7380 case TGSI_OPCODE_ARL
:
7381 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
7383 case TGSI_OPCODE_ARR
:
7384 alu
.op
= ALU_OP1_FLT_TO_INT
;
7386 case TGSI_OPCODE_UARL
:
7387 alu
.op
= ALU_OP1_MOV
;
7394 for (i
= 0; i
<= lasti
; ++i
) {
7395 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7397 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7398 alu
.last
= i
== lasti
;
7402 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7407 if (inst
->Dst
[0].Register
.Index
> 0)
7408 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
7410 ctx
->bc
->ar_loaded
= 0;
7414 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
7416 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7417 struct r600_bytecode_alu alu
;
7419 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7421 switch (inst
->Instruction
.Opcode
) {
7422 case TGSI_OPCODE_ARL
:
7423 memset(&alu
, 0, sizeof(alu
));
7424 alu
.op
= ALU_OP1_FLOOR
;
7425 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7427 for (i
= 0; i
<= lasti
; ++i
) {
7428 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
7430 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7431 alu
.last
= i
== lasti
;
7432 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7437 memset(&alu
, 0, sizeof(alu
));
7438 alu
.op
= ALU_OP1_FLT_TO_INT
;
7439 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
7440 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7442 /* FLT_TO_INT is trans-only on r600/r700 */
7444 for (i
= 0; i
<= lasti
; ++i
) {
7446 alu
.src
[0].chan
= i
;
7447 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7451 case TGSI_OPCODE_ARR
:
7452 memset(&alu
, 0, sizeof(alu
));
7453 alu
.op
= ALU_OP1_FLT_TO_INT
;
7454 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7456 /* FLT_TO_INT is trans-only on r600/r700 */
7458 for (i
= 0; i
<= lasti
; ++i
) {
7459 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
7461 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7462 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7467 case TGSI_OPCODE_UARL
:
7468 memset(&alu
, 0, sizeof(alu
));
7469 alu
.op
= ALU_OP1_MOV
;
7470 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7472 for (i
= 0; i
<= lasti
; ++i
) {
7473 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
7475 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7476 alu
.last
= i
== lasti
;
7477 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7487 ctx
->bc
->ar_loaded
= 0;
7491 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
7493 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7494 struct r600_bytecode_alu alu
;
7497 for (i
= 0; i
< 4; i
++) {
7498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7500 alu
.op
= ALU_OP2_MUL
;
7501 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7503 if (i
== 0 || i
== 3) {
7504 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7506 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7509 if (i
== 0 || i
== 2) {
7510 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
7512 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
7516 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7523 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
7525 struct r600_bytecode_alu alu
;
7528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7530 alu
.execute_mask
= 1;
7531 alu
.update_pred
= 1;
7533 alu
.dst
.sel
= ctx
->temp_reg
;
7537 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7538 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7539 alu
.src
[1].chan
= 0;
7543 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
7549 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
7551 unsigned force_pop
= ctx
->bc
->force_add_cf
;
7555 if (ctx
->bc
->cf_last
) {
7556 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
7558 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
7563 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
7564 ctx
->bc
->force_add_cf
= 1;
7565 } else if (alu_pop
== 2) {
7566 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
7567 ctx
->bc
->force_add_cf
= 1;
7574 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
7575 ctx
->bc
->cf_last
->pop_count
= pops
;
7576 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7582 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
7585 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
7586 unsigned elements
, entries
;
7588 unsigned entry_size
= stack
->entry_size
;
7590 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
7591 elements
+= stack
->push
;
7593 switch (ctx
->bc
->chip_class
) {
7596 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
7597 * the stack must be reserved to hold the current active/continue
7599 if (reason
== FC_PUSH_VPM
) {
7605 /* r9xx: any stack operation on empty stack consumes 2 additional
7610 /* FIXME: do the two elements added above cover the cases for the
7614 /* r8xx+: 2 extra elements are not always required, but one extra
7615 * element must be added for each of the following cases:
7616 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
7618 * (Currently we don't use ALU_ELSE_AFTER.)
7619 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
7620 * PUSH instruction executed.
7622 * NOTE: it seems we also need to reserve additional element in some
7623 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
7624 * then STACK_SIZE should be 2 instead of 1 */
7625 if (reason
== FC_PUSH_VPM
) {
7635 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
7636 * for all chips, so we use 4 in the final formula, not the real entry_size
7640 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
7642 if (entries
> stack
->max_entries
)
7643 stack
->max_entries
= entries
;
7646 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
7650 --ctx
->bc
->stack
.push
;
7651 assert(ctx
->bc
->stack
.push
>= 0);
7654 --ctx
->bc
->stack
.push_wqm
;
7655 assert(ctx
->bc
->stack
.push_wqm
>= 0);
7658 --ctx
->bc
->stack
.loop
;
7659 assert(ctx
->bc
->stack
.loop
>= 0);
7667 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
7671 ++ctx
->bc
->stack
.push
;
7674 ++ctx
->bc
->stack
.push_wqm
;
7676 ++ctx
->bc
->stack
.loop
;
7682 callstack_update_max_depth(ctx
, reason
);
7685 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
7687 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
7689 sp
->mid
= realloc((void *)sp
->mid
,
7690 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
7691 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
7695 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
7698 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
7699 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
7702 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
7704 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
7714 static int emit_return(struct r600_shader_ctx
*ctx
)
7716 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
7720 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
7723 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
7724 ctx
->bc
->cf_last
->pop_count
= pops
;
7725 /* XXX work out offset */
7729 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
7734 static void emit_testflag(struct r600_shader_ctx
*ctx
)
7739 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
7742 emit_jump_to_offset(ctx
, 1, 4);
7743 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
7744 pops(ctx
, ifidx
+ 1);
7748 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
7752 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
7753 ctx
->bc
->cf_last
->pop_count
= 1;
7755 fc_set_mid(ctx
, fc_sp
);
7761 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
7763 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
7765 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
7766 * LOOP_STARTxxx for nested loops may put the branch stack into a state
7767 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
7768 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
7769 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
7770 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
7771 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7772 alu_type
= CF_OP_ALU
;
7775 emit_logic_pred(ctx
, opcode
, alu_type
);
7777 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
7779 fc_pushlevel(ctx
, FC_IF
);
7781 callstack_push(ctx
, FC_PUSH_VPM
);
7785 static int tgsi_if(struct r600_shader_ctx
*ctx
)
7787 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
7790 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
7792 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
7795 static int tgsi_else(struct r600_shader_ctx
*ctx
)
7797 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
7798 ctx
->bc
->cf_last
->pop_count
= 1;
7800 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
7801 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
7805 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
7808 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
7809 R600_ERR("if/endif unbalanced in shader\n");
7813 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
7814 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7815 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
7817 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7821 callstack_pop(ctx
, FC_PUSH_VPM
);
7825 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
7827 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
7828 * limited to 4096 iterations, like the other LOOP_* instructions. */
7829 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
7831 fc_pushlevel(ctx
, FC_LOOP
);
7833 /* check stack depth */
7834 callstack_push(ctx
, FC_LOOP
);
7838 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
7842 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
7844 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
7845 R600_ERR("loop/endloop in shader code are not paired.\n");
7849 /* fixup loop pointers - from r600isa
7850 LOOP END points to CF after LOOP START,
7851 LOOP START point to CF after LOOP END
7852 BRK/CONT point to LOOP END CF
7854 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
7856 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7858 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
7859 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
7861 /* XXX add LOOPRET support */
7863 callstack_pop(ctx
, FC_LOOP
);
7867 static int tgsi_loop_breakc(struct r600_shader_ctx
*ctx
)
7872 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
7874 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
7878 R600_ERR("BREAKC not inside loop/endloop pair\n");
7882 if (ctx
->bc
->chip_class
== EVERGREEN
&&
7883 ctx
->bc
->family
!= CHIP_CYPRESS
&&
7884 ctx
->bc
->family
!= CHIP_JUNIPER
) {
7885 /* HW bug: ALU_BREAK does not save the active mask correctly */
7890 r
= r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_BREAK
);
7893 fc_set_mid(ctx
, fscp
);
7895 return tgsi_endif(ctx
);
7897 r
= emit_logic_pred(ctx
, ALU_OP2_PRED_SETE_INT
, CF_OP_ALU_BREAK
);
7900 fc_set_mid(ctx
, fscp
);
7906 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
7910 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
7912 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
7917 R600_ERR("Break not inside loop/endloop pair\n");
7921 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
7923 fc_set_mid(ctx
, fscp
);
7928 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
7930 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7931 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
7934 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
7935 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
7937 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
7939 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
7940 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
7945 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
7947 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7948 struct r600_bytecode_alu alu
;
7950 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7953 for (i
= 0; i
< lasti
+ 1; i
++) {
7954 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7957 if (ctx
->bc
->chip_class
== CAYMAN
) {
7958 for (j
= 0 ; j
< 4; j
++) {
7959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7961 alu
.op
= ALU_OP2_MULLO_UINT
;
7962 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
7963 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
7966 alu
.dst
.sel
= ctx
->temp_reg
;
7967 alu
.dst
.write
= (j
== i
);
7970 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7978 alu
.dst
.sel
= ctx
->temp_reg
;
7981 alu
.op
= ALU_OP2_MULLO_UINT
;
7982 for (j
= 0; j
< 2; j
++) {
7983 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
7987 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7994 for (i
= 0; i
< lasti
+ 1; i
++) {
7995 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7999 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8001 alu
.op
= ALU_OP2_ADD_INT
;
8003 alu
.src
[0].sel
= ctx
->temp_reg
;
8004 alu
.src
[0].chan
= i
;
8006 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8010 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8017 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
8018 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
8019 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
8020 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
8023 * For state trackers other than OpenGL, we'll want to use
8024 * _RECIP_IEEE instead.
8026 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
8028 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
8029 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
8030 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
8031 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
8032 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
8033 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
8034 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
8035 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
8036 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
8037 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
8038 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
8039 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
8040 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
8041 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
8042 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
8043 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8044 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
8045 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8046 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
8047 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
8048 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
8049 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8050 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
8051 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
8052 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
8053 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
8054 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
8055 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
8056 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
8057 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
8058 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
8059 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
8060 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
8061 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8062 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8063 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
8064 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8065 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8066 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8067 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8068 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
8069 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
8070 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
8071 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
8072 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
8073 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
8074 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
8075 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
8076 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8077 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
8078 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8079 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8080 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8081 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8082 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8083 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
8084 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
8085 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
8086 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
8087 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8088 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8089 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
8090 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
8091 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
8092 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8093 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
8094 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8095 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
8096 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8097 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
8098 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
8099 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
8100 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
8101 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
8102 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
8103 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8104 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8105 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8106 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8107 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
8108 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
8109 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
8110 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
8111 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
8112 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
8113 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
8114 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
8115 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
8116 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
8117 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8118 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
8119 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8120 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
8121 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
8122 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
8123 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
8124 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8125 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
8126 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8127 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8128 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
8129 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
8130 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
8131 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8132 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
8133 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
8134 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
8135 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
8136 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
8137 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8138 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
8139 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_loop_breakc
},
8140 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
8141 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
8142 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
8143 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
8144 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
8145 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
8146 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
8147 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
8148 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
8149 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
8150 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
8151 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
8152 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
8153 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
8154 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
8155 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
8156 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
8157 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
8158 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
8159 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
8160 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
8161 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
8162 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
8163 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
8164 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
8165 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8166 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8167 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8168 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8169 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
8170 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
8171 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
8172 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
8173 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
8174 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
8175 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
8176 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
8177 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
8178 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
8179 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
8180 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
8181 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
8182 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
8183 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
8184 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
8185 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8186 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8187 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8188 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8189 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8190 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8191 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8192 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8193 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8194 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8195 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8196 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8197 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8198 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8199 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8200 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8201 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8202 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8203 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8204 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
8205 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
8206 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
8207 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
8208 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
8209 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
8210 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8211 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
8212 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
8213 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
8214 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
8215 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
8216 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8217 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8218 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8219 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8222 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
8223 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8224 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
8225 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
8226 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
8227 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
8228 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
8229 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
8230 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
8231 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
8232 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
8233 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
8234 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
8235 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
8236 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
8237 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
8238 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
8239 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
8240 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
8241 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
8242 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8243 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
8244 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8245 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
8246 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
8247 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
8248 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8249 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
8250 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
8251 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
8252 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
8253 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
8254 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
8255 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
8256 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
8257 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
8258 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
8259 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
8260 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8261 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8262 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
8263 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8264 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8265 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8266 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8267 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
8268 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
8269 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
8270 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
8271 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
8272 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
8273 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
8274 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
8275 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8276 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
8277 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8278 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8279 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8280 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8281 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8282 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
8283 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
8284 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8285 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
8286 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8287 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8288 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
8289 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
8290 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
8291 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8292 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
8293 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8294 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
8295 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8296 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
8297 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
8298 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
8299 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
8300 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
8301 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
8302 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8303 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8304 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8305 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8306 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
8307 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
8308 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
8309 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
8310 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
8311 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
8312 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
8313 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
8314 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
8315 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
8316 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8317 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
8318 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8319 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
8320 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
8321 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
8322 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
8323 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8324 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
8325 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8326 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8327 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
8328 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
8329 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
8330 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8331 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
8332 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
8333 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
8334 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
8335 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
8336 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8337 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
8338 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8339 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
8340 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
8341 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
8342 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
8343 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
8344 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
8345 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
8346 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
8347 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
8348 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
8349 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
8350 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
8351 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
8352 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
8353 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
8354 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
8355 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
8356 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
8357 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
8358 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
8359 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
8360 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
8361 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
8362 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
8363 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
8364 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8365 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8366 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8367 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8368 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
8369 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
8370 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
8371 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
8372 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
8373 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
8374 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
8375 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
8376 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
8377 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
8378 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
8379 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
8380 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
8381 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
8382 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
8383 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
8384 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8385 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8386 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8387 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8388 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8389 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8390 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8391 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8392 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8393 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8394 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8395 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8396 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8397 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8398 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8399 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8400 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8401 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8402 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8403 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
8404 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
8405 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
8406 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
8407 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_op3
},
8408 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_op3
},
8409 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
8410 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
8411 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
8412 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
8413 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
8414 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
8415 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8416 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8417 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8418 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
8419 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
8420 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
8421 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
8422 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
8423 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
8424 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
8425 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
8426 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
8427 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
8428 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
8429 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
8430 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
8431 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
8432 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
8433 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
8434 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
8435 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
8436 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
8437 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
8438 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
8439 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
8440 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
8441 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8444 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
8445 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8446 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
8447 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
8448 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
8449 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
8450 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
8451 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
8452 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
8453 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
8454 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
8455 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
8456 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
8457 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
8458 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
8459 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
8460 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
8461 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
8462 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
8463 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
8464 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8465 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
8466 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8467 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
8468 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
8469 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
8470 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8471 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
8472 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
8473 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
8474 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
8475 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
8476 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
8477 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
8478 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
8479 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
8480 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
8481 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
8482 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8483 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8484 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
8485 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8486 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8487 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8488 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8489 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
8490 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
8491 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
8492 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
8493 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
8494 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
8495 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
8496 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
8497 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8498 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
8499 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8500 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8501 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8502 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8503 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8504 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
8505 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
8506 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8507 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
8508 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8509 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8510 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
8511 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
8512 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
8513 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8514 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
8515 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8516 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
8517 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8518 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
8519 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
8520 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
8521 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
8522 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
8523 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
8524 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8525 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8526 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8527 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8528 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
8529 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
8530 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
8531 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
8532 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
8533 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
8534 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
8535 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
8536 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
8537 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
8538 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8539 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
8540 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8541 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
8542 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
8543 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
8544 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
8545 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8546 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
8547 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8548 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8549 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
8550 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
8551 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
8552 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8553 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
8554 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
8555 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
8556 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
8557 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
8558 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8559 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
8560 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8561 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
8562 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
8563 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
8564 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
8565 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
8566 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
8567 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
8568 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
8569 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
8570 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
8571 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
8572 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
8573 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
8574 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
8575 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
8576 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
8577 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
8578 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
8579 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
8580 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
8581 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
8582 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
8583 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
8584 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
8585 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
8586 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8587 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8588 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8589 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8590 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
8591 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
8592 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
8593 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
8594 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
8595 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
8596 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
8597 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
8598 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
8599 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
8600 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
8601 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
8602 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
8603 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
8604 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
8605 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
8606 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8607 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8608 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8609 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8610 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8611 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8612 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8613 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8614 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8615 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8616 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8617 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8618 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8619 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8620 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8621 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8622 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8623 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8624 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8625 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
8626 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
8627 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
8628 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
8629 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_op3
},
8630 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_op3
},
8631 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
8632 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
8633 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
8634 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
8635 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
8636 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
8637 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8638 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8639 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8640 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
8641 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
8642 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
8643 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
8644 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
8645 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
8646 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
8647 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
8648 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
8649 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
8650 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
8651 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
8652 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
8653 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
8654 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
8655 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
8656 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
8657 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
8658 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
8659 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
8660 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
8661 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
8662 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
8663 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},