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
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 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
64 struct r600_pipe_shader
*pipeshader
,
65 struct r600_shader_key key
);
67 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
68 int size
, unsigned comp_mask
) {
73 if (ps
->num_arrays
== ps
->max_arrays
) {
75 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
76 sizeof(struct r600_shader_array
));
79 int n
= ps
->num_arrays
;
82 ps
->arrays
[n
].comp_mask
= comp_mask
;
83 ps
->arrays
[n
].gpr_start
= start_gpr
;
84 ps
->arrays
[n
].gpr_count
= size
;
87 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
91 fprintf(stderr
, "STREAMOUT\n");
92 for (i
= 0; i
< so
->num_outputs
; i
++) {
93 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
94 so
->output
[i
].start_component
;
95 fprintf(stderr
, " %i: MEM_STREAM0_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
96 i
, so
->output
[i
].output_buffer
,
97 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
98 so
->output
[i
].register_index
,
103 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
107 int r600_pipe_shader_create(struct pipe_context
*ctx
,
108 struct r600_pipe_shader
*shader
,
109 struct r600_shader_key key
)
111 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
112 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
115 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
, sel
->tokens
);
116 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
117 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
119 shader
->shader
.bc
.isa
= rctx
->isa
;
122 fprintf(stderr
, "--------------------------------------------------------------\n");
123 tgsi_dump(sel
->tokens
, 0);
125 if (sel
->so
.num_outputs
) {
126 r600_dump_streamout(&sel
->so
);
129 r
= r600_shader_from_tgsi(rctx
->screen
, shader
, key
);
131 R600_ERR("translation from TGSI failed !\n");
135 /* Check if the bytecode has already been built. When using the llvm
136 * backend, r600_shader_from_tgsi() will take care of building the
139 if (!shader
->shader
.bc
.bytecode
) {
140 r
= r600_bytecode_build(&shader
->shader
.bc
);
142 R600_ERR("building bytecode failed !\n");
147 if (dump
&& !sb_disasm
) {
148 fprintf(stderr
, "--------------------------------------------------------------\n");
149 r600_bytecode_disasm(&shader
->shader
.bc
);
150 fprintf(stderr
, "______________________________________________________________\n");
151 } else if ((dump
&& sb_disasm
) || use_sb
) {
152 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
155 R600_ERR("r600_sb_bytecode_process failed !\n");
160 /* Store the shader in a buffer. */
161 if (shader
->bo
== NULL
) {
162 shader
->bo
= (struct r600_resource
*)
163 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
164 if (shader
->bo
== NULL
) {
167 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
168 if (R600_BIG_ENDIAN
) {
169 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
170 ptr
[i
] = util_bswap32(shader
->shader
.bc
.bytecode
[i
]);
173 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
175 rctx
->b
.ws
->buffer_unmap(shader
->bo
->cs_buf
);
179 switch (shader
->shader
.processor_type
) {
180 case TGSI_PROCESSOR_VERTEX
:
181 if (rctx
->b
.chip_class
>= EVERGREEN
) {
182 evergreen_update_vs_state(ctx
, shader
);
184 r600_update_vs_state(ctx
, shader
);
187 case TGSI_PROCESSOR_FRAGMENT
:
188 if (rctx
->b
.chip_class
>= EVERGREEN
) {
189 evergreen_update_ps_state(ctx
, shader
);
191 r600_update_ps_state(ctx
, shader
);
200 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
202 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
203 r600_bytecode_clear(&shader
->shader
.bc
);
204 r600_release_command_buffer(&shader
->command_buffer
);
208 * tgsi -> r600 shader
210 struct r600_shader_tgsi_instruction
;
212 struct r600_shader_src
{
222 struct r600_shader_ctx
{
223 struct tgsi_shader_info info
;
224 struct tgsi_parse_context parse
;
225 const struct tgsi_token
*tokens
;
227 unsigned file_offset
[TGSI_FILE_COUNT
];
229 struct r600_shader_tgsi_instruction
*inst_info
;
230 struct r600_bytecode
*bc
;
231 struct r600_shader
*shader
;
232 struct r600_shader_src src
[4];
235 uint32_t max_driver_temp_used
;
237 /* needed for evergreen interpolation */
238 boolean input_centroid
;
239 boolean input_linear
;
240 boolean input_perspective
;
244 boolean clip_vertex_write
;
250 struct r600_shader_tgsi_instruction
{
251 unsigned tgsi_opcode
;
254 int (*process
)(struct r600_shader_ctx
*ctx
);
257 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
258 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
259 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
260 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
261 static int tgsi_else(struct r600_shader_ctx
*ctx
);
262 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
263 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
264 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
265 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
267 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
269 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
272 if (i
->Instruction
.NumDstRegs
> 1) {
273 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
276 if (i
->Instruction
.Predicate
) {
277 R600_ERR("predicate unsupported\n");
281 if (i
->Instruction
.Label
) {
282 R600_ERR("label unsupported\n");
286 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
287 if (i
->Src
[j
].Register
.Dimension
) {
288 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
289 R600_ERR("unsupported src %d (dimension %d)\n", j
,
290 i
->Src
[j
].Register
.Dimension
);
295 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
296 if (i
->Dst
[j
].Register
.Dimension
) {
297 R600_ERR("unsupported dst (dimension)\n");
304 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
309 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
310 if (ctx
->shader
->input
[input
].centroid
)
312 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
313 /* if we have perspective add one */
314 if (ctx
->input_perspective
) {
316 /* if we have perspective centroid */
317 if (ctx
->input_centroid
)
320 if (ctx
->shader
->input
[input
].centroid
)
324 ctx
->shader
->input
[input
].ij_index
= ij_index
;
327 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
330 struct r600_bytecode_alu alu
;
331 int gpr
= 0, base_chan
= 0;
332 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
334 /* work out gpr and base_chan from index */
336 base_chan
= (2 * (ij_index
% 2)) + 1;
338 for (i
= 0; i
< 8; i
++) {
339 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
342 alu
.op
= ALU_OP2_INTERP_ZW
;
344 alu
.op
= ALU_OP2_INTERP_XY
;
346 if ((i
> 1) && (i
< 6)) {
347 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
351 alu
.dst
.chan
= i
% 4;
353 alu
.src
[0].sel
= gpr
;
354 alu
.src
[0].chan
= (base_chan
- (i
% 2));
356 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
358 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
361 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
368 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
371 struct r600_bytecode_alu alu
;
373 for (i
= 0; i
< 4; i
++) {
374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
376 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
378 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
383 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
388 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
396 * Special export handling in shaders
398 * shader export ARRAY_BASE for EXPORT_POS:
401 * 62, 63 are clip distance vectors
403 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
404 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
405 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
406 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
407 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
408 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
409 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
410 * exclusive from render target index)
411 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
414 * shader export ARRAY_BASE for EXPORT_PIXEL:
416 * 61 computed Z vector
418 * The use of the values exported in the computed Z vector are controlled
419 * by DB_SHADER_CONTROL:
420 * Z_EXPORT_ENABLE - Z as a float in RED
421 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
422 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
423 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
424 * DB_SOURCE_FORMAT - export control restrictions
429 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
430 static int r600_spi_sid(struct r600_shader_io
* io
)
432 int index
, name
= io
->name
;
434 /* These params are handled differently, they don't need
435 * semantic indices, so we'll use 0 for them.
437 if (name
== TGSI_SEMANTIC_POSITION
||
438 name
== TGSI_SEMANTIC_PSIZE
||
439 name
== TGSI_SEMANTIC_FACE
)
442 if (name
== TGSI_SEMANTIC_GENERIC
) {
443 /* For generic params simply use sid from tgsi */
446 /* For non-generic params - pack name and sid into 8 bits */
447 index
= 0x80 | (name
<<3) | (io
->sid
);
450 /* Make sure that all really used indices have nonzero value, so
451 * we can just compare it to 0 later instead of comparing the name
452 * with different values to detect special cases. */
459 /* turn input into interpolate on EG */
460 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
464 if (ctx
->shader
->input
[index
].spi_sid
) {
465 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
466 if (ctx
->shader
->input
[index
].interpolate
> 0) {
467 evergreen_interp_assign_ij_index(ctx
, index
);
469 r
= evergreen_interp_alu(ctx
, index
);
472 r
= evergreen_interp_flat(ctx
, index
);
478 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
480 struct r600_bytecode_alu alu
;
482 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
483 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
485 for (i
= 0; i
< 4; i
++) {
486 memset(&alu
, 0, sizeof(alu
));
487 alu
.op
= ALU_OP3_CNDGT
;
490 alu
.dst
.sel
= gpr_front
;
491 alu
.src
[0].sel
= ctx
->face_gpr
;
492 alu
.src
[1].sel
= gpr_front
;
493 alu
.src
[2].sel
= gpr_back
;
500 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
507 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
509 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
510 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
512 switch (d
->Declaration
.File
) {
513 case TGSI_FILE_INPUT
:
514 i
= ctx
->shader
->ninput
;
515 assert(i
< Elements(ctx
->shader
->input
));
516 ctx
->shader
->ninput
+= count
;
517 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
518 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
519 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
520 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
521 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
522 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
523 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
524 switch (ctx
->shader
->input
[i
].name
) {
525 case TGSI_SEMANTIC_FACE
:
526 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
528 case TGSI_SEMANTIC_COLOR
:
531 case TGSI_SEMANTIC_POSITION
:
532 ctx
->fragcoord_input
= i
;
535 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
536 if ((r
= evergreen_interp_input(ctx
, i
)))
540 for (j
= 1; j
< count
; ++j
) {
541 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
542 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
545 case TGSI_FILE_OUTPUT
:
546 i
= ctx
->shader
->noutput
++;
547 assert(i
< Elements(ctx
->shader
->output
));
548 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
549 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
550 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
551 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
552 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
553 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
554 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
555 switch (d
->Semantic
.Name
) {
556 case TGSI_SEMANTIC_CLIPDIST
:
557 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
559 case TGSI_SEMANTIC_PSIZE
:
560 ctx
->shader
->vs_out_misc_write
= 1;
561 ctx
->shader
->vs_out_point_size
= 1;
563 case TGSI_SEMANTIC_CLIPVERTEX
:
564 ctx
->clip_vertex_write
= TRUE
;
568 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
569 switch (d
->Semantic
.Name
) {
570 case TGSI_SEMANTIC_COLOR
:
571 ctx
->shader
->nr_ps_max_color_exports
++;
576 case TGSI_FILE_TEMPORARY
:
577 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
578 if (d
->Array
.ArrayID
) {
579 r600_add_gpr_array(ctx
->shader
,
580 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
582 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
587 case TGSI_FILE_CONSTANT
:
588 case TGSI_FILE_SAMPLER
:
589 case TGSI_FILE_ADDRESS
:
592 case TGSI_FILE_SYSTEM_VALUE
:
593 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
594 if (!ctx
->native_integers
) {
595 struct r600_bytecode_alu alu
;
596 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
598 alu
.op
= ALU_OP1_INT_TO_FLT
;
607 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
611 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
614 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
620 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
622 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
626 * for evergreen we need to scan the shader to find the number of GPRs we need to
627 * reserve for interpolation.
629 * we need to know if we are going to emit
630 * any centroid inputs
631 * if perspective and linear are required
633 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
638 ctx
->input_linear
= FALSE
;
639 ctx
->input_perspective
= FALSE
;
640 ctx
->input_centroid
= FALSE
;
641 ctx
->num_interp_gpr
= 1;
643 /* any centroid inputs */
644 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
645 /* skip position/face */
646 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
647 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
649 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
650 ctx
->input_linear
= TRUE
;
651 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
652 ctx
->input_perspective
= TRUE
;
653 if (ctx
->info
.input_centroid
[i
])
654 ctx
->input_centroid
= TRUE
;
658 /* ignoring sample for now */
659 if (ctx
->input_perspective
)
661 if (ctx
->input_linear
)
663 if (ctx
->input_centroid
)
666 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
668 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
669 return ctx
->num_interp_gpr
;
672 static void tgsi_src(struct r600_shader_ctx
*ctx
,
673 const struct tgsi_full_src_register
*tgsi_src
,
674 struct r600_shader_src
*r600_src
)
676 memset(r600_src
, 0, sizeof(*r600_src
));
677 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
678 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
679 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
680 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
681 r600_src
->neg
= tgsi_src
->Register
.Negate
;
682 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
684 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
686 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
687 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
688 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
690 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
691 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
692 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
695 index
= tgsi_src
->Register
.Index
;
696 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
697 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
698 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
699 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
700 r600_src
->swizzle
[0] = 3;
701 r600_src
->swizzle
[1] = 3;
702 r600_src
->swizzle
[2] = 3;
703 r600_src
->swizzle
[3] = 3;
705 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
706 r600_src
->swizzle
[0] = 0;
707 r600_src
->swizzle
[1] = 0;
708 r600_src
->swizzle
[2] = 0;
709 r600_src
->swizzle
[3] = 0;
713 if (tgsi_src
->Register
.Indirect
)
714 r600_src
->rel
= V_SQ_REL_RELATIVE
;
715 r600_src
->sel
= tgsi_src
->Register
.Index
;
716 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
718 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
719 if (tgsi_src
->Register
.Dimension
) {
720 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
725 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
727 struct r600_bytecode_vtx vtx
;
732 struct r600_bytecode_alu alu
;
734 memset(&alu
, 0, sizeof(alu
));
736 alu
.op
= ALU_OP2_ADD_INT
;
737 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
739 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
740 alu
.src
[1].value
= offset
;
742 alu
.dst
.sel
= dst_reg
;
746 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
751 ar_reg
= ctx
->bc
->ar_reg
;
754 memset(&vtx
, 0, sizeof(vtx
));
755 vtx
.buffer_id
= cb_idx
;
756 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
757 vtx
.src_gpr
= ar_reg
;
758 vtx
.mega_fetch_count
= 16;
759 vtx
.dst_gpr
= dst_reg
;
760 vtx
.dst_sel_x
= 0; /* SEL_X */
761 vtx
.dst_sel_y
= 1; /* SEL_Y */
762 vtx
.dst_sel_z
= 2; /* SEL_Z */
763 vtx
.dst_sel_w
= 3; /* SEL_W */
764 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
765 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
766 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
767 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
768 vtx
.endian
= r600_endian_swap(32);
770 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
776 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
778 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
779 struct r600_bytecode_alu alu
;
780 int i
, j
, k
, nconst
, r
;
782 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
783 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
786 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
788 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
789 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
793 if (ctx
->src
[i
].rel
) {
794 int treg
= r600_get_temp(ctx
);
795 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
798 ctx
->src
[i
].kc_bank
= 0;
799 ctx
->src
[i
].sel
= treg
;
803 int treg
= r600_get_temp(ctx
);
804 for (k
= 0; k
< 4; k
++) {
805 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
806 alu
.op
= ALU_OP1_MOV
;
807 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
809 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
815 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
819 ctx
->src
[i
].sel
= treg
;
827 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
828 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
830 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
831 struct r600_bytecode_alu alu
;
832 int i
, j
, k
, nliteral
, r
;
834 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
835 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
839 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
840 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
841 int treg
= r600_get_temp(ctx
);
842 for (k
= 0; k
< 4; k
++) {
843 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
844 alu
.op
= ALU_OP1_MOV
;
845 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
847 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
853 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
857 ctx
->src
[i
].sel
= treg
;
864 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
866 int i
, r
, count
= ctx
->shader
->ninput
;
868 for (i
= 0; i
< count
; i
++) {
869 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
870 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
879 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
880 struct r600_pipe_shader
*pipeshader
,
881 struct r600_shader_key key
)
883 struct r600_shader
*shader
= &pipeshader
->shader
;
884 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
885 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
886 struct tgsi_full_immediate
*immediate
;
887 struct tgsi_full_property
*property
;
888 struct r600_shader_ctx ctx
;
889 struct r600_bytecode_output output
[32];
890 unsigned output_done
, noutput
;
893 int next_pos_base
= 60, next_param_base
= 0;
894 int max_color_exports
= MAX2(key
.nr_cbufs
, 1);
895 /* Declarations used by llvm code */
896 bool use_llvm
= false;
900 use_llvm
= !(rscreen
->b
.debug_flags
& DBG_NO_LLVM
);
902 ctx
.bc
= &shader
->bc
;
904 ctx
.native_integers
= true;
906 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
907 rscreen
->has_compressed_msaa_texturing
);
909 tgsi_scan_shader(tokens
, &ctx
.info
);
910 shader
->indirect_files
= ctx
.info
.indirect_files
;
911 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
912 tgsi_parse_init(&ctx
.parse
, tokens
);
913 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
914 shader
->processor_type
= ctx
.type
;
915 ctx
.bc
->type
= shader
->processor_type
;
918 ctx
.fragcoord_input
= -1;
920 ctx
.clip_vertex_write
= 0;
922 shader
->nr_ps_color_exports
= 0;
923 shader
->nr_ps_max_color_exports
= 0;
925 shader
->two_side
= key
.color_two_side
;
927 /* register allocations */
928 /* Values [0,127] correspond to GPR[0..127].
929 * Values [128,159] correspond to constant buffer bank 0
930 * Values [160,191] correspond to constant buffer bank 1
931 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
932 * Values [256,287] correspond to constant buffer bank 2 (EG)
933 * Values [288,319] correspond to constant buffer bank 3 (EG)
934 * Other special values are shown in the list below.
935 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
936 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
937 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
938 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
939 * 248 SQ_ALU_SRC_0: special constant 0.0.
940 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
941 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
942 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
943 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
944 * 253 SQ_ALU_SRC_LITERAL: literal constant.
945 * 254 SQ_ALU_SRC_PV: previous vector result.
946 * 255 SQ_ALU_SRC_PS: previous scalar result.
948 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
949 ctx
.file_offset
[i
] = 0;
953 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
954 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
955 "indirect adressing. Falling back to TGSI "
960 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
961 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
963 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
966 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
967 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
969 ctx
.use_llvm
= use_llvm
;
972 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
973 ctx
.file_offset
[TGSI_FILE_INPUT
];
975 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
976 ctx
.file_offset
[TGSI_FILE_INPUT
] +
977 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
979 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
980 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
982 /* Outside the GPR range. This will be translated to one of the
983 * kcache banks later. */
984 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
986 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
987 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
988 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
989 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
992 shader
->max_arrays
= 0;
993 shader
->num_arrays
= 0;
995 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
996 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
997 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
998 ctx
.file_offset
[TGSI_FILE_INPUT
],
1001 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1002 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1003 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1004 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1010 ctx
.literals
= NULL
;
1011 shader
->fs_write_all
= FALSE
;
1012 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1013 tgsi_parse_token(&ctx
.parse
);
1014 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1015 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1016 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1017 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1018 if(ctx
.literals
== NULL
) {
1022 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1023 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1024 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1025 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1028 case TGSI_TOKEN_TYPE_DECLARATION
:
1029 r
= tgsi_declaration(&ctx
);
1033 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1035 case TGSI_TOKEN_TYPE_PROPERTY
:
1036 property
= &ctx
.parse
.FullToken
.FullProperty
;
1037 switch (property
->Property
.PropertyName
) {
1038 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1039 if (property
->u
[0].Data
== 1)
1040 shader
->fs_write_all
= TRUE
;
1042 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1043 /* we don't need this one */
1048 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1054 /* Process two side if needed */
1055 if (shader
->two_side
&& ctx
.colors_used
) {
1056 int i
, count
= ctx
.shader
->ninput
;
1057 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1059 /* additional inputs will be allocated right after the existing inputs,
1060 * we won't need them after the color selection, so we don't need to
1061 * reserve these gprs for the rest of the shader code and to adjust
1062 * output offsets etc. */
1063 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1064 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1066 if (ctx
.face_gpr
== -1) {
1067 i
= ctx
.shader
->ninput
++;
1068 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1069 ctx
.shader
->input
[i
].spi_sid
= 0;
1070 ctx
.shader
->input
[i
].gpr
= gpr
++;
1071 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1074 for (i
= 0; i
< count
; i
++) {
1075 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1076 int ni
= ctx
.shader
->ninput
++;
1077 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1078 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1079 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1080 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1081 // TGSI to LLVM needs to know the lds position of inputs.
1082 // Non LLVM path computes it later (in process_twoside_color)
1083 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1084 ctx
.shader
->input
[i
].back_color_input
= ni
;
1085 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1086 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1093 /* LLVM backend setup */
1094 #ifdef R600_USE_LLVM
1096 struct radeon_llvm_context radeon_llvm_ctx
;
1098 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
1099 boolean use_kill
= false;
1101 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1102 radeon_llvm_ctx
.type
= ctx
.type
;
1103 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1104 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1105 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1106 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1107 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
1108 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1109 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
1110 radeon_llvm_ctx
.stream_outputs
= &so
;
1111 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1112 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1113 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1114 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1115 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
1117 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
1118 radeon_llvm_dispose(&radeon_llvm_ctx
);
1120 fprintf(stderr
, "R600 LLVM backend failed to compile "
1121 "shader. Falling back to TGSI\n");
1123 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1124 ctx
.file_offset
[TGSI_FILE_INPUT
];
1127 ctx
.shader
->uses_kill
= use_kill
;
1128 radeon_llvm_dispose(&radeon_llvm_ctx
);
1131 /* End of LLVM backend setup */
1133 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
1134 shader
->nr_ps_max_color_exports
= 8;
1137 if (ctx
.fragcoord_input
>= 0) {
1138 if (ctx
.bc
->chip_class
== CAYMAN
) {
1139 for (j
= 0 ; j
< 4; j
++) {
1140 struct r600_bytecode_alu alu
;
1141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1142 alu
.op
= ALU_OP1_RECIP_IEEE
;
1143 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1144 alu
.src
[0].chan
= 3;
1146 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1148 alu
.dst
.write
= (j
== 3);
1150 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1154 struct r600_bytecode_alu alu
;
1155 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1156 alu
.op
= ALU_OP1_RECIP_IEEE
;
1157 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1158 alu
.src
[0].chan
= 3;
1160 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1164 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1169 if (shader
->two_side
&& ctx
.colors_used
) {
1170 if ((r
= process_twoside_color_inputs(&ctx
)))
1174 tgsi_parse_init(&ctx
.parse
, tokens
);
1175 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1176 tgsi_parse_token(&ctx
.parse
);
1177 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1178 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1179 r
= tgsi_is_supported(&ctx
);
1182 ctx
.max_driver_temp_used
= 0;
1183 /* reserve first tmp for everyone */
1184 r600_get_temp(&ctx
);
1186 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1187 if ((r
= tgsi_split_constant(&ctx
)))
1189 if ((r
= tgsi_split_literal_constant(&ctx
)))
1191 if (ctx
.bc
->chip_class
== CAYMAN
)
1192 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1193 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1194 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1196 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1197 r
= ctx
.inst_info
->process(&ctx
);
1207 /* Reset the temporary register counter. */
1208 ctx
.max_driver_temp_used
= 0;
1210 noutput
= shader
->noutput
;
1212 if (ctx
.clip_vertex_write
) {
1213 unsigned clipdist_temp
[2];
1215 clipdist_temp
[0] = r600_get_temp(&ctx
);
1216 clipdist_temp
[1] = r600_get_temp(&ctx
);
1218 /* need to convert a clipvertex write into clipdistance writes and not export
1219 the clip vertex anymore */
1221 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1222 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1223 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1225 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1226 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1229 /* reset spi_sid for clipvertex output to avoid confusing spi */
1230 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1232 shader
->clip_dist_write
= 0xFF;
1234 for (i
= 0; i
< 8; i
++) {
1238 for (j
= 0; j
< 4; j
++) {
1239 struct r600_bytecode_alu alu
;
1240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1241 alu
.op
= ALU_OP2_DOT4
;
1242 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1243 alu
.src
[0].chan
= j
;
1245 alu
.src
[1].sel
= 512 + i
;
1246 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1247 alu
.src
[1].chan
= j
;
1249 alu
.dst
.sel
= clipdist_temp
[oreg
];
1251 alu
.dst
.write
= (j
== ochan
);
1255 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1262 /* Add stream outputs. */
1263 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1264 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1266 /* Sanity checking. */
1267 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1268 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1272 for (i
= 0; i
< so
.num_outputs
; i
++) {
1273 if (so
.output
[i
].output_buffer
>= 4) {
1274 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1275 so
.output
[i
].output_buffer
);
1281 /* Initialize locations where the outputs are stored. */
1282 for (i
= 0; i
< so
.num_outputs
; i
++) {
1283 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1285 /* Lower outputs with dst_offset < start_component.
1287 * We can only output 4D vectors with a write mask, e.g. we can
1288 * only output the W component at offset 3, etc. If we want
1289 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1290 * to move it to X and output X. */
1291 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1292 unsigned tmp
= r600_get_temp(&ctx
);
1294 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1295 struct r600_bytecode_alu alu
;
1296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1297 alu
.op
= ALU_OP1_MOV
;
1298 alu
.src
[0].sel
= so_gpr
[i
];
1299 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1304 if (j
== so
.output
[i
].num_components
- 1)
1306 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1310 so
.output
[i
].start_component
= 0;
1315 /* Write outputs to buffers. */
1316 for (i
= 0; i
< so
.num_outputs
; i
++) {
1317 struct r600_bytecode_output output
;
1319 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1320 output
.gpr
= so_gpr
[i
];
1321 output
.elem_size
= so
.output
[i
].num_components
;
1322 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1323 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1324 output
.burst_count
= 1;
1326 /* array_size is an upper limit for the burst_count
1327 * with MEM_STREAM instructions */
1328 output
.array_size
= 0xFFF;
1329 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1330 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1331 switch (so
.output
[i
].output_buffer
) {
1333 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1336 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1339 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1342 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1346 switch (so
.output
[i
].output_buffer
) {
1348 output
.op
= CF_OP_MEM_STREAM0
;
1351 output
.op
= CF_OP_MEM_STREAM1
;
1354 output
.op
= CF_OP_MEM_STREAM2
;
1357 output
.op
= CF_OP_MEM_STREAM3
;
1361 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1368 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1369 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1370 output
[j
].gpr
= shader
->output
[i
].gpr
;
1371 output
[j
].elem_size
= 3;
1372 output
[j
].swizzle_x
= 0;
1373 output
[j
].swizzle_y
= 1;
1374 output
[j
].swizzle_z
= 2;
1375 output
[j
].swizzle_w
= 3;
1376 output
[j
].burst_count
= 1;
1377 output
[j
].barrier
= 1;
1378 output
[j
].type
= -1;
1379 output
[j
].op
= CF_OP_EXPORT
;
1381 case TGSI_PROCESSOR_VERTEX
:
1382 switch (shader
->output
[i
].name
) {
1383 case TGSI_SEMANTIC_POSITION
:
1384 output
[j
].array_base
= next_pos_base
++;
1385 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1388 case TGSI_SEMANTIC_PSIZE
:
1389 output
[j
].array_base
= next_pos_base
++;
1390 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1392 case TGSI_SEMANTIC_CLIPVERTEX
:
1395 case TGSI_SEMANTIC_CLIPDIST
:
1396 output
[j
].array_base
= next_pos_base
++;
1397 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1398 /* spi_sid is 0 for clipdistance outputs that were generated
1399 * for clipvertex - we don't need to pass them to PS */
1400 if (shader
->output
[i
].spi_sid
) {
1402 /* duplicate it as PARAM to pass to the pixel shader */
1403 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1404 output
[j
].array_base
= next_param_base
++;
1405 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1408 case TGSI_SEMANTIC_FOG
:
1409 output
[j
].swizzle_y
= 4; /* 0 */
1410 output
[j
].swizzle_z
= 4; /* 0 */
1411 output
[j
].swizzle_w
= 5; /* 1 */
1415 case TGSI_PROCESSOR_FRAGMENT
:
1416 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1417 /* never export more colors than the number of CBs */
1418 if (shader
->output
[i
].sid
>= max_color_exports
) {
1423 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1424 output
[j
].array_base
= shader
->output
[i
].sid
;
1425 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1426 shader
->nr_ps_color_exports
++;
1427 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
1428 for (k
= 1; k
< max_color_exports
; k
++) {
1430 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1431 output
[j
].gpr
= shader
->output
[i
].gpr
;
1432 output
[j
].elem_size
= 3;
1433 output
[j
].swizzle_x
= 0;
1434 output
[j
].swizzle_y
= 1;
1435 output
[j
].swizzle_z
= 2;
1436 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1437 output
[j
].burst_count
= 1;
1438 output
[j
].barrier
= 1;
1439 output
[j
].array_base
= k
;
1440 output
[j
].op
= CF_OP_EXPORT
;
1441 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1442 shader
->nr_ps_color_exports
++;
1445 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1446 output
[j
].array_base
= 61;
1447 output
[j
].swizzle_x
= 2;
1448 output
[j
].swizzle_y
= 7;
1449 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1450 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1451 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1452 output
[j
].array_base
= 61;
1453 output
[j
].swizzle_x
= 7;
1454 output
[j
].swizzle_y
= 1;
1455 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1456 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1458 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1464 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1469 if (output
[j
].type
==-1) {
1470 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1471 output
[j
].array_base
= next_param_base
++;
1475 /* add fake position export */
1476 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1477 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1479 output
[j
].elem_size
= 3;
1480 output
[j
].swizzle_x
= 7;
1481 output
[j
].swizzle_y
= 7;
1482 output
[j
].swizzle_z
= 7;
1483 output
[j
].swizzle_w
= 7;
1484 output
[j
].burst_count
= 1;
1485 output
[j
].barrier
= 1;
1486 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1487 output
[j
].array_base
= next_pos_base
;
1488 output
[j
].op
= CF_OP_EXPORT
;
1492 /* add fake param output for vertex shader if no param is exported */
1493 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1494 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1496 output
[j
].elem_size
= 3;
1497 output
[j
].swizzle_x
= 7;
1498 output
[j
].swizzle_y
= 7;
1499 output
[j
].swizzle_z
= 7;
1500 output
[j
].swizzle_w
= 7;
1501 output
[j
].burst_count
= 1;
1502 output
[j
].barrier
= 1;
1503 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1504 output
[j
].array_base
= 0;
1505 output
[j
].op
= CF_OP_EXPORT
;
1509 /* add fake pixel export */
1510 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
1511 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1513 output
[j
].elem_size
= 3;
1514 output
[j
].swizzle_x
= 7;
1515 output
[j
].swizzle_y
= 7;
1516 output
[j
].swizzle_z
= 7;
1517 output
[j
].swizzle_w
= 7;
1518 output
[j
].burst_count
= 1;
1519 output
[j
].barrier
= 1;
1520 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1521 output
[j
].array_base
= 0;
1522 output
[j
].op
= CF_OP_EXPORT
;
1528 /* set export done on last export of each type */
1529 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1530 if (ctx
.bc
->chip_class
< CAYMAN
) {
1531 if (i
== (noutput
- 1)) {
1532 output
[i
].end_of_program
= 1;
1535 if (!(output_done
& (1 << output
[i
].type
))) {
1536 output_done
|= (1 << output
[i
].type
);
1537 output
[i
].op
= CF_OP_EXPORT_DONE
;
1540 /* add output to bytecode */
1542 for (i
= 0; i
< noutput
; i
++) {
1543 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1548 /* add program end */
1549 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1550 cm_bytecode_add_cf_end(ctx
.bc
);
1552 /* check GPR limit - we have 124 = 128 - 4
1553 * (4 are reserved as alu clause temporary registers) */
1554 if (ctx
.bc
->ngpr
> 124) {
1555 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1561 tgsi_parse_free(&ctx
.parse
);
1565 tgsi_parse_free(&ctx
.parse
);
1569 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1571 R600_ERR("%s tgsi opcode unsupported\n",
1572 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1576 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1581 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1582 const struct r600_shader_src
*shader_src
,
1585 bc_src
->sel
= shader_src
->sel
;
1586 bc_src
->chan
= shader_src
->swizzle
[chan
];
1587 bc_src
->neg
= shader_src
->neg
;
1588 bc_src
->abs
= shader_src
->abs
;
1589 bc_src
->rel
= shader_src
->rel
;
1590 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1591 bc_src
->kc_bank
= shader_src
->kc_bank
;
1594 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1600 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1602 bc_src
->neg
= !bc_src
->neg
;
1605 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1606 const struct tgsi_full_dst_register
*tgsi_dst
,
1608 struct r600_bytecode_alu_dst
*r600_dst
)
1610 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1612 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1613 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1614 r600_dst
->chan
= swizzle
;
1615 r600_dst
->write
= 1;
1616 if (tgsi_dst
->Register
.Indirect
)
1617 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1618 if (inst
->Instruction
.Saturate
) {
1619 r600_dst
->clamp
= 1;
1623 static int tgsi_last_instruction(unsigned writemask
)
1627 for (i
= 0; i
< 4; i
++) {
1628 if (writemask
& (1 << i
)) {
1635 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1637 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1638 struct r600_bytecode_alu alu
;
1640 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1642 for (i
= 0; i
< lasti
+ 1; i
++) {
1643 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1646 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1647 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1649 alu
.op
= ctx
->inst_info
->op
;
1651 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1652 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
1655 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
1656 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1658 /* handle some special cases */
1659 switch (ctx
->inst_info
->tgsi_opcode
) {
1660 case TGSI_OPCODE_SUB
:
1661 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
1663 case TGSI_OPCODE_ABS
:
1664 r600_bytecode_src_set_abs(&alu
.src
[0]);
1669 if (i
== lasti
|| trans_only
) {
1672 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1679 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
1681 return tgsi_op2_s(ctx
, 0, 0);
1684 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
1686 return tgsi_op2_s(ctx
, 1, 0);
1689 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
1691 return tgsi_op2_s(ctx
, 0, 1);
1694 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
1696 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1697 struct r600_bytecode_alu alu
;
1699 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1701 for (i
= 0; i
< lasti
+ 1; i
++) {
1703 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1706 alu
.op
= ctx
->inst_info
->op
;
1708 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1710 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1712 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1725 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
1727 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1729 struct r600_bytecode_alu alu
;
1730 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1732 for (i
= 0 ; i
< last_slot
; i
++) {
1733 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1734 alu
.op
= ctx
->inst_info
->op
;
1735 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1736 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
1738 /* RSQ should take the absolute value of src */
1739 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
1740 r600_bytecode_src_set_abs(&alu
.src
[j
]);
1743 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1744 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1746 if (i
== last_slot
- 1)
1748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1755 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
1757 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1759 struct r600_bytecode_alu alu
;
1760 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1761 for (k
= 0; k
< last_slot
; k
++) {
1762 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
1765 for (i
= 0 ; i
< 4; i
++) {
1766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1767 alu
.op
= ctx
->inst_info
->op
;
1768 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1769 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
1771 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1772 alu
.dst
.write
= (i
== k
);
1775 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1784 * r600 - trunc to -PI..PI range
1785 * r700 - normalize by dividing by 2PI
1788 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
1790 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
1791 static float double_pi
= 3.1415926535 * 2;
1792 static float neg_pi
= -3.1415926535;
1795 struct r600_bytecode_alu alu
;
1797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1798 alu
.op
= ALU_OP3_MULADD
;
1802 alu
.dst
.sel
= ctx
->temp_reg
;
1805 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
1807 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1808 alu
.src
[1].chan
= 0;
1809 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
1810 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1811 alu
.src
[2].chan
= 0;
1813 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1817 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1818 alu
.op
= ALU_OP1_FRACT
;
1821 alu
.dst
.sel
= ctx
->temp_reg
;
1824 alu
.src
[0].sel
= ctx
->temp_reg
;
1825 alu
.src
[0].chan
= 0;
1827 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1832 alu
.op
= ALU_OP3_MULADD
;
1836 alu
.dst
.sel
= ctx
->temp_reg
;
1839 alu
.src
[0].sel
= ctx
->temp_reg
;
1840 alu
.src
[0].chan
= 0;
1842 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1843 alu
.src
[1].chan
= 0;
1844 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
1845 alu
.src
[2].chan
= 0;
1847 if (ctx
->bc
->chip_class
== R600
) {
1848 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
1849 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
1851 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
1852 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1857 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1863 static int cayman_trig(struct r600_shader_ctx
*ctx
)
1865 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1866 struct r600_bytecode_alu alu
;
1867 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1870 r
= tgsi_setup_trig(ctx
);
1875 for (i
= 0; i
< last_slot
; i
++) {
1876 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1877 alu
.op
= ctx
->inst_info
->op
;
1880 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1881 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1883 alu
.src
[0].sel
= ctx
->temp_reg
;
1884 alu
.src
[0].chan
= 0;
1885 if (i
== last_slot
- 1)
1887 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1894 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
1896 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1897 struct r600_bytecode_alu alu
;
1899 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1901 r
= tgsi_setup_trig(ctx
);
1905 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1906 alu
.op
= ctx
->inst_info
->op
;
1908 alu
.dst
.sel
= ctx
->temp_reg
;
1911 alu
.src
[0].sel
= ctx
->temp_reg
;
1912 alu
.src
[0].chan
= 0;
1914 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1918 /* replicate result */
1919 for (i
= 0; i
< lasti
+ 1; i
++) {
1920 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1923 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1924 alu
.op
= ALU_OP1_MOV
;
1926 alu
.src
[0].sel
= ctx
->temp_reg
;
1927 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1930 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1937 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
1939 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1940 struct r600_bytecode_alu alu
;
1943 /* We'll only need the trig stuff if we are going to write to the
1944 * X or Y components of the destination vector.
1946 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
1947 r
= tgsi_setup_trig(ctx
);
1953 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
1954 if (ctx
->bc
->chip_class
== CAYMAN
) {
1955 for (i
= 0 ; i
< 3; i
++) {
1956 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1957 alu
.op
= ALU_OP1_COS
;
1958 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1964 alu
.src
[0].sel
= ctx
->temp_reg
;
1965 alu
.src
[0].chan
= 0;
1968 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1974 alu
.op
= ALU_OP1_COS
;
1975 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
1977 alu
.src
[0].sel
= ctx
->temp_reg
;
1978 alu
.src
[0].chan
= 0;
1980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1987 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
1988 if (ctx
->bc
->chip_class
== CAYMAN
) {
1989 for (i
= 0 ; i
< 3; i
++) {
1990 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1991 alu
.op
= ALU_OP1_SIN
;
1992 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1997 alu
.src
[0].sel
= ctx
->temp_reg
;
1998 alu
.src
[0].chan
= 0;
2001 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2006 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2007 alu
.op
= ALU_OP1_SIN
;
2008 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2010 alu
.src
[0].sel
= ctx
->temp_reg
;
2011 alu
.src
[0].chan
= 0;
2013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2020 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2021 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2023 alu
.op
= ALU_OP1_MOV
;
2025 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2027 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2028 alu
.src
[0].chan
= 0;
2032 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2038 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2041 alu
.op
= ALU_OP1_MOV
;
2043 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2045 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2046 alu
.src
[0].chan
= 0;
2050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2058 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2060 struct r600_bytecode_alu alu
;
2063 for (i
= 0; i
< 4; i
++) {
2064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2065 alu
.op
= ctx
->inst_info
->op
;
2069 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2071 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILL
) {
2072 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2075 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2080 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2085 /* kill must be last in ALU */
2086 ctx
->bc
->force_add_cf
= 1;
2087 ctx
->shader
->uses_kill
= TRUE
;
2091 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2093 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2094 struct r600_bytecode_alu alu
;
2097 /* tmp.x = max(src.y, 0.0) */
2098 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2099 alu
.op
= ALU_OP2_MAX
;
2100 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2101 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2102 alu
.src
[1].chan
= 1;
2104 alu
.dst
.sel
= ctx
->temp_reg
;
2109 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2113 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2119 if (ctx
->bc
->chip_class
== CAYMAN
) {
2120 for (i
= 0; i
< 3; i
++) {
2121 /* tmp.z = log(tmp.x) */
2122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2123 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2124 alu
.src
[0].sel
= ctx
->temp_reg
;
2125 alu
.src
[0].chan
= 0;
2126 alu
.dst
.sel
= ctx
->temp_reg
;
2134 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2139 /* tmp.z = log(tmp.x) */
2140 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2141 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2142 alu
.src
[0].sel
= ctx
->temp_reg
;
2143 alu
.src
[0].chan
= 0;
2144 alu
.dst
.sel
= ctx
->temp_reg
;
2148 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2153 chan
= alu
.dst
.chan
;
2156 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2157 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2158 alu
.op
= ALU_OP3_MUL_LIT
;
2159 alu
.src
[0].sel
= sel
;
2160 alu
.src
[0].chan
= chan
;
2161 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2162 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2163 alu
.dst
.sel
= ctx
->temp_reg
;
2168 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2172 if (ctx
->bc
->chip_class
== CAYMAN
) {
2173 for (i
= 0; i
< 3; i
++) {
2174 /* dst.z = exp(tmp.x) */
2175 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2176 alu
.op
= ALU_OP1_EXP_IEEE
;
2177 alu
.src
[0].sel
= ctx
->temp_reg
;
2178 alu
.src
[0].chan
= 0;
2179 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2185 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2190 /* dst.z = exp(tmp.x) */
2191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2192 alu
.op
= ALU_OP1_EXP_IEEE
;
2193 alu
.src
[0].sel
= ctx
->temp_reg
;
2194 alu
.src
[0].chan
= 0;
2195 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2197 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2204 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2205 alu
.op
= ALU_OP1_MOV
;
2206 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2207 alu
.src
[0].chan
= 0;
2208 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2209 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2210 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2214 /* dst.y = max(src.x, 0.0) */
2215 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2216 alu
.op
= ALU_OP2_MAX
;
2217 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2218 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2219 alu
.src
[1].chan
= 0;
2220 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2221 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2227 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2228 alu
.op
= ALU_OP1_MOV
;
2229 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2230 alu
.src
[0].chan
= 0;
2231 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2232 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2234 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2241 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2243 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2244 struct r600_bytecode_alu alu
;
2247 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2250 * For state trackers other than OpenGL, we'll want to use
2251 * _RECIPSQRT_IEEE instead.
2253 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2255 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2256 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2257 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2259 alu
.dst
.sel
= ctx
->temp_reg
;
2262 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2265 /* replicate result */
2266 return tgsi_helper_tempx_replicate(ctx
);
2269 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2271 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2272 struct r600_bytecode_alu alu
;
2275 for (i
= 0; i
< 4; i
++) {
2276 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2277 alu
.src
[0].sel
= ctx
->temp_reg
;
2278 alu
.op
= ALU_OP1_MOV
;
2280 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2281 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2291 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2293 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2294 struct r600_bytecode_alu alu
;
2297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2298 alu
.op
= ctx
->inst_info
->op
;
2299 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2300 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2302 alu
.dst
.sel
= ctx
->temp_reg
;
2305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2308 /* replicate result */
2309 return tgsi_helper_tempx_replicate(ctx
);
2312 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2314 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2316 struct r600_bytecode_alu alu
;
2317 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2319 for (i
= 0; i
< 3; i
++) {
2320 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2321 alu
.op
= ALU_OP1_LOG_IEEE
;
2322 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2323 alu
.dst
.sel
= ctx
->temp_reg
;
2328 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2335 alu
.op
= ALU_OP2_MUL
;
2336 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2337 alu
.src
[1].sel
= ctx
->temp_reg
;
2338 alu
.dst
.sel
= ctx
->temp_reg
;
2341 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2345 for (i
= 0; i
< last_slot
; i
++) {
2346 /* POW(a,b) = EXP2(b * LOG2(a))*/
2347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2348 alu
.op
= ALU_OP1_EXP_IEEE
;
2349 alu
.src
[0].sel
= ctx
->temp_reg
;
2351 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2352 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2353 if (i
== last_slot
- 1)
2355 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2362 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2364 struct r600_bytecode_alu alu
;
2368 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2369 alu
.op
= ALU_OP1_LOG_IEEE
;
2370 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2371 alu
.dst
.sel
= ctx
->temp_reg
;
2374 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2378 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2379 alu
.op
= ALU_OP2_MUL
;
2380 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2381 alu
.src
[1].sel
= ctx
->temp_reg
;
2382 alu
.dst
.sel
= ctx
->temp_reg
;
2385 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2388 /* POW(a,b) = EXP2(b * LOG2(a))*/
2389 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2390 alu
.op
= ALU_OP1_EXP_IEEE
;
2391 alu
.src
[0].sel
= ctx
->temp_reg
;
2392 alu
.dst
.sel
= ctx
->temp_reg
;
2395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2398 return tgsi_helper_tempx_replicate(ctx
);
2401 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2403 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2404 struct r600_bytecode_alu alu
;
2406 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2407 int tmp0
= ctx
->temp_reg
;
2408 int tmp1
= r600_get_temp(ctx
);
2409 int tmp2
= r600_get_temp(ctx
);
2410 int tmp3
= r600_get_temp(ctx
);
2413 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2415 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2416 * 2. tmp0.z = lo (tmp0.x * src2)
2417 * 3. tmp0.w = -tmp0.z
2418 * 4. tmp0.y = hi (tmp0.x * src2)
2419 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2420 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2421 * 7. tmp1.x = tmp0.x - tmp0.w
2422 * 8. tmp1.y = tmp0.x + tmp0.w
2423 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2424 * 10. tmp0.z = hi(tmp0.x * src1) = q
2425 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2427 * 12. tmp0.w = src1 - tmp0.y = r
2428 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2429 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2433 * 15. tmp1.z = tmp0.z + 1 = q + 1
2434 * 16. tmp1.w = tmp0.z - 1 = q - 1
2438 * 15. tmp1.z = tmp0.w - src2 = r - src2
2439 * 16. tmp1.w = tmp0.w + src2 = r + src2
2443 * 17. tmp1.x = tmp1.x & tmp1.y
2445 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2446 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2448 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2449 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2453 * Same as unsigned, using abs values of the operands,
2454 * and fixing the sign of the result in the end.
2457 for (i
= 0; i
< 4; i
++) {
2458 if (!(write_mask
& (1<<i
)))
2463 /* tmp2.x = -src0 */
2464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2465 alu
.op
= ALU_OP2_SUB_INT
;
2471 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2473 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2476 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2479 /* tmp2.y = -src1 */
2480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2481 alu
.op
= ALU_OP2_SUB_INT
;
2487 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2489 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2492 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2495 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2496 /* it will be a sign of the quotient */
2499 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2500 alu
.op
= ALU_OP2_XOR_INT
;
2506 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2507 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2510 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2514 /* tmp2.x = |src0| */
2515 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2516 alu
.op
= ALU_OP3_CNDGE_INT
;
2523 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2524 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2525 alu
.src
[2].sel
= tmp2
;
2526 alu
.src
[2].chan
= 0;
2529 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2532 /* tmp2.y = |src1| */
2533 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2534 alu
.op
= ALU_OP3_CNDGE_INT
;
2541 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2542 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2543 alu
.src
[2].sel
= tmp2
;
2544 alu
.src
[2].chan
= 1;
2547 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2552 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2553 if (ctx
->bc
->chip_class
== CAYMAN
) {
2554 /* tmp3.x = u2f(src2) */
2555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2556 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2563 alu
.src
[0].sel
= tmp2
;
2564 alu
.src
[0].chan
= 1;
2566 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2570 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2573 /* tmp0.x = recip(tmp3.x) */
2574 for (j
= 0 ; j
< 3; j
++) {
2575 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2576 alu
.op
= ALU_OP1_RECIP_IEEE
;
2580 alu
.dst
.write
= (j
== 0);
2582 alu
.src
[0].sel
= tmp3
;
2583 alu
.src
[0].chan
= 0;
2587 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2591 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2592 alu
.op
= ALU_OP2_MUL
;
2594 alu
.src
[0].sel
= tmp0
;
2595 alu
.src
[0].chan
= 0;
2597 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2598 alu
.src
[1].value
= 0x4f800000;
2603 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2607 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2608 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2614 alu
.src
[0].sel
= tmp3
;
2615 alu
.src
[0].chan
= 0;
2618 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2622 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2623 alu
.op
= ALU_OP1_RECIP_UINT
;
2630 alu
.src
[0].sel
= tmp2
;
2631 alu
.src
[0].chan
= 1;
2633 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2637 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2641 /* 2. tmp0.z = lo (tmp0.x * src2) */
2642 if (ctx
->bc
->chip_class
== CAYMAN
) {
2643 for (j
= 0 ; j
< 4; j
++) {
2644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2645 alu
.op
= ALU_OP2_MULLO_UINT
;
2649 alu
.dst
.write
= (j
== 2);
2651 alu
.src
[0].sel
= tmp0
;
2652 alu
.src
[0].chan
= 0;
2654 alu
.src
[1].sel
= tmp2
;
2655 alu
.src
[1].chan
= 1;
2657 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2660 alu
.last
= (j
== 3);
2661 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2665 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2666 alu
.op
= ALU_OP2_MULLO_UINT
;
2672 alu
.src
[0].sel
= tmp0
;
2673 alu
.src
[0].chan
= 0;
2675 alu
.src
[1].sel
= tmp2
;
2676 alu
.src
[1].chan
= 1;
2678 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2682 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2686 /* 3. tmp0.w = -tmp0.z */
2687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2688 alu
.op
= ALU_OP2_SUB_INT
;
2694 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2695 alu
.src
[1].sel
= tmp0
;
2696 alu
.src
[1].chan
= 2;
2699 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2702 /* 4. tmp0.y = hi (tmp0.x * src2) */
2703 if (ctx
->bc
->chip_class
== CAYMAN
) {
2704 for (j
= 0 ; j
< 4; j
++) {
2705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2706 alu
.op
= ALU_OP2_MULHI_UINT
;
2710 alu
.dst
.write
= (j
== 1);
2712 alu
.src
[0].sel
= tmp0
;
2713 alu
.src
[0].chan
= 0;
2716 alu
.src
[1].sel
= tmp2
;
2717 alu
.src
[1].chan
= 1;
2719 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2721 alu
.last
= (j
== 3);
2722 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2726 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2727 alu
.op
= ALU_OP2_MULHI_UINT
;
2733 alu
.src
[0].sel
= tmp0
;
2734 alu
.src
[0].chan
= 0;
2737 alu
.src
[1].sel
= tmp2
;
2738 alu
.src
[1].chan
= 1;
2740 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2744 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2748 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
2749 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2750 alu
.op
= ALU_OP3_CNDE_INT
;
2757 alu
.src
[0].sel
= tmp0
;
2758 alu
.src
[0].chan
= 1;
2759 alu
.src
[1].sel
= tmp0
;
2760 alu
.src
[1].chan
= 3;
2761 alu
.src
[2].sel
= tmp0
;
2762 alu
.src
[2].chan
= 2;
2765 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2768 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
2769 if (ctx
->bc
->chip_class
== CAYMAN
) {
2770 for (j
= 0 ; j
< 4; j
++) {
2771 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2772 alu
.op
= ALU_OP2_MULHI_UINT
;
2776 alu
.dst
.write
= (j
== 3);
2778 alu
.src
[0].sel
= tmp0
;
2779 alu
.src
[0].chan
= 2;
2781 alu
.src
[1].sel
= tmp0
;
2782 alu
.src
[1].chan
= 0;
2784 alu
.last
= (j
== 3);
2785 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2789 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2790 alu
.op
= ALU_OP2_MULHI_UINT
;
2796 alu
.src
[0].sel
= tmp0
;
2797 alu
.src
[0].chan
= 2;
2799 alu
.src
[1].sel
= tmp0
;
2800 alu
.src
[1].chan
= 0;
2803 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2807 /* 7. tmp1.x = tmp0.x - tmp0.w */
2808 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2809 alu
.op
= ALU_OP2_SUB_INT
;
2815 alu
.src
[0].sel
= tmp0
;
2816 alu
.src
[0].chan
= 0;
2817 alu
.src
[1].sel
= tmp0
;
2818 alu
.src
[1].chan
= 3;
2821 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2824 /* 8. tmp1.y = tmp0.x + tmp0.w */
2825 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2826 alu
.op
= ALU_OP2_ADD_INT
;
2832 alu
.src
[0].sel
= tmp0
;
2833 alu
.src
[0].chan
= 0;
2834 alu
.src
[1].sel
= tmp0
;
2835 alu
.src
[1].chan
= 3;
2838 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2841 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
2842 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2843 alu
.op
= ALU_OP3_CNDE_INT
;
2850 alu
.src
[0].sel
= tmp0
;
2851 alu
.src
[0].chan
= 1;
2852 alu
.src
[1].sel
= tmp1
;
2853 alu
.src
[1].chan
= 1;
2854 alu
.src
[2].sel
= tmp1
;
2855 alu
.src
[2].chan
= 0;
2858 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2861 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
2862 if (ctx
->bc
->chip_class
== CAYMAN
) {
2863 for (j
= 0 ; j
< 4; j
++) {
2864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2865 alu
.op
= ALU_OP2_MULHI_UINT
;
2869 alu
.dst
.write
= (j
== 2);
2871 alu
.src
[0].sel
= tmp0
;
2872 alu
.src
[0].chan
= 0;
2875 alu
.src
[1].sel
= tmp2
;
2876 alu
.src
[1].chan
= 0;
2878 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2881 alu
.last
= (j
== 3);
2882 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2886 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2887 alu
.op
= ALU_OP2_MULHI_UINT
;
2893 alu
.src
[0].sel
= tmp0
;
2894 alu
.src
[0].chan
= 0;
2897 alu
.src
[1].sel
= tmp2
;
2898 alu
.src
[1].chan
= 0;
2900 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2904 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2908 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
2909 if (ctx
->bc
->chip_class
== CAYMAN
) {
2910 for (j
= 0 ; j
< 4; j
++) {
2911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2912 alu
.op
= ALU_OP2_MULLO_UINT
;
2916 alu
.dst
.write
= (j
== 1);
2919 alu
.src
[0].sel
= tmp2
;
2920 alu
.src
[0].chan
= 1;
2922 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2925 alu
.src
[1].sel
= tmp0
;
2926 alu
.src
[1].chan
= 2;
2928 alu
.last
= (j
== 3);
2929 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2934 alu
.op
= ALU_OP2_MULLO_UINT
;
2941 alu
.src
[0].sel
= tmp2
;
2942 alu
.src
[0].chan
= 1;
2944 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2947 alu
.src
[1].sel
= tmp0
;
2948 alu
.src
[1].chan
= 2;
2951 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2955 /* 12. tmp0.w = src1 - tmp0.y = r */
2956 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2957 alu
.op
= ALU_OP2_SUB_INT
;
2964 alu
.src
[0].sel
= tmp2
;
2965 alu
.src
[0].chan
= 0;
2967 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2970 alu
.src
[1].sel
= tmp0
;
2971 alu
.src
[1].chan
= 1;
2974 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2977 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
2978 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2979 alu
.op
= ALU_OP2_SETGE_UINT
;
2985 alu
.src
[0].sel
= tmp0
;
2986 alu
.src
[0].chan
= 3;
2988 alu
.src
[1].sel
= tmp2
;
2989 alu
.src
[1].chan
= 1;
2991 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2995 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2998 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
2999 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3000 alu
.op
= ALU_OP2_SETGE_UINT
;
3007 alu
.src
[0].sel
= tmp2
;
3008 alu
.src
[0].chan
= 0;
3010 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3013 alu
.src
[1].sel
= tmp0
;
3014 alu
.src
[1].chan
= 1;
3017 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3020 if (mod
) { /* UMOD */
3022 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3023 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3024 alu
.op
= ALU_OP2_SUB_INT
;
3030 alu
.src
[0].sel
= tmp0
;
3031 alu
.src
[0].chan
= 3;
3034 alu
.src
[1].sel
= tmp2
;
3035 alu
.src
[1].chan
= 1;
3037 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3041 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3044 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3046 alu
.op
= ALU_OP2_ADD_INT
;
3052 alu
.src
[0].sel
= tmp0
;
3053 alu
.src
[0].chan
= 3;
3055 alu
.src
[1].sel
= tmp2
;
3056 alu
.src
[1].chan
= 1;
3058 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3062 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3067 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3068 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3069 alu
.op
= ALU_OP2_ADD_INT
;
3075 alu
.src
[0].sel
= tmp0
;
3076 alu
.src
[0].chan
= 2;
3077 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3080 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3083 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3084 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3085 alu
.op
= ALU_OP2_ADD_INT
;
3091 alu
.src
[0].sel
= tmp0
;
3092 alu
.src
[0].chan
= 2;
3093 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3096 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3101 /* 17. tmp1.x = tmp1.x & tmp1.y */
3102 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3103 alu
.op
= ALU_OP2_AND_INT
;
3109 alu
.src
[0].sel
= tmp1
;
3110 alu
.src
[0].chan
= 0;
3111 alu
.src
[1].sel
= tmp1
;
3112 alu
.src
[1].chan
= 1;
3115 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3118 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3119 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3121 alu
.op
= ALU_OP3_CNDE_INT
;
3128 alu
.src
[0].sel
= tmp1
;
3129 alu
.src
[0].chan
= 0;
3130 alu
.src
[1].sel
= tmp0
;
3131 alu
.src
[1].chan
= mod
? 3 : 2;
3132 alu
.src
[2].sel
= tmp1
;
3133 alu
.src
[2].chan
= 2;
3136 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3139 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3140 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3141 alu
.op
= ALU_OP3_CNDE_INT
;
3149 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3152 alu
.src
[0].sel
= tmp1
;
3153 alu
.src
[0].chan
= 1;
3154 alu
.src
[1].sel
= tmp1
;
3155 alu
.src
[1].chan
= 3;
3156 alu
.src
[2].sel
= tmp0
;
3157 alu
.src
[2].chan
= 2;
3160 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3165 /* fix the sign of the result */
3169 /* tmp0.x = -tmp0.z */
3170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3171 alu
.op
= ALU_OP2_SUB_INT
;
3177 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3178 alu
.src
[1].sel
= tmp0
;
3179 alu
.src
[1].chan
= 2;
3182 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3185 /* sign of the remainder is the same as the sign of src0 */
3186 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3188 alu
.op
= ALU_OP3_CNDGE_INT
;
3191 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3193 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3194 alu
.src
[1].sel
= tmp0
;
3195 alu
.src
[1].chan
= 2;
3196 alu
.src
[2].sel
= tmp0
;
3197 alu
.src
[2].chan
= 0;
3200 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3205 /* tmp0.x = -tmp0.z */
3206 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3207 alu
.op
= ALU_OP2_SUB_INT
;
3213 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3214 alu
.src
[1].sel
= tmp0
;
3215 alu
.src
[1].chan
= 2;
3218 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3221 /* fix the quotient sign (same as the sign of src0*src1) */
3222 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3224 alu
.op
= ALU_OP3_CNDGE_INT
;
3227 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3229 alu
.src
[0].sel
= tmp2
;
3230 alu
.src
[0].chan
= 2;
3231 alu
.src
[1].sel
= tmp0
;
3232 alu
.src
[1].chan
= 2;
3233 alu
.src
[2].sel
= tmp0
;
3234 alu
.src
[2].chan
= 0;
3237 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3245 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3247 return tgsi_divmod(ctx
, 0, 0);
3250 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3252 return tgsi_divmod(ctx
, 1, 0);
3255 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3257 return tgsi_divmod(ctx
, 0, 1);
3260 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3262 return tgsi_divmod(ctx
, 1, 1);
3266 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3268 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3269 struct r600_bytecode_alu alu
;
3271 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3272 int last_inst
= tgsi_last_instruction(write_mask
);
3274 for (i
= 0; i
< 4; i
++) {
3275 if (!(write_mask
& (1<<i
)))
3278 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3279 alu
.op
= ALU_OP1_TRUNC
;
3281 alu
.dst
.sel
= ctx
->temp_reg
;
3285 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3293 for (i
= 0; i
< 4; i
++) {
3294 if (!(write_mask
& (1<<i
)))
3297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3298 alu
.op
= ctx
->inst_info
->op
;
3300 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3302 alu
.src
[0].sel
= ctx
->temp_reg
;
3303 alu
.src
[0].chan
= i
;
3305 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3307 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3315 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3317 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3318 struct r600_bytecode_alu alu
;
3320 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3321 int last_inst
= tgsi_last_instruction(write_mask
);
3324 for (i
= 0; i
< 4; i
++) {
3325 if (!(write_mask
& (1<<i
)))
3328 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3329 alu
.op
= ALU_OP2_SUB_INT
;
3331 alu
.dst
.sel
= ctx
->temp_reg
;
3335 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3336 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3340 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3345 /* dst = (src >= 0 ? src : tmp) */
3346 for (i
= 0; i
< 4; i
++) {
3347 if (!(write_mask
& (1<<i
)))
3350 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3351 alu
.op
= ALU_OP3_CNDGE_INT
;
3355 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3357 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3358 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3359 alu
.src
[2].sel
= ctx
->temp_reg
;
3360 alu
.src
[2].chan
= i
;
3364 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3371 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3373 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3374 struct r600_bytecode_alu alu
;
3376 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3377 int last_inst
= tgsi_last_instruction(write_mask
);
3379 /* tmp = (src >= 0 ? src : -1) */
3380 for (i
= 0; i
< 4; i
++) {
3381 if (!(write_mask
& (1<<i
)))
3384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3385 alu
.op
= ALU_OP3_CNDGE_INT
;
3388 alu
.dst
.sel
= ctx
->temp_reg
;
3392 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3393 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3394 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3403 /* dst = (tmp > 0 ? 1 : tmp) */
3404 for (i
= 0; i
< 4; i
++) {
3405 if (!(write_mask
& (1<<i
)))
3408 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3409 alu
.op
= ALU_OP3_CNDGT_INT
;
3413 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3415 alu
.src
[0].sel
= ctx
->temp_reg
;
3416 alu
.src
[0].chan
= i
;
3418 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3420 alu
.src
[2].sel
= ctx
->temp_reg
;
3421 alu
.src
[2].chan
= i
;
3425 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3434 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3436 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3437 struct r600_bytecode_alu alu
;
3440 /* tmp = (src > 0 ? 1 : src) */
3441 for (i
= 0; i
< 4; i
++) {
3442 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3443 alu
.op
= ALU_OP3_CNDGT
;
3446 alu
.dst
.sel
= ctx
->temp_reg
;
3449 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3450 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3451 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3455 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3460 /* dst = (-tmp > 0 ? -1 : tmp) */
3461 for (i
= 0; i
< 4; i
++) {
3462 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3463 alu
.op
= ALU_OP3_CNDGT
;
3465 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3467 alu
.src
[0].sel
= ctx
->temp_reg
;
3468 alu
.src
[0].chan
= i
;
3471 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3474 alu
.src
[2].sel
= ctx
->temp_reg
;
3475 alu
.src
[2].chan
= i
;
3479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3486 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3488 struct r600_bytecode_alu alu
;
3491 for (i
= 0; i
< 4; i
++) {
3492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3493 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3494 alu
.op
= ALU_OP0_NOP
;
3497 alu
.op
= ALU_OP1_MOV
;
3498 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3499 alu
.src
[0].sel
= ctx
->temp_reg
;
3500 alu
.src
[0].chan
= i
;
3505 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3512 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3514 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3515 struct r600_bytecode_alu alu
;
3517 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3519 for (i
= 0; i
< lasti
+ 1; i
++) {
3520 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3523 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3524 alu
.op
= ctx
->inst_info
->op
;
3525 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3526 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3529 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3536 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3543 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3545 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3546 struct r600_bytecode_alu alu
;
3549 for (i
= 0; i
< 4; i
++) {
3550 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3551 alu
.op
= ctx
->inst_info
->op
;
3552 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3553 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3556 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3558 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3559 /* handle some special cases */
3560 switch (ctx
->inst_info
->tgsi_opcode
) {
3561 case TGSI_OPCODE_DP2
:
3563 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3564 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3567 case TGSI_OPCODE_DP3
:
3569 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3570 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3573 case TGSI_OPCODE_DPH
:
3575 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3576 alu
.src
[0].chan
= 0;
3586 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3593 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3596 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3597 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3598 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3599 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3600 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3603 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3606 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3607 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3610 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3612 struct r600_bytecode_vtx vtx
;
3613 struct r600_bytecode_alu alu
;
3614 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3616 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3618 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3619 if (src_requires_loading
) {
3620 for (i
= 0; i
< 4; i
++) {
3621 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3622 alu
.op
= ALU_OP1_MOV
;
3623 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3624 alu
.dst
.sel
= ctx
->temp_reg
;
3629 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3633 src_gpr
= ctx
->temp_reg
;
3636 memset(&vtx
, 0, sizeof(vtx
));
3637 vtx
.op
= FETCH_OP_VFETCH
;
3638 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3639 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3640 vtx
.src_gpr
= src_gpr
;
3641 vtx
.mega_fetch_count
= 16;
3642 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3643 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3644 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3645 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
3646 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
3647 vtx
.use_const_fields
= 1;
3648 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
3650 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
3653 if (ctx
->bc
->chip_class
>= EVERGREEN
)
3656 for (i
= 0; i
< 4; i
++) {
3657 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3658 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3661 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3662 alu
.op
= ALU_OP2_AND_INT
;
3665 alu
.dst
.sel
= vtx
.dst_gpr
;
3668 alu
.src
[0].sel
= vtx
.dst_gpr
;
3669 alu
.src
[0].chan
= i
;
3671 alu
.src
[1].sel
= 512 + (id
* 2);
3672 alu
.src
[1].chan
= i
% 4;
3673 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3677 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3682 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
3683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3684 alu
.op
= ALU_OP2_OR_INT
;
3687 alu
.dst
.sel
= vtx
.dst_gpr
;
3690 alu
.src
[0].sel
= vtx
.dst_gpr
;
3691 alu
.src
[0].chan
= 3;
3693 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
3694 alu
.src
[1].chan
= 0;
3695 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3698 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3705 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
3707 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3708 struct r600_bytecode_alu alu
;
3710 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3712 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3713 alu
.op
= ALU_OP1_MOV
;
3715 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
3716 alu
.src
[0].sel
= 512 + (id
/ 4);
3717 alu
.src
[0].chan
= id
% 4;
3719 /* r600 we have them at channel 2 of the second dword */
3720 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
3721 alu
.src
[0].chan
= 1;
3723 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3724 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3732 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
3734 static float one_point_five
= 1.5f
;
3735 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3736 struct r600_bytecode_tex tex
;
3737 struct r600_bytecode_alu alu
;
3741 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
3742 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
3743 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
3744 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
3746 /* Texture fetch instructions can only use gprs as source.
3747 * Also they cannot negate the source or take the absolute value */
3748 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
3749 tgsi_tex_src_requires_loading(ctx
, 0)) ||
3750 read_compressed_msaa
;
3751 boolean src_loaded
= FALSE
;
3752 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
3753 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
3754 boolean has_txq_cube_array_z
= false;
3756 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
3757 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3758 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
3759 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
3760 ctx
->shader
->has_txq_cube_array_z_comp
= true;
3761 has_txq_cube_array_z
= true;
3764 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
3765 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
3766 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
3767 sampler_src_reg
= 2;
3769 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3771 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
3772 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
3773 ctx
->shader
->uses_tex_buffers
= true;
3774 return r600_do_buffer_txq(ctx
);
3776 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3777 if (ctx
->bc
->chip_class
< EVERGREEN
)
3778 ctx
->shader
->uses_tex_buffers
= true;
3779 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
3783 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3784 /* get offset values */
3785 if (inst
->Texture
.NumOffsets
) {
3786 assert(inst
->Texture
.NumOffsets
== 1);
3788 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
3789 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
3790 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
3792 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
3793 /* TGSI moves the sampler to src reg 3 for TXD */
3794 sampler_src_reg
= 3;
3796 for (i
= 1; i
< 3; i
++) {
3797 /* set gradients h/v */
3798 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
3799 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
3800 FETCH_OP_SET_GRADIENTS_V
;
3801 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
3802 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
3804 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
3805 tex
.src_gpr
= r600_get_temp(ctx
);
3811 for (j
= 0; j
< 4; j
++) {
3812 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3813 alu
.op
= ALU_OP1_MOV
;
3814 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
3815 alu
.dst
.sel
= tex
.src_gpr
;
3820 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3826 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
3827 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
3828 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
3829 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
3830 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
3831 tex
.src_rel
= ctx
->src
[i
].rel
;
3833 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
3834 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
3835 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
3836 tex
.coord_type_x
= 1;
3837 tex
.coord_type_y
= 1;
3838 tex
.coord_type_z
= 1;
3839 tex
.coord_type_w
= 1;
3841 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
3845 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
3847 /* Add perspective divide */
3848 if (ctx
->bc
->chip_class
== CAYMAN
) {
3850 for (i
= 0; i
< 3; i
++) {
3851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3852 alu
.op
= ALU_OP1_RECIP_IEEE
;
3853 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3855 alu
.dst
.sel
= ctx
->temp_reg
;
3861 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3868 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3869 alu
.op
= ALU_OP1_RECIP_IEEE
;
3870 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3872 alu
.dst
.sel
= ctx
->temp_reg
;
3873 alu
.dst
.chan
= out_chan
;
3876 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3881 for (i
= 0; i
< 3; i
++) {
3882 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3883 alu
.op
= ALU_OP2_MUL
;
3884 alu
.src
[0].sel
= ctx
->temp_reg
;
3885 alu
.src
[0].chan
= out_chan
;
3886 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3887 alu
.dst
.sel
= ctx
->temp_reg
;
3890 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3894 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3895 alu
.op
= ALU_OP1_MOV
;
3896 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3897 alu
.src
[0].chan
= 0;
3898 alu
.dst
.sel
= ctx
->temp_reg
;
3902 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3906 src_gpr
= ctx
->temp_reg
;
3909 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
3910 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3911 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
3912 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
3913 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
3914 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
3916 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
3917 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
3919 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
3920 for (i
= 0; i
< 4; i
++) {
3921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3922 alu
.op
= ALU_OP2_CUBE
;
3923 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
3924 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
3925 alu
.dst
.sel
= ctx
->temp_reg
;
3930 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3935 /* tmp1.z = RCP_e(|tmp1.z|) */
3936 if (ctx
->bc
->chip_class
== CAYMAN
) {
3937 for (i
= 0; i
< 3; i
++) {
3938 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3939 alu
.op
= ALU_OP1_RECIP_IEEE
;
3940 alu
.src
[0].sel
= ctx
->temp_reg
;
3941 alu
.src
[0].chan
= 2;
3943 alu
.dst
.sel
= ctx
->temp_reg
;
3949 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3954 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3955 alu
.op
= ALU_OP1_RECIP_IEEE
;
3956 alu
.src
[0].sel
= ctx
->temp_reg
;
3957 alu
.src
[0].chan
= 2;
3959 alu
.dst
.sel
= ctx
->temp_reg
;
3963 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3968 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
3969 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
3970 * muladd has no writemask, have to use another temp
3972 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3973 alu
.op
= ALU_OP3_MULADD
;
3976 alu
.src
[0].sel
= ctx
->temp_reg
;
3977 alu
.src
[0].chan
= 0;
3978 alu
.src
[1].sel
= ctx
->temp_reg
;
3979 alu
.src
[1].chan
= 2;
3981 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
3982 alu
.src
[2].chan
= 0;
3983 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
3985 alu
.dst
.sel
= ctx
->temp_reg
;
3989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3993 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3994 alu
.op
= ALU_OP3_MULADD
;
3997 alu
.src
[0].sel
= ctx
->temp_reg
;
3998 alu
.src
[0].chan
= 1;
3999 alu
.src
[1].sel
= ctx
->temp_reg
;
4000 alu
.src
[1].chan
= 2;
4002 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4003 alu
.src
[2].chan
= 0;
4004 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4006 alu
.dst
.sel
= ctx
->temp_reg
;
4011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4014 /* write initial compare value into Z component
4015 - W src 0 for shadow cube
4016 - X src 1 for shadow cube array */
4017 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4018 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4020 alu
.op
= ALU_OP1_MOV
;
4021 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4022 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4024 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4025 alu
.dst
.sel
= ctx
->temp_reg
;
4029 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4034 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4035 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4036 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4037 int mytmp
= r600_get_temp(ctx
);
4038 static const float eight
= 8.0f
;
4039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4040 alu
.op
= ALU_OP1_MOV
;
4041 alu
.src
[0].sel
= ctx
->temp_reg
;
4042 alu
.src
[0].chan
= 3;
4043 alu
.dst
.sel
= mytmp
;
4047 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4051 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4053 alu
.op
= ALU_OP3_MULADD
;
4055 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4056 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4057 alu
.src
[1].chan
= 0;
4058 alu
.src
[1].value
= *(uint32_t *)&eight
;
4059 alu
.src
[2].sel
= mytmp
;
4060 alu
.src
[2].chan
= 0;
4061 alu
.dst
.sel
= ctx
->temp_reg
;
4065 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4068 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4069 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4070 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4071 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4072 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4073 tex
.src_gpr
= r600_get_temp(ctx
);
4078 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4079 tex
.coord_type_x
= 1;
4080 tex
.coord_type_y
= 1;
4081 tex
.coord_type_z
= 1;
4082 tex
.coord_type_w
= 1;
4083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4084 alu
.op
= ALU_OP1_MOV
;
4085 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4086 alu
.dst
.sel
= tex
.src_gpr
;
4090 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4094 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4101 /* for cube forms of lod and bias we need to route things */
4102 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4103 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4104 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4105 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4106 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4107 alu
.op
= ALU_OP1_MOV
;
4108 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4109 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4110 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4112 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4113 alu
.dst
.sel
= ctx
->temp_reg
;
4117 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4123 src_gpr
= ctx
->temp_reg
;
4126 if (src_requires_loading
&& !src_loaded
) {
4127 for (i
= 0; i
< 4; i
++) {
4128 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4129 alu
.op
= ALU_OP1_MOV
;
4130 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4131 alu
.dst
.sel
= ctx
->temp_reg
;
4136 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4141 src_gpr
= ctx
->temp_reg
;
4144 /* Obtain the sample index for reading a compressed MSAA color texture.
4145 * To read the FMASK, we use the ldfptr instruction, which tells us
4146 * where the samples are stored.
4147 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4148 * which is the identity mapping. Each nibble says which physical sample
4149 * should be fetched to get that sample.
4151 * Assume src.z contains the sample index. It should be modified like this:
4152 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4153 * Then fetch the texel with src.
4155 if (read_compressed_msaa
) {
4156 unsigned sample_chan
= 3;
4157 unsigned temp
= r600_get_temp(ctx
);
4160 /* temp.w = ldfptr() */
4161 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4162 tex
.op
= FETCH_OP_LD
;
4163 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4164 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4165 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4166 tex
.src_gpr
= src_gpr
;
4168 tex
.dst_sel_x
= 7; /* mask out these components */
4171 tex
.dst_sel_w
= 0; /* store X */
4176 tex
.offset_x
= offset_x
;
4177 tex
.offset_y
= offset_y
;
4178 tex
.offset_z
= offset_z
;
4179 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4183 /* temp.x = sample_index*4 */
4184 if (ctx
->bc
->chip_class
== CAYMAN
) {
4185 for (i
= 0 ; i
< 4; i
++) {
4186 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4187 alu
.op
= ALU_OP2_MULLO_INT
;
4188 alu
.src
[0].sel
= src_gpr
;
4189 alu
.src
[0].chan
= sample_chan
;
4190 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4191 alu
.src
[1].value
= 4;
4194 alu
.dst
.write
= i
== 0;
4197 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4203 alu
.op
= ALU_OP2_MULLO_INT
;
4204 alu
.src
[0].sel
= src_gpr
;
4205 alu
.src
[0].chan
= sample_chan
;
4206 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4207 alu
.src
[1].value
= 4;
4212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4217 /* sample_index = temp.w >> temp.x */
4218 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4219 alu
.op
= ALU_OP2_LSHR_INT
;
4220 alu
.src
[0].sel
= temp
;
4221 alu
.src
[0].chan
= 3;
4222 alu
.src
[1].sel
= temp
;
4223 alu
.src
[1].chan
= 0;
4224 alu
.dst
.sel
= src_gpr
;
4225 alu
.dst
.chan
= sample_chan
;
4228 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4232 /* sample_index & 0xF */
4233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4234 alu
.op
= ALU_OP2_AND_INT
;
4235 alu
.src
[0].sel
= src_gpr
;
4236 alu
.src
[0].chan
= sample_chan
;
4237 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4238 alu
.src
[1].value
= 0xF;
4239 alu
.dst
.sel
= src_gpr
;
4240 alu
.dst
.chan
= sample_chan
;
4243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4247 /* visualize the FMASK */
4248 for (i
= 0; i
< 4; i
++) {
4249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4250 alu
.op
= ALU_OP1_INT_TO_FLT
;
4251 alu
.src
[0].sel
= src_gpr
;
4252 alu
.src
[0].chan
= sample_chan
;
4253 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4257 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4265 /* does this shader want a num layers from TXQ for a cube array? */
4266 if (has_txq_cube_array_z
) {
4267 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4270 alu
.op
= ALU_OP1_MOV
;
4272 alu
.src
[0].sel
= 512 + (id
/ 4);
4273 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4274 alu
.src
[0].chan
= id
% 4;
4275 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4277 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4280 /* disable writemask from texture instruction */
4281 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4284 opcode
= ctx
->inst_info
->op
;
4285 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4286 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4287 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4288 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4289 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4290 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4291 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4293 case FETCH_OP_SAMPLE
:
4294 opcode
= FETCH_OP_SAMPLE_C
;
4296 case FETCH_OP_SAMPLE_L
:
4297 opcode
= FETCH_OP_SAMPLE_C_L
;
4299 case FETCH_OP_SAMPLE_LB
:
4300 opcode
= FETCH_OP_SAMPLE_C_LB
;
4302 case FETCH_OP_SAMPLE_G
:
4303 opcode
= FETCH_OP_SAMPLE_C_G
;
4308 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4311 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4312 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4313 tex
.src_gpr
= src_gpr
;
4314 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4315 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4316 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4317 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4318 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4320 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4325 } else if (src_loaded
) {
4331 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4332 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4333 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4334 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4335 tex
.src_rel
= ctx
->src
[0].rel
;
4338 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4339 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4340 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4341 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4345 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4348 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4349 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4350 tex
.coord_type_x
= 1;
4351 tex
.coord_type_y
= 1;
4353 tex
.coord_type_z
= 1;
4354 tex
.coord_type_w
= 1;
4356 tex
.offset_x
= offset_x
;
4357 tex
.offset_y
= offset_y
;
4358 tex
.offset_z
= offset_z
;
4360 /* Put the depth for comparison in W.
4361 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4362 * Some instructions expect the depth in Z. */
4363 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4364 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4365 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4366 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4367 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4368 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4369 tex
.src_sel_w
= tex
.src_sel_z
;
4372 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4373 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4374 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4375 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4376 /* the array index is read from Y */
4377 tex
.coord_type_y
= 0;
4379 /* the array index is read from Z */
4380 tex
.coord_type_z
= 0;
4381 tex
.src_sel_z
= tex
.src_sel_y
;
4383 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4384 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4385 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4386 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4387 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4388 /* the array index is read from Z */
4389 tex
.coord_type_z
= 0;
4391 /* mask unused source components */
4392 if (opcode
== FETCH_OP_SAMPLE
) {
4393 switch (inst
->Texture
.Texture
) {
4394 case TGSI_TEXTURE_2D
:
4395 case TGSI_TEXTURE_RECT
:
4399 case TGSI_TEXTURE_1D_ARRAY
:
4403 case TGSI_TEXTURE_1D
:
4411 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4415 /* add shadow ambient support - gallium doesn't do it yet */
4419 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4421 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4422 struct r600_bytecode_alu alu
;
4423 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4427 /* optimize if it's just an equal balance */
4428 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4429 for (i
= 0; i
< lasti
+ 1; i
++) {
4430 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4433 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4434 alu
.op
= ALU_OP2_ADD
;
4435 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4436 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4438 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4443 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4451 for (i
= 0; i
< lasti
+ 1; i
++) {
4452 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4455 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4456 alu
.op
= ALU_OP2_ADD
;
4457 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4458 alu
.src
[0].chan
= 0;
4459 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4460 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4461 alu
.dst
.sel
= ctx
->temp_reg
;
4467 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4472 /* (1 - src0) * src2 */
4473 for (i
= 0; i
< lasti
+ 1; i
++) {
4474 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4477 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4478 alu
.op
= ALU_OP2_MUL
;
4479 alu
.src
[0].sel
= ctx
->temp_reg
;
4480 alu
.src
[0].chan
= i
;
4481 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4482 alu
.dst
.sel
= ctx
->temp_reg
;
4488 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4493 /* src0 * src1 + (1 - src0) * src2 */
4494 for (i
= 0; i
< lasti
+ 1; i
++) {
4495 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4499 alu
.op
= ALU_OP3_MULADD
;
4501 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4502 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4503 alu
.src
[2].sel
= ctx
->temp_reg
;
4504 alu
.src
[2].chan
= i
;
4506 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4511 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4518 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4520 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4521 struct r600_bytecode_alu alu
;
4523 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4525 for (i
= 0; i
< lasti
+ 1; i
++) {
4526 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4530 alu
.op
= ALU_OP3_CNDGE
;
4531 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4532 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4533 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4534 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4540 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4547 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4549 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4550 struct r600_bytecode_alu alu
;
4552 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4554 for (i
= 0; i
< lasti
+ 1; i
++) {
4555 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4558 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4559 alu
.op
= ALU_OP3_CNDGE_INT
;
4560 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4561 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4562 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4563 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4569 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4576 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4578 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4579 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4580 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4581 struct r600_bytecode_alu alu
;
4582 uint32_t use_temp
= 0;
4585 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4588 for (i
= 0; i
< 4; i
++) {
4589 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4590 alu
.op
= ALU_OP2_MUL
;
4592 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4593 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4595 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4596 alu
.src
[0].chan
= i
;
4597 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4598 alu
.src
[1].chan
= i
;
4601 alu
.dst
.sel
= ctx
->temp_reg
;
4607 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4612 for (i
= 0; i
< 4; i
++) {
4613 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4614 alu
.op
= ALU_OP3_MULADD
;
4617 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4618 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4620 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4621 alu
.src
[0].chan
= i
;
4622 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4623 alu
.src
[1].chan
= i
;
4626 alu
.src
[2].sel
= ctx
->temp_reg
;
4628 alu
.src
[2].chan
= i
;
4631 alu
.dst
.sel
= ctx
->temp_reg
;
4633 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4639 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4644 return tgsi_helper_copy(ctx
, inst
);
4648 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4650 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4651 struct r600_bytecode_alu alu
;
4655 /* result.x = 2^floor(src); */
4656 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4657 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4659 alu
.op
= ALU_OP1_FLOOR
;
4660 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4662 alu
.dst
.sel
= ctx
->temp_reg
;
4666 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4670 if (ctx
->bc
->chip_class
== CAYMAN
) {
4671 for (i
= 0; i
< 3; i
++) {
4672 alu
.op
= ALU_OP1_EXP_IEEE
;
4673 alu
.src
[0].sel
= ctx
->temp_reg
;
4674 alu
.src
[0].chan
= 0;
4676 alu
.dst
.sel
= ctx
->temp_reg
;
4678 alu
.dst
.write
= i
== 0;
4680 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4685 alu
.op
= ALU_OP1_EXP_IEEE
;
4686 alu
.src
[0].sel
= ctx
->temp_reg
;
4687 alu
.src
[0].chan
= 0;
4689 alu
.dst
.sel
= ctx
->temp_reg
;
4693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4699 /* result.y = tmp - floor(tmp); */
4700 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4701 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4703 alu
.op
= ALU_OP1_FRACT
;
4704 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4706 alu
.dst
.sel
= ctx
->temp_reg
;
4708 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4722 /* result.z = RoughApprox2ToX(tmp);*/
4723 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
4724 if (ctx
->bc
->chip_class
== CAYMAN
) {
4725 for (i
= 0; i
< 3; i
++) {
4726 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4727 alu
.op
= ALU_OP1_EXP_IEEE
;
4728 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4730 alu
.dst
.sel
= ctx
->temp_reg
;
4737 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4742 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4743 alu
.op
= ALU_OP1_EXP_IEEE
;
4744 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4746 alu
.dst
.sel
= ctx
->temp_reg
;
4752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4758 /* result.w = 1.0;*/
4759 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
4760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4762 alu
.op
= ALU_OP1_MOV
;
4763 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4764 alu
.src
[0].chan
= 0;
4766 alu
.dst
.sel
= ctx
->temp_reg
;
4770 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4774 return tgsi_helper_copy(ctx
, inst
);
4777 static int tgsi_log(struct r600_shader_ctx
*ctx
)
4779 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4780 struct r600_bytecode_alu alu
;
4784 /* result.x = floor(log2(|src|)); */
4785 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4786 if (ctx
->bc
->chip_class
== CAYMAN
) {
4787 for (i
= 0; i
< 3; i
++) {
4788 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4790 alu
.op
= ALU_OP1_LOG_IEEE
;
4791 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4792 r600_bytecode_src_set_abs(&alu
.src
[0]);
4794 alu
.dst
.sel
= ctx
->temp_reg
;
4800 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4806 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4808 alu
.op
= ALU_OP1_LOG_IEEE
;
4809 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4810 r600_bytecode_src_set_abs(&alu
.src
[0]);
4812 alu
.dst
.sel
= ctx
->temp_reg
;
4816 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4821 alu
.op
= ALU_OP1_FLOOR
;
4822 alu
.src
[0].sel
= ctx
->temp_reg
;
4823 alu
.src
[0].chan
= 0;
4825 alu
.dst
.sel
= ctx
->temp_reg
;
4830 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4835 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
4836 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4838 if (ctx
->bc
->chip_class
== CAYMAN
) {
4839 for (i
= 0; i
< 3; i
++) {
4840 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4842 alu
.op
= ALU_OP1_LOG_IEEE
;
4843 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4844 r600_bytecode_src_set_abs(&alu
.src
[0]);
4846 alu
.dst
.sel
= ctx
->temp_reg
;
4853 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4858 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4860 alu
.op
= ALU_OP1_LOG_IEEE
;
4861 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4862 r600_bytecode_src_set_abs(&alu
.src
[0]);
4864 alu
.dst
.sel
= ctx
->temp_reg
;
4869 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4874 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4876 alu
.op
= ALU_OP1_FLOOR
;
4877 alu
.src
[0].sel
= ctx
->temp_reg
;
4878 alu
.src
[0].chan
= 1;
4880 alu
.dst
.sel
= ctx
->temp_reg
;
4885 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4889 if (ctx
->bc
->chip_class
== CAYMAN
) {
4890 for (i
= 0; i
< 3; i
++) {
4891 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4892 alu
.op
= ALU_OP1_EXP_IEEE
;
4893 alu
.src
[0].sel
= ctx
->temp_reg
;
4894 alu
.src
[0].chan
= 1;
4896 alu
.dst
.sel
= ctx
->temp_reg
;
4903 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4909 alu
.op
= ALU_OP1_EXP_IEEE
;
4910 alu
.src
[0].sel
= ctx
->temp_reg
;
4911 alu
.src
[0].chan
= 1;
4913 alu
.dst
.sel
= ctx
->temp_reg
;
4918 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4923 if (ctx
->bc
->chip_class
== CAYMAN
) {
4924 for (i
= 0; i
< 3; i
++) {
4925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4926 alu
.op
= ALU_OP1_RECIP_IEEE
;
4927 alu
.src
[0].sel
= ctx
->temp_reg
;
4928 alu
.src
[0].chan
= 1;
4930 alu
.dst
.sel
= ctx
->temp_reg
;
4937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4943 alu
.op
= ALU_OP1_RECIP_IEEE
;
4944 alu
.src
[0].sel
= ctx
->temp_reg
;
4945 alu
.src
[0].chan
= 1;
4947 alu
.dst
.sel
= ctx
->temp_reg
;
4952 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4957 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4959 alu
.op
= ALU_OP2_MUL
;
4961 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4962 r600_bytecode_src_set_abs(&alu
.src
[0]);
4964 alu
.src
[1].sel
= ctx
->temp_reg
;
4965 alu
.src
[1].chan
= 1;
4967 alu
.dst
.sel
= ctx
->temp_reg
;
4972 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4977 /* result.z = log2(|src|);*/
4978 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
4979 if (ctx
->bc
->chip_class
== CAYMAN
) {
4980 for (i
= 0; i
< 3; i
++) {
4981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4983 alu
.op
= ALU_OP1_LOG_IEEE
;
4984 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4985 r600_bytecode_src_set_abs(&alu
.src
[0]);
4987 alu
.dst
.sel
= ctx
->temp_reg
;
4994 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4999 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5001 alu
.op
= ALU_OP1_LOG_IEEE
;
5002 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5003 r600_bytecode_src_set_abs(&alu
.src
[0]);
5005 alu
.dst
.sel
= ctx
->temp_reg
;
5010 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5016 /* result.w = 1.0; */
5017 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5020 alu
.op
= ALU_OP1_MOV
;
5021 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5022 alu
.src
[0].chan
= 0;
5024 alu
.dst
.sel
= ctx
->temp_reg
;
5029 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5034 return tgsi_helper_copy(ctx
, inst
);
5037 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5039 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5040 struct r600_bytecode_alu alu
;
5043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5045 switch (inst
->Instruction
.Opcode
) {
5046 case TGSI_OPCODE_ARL
:
5047 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5049 case TGSI_OPCODE_ARR
:
5050 alu
.op
= ALU_OP1_FLT_TO_INT
;
5052 case TGSI_OPCODE_UARL
:
5053 alu
.op
= ALU_OP1_MOV
;
5060 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5062 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5064 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5068 ctx
->bc
->ar_loaded
= 0;
5071 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5073 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5074 struct r600_bytecode_alu alu
;
5077 switch (inst
->Instruction
.Opcode
) {
5078 case TGSI_OPCODE_ARL
:
5079 memset(&alu
, 0, sizeof(alu
));
5080 alu
.op
= ALU_OP1_FLOOR
;
5081 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5082 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5086 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5089 memset(&alu
, 0, sizeof(alu
));
5090 alu
.op
= ALU_OP1_FLT_TO_INT
;
5091 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5092 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5096 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5099 case TGSI_OPCODE_ARR
:
5100 memset(&alu
, 0, sizeof(alu
));
5101 alu
.op
= ALU_OP1_FLT_TO_INT
;
5102 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5103 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5107 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5110 case TGSI_OPCODE_UARL
:
5111 memset(&alu
, 0, sizeof(alu
));
5112 alu
.op
= ALU_OP1_MOV
;
5113 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5114 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5118 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5126 ctx
->bc
->ar_loaded
= 0;
5130 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5132 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5133 struct r600_bytecode_alu alu
;
5136 for (i
= 0; i
< 4; i
++) {
5137 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5139 alu
.op
= ALU_OP2_MUL
;
5140 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5142 if (i
== 0 || i
== 3) {
5143 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5145 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5148 if (i
== 0 || i
== 2) {
5149 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5151 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5162 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5164 struct r600_bytecode_alu alu
;
5167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5169 alu
.execute_mask
= 1;
5170 alu
.update_pred
= 1;
5172 alu
.dst
.sel
= ctx
->temp_reg
;
5176 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5177 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5178 alu
.src
[1].chan
= 0;
5182 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5188 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5190 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5194 if (ctx
->bc
->cf_last
) {
5195 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5197 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5202 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5203 ctx
->bc
->force_add_cf
= 1;
5204 } else if (alu_pop
== 2) {
5205 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5206 ctx
->bc
->force_add_cf
= 1;
5213 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5214 ctx
->bc
->cf_last
->pop_count
= pops
;
5215 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5221 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5224 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5225 unsigned elements
, entries
;
5227 unsigned entry_size
= stack
->entry_size
;
5229 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5230 elements
+= stack
->push
;
5232 switch (ctx
->bc
->chip_class
) {
5235 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5236 * the stack must be reserved to hold the current active/continue
5238 if (reason
== FC_PUSH_VPM
) {
5244 /* r9xx: any stack operation on empty stack consumes 2 additional
5249 /* FIXME: do the two elements added above cover the cases for the
5253 /* r8xx+: 2 extra elements are not always required, but one extra
5254 * element must be added for each of the following cases:
5255 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5257 * (Currently we don't use ALU_ELSE_AFTER.)
5258 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5259 * PUSH instruction executed.
5261 * NOTE: it seems we also need to reserve additional element in some
5262 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5263 * then STACK_SIZE should be 2 instead of 1 */
5264 if (reason
== FC_PUSH_VPM
) {
5274 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5275 * for all chips, so we use 4 in the final formula, not the real entry_size
5279 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5281 if (entries
> stack
->max_entries
)
5282 stack
->max_entries
= entries
;
5285 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5289 --ctx
->bc
->stack
.push
;
5290 assert(ctx
->bc
->stack
.push
>= 0);
5293 --ctx
->bc
->stack
.push_wqm
;
5294 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5297 --ctx
->bc
->stack
.loop
;
5298 assert(ctx
->bc
->stack
.loop
>= 0);
5306 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5310 ++ctx
->bc
->stack
.push
;
5313 ++ctx
->bc
->stack
.push_wqm
;
5315 ++ctx
->bc
->stack
.loop
;
5321 callstack_update_max_depth(ctx
, reason
);
5324 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5326 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5328 sp
->mid
= realloc((void *)sp
->mid
,
5329 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5330 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5334 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5337 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5338 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5341 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5343 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5353 static int emit_return(struct r600_shader_ctx
*ctx
)
5355 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5359 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5362 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5363 ctx
->bc
->cf_last
->pop_count
= pops
;
5364 /* XXX work out offset */
5368 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5373 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5378 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5381 emit_jump_to_offset(ctx
, 1, 4);
5382 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5383 pops(ctx
, ifidx
+ 1);
5387 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5391 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5392 ctx
->bc
->cf_last
->pop_count
= 1;
5394 fc_set_mid(ctx
, fc_sp
);
5400 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5402 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5404 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5405 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5406 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5407 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5408 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5409 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5410 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5411 alu_type
= CF_OP_ALU
;
5414 emit_logic_pred(ctx
, opcode
, alu_type
);
5416 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5418 fc_pushlevel(ctx
, FC_IF
);
5420 callstack_push(ctx
, FC_PUSH_VPM
);
5424 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5426 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5429 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5431 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5434 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5436 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5437 ctx
->bc
->cf_last
->pop_count
= 1;
5439 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5440 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5444 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5447 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5448 R600_ERR("if/endif unbalanced in shader\n");
5452 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5453 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5454 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5456 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5460 callstack_pop(ctx
, FC_PUSH_VPM
);
5464 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5466 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5467 * limited to 4096 iterations, like the other LOOP_* instructions. */
5468 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5470 fc_pushlevel(ctx
, FC_LOOP
);
5472 /* check stack depth */
5473 callstack_push(ctx
, FC_LOOP
);
5477 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5481 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5483 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5484 R600_ERR("loop/endloop in shader code are not paired.\n");
5488 /* fixup loop pointers - from r600isa
5489 LOOP END points to CF after LOOP START,
5490 LOOP START point to CF after LOOP END
5491 BRK/CONT point to LOOP END CF
5493 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5495 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5497 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5498 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5500 /* XXX add LOOPRET support */
5502 callstack_pop(ctx
, FC_LOOP
);
5506 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5510 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5512 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5517 R600_ERR("Break not inside loop/endloop pair\n");
5521 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5523 fc_set_mid(ctx
, fscp
);
5528 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5530 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5531 struct r600_bytecode_alu alu
;
5533 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5536 for (i
= 0; i
< lasti
+ 1; i
++) {
5537 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5540 if (ctx
->bc
->chip_class
== CAYMAN
) {
5541 for (j
= 0 ; j
< 4; j
++) {
5542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5544 alu
.op
= ALU_OP2_MULLO_UINT
;
5545 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5546 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5548 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5549 alu
.dst
.sel
= ctx
->temp_reg
;
5550 alu
.dst
.write
= (j
== i
);
5553 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5558 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5561 alu
.dst
.sel
= ctx
->temp_reg
;
5564 alu
.op
= ALU_OP2_MULLO_UINT
;
5565 for (j
= 0; j
< 2; j
++) {
5566 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5570 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5577 for (i
= 0; i
< lasti
+ 1; i
++) {
5578 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5581 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5582 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5584 alu
.op
= ALU_OP2_ADD_INT
;
5586 alu
.src
[0].sel
= ctx
->temp_reg
;
5587 alu
.src
[0].chan
= i
;
5589 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5593 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5600 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5601 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5602 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5603 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5606 * For state trackers other than OpenGL, we'll want to use
5607 * _RECIP_IEEE instead.
5609 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5611 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5612 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5613 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5614 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5615 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5616 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5617 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5618 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5619 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5620 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5621 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5622 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5623 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5624 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5625 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5626 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5628 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5629 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5631 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5632 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5633 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5634 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5635 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5636 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5637 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5638 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5639 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5640 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5642 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5643 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5644 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5645 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5646 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5647 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5648 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5649 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
5650 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5651 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5652 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5653 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5654 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5655 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5656 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5657 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5658 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5659 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5660 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5661 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5662 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5663 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5664 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5665 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5666 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5667 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5668 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5669 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5670 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5671 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5672 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5673 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5674 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5675 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5676 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5677 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5678 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5679 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5680 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5681 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5682 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5683 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5684 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5685 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5686 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5687 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5688 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5690 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5691 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5692 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5693 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5694 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5695 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5696 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5697 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5698 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
5700 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5701 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5702 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5703 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5704 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5705 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5706 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5707 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5708 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5709 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5710 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5711 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5712 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5713 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5714 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5715 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5717 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5718 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5719 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5720 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5721 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
5722 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
5723 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
5724 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
5725 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5726 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5728 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5729 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5730 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5731 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5733 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5734 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
5735 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5736 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5737 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5738 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5739 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5740 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
5741 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5742 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
5743 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5744 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5745 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5746 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5747 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5748 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5749 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5750 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5751 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5752 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5753 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
5754 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5755 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
5756 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5757 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5758 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5759 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5760 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5761 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5762 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5763 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5764 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5765 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5766 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5767 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5768 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5769 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5770 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5771 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5772 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
5773 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5774 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5775 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5776 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5777 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5778 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5779 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5780 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5781 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5782 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5783 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5784 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5785 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5786 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5787 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5788 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5789 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5790 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5791 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5792 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5793 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5794 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5795 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5798 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
5799 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5800 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5801 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5802 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
5803 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
5804 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5805 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5806 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5807 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5808 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5809 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5810 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5811 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5812 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5813 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5814 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5815 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5816 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5817 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5818 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5820 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5821 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5823 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5824 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5825 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5826 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5827 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5828 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5829 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5830 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5831 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5832 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5834 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5835 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5836 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5837 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5838 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5839 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5840 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5841 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
5842 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5843 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5844 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5845 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5846 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5847 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5848 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5849 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5850 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5851 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5852 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5853 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5854 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5855 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5856 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5857 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5858 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5859 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5860 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5861 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5862 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5863 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5864 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5865 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5866 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5867 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5868 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5869 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5870 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5871 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5872 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5873 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5874 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5875 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5876 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5877 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5878 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5879 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5880 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5882 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5883 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5884 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5885 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5886 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5887 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5888 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5889 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5890 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
5892 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5893 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5894 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5895 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5896 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5897 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5898 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5899 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5900 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5901 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5902 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5903 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5904 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5905 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5906 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5907 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5909 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5910 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5911 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5912 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5913 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
5914 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
5915 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
5916 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
5917 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5918 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5920 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5921 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5922 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5923 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5925 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5926 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
5927 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5928 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5929 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5930 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5931 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5932 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
5933 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5934 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
5935 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5936 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5937 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5938 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5939 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5940 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5941 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5942 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5943 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5944 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5945 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
5946 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5947 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
5948 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5949 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5950 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5951 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5952 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5953 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5954 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5955 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5956 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5957 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5958 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5959 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5960 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5961 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5962 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5963 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5964 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
5965 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5966 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5967 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5968 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5969 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5970 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5971 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5972 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5973 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5974 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5975 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5977 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5978 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5979 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5980 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5981 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5982 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5983 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5984 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5985 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5986 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5987 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5990 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
5991 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5992 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5993 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5994 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
5995 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
5996 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5997 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5998 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5999 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6000 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6001 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6002 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6003 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6004 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6005 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6006 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6007 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6008 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6009 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6010 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6012 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6013 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6015 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6016 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6017 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6018 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6019 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6020 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6021 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6022 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6023 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6024 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6026 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6027 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6028 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6029 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6030 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6031 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6032 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6033 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6034 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6035 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6036 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6037 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6038 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6039 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6040 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6041 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6042 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6043 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6044 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6045 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6046 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6047 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6048 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6049 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6050 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6051 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6052 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6053 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6054 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6055 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6056 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6057 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6058 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6059 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6060 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6061 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6062 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6063 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6064 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6065 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6066 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6067 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6068 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6069 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6070 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6071 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6072 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6074 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6075 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6076 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6078 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6079 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6080 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6081 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6082 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6084 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6085 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6086 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6087 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6088 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6089 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6090 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6091 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6092 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6093 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6094 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6095 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6096 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6097 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6098 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6099 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6101 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6102 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6103 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6106 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6107 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6108 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6109 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6110 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6111 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6114 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6115 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6116 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6118 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6119 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6120 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6121 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6122 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6123 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6124 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6125 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6126 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6127 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6128 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6129 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6130 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6131 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6132 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6133 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6134 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6135 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6136 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6137 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6138 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6139 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6140 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6141 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6142 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6143 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6144 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6145 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6146 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6147 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6148 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6149 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6150 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6151 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6152 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6153 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6154 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6155 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6156 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6157 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6158 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6159 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6160 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6161 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6162 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6163 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6164 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6165 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6166 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6167 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6168 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6170 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6172 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6173 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6174 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6175 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6176 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6177 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6178 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6179 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6180 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},