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 "pipe/p_shader_tokens.h"
31 #include "tgsi/tgsi_info.h"
32 #include "tgsi/tgsi_parse.h"
33 #include "tgsi/tgsi_scan.h"
34 #include "tgsi/tgsi_dump.h"
35 #include "util/u_memory.h"
41 Why CAYMAN got loops for lots of instructions is explained here.
43 -These 8xx t-slot only ops are implemented in all vector slots.
44 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
45 These 8xx t-slot only opcodes become vector ops, with all four
46 slots expecting the arguments on sources a and b. Result is
47 broadcast to all channels.
48 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT
49 These 8xx t-slot only opcodes become vector ops in the z, y, and
51 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
52 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
55 The w slot may have an independent co-issued operation, or if the
56 result is required to be in the w slot, the opcode above may be
57 issued in the w slot as well.
58 The compiler must issue the source argument to slots z, y, and x
61 static int r600_pipe_shader(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
63 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
64 struct r600_shader
*rshader
= &shader
->shader
;
69 if (shader
->bo
== NULL
) {
70 shader
->bo
= (struct r600_resource
*)
71 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, rshader
->bc
.ndw
* 4);
72 if (shader
->bo
== NULL
) {
75 ptr
= (uint32_t*)rctx
->ws
->buffer_map(shader
->bo
->cs_buf
, rctx
->cs
, PIPE_TRANSFER_WRITE
);
76 if (R600_BIG_ENDIAN
) {
77 for (i
= 0; i
< rshader
->bc
.ndw
; ++i
) {
78 ptr
[i
] = bswap_32(rshader
->bc
.bytecode
[i
]);
81 memcpy(ptr
, rshader
->bc
.bytecode
, rshader
->bc
.ndw
* sizeof(*ptr
));
83 rctx
->ws
->buffer_unmap(shader
->bo
->cs_buf
);
86 switch (rshader
->processor_type
) {
87 case TGSI_PROCESSOR_VERTEX
:
88 if (rctx
->chip_class
>= EVERGREEN
) {
89 evergreen_pipe_shader_vs(ctx
, shader
);
91 r600_pipe_shader_vs(ctx
, shader
);
94 case TGSI_PROCESSOR_FRAGMENT
:
95 if (rctx
->chip_class
>= EVERGREEN
) {
96 evergreen_pipe_shader_ps(ctx
, shader
);
98 r600_pipe_shader_ps(ctx
, shader
);
107 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
108 struct r600_pipe_shader
*pipeshader
,
109 struct r600_shader_key key
);
111 int r600_pipe_shader_create(struct pipe_context
*ctx
,
112 struct r600_pipe_shader
*shader
,
113 struct r600_shader_key key
)
115 static int dump_shaders
= -1;
116 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
117 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
120 /* Would like some magic "get_bool_option_once" routine.
122 if (dump_shaders
== -1)
123 dump_shaders
= debug_get_bool_option("R600_DUMP_SHADERS", FALSE
);
126 fprintf(stderr
, "--------------------------------------------------------------\n");
127 tgsi_dump(sel
->tokens
, 0);
129 if (sel
->so
.num_outputs
) {
131 fprintf(stderr
, "STREAMOUT\n");
132 for (i
= 0; i
< sel
->so
.num_outputs
; i
++) {
133 unsigned mask
= ((1 << sel
->so
.output
[i
].num_components
) - 1) <<
134 sel
->so
.output
[i
].start_component
;
135 fprintf(stderr
, " %i: MEM_STREAM0_BUF%i OUT[%i].%s%s%s%s\n", i
,
136 sel
->so
.output
[i
].output_buffer
, sel
->so
.output
[i
].register_index
,
137 mask
& 1 ? "x" : "_",
138 (mask
>> 1) & 1 ? "y" : "_",
139 (mask
>> 2) & 1 ? "z" : "_",
140 (mask
>> 3) & 1 ? "w" : "_");
144 r
= r600_shader_from_tgsi(rctx
->screen
, shader
, key
);
146 R600_ERR("translation from TGSI failed !\n");
149 r
= r600_bytecode_build(&shader
->shader
.bc
);
151 R600_ERR("building bytecode failed !\n");
155 r600_bytecode_dump(&shader
->shader
.bc
);
156 fprintf(stderr
, "______________________________________________________________\n");
158 return r600_pipe_shader(ctx
, shader
);
161 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
163 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
164 r600_bytecode_clear(&shader
->shader
.bc
);
168 * tgsi -> r600 shader
170 struct r600_shader_tgsi_instruction
;
172 struct r600_shader_src
{
181 struct r600_shader_ctx
{
182 struct tgsi_shader_info info
;
183 struct tgsi_parse_context parse
;
184 const struct tgsi_token
*tokens
;
186 unsigned file_offset
[TGSI_FILE_COUNT
];
188 struct r600_shader_tgsi_instruction
*inst_info
;
189 struct r600_bytecode
*bc
;
190 struct r600_shader
*shader
;
191 struct r600_shader_src src
[4];
194 uint32_t max_driver_temp_used
;
196 /* needed for evergreen interpolation */
197 boolean input_centroid
;
198 boolean input_linear
;
199 boolean input_perspective
;
203 boolean clip_vertex_write
;
209 struct r600_shader_tgsi_instruction
{
210 unsigned tgsi_opcode
;
212 unsigned r600_opcode
;
213 int (*process
)(struct r600_shader_ctx
*ctx
);
216 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
217 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
218 static inline void callstack_check_depth(struct r600_shader_ctx
*ctx
, unsigned reason
, unsigned check_max_only
);
219 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
220 static int tgsi_else(struct r600_shader_ctx
*ctx
);
221 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
222 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
223 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
224 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
227 * bytestream -> r600 shader
229 * These functions are used to transform the output of the LLVM backend into
230 * struct r600_bytecode.
233 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
234 unsigned char * bytes
, unsigned num_bytes
);
237 int r600_compute_shader_create(struct pipe_context
* ctx
,
238 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
)
240 struct r600_context
*r600_ctx
= (struct r600_context
*)ctx
;
241 unsigned char * bytes
;
243 struct r600_shader_ctx shader_ctx
;
246 if (debug_get_bool_option("R600_DUMP_SHADERS", FALSE
)) {
250 r600_llvm_compile(mod
, &bytes
, &byte_count
, r600_ctx
->family
, dump
);
251 shader_ctx
.bc
= bytecode
;
252 r600_bytecode_init(shader_ctx
.bc
, r600_ctx
->chip_class
, r600_ctx
->family
,
253 r600_ctx
->screen
->msaa_texture_support
);
254 shader_ctx
.bc
->type
= TGSI_PROCESSOR_COMPUTE
;
255 r600_bytecode_from_byte_stream(&shader_ctx
, bytes
, byte_count
);
256 if (shader_ctx
.bc
->chip_class
== CAYMAN
) {
257 cm_bytecode_add_cf_end(shader_ctx
.bc
);
259 r600_bytecode_build(shader_ctx
.bc
);
261 r600_bytecode_dump(shader_ctx
.bc
);
267 #endif /* HAVE_OPENCL */
269 static uint32_t i32_from_byte_stream(unsigned char * bytes
,
270 unsigned * bytes_read
)
274 for (i
= 0; i
< 4; i
++) {
275 out
|= bytes
[(*bytes_read
)++] << (8 * i
);
280 static unsigned r600_src_from_byte_stream(unsigned char * bytes
,
281 unsigned bytes_read
, struct r600_bytecode_alu
* alu
, unsigned src_idx
)
285 sel0
= bytes
[bytes_read
++];
286 sel1
= bytes
[bytes_read
++];
287 alu
->src
[src_idx
].sel
= sel0
| (sel1
<< 8);
288 alu
->src
[src_idx
].chan
= bytes
[bytes_read
++];
289 alu
->src
[src_idx
].neg
= bytes
[bytes_read
++];
290 alu
->src
[src_idx
].abs
= bytes
[bytes_read
++];
291 alu
->src
[src_idx
].rel
= bytes
[bytes_read
++];
292 alu
->src
[src_idx
].kc_bank
= bytes
[bytes_read
++];
293 for (i
= 0; i
< 4; i
++) {
294 alu
->src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
299 static unsigned r600_alu_from_byte_stream(struct r600_shader_ctx
*ctx
,
300 unsigned char * bytes
, unsigned bytes_read
)
303 struct r600_bytecode_alu alu
;
304 unsigned src_const_reg
[3];
305 uint32_t word0
, word1
;
307 memset(&alu
, 0, sizeof(alu
));
308 for(src_idx
= 0; src_idx
< 3; src_idx
++) {
310 src_const_reg
[src_idx
] = bytes
[bytes_read
++];
311 for (i
= 0; i
< 4; i
++) {
312 alu
.src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
316 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
317 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
319 switch(ctx
->bc
->chip_class
) {
321 r600_bytecode_alu_read(&alu
, word0
, word1
);
326 r700_bytecode_alu_read(&alu
, word0
, word1
);
330 for(src_idx
= 0; src_idx
< 3; src_idx
++) {
331 if (src_const_reg
[src_idx
])
332 alu
.src
[src_idx
].sel
+= 512;
335 #if HAVE_LLVM < 0x0302
336 if (alu
.inst
== CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
) ||
337 alu
.inst
== CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
) ||
338 alu
.inst
== CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
) ||
339 alu
.inst
== CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
)) {
342 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
348 if (alu
.execute_mask
) {
350 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
));
352 r600_bytecode_add_alu(ctx
->bc
, &alu
);
355 /* XXX: Handle other KILL instructions */
356 if (alu
.inst
== CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
)) {
357 ctx
->shader
->uses_kill
= 1;
358 /* XXX: This should be enforced in the LLVM backend. */
359 ctx
->bc
->force_add_cf
= 1;
364 static void llvm_if(struct r600_shader_ctx
*ctx
, struct r600_bytecode_alu
* alu
,
367 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_JUMP
));
368 fc_pushlevel(ctx
, FC_IF
);
369 callstack_check_depth(ctx
, FC_PUSH_VPM
, 0);
372 static void r600_break_from_byte_stream(struct r600_shader_ctx
*ctx
,
373 struct r600_bytecode_alu
*alu
, unsigned compare_opcode
)
375 unsigned opcode
= TGSI_OPCODE_BRK
;
376 if (ctx
->bc
->chip_class
== CAYMAN
)
377 ctx
->inst_info
= &cm_shader_tgsi_instruction
[opcode
];
378 else if (ctx
->bc
->chip_class
>= EVERGREEN
)
379 ctx
->inst_info
= &eg_shader_tgsi_instruction
[opcode
];
381 ctx
->inst_info
= &r600_shader_tgsi_instruction
[opcode
];
382 llvm_if(ctx
, alu
, compare_opcode
);
383 tgsi_loop_brk_cont(ctx
);
387 static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx
*ctx
,
388 unsigned char * bytes
, unsigned bytes_read
)
390 struct r600_bytecode_alu alu
;
392 memset(&alu
, 0, sizeof(alu
));
393 bytes_read
= r600_src_from_byte_stream(bytes
, bytes_read
, &alu
, 0);
394 inst
= bytes
[bytes_read
++];
398 CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
));
400 case 1: /* FC_IF_INT */
402 CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
));
404 case 2: /* FC_ELSE */
407 case 3: /* FC_ENDIF */
410 case 4: /* FC_BGNLOOP */
413 case 5: /* FC_ENDLOOP */
416 case 6: /* FC_BREAK */
417 r600_break_from_byte_stream(ctx
, &alu
,
418 CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
));
420 case 7: /* FC_BREAK_NZ_INT */
421 r600_break_from_byte_stream(ctx
, &alu
,
422 CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
));
424 case 8: /* FC_CONTINUE */
426 unsigned opcode
= TGSI_OPCODE_CONT
;
427 if (ctx
->bc
->chip_class
== CAYMAN
) {
429 &cm_shader_tgsi_instruction
[opcode
];
430 } else if (ctx
->bc
->chip_class
>= EVERGREEN
) {
432 &eg_shader_tgsi_instruction
[opcode
];
435 &r600_shader_tgsi_instruction
[opcode
];
437 tgsi_loop_brk_cont(ctx
);
440 case 9: /* FC_BREAK_Z_INT */
441 r600_break_from_byte_stream(ctx
, &alu
,
442 CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT
));
444 case 10: /* FC_BREAK_NZ */
445 r600_break_from_byte_stream(ctx
, &alu
,
446 CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
));
453 static unsigned r600_tex_from_byte_stream(struct r600_shader_ctx
*ctx
,
454 unsigned char * bytes
, unsigned bytes_read
)
456 struct r600_bytecode_tex tex
;
458 tex
.inst
= bytes
[bytes_read
++];
459 tex
.resource_id
= bytes
[bytes_read
++];
460 tex
.src_gpr
= bytes
[bytes_read
++];
461 tex
.src_rel
= bytes
[bytes_read
++];
462 tex
.dst_gpr
= bytes
[bytes_read
++];
463 tex
.dst_rel
= bytes
[bytes_read
++];
464 tex
.dst_sel_x
= bytes
[bytes_read
++];
465 tex
.dst_sel_y
= bytes
[bytes_read
++];
466 tex
.dst_sel_z
= bytes
[bytes_read
++];
467 tex
.dst_sel_w
= bytes
[bytes_read
++];
468 tex
.lod_bias
= bytes
[bytes_read
++];
469 tex
.coord_type_x
= bytes
[bytes_read
++];
470 tex
.coord_type_y
= bytes
[bytes_read
++];
471 tex
.coord_type_z
= bytes
[bytes_read
++];
472 tex
.coord_type_w
= bytes
[bytes_read
++];
473 tex
.offset_x
= bytes
[bytes_read
++];
474 tex
.offset_y
= bytes
[bytes_read
++];
475 tex
.offset_z
= bytes
[bytes_read
++];
476 tex
.sampler_id
= bytes
[bytes_read
++];
477 tex
.src_sel_x
= bytes
[bytes_read
++];
478 tex
.src_sel_y
= bytes
[bytes_read
++];
479 tex
.src_sel_z
= bytes
[bytes_read
++];
480 tex
.src_sel_w
= bytes
[bytes_read
++];
482 r600_bytecode_add_tex(ctx
->bc
, &tex
);
487 static int r600_vtx_from_byte_stream(struct r600_shader_ctx
*ctx
,
488 unsigned char * bytes
, unsigned bytes_read
)
490 struct r600_bytecode_vtx vtx
;
492 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
493 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
494 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
496 memset(&vtx
, 0, sizeof(vtx
));
499 vtx
.inst
= G_SQ_VTX_WORD0_VTX_INST(word0
);
500 vtx
.fetch_type
= G_SQ_VTX_WORD0_FETCH_TYPE(word0
);
501 vtx
.buffer_id
= G_SQ_VTX_WORD0_BUFFER_ID(word0
);
502 vtx
.src_gpr
= G_SQ_VTX_WORD0_SRC_GPR(word0
);
503 vtx
.src_sel_x
= G_SQ_VTX_WORD0_SRC_SEL_X(word0
);
504 vtx
.mega_fetch_count
= G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(word0
);
507 vtx
.dst_gpr
= G_SQ_VTX_WORD1_GPR_DST_GPR(word1
);
508 vtx
.dst_sel_x
= G_SQ_VTX_WORD1_DST_SEL_X(word1
);
509 vtx
.dst_sel_y
= G_SQ_VTX_WORD1_DST_SEL_Y(word1
);
510 vtx
.dst_sel_z
= G_SQ_VTX_WORD1_DST_SEL_Z(word1
);
511 vtx
.dst_sel_w
= G_SQ_VTX_WORD1_DST_SEL_W(word1
);
512 vtx
.use_const_fields
= G_SQ_VTX_WORD1_USE_CONST_FIELDS(word1
);
513 vtx
.data_format
= G_SQ_VTX_WORD1_DATA_FORMAT(word1
);
514 vtx
.num_format_all
= G_SQ_VTX_WORD1_NUM_FORMAT_ALL(word1
);
515 vtx
.format_comp_all
= G_SQ_VTX_WORD1_FORMAT_COMP_ALL(word1
);
516 vtx
.srf_mode_all
= G_SQ_VTX_WORD1_SRF_MODE_ALL(word1
);
519 vtx
.offset
= G_SQ_VTX_WORD2_OFFSET(word2
);
520 vtx
.endian
= G_SQ_VTX_WORD2_ENDIAN_SWAP(word2
);
522 if (r600_bytecode_add_vtx(ctx
->bc
, &vtx
)) {
523 fprintf(stderr
, "Error adding vtx\n");
525 /* Use the Texture Cache */
526 ctx
->bc
->cf_last
->inst
= EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX
;
530 static int r600_export_from_byte_stream(struct r600_shader_ctx
*ctx
,
531 unsigned char * bytes
, unsigned bytes_read
)
533 struct r600_bytecode_output output
;
534 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
535 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
536 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
537 if (ctx
->bc
->chip_class
>= EVERGREEN
)
538 eg_bytecode_export_read(&output
, word0
,word1
);
540 r600_bytecode_export_read(&output
, word0
,word1
);
541 r600_bytecode_add_output(ctx
->bc
, &output
);
545 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
546 unsigned char * bytes
, unsigned num_bytes
)
548 unsigned bytes_read
= 0;
550 while (bytes_read
< num_bytes
) {
551 char inst_type
= bytes
[bytes_read
++];
554 bytes_read
= r600_alu_from_byte_stream(ctx
, bytes
,
558 bytes_read
= r600_tex_from_byte_stream(ctx
, bytes
,
562 bytes_read
= r600_fc_from_byte_stream(ctx
, bytes
,
566 r600_bytecode_add_cfinst(ctx
->bc
, CF_NATIVE
);
567 for (i
= 0; i
< 2; i
++) {
568 for (byte
= 0 ; byte
< 4; byte
++) {
569 ctx
->bc
->cf_last
->isa
[i
] |=
570 (bytes
[bytes_read
++] << (byte
* 8));
576 bytes_read
= r600_vtx_from_byte_stream(ctx
, bytes
,
580 bytes_read
= r600_export_from_byte_stream(ctx
, bytes
,
584 /* XXX: Error here */
590 /* End bytestream -> r600 shader functions*/
592 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
594 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
597 if (i
->Instruction
.NumDstRegs
> 1) {
598 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
601 if (i
->Instruction
.Predicate
) {
602 R600_ERR("predicate unsupported\n");
606 if (i
->Instruction
.Label
) {
607 R600_ERR("label unsupported\n");
611 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
612 if (i
->Src
[j
].Register
.Dimension
) {
613 R600_ERR("unsupported src %d (dimension %d)\n", j
,
614 i
->Src
[j
].Register
.Dimension
);
618 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
619 if (i
->Dst
[j
].Register
.Dimension
) {
620 R600_ERR("unsupported dst (dimension)\n");
627 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
630 struct r600_bytecode_alu alu
;
631 int gpr
= 0, base_chan
= 0;
634 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
636 if (ctx
->shader
->input
[input
].centroid
)
638 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
640 /* if we have perspective add one */
641 if (ctx
->input_perspective
) {
643 /* if we have perspective centroid */
644 if (ctx
->input_centroid
)
647 if (ctx
->shader
->input
[input
].centroid
)
651 /* work out gpr and base_chan from index */
653 base_chan
= (2 * (ij_index
% 2)) + 1;
655 for (i
= 0; i
< 8; i
++) {
656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
659 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_ZW
;
661 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_XY
;
663 if ((i
> 1) && (i
< 6)) {
664 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
668 alu
.dst
.chan
= i
% 4;
670 alu
.src
[0].sel
= gpr
;
671 alu
.src
[0].chan
= (base_chan
- (i
% 2));
673 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
675 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
678 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
685 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
688 struct r600_bytecode_alu alu
;
690 for (i
= 0; i
< 4; i
++) {
691 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
693 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INTERP_LOAD_P0
;
695 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
700 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
705 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
713 * Special export handling in shaders
715 * shader export ARRAY_BASE for EXPORT_POS:
718 * 62, 63 are clip distance vectors
720 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
721 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
722 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
723 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
724 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
725 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
726 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
727 * exclusive from render target index)
728 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
731 * shader export ARRAY_BASE for EXPORT_PIXEL:
733 * 61 computed Z vector
735 * The use of the values exported in the computed Z vector are controlled
736 * by DB_SHADER_CONTROL:
737 * Z_EXPORT_ENABLE - Z as a float in RED
738 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
739 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
740 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
741 * DB_SOURCE_FORMAT - export control restrictions
746 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
747 static int r600_spi_sid(struct r600_shader_io
* io
)
749 int index
, name
= io
->name
;
751 /* These params are handled differently, they don't need
752 * semantic indices, so we'll use 0 for them.
754 if (name
== TGSI_SEMANTIC_POSITION
||
755 name
== TGSI_SEMANTIC_PSIZE
||
756 name
== TGSI_SEMANTIC_FACE
)
759 if (name
== TGSI_SEMANTIC_GENERIC
) {
760 /* For generic params simply use sid from tgsi */
763 /* For non-generic params - pack name and sid into 8 bits */
764 index
= 0x80 | (name
<<3) | (io
->sid
);
767 /* Make sure that all really used indices have nonzero value, so
768 * we can just compare it to 0 later instead of comparing the name
769 * with different values to detect special cases. */
776 /* turn input into interpolate on EG */
777 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
781 if (ctx
->shader
->input
[index
].spi_sid
) {
782 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
783 if (!ctx
->use_llvm
) {
784 if (ctx
->shader
->input
[index
].interpolate
> 0) {
785 r
= evergreen_interp_alu(ctx
, index
);
787 r
= evergreen_interp_flat(ctx
, index
);
794 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
796 struct r600_bytecode_alu alu
;
798 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
799 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
801 for (i
= 0; i
< 4; i
++) {
802 memset(&alu
, 0, sizeof(alu
));
803 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT
);
806 alu
.dst
.sel
= gpr_front
;
807 alu
.src
[0].sel
= ctx
->face_gpr
;
808 alu
.src
[1].sel
= gpr_front
;
809 alu
.src
[2].sel
= gpr_back
;
816 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
823 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
825 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
829 switch (d
->Declaration
.File
) {
830 case TGSI_FILE_INPUT
:
831 i
= ctx
->shader
->ninput
++;
832 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
833 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
834 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
835 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
836 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
837 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
838 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
839 switch (ctx
->shader
->input
[i
].name
) {
840 case TGSI_SEMANTIC_FACE
:
841 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
843 case TGSI_SEMANTIC_COLOR
:
846 case TGSI_SEMANTIC_POSITION
:
847 ctx
->fragcoord_input
= i
;
850 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
851 if ((r
= evergreen_interp_input(ctx
, i
)))
856 case TGSI_FILE_OUTPUT
:
857 i
= ctx
->shader
->noutput
++;
858 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
859 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
860 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
861 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
862 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
863 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
864 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
865 switch (d
->Semantic
.Name
) {
866 case TGSI_SEMANTIC_CLIPDIST
:
867 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
869 case TGSI_SEMANTIC_PSIZE
:
870 ctx
->shader
->vs_out_misc_write
= 1;
871 ctx
->shader
->vs_out_point_size
= 1;
873 case TGSI_SEMANTIC_CLIPVERTEX
:
874 ctx
->clip_vertex_write
= TRUE
;
878 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
879 switch (d
->Semantic
.Name
) {
880 case TGSI_SEMANTIC_COLOR
:
881 ctx
->shader
->nr_ps_max_color_exports
++;
886 case TGSI_FILE_CONSTANT
:
887 case TGSI_FILE_TEMPORARY
:
888 case TGSI_FILE_SAMPLER
:
889 case TGSI_FILE_ADDRESS
:
892 case TGSI_FILE_SYSTEM_VALUE
:
893 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
894 if (!ctx
->native_integers
) {
895 struct r600_bytecode_alu alu
;
896 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
898 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
);
907 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
911 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
914 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
920 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
922 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
926 * for evergreen we need to scan the shader to find the number of GPRs we need to
927 * reserve for interpolation.
929 * we need to know if we are going to emit
930 * any centroid inputs
931 * if perspective and linear are required
933 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
938 ctx
->input_linear
= FALSE
;
939 ctx
->input_perspective
= FALSE
;
940 ctx
->input_centroid
= FALSE
;
941 ctx
->num_interp_gpr
= 1;
943 /* any centroid inputs */
944 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
945 /* skip position/face */
946 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
947 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
949 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
950 ctx
->input_linear
= TRUE
;
951 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
952 ctx
->input_perspective
= TRUE
;
953 if (ctx
->info
.input_centroid
[i
])
954 ctx
->input_centroid
= TRUE
;
958 /* ignoring sample for now */
959 if (ctx
->input_perspective
)
961 if (ctx
->input_linear
)
963 if (ctx
->input_centroid
)
966 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
968 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
969 return ctx
->num_interp_gpr
;
972 static void tgsi_src(struct r600_shader_ctx
*ctx
,
973 const struct tgsi_full_src_register
*tgsi_src
,
974 struct r600_shader_src
*r600_src
)
976 memset(r600_src
, 0, sizeof(*r600_src
));
977 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
978 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
979 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
980 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
981 r600_src
->neg
= tgsi_src
->Register
.Negate
;
982 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
984 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
986 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
987 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
988 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
990 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
991 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
992 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
995 index
= tgsi_src
->Register
.Index
;
996 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
997 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
998 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
999 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1000 r600_src
->swizzle
[0] = 3;
1001 r600_src
->swizzle
[1] = 3;
1002 r600_src
->swizzle
[2] = 3;
1003 r600_src
->swizzle
[3] = 3;
1005 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1006 r600_src
->swizzle
[0] = 0;
1007 r600_src
->swizzle
[1] = 0;
1008 r600_src
->swizzle
[2] = 0;
1009 r600_src
->swizzle
[3] = 0;
1013 if (tgsi_src
->Register
.Indirect
)
1014 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1015 r600_src
->sel
= tgsi_src
->Register
.Index
;
1016 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1020 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int offset
, unsigned int dst_reg
)
1022 struct r600_bytecode_vtx vtx
;
1023 unsigned int ar_reg
;
1027 struct r600_bytecode_alu alu
;
1029 memset(&alu
, 0, sizeof(alu
));
1031 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
);
1032 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1034 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1035 alu
.src
[1].value
= offset
;
1037 alu
.dst
.sel
= dst_reg
;
1041 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1046 ar_reg
= ctx
->bc
->ar_reg
;
1049 memset(&vtx
, 0, sizeof(vtx
));
1050 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
1051 vtx
.src_gpr
= ar_reg
;
1052 vtx
.mega_fetch_count
= 16;
1053 vtx
.dst_gpr
= dst_reg
;
1054 vtx
.dst_sel_x
= 0; /* SEL_X */
1055 vtx
.dst_sel_y
= 1; /* SEL_Y */
1056 vtx
.dst_sel_z
= 2; /* SEL_Z */
1057 vtx
.dst_sel_w
= 3; /* SEL_W */
1058 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1059 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1060 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1061 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1062 vtx
.endian
= r600_endian_swap(32);
1064 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1070 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1072 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1073 struct r600_bytecode_alu alu
;
1074 int i
, j
, k
, nconst
, r
;
1076 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1077 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1080 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1082 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1083 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1087 if (ctx
->src
[i
].rel
) {
1088 int treg
= r600_get_temp(ctx
);
1089 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].sel
- 512, treg
)))
1092 ctx
->src
[i
].sel
= treg
;
1093 ctx
->src
[i
].rel
= 0;
1096 int treg
= r600_get_temp(ctx
);
1097 for (k
= 0; k
< 4; k
++) {
1098 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1099 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
1100 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1101 alu
.src
[0].chan
= k
;
1102 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1108 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1112 ctx
->src
[i
].sel
= treg
;
1120 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1121 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1123 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1124 struct r600_bytecode_alu alu
;
1125 int i
, j
, k
, nliteral
, r
;
1127 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1128 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1132 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1133 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1134 int treg
= r600_get_temp(ctx
);
1135 for (k
= 0; k
< 4; k
++) {
1136 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1137 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
1138 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1139 alu
.src
[0].chan
= k
;
1140 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1146 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1150 ctx
->src
[i
].sel
= treg
;
1157 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1159 int i
, r
, count
= ctx
->shader
->ninput
;
1161 for (i
= 0; i
< count
; i
++) {
1162 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1163 unsigned back_facing_reg
= ctx
->shader
->input
[i
].potential_back_facing_reg
;
1164 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1165 if ((r
= evergreen_interp_input(ctx
, back_facing_reg
)))
1169 if (!ctx
->use_llvm
) {
1170 r
= select_twoside_color(ctx
, i
, back_facing_reg
);
1179 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
1180 struct r600_pipe_shader
*pipeshader
,
1181 struct r600_shader_key key
)
1183 struct r600_shader
*shader
= &pipeshader
->shader
;
1184 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1185 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1186 struct tgsi_full_immediate
*immediate
;
1187 struct tgsi_full_property
*property
;
1188 struct r600_shader_ctx ctx
;
1189 struct r600_bytecode_output output
[32];
1190 unsigned output_done
, noutput
;
1193 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
1194 /* Declarations used by llvm code */
1195 bool use_llvm
= false;
1196 unsigned char * inst_bytes
= NULL
;
1197 unsigned inst_byte_count
= 0;
1199 #ifdef R600_USE_LLVM
1200 use_llvm
= debug_get_bool_option("R600_LLVM", TRUE
);
1202 ctx
.bc
= &shader
->bc
;
1203 ctx
.shader
= shader
;
1204 ctx
.native_integers
= true;
1206 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
1207 rscreen
->msaa_texture_support
);
1208 ctx
.tokens
= tokens
;
1209 tgsi_scan_shader(tokens
, &ctx
.info
);
1210 tgsi_parse_init(&ctx
.parse
, tokens
);
1211 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1212 shader
->processor_type
= ctx
.type
;
1213 ctx
.bc
->type
= shader
->processor_type
;
1216 ctx
.fragcoord_input
= -1;
1217 ctx
.colors_used
= 0;
1218 ctx
.clip_vertex_write
= 0;
1220 shader
->nr_ps_color_exports
= 0;
1221 shader
->nr_ps_max_color_exports
= 0;
1223 shader
->two_side
= key
.color_two_side
;
1225 /* register allocations */
1226 /* Values [0,127] correspond to GPR[0..127].
1227 * Values [128,159] correspond to constant buffer bank 0
1228 * Values [160,191] correspond to constant buffer bank 1
1229 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1230 * Values [256,287] correspond to constant buffer bank 2 (EG)
1231 * Values [288,319] correspond to constant buffer bank 3 (EG)
1232 * Other special values are shown in the list below.
1233 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1234 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1235 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1236 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1237 * 248 SQ_ALU_SRC_0: special constant 0.0.
1238 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1239 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1240 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1241 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1242 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1243 * 254 SQ_ALU_SRC_PV: previous vector result.
1244 * 255 SQ_ALU_SRC_PS: previous scalar result.
1246 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1247 ctx
.file_offset
[i
] = 0;
1249 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1250 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1251 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1252 r600_bytecode_add_cfinst(ctx
.bc
, EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
);
1254 r600_bytecode_add_cfinst(ctx
.bc
, V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
);
1257 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1258 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1261 #ifdef R600_USE_LLVM
1262 if (use_llvm
&& ctx
.info
.indirect_files
) {
1263 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1264 "indirect adressing. Falling back to TGSI "
1269 ctx
.use_llvm
= use_llvm
;
1272 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1273 ctx
.file_offset
[TGSI_FILE_INPUT
];
1275 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1276 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1277 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1279 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1280 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1282 /* Outside the GPR range. This will be translated to one of the
1283 * kcache banks later. */
1284 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1286 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1287 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1288 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1289 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1292 ctx
.literals
= NULL
;
1293 shader
->fs_write_all
= FALSE
;
1294 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1295 tgsi_parse_token(&ctx
.parse
);
1296 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1297 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1298 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1299 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1300 if(ctx
.literals
== NULL
) {
1304 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1305 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1306 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1307 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1310 case TGSI_TOKEN_TYPE_DECLARATION
:
1311 r
= tgsi_declaration(&ctx
);
1315 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1317 case TGSI_TOKEN_TYPE_PROPERTY
:
1318 property
= &ctx
.parse
.FullToken
.FullProperty
;
1319 switch (property
->Property
.PropertyName
) {
1320 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1321 if (property
->u
[0].Data
== 1)
1322 shader
->fs_write_all
= TRUE
;
1324 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1325 /* we don't need this one */
1330 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1336 /* Process two side if needed */
1337 if (shader
->two_side
&& ctx
.colors_used
) {
1338 int i
, count
= ctx
.shader
->ninput
;
1339 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1341 /* additional inputs will be allocated right after the existing inputs,
1342 * we won't need them after the color selection, so we don't need to
1343 * reserve these gprs for the rest of the shader code and to adjust
1344 * output offsets etc. */
1345 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1346 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1348 if (ctx
.face_gpr
== -1) {
1349 i
= ctx
.shader
->ninput
++;
1350 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1351 ctx
.shader
->input
[i
].spi_sid
= 0;
1352 ctx
.shader
->input
[i
].gpr
= gpr
++;
1353 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1356 for (i
= 0; i
< count
; i
++) {
1357 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1358 int ni
= ctx
.shader
->ninput
++;
1359 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1360 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1361 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1362 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1363 // TGSI to LLVM needs to know the lds position of inputs.
1364 // Non LLVM path computes it later (in process_twoside_color)
1365 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1366 ctx
.shader
->input
[i
].potential_back_facing_reg
= ni
;
1371 /* LLVM backend setup */
1372 #ifdef R600_USE_LLVM
1374 struct radeon_llvm_context radeon_llvm_ctx
;
1377 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1378 radeon_llvm_ctx
.reserved_reg_count
= ctx
.file_offset
[TGSI_FILE_INPUT
];
1379 radeon_llvm_ctx
.type
= ctx
.type
;
1380 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1381 radeon_llvm_ctx
.face_input
= ctx
.face_gpr
;
1382 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1383 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1384 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1385 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1386 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1387 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1388 if (debug_get_bool_option("R600_DUMP_SHADERS", FALSE
)) {
1391 if (r600_llvm_compile(mod
, &inst_bytes
, &inst_byte_count
,
1392 rscreen
->family
, dump
)) {
1394 radeon_llvm_dispose(&radeon_llvm_ctx
);
1396 fprintf(stderr
, "R600 LLVM backend failed to compile "
1397 "shader. Falling back to TGSI\n");
1399 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1400 ctx
.file_offset
[TGSI_FILE_INPUT
];
1402 radeon_llvm_dispose(&radeon_llvm_ctx
);
1405 /* End of LLVM backend setup */
1407 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1408 shader
->nr_ps_max_color_exports
= 8;
1410 if (ctx
.fragcoord_input
>= 0 && !use_llvm
) {
1411 if (ctx
.bc
->chip_class
== CAYMAN
) {
1412 for (j
= 0 ; j
< 4; j
++) {
1413 struct r600_bytecode_alu alu
;
1414 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1415 alu
.inst
= BC_INST(ctx
.bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
1416 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1417 alu
.src
[0].chan
= 3;
1419 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1421 alu
.dst
.write
= (j
== 3);
1423 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1427 struct r600_bytecode_alu alu
;
1428 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1429 alu
.inst
= BC_INST(ctx
.bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
1430 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1431 alu
.src
[0].chan
= 3;
1433 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1437 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1442 if (shader
->two_side
&& ctx
.colors_used
) {
1443 if ((r
= process_twoside_color_inputs(&ctx
)))
1447 tgsi_parse_init(&ctx
.parse
, tokens
);
1448 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1449 tgsi_parse_token(&ctx
.parse
);
1450 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1451 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1455 r
= tgsi_is_supported(&ctx
);
1458 ctx
.max_driver_temp_used
= 0;
1459 /* reserve first tmp for everyone */
1460 r600_get_temp(&ctx
);
1462 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1463 if ((r
= tgsi_split_constant(&ctx
)))
1465 if ((r
= tgsi_split_literal_constant(&ctx
)))
1467 if (ctx
.bc
->chip_class
== CAYMAN
)
1468 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1469 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1470 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1472 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1473 r
= ctx
.inst_info
->process(&ctx
);
1482 /* Get instructions if we are using the LLVM backend. */
1484 r600_bytecode_from_byte_stream(&ctx
, inst_bytes
, inst_byte_count
);
1488 noutput
= shader
->noutput
;
1490 if (ctx
.clip_vertex_write
) {
1491 /* need to convert a clipvertex write into clipdistance writes and not export
1492 the clip vertex anymore */
1494 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1495 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1496 shader
->output
[noutput
].gpr
= ctx
.temp_reg
;
1498 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1499 shader
->output
[noutput
].gpr
= ctx
.temp_reg
+1;
1502 /* reset spi_sid for clipvertex output to avoid confusing spi */
1503 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1505 shader
->clip_dist_write
= 0xFF;
1507 for (i
= 0; i
< 8; i
++) {
1511 for (j
= 0; j
< 4; j
++) {
1512 struct r600_bytecode_alu alu
;
1513 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1514 alu
.inst
= BC_INST(ctx
.bc
, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
);
1515 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1516 alu
.src
[0].chan
= j
;
1518 alu
.src
[1].sel
= 512 + i
;
1519 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1520 alu
.src
[1].chan
= j
;
1522 alu
.dst
.sel
= ctx
.temp_reg
+ oreg
;
1524 alu
.dst
.write
= (j
== ochan
);
1527 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1534 /* Add stream outputs. */
1535 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
) {
1536 for (i
= 0; i
< so
.num_outputs
; i
++) {
1537 struct r600_bytecode_output output
;
1539 if (so
.output
[i
].output_buffer
>= 4) {
1540 R600_ERR("exceeded the max number of stream output buffers, got: %d\n",
1541 so
.output
[i
].output_buffer
);
1545 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1546 R600_ERR("stream_output - dst_offset cannot be less than start_component\n");
1551 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1552 output
.gpr
= shader
->output
[so
.output
[i
].register_index
].gpr
;
1553 output
.elem_size
= 0;
1554 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1555 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1556 output
.burst_count
= 1;
1558 /* array_size is an upper limit for the burst_count
1559 * with MEM_STREAM instructions */
1560 output
.array_size
= 0xFFF;
1561 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1562 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1563 switch (so
.output
[i
].output_buffer
) {
1565 output
.inst
= EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0
;
1568 output
.inst
= EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1
;
1571 output
.inst
= EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2
;
1574 output
.inst
= EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3
;
1578 switch (so
.output
[i
].output_buffer
) {
1580 output
.inst
= V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0
;
1583 output
.inst
= V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1
;
1586 output
.inst
= V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2
;
1589 output
.inst
= V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3
;
1593 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1600 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1601 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1602 output
[j
].gpr
= shader
->output
[i
].gpr
;
1603 output
[j
].elem_size
= 3;
1604 output
[j
].swizzle_x
= 0;
1605 output
[j
].swizzle_y
= 1;
1606 output
[j
].swizzle_z
= 2;
1607 output
[j
].swizzle_w
= 3;
1608 output
[j
].burst_count
= 1;
1609 output
[j
].barrier
= 1;
1610 output
[j
].type
= -1;
1611 output
[j
].inst
= BC_INST(ctx
.bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
);
1613 case TGSI_PROCESSOR_VERTEX
:
1614 switch (shader
->output
[i
].name
) {
1615 case TGSI_SEMANTIC_POSITION
:
1616 output
[j
].array_base
= next_pos_base
++;
1617 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1620 case TGSI_SEMANTIC_PSIZE
:
1621 output
[j
].array_base
= next_pos_base
++;
1622 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1624 case TGSI_SEMANTIC_CLIPVERTEX
:
1627 case TGSI_SEMANTIC_CLIPDIST
:
1628 output
[j
].array_base
= next_pos_base
++;
1629 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1630 /* spi_sid is 0 for clipdistance outputs that were generated
1631 * for clipvertex - we don't need to pass them to PS */
1632 if (shader
->output
[i
].spi_sid
) {
1634 /* duplicate it as PARAM to pass to the pixel shader */
1635 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1636 output
[j
].array_base
= next_param_base
++;
1637 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1640 case TGSI_SEMANTIC_FOG
:
1641 output
[j
].swizzle_y
= 4; /* 0 */
1642 output
[j
].swizzle_z
= 4; /* 0 */
1643 output
[j
].swizzle_w
= 5; /* 1 */
1647 case TGSI_PROCESSOR_FRAGMENT
:
1648 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1649 /* never export more colors than the number of CBs */
1650 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1655 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1656 output
[j
].array_base
= next_pixel_base
++;
1657 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1658 shader
->nr_ps_color_exports
++;
1659 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1660 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1662 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1663 output
[j
].gpr
= shader
->output
[i
].gpr
;
1664 output
[j
].elem_size
= 3;
1665 output
[j
].swizzle_x
= 0;
1666 output
[j
].swizzle_y
= 1;
1667 output
[j
].swizzle_z
= 2;
1668 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1669 output
[j
].burst_count
= 1;
1670 output
[j
].barrier
= 1;
1671 output
[j
].array_base
= next_pixel_base
++;
1672 output
[j
].inst
= BC_INST(ctx
.bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
);
1673 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1674 shader
->nr_ps_color_exports
++;
1677 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1678 output
[j
].array_base
= 61;
1679 output
[j
].swizzle_x
= 2;
1680 output
[j
].swizzle_y
= 7;
1681 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1682 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1683 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1684 output
[j
].array_base
= 61;
1685 output
[j
].swizzle_x
= 7;
1686 output
[j
].swizzle_y
= 1;
1687 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1688 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1690 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1696 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1701 if (output
[j
].type
==-1) {
1702 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1703 output
[j
].array_base
= next_param_base
++;
1707 /* add fake param output for vertex shader if no param is exported */
1708 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1709 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1711 output
[j
].elem_size
= 3;
1712 output
[j
].swizzle_x
= 7;
1713 output
[j
].swizzle_y
= 7;
1714 output
[j
].swizzle_z
= 7;
1715 output
[j
].swizzle_w
= 7;
1716 output
[j
].burst_count
= 1;
1717 output
[j
].barrier
= 1;
1718 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1719 output
[j
].array_base
= 0;
1720 output
[j
].inst
= BC_INST(ctx
.bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
);
1724 /* add fake pixel export */
1725 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1726 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1728 output
[j
].elem_size
= 3;
1729 output
[j
].swizzle_x
= 7;
1730 output
[j
].swizzle_y
= 7;
1731 output
[j
].swizzle_z
= 7;
1732 output
[j
].swizzle_w
= 7;
1733 output
[j
].burst_count
= 1;
1734 output
[j
].barrier
= 1;
1735 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1736 output
[j
].array_base
= 0;
1737 output
[j
].inst
= BC_INST(ctx
.bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
);
1743 /* set export done on last export of each type */
1744 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1745 if (ctx
.bc
->chip_class
< CAYMAN
) {
1746 if (i
== (noutput
- 1)) {
1747 output
[i
].end_of_program
= 1;
1750 if (!(output_done
& (1 << output
[i
].type
))) {
1751 output_done
|= (1 << output
[i
].type
);
1752 output
[i
].inst
= BC_INST(ctx
.bc
, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
);
1755 /* add output to bytecode */
1756 if (!use_llvm
|| ctx
.type
!= TGSI_PROCESSOR_FRAGMENT
) {
1757 for (i
= 0; i
< noutput
; i
++) {
1758 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1763 /* add program end */
1764 if (ctx
.bc
->chip_class
== CAYMAN
)
1765 cm_bytecode_add_cf_end(ctx
.bc
);
1767 /* check GPR limit - we have 124 = 128 - 4
1768 * (4 are reserved as alu clause temporary registers) */
1769 if (ctx
.bc
->ngpr
> 124) {
1770 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1776 tgsi_parse_free(&ctx
.parse
);
1780 tgsi_parse_free(&ctx
.parse
);
1784 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1786 R600_ERR("%s tgsi opcode unsupported\n",
1787 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1791 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1796 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1797 const struct r600_shader_src
*shader_src
,
1800 bc_src
->sel
= shader_src
->sel
;
1801 bc_src
->chan
= shader_src
->swizzle
[chan
];
1802 bc_src
->neg
= shader_src
->neg
;
1803 bc_src
->abs
= shader_src
->abs
;
1804 bc_src
->rel
= shader_src
->rel
;
1805 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1808 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1814 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1816 bc_src
->neg
= !bc_src
->neg
;
1819 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1820 const struct tgsi_full_dst_register
*tgsi_dst
,
1822 struct r600_bytecode_alu_dst
*r600_dst
)
1824 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1826 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1827 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1828 r600_dst
->chan
= swizzle
;
1829 r600_dst
->write
= 1;
1830 if (tgsi_dst
->Register
.Indirect
)
1831 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1832 if (inst
->Instruction
.Saturate
) {
1833 r600_dst
->clamp
= 1;
1837 static int tgsi_last_instruction(unsigned writemask
)
1841 for (i
= 0; i
< 4; i
++) {
1842 if (writemask
& (1 << i
)) {
1849 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1851 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1852 struct r600_bytecode_alu alu
;
1854 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1856 for (i
= 0; i
< lasti
+ 1; i
++) {
1857 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1860 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1861 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1863 alu
.inst
= ctx
->inst_info
->r600_opcode
;
1865 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1866 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
1869 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
1870 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1872 /* handle some special cases */
1873 switch (ctx
->inst_info
->tgsi_opcode
) {
1874 case TGSI_OPCODE_SUB
:
1875 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
1877 case TGSI_OPCODE_ABS
:
1878 r600_bytecode_src_set_abs(&alu
.src
[0]);
1883 if (i
== lasti
|| trans_only
) {
1886 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1893 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
1895 return tgsi_op2_s(ctx
, 0, 0);
1898 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
1900 return tgsi_op2_s(ctx
, 1, 0);
1903 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
1905 return tgsi_op2_s(ctx
, 0, 1);
1908 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
1910 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1911 struct r600_bytecode_alu alu
;
1913 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1915 for (i
= 0; i
< lasti
+ 1; i
++) {
1917 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1919 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1920 alu
.inst
= ctx
->inst_info
->r600_opcode
;
1922 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1924 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1926 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1931 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1939 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
1941 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1943 struct r600_bytecode_alu alu
;
1944 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1946 for (i
= 0 ; i
< last_slot
; i
++) {
1947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1948 alu
.inst
= ctx
->inst_info
->r600_opcode
;
1949 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1950 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
1952 /* RSQ should take the absolute value of src */
1953 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
1954 r600_bytecode_src_set_abs(&alu
.src
[j
]);
1957 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1958 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1960 if (i
== last_slot
- 1)
1962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1969 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
1971 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1973 struct r600_bytecode_alu alu
;
1974 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1975 for (k
= 0; k
< last_slot
; k
++) {
1976 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
1979 for (i
= 0 ; i
< 4; i
++) {
1980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1981 alu
.inst
= ctx
->inst_info
->r600_opcode
;
1982 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1983 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
1985 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1986 alu
.dst
.write
= (i
== k
);
1989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1998 * r600 - trunc to -PI..PI range
1999 * r700 - normalize by dividing by 2PI
2002 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2004 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2005 static float double_pi
= 3.1415926535 * 2;
2006 static float neg_pi
= -3.1415926535;
2009 struct r600_bytecode_alu alu
;
2011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2012 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
);
2016 alu
.dst
.sel
= ctx
->temp_reg
;
2019 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2021 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2022 alu
.src
[1].chan
= 0;
2023 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2024 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2025 alu
.src
[2].chan
= 0;
2027 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2031 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2032 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
);
2035 alu
.dst
.sel
= ctx
->temp_reg
;
2038 alu
.src
[0].sel
= ctx
->temp_reg
;
2039 alu
.src
[0].chan
= 0;
2041 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2046 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
);
2050 alu
.dst
.sel
= ctx
->temp_reg
;
2053 alu
.src
[0].sel
= ctx
->temp_reg
;
2054 alu
.src
[0].chan
= 0;
2056 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2057 alu
.src
[1].chan
= 0;
2058 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2059 alu
.src
[2].chan
= 0;
2061 if (ctx
->bc
->chip_class
== R600
) {
2062 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2063 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2065 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2066 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2071 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2077 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2079 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2080 struct r600_bytecode_alu alu
;
2081 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2084 r
= tgsi_setup_trig(ctx
);
2089 for (i
= 0; i
< last_slot
; i
++) {
2090 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2091 alu
.inst
= ctx
->inst_info
->r600_opcode
;
2094 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2095 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2097 alu
.src
[0].sel
= ctx
->temp_reg
;
2098 alu
.src
[0].chan
= 0;
2099 if (i
== last_slot
- 1)
2101 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2108 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2110 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2111 struct r600_bytecode_alu alu
;
2113 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2115 r
= tgsi_setup_trig(ctx
);
2119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2120 alu
.inst
= ctx
->inst_info
->r600_opcode
;
2122 alu
.dst
.sel
= ctx
->temp_reg
;
2125 alu
.src
[0].sel
= ctx
->temp_reg
;
2126 alu
.src
[0].chan
= 0;
2128 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2132 /* replicate result */
2133 for (i
= 0; i
< lasti
+ 1; i
++) {
2134 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2137 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2138 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
2140 alu
.src
[0].sel
= ctx
->temp_reg
;
2141 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2144 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2151 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2153 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2154 struct r600_bytecode_alu alu
;
2157 /* We'll only need the trig stuff if we are going to write to the
2158 * X or Y components of the destination vector.
2160 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2161 r
= tgsi_setup_trig(ctx
);
2167 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2168 if (ctx
->bc
->chip_class
== CAYMAN
) {
2169 for (i
= 0 ; i
< 3; i
++) {
2170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2171 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
);
2172 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2178 alu
.src
[0].sel
= ctx
->temp_reg
;
2179 alu
.src
[0].chan
= 0;
2182 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2188 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
);
2189 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2191 alu
.src
[0].sel
= ctx
->temp_reg
;
2192 alu
.src
[0].chan
= 0;
2194 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2201 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2202 if (ctx
->bc
->chip_class
== CAYMAN
) {
2203 for (i
= 0 ; i
< 3; i
++) {
2204 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2205 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
);
2206 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2211 alu
.src
[0].sel
= ctx
->temp_reg
;
2212 alu
.src
[0].chan
= 0;
2215 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2220 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2221 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
);
2222 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2224 alu
.src
[0].sel
= ctx
->temp_reg
;
2225 alu
.src
[0].chan
= 0;
2227 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2234 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2237 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
2239 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2241 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2242 alu
.src
[0].chan
= 0;
2246 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2252 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2255 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
2257 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2259 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2260 alu
.src
[0].chan
= 0;
2264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2272 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2274 struct r600_bytecode_alu alu
;
2277 for (i
= 0; i
< 4; i
++) {
2278 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2279 alu
.inst
= ctx
->inst_info
->r600_opcode
;
2283 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2285 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2286 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2289 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2294 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2299 /* kill must be last in ALU */
2300 ctx
->bc
->force_add_cf
= 1;
2301 ctx
->shader
->uses_kill
= TRUE
;
2305 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2307 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2308 struct r600_bytecode_alu alu
;
2311 /* tmp.x = max(src.y, 0.0) */
2312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2313 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
);
2314 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2315 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2316 alu
.src
[1].chan
= 1;
2318 alu
.dst
.sel
= ctx
->temp_reg
;
2323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2327 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2333 if (ctx
->bc
->chip_class
== CAYMAN
) {
2334 for (i
= 0; i
< 3; i
++) {
2335 /* tmp.z = log(tmp.x) */
2336 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2337 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
);
2338 alu
.src
[0].sel
= ctx
->temp_reg
;
2339 alu
.src
[0].chan
= 0;
2340 alu
.dst
.sel
= ctx
->temp_reg
;
2348 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2353 /* tmp.z = log(tmp.x) */
2354 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2355 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
);
2356 alu
.src
[0].sel
= ctx
->temp_reg
;
2357 alu
.src
[0].chan
= 0;
2358 alu
.dst
.sel
= ctx
->temp_reg
;
2362 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2367 chan
= alu
.dst
.chan
;
2370 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2371 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2372 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT
);
2373 alu
.src
[0].sel
= sel
;
2374 alu
.src
[0].chan
= chan
;
2375 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2376 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2377 alu
.dst
.sel
= ctx
->temp_reg
;
2382 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2386 if (ctx
->bc
->chip_class
== CAYMAN
) {
2387 for (i
= 0; i
< 3; i
++) {
2388 /* dst.z = exp(tmp.x) */
2389 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2390 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
2391 alu
.src
[0].sel
= ctx
->temp_reg
;
2392 alu
.src
[0].chan
= 0;
2393 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2404 /* dst.z = exp(tmp.x) */
2405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2406 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
2407 alu
.src
[0].sel
= ctx
->temp_reg
;
2408 alu
.src
[0].chan
= 0;
2409 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2418 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2419 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
2420 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2421 alu
.src
[0].chan
= 0;
2422 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2423 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2428 /* dst.y = max(src.x, 0.0) */
2429 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2430 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
);
2431 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2432 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2433 alu
.src
[1].chan
= 0;
2434 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2435 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2436 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2441 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2442 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
2443 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2444 alu
.src
[0].chan
= 0;
2445 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2446 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2448 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2455 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2457 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2458 struct r600_bytecode_alu alu
;
2461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2464 * For state trackers other than OpenGL, we'll want to use
2465 * _RECIPSQRT_IEEE instead.
2467 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED
);
2469 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2470 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2471 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2473 alu
.dst
.sel
= ctx
->temp_reg
;
2476 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2479 /* replicate result */
2480 return tgsi_helper_tempx_replicate(ctx
);
2483 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2485 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2486 struct r600_bytecode_alu alu
;
2489 for (i
= 0; i
< 4; i
++) {
2490 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2491 alu
.src
[0].sel
= ctx
->temp_reg
;
2492 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
2494 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2495 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2498 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2505 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2507 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2508 struct r600_bytecode_alu alu
;
2511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2512 alu
.inst
= ctx
->inst_info
->r600_opcode
;
2513 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2514 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2516 alu
.dst
.sel
= ctx
->temp_reg
;
2519 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2522 /* replicate result */
2523 return tgsi_helper_tempx_replicate(ctx
);
2526 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2528 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2530 struct r600_bytecode_alu alu
;
2531 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2533 for (i
= 0; i
< 3; i
++) {
2534 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2535 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
2536 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2537 alu
.dst
.sel
= ctx
->temp_reg
;
2542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2549 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
2550 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2551 alu
.src
[1].sel
= ctx
->temp_reg
;
2552 alu
.dst
.sel
= ctx
->temp_reg
;
2555 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2559 for (i
= 0; i
< last_slot
; i
++) {
2560 /* POW(a,b) = EXP2(b * LOG2(a))*/
2561 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2562 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
2563 alu
.src
[0].sel
= ctx
->temp_reg
;
2565 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2566 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2567 if (i
== last_slot
- 1)
2569 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2576 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2578 struct r600_bytecode_alu alu
;
2582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2583 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
2584 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2585 alu
.dst
.sel
= ctx
->temp_reg
;
2588 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2593 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
2594 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2595 alu
.src
[1].sel
= ctx
->temp_reg
;
2596 alu
.dst
.sel
= ctx
->temp_reg
;
2599 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2602 /* POW(a,b) = EXP2(b * LOG2(a))*/
2603 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2604 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
2605 alu
.src
[0].sel
= ctx
->temp_reg
;
2606 alu
.dst
.sel
= ctx
->temp_reg
;
2609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2612 return tgsi_helper_tempx_replicate(ctx
);
2615 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2617 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2618 struct r600_bytecode_alu alu
;
2620 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2621 int tmp0
= ctx
->temp_reg
;
2622 int tmp1
= r600_get_temp(ctx
);
2623 int tmp2
= r600_get_temp(ctx
);
2624 int tmp3
= r600_get_temp(ctx
);
2627 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2629 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2630 * 2. tmp0.z = lo (tmp0.x * src2)
2631 * 3. tmp0.w = -tmp0.z
2632 * 4. tmp0.y = hi (tmp0.x * src2)
2633 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2634 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2635 * 7. tmp1.x = tmp0.x - tmp0.w
2636 * 8. tmp1.y = tmp0.x + tmp0.w
2637 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2638 * 10. tmp0.z = hi(tmp0.x * src1) = q
2639 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2641 * 12. tmp0.w = src1 - tmp0.y = r
2642 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2643 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2647 * 15. tmp1.z = tmp0.z + 1 = q + 1
2648 * 16. tmp1.w = tmp0.z - 1 = q - 1
2652 * 15. tmp1.z = tmp0.w - src2 = r - src2
2653 * 16. tmp1.w = tmp0.w + src2 = r + src2
2657 * 17. tmp1.x = tmp1.x & tmp1.y
2659 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2660 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2662 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2663 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2667 * Same as unsigned, using abs values of the operands,
2668 * and fixing the sign of the result in the end.
2671 for (i
= 0; i
< 4; i
++) {
2672 if (!(write_mask
& (1<<i
)))
2677 /* tmp2.x = -src0 */
2678 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2679 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
2685 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2687 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2690 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2693 /* tmp2.y = -src1 */
2694 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2695 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
2701 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2703 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2706 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2709 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2710 /* it will be a sign of the quotient */
2713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2714 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
);
2720 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2721 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2724 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2728 /* tmp2.x = |src0| */
2729 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2730 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT
);
2737 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2738 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2739 alu
.src
[2].sel
= tmp2
;
2740 alu
.src
[2].chan
= 0;
2743 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2746 /* tmp2.y = |src1| */
2747 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2748 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT
);
2755 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2756 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2757 alu
.src
[2].sel
= tmp2
;
2758 alu
.src
[2].chan
= 1;
2761 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2766 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2767 if (ctx
->bc
->chip_class
== CAYMAN
) {
2768 /* tmp3.x = u2f(src2) */
2769 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2770 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
);
2777 alu
.src
[0].sel
= tmp2
;
2778 alu
.src
[0].chan
= 1;
2780 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2784 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2787 /* tmp0.x = recip(tmp3.x) */
2788 for (j
= 0 ; j
< 3; j
++) {
2789 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2790 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
;
2794 alu
.dst
.write
= (j
== 0);
2796 alu
.src
[0].sel
= tmp3
;
2797 alu
.src
[0].chan
= 0;
2801 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2805 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2806 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
2808 alu
.src
[0].sel
= tmp0
;
2809 alu
.src
[0].chan
= 0;
2811 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2812 alu
.src
[1].value
= 0x4f800000;
2817 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2821 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2822 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
);
2828 alu
.src
[0].sel
= tmp3
;
2829 alu
.src
[0].chan
= 0;
2832 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2836 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2837 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT
);
2844 alu
.src
[0].sel
= tmp2
;
2845 alu
.src
[0].chan
= 1;
2847 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2851 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2855 /* 2. tmp0.z = lo (tmp0.x * src2) */
2856 if (ctx
->bc
->chip_class
== CAYMAN
) {
2857 for (j
= 0 ; j
< 4; j
++) {
2858 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2859 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
);
2863 alu
.dst
.write
= (j
== 2);
2865 alu
.src
[0].sel
= tmp0
;
2866 alu
.src
[0].chan
= 0;
2868 alu
.src
[1].sel
= tmp2
;
2869 alu
.src
[1].chan
= 1;
2871 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2874 alu
.last
= (j
== 3);
2875 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2880 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
);
2886 alu
.src
[0].sel
= tmp0
;
2887 alu
.src
[0].chan
= 0;
2889 alu
.src
[1].sel
= tmp2
;
2890 alu
.src
[1].chan
= 1;
2892 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2896 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2900 /* 3. tmp0.w = -tmp0.z */
2901 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2902 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
2908 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2909 alu
.src
[1].sel
= tmp0
;
2910 alu
.src
[1].chan
= 2;
2913 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2916 /* 4. tmp0.y = hi (tmp0.x * src2) */
2917 if (ctx
->bc
->chip_class
== CAYMAN
) {
2918 for (j
= 0 ; j
< 4; j
++) {
2919 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2920 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2924 alu
.dst
.write
= (j
== 1);
2926 alu
.src
[0].sel
= tmp0
;
2927 alu
.src
[0].chan
= 0;
2930 alu
.src
[1].sel
= tmp2
;
2931 alu
.src
[1].chan
= 1;
2933 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2935 alu
.last
= (j
== 3);
2936 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2940 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2941 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2947 alu
.src
[0].sel
= tmp0
;
2948 alu
.src
[0].chan
= 0;
2951 alu
.src
[1].sel
= tmp2
;
2952 alu
.src
[1].chan
= 1;
2954 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2958 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2962 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
2963 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2964 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT
);
2971 alu
.src
[0].sel
= tmp0
;
2972 alu
.src
[0].chan
= 1;
2973 alu
.src
[1].sel
= tmp0
;
2974 alu
.src
[1].chan
= 3;
2975 alu
.src
[2].sel
= tmp0
;
2976 alu
.src
[2].chan
= 2;
2979 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2982 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
2983 if (ctx
->bc
->chip_class
== CAYMAN
) {
2984 for (j
= 0 ; j
< 4; j
++) {
2985 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2986 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
2990 alu
.dst
.write
= (j
== 3);
2992 alu
.src
[0].sel
= tmp0
;
2993 alu
.src
[0].chan
= 2;
2995 alu
.src
[1].sel
= tmp0
;
2996 alu
.src
[1].chan
= 0;
2998 alu
.last
= (j
== 3);
2999 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3004 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
3010 alu
.src
[0].sel
= tmp0
;
3011 alu
.src
[0].chan
= 2;
3013 alu
.src
[1].sel
= tmp0
;
3014 alu
.src
[1].chan
= 0;
3017 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3021 /* 7. tmp1.x = tmp0.x - tmp0.w */
3022 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3023 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
3029 alu
.src
[0].sel
= tmp0
;
3030 alu
.src
[0].chan
= 0;
3031 alu
.src
[1].sel
= tmp0
;
3032 alu
.src
[1].chan
= 3;
3035 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3038 /* 8. tmp1.y = tmp0.x + tmp0.w */
3039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3040 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
);
3046 alu
.src
[0].sel
= tmp0
;
3047 alu
.src
[0].chan
= 0;
3048 alu
.src
[1].sel
= tmp0
;
3049 alu
.src
[1].chan
= 3;
3052 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3055 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3056 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3057 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT
);
3064 alu
.src
[0].sel
= tmp0
;
3065 alu
.src
[0].chan
= 1;
3066 alu
.src
[1].sel
= tmp1
;
3067 alu
.src
[1].chan
= 1;
3068 alu
.src
[2].sel
= tmp1
;
3069 alu
.src
[2].chan
= 0;
3072 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3075 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3076 if (ctx
->bc
->chip_class
== CAYMAN
) {
3077 for (j
= 0 ; j
< 4; j
++) {
3078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3079 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
3083 alu
.dst
.write
= (j
== 2);
3085 alu
.src
[0].sel
= tmp0
;
3086 alu
.src
[0].chan
= 0;
3089 alu
.src
[1].sel
= tmp2
;
3090 alu
.src
[1].chan
= 0;
3092 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3095 alu
.last
= (j
== 3);
3096 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3100 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3101 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT
);
3107 alu
.src
[0].sel
= tmp0
;
3108 alu
.src
[0].chan
= 0;
3111 alu
.src
[1].sel
= tmp2
;
3112 alu
.src
[1].chan
= 0;
3114 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3118 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3122 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3123 if (ctx
->bc
->chip_class
== CAYMAN
) {
3124 for (j
= 0 ; j
< 4; j
++) {
3125 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3126 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
);
3130 alu
.dst
.write
= (j
== 1);
3133 alu
.src
[0].sel
= tmp2
;
3134 alu
.src
[0].chan
= 1;
3136 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3139 alu
.src
[1].sel
= tmp0
;
3140 alu
.src
[1].chan
= 2;
3142 alu
.last
= (j
== 3);
3143 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3147 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3148 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
);
3155 alu
.src
[0].sel
= tmp2
;
3156 alu
.src
[0].chan
= 1;
3158 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3161 alu
.src
[1].sel
= tmp0
;
3162 alu
.src
[1].chan
= 2;
3165 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3169 /* 12. tmp0.w = src1 - tmp0.y = r */
3170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3171 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
3178 alu
.src
[0].sel
= tmp2
;
3179 alu
.src
[0].chan
= 0;
3181 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3184 alu
.src
[1].sel
= tmp0
;
3185 alu
.src
[1].chan
= 1;
3188 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3191 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3192 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3193 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
);
3199 alu
.src
[0].sel
= tmp0
;
3200 alu
.src
[0].chan
= 3;
3202 alu
.src
[1].sel
= tmp2
;
3203 alu
.src
[1].chan
= 1;
3205 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3209 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3212 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3214 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
);
3221 alu
.src
[0].sel
= tmp2
;
3222 alu
.src
[0].chan
= 0;
3224 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3227 alu
.src
[1].sel
= tmp0
;
3228 alu
.src
[1].chan
= 1;
3231 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3234 if (mod
) { /* UMOD */
3236 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3237 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3238 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
3244 alu
.src
[0].sel
= tmp0
;
3245 alu
.src
[0].chan
= 3;
3248 alu
.src
[1].sel
= tmp2
;
3249 alu
.src
[1].chan
= 1;
3251 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3255 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3258 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3259 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3260 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
);
3266 alu
.src
[0].sel
= tmp0
;
3267 alu
.src
[0].chan
= 3;
3269 alu
.src
[1].sel
= tmp2
;
3270 alu
.src
[1].chan
= 1;
3272 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3276 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3281 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3282 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3283 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
);
3289 alu
.src
[0].sel
= tmp0
;
3290 alu
.src
[0].chan
= 2;
3291 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3294 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3297 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3298 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3299 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
);
3305 alu
.src
[0].sel
= tmp0
;
3306 alu
.src
[0].chan
= 2;
3307 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3310 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3315 /* 17. tmp1.x = tmp1.x & tmp1.y */
3316 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3317 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
);
3323 alu
.src
[0].sel
= tmp1
;
3324 alu
.src
[0].chan
= 0;
3325 alu
.src
[1].sel
= tmp1
;
3326 alu
.src
[1].chan
= 1;
3329 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3332 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3333 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3335 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT
);
3342 alu
.src
[0].sel
= tmp1
;
3343 alu
.src
[0].chan
= 0;
3344 alu
.src
[1].sel
= tmp0
;
3345 alu
.src
[1].chan
= mod
? 3 : 2;
3346 alu
.src
[2].sel
= tmp1
;
3347 alu
.src
[2].chan
= 2;
3350 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3353 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3354 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3355 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT
);
3363 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3366 alu
.src
[0].sel
= tmp1
;
3367 alu
.src
[0].chan
= 1;
3368 alu
.src
[1].sel
= tmp1
;
3369 alu
.src
[1].chan
= 3;
3370 alu
.src
[2].sel
= tmp0
;
3371 alu
.src
[2].chan
= 2;
3374 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3379 /* fix the sign of the result */
3383 /* tmp0.x = -tmp0.z */
3384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3385 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
3391 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3392 alu
.src
[1].sel
= tmp0
;
3393 alu
.src
[1].chan
= 2;
3396 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3399 /* sign of the remainder is the same as the sign of src0 */
3400 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3402 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT
);
3405 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3407 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3408 alu
.src
[1].sel
= tmp0
;
3409 alu
.src
[1].chan
= 2;
3410 alu
.src
[2].sel
= tmp0
;
3411 alu
.src
[2].chan
= 0;
3414 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3419 /* tmp0.x = -tmp0.z */
3420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3421 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
3427 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3428 alu
.src
[1].sel
= tmp0
;
3429 alu
.src
[1].chan
= 2;
3432 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3435 /* fix the quotient sign (same as the sign of src0*src1) */
3436 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3437 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3438 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT
);
3441 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3443 alu
.src
[0].sel
= tmp2
;
3444 alu
.src
[0].chan
= 2;
3445 alu
.src
[1].sel
= tmp0
;
3446 alu
.src
[1].chan
= 2;
3447 alu
.src
[2].sel
= tmp0
;
3448 alu
.src
[2].chan
= 0;
3451 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3459 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3461 return tgsi_divmod(ctx
, 0, 0);
3464 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3466 return tgsi_divmod(ctx
, 1, 0);
3469 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3471 return tgsi_divmod(ctx
, 0, 1);
3474 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3476 return tgsi_divmod(ctx
, 1, 1);
3480 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3482 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3483 struct r600_bytecode_alu alu
;
3485 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3486 int last_inst
= tgsi_last_instruction(write_mask
);
3488 for (i
= 0; i
< 4; i
++) {
3489 if (!(write_mask
& (1<<i
)))
3492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3493 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
);
3495 alu
.dst
.sel
= ctx
->temp_reg
;
3499 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3502 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3507 for (i
= 0; i
< 4; i
++) {
3508 if (!(write_mask
& (1<<i
)))
3511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3512 alu
.inst
= ctx
->inst_info
->r600_opcode
;
3514 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3516 alu
.src
[0].sel
= ctx
->temp_reg
;
3517 alu
.src
[0].chan
= i
;
3519 if (i
== last_inst
|| alu
.inst
== EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
)
3521 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3529 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3531 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3532 struct r600_bytecode_alu alu
;
3534 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3535 int last_inst
= tgsi_last_instruction(write_mask
);
3538 for (i
= 0; i
< 4; i
++) {
3539 if (!(write_mask
& (1<<i
)))
3542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3543 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
);
3545 alu
.dst
.sel
= ctx
->temp_reg
;
3549 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3550 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3554 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3559 /* dst = (src >= 0 ? src : tmp) */
3560 for (i
= 0; i
< 4; i
++) {
3561 if (!(write_mask
& (1<<i
)))
3564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3565 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT
);
3569 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3571 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3572 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3573 alu
.src
[2].sel
= ctx
->temp_reg
;
3574 alu
.src
[2].chan
= i
;
3578 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3585 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3587 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3588 struct r600_bytecode_alu alu
;
3590 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3591 int last_inst
= tgsi_last_instruction(write_mask
);
3593 /* tmp = (src >= 0 ? src : -1) */
3594 for (i
= 0; i
< 4; i
++) {
3595 if (!(write_mask
& (1<<i
)))
3598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3599 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT
);
3602 alu
.dst
.sel
= ctx
->temp_reg
;
3606 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3607 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3608 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3612 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3617 /* dst = (tmp > 0 ? 1 : tmp) */
3618 for (i
= 0; i
< 4; i
++) {
3619 if (!(write_mask
& (1<<i
)))
3622 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3623 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT_INT
);
3627 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3629 alu
.src
[0].sel
= ctx
->temp_reg
;
3630 alu
.src
[0].chan
= i
;
3632 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3634 alu
.src
[2].sel
= ctx
->temp_reg
;
3635 alu
.src
[2].chan
= i
;
3639 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3648 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3650 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3651 struct r600_bytecode_alu alu
;
3654 /* tmp = (src > 0 ? 1 : src) */
3655 for (i
= 0; i
< 4; i
++) {
3656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3657 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT
);
3660 alu
.dst
.sel
= ctx
->temp_reg
;
3663 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3664 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3665 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3669 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3674 /* dst = (-tmp > 0 ? -1 : tmp) */
3675 for (i
= 0; i
< 4; i
++) {
3676 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3677 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT
);
3679 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3681 alu
.src
[0].sel
= ctx
->temp_reg
;
3682 alu
.src
[0].chan
= i
;
3685 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3688 alu
.src
[2].sel
= ctx
->temp_reg
;
3689 alu
.src
[2].chan
= i
;
3693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3700 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3702 struct r600_bytecode_alu alu
;
3705 for (i
= 0; i
< 4; i
++) {
3706 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3707 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3708 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
);
3711 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
3712 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3713 alu
.src
[0].sel
= ctx
->temp_reg
;
3714 alu
.src
[0].chan
= i
;
3719 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3726 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3728 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3729 struct r600_bytecode_alu alu
;
3731 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3733 for (i
= 0; i
< lasti
+ 1; i
++) {
3734 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3738 alu
.inst
= ctx
->inst_info
->r600_opcode
;
3739 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3740 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3743 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3757 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3759 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3760 struct r600_bytecode_alu alu
;
3763 for (i
= 0; i
< 4; i
++) {
3764 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3765 alu
.inst
= ctx
->inst_info
->r600_opcode
;
3766 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3767 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3770 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3772 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3773 /* handle some special cases */
3774 switch (ctx
->inst_info
->tgsi_opcode
) {
3775 case TGSI_OPCODE_DP2
:
3777 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3778 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3781 case TGSI_OPCODE_DP3
:
3783 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3784 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3787 case TGSI_OPCODE_DPH
:
3789 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3790 alu
.src
[0].chan
= 0;
3800 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3807 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3810 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3811 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3812 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3813 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3814 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3817 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3820 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3821 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3824 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
3826 static float one_point_five
= 1.5f
;
3827 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3828 struct r600_bytecode_tex tex
;
3829 struct r600_bytecode_alu alu
;
3833 bool read_compressed_msaa
= ctx
->bc
->msaa_texture_mode
== MSAA_TEXTURE_COMPRESSED
&&
3834 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
3835 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
3836 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
3837 /* Texture fetch instructions can only use gprs as source.
3838 * Also they cannot negate the source or take the absolute value */
3839 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
3840 tgsi_tex_src_requires_loading(ctx
, 0)) ||
3841 read_compressed_msaa
;
3842 boolean src_loaded
= FALSE
;
3843 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
3844 uint8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
3846 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3848 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3849 /* get offset values */
3850 if (inst
->Texture
.NumOffsets
) {
3851 assert(inst
->Texture
.NumOffsets
== 1);
3853 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
3854 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
3855 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
3857 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
3858 /* TGSI moves the sampler to src reg 3 for TXD */
3859 sampler_src_reg
= 3;
3861 for (i
= 1; i
< 3; i
++) {
3862 /* set gradients h/v */
3863 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
3864 tex
.inst
= (i
== 1) ? SQ_TEX_INST_SET_GRADIENTS_H
:
3865 SQ_TEX_INST_SET_GRADIENTS_V
;
3866 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
3867 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
3869 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
3870 tex
.src_gpr
= r600_get_temp(ctx
);
3876 for (j
= 0; j
< 4; j
++) {
3877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3878 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
3879 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
3880 alu
.dst
.sel
= tex
.src_gpr
;
3885 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3891 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
3892 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
3893 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
3894 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
3895 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
3896 tex
.src_rel
= ctx
->src
[i
].rel
;
3898 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
3899 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
3900 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
3901 tex
.coord_type_x
= 1;
3902 tex
.coord_type_y
= 1;
3903 tex
.coord_type_z
= 1;
3904 tex
.coord_type_w
= 1;
3906 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
3910 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
3912 /* Add perspective divide */
3913 if (ctx
->bc
->chip_class
== CAYMAN
) {
3915 for (i
= 0; i
< 3; i
++) {
3916 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3917 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
3918 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3920 alu
.dst
.sel
= ctx
->temp_reg
;
3926 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3934 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
3935 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3937 alu
.dst
.sel
= ctx
->temp_reg
;
3938 alu
.dst
.chan
= out_chan
;
3941 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3946 for (i
= 0; i
< 3; i
++) {
3947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3948 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
3949 alu
.src
[0].sel
= ctx
->temp_reg
;
3950 alu
.src
[0].chan
= out_chan
;
3951 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3952 alu
.dst
.sel
= ctx
->temp_reg
;
3955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3960 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
3961 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3962 alu
.src
[0].chan
= 0;
3963 alu
.dst
.sel
= ctx
->temp_reg
;
3967 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3971 src_gpr
= ctx
->temp_reg
;
3974 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
3975 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
) &&
3976 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
3977 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
3979 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
3980 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
3982 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
3983 for (i
= 0; i
< 4; i
++) {
3984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3985 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
);
3986 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
3987 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
3988 alu
.dst
.sel
= ctx
->temp_reg
;
3993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3998 /* tmp1.z = RCP_e(|tmp1.z|) */
3999 if (ctx
->bc
->chip_class
== CAYMAN
) {
4000 for (i
= 0; i
< 3; i
++) {
4001 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4002 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
4003 alu
.src
[0].sel
= ctx
->temp_reg
;
4004 alu
.src
[0].chan
= 2;
4006 alu
.dst
.sel
= ctx
->temp_reg
;
4012 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4017 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4018 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
4019 alu
.src
[0].sel
= ctx
->temp_reg
;
4020 alu
.src
[0].chan
= 2;
4022 alu
.dst
.sel
= ctx
->temp_reg
;
4026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4031 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4032 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4033 * muladd has no writemask, have to use another temp
4035 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4036 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
);
4039 alu
.src
[0].sel
= ctx
->temp_reg
;
4040 alu
.src
[0].chan
= 0;
4041 alu
.src
[1].sel
= ctx
->temp_reg
;
4042 alu
.src
[1].chan
= 2;
4044 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4045 alu
.src
[2].chan
= 0;
4046 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4048 alu
.dst
.sel
= ctx
->temp_reg
;
4052 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4056 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4057 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
);
4060 alu
.src
[0].sel
= ctx
->temp_reg
;
4061 alu
.src
[0].chan
= 1;
4062 alu
.src
[1].sel
= ctx
->temp_reg
;
4063 alu
.src
[1].chan
= 2;
4065 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4066 alu
.src
[2].chan
= 0;
4067 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4069 alu
.dst
.sel
= ctx
->temp_reg
;
4074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4077 /* write initial W value into Z component */
4078 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
) {
4079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4080 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
4081 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4082 alu
.dst
.sel
= ctx
->temp_reg
;
4086 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4091 src_gpr
= ctx
->temp_reg
;
4094 if (src_requires_loading
&& !src_loaded
) {
4095 for (i
= 0; i
< 4; i
++) {
4096 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4097 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
4098 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4099 alu
.dst
.sel
= ctx
->temp_reg
;
4104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4109 src_gpr
= ctx
->temp_reg
;
4112 /* Obtain the sample index for reading a compressed MSAA color texture.
4113 * To read the FMASK, we use the ldfptr instruction, which tells us
4114 * where the samples are stored.
4115 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4116 * which is the identity mapping. Each nibble says which physical sample
4117 * should be fetched to get that sample.
4119 * Assume src.z contains the sample index. It should be modified like this:
4120 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4121 * Then fetch the texel with src.
4123 if (read_compressed_msaa
) {
4124 unsigned sample_chan
= inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
? 3 : 4;
4125 unsigned temp
= r600_get_temp(ctx
);
4128 /* temp.w = ldfptr() */
4129 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4130 tex
.inst
= SQ_TEX_INST_LD
;
4131 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4132 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4133 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4134 tex
.src_gpr
= src_gpr
;
4136 tex
.dst_sel_x
= 7; /* mask out these components */
4139 tex
.dst_sel_w
= 0; /* store X */
4144 tex
.offset_x
= offset_x
;
4145 tex
.offset_y
= offset_y
;
4146 tex
.offset_z
= offset_z
;
4147 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4151 /* temp.x = sample_index*4 */
4152 if (ctx
->bc
->chip_class
== CAYMAN
) {
4153 for (i
= 0 ; i
< 4; i
++) {
4154 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4155 alu
.inst
= ctx
->inst_info
->r600_opcode
;
4156 alu
.src
[0].sel
= src_gpr
;
4157 alu
.src
[0].chan
= sample_chan
;
4158 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4159 alu
.src
[1].value
= 4;
4162 alu
.dst
.write
= i
== 0;
4165 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4171 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
);
4172 alu
.src
[0].sel
= src_gpr
;
4173 alu
.src
[0].chan
= sample_chan
;
4174 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4175 alu
.src
[1].value
= 4;
4180 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4185 /* sample_index = temp.w >> temp.x */
4186 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4187 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
);
4188 alu
.src
[0].sel
= temp
;
4189 alu
.src
[0].chan
= 3;
4190 alu
.src
[1].sel
= temp
;
4191 alu
.src
[1].chan
= 0;
4192 alu
.dst
.sel
= src_gpr
;
4193 alu
.dst
.chan
= sample_chan
;
4196 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4200 /* sample_index & 0xF */
4201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4202 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
);
4203 alu
.src
[0].sel
= src_gpr
;
4204 alu
.src
[0].chan
= sample_chan
;
4205 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4206 alu
.src
[1].value
= 0xF;
4207 alu
.dst
.sel
= src_gpr
;
4208 alu
.dst
.chan
= sample_chan
;
4211 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4215 /* visualize the FMASK */
4216 for (i
= 0; i
< 4; i
++) {
4217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4218 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
);
4219 alu
.src
[0].sel
= src_gpr
;
4220 alu
.src
[0].chan
= sample_chan
;
4221 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4233 opcode
= ctx
->inst_info
->r600_opcode
;
4234 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4235 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4236 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4237 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4238 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4239 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
) {
4241 case SQ_TEX_INST_SAMPLE
:
4242 opcode
= SQ_TEX_INST_SAMPLE_C
;
4244 case SQ_TEX_INST_SAMPLE_L
:
4245 opcode
= SQ_TEX_INST_SAMPLE_C_L
;
4247 case SQ_TEX_INST_SAMPLE_LB
:
4248 opcode
= SQ_TEX_INST_SAMPLE_C_LB
;
4250 case SQ_TEX_INST_SAMPLE_G
:
4251 opcode
= SQ_TEX_INST_SAMPLE_C_G
;
4256 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4259 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4260 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4261 tex
.src_gpr
= src_gpr
;
4262 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4263 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4264 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4265 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4266 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4268 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4273 } else if (src_loaded
) {
4279 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4280 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4281 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4282 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4283 tex
.src_rel
= ctx
->src
[0].rel
;
4286 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
) {
4292 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
) {
4296 tex
.src_sel_w
= 2; /* route Z compare value into W */
4299 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4300 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4301 tex
.coord_type_x
= 1;
4302 tex
.coord_type_y
= 1;
4304 tex
.coord_type_z
= 1;
4305 tex
.coord_type_w
= 1;
4307 tex
.offset_x
= offset_x
;
4308 tex
.offset_y
= offset_y
;
4309 tex
.offset_z
= offset_z
;
4311 /* Put the depth for comparison in W.
4312 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4313 * Some instructions expect the depth in Z. */
4314 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4315 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4316 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4317 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4318 opcode
!= SQ_TEX_INST_SAMPLE_C_L
&&
4319 opcode
!= SQ_TEX_INST_SAMPLE_C_LB
) {
4320 tex
.src_sel_w
= tex
.src_sel_z
;
4323 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4324 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4325 if (opcode
== SQ_TEX_INST_SAMPLE_C_L
||
4326 opcode
== SQ_TEX_INST_SAMPLE_C_LB
) {
4327 /* the array index is read from Y */
4328 tex
.coord_type_y
= 0;
4330 /* the array index is read from Z */
4331 tex
.coord_type_z
= 0;
4332 tex
.src_sel_z
= tex
.src_sel_y
;
4334 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4335 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)
4336 /* the array index is read from Z */
4337 tex
.coord_type_z
= 0;
4339 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4343 /* add shadow ambient support - gallium doesn't do it yet */
4347 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4349 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4350 struct r600_bytecode_alu alu
;
4351 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4355 /* optimize if it's just an equal balance */
4356 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4357 for (i
= 0; i
< lasti
+ 1; i
++) {
4358 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4362 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
);
4363 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4364 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4366 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4371 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4379 for (i
= 0; i
< lasti
+ 1; i
++) {
4380 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4384 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
);
4385 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4386 alu
.src
[0].chan
= 0;
4387 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4388 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4389 alu
.dst
.sel
= ctx
->temp_reg
;
4395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4400 /* (1 - src0) * src2 */
4401 for (i
= 0; i
< lasti
+ 1; i
++) {
4402 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4406 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
4407 alu
.src
[0].sel
= ctx
->temp_reg
;
4408 alu
.src
[0].chan
= i
;
4409 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4410 alu
.dst
.sel
= ctx
->temp_reg
;
4416 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4421 /* src0 * src1 + (1 - src0) * src2 */
4422 for (i
= 0; i
< lasti
+ 1; i
++) {
4423 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4426 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4427 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
);
4429 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4430 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4431 alu
.src
[2].sel
= ctx
->temp_reg
;
4432 alu
.src
[2].chan
= i
;
4434 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4439 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4446 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4448 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4449 struct r600_bytecode_alu alu
;
4451 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4453 for (i
= 0; i
< lasti
+ 1; i
++) {
4454 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4457 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4458 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE
);
4459 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4460 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4461 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4462 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4475 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4477 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4478 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4479 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4480 struct r600_bytecode_alu alu
;
4481 uint32_t use_temp
= 0;
4484 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4487 for (i
= 0; i
< 4; i
++) {
4488 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4489 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
4491 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4492 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4494 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4495 alu
.src
[0].chan
= i
;
4496 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4497 alu
.src
[1].chan
= i
;
4500 alu
.dst
.sel
= ctx
->temp_reg
;
4506 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4511 for (i
= 0; i
< 4; i
++) {
4512 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4513 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
);
4516 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4517 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4519 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4520 alu
.src
[0].chan
= i
;
4521 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4522 alu
.src
[1].chan
= i
;
4525 alu
.src
[2].sel
= ctx
->temp_reg
;
4527 alu
.src
[2].chan
= i
;
4530 alu
.dst
.sel
= ctx
->temp_reg
;
4532 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4543 return tgsi_helper_copy(ctx
, inst
);
4547 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4549 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4550 struct r600_bytecode_alu alu
;
4554 /* result.x = 2^floor(src); */
4555 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4556 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4558 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
);
4559 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4561 alu
.dst
.sel
= ctx
->temp_reg
;
4565 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4569 if (ctx
->bc
->chip_class
== CAYMAN
) {
4570 for (i
= 0; i
< 3; i
++) {
4571 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
4572 alu
.src
[0].sel
= ctx
->temp_reg
;
4573 alu
.src
[0].chan
= 0;
4575 alu
.dst
.sel
= ctx
->temp_reg
;
4577 alu
.dst
.write
= i
== 0;
4579 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4584 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
4585 alu
.src
[0].sel
= ctx
->temp_reg
;
4586 alu
.src
[0].chan
= 0;
4588 alu
.dst
.sel
= ctx
->temp_reg
;
4592 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4598 /* result.y = tmp - floor(tmp); */
4599 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4602 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
);
4603 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4605 alu
.dst
.sel
= ctx
->temp_reg
;
4607 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4616 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4621 /* result.z = RoughApprox2ToX(tmp);*/
4622 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
4623 if (ctx
->bc
->chip_class
== CAYMAN
) {
4624 for (i
= 0; i
< 3; i
++) {
4625 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4626 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
4627 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4629 alu
.dst
.sel
= ctx
->temp_reg
;
4636 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4641 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4642 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
4643 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4645 alu
.dst
.sel
= ctx
->temp_reg
;
4651 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4657 /* result.w = 1.0;*/
4658 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
4659 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4661 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
4662 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4663 alu
.src
[0].chan
= 0;
4665 alu
.dst
.sel
= ctx
->temp_reg
;
4669 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4673 return tgsi_helper_copy(ctx
, inst
);
4676 static int tgsi_log(struct r600_shader_ctx
*ctx
)
4678 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4679 struct r600_bytecode_alu alu
;
4683 /* result.x = floor(log2(|src|)); */
4684 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4685 if (ctx
->bc
->chip_class
== CAYMAN
) {
4686 for (i
= 0; i
< 3; i
++) {
4687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4689 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
4690 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4691 r600_bytecode_src_set_abs(&alu
.src
[0]);
4693 alu
.dst
.sel
= ctx
->temp_reg
;
4699 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4707 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
4708 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4709 r600_bytecode_src_set_abs(&alu
.src
[0]);
4711 alu
.dst
.sel
= ctx
->temp_reg
;
4715 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4720 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
);
4721 alu
.src
[0].sel
= ctx
->temp_reg
;
4722 alu
.src
[0].chan
= 0;
4724 alu
.dst
.sel
= ctx
->temp_reg
;
4729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4734 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
4735 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4737 if (ctx
->bc
->chip_class
== CAYMAN
) {
4738 for (i
= 0; i
< 3; i
++) {
4739 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4741 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
4742 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4743 r600_bytecode_src_set_abs(&alu
.src
[0]);
4745 alu
.dst
.sel
= ctx
->temp_reg
;
4752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4759 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
4760 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4761 r600_bytecode_src_set_abs(&alu
.src
[0]);
4763 alu
.dst
.sel
= ctx
->temp_reg
;
4768 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4773 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4775 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
);
4776 alu
.src
[0].sel
= ctx
->temp_reg
;
4777 alu
.src
[0].chan
= 1;
4779 alu
.dst
.sel
= ctx
->temp_reg
;
4784 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4788 if (ctx
->bc
->chip_class
== CAYMAN
) {
4789 for (i
= 0; i
< 3; i
++) {
4790 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4791 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
4792 alu
.src
[0].sel
= ctx
->temp_reg
;
4793 alu
.src
[0].chan
= 1;
4795 alu
.dst
.sel
= ctx
->temp_reg
;
4802 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4807 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4808 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
);
4809 alu
.src
[0].sel
= ctx
->temp_reg
;
4810 alu
.src
[0].chan
= 1;
4812 alu
.dst
.sel
= ctx
->temp_reg
;
4817 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4822 if (ctx
->bc
->chip_class
== CAYMAN
) {
4823 for (i
= 0; i
< 3; i
++) {
4824 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4825 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
4826 alu
.src
[0].sel
= ctx
->temp_reg
;
4827 alu
.src
[0].chan
= 1;
4829 alu
.dst
.sel
= ctx
->temp_reg
;
4836 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4841 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4842 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
);
4843 alu
.src
[0].sel
= ctx
->temp_reg
;
4844 alu
.src
[0].chan
= 1;
4846 alu
.dst
.sel
= ctx
->temp_reg
;
4851 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4858 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
4860 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4861 r600_bytecode_src_set_abs(&alu
.src
[0]);
4863 alu
.src
[1].sel
= ctx
->temp_reg
;
4864 alu
.src
[1].chan
= 1;
4866 alu
.dst
.sel
= ctx
->temp_reg
;
4871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4876 /* result.z = log2(|src|);*/
4877 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
4878 if (ctx
->bc
->chip_class
== CAYMAN
) {
4879 for (i
= 0; i
< 3; i
++) {
4880 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4882 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
4883 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4884 r600_bytecode_src_set_abs(&alu
.src
[0]);
4886 alu
.dst
.sel
= ctx
->temp_reg
;
4893 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4898 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4900 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
);
4901 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4902 r600_bytecode_src_set_abs(&alu
.src
[0]);
4904 alu
.dst
.sel
= ctx
->temp_reg
;
4909 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4915 /* result.w = 1.0; */
4916 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
4917 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4919 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
);
4920 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4921 alu
.src
[0].chan
= 0;
4923 alu
.dst
.sel
= ctx
->temp_reg
;
4928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4933 return tgsi_helper_copy(ctx
, inst
);
4936 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
4938 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4939 struct r600_bytecode_alu alu
;
4942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4944 switch (inst
->Instruction
.Opcode
) {
4945 case TGSI_OPCODE_ARL
:
4946 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR
;
4948 case TGSI_OPCODE_ARR
:
4949 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
;
4951 case TGSI_OPCODE_UARL
:
4952 alu
.inst
= EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
;
4959 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4961 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
4963 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4967 ctx
->bc
->ar_loaded
= 0;
4970 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
4972 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4973 struct r600_bytecode_alu alu
;
4976 switch (inst
->Instruction
.Opcode
) {
4977 case TGSI_OPCODE_ARL
:
4978 memset(&alu
, 0, sizeof(alu
));
4979 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
;
4980 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4981 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
4985 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4988 memset(&alu
, 0, sizeof(alu
));
4989 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
;
4990 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
4991 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
4995 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4998 case TGSI_OPCODE_ARR
:
4999 memset(&alu
, 0, sizeof(alu
));
5000 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
;
5001 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5002 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5006 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5009 case TGSI_OPCODE_UARL
:
5010 memset(&alu
, 0, sizeof(alu
));
5011 alu
.inst
= V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
;
5012 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5013 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5017 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5025 ctx
->bc
->ar_loaded
= 0;
5029 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5031 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5032 struct r600_bytecode_alu alu
;
5035 for (i
= 0; i
< 4; i
++) {
5036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5038 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
);
5039 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5041 if (i
== 0 || i
== 3) {
5042 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5044 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5047 if (i
== 0 || i
== 2) {
5048 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5050 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5054 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5061 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
)
5063 struct r600_bytecode_alu alu
;
5066 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5068 alu
.execute_mask
= 1;
5069 alu
.update_pred
= 1;
5071 alu
.dst
.sel
= ctx
->temp_reg
;
5075 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5076 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5077 alu
.src
[1].chan
= 0;
5081 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
));
5087 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5089 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5093 if (ctx
->bc
->cf_last
) {
5094 if (ctx
->bc
->cf_last
->inst
== CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
))
5096 else if (ctx
->bc
->cf_last
->inst
== CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
))
5101 ctx
->bc
->cf_last
->inst
= CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
);
5102 ctx
->bc
->force_add_cf
= 1;
5103 } else if (alu_pop
== 2) {
5104 ctx
->bc
->cf_last
->inst
= CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
);
5105 ctx
->bc
->force_add_cf
= 1;
5112 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_POP
));
5113 ctx
->bc
->cf_last
->pop_count
= pops
;
5114 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5120 static inline void callstack_decrease_current(struct r600_shader_ctx
*ctx
, unsigned reason
)
5124 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
--;
5128 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
-= 4;
5131 /* TOODO : for 16 vp asic should -= 2; */
5132 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
--;
5137 static inline void callstack_check_depth(struct r600_shader_ctx
*ctx
, unsigned reason
, unsigned check_max_only
)
5139 if (check_max_only
) {
5152 if ((ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
+ diff
) >
5153 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
) {
5154 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
=
5155 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
+ diff
;
5161 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
++;
5165 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
+= 4;
5168 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
++;
5172 if ((ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
) >
5173 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
) {
5174 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
=
5175 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
;
5179 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5181 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5183 sp
->mid
= realloc((void *)sp
->mid
,
5184 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5185 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5189 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5192 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5193 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5196 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5198 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5208 static int emit_return(struct r600_shader_ctx
*ctx
)
5210 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
));
5214 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5217 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_JUMP
));
5218 ctx
->bc
->cf_last
->pop_count
= pops
;
5219 /* XXX work out offset */
5223 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5228 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5233 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5236 emit_jump_to_offset(ctx
, 1, 4);
5237 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5238 pops(ctx
, ifidx
+ 1);
5242 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5246 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->r600_opcode
);
5247 ctx
->bc
->cf_last
->pop_count
= 1;
5249 fc_set_mid(ctx
, fc_sp
);
5255 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5257 emit_logic_pred(ctx
, CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT
));
5259 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_JUMP
));
5261 fc_pushlevel(ctx
, FC_IF
);
5263 callstack_check_depth(ctx
, FC_PUSH_VPM
, 0);
5267 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5269 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_ELSE
));
5270 ctx
->bc
->cf_last
->pop_count
= 1;
5272 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5273 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5277 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5280 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5281 R600_ERR("if/endif unbalanced in shader\n");
5285 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5286 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5287 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5289 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5293 callstack_decrease_current(ctx
, FC_PUSH_VPM
);
5297 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5299 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5300 * limited to 4096 iterations, like the other LOOP_* instructions. */
5301 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10
));
5303 fc_pushlevel(ctx
, FC_LOOP
);
5305 /* check stack depth */
5306 callstack_check_depth(ctx
, FC_LOOP
, 0);
5310 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5314 r600_bytecode_add_cfinst(ctx
->bc
, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
));
5316 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5317 R600_ERR("loop/endloop in shader code are not paired.\n");
5321 /* fixup loop pointers - from r600isa
5322 LOOP END points to CF after LOOP START,
5323 LOOP START point to CF after LOOP END
5324 BRK/CONT point to LOOP END CF
5326 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5328 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5330 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5331 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5333 /* XXX add LOOPRET support */
5335 callstack_decrease_current(ctx
, FC_LOOP
);
5339 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5343 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5345 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5350 R600_ERR("Break not inside loop/endloop pair\n");
5354 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->r600_opcode
);
5356 fc_set_mid(ctx
, fscp
);
5358 callstack_check_depth(ctx
, FC_PUSH_VPM
, 1);
5362 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5364 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5365 struct r600_bytecode_alu alu
;
5367 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5370 for (i
= 0; i
< lasti
+ 1; i
++) {
5371 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5377 alu
.dst
.sel
= ctx
->temp_reg
;
5380 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
);
5381 for (j
= 0; j
< 2; j
++) {
5382 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5386 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5392 for (i
= 0; i
< lasti
+ 1; i
++) {
5393 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5396 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5397 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5399 alu
.inst
= CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
);
5401 alu
.src
[0].sel
= ctx
->temp_reg
;
5402 alu
.src
[0].chan
= i
;
5404 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5408 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5415 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5416 {TGSI_OPCODE_ARL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_r600_arl
},
5417 {TGSI_OPCODE_MOV
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
, tgsi_op2
},
5418 {TGSI_OPCODE_LIT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_lit
},
5421 * For state trackers other than OpenGL, we'll want to use
5422 * _RECIP_IEEE instead.
5424 {TGSI_OPCODE_RCP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5426 {TGSI_OPCODE_RSQ
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_rsq
},
5427 {TGSI_OPCODE_EXP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_exp
},
5428 {TGSI_OPCODE_LOG
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_log
},
5429 {TGSI_OPCODE_MUL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
, tgsi_op2
},
5430 {TGSI_OPCODE_ADD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
, tgsi_op2
},
5431 {TGSI_OPCODE_DP3
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5432 {TGSI_OPCODE_DP4
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5433 {TGSI_OPCODE_DST
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_opdst
},
5434 {TGSI_OPCODE_MIN
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
, tgsi_op2
},
5435 {TGSI_OPCODE_MAX
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
, tgsi_op2
},
5436 {TGSI_OPCODE_SLT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
, tgsi_op2_swap
},
5437 {TGSI_OPCODE_SGE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
, tgsi_op2
},
5438 {TGSI_OPCODE_MAD
, 1, V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
, tgsi_op3
},
5439 {TGSI_OPCODE_SUB
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
, tgsi_op2
},
5440 {TGSI_OPCODE_LRP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_lrp
},
5441 {TGSI_OPCODE_CND
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5443 {20, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5444 {TGSI_OPCODE_DP2A
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5446 {22, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5447 {23, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5448 {TGSI_OPCODE_FRC
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
, tgsi_op2
},
5449 {TGSI_OPCODE_CLAMP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5450 {TGSI_OPCODE_FLR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
, tgsi_op2
},
5451 {TGSI_OPCODE_ROUND
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
, tgsi_op2
},
5452 {TGSI_OPCODE_EX2
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5453 {TGSI_OPCODE_LG2
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5454 {TGSI_OPCODE_POW
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_pow
},
5455 {TGSI_OPCODE_XPD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_xpd
},
5457 {32, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5458 {TGSI_OPCODE_ABS
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
, tgsi_op2
},
5459 {TGSI_OPCODE_RCC
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5460 {TGSI_OPCODE_DPH
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5461 {TGSI_OPCODE_COS
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
, tgsi_trig
},
5462 {TGSI_OPCODE_DDX
, 0, SQ_TEX_INST_GET_GRADIENTS_H
, tgsi_tex
},
5463 {TGSI_OPCODE_DDY
, 0, SQ_TEX_INST_GET_GRADIENTS_V
, tgsi_tex
},
5464 {TGSI_OPCODE_KILP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
, tgsi_kill
}, /* predicated kill */
5465 {TGSI_OPCODE_PK2H
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5466 {TGSI_OPCODE_PK2US
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5467 {TGSI_OPCODE_PK4B
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5468 {TGSI_OPCODE_PK4UB
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5469 {TGSI_OPCODE_RFL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5470 {TGSI_OPCODE_SEQ
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
, tgsi_op2
},
5471 {TGSI_OPCODE_SFL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5472 {TGSI_OPCODE_SGT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
, tgsi_op2
},
5473 {TGSI_OPCODE_SIN
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
, tgsi_trig
},
5474 {TGSI_OPCODE_SLE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
, tgsi_op2_swap
},
5475 {TGSI_OPCODE_SNE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
, tgsi_op2
},
5476 {TGSI_OPCODE_STR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5477 {TGSI_OPCODE_TEX
, 0, SQ_TEX_INST_SAMPLE
, tgsi_tex
},
5478 {TGSI_OPCODE_TXD
, 0, SQ_TEX_INST_SAMPLE_G
, tgsi_tex
},
5479 {TGSI_OPCODE_TXP
, 0, SQ_TEX_INST_SAMPLE
, tgsi_tex
},
5480 {TGSI_OPCODE_UP2H
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5481 {TGSI_OPCODE_UP2US
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5482 {TGSI_OPCODE_UP4B
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5483 {TGSI_OPCODE_UP4UB
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5484 {TGSI_OPCODE_X2D
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5485 {TGSI_OPCODE_ARA
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5486 {TGSI_OPCODE_ARR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_r600_arl
},
5487 {TGSI_OPCODE_BRA
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5488 {TGSI_OPCODE_CAL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5489 {TGSI_OPCODE_RET
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5490 {TGSI_OPCODE_SSG
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_ssg
},
5491 {TGSI_OPCODE_CMP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_cmp
},
5492 {TGSI_OPCODE_SCS
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_scs
},
5493 {TGSI_OPCODE_TXB
, 0, SQ_TEX_INST_SAMPLE_LB
, tgsi_tex
},
5494 {TGSI_OPCODE_NRM
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5495 {TGSI_OPCODE_DIV
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5496 {TGSI_OPCODE_DP2
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5497 {TGSI_OPCODE_TXL
, 0, SQ_TEX_INST_SAMPLE_L
, tgsi_tex
},
5498 {TGSI_OPCODE_BRK
, 0, V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
, tgsi_loop_brk_cont
},
5499 {TGSI_OPCODE_IF
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_if
},
5501 {75, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5502 {76, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5503 {TGSI_OPCODE_ELSE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_else
},
5504 {TGSI_OPCODE_ENDIF
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_endif
},
5506 {79, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5507 {80, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5508 {TGSI_OPCODE_PUSHA
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5509 {TGSI_OPCODE_POPA
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5510 {TGSI_OPCODE_CEIL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL
, tgsi_op2
},
5511 {TGSI_OPCODE_I2F
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
, tgsi_op2_trans
},
5512 {TGSI_OPCODE_NOT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
, tgsi_op2
},
5513 {TGSI_OPCODE_TRUNC
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
, tgsi_op2
},
5514 {TGSI_OPCODE_SHL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
, tgsi_op2_trans
},
5516 {88, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5517 {TGSI_OPCODE_AND
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
, tgsi_op2
},
5518 {TGSI_OPCODE_OR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
, tgsi_op2
},
5519 {TGSI_OPCODE_MOD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_imod
},
5520 {TGSI_OPCODE_XOR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
, tgsi_op2
},
5521 {TGSI_OPCODE_SAD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5522 {TGSI_OPCODE_TXF
, 0, SQ_TEX_INST_LD
, tgsi_tex
},
5523 {TGSI_OPCODE_TXQ
, 0, SQ_TEX_INST_GET_TEXTURE_RESINFO
, tgsi_tex
},
5524 {TGSI_OPCODE_CONT
, 0, V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5525 {TGSI_OPCODE_EMIT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5526 {TGSI_OPCODE_ENDPRIM
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5527 {TGSI_OPCODE_BGNLOOP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_bgnloop
},
5528 {TGSI_OPCODE_BGNSUB
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5529 {TGSI_OPCODE_ENDLOOP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_endloop
},
5530 {TGSI_OPCODE_ENDSUB
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5531 {TGSI_OPCODE_TXQ_LZ
, 0, SQ_TEX_INST_GET_TEXTURE_RESINFO
, tgsi_tex
},
5533 {104, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5534 {105, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5535 {106, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5536 {TGSI_OPCODE_NOP
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5538 {108, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5539 {109, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5540 {110, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5541 {111, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5542 {TGSI_OPCODE_NRM4
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5543 {TGSI_OPCODE_CALLNZ
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5544 {TGSI_OPCODE_IFC
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5545 {TGSI_OPCODE_BREAKC
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5546 {TGSI_OPCODE_KIL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
, tgsi_kill
}, /* conditional kill */
5547 {TGSI_OPCODE_END
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_end
}, /* aka HALT */
5549 {118, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5550 {TGSI_OPCODE_F2I
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
, tgsi_op2_trans
},
5551 {TGSI_OPCODE_IDIV
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_idiv
},
5552 {TGSI_OPCODE_IMAX
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT
, tgsi_op2
},
5553 {TGSI_OPCODE_IMIN
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT
, tgsi_op2
},
5554 {TGSI_OPCODE_INEG
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
, tgsi_ineg
},
5555 {TGSI_OPCODE_ISGE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT
, tgsi_op2
},
5556 {TGSI_OPCODE_ISHR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
, tgsi_op2_trans
},
5557 {TGSI_OPCODE_ISLT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT
, tgsi_op2_swap
},
5558 {TGSI_OPCODE_F2U
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
, tgsi_op2_trans
},
5559 {TGSI_OPCODE_U2F
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
, tgsi_op2_trans
},
5560 {TGSI_OPCODE_UADD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
, tgsi_op2
},
5561 {TGSI_OPCODE_UDIV
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_udiv
},
5562 {TGSI_OPCODE_UMAD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_umad
},
5563 {TGSI_OPCODE_UMAX
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT
, tgsi_op2
},
5564 {TGSI_OPCODE_UMIN
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT
, tgsi_op2
},
5565 {TGSI_OPCODE_UMOD
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_umod
},
5566 {TGSI_OPCODE_UMUL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
, tgsi_op2_trans
},
5567 {TGSI_OPCODE_USEQ
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT
, tgsi_op2
},
5568 {TGSI_OPCODE_USGE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
, tgsi_op2
},
5569 {TGSI_OPCODE_USHR
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
, tgsi_op2_trans
},
5570 {TGSI_OPCODE_USLT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT
, tgsi_op2_swap
},
5571 {TGSI_OPCODE_USNE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT
, tgsi_op2_swap
},
5572 {TGSI_OPCODE_SWITCH
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5573 {TGSI_OPCODE_CASE
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5574 {TGSI_OPCODE_DEFAULT
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5575 {TGSI_OPCODE_ENDSWITCH
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5576 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5577 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5578 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5579 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5580 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5581 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5582 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5583 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5584 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5585 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5586 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5587 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5588 {TGSI_OPCODE_UARL
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
, tgsi_r600_arl
},
5589 {TGSI_OPCODE_UCMP
, 0, 0, tgsi_unsupported
},
5590 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5591 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5592 {TGSI_OPCODE_LAST
, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5595 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
5596 {TGSI_OPCODE_ARL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_eg_arl
},
5597 {TGSI_OPCODE_MOV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
, tgsi_op2
},
5598 {TGSI_OPCODE_LIT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_lit
},
5599 {TGSI_OPCODE_RCP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
5600 {TGSI_OPCODE_RSQ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
, tgsi_rsq
},
5601 {TGSI_OPCODE_EXP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_exp
},
5602 {TGSI_OPCODE_LOG
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_log
},
5603 {TGSI_OPCODE_MUL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
, tgsi_op2
},
5604 {TGSI_OPCODE_ADD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
, tgsi_op2
},
5605 {TGSI_OPCODE_DP3
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5606 {TGSI_OPCODE_DP4
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5607 {TGSI_OPCODE_DST
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_opdst
},
5608 {TGSI_OPCODE_MIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
, tgsi_op2
},
5609 {TGSI_OPCODE_MAX
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
, tgsi_op2
},
5610 {TGSI_OPCODE_SLT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
, tgsi_op2_swap
},
5611 {TGSI_OPCODE_SGE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
, tgsi_op2
},
5612 {TGSI_OPCODE_MAD
, 1, EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
, tgsi_op3
},
5613 {TGSI_OPCODE_SUB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
, tgsi_op2
},
5614 {TGSI_OPCODE_LRP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_lrp
},
5615 {TGSI_OPCODE_CND
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5617 {20, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5618 {TGSI_OPCODE_DP2A
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5620 {22, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5621 {23, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5622 {TGSI_OPCODE_FRC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
, tgsi_op2
},
5623 {TGSI_OPCODE_CLAMP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5624 {TGSI_OPCODE_FLR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
, tgsi_op2
},
5625 {TGSI_OPCODE_ROUND
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
, tgsi_op2
},
5626 {TGSI_OPCODE_EX2
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5627 {TGSI_OPCODE_LG2
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5628 {TGSI_OPCODE_POW
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_pow
},
5629 {TGSI_OPCODE_XPD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_xpd
},
5631 {32, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5632 {TGSI_OPCODE_ABS
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
, tgsi_op2
},
5633 {TGSI_OPCODE_RCC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5634 {TGSI_OPCODE_DPH
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5635 {TGSI_OPCODE_COS
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
, tgsi_trig
},
5636 {TGSI_OPCODE_DDX
, 0, SQ_TEX_INST_GET_GRADIENTS_H
, tgsi_tex
},
5637 {TGSI_OPCODE_DDY
, 0, SQ_TEX_INST_GET_GRADIENTS_V
, tgsi_tex
},
5638 {TGSI_OPCODE_KILP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
, tgsi_kill
}, /* predicated kill */
5639 {TGSI_OPCODE_PK2H
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5640 {TGSI_OPCODE_PK2US
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5641 {TGSI_OPCODE_PK4B
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5642 {TGSI_OPCODE_PK4UB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5643 {TGSI_OPCODE_RFL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5644 {TGSI_OPCODE_SEQ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
, tgsi_op2
},
5645 {TGSI_OPCODE_SFL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5646 {TGSI_OPCODE_SGT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
, tgsi_op2
},
5647 {TGSI_OPCODE_SIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
, tgsi_trig
},
5648 {TGSI_OPCODE_SLE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
, tgsi_op2_swap
},
5649 {TGSI_OPCODE_SNE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
, tgsi_op2
},
5650 {TGSI_OPCODE_STR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5651 {TGSI_OPCODE_TEX
, 0, SQ_TEX_INST_SAMPLE
, tgsi_tex
},
5652 {TGSI_OPCODE_TXD
, 0, SQ_TEX_INST_SAMPLE_G
, tgsi_tex
},
5653 {TGSI_OPCODE_TXP
, 0, SQ_TEX_INST_SAMPLE
, tgsi_tex
},
5654 {TGSI_OPCODE_UP2H
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5655 {TGSI_OPCODE_UP2US
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5656 {TGSI_OPCODE_UP4B
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5657 {TGSI_OPCODE_UP4UB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5658 {TGSI_OPCODE_X2D
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5659 {TGSI_OPCODE_ARA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5660 {TGSI_OPCODE_ARR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_eg_arl
},
5661 {TGSI_OPCODE_BRA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5662 {TGSI_OPCODE_CAL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5663 {TGSI_OPCODE_RET
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5664 {TGSI_OPCODE_SSG
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_ssg
},
5665 {TGSI_OPCODE_CMP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_cmp
},
5666 {TGSI_OPCODE_SCS
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_scs
},
5667 {TGSI_OPCODE_TXB
, 0, SQ_TEX_INST_SAMPLE_LB
, tgsi_tex
},
5668 {TGSI_OPCODE_NRM
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5669 {TGSI_OPCODE_DIV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5670 {TGSI_OPCODE_DP2
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5671 {TGSI_OPCODE_TXL
, 0, SQ_TEX_INST_SAMPLE_L
, tgsi_tex
},
5672 {TGSI_OPCODE_BRK
, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
, tgsi_loop_brk_cont
},
5673 {TGSI_OPCODE_IF
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_if
},
5675 {75, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5676 {76, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5677 {TGSI_OPCODE_ELSE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_else
},
5678 {TGSI_OPCODE_ENDIF
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_endif
},
5680 {79, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5681 {80, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5682 {TGSI_OPCODE_PUSHA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5683 {TGSI_OPCODE_POPA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5684 {TGSI_OPCODE_CEIL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL
, tgsi_op2
},
5685 {TGSI_OPCODE_I2F
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
, tgsi_op2_trans
},
5686 {TGSI_OPCODE_NOT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
, tgsi_op2
},
5687 {TGSI_OPCODE_TRUNC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
, tgsi_op2
},
5688 {TGSI_OPCODE_SHL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
, tgsi_op2
},
5690 {88, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5691 {TGSI_OPCODE_AND
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
, tgsi_op2
},
5692 {TGSI_OPCODE_OR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
, tgsi_op2
},
5693 {TGSI_OPCODE_MOD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_imod
},
5694 {TGSI_OPCODE_XOR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
, tgsi_op2
},
5695 {TGSI_OPCODE_SAD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5696 {TGSI_OPCODE_TXF
, 0, SQ_TEX_INST_LD
, tgsi_tex
},
5697 {TGSI_OPCODE_TXQ
, 0, SQ_TEX_INST_GET_TEXTURE_RESINFO
, tgsi_tex
},
5698 {TGSI_OPCODE_CONT
, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5699 {TGSI_OPCODE_EMIT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5700 {TGSI_OPCODE_ENDPRIM
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5701 {TGSI_OPCODE_BGNLOOP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_bgnloop
},
5702 {TGSI_OPCODE_BGNSUB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5703 {TGSI_OPCODE_ENDLOOP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_endloop
},
5704 {TGSI_OPCODE_ENDSUB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5705 {TGSI_OPCODE_TXQ_LZ
, 0, SQ_TEX_INST_GET_TEXTURE_RESINFO
, tgsi_tex
},
5707 {104, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5708 {105, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5709 {106, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5710 {TGSI_OPCODE_NOP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5712 {108, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5713 {109, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5714 {110, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5715 {111, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5716 {TGSI_OPCODE_NRM4
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5717 {TGSI_OPCODE_CALLNZ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5718 {TGSI_OPCODE_IFC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5719 {TGSI_OPCODE_BREAKC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5720 {TGSI_OPCODE_KIL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
, tgsi_kill
}, /* conditional kill */
5721 {TGSI_OPCODE_END
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_end
}, /* aka HALT */
5723 {118, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5724 {TGSI_OPCODE_F2I
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
, tgsi_f2i
},
5725 {TGSI_OPCODE_IDIV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_idiv
},
5726 {TGSI_OPCODE_IMAX
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT
, tgsi_op2
},
5727 {TGSI_OPCODE_IMIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT
, tgsi_op2
},
5728 {TGSI_OPCODE_INEG
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
, tgsi_ineg
},
5729 {TGSI_OPCODE_ISGE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT
, tgsi_op2
},
5730 {TGSI_OPCODE_ISHR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
, tgsi_op2
},
5731 {TGSI_OPCODE_ISLT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT
, tgsi_op2_swap
},
5732 {TGSI_OPCODE_F2U
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
, tgsi_f2i
},
5733 {TGSI_OPCODE_U2F
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
, tgsi_op2_trans
},
5734 {TGSI_OPCODE_UADD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
, tgsi_op2
},
5735 {TGSI_OPCODE_UDIV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_udiv
},
5736 {TGSI_OPCODE_UMAD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_umad
},
5737 {TGSI_OPCODE_UMAX
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT
, tgsi_op2
},
5738 {TGSI_OPCODE_UMIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT
, tgsi_op2
},
5739 {TGSI_OPCODE_UMOD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_umod
},
5740 {TGSI_OPCODE_UMUL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT
, tgsi_op2_trans
},
5741 {TGSI_OPCODE_USEQ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT
, tgsi_op2
},
5742 {TGSI_OPCODE_USGE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
, tgsi_op2
},
5743 {TGSI_OPCODE_USHR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
, tgsi_op2
},
5744 {TGSI_OPCODE_USLT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT
, tgsi_op2_swap
},
5745 {TGSI_OPCODE_USNE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT
, tgsi_op2
},
5746 {TGSI_OPCODE_SWITCH
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5747 {TGSI_OPCODE_CASE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5748 {TGSI_OPCODE_DEFAULT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5749 {TGSI_OPCODE_ENDSWITCH
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5750 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5751 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5752 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5753 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5754 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5755 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5756 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5757 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5758 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5759 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5760 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5761 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5762 {TGSI_OPCODE_UARL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
, tgsi_eg_arl
},
5763 {TGSI_OPCODE_UCMP
, 0, 0, tgsi_unsupported
},
5764 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5765 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5766 {TGSI_OPCODE_LAST
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5769 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
5770 {TGSI_OPCODE_ARL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_eg_arl
},
5771 {TGSI_OPCODE_MOV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
, tgsi_op2
},
5772 {TGSI_OPCODE_LIT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_lit
},
5773 {TGSI_OPCODE_RCP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
, cayman_emit_float_instr
},
5774 {TGSI_OPCODE_RSQ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
5775 {TGSI_OPCODE_EXP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_exp
},
5776 {TGSI_OPCODE_LOG
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_log
},
5777 {TGSI_OPCODE_MUL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
, tgsi_op2
},
5778 {TGSI_OPCODE_ADD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
, tgsi_op2
},
5779 {TGSI_OPCODE_DP3
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5780 {TGSI_OPCODE_DP4
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5781 {TGSI_OPCODE_DST
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_opdst
},
5782 {TGSI_OPCODE_MIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
, tgsi_op2
},
5783 {TGSI_OPCODE_MAX
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
, tgsi_op2
},
5784 {TGSI_OPCODE_SLT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
, tgsi_op2_swap
},
5785 {TGSI_OPCODE_SGE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
, tgsi_op2
},
5786 {TGSI_OPCODE_MAD
, 1, EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD
, tgsi_op3
},
5787 {TGSI_OPCODE_SUB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
, tgsi_op2
},
5788 {TGSI_OPCODE_LRP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_lrp
},
5789 {TGSI_OPCODE_CND
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5791 {20, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5792 {TGSI_OPCODE_DP2A
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5794 {22, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5795 {23, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5796 {TGSI_OPCODE_FRC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
, tgsi_op2
},
5797 {TGSI_OPCODE_CLAMP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5798 {TGSI_OPCODE_FLR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
, tgsi_op2
},
5799 {TGSI_OPCODE_ROUND
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE
, tgsi_op2
},
5800 {TGSI_OPCODE_EX2
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
, cayman_emit_float_instr
},
5801 {TGSI_OPCODE_LG2
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
, cayman_emit_float_instr
},
5802 {TGSI_OPCODE_POW
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, cayman_pow
},
5803 {TGSI_OPCODE_XPD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_xpd
},
5805 {32, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5806 {TGSI_OPCODE_ABS
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
, tgsi_op2
},
5807 {TGSI_OPCODE_RCC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5808 {TGSI_OPCODE_DPH
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5809 {TGSI_OPCODE_COS
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
, cayman_trig
},
5810 {TGSI_OPCODE_DDX
, 0, SQ_TEX_INST_GET_GRADIENTS_H
, tgsi_tex
},
5811 {TGSI_OPCODE_DDY
, 0, SQ_TEX_INST_GET_GRADIENTS_V
, tgsi_tex
},
5812 {TGSI_OPCODE_KILP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
, tgsi_kill
}, /* predicated kill */
5813 {TGSI_OPCODE_PK2H
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5814 {TGSI_OPCODE_PK2US
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5815 {TGSI_OPCODE_PK4B
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5816 {TGSI_OPCODE_PK4UB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5817 {TGSI_OPCODE_RFL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5818 {TGSI_OPCODE_SEQ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
, tgsi_op2
},
5819 {TGSI_OPCODE_SFL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5820 {TGSI_OPCODE_SGT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
, tgsi_op2
},
5821 {TGSI_OPCODE_SIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
, cayman_trig
},
5822 {TGSI_OPCODE_SLE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
, tgsi_op2_swap
},
5823 {TGSI_OPCODE_SNE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
, tgsi_op2
},
5824 {TGSI_OPCODE_STR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5825 {TGSI_OPCODE_TEX
, 0, SQ_TEX_INST_SAMPLE
, tgsi_tex
},
5826 {TGSI_OPCODE_TXD
, 0, SQ_TEX_INST_SAMPLE_G
, tgsi_tex
},
5827 {TGSI_OPCODE_TXP
, 0, SQ_TEX_INST_SAMPLE
, tgsi_tex
},
5828 {TGSI_OPCODE_UP2H
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5829 {TGSI_OPCODE_UP2US
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5830 {TGSI_OPCODE_UP4B
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5831 {TGSI_OPCODE_UP4UB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5832 {TGSI_OPCODE_X2D
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5833 {TGSI_OPCODE_ARA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5834 {TGSI_OPCODE_ARR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_eg_arl
},
5835 {TGSI_OPCODE_BRA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5836 {TGSI_OPCODE_CAL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5837 {TGSI_OPCODE_RET
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5838 {TGSI_OPCODE_SSG
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_ssg
},
5839 {TGSI_OPCODE_CMP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_cmp
},
5840 {TGSI_OPCODE_SCS
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_scs
},
5841 {TGSI_OPCODE_TXB
, 0, SQ_TEX_INST_SAMPLE_LB
, tgsi_tex
},
5842 {TGSI_OPCODE_NRM
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5843 {TGSI_OPCODE_DIV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5844 {TGSI_OPCODE_DP2
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
, tgsi_dp
},
5845 {TGSI_OPCODE_TXL
, 0, SQ_TEX_INST_SAMPLE_L
, tgsi_tex
},
5846 {TGSI_OPCODE_BRK
, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
, tgsi_loop_brk_cont
},
5847 {TGSI_OPCODE_IF
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_if
},
5849 {75, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5850 {76, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5851 {TGSI_OPCODE_ELSE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_else
},
5852 {TGSI_OPCODE_ENDIF
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_endif
},
5854 {79, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5855 {80, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5856 {TGSI_OPCODE_PUSHA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5857 {TGSI_OPCODE_POPA
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5858 {TGSI_OPCODE_CEIL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL
, tgsi_op2
},
5859 {TGSI_OPCODE_I2F
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT
, tgsi_op2
},
5860 {TGSI_OPCODE_NOT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT
, tgsi_op2
},
5861 {TGSI_OPCODE_TRUNC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
, tgsi_op2
},
5862 {TGSI_OPCODE_SHL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT
, tgsi_op2
},
5864 {88, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5865 {TGSI_OPCODE_AND
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT
, tgsi_op2
},
5866 {TGSI_OPCODE_OR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT
, tgsi_op2
},
5867 {TGSI_OPCODE_MOD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_imod
},
5868 {TGSI_OPCODE_XOR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT
, tgsi_op2
},
5869 {TGSI_OPCODE_SAD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5870 {TGSI_OPCODE_TXF
, 0, SQ_TEX_INST_LD
, tgsi_tex
},
5871 {TGSI_OPCODE_TXQ
, 0, SQ_TEX_INST_GET_TEXTURE_RESINFO
, tgsi_tex
},
5872 {TGSI_OPCODE_CONT
, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5873 {TGSI_OPCODE_EMIT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5874 {TGSI_OPCODE_ENDPRIM
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5875 {TGSI_OPCODE_BGNLOOP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_bgnloop
},
5876 {TGSI_OPCODE_BGNSUB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5877 {TGSI_OPCODE_ENDLOOP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_endloop
},
5878 {TGSI_OPCODE_ENDSUB
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5879 {TGSI_OPCODE_TXQ_LZ
, 0, SQ_TEX_INST_GET_TEXTURE_RESINFO
, tgsi_tex
},
5881 {104, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5882 {105, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5883 {106, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5884 {TGSI_OPCODE_NOP
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5886 {108, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5887 {109, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5888 {110, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5889 {111, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5890 {TGSI_OPCODE_NRM4
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5891 {TGSI_OPCODE_CALLNZ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5892 {TGSI_OPCODE_IFC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5893 {TGSI_OPCODE_BREAKC
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5894 {TGSI_OPCODE_KIL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
, tgsi_kill
}, /* conditional kill */
5895 {TGSI_OPCODE_END
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_end
}, /* aka HALT */
5897 {118, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5898 {TGSI_OPCODE_F2I
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
, tgsi_op2
},
5899 {TGSI_OPCODE_IDIV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_idiv
},
5900 {TGSI_OPCODE_IMAX
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT
, tgsi_op2
},
5901 {TGSI_OPCODE_IMIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT
, tgsi_op2
},
5902 {TGSI_OPCODE_INEG
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT
, tgsi_ineg
},
5903 {TGSI_OPCODE_ISGE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT
, tgsi_op2
},
5904 {TGSI_OPCODE_ISHR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT
, tgsi_op2
},
5905 {TGSI_OPCODE_ISLT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT
, tgsi_op2_swap
},
5906 {TGSI_OPCODE_F2U
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT
, tgsi_op2
},
5907 {TGSI_OPCODE_U2F
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT
, tgsi_op2
},
5908 {TGSI_OPCODE_UADD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT
, tgsi_op2
},
5909 {TGSI_OPCODE_UDIV
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_udiv
},
5910 {TGSI_OPCODE_UMAD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_umad
},
5911 {TGSI_OPCODE_UMAX
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT
, tgsi_op2
},
5912 {TGSI_OPCODE_UMIN
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT
, tgsi_op2
},
5913 {TGSI_OPCODE_UMOD
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_umod
},
5914 {TGSI_OPCODE_UMUL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT
, cayman_mul_int_instr
},
5915 {TGSI_OPCODE_USEQ
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT
, tgsi_op2
},
5916 {TGSI_OPCODE_USGE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT
, tgsi_op2
},
5917 {TGSI_OPCODE_USHR
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT
, tgsi_op2
},
5918 {TGSI_OPCODE_USLT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT
, tgsi_op2_swap
},
5919 {TGSI_OPCODE_USNE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT
, tgsi_op2
},
5920 {TGSI_OPCODE_SWITCH
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5921 {TGSI_OPCODE_CASE
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5922 {TGSI_OPCODE_DEFAULT
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5923 {TGSI_OPCODE_ENDSWITCH
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},
5924 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5925 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5926 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5927 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5928 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5929 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5930 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5931 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5932 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5933 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5934 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5935 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5936 {TGSI_OPCODE_UARL
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT
, tgsi_eg_arl
},
5937 {TGSI_OPCODE_UCMP
, 0, 0, tgsi_unsupported
},
5938 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5939 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5940 {TGSI_OPCODE_LAST
, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
, tgsi_unsupported
},