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_shader_from_tgsi(struct r600_screen
*rscreen
,
62 struct r600_pipe_shader
*pipeshader
,
63 struct r600_shader_key key
);
65 static unsigned tgsi_get_processor_type(const struct tgsi_token
*tokens
)
67 struct tgsi_parse_context parse
;
69 if (tgsi_parse_init( &parse
, tokens
) != TGSI_PARSE_OK
) {
70 debug_printf("tgsi_parse_init() failed in %s:%i!\n", __func__
, __LINE__
);
73 return parse
.FullHeader
.Processor
.Processor
;
76 static bool r600_can_dump_shader(struct r600_screen
*rscreen
, unsigned processor_type
)
78 switch (processor_type
) {
79 case TGSI_PROCESSOR_VERTEX
:
80 return (rscreen
->debug_flags
& DBG_VS
) != 0;
81 case TGSI_PROCESSOR_GEOMETRY
:
82 return (rscreen
->debug_flags
& DBG_GS
) != 0;
83 case TGSI_PROCESSOR_FRAGMENT
:
84 return (rscreen
->debug_flags
& DBG_PS
) != 0;
85 case TGSI_PROCESSOR_COMPUTE
:
86 return (rscreen
->debug_flags
& DBG_CS
) != 0;
92 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
96 fprintf(stderr
, "STREAMOUT\n");
97 for (i
= 0; i
< so
->num_outputs
; i
++) {
98 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
99 so
->output
[i
].start_component
;
100 fprintf(stderr
, " %i: MEM_STREAM0_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
101 i
, so
->output
[i
].output_buffer
,
102 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
103 so
->output
[i
].register_index
,
108 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
112 int r600_pipe_shader_create(struct pipe_context
*ctx
,
113 struct r600_pipe_shader
*shader
,
114 struct r600_shader_key key
)
116 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
117 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
120 bool dump
= r600_can_dump_shader(rctx
->screen
, tgsi_get_processor_type(sel
->tokens
));
122 shader
->shader
.bc
.isa
= rctx
->isa
;
125 fprintf(stderr
, "--------------------------------------------------------------\n");
126 tgsi_dump(sel
->tokens
, 0);
128 if (sel
->so
.num_outputs
) {
129 r600_dump_streamout(&sel
->so
);
132 r
= r600_shader_from_tgsi(rctx
->screen
, shader
, key
);
134 R600_ERR("translation from TGSI failed !\n");
137 r
= r600_bytecode_build(&shader
->shader
.bc
);
139 R600_ERR("building bytecode failed !\n");
143 fprintf(stderr
, "--------------------------------------------------------------\n");
144 r600_bytecode_disasm(&shader
->shader
.bc
);
145 fprintf(stderr
, "______________________________________________________________\n");
149 /* Store the shader in a buffer. */
150 if (shader
->bo
== NULL
) {
151 shader
->bo
= (struct r600_resource
*)
152 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
153 if (shader
->bo
== NULL
) {
156 ptr
= r600_buffer_mmap_sync_with_rings(rctx
, shader
->bo
, PIPE_TRANSFER_WRITE
);
157 if (R600_BIG_ENDIAN
) {
158 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
159 ptr
[i
] = bswap_32(shader
->shader
.bc
.bytecode
[i
]);
162 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
164 rctx
->ws
->buffer_unmap(shader
->bo
->cs_buf
);
168 switch (shader
->shader
.processor_type
) {
169 case TGSI_PROCESSOR_VERTEX
:
170 if (rctx
->chip_class
>= EVERGREEN
) {
171 evergreen_update_vs_state(ctx
, shader
);
173 r600_update_vs_state(ctx
, shader
);
176 case TGSI_PROCESSOR_FRAGMENT
:
177 if (rctx
->chip_class
>= EVERGREEN
) {
178 evergreen_update_ps_state(ctx
, shader
);
180 r600_update_ps_state(ctx
, shader
);
189 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
191 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
192 r600_bytecode_clear(&shader
->shader
.bc
);
193 r600_release_command_buffer(&shader
->command_buffer
);
197 * tgsi -> r600 shader
199 struct r600_shader_tgsi_instruction
;
201 struct r600_shader_src
{
211 struct r600_shader_ctx
{
212 struct tgsi_shader_info info
;
213 struct tgsi_parse_context parse
;
214 const struct tgsi_token
*tokens
;
216 unsigned file_offset
[TGSI_FILE_COUNT
];
218 struct r600_shader_tgsi_instruction
*inst_info
;
219 struct r600_bytecode
*bc
;
220 struct r600_shader
*shader
;
221 struct r600_shader_src src
[4];
224 uint32_t max_driver_temp_used
;
226 /* needed for evergreen interpolation */
227 boolean input_centroid
;
228 boolean input_linear
;
229 boolean input_perspective
;
233 boolean clip_vertex_write
;
239 struct r600_shader_tgsi_instruction
{
240 unsigned tgsi_opcode
;
243 int (*process
)(struct r600_shader_ctx
*ctx
);
246 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
247 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
248 static inline void callstack_check_depth(struct r600_shader_ctx
*ctx
, unsigned reason
, unsigned check_max_only
);
249 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
250 static int tgsi_else(struct r600_shader_ctx
*ctx
);
251 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
252 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
253 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
254 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
257 * bytestream -> r600 shader
259 * These functions are used to transform the output of the LLVM backend into
260 * struct r600_bytecode.
263 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
264 unsigned char * bytes
, unsigned num_bytes
);
267 int r600_compute_shader_create(struct pipe_context
* ctx
,
268 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
)
270 struct r600_context
*r600_ctx
= (struct r600_context
*)ctx
;
271 unsigned char * bytes
;
273 struct r600_shader_ctx shader_ctx
;
274 bool dump
= (r600_ctx
->screen
->debug_flags
& DBG_CS
) != 0;
276 r600_llvm_compile(mod
, &bytes
, &byte_count
, r600_ctx
->family
, dump
);
277 shader_ctx
.bc
= bytecode
;
278 r600_bytecode_init(shader_ctx
.bc
, r600_ctx
->chip_class
, r600_ctx
->family
,
279 r600_ctx
->screen
->msaa_texture_support
);
280 shader_ctx
.bc
->type
= TGSI_PROCESSOR_COMPUTE
;
281 shader_ctx
.bc
->isa
= r600_ctx
->isa
;
282 r600_bytecode_from_byte_stream(&shader_ctx
, bytes
, byte_count
);
283 if (shader_ctx
.bc
->chip_class
== CAYMAN
) {
284 cm_bytecode_add_cf_end(shader_ctx
.bc
);
286 r600_bytecode_build(shader_ctx
.bc
);
288 r600_bytecode_disasm(shader_ctx
.bc
);
294 #endif /* HAVE_OPENCL */
296 static uint32_t i32_from_byte_stream(unsigned char * bytes
,
297 unsigned * bytes_read
)
301 for (i
= 0; i
< 4; i
++) {
302 out
|= bytes
[(*bytes_read
)++] << (8 * i
);
307 static unsigned r600_src_from_byte_stream(unsigned char * bytes
,
308 unsigned bytes_read
, struct r600_bytecode_alu
* alu
, unsigned src_idx
)
312 sel0
= bytes
[bytes_read
++];
313 sel1
= bytes
[bytes_read
++];
314 alu
->src
[src_idx
].sel
= sel0
| (sel1
<< 8);
315 alu
->src
[src_idx
].chan
= bytes
[bytes_read
++];
316 alu
->src
[src_idx
].neg
= bytes
[bytes_read
++];
317 alu
->src
[src_idx
].abs
= bytes
[bytes_read
++];
318 alu
->src
[src_idx
].rel
= bytes
[bytes_read
++];
319 alu
->src
[src_idx
].kc_bank
= bytes
[bytes_read
++];
320 for (i
= 0; i
< 4; i
++) {
321 alu
->src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
326 static unsigned r600_alu_from_byte_stream(struct r600_shader_ctx
*ctx
,
327 unsigned char * bytes
, unsigned bytes_read
)
329 unsigned src_idx
, src_num
;
330 struct r600_bytecode_alu alu
;
331 unsigned src_use_sel
[3];
332 const struct alu_op_info
*alu_op
;
333 unsigned src_sel
[3] = {};
334 uint32_t word0
, word1
;
336 src_num
= bytes
[bytes_read
++];
338 memset(&alu
, 0, sizeof(alu
));
339 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
341 src_use_sel
[src_idx
] = bytes
[bytes_read
++];
342 for (i
= 0; i
< 4; i
++) {
343 src_sel
[src_idx
] |= bytes
[bytes_read
++] << (i
* 8);
345 for (i
= 0; i
< 4; i
++) {
346 alu
.src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
350 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
351 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
353 switch(ctx
->bc
->chip_class
) {
356 r600_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
361 r700_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
365 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
366 if (src_use_sel
[src_idx
]) {
367 unsigned sel
= src_sel
[src_idx
];
369 alu
.src
[src_idx
].chan
= sel
& 3;
372 if (sel
>=512) { /* constant */
374 alu
.src
[src_idx
].kc_bank
= sel
>> 12;
375 alu
.src
[src_idx
].sel
= (sel
& 4095) + 512;
378 alu
.src
[src_idx
].sel
= sel
;
383 alu_op
= r600_isa_alu(alu
.op
);
385 #if HAVE_LLVM < 0x0302
386 if ((alu_op
->flags
& AF_PRED
) && alu_op
->src_count
== 2) {
389 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
395 if (alu_op
->flags
& AF_MOVA
) {
396 ctx
->bc
->ar_reg
= alu
.src
[0].sel
;
397 ctx
->bc
->ar_chan
= alu
.src
[0].chan
;
398 ctx
->bc
->ar_loaded
= 0;
402 if (alu
.execute_mask
) {
404 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
406 r600_bytecode_add_alu(ctx
->bc
, &alu
);
409 /* XXX: Handle other KILL instructions */
410 if (alu_op
->flags
& AF_KILL
) {
411 ctx
->shader
->uses_kill
= 1;
412 /* XXX: This should be enforced in the LLVM backend. */
413 ctx
->bc
->force_add_cf
= 1;
418 static void llvm_if(struct r600_shader_ctx
*ctx
)
420 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
421 fc_pushlevel(ctx
, FC_IF
);
422 callstack_check_depth(ctx
, FC_PUSH_VPM
, 0);
425 static void r600_break_from_byte_stream(struct r600_shader_ctx
*ctx
)
427 unsigned opcode
= TGSI_OPCODE_BRK
;
428 if (ctx
->bc
->chip_class
== CAYMAN
)
429 ctx
->inst_info
= &cm_shader_tgsi_instruction
[opcode
];
430 else if (ctx
->bc
->chip_class
>= EVERGREEN
)
431 ctx
->inst_info
= &eg_shader_tgsi_instruction
[opcode
];
433 ctx
->inst_info
= &r600_shader_tgsi_instruction
[opcode
];
435 tgsi_loop_brk_cont(ctx
);
439 static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx
*ctx
,
440 unsigned char * bytes
, unsigned bytes_read
)
442 struct r600_bytecode_alu alu
;
444 memset(&alu
, 0, sizeof(alu
));
445 bytes_read
= r600_src_from_byte_stream(bytes
, bytes_read
, &alu
, 0);
446 inst
= bytes
[bytes_read
++];
448 case 0: /* IF_PREDICATED */
457 case 3: /* BGNLOOP */
460 case 4: /* ENDLOOP */
463 case 5: /* PREDICATED_BREAK */
464 r600_break_from_byte_stream(ctx
);
466 case 6: /* CONTINUE */
468 unsigned opcode
= TGSI_OPCODE_CONT
;
469 if (ctx
->bc
->chip_class
== CAYMAN
) {
471 &cm_shader_tgsi_instruction
[opcode
];
472 } else if (ctx
->bc
->chip_class
>= EVERGREEN
) {
474 &eg_shader_tgsi_instruction
[opcode
];
477 &r600_shader_tgsi_instruction
[opcode
];
479 tgsi_loop_brk_cont(ctx
);
487 static unsigned r600_tex_from_byte_stream(struct r600_shader_ctx
*ctx
,
488 unsigned char * bytes
, unsigned bytes_read
)
490 struct r600_bytecode_tex tex
;
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 tex
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
, G_SQ_TEX_WORD0_TEX_INST(word0
));
497 tex
.resource_id
= G_SQ_TEX_WORD0_RESOURCE_ID(word0
);
498 tex
.src_gpr
= G_SQ_TEX_WORD0_SRC_GPR(word0
);
499 tex
.src_rel
= G_SQ_TEX_WORD0_SRC_REL(word0
);
500 tex
.dst_gpr
= G_SQ_TEX_WORD1_DST_GPR(word1
);
501 tex
.dst_rel
= G_SQ_TEX_WORD1_DST_REL(word1
);
502 tex
.dst_sel_x
= G_SQ_TEX_WORD1_DST_SEL_X(word1
);
503 tex
.dst_sel_y
= G_SQ_TEX_WORD1_DST_SEL_Y(word1
);
504 tex
.dst_sel_z
= G_SQ_TEX_WORD1_DST_SEL_Z(word1
);
505 tex
.dst_sel_w
= G_SQ_TEX_WORD1_DST_SEL_W(word1
);
506 tex
.lod_bias
= G_SQ_TEX_WORD1_LOD_BIAS(word1
);
507 tex
.coord_type_x
= G_SQ_TEX_WORD1_COORD_TYPE_X(word1
);
508 tex
.coord_type_y
= G_SQ_TEX_WORD1_COORD_TYPE_Y(word1
);
509 tex
.coord_type_z
= G_SQ_TEX_WORD1_COORD_TYPE_Z(word1
);
510 tex
.coord_type_w
= G_SQ_TEX_WORD1_COORD_TYPE_W(word1
);
511 tex
.offset_x
= G_SQ_TEX_WORD2_OFFSET_X(word2
);
512 tex
.offset_y
= G_SQ_TEX_WORD2_OFFSET_Y(word2
);
513 tex
.offset_z
= G_SQ_TEX_WORD2_OFFSET_Z(word2
);
514 tex
.sampler_id
= G_SQ_TEX_WORD2_SAMPLER_ID(word2
);
515 tex
.src_sel_x
= G_SQ_TEX_WORD2_SRC_SEL_X(word2
);
516 tex
.src_sel_y
= G_SQ_TEX_WORD2_SRC_SEL_Y(word2
);
517 tex
.src_sel_z
= G_SQ_TEX_WORD2_SRC_SEL_Z(word2
);
518 tex
.src_sel_w
= G_SQ_TEX_WORD2_SRC_SEL_W(word2
);
522 r600_bytecode_add_tex(ctx
->bc
, &tex
);
527 static int r600_vtx_from_byte_stream(struct r600_shader_ctx
*ctx
,
528 unsigned char * bytes
, unsigned bytes_read
)
530 struct r600_bytecode_vtx vtx
;
532 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
533 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
534 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
536 memset(&vtx
, 0, sizeof(vtx
));
539 vtx
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
,
540 G_SQ_VTX_WORD0_VTX_INST(word0
));
541 vtx
.fetch_type
= G_SQ_VTX_WORD0_FETCH_TYPE(word0
);
542 vtx
.buffer_id
= G_SQ_VTX_WORD0_BUFFER_ID(word0
);
543 vtx
.src_gpr
= G_SQ_VTX_WORD0_SRC_GPR(word0
);
544 vtx
.src_sel_x
= G_SQ_VTX_WORD0_SRC_SEL_X(word0
);
545 vtx
.mega_fetch_count
= G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(word0
);
548 vtx
.dst_gpr
= G_SQ_VTX_WORD1_GPR_DST_GPR(word1
);
549 vtx
.dst_sel_x
= G_SQ_VTX_WORD1_DST_SEL_X(word1
);
550 vtx
.dst_sel_y
= G_SQ_VTX_WORD1_DST_SEL_Y(word1
);
551 vtx
.dst_sel_z
= G_SQ_VTX_WORD1_DST_SEL_Z(word1
);
552 vtx
.dst_sel_w
= G_SQ_VTX_WORD1_DST_SEL_W(word1
);
553 vtx
.use_const_fields
= G_SQ_VTX_WORD1_USE_CONST_FIELDS(word1
);
554 vtx
.data_format
= G_SQ_VTX_WORD1_DATA_FORMAT(word1
);
555 vtx
.num_format_all
= G_SQ_VTX_WORD1_NUM_FORMAT_ALL(word1
);
556 vtx
.format_comp_all
= G_SQ_VTX_WORD1_FORMAT_COMP_ALL(word1
);
557 vtx
.srf_mode_all
= G_SQ_VTX_WORD1_SRF_MODE_ALL(word1
);
560 vtx
.offset
= G_SQ_VTX_WORD2_OFFSET(word2
);
561 vtx
.endian
= G_SQ_VTX_WORD2_ENDIAN_SWAP(word2
);
563 if (r600_bytecode_add_vtx(ctx
->bc
, &vtx
)) {
564 fprintf(stderr
, "Error adding vtx\n");
567 /* Use the Texture Cache for compute shaders*/
568 if (ctx
->bc
->chip_class
>= EVERGREEN
&&
569 ctx
->bc
->type
== TGSI_PROCESSOR_COMPUTE
) {
570 ctx
->bc
->cf_last
->op
= CF_OP_TEX
;
575 static int r600_export_from_byte_stream(struct r600_shader_ctx
*ctx
,
576 unsigned char * bytes
, unsigned bytes_read
)
578 uint32_t word0
= 0, word1
= 0;
579 struct r600_bytecode_output output
;
580 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
581 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
582 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
583 if (ctx
->bc
->chip_class
>= EVERGREEN
)
584 eg_bytecode_export_read(ctx
->bc
, &output
, word0
,word1
);
586 r600_bytecode_export_read(ctx
->bc
, &output
, word0
,word1
);
587 r600_bytecode_add_output(ctx
->bc
, &output
);
591 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
592 unsigned char * bytes
, unsigned num_bytes
)
594 unsigned bytes_read
= 0;
595 ctx
->bc
->nstack
= bytes
[bytes_read
++];
597 while (bytes_read
< num_bytes
) {
598 char inst_type
= bytes
[bytes_read
++];
601 bytes_read
= r600_alu_from_byte_stream(ctx
, bytes
,
605 bytes_read
= r600_tex_from_byte_stream(ctx
, bytes
,
609 bytes_read
= r600_fc_from_byte_stream(ctx
, bytes
,
613 r600_bytecode_add_cfinst(ctx
->bc
, CF_NATIVE
);
614 for (i
= 0; i
< 2; i
++) {
615 for (byte
= 0 ; byte
< 4; byte
++) {
616 ctx
->bc
->cf_last
->isa
[i
] |=
617 (bytes
[bytes_read
++] << (byte
* 8));
623 bytes_read
= r600_vtx_from_byte_stream(ctx
, bytes
,
627 bytes_read
= r600_export_from_byte_stream(ctx
, bytes
,
631 int32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
632 int32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
634 r600_bytecode_add_cf(ctx
->bc
);
635 ctx
->bc
->cf_last
->op
= r600_isa_cf_by_opcode(ctx
->bc
->isa
, 8/* CF_ALU*/, 1);
636 ctx
->bc
->cf_last
->kcache
[0].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK0(word0
);
637 ctx
->bc
->cf_last
->kcache
[0].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(word1
);
638 ctx
->bc
->cf_last
->kcache
[0].mode
= G_SQ_CF_ALU_WORD0_KCACHE_MODE0(word0
);
639 ctx
->bc
->cf_last
->kcache
[1].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK1(word0
);
640 ctx
->bc
->cf_last
->kcache
[1].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(word1
);
641 ctx
->bc
->cf_last
->kcache
[1].mode
= G_SQ_CF_ALU_WORD1_KCACHE_MODE1(word1
);
645 /* XXX: Error here */
651 /* End bytestream -> r600 shader functions*/
653 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
655 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
658 if (i
->Instruction
.NumDstRegs
> 1) {
659 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
662 if (i
->Instruction
.Predicate
) {
663 R600_ERR("predicate unsupported\n");
667 if (i
->Instruction
.Label
) {
668 R600_ERR("label unsupported\n");
672 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
673 if (i
->Src
[j
].Register
.Dimension
) {
674 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
675 R600_ERR("unsupported src %d (dimension %d)\n", j
,
676 i
->Src
[j
].Register
.Dimension
);
681 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
682 if (i
->Dst
[j
].Register
.Dimension
) {
683 R600_ERR("unsupported dst (dimension)\n");
690 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
695 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
696 if (ctx
->shader
->input
[input
].centroid
)
698 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
699 /* if we have perspective add one */
700 if (ctx
->input_perspective
) {
702 /* if we have perspective centroid */
703 if (ctx
->input_centroid
)
706 if (ctx
->shader
->input
[input
].centroid
)
710 ctx
->shader
->input
[input
].ij_index
= ij_index
;
713 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
716 struct r600_bytecode_alu alu
;
717 int gpr
= 0, base_chan
= 0;
718 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
720 /* work out gpr and base_chan from index */
722 base_chan
= (2 * (ij_index
% 2)) + 1;
724 for (i
= 0; i
< 8; i
++) {
725 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
728 alu
.op
= ALU_OP2_INTERP_ZW
;
730 alu
.op
= ALU_OP2_INTERP_XY
;
732 if ((i
> 1) && (i
< 6)) {
733 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
737 alu
.dst
.chan
= i
% 4;
739 alu
.src
[0].sel
= gpr
;
740 alu
.src
[0].chan
= (base_chan
- (i
% 2));
742 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
744 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
747 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
754 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
757 struct r600_bytecode_alu alu
;
759 for (i
= 0; i
< 4; i
++) {
760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
762 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
764 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
769 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
774 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
782 * Special export handling in shaders
784 * shader export ARRAY_BASE for EXPORT_POS:
787 * 62, 63 are clip distance vectors
789 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
790 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
791 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
792 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
793 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
794 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
795 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
796 * exclusive from render target index)
797 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
800 * shader export ARRAY_BASE for EXPORT_PIXEL:
802 * 61 computed Z vector
804 * The use of the values exported in the computed Z vector are controlled
805 * by DB_SHADER_CONTROL:
806 * Z_EXPORT_ENABLE - Z as a float in RED
807 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
808 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
809 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
810 * DB_SOURCE_FORMAT - export control restrictions
815 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
816 static int r600_spi_sid(struct r600_shader_io
* io
)
818 int index
, name
= io
->name
;
820 /* These params are handled differently, they don't need
821 * semantic indices, so we'll use 0 for them.
823 if (name
== TGSI_SEMANTIC_POSITION
||
824 name
== TGSI_SEMANTIC_PSIZE
||
825 name
== TGSI_SEMANTIC_FACE
)
828 if (name
== TGSI_SEMANTIC_GENERIC
) {
829 /* For generic params simply use sid from tgsi */
832 /* For non-generic params - pack name and sid into 8 bits */
833 index
= 0x80 | (name
<<3) | (io
->sid
);
836 /* Make sure that all really used indices have nonzero value, so
837 * we can just compare it to 0 later instead of comparing the name
838 * with different values to detect special cases. */
845 /* turn input into interpolate on EG */
846 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
850 if (ctx
->shader
->input
[index
].spi_sid
) {
851 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
852 if (ctx
->shader
->input
[index
].interpolate
> 0) {
853 evergreen_interp_assign_ij_index(ctx
, index
);
855 r
= evergreen_interp_alu(ctx
, index
);
858 r
= evergreen_interp_flat(ctx
, index
);
864 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
866 struct r600_bytecode_alu alu
;
868 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
869 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
871 for (i
= 0; i
< 4; i
++) {
872 memset(&alu
, 0, sizeof(alu
));
873 alu
.op
= ALU_OP3_CNDGT
;
876 alu
.dst
.sel
= gpr_front
;
877 alu
.src
[0].sel
= ctx
->face_gpr
;
878 alu
.src
[1].sel
= gpr_front
;
879 alu
.src
[2].sel
= gpr_back
;
886 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
893 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
895 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
896 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
898 switch (d
->Declaration
.File
) {
899 case TGSI_FILE_INPUT
:
900 i
= ctx
->shader
->ninput
;
901 ctx
->shader
->ninput
+= count
;
902 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
903 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
904 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
905 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
906 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
907 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
908 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
909 switch (ctx
->shader
->input
[i
].name
) {
910 case TGSI_SEMANTIC_FACE
:
911 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
913 case TGSI_SEMANTIC_COLOR
:
916 case TGSI_SEMANTIC_POSITION
:
917 ctx
->fragcoord_input
= i
;
920 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
921 if ((r
= evergreen_interp_input(ctx
, i
)))
925 for (j
= 1; j
< count
; ++j
) {
926 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
927 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
930 case TGSI_FILE_OUTPUT
:
931 i
= ctx
->shader
->noutput
++;
932 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
933 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
934 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
935 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
936 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
937 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
938 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
939 switch (d
->Semantic
.Name
) {
940 case TGSI_SEMANTIC_CLIPDIST
:
941 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
943 case TGSI_SEMANTIC_PSIZE
:
944 ctx
->shader
->vs_out_misc_write
= 1;
945 ctx
->shader
->vs_out_point_size
= 1;
947 case TGSI_SEMANTIC_CLIPVERTEX
:
948 ctx
->clip_vertex_write
= TRUE
;
952 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
953 switch (d
->Semantic
.Name
) {
954 case TGSI_SEMANTIC_COLOR
:
955 ctx
->shader
->nr_ps_max_color_exports
++;
960 case TGSI_FILE_CONSTANT
:
961 case TGSI_FILE_TEMPORARY
:
962 case TGSI_FILE_SAMPLER
:
963 case TGSI_FILE_ADDRESS
:
966 case TGSI_FILE_SYSTEM_VALUE
:
967 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
968 if (!ctx
->native_integers
) {
969 struct r600_bytecode_alu alu
;
970 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
972 alu
.op
= ALU_OP1_INT_TO_FLT
;
981 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
985 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
988 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
994 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
996 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
1000 * for evergreen we need to scan the shader to find the number of GPRs we need to
1001 * reserve for interpolation.
1003 * we need to know if we are going to emit
1004 * any centroid inputs
1005 * if perspective and linear are required
1007 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1012 ctx
->input_linear
= FALSE
;
1013 ctx
->input_perspective
= FALSE
;
1014 ctx
->input_centroid
= FALSE
;
1015 ctx
->num_interp_gpr
= 1;
1017 /* any centroid inputs */
1018 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1019 /* skip position/face */
1020 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1021 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
1023 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
1024 ctx
->input_linear
= TRUE
;
1025 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
1026 ctx
->input_perspective
= TRUE
;
1027 if (ctx
->info
.input_centroid
[i
])
1028 ctx
->input_centroid
= TRUE
;
1032 /* ignoring sample for now */
1033 if (ctx
->input_perspective
)
1035 if (ctx
->input_linear
)
1037 if (ctx
->input_centroid
)
1040 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
1042 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
1043 return ctx
->num_interp_gpr
;
1046 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1047 const struct tgsi_full_src_register
*tgsi_src
,
1048 struct r600_shader_src
*r600_src
)
1050 memset(r600_src
, 0, sizeof(*r600_src
));
1051 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1052 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1053 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1054 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1055 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1056 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1058 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1060 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1061 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1062 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1064 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1065 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
1066 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1069 index
= tgsi_src
->Register
.Index
;
1070 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1071 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1072 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1073 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1074 r600_src
->swizzle
[0] = 3;
1075 r600_src
->swizzle
[1] = 3;
1076 r600_src
->swizzle
[2] = 3;
1077 r600_src
->swizzle
[3] = 3;
1079 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1080 r600_src
->swizzle
[0] = 0;
1081 r600_src
->swizzle
[1] = 0;
1082 r600_src
->swizzle
[2] = 0;
1083 r600_src
->swizzle
[3] = 0;
1087 if (tgsi_src
->Register
.Indirect
)
1088 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1089 r600_src
->sel
= tgsi_src
->Register
.Index
;
1090 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1092 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1093 if (tgsi_src
->Register
.Dimension
) {
1094 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1099 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
1101 struct r600_bytecode_vtx vtx
;
1102 unsigned int ar_reg
;
1106 struct r600_bytecode_alu alu
;
1108 memset(&alu
, 0, sizeof(alu
));
1110 alu
.op
= ALU_OP2_ADD_INT
;
1111 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1113 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1114 alu
.src
[1].value
= offset
;
1116 alu
.dst
.sel
= dst_reg
;
1120 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1125 ar_reg
= ctx
->bc
->ar_reg
;
1128 memset(&vtx
, 0, sizeof(vtx
));
1129 vtx
.buffer_id
= cb_idx
;
1130 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
1131 vtx
.src_gpr
= ar_reg
;
1132 vtx
.mega_fetch_count
= 16;
1133 vtx
.dst_gpr
= dst_reg
;
1134 vtx
.dst_sel_x
= 0; /* SEL_X */
1135 vtx
.dst_sel_y
= 1; /* SEL_Y */
1136 vtx
.dst_sel_z
= 2; /* SEL_Z */
1137 vtx
.dst_sel_w
= 3; /* SEL_W */
1138 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1139 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1140 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1141 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1142 vtx
.endian
= r600_endian_swap(32);
1144 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1150 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1152 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1153 struct r600_bytecode_alu alu
;
1154 int i
, j
, k
, nconst
, r
;
1156 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1157 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1160 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1162 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1163 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1167 if (ctx
->src
[i
].rel
) {
1168 int treg
= r600_get_temp(ctx
);
1169 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
1172 ctx
->src
[i
].kc_bank
= 0;
1173 ctx
->src
[i
].sel
= treg
;
1174 ctx
->src
[i
].rel
= 0;
1177 int treg
= r600_get_temp(ctx
);
1178 for (k
= 0; k
< 4; k
++) {
1179 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1180 alu
.op
= ALU_OP1_MOV
;
1181 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1182 alu
.src
[0].chan
= k
;
1183 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1189 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1193 ctx
->src
[i
].sel
= treg
;
1201 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1202 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1204 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1205 struct r600_bytecode_alu alu
;
1206 int i
, j
, k
, nliteral
, r
;
1208 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1209 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1213 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1214 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1215 int treg
= r600_get_temp(ctx
);
1216 for (k
= 0; k
< 4; k
++) {
1217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1218 alu
.op
= ALU_OP1_MOV
;
1219 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1220 alu
.src
[0].chan
= k
;
1221 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1227 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1231 ctx
->src
[i
].sel
= treg
;
1238 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1240 int i
, r
, count
= ctx
->shader
->ninput
;
1242 for (i
= 0; i
< count
; i
++) {
1243 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1244 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1252 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
1253 struct r600_pipe_shader
*pipeshader
,
1254 struct r600_shader_key key
)
1256 struct r600_shader
*shader
= &pipeshader
->shader
;
1257 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1258 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1259 struct tgsi_full_immediate
*immediate
;
1260 struct tgsi_full_property
*property
;
1261 struct r600_shader_ctx ctx
;
1262 struct r600_bytecode_output output
[32];
1263 unsigned output_done
, noutput
;
1266 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
1267 /* Declarations used by llvm code */
1268 bool use_llvm
= false;
1269 unsigned char * inst_bytes
= NULL
;
1270 unsigned inst_byte_count
= 0;
1272 #ifdef R600_USE_LLVM
1273 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
1275 ctx
.bc
= &shader
->bc
;
1276 ctx
.shader
= shader
;
1277 ctx
.native_integers
= true;
1279 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
1280 rscreen
->msaa_texture_support
);
1281 ctx
.tokens
= tokens
;
1282 tgsi_scan_shader(tokens
, &ctx
.info
);
1283 tgsi_parse_init(&ctx
.parse
, tokens
);
1284 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1285 shader
->processor_type
= ctx
.type
;
1286 ctx
.bc
->type
= shader
->processor_type
;
1289 ctx
.fragcoord_input
= -1;
1290 ctx
.colors_used
= 0;
1291 ctx
.clip_vertex_write
= 0;
1293 shader
->nr_ps_color_exports
= 0;
1294 shader
->nr_ps_max_color_exports
= 0;
1296 shader
->two_side
= key
.color_two_side
;
1298 /* register allocations */
1299 /* Values [0,127] correspond to GPR[0..127].
1300 * Values [128,159] correspond to constant buffer bank 0
1301 * Values [160,191] correspond to constant buffer bank 1
1302 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1303 * Values [256,287] correspond to constant buffer bank 2 (EG)
1304 * Values [288,319] correspond to constant buffer bank 3 (EG)
1305 * Other special values are shown in the list below.
1306 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1307 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1308 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1309 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1310 * 248 SQ_ALU_SRC_0: special constant 0.0.
1311 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1312 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1313 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1314 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1315 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1316 * 254 SQ_ALU_SRC_PV: previous vector result.
1317 * 255 SQ_ALU_SRC_PS: previous scalar result.
1319 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1320 ctx
.file_offset
[i
] = 0;
1322 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1323 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1324 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1326 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1327 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1330 #ifdef R600_USE_LLVM
1331 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1332 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1333 "indirect adressing. Falling back to TGSI "
1338 ctx
.use_llvm
= use_llvm
;
1341 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1342 ctx
.file_offset
[TGSI_FILE_INPUT
];
1344 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1345 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1346 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1348 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1349 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1351 /* Outside the GPR range. This will be translated to one of the
1352 * kcache banks later. */
1353 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1355 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1356 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1357 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1358 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1361 ctx
.literals
= NULL
;
1362 shader
->fs_write_all
= FALSE
;
1363 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1364 tgsi_parse_token(&ctx
.parse
);
1365 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1366 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1367 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1368 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1369 if(ctx
.literals
== NULL
) {
1373 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1374 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1375 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1376 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1379 case TGSI_TOKEN_TYPE_DECLARATION
:
1380 r
= tgsi_declaration(&ctx
);
1384 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1386 case TGSI_TOKEN_TYPE_PROPERTY
:
1387 property
= &ctx
.parse
.FullToken
.FullProperty
;
1388 switch (property
->Property
.PropertyName
) {
1389 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1390 if (property
->u
[0].Data
== 1)
1391 shader
->fs_write_all
= TRUE
;
1393 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1394 /* we don't need this one */
1399 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1405 /* Process two side if needed */
1406 if (shader
->two_side
&& ctx
.colors_used
) {
1407 int i
, count
= ctx
.shader
->ninput
;
1408 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1410 /* additional inputs will be allocated right after the existing inputs,
1411 * we won't need them after the color selection, so we don't need to
1412 * reserve these gprs for the rest of the shader code and to adjust
1413 * output offsets etc. */
1414 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1415 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1417 if (ctx
.face_gpr
== -1) {
1418 i
= ctx
.shader
->ninput
++;
1419 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1420 ctx
.shader
->input
[i
].spi_sid
= 0;
1421 ctx
.shader
->input
[i
].gpr
= gpr
++;
1422 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1425 for (i
= 0; i
< count
; i
++) {
1426 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1427 int ni
= ctx
.shader
->ninput
++;
1428 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1429 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1430 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1431 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1432 // TGSI to LLVM needs to know the lds position of inputs.
1433 // Non LLVM path computes it later (in process_twoside_color)
1434 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1435 ctx
.shader
->input
[i
].back_color_input
= ni
;
1436 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1437 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1444 /* LLVM backend setup */
1445 #ifdef R600_USE_LLVM
1447 struct radeon_llvm_context radeon_llvm_ctx
;
1449 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1451 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1452 radeon_llvm_ctx
.type
= ctx
.type
;
1453 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1454 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1455 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1456 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1457 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1458 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1459 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1460 radeon_llvm_ctx
.stream_outputs
= &so
;
1461 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1462 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1463 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1465 if (r600_llvm_compile(mod
, &inst_bytes
, &inst_byte_count
,
1466 rscreen
->family
, dump
)) {
1468 radeon_llvm_dispose(&radeon_llvm_ctx
);
1470 fprintf(stderr
, "R600 LLVM backend failed to compile "
1471 "shader. Falling back to TGSI\n");
1473 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1474 ctx
.file_offset
[TGSI_FILE_INPUT
];
1476 radeon_llvm_dispose(&radeon_llvm_ctx
);
1479 /* End of LLVM backend setup */
1481 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1482 shader
->nr_ps_max_color_exports
= 8;
1485 if (ctx
.fragcoord_input
>= 0) {
1486 if (ctx
.bc
->chip_class
== CAYMAN
) {
1487 for (j
= 0 ; j
< 4; j
++) {
1488 struct r600_bytecode_alu alu
;
1489 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1490 alu
.op
= ALU_OP1_RECIP_IEEE
;
1491 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1492 alu
.src
[0].chan
= 3;
1494 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1496 alu
.dst
.write
= (j
== 3);
1498 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1502 struct r600_bytecode_alu alu
;
1503 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1504 alu
.op
= ALU_OP1_RECIP_IEEE
;
1505 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1506 alu
.src
[0].chan
= 3;
1508 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1512 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1517 if (shader
->two_side
&& ctx
.colors_used
) {
1518 if ((r
= process_twoside_color_inputs(&ctx
)))
1522 tgsi_parse_init(&ctx
.parse
, tokens
);
1523 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1524 tgsi_parse_token(&ctx
.parse
);
1525 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1526 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1527 r
= tgsi_is_supported(&ctx
);
1530 ctx
.max_driver_temp_used
= 0;
1531 /* reserve first tmp for everyone */
1532 r600_get_temp(&ctx
);
1534 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1535 if ((r
= tgsi_split_constant(&ctx
)))
1537 if ((r
= tgsi_split_literal_constant(&ctx
)))
1539 if (ctx
.bc
->chip_class
== CAYMAN
)
1540 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1541 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1542 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1544 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1545 r
= ctx
.inst_info
->process(&ctx
);
1555 /* Reset the temporary register counter. */
1556 ctx
.max_driver_temp_used
= 0;
1558 /* Get instructions if we are using the LLVM backend. */
1560 r600_bytecode_from_byte_stream(&ctx
, inst_bytes
, inst_byte_count
);
1564 noutput
= shader
->noutput
;
1566 if (ctx
.clip_vertex_write
) {
1567 unsigned clipdist_temp
[2];
1569 clipdist_temp
[0] = r600_get_temp(&ctx
);
1570 clipdist_temp
[1] = r600_get_temp(&ctx
);
1572 /* need to convert a clipvertex write into clipdistance writes and not export
1573 the clip vertex anymore */
1575 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1576 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1577 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1579 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1580 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1583 /* reset spi_sid for clipvertex output to avoid confusing spi */
1584 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1586 shader
->clip_dist_write
= 0xFF;
1588 for (i
= 0; i
< 8; i
++) {
1592 for (j
= 0; j
< 4; j
++) {
1593 struct r600_bytecode_alu alu
;
1594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1595 alu
.op
= ALU_OP2_DOT4
;
1596 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1597 alu
.src
[0].chan
= j
;
1599 alu
.src
[1].sel
= 512 + i
;
1600 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1601 alu
.src
[1].chan
= j
;
1603 alu
.dst
.sel
= clipdist_temp
[oreg
];
1605 alu
.dst
.write
= (j
== ochan
);
1609 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1616 /* Add stream outputs. */
1617 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1618 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1620 /* Sanity checking. */
1621 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1622 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1626 for (i
= 0; i
< so
.num_outputs
; i
++) {
1627 if (so
.output
[i
].output_buffer
>= 4) {
1628 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1629 so
.output
[i
].output_buffer
);
1635 /* Initialize locations where the outputs are stored. */
1636 for (i
= 0; i
< so
.num_outputs
; i
++) {
1637 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1639 /* Lower outputs with dst_offset < start_component.
1641 * We can only output 4D vectors with a write mask, e.g. we can
1642 * only output the W component at offset 3, etc. If we want
1643 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1644 * to move it to X and output X. */
1645 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1646 unsigned tmp
= r600_get_temp(&ctx
);
1648 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1649 struct r600_bytecode_alu alu
;
1650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1651 alu
.op
= ALU_OP1_MOV
;
1652 alu
.src
[0].sel
= so_gpr
[i
];
1653 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1658 if (j
== so
.output
[i
].num_components
- 1)
1660 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1664 so
.output
[i
].start_component
= 0;
1669 /* Write outputs to buffers. */
1670 for (i
= 0; i
< so
.num_outputs
; i
++) {
1671 struct r600_bytecode_output output
;
1673 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1674 output
.gpr
= so_gpr
[i
];
1675 output
.elem_size
= so
.output
[i
].num_components
;
1676 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1677 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1678 output
.burst_count
= 1;
1680 /* array_size is an upper limit for the burst_count
1681 * with MEM_STREAM instructions */
1682 output
.array_size
= 0xFFF;
1683 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1684 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1685 switch (so
.output
[i
].output_buffer
) {
1687 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1690 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1693 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1696 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1700 switch (so
.output
[i
].output_buffer
) {
1702 output
.op
= CF_OP_MEM_STREAM0
;
1705 output
.op
= CF_OP_MEM_STREAM1
;
1708 output
.op
= CF_OP_MEM_STREAM2
;
1711 output
.op
= CF_OP_MEM_STREAM3
;
1715 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1722 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1723 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1724 output
[j
].gpr
= shader
->output
[i
].gpr
;
1725 output
[j
].elem_size
= 3;
1726 output
[j
].swizzle_x
= 0;
1727 output
[j
].swizzle_y
= 1;
1728 output
[j
].swizzle_z
= 2;
1729 output
[j
].swizzle_w
= 3;
1730 output
[j
].burst_count
= 1;
1731 output
[j
].barrier
= 1;
1732 output
[j
].type
= -1;
1733 output
[j
].op
= CF_OP_EXPORT
;
1735 case TGSI_PROCESSOR_VERTEX
:
1736 switch (shader
->output
[i
].name
) {
1737 case TGSI_SEMANTIC_POSITION
:
1738 output
[j
].array_base
= next_pos_base
++;
1739 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1742 case TGSI_SEMANTIC_PSIZE
:
1743 output
[j
].array_base
= next_pos_base
++;
1744 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1746 case TGSI_SEMANTIC_CLIPVERTEX
:
1749 case TGSI_SEMANTIC_CLIPDIST
:
1750 output
[j
].array_base
= next_pos_base
++;
1751 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1752 /* spi_sid is 0 for clipdistance outputs that were generated
1753 * for clipvertex - we don't need to pass them to PS */
1754 if (shader
->output
[i
].spi_sid
) {
1756 /* duplicate it as PARAM to pass to the pixel shader */
1757 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1758 output
[j
].array_base
= next_param_base
++;
1759 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1762 case TGSI_SEMANTIC_FOG
:
1763 output
[j
].swizzle_y
= 4; /* 0 */
1764 output
[j
].swizzle_z
= 4; /* 0 */
1765 output
[j
].swizzle_w
= 5; /* 1 */
1769 case TGSI_PROCESSOR_FRAGMENT
:
1770 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1771 /* never export more colors than the number of CBs */
1772 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1777 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1778 output
[j
].array_base
= next_pixel_base
++;
1779 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1780 shader
->nr_ps_color_exports
++;
1781 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1782 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1784 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1785 output
[j
].gpr
= shader
->output
[i
].gpr
;
1786 output
[j
].elem_size
= 3;
1787 output
[j
].swizzle_x
= 0;
1788 output
[j
].swizzle_y
= 1;
1789 output
[j
].swizzle_z
= 2;
1790 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1791 output
[j
].burst_count
= 1;
1792 output
[j
].barrier
= 1;
1793 output
[j
].array_base
= next_pixel_base
++;
1794 output
[j
].op
= CF_OP_EXPORT
;
1795 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1796 shader
->nr_ps_color_exports
++;
1799 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1800 output
[j
].array_base
= 61;
1801 output
[j
].swizzle_x
= 2;
1802 output
[j
].swizzle_y
= 7;
1803 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1804 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1805 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1806 output
[j
].array_base
= 61;
1807 output
[j
].swizzle_x
= 7;
1808 output
[j
].swizzle_y
= 1;
1809 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1810 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1812 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1818 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1823 if (output
[j
].type
==-1) {
1824 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1825 output
[j
].array_base
= next_param_base
++;
1829 /* add fake position export */
1830 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1831 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1833 output
[j
].elem_size
= 3;
1834 output
[j
].swizzle_x
= 7;
1835 output
[j
].swizzle_y
= 7;
1836 output
[j
].swizzle_z
= 7;
1837 output
[j
].swizzle_w
= 7;
1838 output
[j
].burst_count
= 1;
1839 output
[j
].barrier
= 1;
1840 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1841 output
[j
].array_base
= next_pos_base
;
1842 output
[j
].op
= CF_OP_EXPORT
;
1846 /* add fake param output for vertex shader if no param is exported */
1847 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1848 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1850 output
[j
].elem_size
= 3;
1851 output
[j
].swizzle_x
= 7;
1852 output
[j
].swizzle_y
= 7;
1853 output
[j
].swizzle_z
= 7;
1854 output
[j
].swizzle_w
= 7;
1855 output
[j
].burst_count
= 1;
1856 output
[j
].barrier
= 1;
1857 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1858 output
[j
].array_base
= 0;
1859 output
[j
].op
= CF_OP_EXPORT
;
1863 /* add fake pixel export */
1864 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1865 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1867 output
[j
].elem_size
= 3;
1868 output
[j
].swizzle_x
= 7;
1869 output
[j
].swizzle_y
= 7;
1870 output
[j
].swizzle_z
= 7;
1871 output
[j
].swizzle_w
= 7;
1872 output
[j
].burst_count
= 1;
1873 output
[j
].barrier
= 1;
1874 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1875 output
[j
].array_base
= 0;
1876 output
[j
].op
= CF_OP_EXPORT
;
1882 /* set export done on last export of each type */
1883 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1884 if (ctx
.bc
->chip_class
< CAYMAN
) {
1885 if (i
== (noutput
- 1)) {
1886 output
[i
].end_of_program
= 1;
1889 if (!(output_done
& (1 << output
[i
].type
))) {
1890 output_done
|= (1 << output
[i
].type
);
1891 output
[i
].op
= CF_OP_EXPORT_DONE
;
1894 /* add output to bytecode */
1896 for (i
= 0; i
< noutput
; i
++) {
1897 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1902 /* add program end */
1903 if (ctx
.bc
->chip_class
== CAYMAN
)
1904 cm_bytecode_add_cf_end(ctx
.bc
);
1906 /* check GPR limit - we have 124 = 128 - 4
1907 * (4 are reserved as alu clause temporary registers) */
1908 if (ctx
.bc
->ngpr
> 124) {
1909 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1915 tgsi_parse_free(&ctx
.parse
);
1919 tgsi_parse_free(&ctx
.parse
);
1923 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1925 R600_ERR("%s tgsi opcode unsupported\n",
1926 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1930 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1935 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1936 const struct r600_shader_src
*shader_src
,
1939 bc_src
->sel
= shader_src
->sel
;
1940 bc_src
->chan
= shader_src
->swizzle
[chan
];
1941 bc_src
->neg
= shader_src
->neg
;
1942 bc_src
->abs
= shader_src
->abs
;
1943 bc_src
->rel
= shader_src
->rel
;
1944 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1945 bc_src
->kc_bank
= shader_src
->kc_bank
;
1948 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1954 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1956 bc_src
->neg
= !bc_src
->neg
;
1959 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1960 const struct tgsi_full_dst_register
*tgsi_dst
,
1962 struct r600_bytecode_alu_dst
*r600_dst
)
1964 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1966 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1967 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1968 r600_dst
->chan
= swizzle
;
1969 r600_dst
->write
= 1;
1970 if (tgsi_dst
->Register
.Indirect
)
1971 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1972 if (inst
->Instruction
.Saturate
) {
1973 r600_dst
->clamp
= 1;
1977 static int tgsi_last_instruction(unsigned writemask
)
1981 for (i
= 0; i
< 4; i
++) {
1982 if (writemask
& (1 << i
)) {
1989 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1991 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1992 struct r600_bytecode_alu alu
;
1994 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1996 for (i
= 0; i
< lasti
+ 1; i
++) {
1997 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2000 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2001 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2003 alu
.op
= ctx
->inst_info
->op
;
2005 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2006 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2009 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2010 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2012 /* handle some special cases */
2013 switch (ctx
->inst_info
->tgsi_opcode
) {
2014 case TGSI_OPCODE_SUB
:
2015 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2017 case TGSI_OPCODE_ABS
:
2018 r600_bytecode_src_set_abs(&alu
.src
[0]);
2023 if (i
== lasti
|| trans_only
) {
2026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2033 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2035 return tgsi_op2_s(ctx
, 0, 0);
2038 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2040 return tgsi_op2_s(ctx
, 1, 0);
2043 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2045 return tgsi_op2_s(ctx
, 0, 1);
2048 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2050 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2051 struct r600_bytecode_alu alu
;
2053 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2055 for (i
= 0; i
< lasti
+ 1; i
++) {
2057 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2060 alu
.op
= ctx
->inst_info
->op
;
2062 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2064 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2066 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2071 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2079 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2081 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2083 struct r600_bytecode_alu alu
;
2084 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2086 for (i
= 0 ; i
< last_slot
; i
++) {
2087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2088 alu
.op
= ctx
->inst_info
->op
;
2089 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2090 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2092 /* RSQ should take the absolute value of src */
2093 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2094 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2097 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2098 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2100 if (i
== last_slot
- 1)
2102 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2109 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2111 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2113 struct r600_bytecode_alu alu
;
2114 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2115 for (k
= 0; k
< last_slot
; k
++) {
2116 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2119 for (i
= 0 ; i
< 4; i
++) {
2120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2121 alu
.op
= ctx
->inst_info
->op
;
2122 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2123 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2125 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2126 alu
.dst
.write
= (i
== k
);
2129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2138 * r600 - trunc to -PI..PI range
2139 * r700 - normalize by dividing by 2PI
2142 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2144 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2145 static float double_pi
= 3.1415926535 * 2;
2146 static float neg_pi
= -3.1415926535;
2149 struct r600_bytecode_alu alu
;
2151 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2152 alu
.op
= ALU_OP3_MULADD
;
2156 alu
.dst
.sel
= ctx
->temp_reg
;
2159 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2161 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2162 alu
.src
[1].chan
= 0;
2163 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2164 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2165 alu
.src
[2].chan
= 0;
2167 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2172 alu
.op
= ALU_OP1_FRACT
;
2175 alu
.dst
.sel
= ctx
->temp_reg
;
2178 alu
.src
[0].sel
= ctx
->temp_reg
;
2179 alu
.src
[0].chan
= 0;
2181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2185 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2186 alu
.op
= ALU_OP3_MULADD
;
2190 alu
.dst
.sel
= ctx
->temp_reg
;
2193 alu
.src
[0].sel
= ctx
->temp_reg
;
2194 alu
.src
[0].chan
= 0;
2196 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2197 alu
.src
[1].chan
= 0;
2198 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2199 alu
.src
[2].chan
= 0;
2201 if (ctx
->bc
->chip_class
== R600
) {
2202 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2203 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2205 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2206 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2211 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2217 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2219 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2220 struct r600_bytecode_alu alu
;
2221 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2224 r
= tgsi_setup_trig(ctx
);
2229 for (i
= 0; i
< last_slot
; i
++) {
2230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2231 alu
.op
= ctx
->inst_info
->op
;
2234 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2235 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2237 alu
.src
[0].sel
= ctx
->temp_reg
;
2238 alu
.src
[0].chan
= 0;
2239 if (i
== last_slot
- 1)
2241 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2248 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2250 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2251 struct r600_bytecode_alu alu
;
2253 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2255 r
= tgsi_setup_trig(ctx
);
2259 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2260 alu
.op
= ctx
->inst_info
->op
;
2262 alu
.dst
.sel
= ctx
->temp_reg
;
2265 alu
.src
[0].sel
= ctx
->temp_reg
;
2266 alu
.src
[0].chan
= 0;
2268 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2272 /* replicate result */
2273 for (i
= 0; i
< lasti
+ 1; i
++) {
2274 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2278 alu
.op
= ALU_OP1_MOV
;
2280 alu
.src
[0].sel
= ctx
->temp_reg
;
2281 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2291 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2293 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2294 struct r600_bytecode_alu alu
;
2297 /* We'll only need the trig stuff if we are going to write to the
2298 * X or Y components of the destination vector.
2300 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2301 r
= tgsi_setup_trig(ctx
);
2307 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2308 if (ctx
->bc
->chip_class
== CAYMAN
) {
2309 for (i
= 0 ; i
< 3; i
++) {
2310 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2311 alu
.op
= ALU_OP1_COS
;
2312 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2318 alu
.src
[0].sel
= ctx
->temp_reg
;
2319 alu
.src
[0].chan
= 0;
2322 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2327 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2328 alu
.op
= ALU_OP1_COS
;
2329 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2331 alu
.src
[0].sel
= ctx
->temp_reg
;
2332 alu
.src
[0].chan
= 0;
2334 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2341 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2342 if (ctx
->bc
->chip_class
== CAYMAN
) {
2343 for (i
= 0 ; i
< 3; i
++) {
2344 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2345 alu
.op
= ALU_OP1_SIN
;
2346 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2351 alu
.src
[0].sel
= ctx
->temp_reg
;
2352 alu
.src
[0].chan
= 0;
2355 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2360 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2361 alu
.op
= ALU_OP1_SIN
;
2362 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2364 alu
.src
[0].sel
= ctx
->temp_reg
;
2365 alu
.src
[0].chan
= 0;
2367 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2374 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2375 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2377 alu
.op
= ALU_OP1_MOV
;
2379 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2381 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2382 alu
.src
[0].chan
= 0;
2386 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2392 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2393 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2395 alu
.op
= ALU_OP1_MOV
;
2397 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2399 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2400 alu
.src
[0].chan
= 0;
2404 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2412 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2414 struct r600_bytecode_alu alu
;
2417 for (i
= 0; i
< 4; i
++) {
2418 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2419 alu
.op
= ctx
->inst_info
->op
;
2423 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2425 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2426 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2429 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2434 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2439 /* kill must be last in ALU */
2440 ctx
->bc
->force_add_cf
= 1;
2441 ctx
->shader
->uses_kill
= TRUE
;
2445 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2447 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2448 struct r600_bytecode_alu alu
;
2451 /* tmp.x = max(src.y, 0.0) */
2452 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2453 alu
.op
= ALU_OP2_MAX
;
2454 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2455 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2456 alu
.src
[1].chan
= 1;
2458 alu
.dst
.sel
= ctx
->temp_reg
;
2463 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2467 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2473 if (ctx
->bc
->chip_class
== CAYMAN
) {
2474 for (i
= 0; i
< 3; i
++) {
2475 /* tmp.z = log(tmp.x) */
2476 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2477 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2478 alu
.src
[0].sel
= ctx
->temp_reg
;
2479 alu
.src
[0].chan
= 0;
2480 alu
.dst
.sel
= ctx
->temp_reg
;
2488 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2493 /* tmp.z = log(tmp.x) */
2494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2495 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2496 alu
.src
[0].sel
= ctx
->temp_reg
;
2497 alu
.src
[0].chan
= 0;
2498 alu
.dst
.sel
= ctx
->temp_reg
;
2502 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2507 chan
= alu
.dst
.chan
;
2510 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2512 alu
.op
= ALU_OP3_MUL_LIT
;
2513 alu
.src
[0].sel
= sel
;
2514 alu
.src
[0].chan
= chan
;
2515 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2516 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2517 alu
.dst
.sel
= ctx
->temp_reg
;
2522 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2526 if (ctx
->bc
->chip_class
== CAYMAN
) {
2527 for (i
= 0; i
< 3; i
++) {
2528 /* dst.z = exp(tmp.x) */
2529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2530 alu
.op
= ALU_OP1_EXP_IEEE
;
2531 alu
.src
[0].sel
= ctx
->temp_reg
;
2532 alu
.src
[0].chan
= 0;
2533 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2539 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2544 /* dst.z = exp(tmp.x) */
2545 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2546 alu
.op
= ALU_OP1_EXP_IEEE
;
2547 alu
.src
[0].sel
= ctx
->temp_reg
;
2548 alu
.src
[0].chan
= 0;
2549 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2551 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2558 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2559 alu
.op
= ALU_OP1_MOV
;
2560 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2561 alu
.src
[0].chan
= 0;
2562 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2563 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2564 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2568 /* dst.y = max(src.x, 0.0) */
2569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2570 alu
.op
= ALU_OP2_MAX
;
2571 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2572 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2573 alu
.src
[1].chan
= 0;
2574 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2575 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2576 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2581 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2582 alu
.op
= ALU_OP1_MOV
;
2583 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2584 alu
.src
[0].chan
= 0;
2585 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2586 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2588 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2595 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2597 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2598 struct r600_bytecode_alu alu
;
2601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2604 * For state trackers other than OpenGL, we'll want to use
2605 * _RECIPSQRT_IEEE instead.
2607 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2609 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2610 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2611 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2613 alu
.dst
.sel
= ctx
->temp_reg
;
2616 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2619 /* replicate result */
2620 return tgsi_helper_tempx_replicate(ctx
);
2623 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2625 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2626 struct r600_bytecode_alu alu
;
2629 for (i
= 0; i
< 4; i
++) {
2630 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2631 alu
.src
[0].sel
= ctx
->temp_reg
;
2632 alu
.op
= ALU_OP1_MOV
;
2634 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2635 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2638 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2645 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2647 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2648 struct r600_bytecode_alu alu
;
2651 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2652 alu
.op
= ctx
->inst_info
->op
;
2653 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2654 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2656 alu
.dst
.sel
= ctx
->temp_reg
;
2659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2662 /* replicate result */
2663 return tgsi_helper_tempx_replicate(ctx
);
2666 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2668 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2670 struct r600_bytecode_alu alu
;
2671 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2673 for (i
= 0; i
< 3; i
++) {
2674 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2675 alu
.op
= ALU_OP1_LOG_IEEE
;
2676 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2677 alu
.dst
.sel
= ctx
->temp_reg
;
2682 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2688 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2689 alu
.op
= ALU_OP2_MUL
;
2690 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2691 alu
.src
[1].sel
= ctx
->temp_reg
;
2692 alu
.dst
.sel
= ctx
->temp_reg
;
2695 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2699 for (i
= 0; i
< last_slot
; i
++) {
2700 /* POW(a,b) = EXP2(b * LOG2(a))*/
2701 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2702 alu
.op
= ALU_OP1_EXP_IEEE
;
2703 alu
.src
[0].sel
= ctx
->temp_reg
;
2705 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2706 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2707 if (i
== last_slot
- 1)
2709 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2716 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2718 struct r600_bytecode_alu alu
;
2722 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2723 alu
.op
= ALU_OP1_LOG_IEEE
;
2724 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2725 alu
.dst
.sel
= ctx
->temp_reg
;
2728 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2733 alu
.op
= ALU_OP2_MUL
;
2734 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2735 alu
.src
[1].sel
= ctx
->temp_reg
;
2736 alu
.dst
.sel
= ctx
->temp_reg
;
2739 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2742 /* POW(a,b) = EXP2(b * LOG2(a))*/
2743 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2744 alu
.op
= ALU_OP1_EXP_IEEE
;
2745 alu
.src
[0].sel
= ctx
->temp_reg
;
2746 alu
.dst
.sel
= ctx
->temp_reg
;
2749 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2752 return tgsi_helper_tempx_replicate(ctx
);
2755 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2757 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2758 struct r600_bytecode_alu alu
;
2760 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2761 int tmp0
= ctx
->temp_reg
;
2762 int tmp1
= r600_get_temp(ctx
);
2763 int tmp2
= r600_get_temp(ctx
);
2764 int tmp3
= r600_get_temp(ctx
);
2767 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2769 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2770 * 2. tmp0.z = lo (tmp0.x * src2)
2771 * 3. tmp0.w = -tmp0.z
2772 * 4. tmp0.y = hi (tmp0.x * src2)
2773 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2774 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2775 * 7. tmp1.x = tmp0.x - tmp0.w
2776 * 8. tmp1.y = tmp0.x + tmp0.w
2777 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2778 * 10. tmp0.z = hi(tmp0.x * src1) = q
2779 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2781 * 12. tmp0.w = src1 - tmp0.y = r
2782 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2783 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2787 * 15. tmp1.z = tmp0.z + 1 = q + 1
2788 * 16. tmp1.w = tmp0.z - 1 = q - 1
2792 * 15. tmp1.z = tmp0.w - src2 = r - src2
2793 * 16. tmp1.w = tmp0.w + src2 = r + src2
2797 * 17. tmp1.x = tmp1.x & tmp1.y
2799 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2800 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2802 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2803 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2807 * Same as unsigned, using abs values of the operands,
2808 * and fixing the sign of the result in the end.
2811 for (i
= 0; i
< 4; i
++) {
2812 if (!(write_mask
& (1<<i
)))
2817 /* tmp2.x = -src0 */
2818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2819 alu
.op
= ALU_OP2_SUB_INT
;
2825 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2827 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2830 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2833 /* tmp2.y = -src1 */
2834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2835 alu
.op
= ALU_OP2_SUB_INT
;
2841 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2843 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2846 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2849 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2850 /* it will be a sign of the quotient */
2853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2854 alu
.op
= ALU_OP2_XOR_INT
;
2860 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2861 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2864 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2868 /* tmp2.x = |src0| */
2869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2870 alu
.op
= ALU_OP3_CNDGE_INT
;
2877 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2878 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2879 alu
.src
[2].sel
= tmp2
;
2880 alu
.src
[2].chan
= 0;
2883 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2886 /* tmp2.y = |src1| */
2887 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2888 alu
.op
= ALU_OP3_CNDGE_INT
;
2895 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2896 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2897 alu
.src
[2].sel
= tmp2
;
2898 alu
.src
[2].chan
= 1;
2901 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2906 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2907 if (ctx
->bc
->chip_class
== CAYMAN
) {
2908 /* tmp3.x = u2f(src2) */
2909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2910 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2917 alu
.src
[0].sel
= tmp2
;
2918 alu
.src
[0].chan
= 1;
2920 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2924 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2927 /* tmp0.x = recip(tmp3.x) */
2928 for (j
= 0 ; j
< 3; j
++) {
2929 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2930 alu
.op
= ALU_OP1_RECIP_IEEE
;
2934 alu
.dst
.write
= (j
== 0);
2936 alu
.src
[0].sel
= tmp3
;
2937 alu
.src
[0].chan
= 0;
2941 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2946 alu
.op
= ALU_OP2_MUL
;
2948 alu
.src
[0].sel
= tmp0
;
2949 alu
.src
[0].chan
= 0;
2951 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2952 alu
.src
[1].value
= 0x4f800000;
2957 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2962 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2968 alu
.src
[0].sel
= tmp3
;
2969 alu
.src
[0].chan
= 0;
2972 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2976 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2977 alu
.op
= ALU_OP1_RECIP_UINT
;
2984 alu
.src
[0].sel
= tmp2
;
2985 alu
.src
[0].chan
= 1;
2987 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2991 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2995 /* 2. tmp0.z = lo (tmp0.x * src2) */
2996 if (ctx
->bc
->chip_class
== CAYMAN
) {
2997 for (j
= 0 ; j
< 4; j
++) {
2998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2999 alu
.op
= ALU_OP2_MULLO_UINT
;
3003 alu
.dst
.write
= (j
== 2);
3005 alu
.src
[0].sel
= tmp0
;
3006 alu
.src
[0].chan
= 0;
3008 alu
.src
[1].sel
= tmp2
;
3009 alu
.src
[1].chan
= 1;
3011 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3014 alu
.last
= (j
== 3);
3015 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3020 alu
.op
= ALU_OP2_MULLO_UINT
;
3026 alu
.src
[0].sel
= tmp0
;
3027 alu
.src
[0].chan
= 0;
3029 alu
.src
[1].sel
= tmp2
;
3030 alu
.src
[1].chan
= 1;
3032 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3036 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3040 /* 3. tmp0.w = -tmp0.z */
3041 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3042 alu
.op
= ALU_OP2_SUB_INT
;
3048 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3049 alu
.src
[1].sel
= tmp0
;
3050 alu
.src
[1].chan
= 2;
3053 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3056 /* 4. tmp0.y = hi (tmp0.x * src2) */
3057 if (ctx
->bc
->chip_class
== CAYMAN
) {
3058 for (j
= 0 ; j
< 4; j
++) {
3059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3060 alu
.op
= ALU_OP2_MULHI_UINT
;
3064 alu
.dst
.write
= (j
== 1);
3066 alu
.src
[0].sel
= tmp0
;
3067 alu
.src
[0].chan
= 0;
3070 alu
.src
[1].sel
= tmp2
;
3071 alu
.src
[1].chan
= 1;
3073 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3075 alu
.last
= (j
== 3);
3076 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3080 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3081 alu
.op
= ALU_OP2_MULHI_UINT
;
3087 alu
.src
[0].sel
= tmp0
;
3088 alu
.src
[0].chan
= 0;
3091 alu
.src
[1].sel
= tmp2
;
3092 alu
.src
[1].chan
= 1;
3094 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3098 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3102 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3103 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3104 alu
.op
= ALU_OP3_CNDE_INT
;
3111 alu
.src
[0].sel
= tmp0
;
3112 alu
.src
[0].chan
= 1;
3113 alu
.src
[1].sel
= tmp0
;
3114 alu
.src
[1].chan
= 3;
3115 alu
.src
[2].sel
= tmp0
;
3116 alu
.src
[2].chan
= 2;
3119 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3122 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
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
.op
= ALU_OP2_MULHI_UINT
;
3130 alu
.dst
.write
= (j
== 3);
3132 alu
.src
[0].sel
= tmp0
;
3133 alu
.src
[0].chan
= 2;
3135 alu
.src
[1].sel
= tmp0
;
3136 alu
.src
[1].chan
= 0;
3138 alu
.last
= (j
== 3);
3139 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3144 alu
.op
= ALU_OP2_MULHI_UINT
;
3150 alu
.src
[0].sel
= tmp0
;
3151 alu
.src
[0].chan
= 2;
3153 alu
.src
[1].sel
= tmp0
;
3154 alu
.src
[1].chan
= 0;
3157 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3161 /* 7. tmp1.x = tmp0.x - tmp0.w */
3162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3163 alu
.op
= ALU_OP2_SUB_INT
;
3169 alu
.src
[0].sel
= tmp0
;
3170 alu
.src
[0].chan
= 0;
3171 alu
.src
[1].sel
= tmp0
;
3172 alu
.src
[1].chan
= 3;
3175 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3178 /* 8. tmp1.y = tmp0.x + tmp0.w */
3179 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3180 alu
.op
= ALU_OP2_ADD_INT
;
3186 alu
.src
[0].sel
= tmp0
;
3187 alu
.src
[0].chan
= 0;
3188 alu
.src
[1].sel
= tmp0
;
3189 alu
.src
[1].chan
= 3;
3192 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3195 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3197 alu
.op
= ALU_OP3_CNDE_INT
;
3204 alu
.src
[0].sel
= tmp0
;
3205 alu
.src
[0].chan
= 1;
3206 alu
.src
[1].sel
= tmp1
;
3207 alu
.src
[1].chan
= 1;
3208 alu
.src
[2].sel
= tmp1
;
3209 alu
.src
[2].chan
= 0;
3212 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3215 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3216 if (ctx
->bc
->chip_class
== CAYMAN
) {
3217 for (j
= 0 ; j
< 4; j
++) {
3218 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3219 alu
.op
= ALU_OP2_MULHI_UINT
;
3223 alu
.dst
.write
= (j
== 2);
3225 alu
.src
[0].sel
= tmp0
;
3226 alu
.src
[0].chan
= 0;
3229 alu
.src
[1].sel
= tmp2
;
3230 alu
.src
[1].chan
= 0;
3232 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3235 alu
.last
= (j
== 3);
3236 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3241 alu
.op
= ALU_OP2_MULHI_UINT
;
3247 alu
.src
[0].sel
= tmp0
;
3248 alu
.src
[0].chan
= 0;
3251 alu
.src
[1].sel
= tmp2
;
3252 alu
.src
[1].chan
= 0;
3254 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3258 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3262 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3263 if (ctx
->bc
->chip_class
== CAYMAN
) {
3264 for (j
= 0 ; j
< 4; j
++) {
3265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3266 alu
.op
= ALU_OP2_MULLO_UINT
;
3270 alu
.dst
.write
= (j
== 1);
3273 alu
.src
[0].sel
= tmp2
;
3274 alu
.src
[0].chan
= 1;
3276 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3279 alu
.src
[1].sel
= tmp0
;
3280 alu
.src
[1].chan
= 2;
3282 alu
.last
= (j
== 3);
3283 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3287 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3288 alu
.op
= ALU_OP2_MULLO_UINT
;
3295 alu
.src
[0].sel
= tmp2
;
3296 alu
.src
[0].chan
= 1;
3298 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3301 alu
.src
[1].sel
= tmp0
;
3302 alu
.src
[1].chan
= 2;
3305 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3309 /* 12. tmp0.w = src1 - tmp0.y = r */
3310 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3311 alu
.op
= ALU_OP2_SUB_INT
;
3318 alu
.src
[0].sel
= tmp2
;
3319 alu
.src
[0].chan
= 0;
3321 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3324 alu
.src
[1].sel
= tmp0
;
3325 alu
.src
[1].chan
= 1;
3328 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3331 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3332 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3333 alu
.op
= ALU_OP2_SETGE_UINT
;
3339 alu
.src
[0].sel
= tmp0
;
3340 alu
.src
[0].chan
= 3;
3342 alu
.src
[1].sel
= tmp2
;
3343 alu
.src
[1].chan
= 1;
3345 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3349 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3352 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3354 alu
.op
= ALU_OP2_SETGE_UINT
;
3361 alu
.src
[0].sel
= tmp2
;
3362 alu
.src
[0].chan
= 0;
3364 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3367 alu
.src
[1].sel
= tmp0
;
3368 alu
.src
[1].chan
= 1;
3371 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3374 if (mod
) { /* UMOD */
3376 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3378 alu
.op
= ALU_OP2_SUB_INT
;
3384 alu
.src
[0].sel
= tmp0
;
3385 alu
.src
[0].chan
= 3;
3388 alu
.src
[1].sel
= tmp2
;
3389 alu
.src
[1].chan
= 1;
3391 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3395 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3398 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3399 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3400 alu
.op
= ALU_OP2_ADD_INT
;
3406 alu
.src
[0].sel
= tmp0
;
3407 alu
.src
[0].chan
= 3;
3409 alu
.src
[1].sel
= tmp2
;
3410 alu
.src
[1].chan
= 1;
3412 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3416 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3421 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3422 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3423 alu
.op
= ALU_OP2_ADD_INT
;
3429 alu
.src
[0].sel
= tmp0
;
3430 alu
.src
[0].chan
= 2;
3431 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3434 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3437 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3438 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3439 alu
.op
= ALU_OP2_ADD_INT
;
3445 alu
.src
[0].sel
= tmp0
;
3446 alu
.src
[0].chan
= 2;
3447 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3450 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3455 /* 17. tmp1.x = tmp1.x & tmp1.y */
3456 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3457 alu
.op
= ALU_OP2_AND_INT
;
3463 alu
.src
[0].sel
= tmp1
;
3464 alu
.src
[0].chan
= 0;
3465 alu
.src
[1].sel
= tmp1
;
3466 alu
.src
[1].chan
= 1;
3469 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3472 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3473 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3475 alu
.op
= ALU_OP3_CNDE_INT
;
3482 alu
.src
[0].sel
= tmp1
;
3483 alu
.src
[0].chan
= 0;
3484 alu
.src
[1].sel
= tmp0
;
3485 alu
.src
[1].chan
= mod
? 3 : 2;
3486 alu
.src
[2].sel
= tmp1
;
3487 alu
.src
[2].chan
= 2;
3490 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3493 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3495 alu
.op
= ALU_OP3_CNDE_INT
;
3503 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3506 alu
.src
[0].sel
= tmp1
;
3507 alu
.src
[0].chan
= 1;
3508 alu
.src
[1].sel
= tmp1
;
3509 alu
.src
[1].chan
= 3;
3510 alu
.src
[2].sel
= tmp0
;
3511 alu
.src
[2].chan
= 2;
3514 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3519 /* fix the sign of the result */
3523 /* tmp0.x = -tmp0.z */
3524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3525 alu
.op
= ALU_OP2_SUB_INT
;
3531 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3532 alu
.src
[1].sel
= tmp0
;
3533 alu
.src
[1].chan
= 2;
3536 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3539 /* sign of the remainder is the same as the sign of src0 */
3540 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3542 alu
.op
= ALU_OP3_CNDGE_INT
;
3545 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3547 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3548 alu
.src
[1].sel
= tmp0
;
3549 alu
.src
[1].chan
= 2;
3550 alu
.src
[2].sel
= tmp0
;
3551 alu
.src
[2].chan
= 0;
3554 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3559 /* tmp0.x = -tmp0.z */
3560 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3561 alu
.op
= ALU_OP2_SUB_INT
;
3567 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3568 alu
.src
[1].sel
= tmp0
;
3569 alu
.src
[1].chan
= 2;
3572 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3575 /* fix the quotient sign (same as the sign of src0*src1) */
3576 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3577 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3578 alu
.op
= ALU_OP3_CNDGE_INT
;
3581 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3583 alu
.src
[0].sel
= tmp2
;
3584 alu
.src
[0].chan
= 2;
3585 alu
.src
[1].sel
= tmp0
;
3586 alu
.src
[1].chan
= 2;
3587 alu
.src
[2].sel
= tmp0
;
3588 alu
.src
[2].chan
= 0;
3591 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3599 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3601 return tgsi_divmod(ctx
, 0, 0);
3604 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3606 return tgsi_divmod(ctx
, 1, 0);
3609 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3611 return tgsi_divmod(ctx
, 0, 1);
3614 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3616 return tgsi_divmod(ctx
, 1, 1);
3620 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3622 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3623 struct r600_bytecode_alu alu
;
3625 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3626 int last_inst
= tgsi_last_instruction(write_mask
);
3628 for (i
= 0; i
< 4; i
++) {
3629 if (!(write_mask
& (1<<i
)))
3632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3633 alu
.op
= ALU_OP1_TRUNC
;
3635 alu
.dst
.sel
= ctx
->temp_reg
;
3639 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3642 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3647 for (i
= 0; i
< 4; i
++) {
3648 if (!(write_mask
& (1<<i
)))
3651 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3652 alu
.op
= ctx
->inst_info
->op
;
3654 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3656 alu
.src
[0].sel
= ctx
->temp_reg
;
3657 alu
.src
[0].chan
= i
;
3659 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3661 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3669 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3671 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3672 struct r600_bytecode_alu alu
;
3674 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3675 int last_inst
= tgsi_last_instruction(write_mask
);
3678 for (i
= 0; i
< 4; i
++) {
3679 if (!(write_mask
& (1<<i
)))
3682 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3683 alu
.op
= ALU_OP2_SUB_INT
;
3685 alu
.dst
.sel
= ctx
->temp_reg
;
3689 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3690 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3694 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3699 /* dst = (src >= 0 ? src : tmp) */
3700 for (i
= 0; i
< 4; i
++) {
3701 if (!(write_mask
& (1<<i
)))
3704 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3705 alu
.op
= ALU_OP3_CNDGE_INT
;
3709 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3711 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3712 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3713 alu
.src
[2].sel
= ctx
->temp_reg
;
3714 alu
.src
[2].chan
= i
;
3718 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3725 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3727 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3728 struct r600_bytecode_alu alu
;
3730 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3731 int last_inst
= tgsi_last_instruction(write_mask
);
3733 /* tmp = (src >= 0 ? src : -1) */
3734 for (i
= 0; i
< 4; i
++) {
3735 if (!(write_mask
& (1<<i
)))
3738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3739 alu
.op
= ALU_OP3_CNDGE_INT
;
3742 alu
.dst
.sel
= ctx
->temp_reg
;
3746 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3747 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3748 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3757 /* dst = (tmp > 0 ? 1 : tmp) */
3758 for (i
= 0; i
< 4; i
++) {
3759 if (!(write_mask
& (1<<i
)))
3762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3763 alu
.op
= ALU_OP3_CNDGT_INT
;
3767 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3769 alu
.src
[0].sel
= ctx
->temp_reg
;
3770 alu
.src
[0].chan
= i
;
3772 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3774 alu
.src
[2].sel
= ctx
->temp_reg
;
3775 alu
.src
[2].chan
= i
;
3779 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3788 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3790 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3791 struct r600_bytecode_alu alu
;
3794 /* tmp = (src > 0 ? 1 : src) */
3795 for (i
= 0; i
< 4; i
++) {
3796 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3797 alu
.op
= ALU_OP3_CNDGT
;
3800 alu
.dst
.sel
= ctx
->temp_reg
;
3803 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3804 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3805 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3809 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3814 /* dst = (-tmp > 0 ? -1 : tmp) */
3815 for (i
= 0; i
< 4; i
++) {
3816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3817 alu
.op
= ALU_OP3_CNDGT
;
3819 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3821 alu
.src
[0].sel
= ctx
->temp_reg
;
3822 alu
.src
[0].chan
= i
;
3825 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3828 alu
.src
[2].sel
= ctx
->temp_reg
;
3829 alu
.src
[2].chan
= i
;
3833 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3840 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3842 struct r600_bytecode_alu alu
;
3845 for (i
= 0; i
< 4; i
++) {
3846 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3847 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3848 alu
.op
= ALU_OP0_NOP
;
3851 alu
.op
= ALU_OP1_MOV
;
3852 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3853 alu
.src
[0].sel
= ctx
->temp_reg
;
3854 alu
.src
[0].chan
= i
;
3859 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3866 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3868 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3869 struct r600_bytecode_alu alu
;
3871 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3873 for (i
= 0; i
< lasti
+ 1; i
++) {
3874 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3878 alu
.op
= ctx
->inst_info
->op
;
3879 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3880 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3883 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3890 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3897 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3899 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3900 struct r600_bytecode_alu alu
;
3903 for (i
= 0; i
< 4; i
++) {
3904 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3905 alu
.op
= ctx
->inst_info
->op
;
3906 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3907 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3910 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3912 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3913 /* handle some special cases */
3914 switch (ctx
->inst_info
->tgsi_opcode
) {
3915 case TGSI_OPCODE_DP2
:
3917 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3918 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3921 case TGSI_OPCODE_DP3
:
3923 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3924 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3927 case TGSI_OPCODE_DPH
:
3929 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3930 alu
.src
[0].chan
= 0;
3940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3947 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3950 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3951 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3952 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3953 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3954 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3957 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3960 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3961 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3964 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3966 struct r600_bytecode_vtx vtx
;
3967 struct r600_bytecode_alu alu
;
3968 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3970 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3972 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3973 if (src_requires_loading
) {
3974 for (i
= 0; i
< 4; i
++) {
3975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3976 alu
.op
= ALU_OP1_MOV
;
3977 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3978 alu
.dst
.sel
= ctx
->temp_reg
;
3983 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3987 src_gpr
= ctx
->temp_reg
;
3990 memset(&vtx
, 0, sizeof(vtx
));
3991 vtx
.op
= FETCH_OP_VFETCH
;
3992 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3993 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3994 vtx
.src_gpr
= src_gpr
;
3995 vtx
.mega_fetch_count
= 16;
3996 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3997 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3998 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3999 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4000 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4001 vtx
.use_const_fields
= 1;
4002 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4004 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4007 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4010 for (i
= 0; i
< 4; i
++) {
4011 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4012 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4016 alu
.op
= ALU_OP2_AND_INT
;
4019 alu
.dst
.sel
= vtx
.dst_gpr
;
4022 alu
.src
[0].sel
= vtx
.dst_gpr
;
4023 alu
.src
[0].chan
= i
;
4025 alu
.src
[1].sel
= 512 + (id
* 2);
4026 alu
.src
[1].chan
= i
% 4;
4027 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4031 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4036 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4038 alu
.op
= ALU_OP2_OR_INT
;
4041 alu
.dst
.sel
= vtx
.dst_gpr
;
4044 alu
.src
[0].sel
= vtx
.dst_gpr
;
4045 alu
.src
[0].chan
= 3;
4047 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4048 alu
.src
[1].chan
= 0;
4049 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4052 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4059 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4061 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4062 struct r600_bytecode_alu alu
;
4064 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4066 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4067 alu
.op
= ALU_OP1_MOV
;
4069 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4070 alu
.src
[0].sel
= 512 + (id
/ 4);
4071 alu
.src
[0].chan
= id
% 4;
4073 /* r600 we have them at channel 2 of the second dword */
4074 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4075 alu
.src
[0].chan
= 1;
4077 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4078 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4080 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4086 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4088 static float one_point_five
= 1.5f
;
4089 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4090 struct r600_bytecode_tex tex
;
4091 struct r600_bytecode_alu alu
;
4095 bool read_compressed_msaa
= ctx
->bc
->msaa_texture_mode
== MSAA_TEXTURE_COMPRESSED
&&
4096 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4097 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4098 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4099 /* Texture fetch instructions can only use gprs as source.
4100 * Also they cannot negate the source or take the absolute value */
4101 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4102 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4103 read_compressed_msaa
;
4104 boolean src_loaded
= FALSE
;
4105 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4106 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4107 boolean has_txq_cube_array_z
= false;
4109 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4110 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4111 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4112 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4113 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4114 has_txq_cube_array_z
= true;
4117 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4118 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4119 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4120 sampler_src_reg
= 2;
4122 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4124 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4125 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4126 ctx
->shader
->uses_tex_buffers
= true;
4127 return r600_do_buffer_txq(ctx
);
4129 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4130 if (ctx
->bc
->chip_class
< EVERGREEN
)
4131 ctx
->shader
->uses_tex_buffers
= true;
4132 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4136 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4137 /* get offset values */
4138 if (inst
->Texture
.NumOffsets
) {
4139 assert(inst
->Texture
.NumOffsets
== 1);
4141 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4142 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4143 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4145 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4146 /* TGSI moves the sampler to src reg 3 for TXD */
4147 sampler_src_reg
= 3;
4149 for (i
= 1; i
< 3; i
++) {
4150 /* set gradients h/v */
4151 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4152 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4153 FETCH_OP_SET_GRADIENTS_V
;
4154 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4155 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4157 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4158 tex
.src_gpr
= r600_get_temp(ctx
);
4164 for (j
= 0; j
< 4; j
++) {
4165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4166 alu
.op
= ALU_OP1_MOV
;
4167 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4168 alu
.dst
.sel
= tex
.src_gpr
;
4173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4179 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4180 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4181 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4182 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4183 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4184 tex
.src_rel
= ctx
->src
[i
].rel
;
4186 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4187 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4188 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4189 tex
.coord_type_x
= 1;
4190 tex
.coord_type_y
= 1;
4191 tex
.coord_type_z
= 1;
4192 tex
.coord_type_w
= 1;
4194 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4198 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4200 /* Add perspective divide */
4201 if (ctx
->bc
->chip_class
== CAYMAN
) {
4203 for (i
= 0; i
< 3; i
++) {
4204 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4205 alu
.op
= ALU_OP1_RECIP_IEEE
;
4206 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4208 alu
.dst
.sel
= ctx
->temp_reg
;
4214 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4221 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4222 alu
.op
= ALU_OP1_RECIP_IEEE
;
4223 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4225 alu
.dst
.sel
= ctx
->temp_reg
;
4226 alu
.dst
.chan
= out_chan
;
4229 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4234 for (i
= 0; i
< 3; i
++) {
4235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4236 alu
.op
= ALU_OP2_MUL
;
4237 alu
.src
[0].sel
= ctx
->temp_reg
;
4238 alu
.src
[0].chan
= out_chan
;
4239 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4240 alu
.dst
.sel
= ctx
->temp_reg
;
4243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4247 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4248 alu
.op
= ALU_OP1_MOV
;
4249 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4250 alu
.src
[0].chan
= 0;
4251 alu
.dst
.sel
= ctx
->temp_reg
;
4255 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4259 src_gpr
= ctx
->temp_reg
;
4262 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4263 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4264 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4265 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4266 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4267 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4269 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4270 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4272 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4273 for (i
= 0; i
< 4; i
++) {
4274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4275 alu
.op
= ALU_OP2_CUBE
;
4276 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4277 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4278 alu
.dst
.sel
= ctx
->temp_reg
;
4283 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4288 /* tmp1.z = RCP_e(|tmp1.z|) */
4289 if (ctx
->bc
->chip_class
== CAYMAN
) {
4290 for (i
= 0; i
< 3; i
++) {
4291 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4292 alu
.op
= ALU_OP1_RECIP_IEEE
;
4293 alu
.src
[0].sel
= ctx
->temp_reg
;
4294 alu
.src
[0].chan
= 2;
4296 alu
.dst
.sel
= ctx
->temp_reg
;
4302 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4308 alu
.op
= ALU_OP1_RECIP_IEEE
;
4309 alu
.src
[0].sel
= ctx
->temp_reg
;
4310 alu
.src
[0].chan
= 2;
4312 alu
.dst
.sel
= ctx
->temp_reg
;
4316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4321 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4322 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4323 * muladd has no writemask, have to use another temp
4325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4326 alu
.op
= ALU_OP3_MULADD
;
4329 alu
.src
[0].sel
= ctx
->temp_reg
;
4330 alu
.src
[0].chan
= 0;
4331 alu
.src
[1].sel
= ctx
->temp_reg
;
4332 alu
.src
[1].chan
= 2;
4334 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4335 alu
.src
[2].chan
= 0;
4336 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4338 alu
.dst
.sel
= ctx
->temp_reg
;
4342 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4346 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4347 alu
.op
= ALU_OP3_MULADD
;
4350 alu
.src
[0].sel
= ctx
->temp_reg
;
4351 alu
.src
[0].chan
= 1;
4352 alu
.src
[1].sel
= ctx
->temp_reg
;
4353 alu
.src
[1].chan
= 2;
4355 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4356 alu
.src
[2].chan
= 0;
4357 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4359 alu
.dst
.sel
= ctx
->temp_reg
;
4364 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4367 /* write initial compare value into Z component
4368 - W src 0 for shadow cube
4369 - X src 1 for shadow cube array */
4370 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4371 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4372 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4373 alu
.op
= ALU_OP1_MOV
;
4374 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4375 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4377 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4378 alu
.dst
.sel
= ctx
->temp_reg
;
4382 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4387 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4388 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4389 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4390 int mytmp
= r600_get_temp(ctx
);
4391 static const float eight
= 8.0f
;
4392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4393 alu
.op
= ALU_OP1_MOV
;
4394 alu
.src
[0].sel
= ctx
->temp_reg
;
4395 alu
.src
[0].chan
= 3;
4396 alu
.dst
.sel
= mytmp
;
4400 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4404 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4406 alu
.op
= ALU_OP3_MULADD
;
4408 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4409 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4410 alu
.src
[1].chan
= 0;
4411 alu
.src
[1].value
= *(uint32_t *)&eight
;
4412 alu
.src
[2].sel
= mytmp
;
4413 alu
.src
[2].chan
= 0;
4414 alu
.dst
.sel
= ctx
->temp_reg
;
4418 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4421 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4422 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4423 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4424 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4425 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4426 tex
.src_gpr
= r600_get_temp(ctx
);
4431 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4432 tex
.coord_type_x
= 1;
4433 tex
.coord_type_y
= 1;
4434 tex
.coord_type_z
= 1;
4435 tex
.coord_type_w
= 1;
4436 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4437 alu
.op
= ALU_OP1_MOV
;
4438 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4439 alu
.dst
.sel
= tex
.src_gpr
;
4443 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4447 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4454 /* for cube forms of lod and bias we need to route things */
4455 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4456 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4457 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4458 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4459 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4460 alu
.op
= ALU_OP1_MOV
;
4461 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4462 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4463 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4465 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4466 alu
.dst
.sel
= ctx
->temp_reg
;
4470 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4476 src_gpr
= ctx
->temp_reg
;
4479 if (src_requires_loading
&& !src_loaded
) {
4480 for (i
= 0; i
< 4; i
++) {
4481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4482 alu
.op
= ALU_OP1_MOV
;
4483 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4484 alu
.dst
.sel
= ctx
->temp_reg
;
4489 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4494 src_gpr
= ctx
->temp_reg
;
4497 /* Obtain the sample index for reading a compressed MSAA color texture.
4498 * To read the FMASK, we use the ldfptr instruction, which tells us
4499 * where the samples are stored.
4500 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4501 * which is the identity mapping. Each nibble says which physical sample
4502 * should be fetched to get that sample.
4504 * Assume src.z contains the sample index. It should be modified like this:
4505 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4506 * Then fetch the texel with src.
4508 if (read_compressed_msaa
) {
4509 unsigned sample_chan
= inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
? 3 : 4;
4510 unsigned temp
= r600_get_temp(ctx
);
4513 /* temp.w = ldfptr() */
4514 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4515 tex
.op
= FETCH_OP_LD
;
4516 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4517 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4518 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4519 tex
.src_gpr
= src_gpr
;
4521 tex
.dst_sel_x
= 7; /* mask out these components */
4524 tex
.dst_sel_w
= 0; /* store X */
4529 tex
.offset_x
= offset_x
;
4530 tex
.offset_y
= offset_y
;
4531 tex
.offset_z
= offset_z
;
4532 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4536 /* temp.x = sample_index*4 */
4537 if (ctx
->bc
->chip_class
== CAYMAN
) {
4538 for (i
= 0 ; i
< 4; i
++) {
4539 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4540 alu
.op
= ctx
->inst_info
->op
;
4541 alu
.src
[0].sel
= src_gpr
;
4542 alu
.src
[0].chan
= sample_chan
;
4543 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4544 alu
.src
[1].value
= 4;
4547 alu
.dst
.write
= i
== 0;
4550 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4556 alu
.op
= ALU_OP2_MULLO_INT
;
4557 alu
.src
[0].sel
= src_gpr
;
4558 alu
.src
[0].chan
= sample_chan
;
4559 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4560 alu
.src
[1].value
= 4;
4565 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4570 /* sample_index = temp.w >> temp.x */
4571 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4572 alu
.op
= ALU_OP2_LSHR_INT
;
4573 alu
.src
[0].sel
= temp
;
4574 alu
.src
[0].chan
= 3;
4575 alu
.src
[1].sel
= temp
;
4576 alu
.src
[1].chan
= 0;
4577 alu
.dst
.sel
= src_gpr
;
4578 alu
.dst
.chan
= sample_chan
;
4581 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4585 /* sample_index & 0xF */
4586 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4587 alu
.op
= ALU_OP2_AND_INT
;
4588 alu
.src
[0].sel
= src_gpr
;
4589 alu
.src
[0].chan
= sample_chan
;
4590 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4591 alu
.src
[1].value
= 0xF;
4592 alu
.dst
.sel
= src_gpr
;
4593 alu
.dst
.chan
= sample_chan
;
4596 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4600 /* visualize the FMASK */
4601 for (i
= 0; i
< 4; i
++) {
4602 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4603 alu
.op
= ALU_OP1_INT_TO_FLT
;
4604 alu
.src
[0].sel
= src_gpr
;
4605 alu
.src
[0].chan
= sample_chan
;
4606 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4610 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4618 /* does this shader want a num layers from TXQ for a cube array? */
4619 if (has_txq_cube_array_z
) {
4620 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4622 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4623 alu
.op
= ALU_OP1_MOV
;
4625 alu
.src
[0].sel
= 512 + (id
/ 4);
4626 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4627 alu
.src
[0].chan
= id
% 4;
4628 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4630 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4633 /* disable writemask from texture instruction */
4634 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4637 opcode
= ctx
->inst_info
->op
;
4638 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4639 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4640 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4641 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4642 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4643 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4644 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4646 case FETCH_OP_SAMPLE
:
4647 opcode
= FETCH_OP_SAMPLE_C
;
4649 case FETCH_OP_SAMPLE_L
:
4650 opcode
= FETCH_OP_SAMPLE_C_L
;
4652 case FETCH_OP_SAMPLE_LB
:
4653 opcode
= FETCH_OP_SAMPLE_C_LB
;
4655 case FETCH_OP_SAMPLE_G
:
4656 opcode
= FETCH_OP_SAMPLE_C_G
;
4661 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4664 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4665 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4666 tex
.src_gpr
= src_gpr
;
4667 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4668 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4669 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4670 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4671 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4673 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4678 } else if (src_loaded
) {
4684 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4685 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4686 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4687 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4688 tex
.src_rel
= ctx
->src
[0].rel
;
4691 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4692 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4693 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4694 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4698 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4701 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4702 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4703 tex
.coord_type_x
= 1;
4704 tex
.coord_type_y
= 1;
4706 tex
.coord_type_z
= 1;
4707 tex
.coord_type_w
= 1;
4709 tex
.offset_x
= offset_x
;
4710 tex
.offset_y
= offset_y
;
4711 tex
.offset_z
= offset_z
;
4713 /* Put the depth for comparison in W.
4714 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4715 * Some instructions expect the depth in Z. */
4716 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4717 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4718 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4719 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4720 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4721 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4722 tex
.src_sel_w
= tex
.src_sel_z
;
4725 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4726 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4727 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4728 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4729 /* the array index is read from Y */
4730 tex
.coord_type_y
= 0;
4732 /* the array index is read from Z */
4733 tex
.coord_type_z
= 0;
4734 tex
.src_sel_z
= tex
.src_sel_y
;
4736 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4737 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4738 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4739 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4740 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4741 /* the array index is read from Z */
4742 tex
.coord_type_z
= 0;
4744 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4748 /* add shadow ambient support - gallium doesn't do it yet */
4752 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4754 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4755 struct r600_bytecode_alu alu
;
4756 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4760 /* optimize if it's just an equal balance */
4761 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4762 for (i
= 0; i
< lasti
+ 1; i
++) {
4763 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4767 alu
.op
= ALU_OP2_ADD
;
4768 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4769 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4771 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4776 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4784 for (i
= 0; i
< lasti
+ 1; i
++) {
4785 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4788 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4789 alu
.op
= ALU_OP2_ADD
;
4790 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4791 alu
.src
[0].chan
= 0;
4792 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4793 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4794 alu
.dst
.sel
= ctx
->temp_reg
;
4800 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4805 /* (1 - src0) * src2 */
4806 for (i
= 0; i
< lasti
+ 1; i
++) {
4807 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4810 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4811 alu
.op
= ALU_OP2_MUL
;
4812 alu
.src
[0].sel
= ctx
->temp_reg
;
4813 alu
.src
[0].chan
= i
;
4814 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4815 alu
.dst
.sel
= ctx
->temp_reg
;
4821 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4826 /* src0 * src1 + (1 - src0) * src2 */
4827 for (i
= 0; i
< lasti
+ 1; i
++) {
4828 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4832 alu
.op
= ALU_OP3_MULADD
;
4834 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4835 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4836 alu
.src
[2].sel
= ctx
->temp_reg
;
4837 alu
.src
[2].chan
= i
;
4839 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4844 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4851 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4853 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4854 struct r600_bytecode_alu alu
;
4856 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4858 for (i
= 0; i
< lasti
+ 1; i
++) {
4859 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4863 alu
.op
= ALU_OP3_CNDGE
;
4864 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4865 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4866 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4867 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4873 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4880 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4882 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4883 struct r600_bytecode_alu alu
;
4885 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4887 for (i
= 0; i
< lasti
+ 1; i
++) {
4888 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4891 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4892 alu
.op
= ALU_OP3_CNDGE_INT
;
4893 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4894 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4895 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4896 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4902 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4909 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4911 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4912 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4913 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4914 struct r600_bytecode_alu alu
;
4915 uint32_t use_temp
= 0;
4918 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4921 for (i
= 0; i
< 4; i
++) {
4922 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4923 alu
.op
= ALU_OP2_MUL
;
4925 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4926 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4928 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4929 alu
.src
[0].chan
= i
;
4930 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4931 alu
.src
[1].chan
= i
;
4934 alu
.dst
.sel
= ctx
->temp_reg
;
4940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4945 for (i
= 0; i
< 4; i
++) {
4946 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4947 alu
.op
= ALU_OP3_MULADD
;
4950 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4951 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4953 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4954 alu
.src
[0].chan
= i
;
4955 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4956 alu
.src
[1].chan
= i
;
4959 alu
.src
[2].sel
= ctx
->temp_reg
;
4961 alu
.src
[2].chan
= i
;
4964 alu
.dst
.sel
= ctx
->temp_reg
;
4966 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4972 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4977 return tgsi_helper_copy(ctx
, inst
);
4981 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4983 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4984 struct r600_bytecode_alu alu
;
4988 /* result.x = 2^floor(src); */
4989 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4990 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4992 alu
.op
= ALU_OP1_FLOOR
;
4993 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4995 alu
.dst
.sel
= ctx
->temp_reg
;
4999 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5003 if (ctx
->bc
->chip_class
== CAYMAN
) {
5004 for (i
= 0; i
< 3; i
++) {
5005 alu
.op
= ALU_OP1_EXP_IEEE
;
5006 alu
.src
[0].sel
= ctx
->temp_reg
;
5007 alu
.src
[0].chan
= 0;
5009 alu
.dst
.sel
= ctx
->temp_reg
;
5011 alu
.dst
.write
= i
== 0;
5013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5018 alu
.op
= ALU_OP1_EXP_IEEE
;
5019 alu
.src
[0].sel
= ctx
->temp_reg
;
5020 alu
.src
[0].chan
= 0;
5022 alu
.dst
.sel
= ctx
->temp_reg
;
5026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5032 /* result.y = tmp - floor(tmp); */
5033 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5034 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5036 alu
.op
= ALU_OP1_FRACT
;
5037 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5039 alu
.dst
.sel
= ctx
->temp_reg
;
5041 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5055 /* result.z = RoughApprox2ToX(tmp);*/
5056 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5057 if (ctx
->bc
->chip_class
== CAYMAN
) {
5058 for (i
= 0; i
< 3; i
++) {
5059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5060 alu
.op
= ALU_OP1_EXP_IEEE
;
5061 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5063 alu
.dst
.sel
= ctx
->temp_reg
;
5070 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5075 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5076 alu
.op
= ALU_OP1_EXP_IEEE
;
5077 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5079 alu
.dst
.sel
= ctx
->temp_reg
;
5085 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5091 /* result.w = 1.0;*/
5092 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5095 alu
.op
= ALU_OP1_MOV
;
5096 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5097 alu
.src
[0].chan
= 0;
5099 alu
.dst
.sel
= ctx
->temp_reg
;
5103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5107 return tgsi_helper_copy(ctx
, inst
);
5110 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5112 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5113 struct r600_bytecode_alu alu
;
5117 /* result.x = floor(log2(|src|)); */
5118 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5119 if (ctx
->bc
->chip_class
== CAYMAN
) {
5120 for (i
= 0; i
< 3; i
++) {
5121 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5123 alu
.op
= ALU_OP1_LOG_IEEE
;
5124 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5125 r600_bytecode_src_set_abs(&alu
.src
[0]);
5127 alu
.dst
.sel
= ctx
->temp_reg
;
5133 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5139 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5141 alu
.op
= ALU_OP1_LOG_IEEE
;
5142 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5143 r600_bytecode_src_set_abs(&alu
.src
[0]);
5145 alu
.dst
.sel
= ctx
->temp_reg
;
5149 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5154 alu
.op
= ALU_OP1_FLOOR
;
5155 alu
.src
[0].sel
= ctx
->temp_reg
;
5156 alu
.src
[0].chan
= 0;
5158 alu
.dst
.sel
= ctx
->temp_reg
;
5163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5168 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5169 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5171 if (ctx
->bc
->chip_class
== CAYMAN
) {
5172 for (i
= 0; i
< 3; i
++) {
5173 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5175 alu
.op
= ALU_OP1_LOG_IEEE
;
5176 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5177 r600_bytecode_src_set_abs(&alu
.src
[0]);
5179 alu
.dst
.sel
= ctx
->temp_reg
;
5186 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5193 alu
.op
= ALU_OP1_LOG_IEEE
;
5194 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5195 r600_bytecode_src_set_abs(&alu
.src
[0]);
5197 alu
.dst
.sel
= ctx
->temp_reg
;
5202 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5209 alu
.op
= ALU_OP1_FLOOR
;
5210 alu
.src
[0].sel
= ctx
->temp_reg
;
5211 alu
.src
[0].chan
= 1;
5213 alu
.dst
.sel
= ctx
->temp_reg
;
5218 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5222 if (ctx
->bc
->chip_class
== CAYMAN
) {
5223 for (i
= 0; i
< 3; i
++) {
5224 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5225 alu
.op
= ALU_OP1_EXP_IEEE
;
5226 alu
.src
[0].sel
= ctx
->temp_reg
;
5227 alu
.src
[0].chan
= 1;
5229 alu
.dst
.sel
= ctx
->temp_reg
;
5236 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5241 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5242 alu
.op
= ALU_OP1_EXP_IEEE
;
5243 alu
.src
[0].sel
= ctx
->temp_reg
;
5244 alu
.src
[0].chan
= 1;
5246 alu
.dst
.sel
= ctx
->temp_reg
;
5251 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5256 if (ctx
->bc
->chip_class
== CAYMAN
) {
5257 for (i
= 0; i
< 3; i
++) {
5258 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5259 alu
.op
= ALU_OP1_RECIP_IEEE
;
5260 alu
.src
[0].sel
= ctx
->temp_reg
;
5261 alu
.src
[0].chan
= 1;
5263 alu
.dst
.sel
= ctx
->temp_reg
;
5270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5276 alu
.op
= ALU_OP1_RECIP_IEEE
;
5277 alu
.src
[0].sel
= ctx
->temp_reg
;
5278 alu
.src
[0].chan
= 1;
5280 alu
.dst
.sel
= ctx
->temp_reg
;
5285 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5290 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5292 alu
.op
= ALU_OP2_MUL
;
5294 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5295 r600_bytecode_src_set_abs(&alu
.src
[0]);
5297 alu
.src
[1].sel
= ctx
->temp_reg
;
5298 alu
.src
[1].chan
= 1;
5300 alu
.dst
.sel
= ctx
->temp_reg
;
5305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5310 /* result.z = log2(|src|);*/
5311 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5312 if (ctx
->bc
->chip_class
== CAYMAN
) {
5313 for (i
= 0; i
< 3; i
++) {
5314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5316 alu
.op
= ALU_OP1_LOG_IEEE
;
5317 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5318 r600_bytecode_src_set_abs(&alu
.src
[0]);
5320 alu
.dst
.sel
= ctx
->temp_reg
;
5327 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5332 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5334 alu
.op
= ALU_OP1_LOG_IEEE
;
5335 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5336 r600_bytecode_src_set_abs(&alu
.src
[0]);
5338 alu
.dst
.sel
= ctx
->temp_reg
;
5343 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5349 /* result.w = 1.0; */
5350 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5353 alu
.op
= ALU_OP1_MOV
;
5354 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5355 alu
.src
[0].chan
= 0;
5357 alu
.dst
.sel
= ctx
->temp_reg
;
5362 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5367 return tgsi_helper_copy(ctx
, inst
);
5370 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5372 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5373 struct r600_bytecode_alu alu
;
5376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5378 switch (inst
->Instruction
.Opcode
) {
5379 case TGSI_OPCODE_ARL
:
5380 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5382 case TGSI_OPCODE_ARR
:
5383 alu
.op
= ALU_OP1_FLT_TO_INT
;
5385 case TGSI_OPCODE_UARL
:
5386 alu
.op
= ALU_OP1_MOV
;
5393 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5395 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5397 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5401 ctx
->bc
->ar_loaded
= 0;
5404 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5406 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5407 struct r600_bytecode_alu alu
;
5410 switch (inst
->Instruction
.Opcode
) {
5411 case TGSI_OPCODE_ARL
:
5412 memset(&alu
, 0, sizeof(alu
));
5413 alu
.op
= ALU_OP1_FLOOR
;
5414 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5415 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5419 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5422 memset(&alu
, 0, sizeof(alu
));
5423 alu
.op
= ALU_OP1_FLT_TO_INT
;
5424 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5425 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5429 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5432 case TGSI_OPCODE_ARR
:
5433 memset(&alu
, 0, sizeof(alu
));
5434 alu
.op
= ALU_OP1_FLT_TO_INT
;
5435 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5436 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5440 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5443 case TGSI_OPCODE_UARL
:
5444 memset(&alu
, 0, sizeof(alu
));
5445 alu
.op
= ALU_OP1_MOV
;
5446 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5447 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5451 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5459 ctx
->bc
->ar_loaded
= 0;
5463 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5465 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5466 struct r600_bytecode_alu alu
;
5469 for (i
= 0; i
< 4; i
++) {
5470 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5472 alu
.op
= ALU_OP2_MUL
;
5473 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5475 if (i
== 0 || i
== 3) {
5476 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5478 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5481 if (i
== 0 || i
== 2) {
5482 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5484 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5488 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5495 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
)
5497 struct r600_bytecode_alu alu
;
5500 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5502 alu
.execute_mask
= 1;
5503 alu
.update_pred
= 1;
5505 alu
.dst
.sel
= ctx
->temp_reg
;
5509 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5510 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5511 alu
.src
[1].chan
= 0;
5515 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
5521 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5523 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5527 if (ctx
->bc
->cf_last
) {
5528 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5530 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5535 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5536 ctx
->bc
->force_add_cf
= 1;
5537 } else if (alu_pop
== 2) {
5538 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5539 ctx
->bc
->force_add_cf
= 1;
5546 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5547 ctx
->bc
->cf_last
->pop_count
= pops
;
5548 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5554 static inline void callstack_decrease_current(struct r600_shader_ctx
*ctx
, unsigned reason
)
5558 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
--;
5562 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
-= 4;
5565 /* TOODO : for 16 vp asic should -= 2; */
5566 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
--;
5571 static inline void callstack_check_depth(struct r600_shader_ctx
*ctx
, unsigned reason
, unsigned check_max_only
)
5573 if (check_max_only
) {
5586 if ((ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
+ diff
) >
5587 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
) {
5588 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
=
5589 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
+ diff
;
5595 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
++;
5599 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
+= 4;
5602 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
++;
5606 if ((ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
) >
5607 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
) {
5608 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].max
=
5609 ctx
->bc
->callstack
[ctx
->bc
->call_sp
].current
;
5613 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5615 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5617 sp
->mid
= realloc((void *)sp
->mid
,
5618 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5619 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5623 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5626 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5627 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5630 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5632 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5642 static int emit_return(struct r600_shader_ctx
*ctx
)
5644 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5648 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5651 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5652 ctx
->bc
->cf_last
->pop_count
= pops
;
5653 /* XXX work out offset */
5657 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5662 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5667 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5670 emit_jump_to_offset(ctx
, 1, 4);
5671 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5672 pops(ctx
, ifidx
+ 1);
5676 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5680 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5681 ctx
->bc
->cf_last
->pop_count
= 1;
5683 fc_set_mid(ctx
, fc_sp
);
5689 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5691 emit_logic_pred(ctx
, ALU_OP2_PRED_SETNE_INT
);
5693 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5695 fc_pushlevel(ctx
, FC_IF
);
5697 callstack_check_depth(ctx
, FC_PUSH_VPM
, 0);
5701 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5703 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5704 ctx
->bc
->cf_last
->pop_count
= 1;
5706 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5707 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5711 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5714 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5715 R600_ERR("if/endif unbalanced in shader\n");
5719 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5720 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5721 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5723 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5727 callstack_decrease_current(ctx
, FC_PUSH_VPM
);
5731 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5733 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5734 * limited to 4096 iterations, like the other LOOP_* instructions. */
5735 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5737 fc_pushlevel(ctx
, FC_LOOP
);
5739 /* check stack depth */
5740 callstack_check_depth(ctx
, FC_LOOP
, 0);
5744 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5748 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5750 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5751 R600_ERR("loop/endloop in shader code are not paired.\n");
5755 /* fixup loop pointers - from r600isa
5756 LOOP END points to CF after LOOP START,
5757 LOOP START point to CF after LOOP END
5758 BRK/CONT point to LOOP END CF
5760 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5762 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5764 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5765 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5767 /* XXX add LOOPRET support */
5769 callstack_decrease_current(ctx
, FC_LOOP
);
5773 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5777 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5779 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5784 R600_ERR("Break not inside loop/endloop pair\n");
5788 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5790 fc_set_mid(ctx
, fscp
);
5792 callstack_check_depth(ctx
, FC_PUSH_VPM
, 1);
5796 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5798 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5799 struct r600_bytecode_alu alu
;
5801 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5804 for (i
= 0; i
< lasti
+ 1; i
++) {
5805 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5808 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5811 alu
.dst
.sel
= ctx
->temp_reg
;
5814 alu
.op
= ALU_OP2_MULLO_UINT
;
5815 for (j
= 0; j
< 2; j
++) {
5816 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5820 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5826 for (i
= 0; i
< lasti
+ 1; i
++) {
5827 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5830 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5831 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5833 alu
.op
= ALU_OP2_ADD_INT
;
5835 alu
.src
[0].sel
= ctx
->temp_reg
;
5836 alu
.src
[0].chan
= i
;
5838 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5849 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5850 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5851 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5852 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5855 * For state trackers other than OpenGL, we'll want to use
5856 * _RECIP_IEEE instead.
5858 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5860 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5861 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5862 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5863 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5864 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5865 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5866 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5867 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5868 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5869 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5870 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5871 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5872 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5873 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5874 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5875 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5877 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5878 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5880 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5881 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5882 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5883 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5884 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5885 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5886 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5887 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5888 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5889 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5891 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5892 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5893 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5894 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5895 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5896 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5897 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5898 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5899 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5900 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5901 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5902 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5903 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5904 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5905 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5906 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5907 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5908 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5909 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5910 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5911 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5912 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5913 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5914 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5915 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5916 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5917 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5918 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5919 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5920 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5921 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5922 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5923 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5924 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5925 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5926 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5927 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5928 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5929 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5930 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5931 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5932 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5933 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5935 {75, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5936 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5937 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5938 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5940 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5941 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5942 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5943 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5944 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5945 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5946 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5947 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5948 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
5950 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5951 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5952 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5953 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5954 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5955 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5956 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5957 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5958 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5959 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5960 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5961 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5962 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5963 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5964 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5965 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5967 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5968 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5969 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5970 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5972 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5973 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5974 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5975 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5977 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5978 {TGSI_OPCODE_IFC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5979 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5980 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5981 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5983 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5984 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
5985 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5986 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5987 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5988 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5989 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5990 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
5991 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5992 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
5993 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5994 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5995 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5996 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5997 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5998 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5999 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6000 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6001 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6002 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6003 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6004 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6005 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6006 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6007 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6008 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6009 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6010 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6011 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6012 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6013 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6014 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6015 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6016 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6017 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6018 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6019 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6020 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6021 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6022 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6023 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6024 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6025 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6026 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6027 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6028 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6029 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6030 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6031 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6032 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6033 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6034 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6035 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6036 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6037 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6038 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6039 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6040 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6041 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6042 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6043 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6044 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6045 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6048 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6049 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6050 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6051 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6052 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6053 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6054 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6055 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6056 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6057 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6058 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6059 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6060 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6061 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6062 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6063 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6064 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6065 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6066 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6067 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6068 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6070 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6071 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6073 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6074 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6075 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6076 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6078 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6079 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6080 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6081 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6082 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6084 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6085 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6086 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6087 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6088 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6089 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6090 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6091 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6092 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6093 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6094 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6095 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6096 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6097 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6098 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6099 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6100 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6101 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6102 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6103 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6105 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6106 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6107 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6108 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6109 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6110 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6111 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6112 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6114 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6115 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6116 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6117 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6118 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6119 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6120 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6121 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6122 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6123 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6124 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6125 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6126 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6128 {75, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6129 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6130 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6131 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6133 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6134 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6135 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6136 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6137 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6138 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6139 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6140 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6141 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6143 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6144 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6145 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6146 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6147 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6148 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6149 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6150 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6151 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6152 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6153 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6154 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6155 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6156 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6157 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6158 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6160 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6161 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6162 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6163 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6165 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6166 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6167 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6168 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6170 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {TGSI_OPCODE_IFC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6172 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6173 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6174 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6176 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6177 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6178 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6179 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6180 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6181 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6182 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6183 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6184 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6185 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6186 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6187 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6188 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6189 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6190 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6191 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6192 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6193 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6194 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6195 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6196 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6197 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6198 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6199 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6200 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6201 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6202 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6203 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6204 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6205 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6206 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6207 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6208 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6209 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6210 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6211 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6212 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6213 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6214 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6215 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6216 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6217 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6218 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6219 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6220 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6221 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6222 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6223 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6224 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6225 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6226 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6227 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6228 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6229 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6230 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6231 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6232 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6233 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6234 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6235 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6236 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6237 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6238 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6241 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6242 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6243 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6244 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6245 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6246 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6247 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6248 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6249 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6250 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6251 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6252 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6253 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6254 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6255 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6256 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6257 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6258 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6259 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6260 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6261 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6263 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6264 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6266 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6267 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6268 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6269 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6270 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6271 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6272 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6273 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6274 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6275 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6277 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6278 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6279 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6280 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6281 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6282 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6283 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6284 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6285 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6286 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6287 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6288 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6289 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6290 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6291 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6292 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6293 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6294 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6295 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6296 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6297 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6298 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6299 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6300 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6301 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6302 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6303 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6304 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6305 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6306 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6307 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6308 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6309 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6310 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6311 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6312 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6313 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6314 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6315 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6316 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6317 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6318 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6319 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6321 {75, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6322 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6323 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6324 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6326 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6327 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6328 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6329 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6330 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6331 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6332 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6333 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6334 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6336 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6337 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6338 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6339 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6340 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6341 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6342 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6343 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6344 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6345 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6346 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6347 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6348 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6349 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6350 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6351 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6353 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6354 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6355 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6356 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6358 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6359 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6360 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6361 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6362 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6363 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6364 {TGSI_OPCODE_IFC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6365 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6366 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6367 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6369 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6370 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6371 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6372 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6373 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6374 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6375 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6376 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6377 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6378 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6379 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6380 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6381 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6382 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6383 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6384 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6385 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6386 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6387 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6388 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6389 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6390 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6391 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6392 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6393 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6394 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6395 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6396 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6397 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6398 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6399 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6400 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6401 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6402 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6403 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6404 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6405 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6406 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6407 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6408 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6409 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6410 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6411 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6412 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6413 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6414 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6415 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6416 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6417 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6418 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6419 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6420 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6421 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6422 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6423 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6424 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6425 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6426 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6427 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6428 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6429 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6430 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6431 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},