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_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
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 boolean use_kill
= false;
275 bool dump
= (r600_ctx
->screen
->debug_flags
& DBG_CS
) != 0;
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_llvm_compile(mod
, &bytes
, &byte_count
, r600_ctx
->family
,
283 shader_ctx
.bc
, &use_kill
, dump
);
284 r600_bytecode_from_byte_stream(&shader_ctx
, bytes
, byte_count
);
285 if (shader_ctx
.bc
->chip_class
== CAYMAN
) {
286 cm_bytecode_add_cf_end(shader_ctx
.bc
);
288 r600_bytecode_build(shader_ctx
.bc
);
290 r600_bytecode_disasm(shader_ctx
.bc
);
296 #endif /* HAVE_OPENCL */
298 static uint32_t i32_from_byte_stream(unsigned char * bytes
,
299 unsigned * bytes_read
)
303 for (i
= 0; i
< 4; i
++) {
304 out
|= bytes
[(*bytes_read
)++] << (8 * i
);
309 static unsigned r600_src_from_byte_stream(unsigned char * bytes
,
310 unsigned bytes_read
, struct r600_bytecode_alu
* alu
, unsigned src_idx
)
314 sel0
= bytes
[bytes_read
++];
315 sel1
= bytes
[bytes_read
++];
316 alu
->src
[src_idx
].sel
= sel0
| (sel1
<< 8);
317 alu
->src
[src_idx
].chan
= bytes
[bytes_read
++];
318 alu
->src
[src_idx
].neg
= bytes
[bytes_read
++];
319 alu
->src
[src_idx
].abs
= bytes
[bytes_read
++];
320 alu
->src
[src_idx
].rel
= bytes
[bytes_read
++];
321 alu
->src
[src_idx
].kc_bank
= bytes
[bytes_read
++];
322 for (i
= 0; i
< 4; i
++) {
323 alu
->src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
328 static unsigned r600_alu_from_byte_stream(struct r600_shader_ctx
*ctx
,
329 unsigned char * bytes
, unsigned bytes_read
)
331 unsigned src_idx
, src_num
;
332 struct r600_bytecode_alu alu
;
333 unsigned src_use_sel
[3];
334 const struct alu_op_info
*alu_op
;
335 unsigned src_sel
[3] = {};
336 uint32_t word0
, word1
;
338 src_num
= bytes
[bytes_read
++];
340 memset(&alu
, 0, sizeof(alu
));
341 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
343 src_use_sel
[src_idx
] = bytes
[bytes_read
++];
344 for (i
= 0; i
< 4; i
++) {
345 src_sel
[src_idx
] |= bytes
[bytes_read
++] << (i
* 8);
347 for (i
= 0; i
< 4; i
++) {
348 alu
.src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
352 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
353 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
355 switch(ctx
->bc
->chip_class
) {
358 r600_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
363 r700_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
367 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
368 if (src_use_sel
[src_idx
]) {
369 unsigned sel
= src_sel
[src_idx
];
371 alu
.src
[src_idx
].chan
= sel
& 3;
374 if (sel
>=512) { /* constant */
376 alu
.src
[src_idx
].kc_bank
= sel
>> 12;
377 alu
.src
[src_idx
].sel
= (sel
& 4095) + 512;
380 alu
.src
[src_idx
].sel
= sel
;
385 alu_op
= r600_isa_alu(alu
.op
);
387 #if HAVE_LLVM < 0x0302
388 if ((alu_op
->flags
& AF_PRED
) && alu_op
->src_count
== 2) {
391 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
397 if (alu_op
->flags
& AF_MOVA
) {
398 ctx
->bc
->ar_reg
= alu
.src
[0].sel
;
399 ctx
->bc
->ar_chan
= alu
.src
[0].chan
;
400 ctx
->bc
->ar_loaded
= 0;
404 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, ctx
->bc
->cf_last
->op
);
406 /* XXX: Handle other KILL instructions */
407 if (alu_op
->flags
& AF_KILL
) {
408 ctx
->shader
->uses_kill
= 1;
409 /* XXX: This should be enforced in the LLVM backend. */
410 ctx
->bc
->force_add_cf
= 1;
415 static void llvm_if(struct r600_shader_ctx
*ctx
)
417 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
418 fc_pushlevel(ctx
, FC_IF
);
419 callstack_push(ctx
, FC_PUSH_VPM
);
422 static void r600_break_from_byte_stream(struct r600_shader_ctx
*ctx
)
424 unsigned opcode
= TGSI_OPCODE_BRK
;
425 if (ctx
->bc
->chip_class
== CAYMAN
)
426 ctx
->inst_info
= &cm_shader_tgsi_instruction
[opcode
];
427 else if (ctx
->bc
->chip_class
>= EVERGREEN
)
428 ctx
->inst_info
= &eg_shader_tgsi_instruction
[opcode
];
430 ctx
->inst_info
= &r600_shader_tgsi_instruction
[opcode
];
432 tgsi_loop_brk_cont(ctx
);
436 static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx
*ctx
,
437 unsigned char * bytes
, unsigned bytes_read
)
439 struct r600_bytecode_alu alu
;
441 memset(&alu
, 0, sizeof(alu
));
442 bytes_read
= r600_src_from_byte_stream(bytes
, bytes_read
, &alu
, 0);
443 inst
= bytes
[bytes_read
++];
445 case 0: /* IF_PREDICATED */
454 case 3: /* BGNLOOP */
457 case 4: /* ENDLOOP */
460 case 5: /* PREDICATED_BREAK */
461 r600_break_from_byte_stream(ctx
);
463 case 6: /* CONTINUE */
465 unsigned opcode
= TGSI_OPCODE_CONT
;
466 if (ctx
->bc
->chip_class
== CAYMAN
) {
468 &cm_shader_tgsi_instruction
[opcode
];
469 } else if (ctx
->bc
->chip_class
>= EVERGREEN
) {
471 &eg_shader_tgsi_instruction
[opcode
];
474 &r600_shader_tgsi_instruction
[opcode
];
476 tgsi_loop_brk_cont(ctx
);
484 static unsigned r600_tex_from_byte_stream(struct r600_shader_ctx
*ctx
,
485 unsigned char * bytes
, unsigned bytes_read
)
487 struct r600_bytecode_tex tex
;
489 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
490 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
491 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
493 tex
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
, G_SQ_TEX_WORD0_TEX_INST(word0
));
494 tex
.resource_id
= G_SQ_TEX_WORD0_RESOURCE_ID(word0
);
495 tex
.src_gpr
= G_SQ_TEX_WORD0_SRC_GPR(word0
);
496 tex
.src_rel
= G_SQ_TEX_WORD0_SRC_REL(word0
);
497 tex
.dst_gpr
= G_SQ_TEX_WORD1_DST_GPR(word1
);
498 tex
.dst_rel
= G_SQ_TEX_WORD1_DST_REL(word1
);
499 tex
.dst_sel_x
= G_SQ_TEX_WORD1_DST_SEL_X(word1
);
500 tex
.dst_sel_y
= G_SQ_TEX_WORD1_DST_SEL_Y(word1
);
501 tex
.dst_sel_z
= G_SQ_TEX_WORD1_DST_SEL_Z(word1
);
502 tex
.dst_sel_w
= G_SQ_TEX_WORD1_DST_SEL_W(word1
);
503 tex
.lod_bias
= G_SQ_TEX_WORD1_LOD_BIAS(word1
);
504 tex
.coord_type_x
= G_SQ_TEX_WORD1_COORD_TYPE_X(word1
);
505 tex
.coord_type_y
= G_SQ_TEX_WORD1_COORD_TYPE_Y(word1
);
506 tex
.coord_type_z
= G_SQ_TEX_WORD1_COORD_TYPE_Z(word1
);
507 tex
.coord_type_w
= G_SQ_TEX_WORD1_COORD_TYPE_W(word1
);
508 tex
.offset_x
= G_SQ_TEX_WORD2_OFFSET_X(word2
);
509 tex
.offset_y
= G_SQ_TEX_WORD2_OFFSET_Y(word2
);
510 tex
.offset_z
= G_SQ_TEX_WORD2_OFFSET_Z(word2
);
511 tex
.sampler_id
= G_SQ_TEX_WORD2_SAMPLER_ID(word2
);
512 tex
.src_sel_x
= G_SQ_TEX_WORD2_SRC_SEL_X(word2
);
513 tex
.src_sel_y
= G_SQ_TEX_WORD2_SRC_SEL_Y(word2
);
514 tex
.src_sel_z
= G_SQ_TEX_WORD2_SRC_SEL_Z(word2
);
515 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;
596 while (bytes_read
< num_bytes
) {
597 char inst_type
= bytes
[bytes_read
++];
600 bytes_read
= r600_alu_from_byte_stream(ctx
, bytes
,
604 bytes_read
= r600_tex_from_byte_stream(ctx
, bytes
,
608 bytes_read
= r600_fc_from_byte_stream(ctx
, bytes
,
612 r600_bytecode_add_cfinst(ctx
->bc
, CF_NATIVE
);
613 for (i
= 0; i
< 2; i
++) {
614 for (byte
= 0 ; byte
< 4; byte
++) {
615 ctx
->bc
->cf_last
->isa
[i
] |=
616 (bytes
[bytes_read
++] << (byte
* 8));
622 bytes_read
= r600_vtx_from_byte_stream(ctx
, bytes
,
626 bytes_read
= r600_export_from_byte_stream(ctx
, bytes
,
630 int32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
631 int32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
633 r600_bytecode_add_cf(ctx
->bc
);
634 ctx
->bc
->cf_last
->op
= r600_isa_cf_by_opcode(ctx
->bc
->isa
, G_SQ_CF_ALU_WORD1_CF_INST(word1
), 1);
635 ctx
->bc
->cf_last
->kcache
[0].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK0(word0
);
636 ctx
->bc
->cf_last
->kcache
[0].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(word1
);
637 ctx
->bc
->cf_last
->kcache
[0].mode
= G_SQ_CF_ALU_WORD0_KCACHE_MODE0(word0
);
638 ctx
->bc
->cf_last
->kcache
[1].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK1(word0
);
639 ctx
->bc
->cf_last
->kcache
[1].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(word1
);
640 ctx
->bc
->cf_last
->kcache
[1].mode
= G_SQ_CF_ALU_WORD1_KCACHE_MODE1(word1
);
644 /* XXX: Error here */
650 /* End bytestream -> r600 shader functions*/
652 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
654 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
657 if (i
->Instruction
.NumDstRegs
> 1) {
658 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
661 if (i
->Instruction
.Predicate
) {
662 R600_ERR("predicate unsupported\n");
666 if (i
->Instruction
.Label
) {
667 R600_ERR("label unsupported\n");
671 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
672 if (i
->Src
[j
].Register
.Dimension
) {
673 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
674 R600_ERR("unsupported src %d (dimension %d)\n", j
,
675 i
->Src
[j
].Register
.Dimension
);
680 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
681 if (i
->Dst
[j
].Register
.Dimension
) {
682 R600_ERR("unsupported dst (dimension)\n");
689 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
694 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
695 if (ctx
->shader
->input
[input
].centroid
)
697 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
698 /* if we have perspective add one */
699 if (ctx
->input_perspective
) {
701 /* if we have perspective centroid */
702 if (ctx
->input_centroid
)
705 if (ctx
->shader
->input
[input
].centroid
)
709 ctx
->shader
->input
[input
].ij_index
= ij_index
;
712 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
715 struct r600_bytecode_alu alu
;
716 int gpr
= 0, base_chan
= 0;
717 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
719 /* work out gpr and base_chan from index */
721 base_chan
= (2 * (ij_index
% 2)) + 1;
723 for (i
= 0; i
< 8; i
++) {
724 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
727 alu
.op
= ALU_OP2_INTERP_ZW
;
729 alu
.op
= ALU_OP2_INTERP_XY
;
731 if ((i
> 1) && (i
< 6)) {
732 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
736 alu
.dst
.chan
= i
% 4;
738 alu
.src
[0].sel
= gpr
;
739 alu
.src
[0].chan
= (base_chan
- (i
% 2));
741 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
743 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
746 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
753 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
756 struct r600_bytecode_alu alu
;
758 for (i
= 0; i
< 4; i
++) {
759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
761 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
763 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
768 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
773 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
781 * Special export handling in shaders
783 * shader export ARRAY_BASE for EXPORT_POS:
786 * 62, 63 are clip distance vectors
788 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
789 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
790 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
791 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
792 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
793 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
794 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
795 * exclusive from render target index)
796 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
799 * shader export ARRAY_BASE for EXPORT_PIXEL:
801 * 61 computed Z vector
803 * The use of the values exported in the computed Z vector are controlled
804 * by DB_SHADER_CONTROL:
805 * Z_EXPORT_ENABLE - Z as a float in RED
806 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
807 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
808 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
809 * DB_SOURCE_FORMAT - export control restrictions
814 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
815 static int r600_spi_sid(struct r600_shader_io
* io
)
817 int index
, name
= io
->name
;
819 /* These params are handled differently, they don't need
820 * semantic indices, so we'll use 0 for them.
822 if (name
== TGSI_SEMANTIC_POSITION
||
823 name
== TGSI_SEMANTIC_PSIZE
||
824 name
== TGSI_SEMANTIC_FACE
)
827 if (name
== TGSI_SEMANTIC_GENERIC
) {
828 /* For generic params simply use sid from tgsi */
831 /* For non-generic params - pack name and sid into 8 bits */
832 index
= 0x80 | (name
<<3) | (io
->sid
);
835 /* Make sure that all really used indices have nonzero value, so
836 * we can just compare it to 0 later instead of comparing the name
837 * with different values to detect special cases. */
844 /* turn input into interpolate on EG */
845 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
849 if (ctx
->shader
->input
[index
].spi_sid
) {
850 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
851 if (ctx
->shader
->input
[index
].interpolate
> 0) {
852 evergreen_interp_assign_ij_index(ctx
, index
);
854 r
= evergreen_interp_alu(ctx
, index
);
857 r
= evergreen_interp_flat(ctx
, index
);
863 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
865 struct r600_bytecode_alu alu
;
867 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
868 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
870 for (i
= 0; i
< 4; i
++) {
871 memset(&alu
, 0, sizeof(alu
));
872 alu
.op
= ALU_OP3_CNDGT
;
875 alu
.dst
.sel
= gpr_front
;
876 alu
.src
[0].sel
= ctx
->face_gpr
;
877 alu
.src
[1].sel
= gpr_front
;
878 alu
.src
[2].sel
= gpr_back
;
885 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
892 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
894 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
895 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
897 switch (d
->Declaration
.File
) {
898 case TGSI_FILE_INPUT
:
899 i
= ctx
->shader
->ninput
;
900 ctx
->shader
->ninput
+= count
;
901 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
902 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
903 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
904 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
905 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
906 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
907 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
908 switch (ctx
->shader
->input
[i
].name
) {
909 case TGSI_SEMANTIC_FACE
:
910 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
912 case TGSI_SEMANTIC_COLOR
:
915 case TGSI_SEMANTIC_POSITION
:
916 ctx
->fragcoord_input
= i
;
919 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
920 if ((r
= evergreen_interp_input(ctx
, i
)))
924 for (j
= 1; j
< count
; ++j
) {
925 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
926 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
929 case TGSI_FILE_OUTPUT
:
930 i
= ctx
->shader
->noutput
++;
931 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
932 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
933 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
934 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
935 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
936 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
937 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
938 switch (d
->Semantic
.Name
) {
939 case TGSI_SEMANTIC_CLIPDIST
:
940 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
942 case TGSI_SEMANTIC_PSIZE
:
943 ctx
->shader
->vs_out_misc_write
= 1;
944 ctx
->shader
->vs_out_point_size
= 1;
946 case TGSI_SEMANTIC_CLIPVERTEX
:
947 ctx
->clip_vertex_write
= TRUE
;
951 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
952 switch (d
->Semantic
.Name
) {
953 case TGSI_SEMANTIC_COLOR
:
954 ctx
->shader
->nr_ps_max_color_exports
++;
959 case TGSI_FILE_CONSTANT
:
960 case TGSI_FILE_TEMPORARY
:
961 case TGSI_FILE_SAMPLER
:
962 case TGSI_FILE_ADDRESS
:
965 case TGSI_FILE_SYSTEM_VALUE
:
966 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
967 if (!ctx
->native_integers
) {
968 struct r600_bytecode_alu alu
;
969 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
971 alu
.op
= ALU_OP1_INT_TO_FLT
;
980 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
984 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
987 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
993 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
995 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
999 * for evergreen we need to scan the shader to find the number of GPRs we need to
1000 * reserve for interpolation.
1002 * we need to know if we are going to emit
1003 * any centroid inputs
1004 * if perspective and linear are required
1006 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1011 ctx
->input_linear
= FALSE
;
1012 ctx
->input_perspective
= FALSE
;
1013 ctx
->input_centroid
= FALSE
;
1014 ctx
->num_interp_gpr
= 1;
1016 /* any centroid inputs */
1017 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1018 /* skip position/face */
1019 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1020 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
1022 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
1023 ctx
->input_linear
= TRUE
;
1024 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
1025 ctx
->input_perspective
= TRUE
;
1026 if (ctx
->info
.input_centroid
[i
])
1027 ctx
->input_centroid
= TRUE
;
1031 /* ignoring sample for now */
1032 if (ctx
->input_perspective
)
1034 if (ctx
->input_linear
)
1036 if (ctx
->input_centroid
)
1039 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
1041 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
1042 return ctx
->num_interp_gpr
;
1045 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1046 const struct tgsi_full_src_register
*tgsi_src
,
1047 struct r600_shader_src
*r600_src
)
1049 memset(r600_src
, 0, sizeof(*r600_src
));
1050 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1051 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1052 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1053 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1054 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1055 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1057 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1059 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1060 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1061 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1063 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1064 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
1065 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1068 index
= tgsi_src
->Register
.Index
;
1069 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1070 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1071 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1072 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1073 r600_src
->swizzle
[0] = 3;
1074 r600_src
->swizzle
[1] = 3;
1075 r600_src
->swizzle
[2] = 3;
1076 r600_src
->swizzle
[3] = 3;
1078 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1079 r600_src
->swizzle
[0] = 0;
1080 r600_src
->swizzle
[1] = 0;
1081 r600_src
->swizzle
[2] = 0;
1082 r600_src
->swizzle
[3] = 0;
1086 if (tgsi_src
->Register
.Indirect
)
1087 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1088 r600_src
->sel
= tgsi_src
->Register
.Index
;
1089 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1091 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1092 if (tgsi_src
->Register
.Dimension
) {
1093 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1098 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
1100 struct r600_bytecode_vtx vtx
;
1101 unsigned int ar_reg
;
1105 struct r600_bytecode_alu alu
;
1107 memset(&alu
, 0, sizeof(alu
));
1109 alu
.op
= ALU_OP2_ADD_INT
;
1110 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1112 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1113 alu
.src
[1].value
= offset
;
1115 alu
.dst
.sel
= dst_reg
;
1119 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1124 ar_reg
= ctx
->bc
->ar_reg
;
1127 memset(&vtx
, 0, sizeof(vtx
));
1128 vtx
.buffer_id
= cb_idx
;
1129 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
1130 vtx
.src_gpr
= ar_reg
;
1131 vtx
.mega_fetch_count
= 16;
1132 vtx
.dst_gpr
= dst_reg
;
1133 vtx
.dst_sel_x
= 0; /* SEL_X */
1134 vtx
.dst_sel_y
= 1; /* SEL_Y */
1135 vtx
.dst_sel_z
= 2; /* SEL_Z */
1136 vtx
.dst_sel_w
= 3; /* SEL_W */
1137 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1138 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1139 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1140 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1141 vtx
.endian
= r600_endian_swap(32);
1143 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1149 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1151 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1152 struct r600_bytecode_alu alu
;
1153 int i
, j
, k
, nconst
, r
;
1155 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1156 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1159 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1161 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1162 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1166 if (ctx
->src
[i
].rel
) {
1167 int treg
= r600_get_temp(ctx
);
1168 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
1171 ctx
->src
[i
].kc_bank
= 0;
1172 ctx
->src
[i
].sel
= treg
;
1173 ctx
->src
[i
].rel
= 0;
1176 int treg
= r600_get_temp(ctx
);
1177 for (k
= 0; k
< 4; k
++) {
1178 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1179 alu
.op
= ALU_OP1_MOV
;
1180 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1181 alu
.src
[0].chan
= k
;
1182 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1192 ctx
->src
[i
].sel
= treg
;
1200 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1201 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1203 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1204 struct r600_bytecode_alu alu
;
1205 int i
, j
, k
, nliteral
, r
;
1207 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1208 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1212 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1213 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1214 int treg
= r600_get_temp(ctx
);
1215 for (k
= 0; k
< 4; k
++) {
1216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1217 alu
.op
= ALU_OP1_MOV
;
1218 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1219 alu
.src
[0].chan
= k
;
1220 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1226 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1230 ctx
->src
[i
].sel
= treg
;
1237 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1239 int i
, r
, count
= ctx
->shader
->ninput
;
1241 for (i
= 0; i
< count
; i
++) {
1242 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1243 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1251 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
1252 struct r600_pipe_shader
*pipeshader
,
1253 struct r600_shader_key key
)
1255 struct r600_shader
*shader
= &pipeshader
->shader
;
1256 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1257 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1258 struct tgsi_full_immediate
*immediate
;
1259 struct tgsi_full_property
*property
;
1260 struct r600_shader_ctx ctx
;
1261 struct r600_bytecode_output output
[32];
1262 unsigned output_done
, noutput
;
1265 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
1266 /* Declarations used by llvm code */
1267 bool use_llvm
= false;
1268 unsigned char * inst_bytes
= NULL
;
1269 unsigned inst_byte_count
= 0;
1271 #ifdef R600_USE_LLVM
1272 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
1274 ctx
.bc
= &shader
->bc
;
1275 ctx
.shader
= shader
;
1276 ctx
.native_integers
= true;
1278 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
1279 rscreen
->msaa_texture_support
);
1280 ctx
.tokens
= tokens
;
1281 tgsi_scan_shader(tokens
, &ctx
.info
);
1282 tgsi_parse_init(&ctx
.parse
, tokens
);
1283 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1284 shader
->processor_type
= ctx
.type
;
1285 ctx
.bc
->type
= shader
->processor_type
;
1288 ctx
.fragcoord_input
= -1;
1289 ctx
.colors_used
= 0;
1290 ctx
.clip_vertex_write
= 0;
1292 shader
->nr_ps_color_exports
= 0;
1293 shader
->nr_ps_max_color_exports
= 0;
1295 shader
->two_side
= key
.color_two_side
;
1297 /* register allocations */
1298 /* Values [0,127] correspond to GPR[0..127].
1299 * Values [128,159] correspond to constant buffer bank 0
1300 * Values [160,191] correspond to constant buffer bank 1
1301 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1302 * Values [256,287] correspond to constant buffer bank 2 (EG)
1303 * Values [288,319] correspond to constant buffer bank 3 (EG)
1304 * Other special values are shown in the list below.
1305 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1306 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1307 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1308 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1309 * 248 SQ_ALU_SRC_0: special constant 0.0.
1310 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1311 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1312 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1313 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1314 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1315 * 254 SQ_ALU_SRC_PV: previous vector result.
1316 * 255 SQ_ALU_SRC_PS: previous scalar result.
1318 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1319 ctx
.file_offset
[i
] = 0;
1321 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1322 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1323 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1325 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1326 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1329 #ifdef R600_USE_LLVM
1330 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1331 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1332 "indirect adressing. Falling back to TGSI "
1337 ctx
.use_llvm
= use_llvm
;
1340 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1341 ctx
.file_offset
[TGSI_FILE_INPUT
];
1343 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1344 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1345 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1347 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1348 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1350 /* Outside the GPR range. This will be translated to one of the
1351 * kcache banks later. */
1352 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1354 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1355 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1356 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1357 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1360 ctx
.literals
= NULL
;
1361 shader
->fs_write_all
= FALSE
;
1362 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1363 tgsi_parse_token(&ctx
.parse
);
1364 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1365 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1366 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1367 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1368 if(ctx
.literals
== NULL
) {
1372 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1373 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1374 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1375 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1378 case TGSI_TOKEN_TYPE_DECLARATION
:
1379 r
= tgsi_declaration(&ctx
);
1383 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1385 case TGSI_TOKEN_TYPE_PROPERTY
:
1386 property
= &ctx
.parse
.FullToken
.FullProperty
;
1387 switch (property
->Property
.PropertyName
) {
1388 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1389 if (property
->u
[0].Data
== 1)
1390 shader
->fs_write_all
= TRUE
;
1392 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1393 /* we don't need this one */
1398 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1404 /* Process two side if needed */
1405 if (shader
->two_side
&& ctx
.colors_used
) {
1406 int i
, count
= ctx
.shader
->ninput
;
1407 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1409 /* additional inputs will be allocated right after the existing inputs,
1410 * we won't need them after the color selection, so we don't need to
1411 * reserve these gprs for the rest of the shader code and to adjust
1412 * output offsets etc. */
1413 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1414 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1416 if (ctx
.face_gpr
== -1) {
1417 i
= ctx
.shader
->ninput
++;
1418 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1419 ctx
.shader
->input
[i
].spi_sid
= 0;
1420 ctx
.shader
->input
[i
].gpr
= gpr
++;
1421 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1424 for (i
= 0; i
< count
; i
++) {
1425 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1426 int ni
= ctx
.shader
->ninput
++;
1427 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1428 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1429 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1430 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1431 // TGSI to LLVM needs to know the lds position of inputs.
1432 // Non LLVM path computes it later (in process_twoside_color)
1433 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1434 ctx
.shader
->input
[i
].back_color_input
= ni
;
1435 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1436 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1443 /* LLVM backend setup */
1444 #ifdef R600_USE_LLVM
1446 struct radeon_llvm_context radeon_llvm_ctx
;
1448 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1449 boolean use_kill
= false;
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
, ctx
.bc
, &use_kill
, 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
];
1477 ctx
.shader
->uses_kill
= use_kill
;
1478 radeon_llvm_dispose(&radeon_llvm_ctx
);
1481 /* End of LLVM backend setup */
1483 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1484 shader
->nr_ps_max_color_exports
= 8;
1487 if (ctx
.fragcoord_input
>= 0) {
1488 if (ctx
.bc
->chip_class
== CAYMAN
) {
1489 for (j
= 0 ; j
< 4; j
++) {
1490 struct r600_bytecode_alu alu
;
1491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1492 alu
.op
= ALU_OP1_RECIP_IEEE
;
1493 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1494 alu
.src
[0].chan
= 3;
1496 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1498 alu
.dst
.write
= (j
== 3);
1500 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1504 struct r600_bytecode_alu alu
;
1505 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1506 alu
.op
= ALU_OP1_RECIP_IEEE
;
1507 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1508 alu
.src
[0].chan
= 3;
1510 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1514 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1519 if (shader
->two_side
&& ctx
.colors_used
) {
1520 if ((r
= process_twoside_color_inputs(&ctx
)))
1524 tgsi_parse_init(&ctx
.parse
, tokens
);
1525 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1526 tgsi_parse_token(&ctx
.parse
);
1527 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1528 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1529 r
= tgsi_is_supported(&ctx
);
1532 ctx
.max_driver_temp_used
= 0;
1533 /* reserve first tmp for everyone */
1534 r600_get_temp(&ctx
);
1536 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1537 if ((r
= tgsi_split_constant(&ctx
)))
1539 if ((r
= tgsi_split_literal_constant(&ctx
)))
1541 if (ctx
.bc
->chip_class
== CAYMAN
)
1542 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1543 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1544 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1546 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1547 r
= ctx
.inst_info
->process(&ctx
);
1557 /* Reset the temporary register counter. */
1558 ctx
.max_driver_temp_used
= 0;
1560 /* Get instructions if we are using the LLVM backend. */
1562 r600_bytecode_from_byte_stream(&ctx
, inst_bytes
, inst_byte_count
);
1566 noutput
= shader
->noutput
;
1568 if (ctx
.clip_vertex_write
) {
1569 unsigned clipdist_temp
[2];
1571 clipdist_temp
[0] = r600_get_temp(&ctx
);
1572 clipdist_temp
[1] = r600_get_temp(&ctx
);
1574 /* need to convert a clipvertex write into clipdistance writes and not export
1575 the clip vertex anymore */
1577 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1578 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1579 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1581 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1582 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1585 /* reset spi_sid for clipvertex output to avoid confusing spi */
1586 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1588 shader
->clip_dist_write
= 0xFF;
1590 for (i
= 0; i
< 8; i
++) {
1594 for (j
= 0; j
< 4; j
++) {
1595 struct r600_bytecode_alu alu
;
1596 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1597 alu
.op
= ALU_OP2_DOT4
;
1598 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1599 alu
.src
[0].chan
= j
;
1601 alu
.src
[1].sel
= 512 + i
;
1602 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1603 alu
.src
[1].chan
= j
;
1605 alu
.dst
.sel
= clipdist_temp
[oreg
];
1607 alu
.dst
.write
= (j
== ochan
);
1611 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1618 /* Add stream outputs. */
1619 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1620 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1622 /* Sanity checking. */
1623 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1624 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1628 for (i
= 0; i
< so
.num_outputs
; i
++) {
1629 if (so
.output
[i
].output_buffer
>= 4) {
1630 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1631 so
.output
[i
].output_buffer
);
1637 /* Initialize locations where the outputs are stored. */
1638 for (i
= 0; i
< so
.num_outputs
; i
++) {
1639 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1641 /* Lower outputs with dst_offset < start_component.
1643 * We can only output 4D vectors with a write mask, e.g. we can
1644 * only output the W component at offset 3, etc. If we want
1645 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1646 * to move it to X and output X. */
1647 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1648 unsigned tmp
= r600_get_temp(&ctx
);
1650 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1651 struct r600_bytecode_alu alu
;
1652 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1653 alu
.op
= ALU_OP1_MOV
;
1654 alu
.src
[0].sel
= so_gpr
[i
];
1655 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1660 if (j
== so
.output
[i
].num_components
- 1)
1662 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1666 so
.output
[i
].start_component
= 0;
1671 /* Write outputs to buffers. */
1672 for (i
= 0; i
< so
.num_outputs
; i
++) {
1673 struct r600_bytecode_output output
;
1675 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1676 output
.gpr
= so_gpr
[i
];
1677 output
.elem_size
= so
.output
[i
].num_components
;
1678 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1679 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1680 output
.burst_count
= 1;
1682 /* array_size is an upper limit for the burst_count
1683 * with MEM_STREAM instructions */
1684 output
.array_size
= 0xFFF;
1685 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1686 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1687 switch (so
.output
[i
].output_buffer
) {
1689 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1692 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1695 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1698 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1702 switch (so
.output
[i
].output_buffer
) {
1704 output
.op
= CF_OP_MEM_STREAM0
;
1707 output
.op
= CF_OP_MEM_STREAM1
;
1710 output
.op
= CF_OP_MEM_STREAM2
;
1713 output
.op
= CF_OP_MEM_STREAM3
;
1717 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1724 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1725 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1726 output
[j
].gpr
= shader
->output
[i
].gpr
;
1727 output
[j
].elem_size
= 3;
1728 output
[j
].swizzle_x
= 0;
1729 output
[j
].swizzle_y
= 1;
1730 output
[j
].swizzle_z
= 2;
1731 output
[j
].swizzle_w
= 3;
1732 output
[j
].burst_count
= 1;
1733 output
[j
].barrier
= 1;
1734 output
[j
].type
= -1;
1735 output
[j
].op
= CF_OP_EXPORT
;
1737 case TGSI_PROCESSOR_VERTEX
:
1738 switch (shader
->output
[i
].name
) {
1739 case TGSI_SEMANTIC_POSITION
:
1740 output
[j
].array_base
= next_pos_base
++;
1741 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1744 case TGSI_SEMANTIC_PSIZE
:
1745 output
[j
].array_base
= next_pos_base
++;
1746 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1748 case TGSI_SEMANTIC_CLIPVERTEX
:
1751 case TGSI_SEMANTIC_CLIPDIST
:
1752 output
[j
].array_base
= next_pos_base
++;
1753 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1754 /* spi_sid is 0 for clipdistance outputs that were generated
1755 * for clipvertex - we don't need to pass them to PS */
1756 if (shader
->output
[i
].spi_sid
) {
1758 /* duplicate it as PARAM to pass to the pixel shader */
1759 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1760 output
[j
].array_base
= next_param_base
++;
1761 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1764 case TGSI_SEMANTIC_FOG
:
1765 output
[j
].swizzle_y
= 4; /* 0 */
1766 output
[j
].swizzle_z
= 4; /* 0 */
1767 output
[j
].swizzle_w
= 5; /* 1 */
1771 case TGSI_PROCESSOR_FRAGMENT
:
1772 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1773 /* never export more colors than the number of CBs */
1774 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1779 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1780 output
[j
].array_base
= next_pixel_base
++;
1781 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1782 shader
->nr_ps_color_exports
++;
1783 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1784 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1786 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1787 output
[j
].gpr
= shader
->output
[i
].gpr
;
1788 output
[j
].elem_size
= 3;
1789 output
[j
].swizzle_x
= 0;
1790 output
[j
].swizzle_y
= 1;
1791 output
[j
].swizzle_z
= 2;
1792 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1793 output
[j
].burst_count
= 1;
1794 output
[j
].barrier
= 1;
1795 output
[j
].array_base
= next_pixel_base
++;
1796 output
[j
].op
= CF_OP_EXPORT
;
1797 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1798 shader
->nr_ps_color_exports
++;
1801 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1802 output
[j
].array_base
= 61;
1803 output
[j
].swizzle_x
= 2;
1804 output
[j
].swizzle_y
= 7;
1805 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1806 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1807 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1808 output
[j
].array_base
= 61;
1809 output
[j
].swizzle_x
= 7;
1810 output
[j
].swizzle_y
= 1;
1811 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1812 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1814 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1820 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1825 if (output
[j
].type
==-1) {
1826 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1827 output
[j
].array_base
= next_param_base
++;
1831 /* add fake position export */
1832 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1833 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1835 output
[j
].elem_size
= 3;
1836 output
[j
].swizzle_x
= 7;
1837 output
[j
].swizzle_y
= 7;
1838 output
[j
].swizzle_z
= 7;
1839 output
[j
].swizzle_w
= 7;
1840 output
[j
].burst_count
= 1;
1841 output
[j
].barrier
= 1;
1842 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1843 output
[j
].array_base
= next_pos_base
;
1844 output
[j
].op
= CF_OP_EXPORT
;
1848 /* add fake param output for vertex shader if no param is exported */
1849 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1850 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1852 output
[j
].elem_size
= 3;
1853 output
[j
].swizzle_x
= 7;
1854 output
[j
].swizzle_y
= 7;
1855 output
[j
].swizzle_z
= 7;
1856 output
[j
].swizzle_w
= 7;
1857 output
[j
].burst_count
= 1;
1858 output
[j
].barrier
= 1;
1859 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1860 output
[j
].array_base
= 0;
1861 output
[j
].op
= CF_OP_EXPORT
;
1865 /* add fake pixel export */
1866 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1867 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1869 output
[j
].elem_size
= 3;
1870 output
[j
].swizzle_x
= 7;
1871 output
[j
].swizzle_y
= 7;
1872 output
[j
].swizzle_z
= 7;
1873 output
[j
].swizzle_w
= 7;
1874 output
[j
].burst_count
= 1;
1875 output
[j
].barrier
= 1;
1876 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1877 output
[j
].array_base
= 0;
1878 output
[j
].op
= CF_OP_EXPORT
;
1884 /* set export done on last export of each type */
1885 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1886 if (ctx
.bc
->chip_class
< CAYMAN
) {
1887 if (i
== (noutput
- 1)) {
1888 output
[i
].end_of_program
= 1;
1891 if (!(output_done
& (1 << output
[i
].type
))) {
1892 output_done
|= (1 << output
[i
].type
);
1893 output
[i
].op
= CF_OP_EXPORT_DONE
;
1896 /* add output to bytecode */
1898 for (i
= 0; i
< noutput
; i
++) {
1899 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1904 /* add program end */
1905 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1906 cm_bytecode_add_cf_end(ctx
.bc
);
1908 /* check GPR limit - we have 124 = 128 - 4
1909 * (4 are reserved as alu clause temporary registers) */
1910 if (ctx
.bc
->ngpr
> 124) {
1911 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1917 tgsi_parse_free(&ctx
.parse
);
1921 tgsi_parse_free(&ctx
.parse
);
1925 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1927 R600_ERR("%s tgsi opcode unsupported\n",
1928 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1932 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1937 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1938 const struct r600_shader_src
*shader_src
,
1941 bc_src
->sel
= shader_src
->sel
;
1942 bc_src
->chan
= shader_src
->swizzle
[chan
];
1943 bc_src
->neg
= shader_src
->neg
;
1944 bc_src
->abs
= shader_src
->abs
;
1945 bc_src
->rel
= shader_src
->rel
;
1946 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1947 bc_src
->kc_bank
= shader_src
->kc_bank
;
1950 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1956 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1958 bc_src
->neg
= !bc_src
->neg
;
1961 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1962 const struct tgsi_full_dst_register
*tgsi_dst
,
1964 struct r600_bytecode_alu_dst
*r600_dst
)
1966 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1968 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1969 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1970 r600_dst
->chan
= swizzle
;
1971 r600_dst
->write
= 1;
1972 if (tgsi_dst
->Register
.Indirect
)
1973 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1974 if (inst
->Instruction
.Saturate
) {
1975 r600_dst
->clamp
= 1;
1979 static int tgsi_last_instruction(unsigned writemask
)
1983 for (i
= 0; i
< 4; i
++) {
1984 if (writemask
& (1 << i
)) {
1991 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1993 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1994 struct r600_bytecode_alu alu
;
1996 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1998 for (i
= 0; i
< lasti
+ 1; i
++) {
1999 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2003 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2005 alu
.op
= ctx
->inst_info
->op
;
2007 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2008 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2011 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2012 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2014 /* handle some special cases */
2015 switch (ctx
->inst_info
->tgsi_opcode
) {
2016 case TGSI_OPCODE_SUB
:
2017 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2019 case TGSI_OPCODE_ABS
:
2020 r600_bytecode_src_set_abs(&alu
.src
[0]);
2025 if (i
== lasti
|| trans_only
) {
2028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2035 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2037 return tgsi_op2_s(ctx
, 0, 0);
2040 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2042 return tgsi_op2_s(ctx
, 1, 0);
2045 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2047 return tgsi_op2_s(ctx
, 0, 1);
2050 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2052 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2053 struct r600_bytecode_alu alu
;
2055 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2057 for (i
= 0; i
< lasti
+ 1; i
++) {
2059 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2062 alu
.op
= ctx
->inst_info
->op
;
2064 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2066 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2068 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2081 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2083 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2085 struct r600_bytecode_alu alu
;
2086 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2088 for (i
= 0 ; i
< last_slot
; i
++) {
2089 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2090 alu
.op
= ctx
->inst_info
->op
;
2091 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2092 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2094 /* RSQ should take the absolute value of src */
2095 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2096 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2099 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2100 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2102 if (i
== last_slot
- 1)
2104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2111 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2113 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2115 struct r600_bytecode_alu alu
;
2116 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2117 for (k
= 0; k
< last_slot
; k
++) {
2118 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2121 for (i
= 0 ; i
< 4; i
++) {
2122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2123 alu
.op
= ctx
->inst_info
->op
;
2124 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2125 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2127 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2128 alu
.dst
.write
= (i
== k
);
2131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2140 * r600 - trunc to -PI..PI range
2141 * r700 - normalize by dividing by 2PI
2144 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2146 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2147 static float double_pi
= 3.1415926535 * 2;
2148 static float neg_pi
= -3.1415926535;
2151 struct r600_bytecode_alu alu
;
2153 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2154 alu
.op
= ALU_OP3_MULADD
;
2158 alu
.dst
.sel
= ctx
->temp_reg
;
2161 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2163 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2164 alu
.src
[1].chan
= 0;
2165 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2166 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2167 alu
.src
[2].chan
= 0;
2169 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2173 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2174 alu
.op
= ALU_OP1_FRACT
;
2177 alu
.dst
.sel
= ctx
->temp_reg
;
2180 alu
.src
[0].sel
= ctx
->temp_reg
;
2181 alu
.src
[0].chan
= 0;
2183 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2188 alu
.op
= ALU_OP3_MULADD
;
2192 alu
.dst
.sel
= ctx
->temp_reg
;
2195 alu
.src
[0].sel
= ctx
->temp_reg
;
2196 alu
.src
[0].chan
= 0;
2198 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2199 alu
.src
[1].chan
= 0;
2200 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2201 alu
.src
[2].chan
= 0;
2203 if (ctx
->bc
->chip_class
== R600
) {
2204 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2205 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2207 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2208 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2219 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2221 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2222 struct r600_bytecode_alu alu
;
2223 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2226 r
= tgsi_setup_trig(ctx
);
2231 for (i
= 0; i
< last_slot
; i
++) {
2232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2233 alu
.op
= ctx
->inst_info
->op
;
2236 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2237 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2239 alu
.src
[0].sel
= ctx
->temp_reg
;
2240 alu
.src
[0].chan
= 0;
2241 if (i
== last_slot
- 1)
2243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2250 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2252 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2253 struct r600_bytecode_alu alu
;
2255 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2257 r
= tgsi_setup_trig(ctx
);
2261 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2262 alu
.op
= ctx
->inst_info
->op
;
2264 alu
.dst
.sel
= ctx
->temp_reg
;
2267 alu
.src
[0].sel
= ctx
->temp_reg
;
2268 alu
.src
[0].chan
= 0;
2270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2274 /* replicate result */
2275 for (i
= 0; i
< lasti
+ 1; i
++) {
2276 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2279 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2280 alu
.op
= ALU_OP1_MOV
;
2282 alu
.src
[0].sel
= ctx
->temp_reg
;
2283 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2286 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2293 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2295 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2296 struct r600_bytecode_alu alu
;
2299 /* We'll only need the trig stuff if we are going to write to the
2300 * X or Y components of the destination vector.
2302 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2303 r
= tgsi_setup_trig(ctx
);
2309 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2310 if (ctx
->bc
->chip_class
== CAYMAN
) {
2311 for (i
= 0 ; i
< 3; i
++) {
2312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2313 alu
.op
= ALU_OP1_COS
;
2314 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2320 alu
.src
[0].sel
= ctx
->temp_reg
;
2321 alu
.src
[0].chan
= 0;
2324 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2329 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2330 alu
.op
= ALU_OP1_COS
;
2331 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2333 alu
.src
[0].sel
= ctx
->temp_reg
;
2334 alu
.src
[0].chan
= 0;
2336 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2343 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2344 if (ctx
->bc
->chip_class
== CAYMAN
) {
2345 for (i
= 0 ; i
< 3; i
++) {
2346 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2347 alu
.op
= ALU_OP1_SIN
;
2348 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2353 alu
.src
[0].sel
= ctx
->temp_reg
;
2354 alu
.src
[0].chan
= 0;
2357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2363 alu
.op
= ALU_OP1_SIN
;
2364 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2366 alu
.src
[0].sel
= ctx
->temp_reg
;
2367 alu
.src
[0].chan
= 0;
2369 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2376 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2379 alu
.op
= ALU_OP1_MOV
;
2381 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2383 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2384 alu
.src
[0].chan
= 0;
2388 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2394 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2395 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2397 alu
.op
= ALU_OP1_MOV
;
2399 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2401 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2402 alu
.src
[0].chan
= 0;
2406 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2414 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2416 struct r600_bytecode_alu alu
;
2419 for (i
= 0; i
< 4; i
++) {
2420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2421 alu
.op
= ctx
->inst_info
->op
;
2425 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2427 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2428 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2431 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2436 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2441 /* kill must be last in ALU */
2442 ctx
->bc
->force_add_cf
= 1;
2443 ctx
->shader
->uses_kill
= TRUE
;
2447 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2449 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2450 struct r600_bytecode_alu alu
;
2453 /* tmp.x = max(src.y, 0.0) */
2454 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2455 alu
.op
= ALU_OP2_MAX
;
2456 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2457 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2458 alu
.src
[1].chan
= 1;
2460 alu
.dst
.sel
= ctx
->temp_reg
;
2465 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2469 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2475 if (ctx
->bc
->chip_class
== CAYMAN
) {
2476 for (i
= 0; i
< 3; i
++) {
2477 /* tmp.z = log(tmp.x) */
2478 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2479 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2480 alu
.src
[0].sel
= ctx
->temp_reg
;
2481 alu
.src
[0].chan
= 0;
2482 alu
.dst
.sel
= ctx
->temp_reg
;
2490 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2495 /* tmp.z = log(tmp.x) */
2496 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2497 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2498 alu
.src
[0].sel
= ctx
->temp_reg
;
2499 alu
.src
[0].chan
= 0;
2500 alu
.dst
.sel
= ctx
->temp_reg
;
2504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2509 chan
= alu
.dst
.chan
;
2512 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2513 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2514 alu
.op
= ALU_OP3_MUL_LIT
;
2515 alu
.src
[0].sel
= sel
;
2516 alu
.src
[0].chan
= chan
;
2517 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2518 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2519 alu
.dst
.sel
= ctx
->temp_reg
;
2524 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2528 if (ctx
->bc
->chip_class
== CAYMAN
) {
2529 for (i
= 0; i
< 3; i
++) {
2530 /* dst.z = exp(tmp.x) */
2531 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2532 alu
.op
= ALU_OP1_EXP_IEEE
;
2533 alu
.src
[0].sel
= ctx
->temp_reg
;
2534 alu
.src
[0].chan
= 0;
2535 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2541 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2546 /* dst.z = exp(tmp.x) */
2547 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2548 alu
.op
= ALU_OP1_EXP_IEEE
;
2549 alu
.src
[0].sel
= ctx
->temp_reg
;
2550 alu
.src
[0].chan
= 0;
2551 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2553 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2560 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2561 alu
.op
= ALU_OP1_MOV
;
2562 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2563 alu
.src
[0].chan
= 0;
2564 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2565 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2566 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2570 /* dst.y = max(src.x, 0.0) */
2571 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2572 alu
.op
= ALU_OP2_MAX
;
2573 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2574 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2575 alu
.src
[1].chan
= 0;
2576 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2577 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2578 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2583 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2584 alu
.op
= ALU_OP1_MOV
;
2585 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2586 alu
.src
[0].chan
= 0;
2587 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2588 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2590 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2597 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2599 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2600 struct r600_bytecode_alu alu
;
2603 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2606 * For state trackers other than OpenGL, we'll want to use
2607 * _RECIPSQRT_IEEE instead.
2609 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2611 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2612 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2613 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2615 alu
.dst
.sel
= ctx
->temp_reg
;
2618 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2621 /* replicate result */
2622 return tgsi_helper_tempx_replicate(ctx
);
2625 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2627 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2628 struct r600_bytecode_alu alu
;
2631 for (i
= 0; i
< 4; i
++) {
2632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2633 alu
.src
[0].sel
= ctx
->temp_reg
;
2634 alu
.op
= ALU_OP1_MOV
;
2636 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2637 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2647 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2649 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2650 struct r600_bytecode_alu alu
;
2653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2654 alu
.op
= ctx
->inst_info
->op
;
2655 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2656 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2658 alu
.dst
.sel
= ctx
->temp_reg
;
2661 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2664 /* replicate result */
2665 return tgsi_helper_tempx_replicate(ctx
);
2668 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2670 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2672 struct r600_bytecode_alu alu
;
2673 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2675 for (i
= 0; i
< 3; i
++) {
2676 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2677 alu
.op
= ALU_OP1_LOG_IEEE
;
2678 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2679 alu
.dst
.sel
= ctx
->temp_reg
;
2684 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2690 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2691 alu
.op
= ALU_OP2_MUL
;
2692 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2693 alu
.src
[1].sel
= ctx
->temp_reg
;
2694 alu
.dst
.sel
= ctx
->temp_reg
;
2697 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2701 for (i
= 0; i
< last_slot
; i
++) {
2702 /* POW(a,b) = EXP2(b * LOG2(a))*/
2703 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2704 alu
.op
= ALU_OP1_EXP_IEEE
;
2705 alu
.src
[0].sel
= ctx
->temp_reg
;
2707 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2708 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2709 if (i
== last_slot
- 1)
2711 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2718 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2720 struct r600_bytecode_alu alu
;
2724 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2725 alu
.op
= ALU_OP1_LOG_IEEE
;
2726 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2727 alu
.dst
.sel
= ctx
->temp_reg
;
2730 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2734 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2735 alu
.op
= ALU_OP2_MUL
;
2736 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2737 alu
.src
[1].sel
= ctx
->temp_reg
;
2738 alu
.dst
.sel
= ctx
->temp_reg
;
2741 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2744 /* POW(a,b) = EXP2(b * LOG2(a))*/
2745 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2746 alu
.op
= ALU_OP1_EXP_IEEE
;
2747 alu
.src
[0].sel
= ctx
->temp_reg
;
2748 alu
.dst
.sel
= ctx
->temp_reg
;
2751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2754 return tgsi_helper_tempx_replicate(ctx
);
2757 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2759 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2760 struct r600_bytecode_alu alu
;
2762 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2763 int tmp0
= ctx
->temp_reg
;
2764 int tmp1
= r600_get_temp(ctx
);
2765 int tmp2
= r600_get_temp(ctx
);
2766 int tmp3
= r600_get_temp(ctx
);
2769 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2771 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2772 * 2. tmp0.z = lo (tmp0.x * src2)
2773 * 3. tmp0.w = -tmp0.z
2774 * 4. tmp0.y = hi (tmp0.x * src2)
2775 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2776 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2777 * 7. tmp1.x = tmp0.x - tmp0.w
2778 * 8. tmp1.y = tmp0.x + tmp0.w
2779 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2780 * 10. tmp0.z = hi(tmp0.x * src1) = q
2781 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2783 * 12. tmp0.w = src1 - tmp0.y = r
2784 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2785 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2789 * 15. tmp1.z = tmp0.z + 1 = q + 1
2790 * 16. tmp1.w = tmp0.z - 1 = q - 1
2794 * 15. tmp1.z = tmp0.w - src2 = r - src2
2795 * 16. tmp1.w = tmp0.w + src2 = r + src2
2799 * 17. tmp1.x = tmp1.x & tmp1.y
2801 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2802 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2804 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2805 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2809 * Same as unsigned, using abs values of the operands,
2810 * and fixing the sign of the result in the end.
2813 for (i
= 0; i
< 4; i
++) {
2814 if (!(write_mask
& (1<<i
)))
2819 /* tmp2.x = -src0 */
2820 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2821 alu
.op
= ALU_OP2_SUB_INT
;
2827 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2829 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2832 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2835 /* tmp2.y = -src1 */
2836 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2837 alu
.op
= ALU_OP2_SUB_INT
;
2843 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2845 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2848 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2851 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2852 /* it will be a sign of the quotient */
2855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2856 alu
.op
= ALU_OP2_XOR_INT
;
2862 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2863 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2866 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2870 /* tmp2.x = |src0| */
2871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2872 alu
.op
= ALU_OP3_CNDGE_INT
;
2879 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2880 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2881 alu
.src
[2].sel
= tmp2
;
2882 alu
.src
[2].chan
= 0;
2885 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2888 /* tmp2.y = |src1| */
2889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2890 alu
.op
= ALU_OP3_CNDGE_INT
;
2897 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2898 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2899 alu
.src
[2].sel
= tmp2
;
2900 alu
.src
[2].chan
= 1;
2903 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2908 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2909 if (ctx
->bc
->chip_class
== CAYMAN
) {
2910 /* tmp3.x = u2f(src2) */
2911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2912 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2919 alu
.src
[0].sel
= tmp2
;
2920 alu
.src
[0].chan
= 1;
2922 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2926 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2929 /* tmp0.x = recip(tmp3.x) */
2930 for (j
= 0 ; j
< 3; j
++) {
2931 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2932 alu
.op
= ALU_OP1_RECIP_IEEE
;
2936 alu
.dst
.write
= (j
== 0);
2938 alu
.src
[0].sel
= tmp3
;
2939 alu
.src
[0].chan
= 0;
2943 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2948 alu
.op
= ALU_OP2_MUL
;
2950 alu
.src
[0].sel
= tmp0
;
2951 alu
.src
[0].chan
= 0;
2953 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2954 alu
.src
[1].value
= 0x4f800000;
2959 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2963 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2964 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2970 alu
.src
[0].sel
= tmp3
;
2971 alu
.src
[0].chan
= 0;
2974 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2978 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2979 alu
.op
= ALU_OP1_RECIP_UINT
;
2986 alu
.src
[0].sel
= tmp2
;
2987 alu
.src
[0].chan
= 1;
2989 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2993 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2997 /* 2. tmp0.z = lo (tmp0.x * src2) */
2998 if (ctx
->bc
->chip_class
== CAYMAN
) {
2999 for (j
= 0 ; j
< 4; j
++) {
3000 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3001 alu
.op
= ALU_OP2_MULLO_UINT
;
3005 alu
.dst
.write
= (j
== 2);
3007 alu
.src
[0].sel
= tmp0
;
3008 alu
.src
[0].chan
= 0;
3010 alu
.src
[1].sel
= tmp2
;
3011 alu
.src
[1].chan
= 1;
3013 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3016 alu
.last
= (j
== 3);
3017 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3021 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3022 alu
.op
= ALU_OP2_MULLO_UINT
;
3028 alu
.src
[0].sel
= tmp0
;
3029 alu
.src
[0].chan
= 0;
3031 alu
.src
[1].sel
= tmp2
;
3032 alu
.src
[1].chan
= 1;
3034 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3038 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3042 /* 3. tmp0.w = -tmp0.z */
3043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3044 alu
.op
= ALU_OP2_SUB_INT
;
3050 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3051 alu
.src
[1].sel
= tmp0
;
3052 alu
.src
[1].chan
= 2;
3055 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3058 /* 4. tmp0.y = hi (tmp0.x * src2) */
3059 if (ctx
->bc
->chip_class
== CAYMAN
) {
3060 for (j
= 0 ; j
< 4; j
++) {
3061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3062 alu
.op
= ALU_OP2_MULHI_UINT
;
3066 alu
.dst
.write
= (j
== 1);
3068 alu
.src
[0].sel
= tmp0
;
3069 alu
.src
[0].chan
= 0;
3072 alu
.src
[1].sel
= tmp2
;
3073 alu
.src
[1].chan
= 1;
3075 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3077 alu
.last
= (j
== 3);
3078 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3083 alu
.op
= ALU_OP2_MULHI_UINT
;
3089 alu
.src
[0].sel
= tmp0
;
3090 alu
.src
[0].chan
= 0;
3093 alu
.src
[1].sel
= tmp2
;
3094 alu
.src
[1].chan
= 1;
3096 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3100 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3104 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3105 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3106 alu
.op
= ALU_OP3_CNDE_INT
;
3113 alu
.src
[0].sel
= tmp0
;
3114 alu
.src
[0].chan
= 1;
3115 alu
.src
[1].sel
= tmp0
;
3116 alu
.src
[1].chan
= 3;
3117 alu
.src
[2].sel
= tmp0
;
3118 alu
.src
[2].chan
= 2;
3121 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3124 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3125 if (ctx
->bc
->chip_class
== CAYMAN
) {
3126 for (j
= 0 ; j
< 4; j
++) {
3127 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3128 alu
.op
= ALU_OP2_MULHI_UINT
;
3132 alu
.dst
.write
= (j
== 3);
3134 alu
.src
[0].sel
= tmp0
;
3135 alu
.src
[0].chan
= 2;
3137 alu
.src
[1].sel
= tmp0
;
3138 alu
.src
[1].chan
= 0;
3140 alu
.last
= (j
== 3);
3141 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3146 alu
.op
= ALU_OP2_MULHI_UINT
;
3152 alu
.src
[0].sel
= tmp0
;
3153 alu
.src
[0].chan
= 2;
3155 alu
.src
[1].sel
= tmp0
;
3156 alu
.src
[1].chan
= 0;
3159 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3163 /* 7. tmp1.x = tmp0.x - tmp0.w */
3164 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3165 alu
.op
= ALU_OP2_SUB_INT
;
3171 alu
.src
[0].sel
= tmp0
;
3172 alu
.src
[0].chan
= 0;
3173 alu
.src
[1].sel
= tmp0
;
3174 alu
.src
[1].chan
= 3;
3177 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3180 /* 8. tmp1.y = tmp0.x + tmp0.w */
3181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3182 alu
.op
= ALU_OP2_ADD_INT
;
3188 alu
.src
[0].sel
= tmp0
;
3189 alu
.src
[0].chan
= 0;
3190 alu
.src
[1].sel
= tmp0
;
3191 alu
.src
[1].chan
= 3;
3194 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3197 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3198 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3199 alu
.op
= ALU_OP3_CNDE_INT
;
3206 alu
.src
[0].sel
= tmp0
;
3207 alu
.src
[0].chan
= 1;
3208 alu
.src
[1].sel
= tmp1
;
3209 alu
.src
[1].chan
= 1;
3210 alu
.src
[2].sel
= tmp1
;
3211 alu
.src
[2].chan
= 0;
3214 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3217 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3218 if (ctx
->bc
->chip_class
== CAYMAN
) {
3219 for (j
= 0 ; j
< 4; j
++) {
3220 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3221 alu
.op
= ALU_OP2_MULHI_UINT
;
3225 alu
.dst
.write
= (j
== 2);
3227 alu
.src
[0].sel
= tmp0
;
3228 alu
.src
[0].chan
= 0;
3231 alu
.src
[1].sel
= tmp2
;
3232 alu
.src
[1].chan
= 0;
3234 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3237 alu
.last
= (j
== 3);
3238 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3242 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3243 alu
.op
= ALU_OP2_MULHI_UINT
;
3249 alu
.src
[0].sel
= tmp0
;
3250 alu
.src
[0].chan
= 0;
3253 alu
.src
[1].sel
= tmp2
;
3254 alu
.src
[1].chan
= 0;
3256 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3260 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3264 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3265 if (ctx
->bc
->chip_class
== CAYMAN
) {
3266 for (j
= 0 ; j
< 4; j
++) {
3267 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3268 alu
.op
= ALU_OP2_MULLO_UINT
;
3272 alu
.dst
.write
= (j
== 1);
3275 alu
.src
[0].sel
= tmp2
;
3276 alu
.src
[0].chan
= 1;
3278 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3281 alu
.src
[1].sel
= tmp0
;
3282 alu
.src
[1].chan
= 2;
3284 alu
.last
= (j
== 3);
3285 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3290 alu
.op
= ALU_OP2_MULLO_UINT
;
3297 alu
.src
[0].sel
= tmp2
;
3298 alu
.src
[0].chan
= 1;
3300 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3303 alu
.src
[1].sel
= tmp0
;
3304 alu
.src
[1].chan
= 2;
3307 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3311 /* 12. tmp0.w = src1 - tmp0.y = r */
3312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3313 alu
.op
= ALU_OP2_SUB_INT
;
3320 alu
.src
[0].sel
= tmp2
;
3321 alu
.src
[0].chan
= 0;
3323 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3326 alu
.src
[1].sel
= tmp0
;
3327 alu
.src
[1].chan
= 1;
3330 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3333 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3335 alu
.op
= ALU_OP2_SETGE_UINT
;
3341 alu
.src
[0].sel
= tmp0
;
3342 alu
.src
[0].chan
= 3;
3344 alu
.src
[1].sel
= tmp2
;
3345 alu
.src
[1].chan
= 1;
3347 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3351 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3354 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3356 alu
.op
= ALU_OP2_SETGE_UINT
;
3363 alu
.src
[0].sel
= tmp2
;
3364 alu
.src
[0].chan
= 0;
3366 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3369 alu
.src
[1].sel
= tmp0
;
3370 alu
.src
[1].chan
= 1;
3373 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3376 if (mod
) { /* UMOD */
3378 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3379 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3380 alu
.op
= ALU_OP2_SUB_INT
;
3386 alu
.src
[0].sel
= tmp0
;
3387 alu
.src
[0].chan
= 3;
3390 alu
.src
[1].sel
= tmp2
;
3391 alu
.src
[1].chan
= 1;
3393 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3397 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3400 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3402 alu
.op
= ALU_OP2_ADD_INT
;
3408 alu
.src
[0].sel
= tmp0
;
3409 alu
.src
[0].chan
= 3;
3411 alu
.src
[1].sel
= tmp2
;
3412 alu
.src
[1].chan
= 1;
3414 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3418 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3423 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3424 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3425 alu
.op
= ALU_OP2_ADD_INT
;
3431 alu
.src
[0].sel
= tmp0
;
3432 alu
.src
[0].chan
= 2;
3433 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3436 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3439 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3440 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3441 alu
.op
= ALU_OP2_ADD_INT
;
3447 alu
.src
[0].sel
= tmp0
;
3448 alu
.src
[0].chan
= 2;
3449 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3452 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3457 /* 17. tmp1.x = tmp1.x & tmp1.y */
3458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3459 alu
.op
= ALU_OP2_AND_INT
;
3465 alu
.src
[0].sel
= tmp1
;
3466 alu
.src
[0].chan
= 0;
3467 alu
.src
[1].sel
= tmp1
;
3468 alu
.src
[1].chan
= 1;
3471 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3474 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3475 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3476 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3477 alu
.op
= ALU_OP3_CNDE_INT
;
3484 alu
.src
[0].sel
= tmp1
;
3485 alu
.src
[0].chan
= 0;
3486 alu
.src
[1].sel
= tmp0
;
3487 alu
.src
[1].chan
= mod
? 3 : 2;
3488 alu
.src
[2].sel
= tmp1
;
3489 alu
.src
[2].chan
= 2;
3492 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3495 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3496 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3497 alu
.op
= ALU_OP3_CNDE_INT
;
3505 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3508 alu
.src
[0].sel
= tmp1
;
3509 alu
.src
[0].chan
= 1;
3510 alu
.src
[1].sel
= tmp1
;
3511 alu
.src
[1].chan
= 3;
3512 alu
.src
[2].sel
= tmp0
;
3513 alu
.src
[2].chan
= 2;
3516 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3521 /* fix the sign of the result */
3525 /* tmp0.x = -tmp0.z */
3526 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3527 alu
.op
= ALU_OP2_SUB_INT
;
3533 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3534 alu
.src
[1].sel
= tmp0
;
3535 alu
.src
[1].chan
= 2;
3538 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3541 /* sign of the remainder is the same as the sign of src0 */
3542 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3543 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3544 alu
.op
= ALU_OP3_CNDGE_INT
;
3547 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3549 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3550 alu
.src
[1].sel
= tmp0
;
3551 alu
.src
[1].chan
= 2;
3552 alu
.src
[2].sel
= tmp0
;
3553 alu
.src
[2].chan
= 0;
3556 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3561 /* tmp0.x = -tmp0.z */
3562 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3563 alu
.op
= ALU_OP2_SUB_INT
;
3569 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3570 alu
.src
[1].sel
= tmp0
;
3571 alu
.src
[1].chan
= 2;
3574 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3577 /* fix the quotient sign (same as the sign of src0*src1) */
3578 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3580 alu
.op
= ALU_OP3_CNDGE_INT
;
3583 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3585 alu
.src
[0].sel
= tmp2
;
3586 alu
.src
[0].chan
= 2;
3587 alu
.src
[1].sel
= tmp0
;
3588 alu
.src
[1].chan
= 2;
3589 alu
.src
[2].sel
= tmp0
;
3590 alu
.src
[2].chan
= 0;
3593 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3601 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3603 return tgsi_divmod(ctx
, 0, 0);
3606 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3608 return tgsi_divmod(ctx
, 1, 0);
3611 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3613 return tgsi_divmod(ctx
, 0, 1);
3616 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3618 return tgsi_divmod(ctx
, 1, 1);
3622 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3624 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3625 struct r600_bytecode_alu alu
;
3627 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3628 int last_inst
= tgsi_last_instruction(write_mask
);
3630 for (i
= 0; i
< 4; i
++) {
3631 if (!(write_mask
& (1<<i
)))
3634 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3635 alu
.op
= ALU_OP1_TRUNC
;
3637 alu
.dst
.sel
= ctx
->temp_reg
;
3641 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3644 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3649 for (i
= 0; i
< 4; i
++) {
3650 if (!(write_mask
& (1<<i
)))
3653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3654 alu
.op
= ctx
->inst_info
->op
;
3656 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3658 alu
.src
[0].sel
= ctx
->temp_reg
;
3659 alu
.src
[0].chan
= i
;
3661 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3663 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3671 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3673 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3674 struct r600_bytecode_alu alu
;
3676 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3677 int last_inst
= tgsi_last_instruction(write_mask
);
3680 for (i
= 0; i
< 4; i
++) {
3681 if (!(write_mask
& (1<<i
)))
3684 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3685 alu
.op
= ALU_OP2_SUB_INT
;
3687 alu
.dst
.sel
= ctx
->temp_reg
;
3691 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3692 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3696 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3701 /* dst = (src >= 0 ? src : tmp) */
3702 for (i
= 0; i
< 4; i
++) {
3703 if (!(write_mask
& (1<<i
)))
3706 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3707 alu
.op
= ALU_OP3_CNDGE_INT
;
3711 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3713 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3714 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3715 alu
.src
[2].sel
= ctx
->temp_reg
;
3716 alu
.src
[2].chan
= i
;
3720 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3727 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3729 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3730 struct r600_bytecode_alu alu
;
3732 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3733 int last_inst
= tgsi_last_instruction(write_mask
);
3735 /* tmp = (src >= 0 ? src : -1) */
3736 for (i
= 0; i
< 4; i
++) {
3737 if (!(write_mask
& (1<<i
)))
3740 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3741 alu
.op
= ALU_OP3_CNDGE_INT
;
3744 alu
.dst
.sel
= ctx
->temp_reg
;
3748 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3749 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3750 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3754 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3759 /* dst = (tmp > 0 ? 1 : tmp) */
3760 for (i
= 0; i
< 4; i
++) {
3761 if (!(write_mask
& (1<<i
)))
3764 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3765 alu
.op
= ALU_OP3_CNDGT_INT
;
3769 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3771 alu
.src
[0].sel
= ctx
->temp_reg
;
3772 alu
.src
[0].chan
= i
;
3774 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3776 alu
.src
[2].sel
= ctx
->temp_reg
;
3777 alu
.src
[2].chan
= i
;
3781 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3790 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3792 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3793 struct r600_bytecode_alu alu
;
3796 /* tmp = (src > 0 ? 1 : src) */
3797 for (i
= 0; i
< 4; i
++) {
3798 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3799 alu
.op
= ALU_OP3_CNDGT
;
3802 alu
.dst
.sel
= ctx
->temp_reg
;
3805 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3806 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3807 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3811 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3816 /* dst = (-tmp > 0 ? -1 : tmp) */
3817 for (i
= 0; i
< 4; i
++) {
3818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3819 alu
.op
= ALU_OP3_CNDGT
;
3821 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3823 alu
.src
[0].sel
= ctx
->temp_reg
;
3824 alu
.src
[0].chan
= i
;
3827 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3830 alu
.src
[2].sel
= ctx
->temp_reg
;
3831 alu
.src
[2].chan
= i
;
3835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3842 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3844 struct r600_bytecode_alu alu
;
3847 for (i
= 0; i
< 4; i
++) {
3848 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3849 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3850 alu
.op
= ALU_OP0_NOP
;
3853 alu
.op
= ALU_OP1_MOV
;
3854 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3855 alu
.src
[0].sel
= ctx
->temp_reg
;
3856 alu
.src
[0].chan
= i
;
3861 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3868 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3870 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3871 struct r600_bytecode_alu alu
;
3873 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3875 for (i
= 0; i
< lasti
+ 1; i
++) {
3876 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3880 alu
.op
= ctx
->inst_info
->op
;
3881 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3882 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3885 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3892 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3899 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3901 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3902 struct r600_bytecode_alu alu
;
3905 for (i
= 0; i
< 4; i
++) {
3906 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3907 alu
.op
= ctx
->inst_info
->op
;
3908 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3909 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3912 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3914 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3915 /* handle some special cases */
3916 switch (ctx
->inst_info
->tgsi_opcode
) {
3917 case TGSI_OPCODE_DP2
:
3919 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3920 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3923 case TGSI_OPCODE_DP3
:
3925 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3926 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3929 case TGSI_OPCODE_DPH
:
3931 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3932 alu
.src
[0].chan
= 0;
3942 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3949 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3952 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3953 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3954 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3955 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3956 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3959 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3962 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3963 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3966 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3968 struct r600_bytecode_vtx vtx
;
3969 struct r600_bytecode_alu alu
;
3970 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3972 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3974 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3975 if (src_requires_loading
) {
3976 for (i
= 0; i
< 4; i
++) {
3977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3978 alu
.op
= ALU_OP1_MOV
;
3979 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3980 alu
.dst
.sel
= ctx
->temp_reg
;
3985 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3989 src_gpr
= ctx
->temp_reg
;
3992 memset(&vtx
, 0, sizeof(vtx
));
3993 vtx
.op
= FETCH_OP_VFETCH
;
3994 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3995 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3996 vtx
.src_gpr
= src_gpr
;
3997 vtx
.mega_fetch_count
= 16;
3998 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3999 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
4000 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
4001 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4002 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4003 vtx
.use_const_fields
= 1;
4004 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4006 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4009 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4012 for (i
= 0; i
< 4; i
++) {
4013 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4014 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4017 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4018 alu
.op
= ALU_OP2_AND_INT
;
4021 alu
.dst
.sel
= vtx
.dst_gpr
;
4024 alu
.src
[0].sel
= vtx
.dst_gpr
;
4025 alu
.src
[0].chan
= i
;
4027 alu
.src
[1].sel
= 512 + (id
* 2);
4028 alu
.src
[1].chan
= i
% 4;
4029 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4038 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4040 alu
.op
= ALU_OP2_OR_INT
;
4043 alu
.dst
.sel
= vtx
.dst_gpr
;
4046 alu
.src
[0].sel
= vtx
.dst_gpr
;
4047 alu
.src
[0].chan
= 3;
4049 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4050 alu
.src
[1].chan
= 0;
4051 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4054 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4061 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4063 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4064 struct r600_bytecode_alu alu
;
4066 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4068 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4069 alu
.op
= ALU_OP1_MOV
;
4071 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4072 alu
.src
[0].sel
= 512 + (id
/ 4);
4073 alu
.src
[0].chan
= id
% 4;
4075 /* r600 we have them at channel 2 of the second dword */
4076 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4077 alu
.src
[0].chan
= 1;
4079 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4080 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4082 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4088 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4090 static float one_point_five
= 1.5f
;
4091 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4092 struct r600_bytecode_tex tex
;
4093 struct r600_bytecode_alu alu
;
4097 bool read_compressed_msaa
= ctx
->bc
->msaa_texture_mode
== MSAA_TEXTURE_COMPRESSED
&&
4098 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4099 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4100 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4101 /* Texture fetch instructions can only use gprs as source.
4102 * Also they cannot negate the source or take the absolute value */
4103 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4104 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4105 read_compressed_msaa
;
4106 boolean src_loaded
= FALSE
;
4107 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4108 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4109 boolean has_txq_cube_array_z
= false;
4111 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4112 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4113 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4114 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4115 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4116 has_txq_cube_array_z
= true;
4119 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4120 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4121 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4122 sampler_src_reg
= 2;
4124 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4126 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4127 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4128 ctx
->shader
->uses_tex_buffers
= true;
4129 return r600_do_buffer_txq(ctx
);
4131 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4132 if (ctx
->bc
->chip_class
< EVERGREEN
)
4133 ctx
->shader
->uses_tex_buffers
= true;
4134 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4138 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4139 /* get offset values */
4140 if (inst
->Texture
.NumOffsets
) {
4141 assert(inst
->Texture
.NumOffsets
== 1);
4143 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4144 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4145 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4147 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4148 /* TGSI moves the sampler to src reg 3 for TXD */
4149 sampler_src_reg
= 3;
4151 for (i
= 1; i
< 3; i
++) {
4152 /* set gradients h/v */
4153 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4154 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4155 FETCH_OP_SET_GRADIENTS_V
;
4156 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4157 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4159 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4160 tex
.src_gpr
= r600_get_temp(ctx
);
4166 for (j
= 0; j
< 4; j
++) {
4167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4168 alu
.op
= ALU_OP1_MOV
;
4169 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4170 alu
.dst
.sel
= tex
.src_gpr
;
4175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4181 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4182 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4183 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4184 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4185 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4186 tex
.src_rel
= ctx
->src
[i
].rel
;
4188 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4189 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4190 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4191 tex
.coord_type_x
= 1;
4192 tex
.coord_type_y
= 1;
4193 tex
.coord_type_z
= 1;
4194 tex
.coord_type_w
= 1;
4196 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4200 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4202 /* Add perspective divide */
4203 if (ctx
->bc
->chip_class
== CAYMAN
) {
4205 for (i
= 0; i
< 3; i
++) {
4206 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4207 alu
.op
= ALU_OP1_RECIP_IEEE
;
4208 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4210 alu
.dst
.sel
= ctx
->temp_reg
;
4216 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4224 alu
.op
= ALU_OP1_RECIP_IEEE
;
4225 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4227 alu
.dst
.sel
= ctx
->temp_reg
;
4228 alu
.dst
.chan
= out_chan
;
4231 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4236 for (i
= 0; i
< 3; i
++) {
4237 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4238 alu
.op
= ALU_OP2_MUL
;
4239 alu
.src
[0].sel
= ctx
->temp_reg
;
4240 alu
.src
[0].chan
= out_chan
;
4241 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4242 alu
.dst
.sel
= ctx
->temp_reg
;
4245 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4250 alu
.op
= ALU_OP1_MOV
;
4251 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4252 alu
.src
[0].chan
= 0;
4253 alu
.dst
.sel
= ctx
->temp_reg
;
4257 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4261 src_gpr
= ctx
->temp_reg
;
4264 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4265 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4266 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4267 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4268 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4269 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4271 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4272 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4274 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4275 for (i
= 0; i
< 4; i
++) {
4276 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4277 alu
.op
= ALU_OP2_CUBE
;
4278 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4279 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4280 alu
.dst
.sel
= ctx
->temp_reg
;
4285 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4290 /* tmp1.z = RCP_e(|tmp1.z|) */
4291 if (ctx
->bc
->chip_class
== CAYMAN
) {
4292 for (i
= 0; i
< 3; i
++) {
4293 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4294 alu
.op
= ALU_OP1_RECIP_IEEE
;
4295 alu
.src
[0].sel
= ctx
->temp_reg
;
4296 alu
.src
[0].chan
= 2;
4298 alu
.dst
.sel
= ctx
->temp_reg
;
4304 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4309 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4310 alu
.op
= ALU_OP1_RECIP_IEEE
;
4311 alu
.src
[0].sel
= ctx
->temp_reg
;
4312 alu
.src
[0].chan
= 2;
4314 alu
.dst
.sel
= ctx
->temp_reg
;
4318 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4323 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4324 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4325 * muladd has no writemask, have to use another temp
4327 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4328 alu
.op
= ALU_OP3_MULADD
;
4331 alu
.src
[0].sel
= ctx
->temp_reg
;
4332 alu
.src
[0].chan
= 0;
4333 alu
.src
[1].sel
= ctx
->temp_reg
;
4334 alu
.src
[1].chan
= 2;
4336 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4337 alu
.src
[2].chan
= 0;
4338 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4340 alu
.dst
.sel
= ctx
->temp_reg
;
4344 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4348 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4349 alu
.op
= ALU_OP3_MULADD
;
4352 alu
.src
[0].sel
= ctx
->temp_reg
;
4353 alu
.src
[0].chan
= 1;
4354 alu
.src
[1].sel
= ctx
->temp_reg
;
4355 alu
.src
[1].chan
= 2;
4357 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4358 alu
.src
[2].chan
= 0;
4359 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4361 alu
.dst
.sel
= ctx
->temp_reg
;
4366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4369 /* write initial compare value into Z component
4370 - W src 0 for shadow cube
4371 - X src 1 for shadow cube array */
4372 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4373 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4375 alu
.op
= ALU_OP1_MOV
;
4376 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4377 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4379 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4380 alu
.dst
.sel
= ctx
->temp_reg
;
4384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4389 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4390 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4391 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4392 int mytmp
= r600_get_temp(ctx
);
4393 static const float eight
= 8.0f
;
4394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4395 alu
.op
= ALU_OP1_MOV
;
4396 alu
.src
[0].sel
= ctx
->temp_reg
;
4397 alu
.src
[0].chan
= 3;
4398 alu
.dst
.sel
= mytmp
;
4402 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4406 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4407 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4408 alu
.op
= ALU_OP3_MULADD
;
4410 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4411 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4412 alu
.src
[1].chan
= 0;
4413 alu
.src
[1].value
= *(uint32_t *)&eight
;
4414 alu
.src
[2].sel
= mytmp
;
4415 alu
.src
[2].chan
= 0;
4416 alu
.dst
.sel
= ctx
->temp_reg
;
4420 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4423 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4424 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4425 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4426 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4427 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4428 tex
.src_gpr
= r600_get_temp(ctx
);
4433 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4434 tex
.coord_type_x
= 1;
4435 tex
.coord_type_y
= 1;
4436 tex
.coord_type_z
= 1;
4437 tex
.coord_type_w
= 1;
4438 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4439 alu
.op
= ALU_OP1_MOV
;
4440 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4441 alu
.dst
.sel
= tex
.src_gpr
;
4445 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4449 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4456 /* for cube forms of lod and bias we need to route things */
4457 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4458 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4459 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4460 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4462 alu
.op
= ALU_OP1_MOV
;
4463 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4464 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4465 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4467 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4468 alu
.dst
.sel
= ctx
->temp_reg
;
4472 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4478 src_gpr
= ctx
->temp_reg
;
4481 if (src_requires_loading
&& !src_loaded
) {
4482 for (i
= 0; i
< 4; i
++) {
4483 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4484 alu
.op
= ALU_OP1_MOV
;
4485 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4486 alu
.dst
.sel
= ctx
->temp_reg
;
4491 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4496 src_gpr
= ctx
->temp_reg
;
4499 /* Obtain the sample index for reading a compressed MSAA color texture.
4500 * To read the FMASK, we use the ldfptr instruction, which tells us
4501 * where the samples are stored.
4502 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4503 * which is the identity mapping. Each nibble says which physical sample
4504 * should be fetched to get that sample.
4506 * Assume src.z contains the sample index. It should be modified like this:
4507 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4508 * Then fetch the texel with src.
4510 if (read_compressed_msaa
) {
4511 unsigned sample_chan
= 3;
4512 unsigned temp
= r600_get_temp(ctx
);
4515 /* temp.w = ldfptr() */
4516 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4517 tex
.op
= FETCH_OP_LD
;
4518 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4519 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4520 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4521 tex
.src_gpr
= src_gpr
;
4523 tex
.dst_sel_x
= 7; /* mask out these components */
4526 tex
.dst_sel_w
= 0; /* store X */
4531 tex
.offset_x
= offset_x
;
4532 tex
.offset_y
= offset_y
;
4533 tex
.offset_z
= offset_z
;
4534 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4538 /* temp.x = sample_index*4 */
4539 if (ctx
->bc
->chip_class
== CAYMAN
) {
4540 for (i
= 0 ; i
< 4; i
++) {
4541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4542 alu
.op
= ALU_OP2_MULLO_INT
;
4543 alu
.src
[0].sel
= src_gpr
;
4544 alu
.src
[0].chan
= sample_chan
;
4545 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4546 alu
.src
[1].value
= 4;
4549 alu
.dst
.write
= i
== 0;
4552 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4557 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4558 alu
.op
= ALU_OP2_MULLO_INT
;
4559 alu
.src
[0].sel
= src_gpr
;
4560 alu
.src
[0].chan
= sample_chan
;
4561 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4562 alu
.src
[1].value
= 4;
4567 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4572 /* sample_index = temp.w >> temp.x */
4573 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4574 alu
.op
= ALU_OP2_LSHR_INT
;
4575 alu
.src
[0].sel
= temp
;
4576 alu
.src
[0].chan
= 3;
4577 alu
.src
[1].sel
= temp
;
4578 alu
.src
[1].chan
= 0;
4579 alu
.dst
.sel
= src_gpr
;
4580 alu
.dst
.chan
= sample_chan
;
4583 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4587 /* sample_index & 0xF */
4588 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4589 alu
.op
= ALU_OP2_AND_INT
;
4590 alu
.src
[0].sel
= src_gpr
;
4591 alu
.src
[0].chan
= sample_chan
;
4592 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4593 alu
.src
[1].value
= 0xF;
4594 alu
.dst
.sel
= src_gpr
;
4595 alu
.dst
.chan
= sample_chan
;
4598 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4602 /* visualize the FMASK */
4603 for (i
= 0; i
< 4; i
++) {
4604 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4605 alu
.op
= ALU_OP1_INT_TO_FLT
;
4606 alu
.src
[0].sel
= src_gpr
;
4607 alu
.src
[0].chan
= sample_chan
;
4608 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4612 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4620 /* does this shader want a num layers from TXQ for a cube array? */
4621 if (has_txq_cube_array_z
) {
4622 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4624 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4625 alu
.op
= ALU_OP1_MOV
;
4627 alu
.src
[0].sel
= 512 + (id
/ 4);
4628 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4629 alu
.src
[0].chan
= id
% 4;
4630 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4632 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4635 /* disable writemask from texture instruction */
4636 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4639 opcode
= ctx
->inst_info
->op
;
4640 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4641 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4642 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4643 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4644 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4645 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4646 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4648 case FETCH_OP_SAMPLE
:
4649 opcode
= FETCH_OP_SAMPLE_C
;
4651 case FETCH_OP_SAMPLE_L
:
4652 opcode
= FETCH_OP_SAMPLE_C_L
;
4654 case FETCH_OP_SAMPLE_LB
:
4655 opcode
= FETCH_OP_SAMPLE_C_LB
;
4657 case FETCH_OP_SAMPLE_G
:
4658 opcode
= FETCH_OP_SAMPLE_C_G
;
4663 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4666 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4667 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4668 tex
.src_gpr
= src_gpr
;
4669 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4670 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4671 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4672 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4673 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4675 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4680 } else if (src_loaded
) {
4686 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4687 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4688 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4689 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4690 tex
.src_rel
= ctx
->src
[0].rel
;
4693 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4694 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4695 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4696 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4700 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4703 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4704 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4705 tex
.coord_type_x
= 1;
4706 tex
.coord_type_y
= 1;
4708 tex
.coord_type_z
= 1;
4709 tex
.coord_type_w
= 1;
4711 tex
.offset_x
= offset_x
;
4712 tex
.offset_y
= offset_y
;
4713 tex
.offset_z
= offset_z
;
4715 /* Put the depth for comparison in W.
4716 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4717 * Some instructions expect the depth in Z. */
4718 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4719 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4720 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4721 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4722 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4723 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4724 tex
.src_sel_w
= tex
.src_sel_z
;
4727 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4728 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4729 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4730 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4731 /* the array index is read from Y */
4732 tex
.coord_type_y
= 0;
4734 /* the array index is read from Z */
4735 tex
.coord_type_z
= 0;
4736 tex
.src_sel_z
= tex
.src_sel_y
;
4738 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4739 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4740 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4741 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4742 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4743 /* the array index is read from Z */
4744 tex
.coord_type_z
= 0;
4746 /* mask unused source components */
4747 if (opcode
== FETCH_OP_SAMPLE
) {
4748 switch (inst
->Texture
.Texture
) {
4749 case TGSI_TEXTURE_2D
:
4750 case TGSI_TEXTURE_RECT
:
4754 case TGSI_TEXTURE_1D_ARRAY
:
4758 case TGSI_TEXTURE_1D
:
4766 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4770 /* add shadow ambient support - gallium doesn't do it yet */
4774 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4776 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4777 struct r600_bytecode_alu alu
;
4778 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4782 /* optimize if it's just an equal balance */
4783 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
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 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4791 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4793 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4798 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
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_ADD
;
4812 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4813 alu
.src
[0].chan
= 0;
4814 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4815 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4816 alu
.dst
.sel
= ctx
->temp_reg
;
4822 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4827 /* (1 - src0) * src2 */
4828 for (i
= 0; i
< lasti
+ 1; i
++) {
4829 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4832 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4833 alu
.op
= ALU_OP2_MUL
;
4834 alu
.src
[0].sel
= ctx
->temp_reg
;
4835 alu
.src
[0].chan
= i
;
4836 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4837 alu
.dst
.sel
= ctx
->temp_reg
;
4843 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4848 /* src0 * src1 + (1 - src0) * src2 */
4849 for (i
= 0; i
< lasti
+ 1; i
++) {
4850 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4854 alu
.op
= ALU_OP3_MULADD
;
4856 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4857 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4858 alu
.src
[2].sel
= ctx
->temp_reg
;
4859 alu
.src
[2].chan
= i
;
4861 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4866 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4873 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4875 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4876 struct r600_bytecode_alu alu
;
4878 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4880 for (i
= 0; i
< lasti
+ 1; i
++) {
4881 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4884 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4885 alu
.op
= ALU_OP3_CNDGE
;
4886 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4887 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4888 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4889 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4895 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4902 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4904 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4905 struct r600_bytecode_alu alu
;
4907 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4909 for (i
= 0; i
< lasti
+ 1; i
++) {
4910 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4913 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4914 alu
.op
= ALU_OP3_CNDGE_INT
;
4915 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4916 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4917 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4918 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4924 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4931 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4933 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4934 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4935 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4936 struct r600_bytecode_alu alu
;
4937 uint32_t use_temp
= 0;
4940 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4943 for (i
= 0; i
< 4; i
++) {
4944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4945 alu
.op
= ALU_OP2_MUL
;
4947 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4948 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4950 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4951 alu
.src
[0].chan
= i
;
4952 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4953 alu
.src
[1].chan
= i
;
4956 alu
.dst
.sel
= ctx
->temp_reg
;
4962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4967 for (i
= 0; i
< 4; i
++) {
4968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4969 alu
.op
= ALU_OP3_MULADD
;
4972 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4973 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4975 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4976 alu
.src
[0].chan
= i
;
4977 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4978 alu
.src
[1].chan
= i
;
4981 alu
.src
[2].sel
= ctx
->temp_reg
;
4983 alu
.src
[2].chan
= i
;
4986 alu
.dst
.sel
= ctx
->temp_reg
;
4988 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4994 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4999 return tgsi_helper_copy(ctx
, inst
);
5003 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
5005 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5006 struct r600_bytecode_alu alu
;
5010 /* result.x = 2^floor(src); */
5011 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5014 alu
.op
= ALU_OP1_FLOOR
;
5015 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5017 alu
.dst
.sel
= ctx
->temp_reg
;
5021 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5025 if (ctx
->bc
->chip_class
== CAYMAN
) {
5026 for (i
= 0; i
< 3; i
++) {
5027 alu
.op
= ALU_OP1_EXP_IEEE
;
5028 alu
.src
[0].sel
= ctx
->temp_reg
;
5029 alu
.src
[0].chan
= 0;
5031 alu
.dst
.sel
= ctx
->temp_reg
;
5033 alu
.dst
.write
= i
== 0;
5035 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5040 alu
.op
= ALU_OP1_EXP_IEEE
;
5041 alu
.src
[0].sel
= ctx
->temp_reg
;
5042 alu
.src
[0].chan
= 0;
5044 alu
.dst
.sel
= ctx
->temp_reg
;
5048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5054 /* result.y = tmp - floor(tmp); */
5055 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5056 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5058 alu
.op
= ALU_OP1_FRACT
;
5059 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5061 alu
.dst
.sel
= ctx
->temp_reg
;
5063 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5072 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5077 /* result.z = RoughApprox2ToX(tmp);*/
5078 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5079 if (ctx
->bc
->chip_class
== CAYMAN
) {
5080 for (i
= 0; i
< 3; i
++) {
5081 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5082 alu
.op
= ALU_OP1_EXP_IEEE
;
5083 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5085 alu
.dst
.sel
= ctx
->temp_reg
;
5092 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5097 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5098 alu
.op
= ALU_OP1_EXP_IEEE
;
5099 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5101 alu
.dst
.sel
= ctx
->temp_reg
;
5107 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5113 /* result.w = 1.0;*/
5114 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5115 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5117 alu
.op
= ALU_OP1_MOV
;
5118 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5119 alu
.src
[0].chan
= 0;
5121 alu
.dst
.sel
= ctx
->temp_reg
;
5125 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5129 return tgsi_helper_copy(ctx
, inst
);
5132 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5134 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5135 struct r600_bytecode_alu alu
;
5139 /* result.x = floor(log2(|src|)); */
5140 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5141 if (ctx
->bc
->chip_class
== CAYMAN
) {
5142 for (i
= 0; i
< 3; i
++) {
5143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5145 alu
.op
= ALU_OP1_LOG_IEEE
;
5146 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5147 r600_bytecode_src_set_abs(&alu
.src
[0]);
5149 alu
.dst
.sel
= ctx
->temp_reg
;
5155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5161 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5163 alu
.op
= ALU_OP1_LOG_IEEE
;
5164 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5165 r600_bytecode_src_set_abs(&alu
.src
[0]);
5167 alu
.dst
.sel
= ctx
->temp_reg
;
5171 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5176 alu
.op
= ALU_OP1_FLOOR
;
5177 alu
.src
[0].sel
= ctx
->temp_reg
;
5178 alu
.src
[0].chan
= 0;
5180 alu
.dst
.sel
= ctx
->temp_reg
;
5185 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5190 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5191 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5193 if (ctx
->bc
->chip_class
== CAYMAN
) {
5194 for (i
= 0; i
< 3; i
++) {
5195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5197 alu
.op
= ALU_OP1_LOG_IEEE
;
5198 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5199 r600_bytecode_src_set_abs(&alu
.src
[0]);
5201 alu
.dst
.sel
= ctx
->temp_reg
;
5208 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5215 alu
.op
= ALU_OP1_LOG_IEEE
;
5216 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5217 r600_bytecode_src_set_abs(&alu
.src
[0]);
5219 alu
.dst
.sel
= ctx
->temp_reg
;
5224 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5231 alu
.op
= ALU_OP1_FLOOR
;
5232 alu
.src
[0].sel
= ctx
->temp_reg
;
5233 alu
.src
[0].chan
= 1;
5235 alu
.dst
.sel
= ctx
->temp_reg
;
5240 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5244 if (ctx
->bc
->chip_class
== CAYMAN
) {
5245 for (i
= 0; i
< 3; i
++) {
5246 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5247 alu
.op
= ALU_OP1_EXP_IEEE
;
5248 alu
.src
[0].sel
= ctx
->temp_reg
;
5249 alu
.src
[0].chan
= 1;
5251 alu
.dst
.sel
= ctx
->temp_reg
;
5258 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5263 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5264 alu
.op
= ALU_OP1_EXP_IEEE
;
5265 alu
.src
[0].sel
= ctx
->temp_reg
;
5266 alu
.src
[0].chan
= 1;
5268 alu
.dst
.sel
= ctx
->temp_reg
;
5273 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5278 if (ctx
->bc
->chip_class
== CAYMAN
) {
5279 for (i
= 0; i
< 3; i
++) {
5280 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5281 alu
.op
= ALU_OP1_RECIP_IEEE
;
5282 alu
.src
[0].sel
= ctx
->temp_reg
;
5283 alu
.src
[0].chan
= 1;
5285 alu
.dst
.sel
= ctx
->temp_reg
;
5292 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5298 alu
.op
= ALU_OP1_RECIP_IEEE
;
5299 alu
.src
[0].sel
= ctx
->temp_reg
;
5300 alu
.src
[0].chan
= 1;
5302 alu
.dst
.sel
= ctx
->temp_reg
;
5307 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5314 alu
.op
= ALU_OP2_MUL
;
5316 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5317 r600_bytecode_src_set_abs(&alu
.src
[0]);
5319 alu
.src
[1].sel
= ctx
->temp_reg
;
5320 alu
.src
[1].chan
= 1;
5322 alu
.dst
.sel
= ctx
->temp_reg
;
5327 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5332 /* result.z = log2(|src|);*/
5333 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5334 if (ctx
->bc
->chip_class
== CAYMAN
) {
5335 for (i
= 0; i
< 3; i
++) {
5336 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5338 alu
.op
= ALU_OP1_LOG_IEEE
;
5339 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5340 r600_bytecode_src_set_abs(&alu
.src
[0]);
5342 alu
.dst
.sel
= ctx
->temp_reg
;
5349 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5354 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5356 alu
.op
= ALU_OP1_LOG_IEEE
;
5357 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5358 r600_bytecode_src_set_abs(&alu
.src
[0]);
5360 alu
.dst
.sel
= ctx
->temp_reg
;
5365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5371 /* result.w = 1.0; */
5372 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5373 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5375 alu
.op
= ALU_OP1_MOV
;
5376 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5377 alu
.src
[0].chan
= 0;
5379 alu
.dst
.sel
= ctx
->temp_reg
;
5384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5389 return tgsi_helper_copy(ctx
, inst
);
5392 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5394 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5395 struct r600_bytecode_alu alu
;
5398 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5400 switch (inst
->Instruction
.Opcode
) {
5401 case TGSI_OPCODE_ARL
:
5402 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5404 case TGSI_OPCODE_ARR
:
5405 alu
.op
= ALU_OP1_FLT_TO_INT
;
5407 case TGSI_OPCODE_UARL
:
5408 alu
.op
= ALU_OP1_MOV
;
5415 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5417 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5419 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5423 ctx
->bc
->ar_loaded
= 0;
5426 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5428 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5429 struct r600_bytecode_alu alu
;
5432 switch (inst
->Instruction
.Opcode
) {
5433 case TGSI_OPCODE_ARL
:
5434 memset(&alu
, 0, sizeof(alu
));
5435 alu
.op
= ALU_OP1_FLOOR
;
5436 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5437 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5441 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5444 memset(&alu
, 0, sizeof(alu
));
5445 alu
.op
= ALU_OP1_FLT_TO_INT
;
5446 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5447 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5451 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5454 case TGSI_OPCODE_ARR
:
5455 memset(&alu
, 0, sizeof(alu
));
5456 alu
.op
= ALU_OP1_FLT_TO_INT
;
5457 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5458 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5462 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5465 case TGSI_OPCODE_UARL
:
5466 memset(&alu
, 0, sizeof(alu
));
5467 alu
.op
= ALU_OP1_MOV
;
5468 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5469 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5473 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5481 ctx
->bc
->ar_loaded
= 0;
5485 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5487 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5488 struct r600_bytecode_alu alu
;
5491 for (i
= 0; i
< 4; i
++) {
5492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5494 alu
.op
= ALU_OP2_MUL
;
5495 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5497 if (i
== 0 || i
== 3) {
5498 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5500 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5503 if (i
== 0 || i
== 2) {
5504 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5506 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5510 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5517 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5519 struct r600_bytecode_alu alu
;
5522 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5524 alu
.execute_mask
= 1;
5525 alu
.update_pred
= 1;
5527 alu
.dst
.sel
= ctx
->temp_reg
;
5531 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5532 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5533 alu
.src
[1].chan
= 0;
5537 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5543 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5545 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5549 if (ctx
->bc
->cf_last
) {
5550 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5552 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5557 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5558 ctx
->bc
->force_add_cf
= 1;
5559 } else if (alu_pop
== 2) {
5560 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5561 ctx
->bc
->force_add_cf
= 1;
5568 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5569 ctx
->bc
->cf_last
->pop_count
= pops
;
5570 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5576 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5579 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5580 unsigned elements
, entries
;
5582 unsigned entry_size
= stack
->entry_size
;
5584 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5585 elements
+= stack
->push
;
5587 switch (ctx
->bc
->chip_class
) {
5590 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5591 * the stack must be reserved to hold the current active/continue
5593 if (reason
== FC_PUSH_VPM
) {
5599 /* r9xx: any stack operation on empty stack consumes 2 additional
5604 /* FIXME: do the two elements added above cover the cases for the
5608 /* r8xx+: 2 extra elements are not always required, but one extra
5609 * element must be added for each of the following cases:
5610 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5612 * (Currently we don't use ALU_ELSE_AFTER.)
5613 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5614 * PUSH instruction executed.
5616 * NOTE: it seems we also need to reserve additional element in some
5617 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5618 * then STACK_SIZE should be 2 instead of 1 */
5619 if (reason
== FC_PUSH_VPM
) {
5629 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5630 * for all chips, so we use 4 in the final formula, not the real entry_size
5634 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5636 if (entries
> stack
->max_entries
)
5637 stack
->max_entries
= entries
;
5640 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5644 --ctx
->bc
->stack
.push
;
5645 assert(ctx
->bc
->stack
.push
>= 0);
5648 --ctx
->bc
->stack
.push_wqm
;
5649 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5652 --ctx
->bc
->stack
.loop
;
5653 assert(ctx
->bc
->stack
.loop
>= 0);
5661 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5665 ++ctx
->bc
->stack
.push
;
5668 ++ctx
->bc
->stack
.push_wqm
;
5670 ++ctx
->bc
->stack
.loop
;
5676 callstack_update_max_depth(ctx
, reason
);
5679 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5681 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5683 sp
->mid
= realloc((void *)sp
->mid
,
5684 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5685 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5689 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5692 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5693 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5696 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5698 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5708 static int emit_return(struct r600_shader_ctx
*ctx
)
5710 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5714 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5717 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5718 ctx
->bc
->cf_last
->pop_count
= pops
;
5719 /* XXX work out offset */
5723 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5728 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5733 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5736 emit_jump_to_offset(ctx
, 1, 4);
5737 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5738 pops(ctx
, ifidx
+ 1);
5742 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5746 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5747 ctx
->bc
->cf_last
->pop_count
= 1;
5749 fc_set_mid(ctx
, fc_sp
);
5755 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5757 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5759 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5760 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5761 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5762 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5763 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5764 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5765 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5766 alu_type
= CF_OP_ALU
;
5769 emit_logic_pred(ctx
, opcode
, alu_type
);
5771 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5773 fc_pushlevel(ctx
, FC_IF
);
5775 callstack_push(ctx
, FC_PUSH_VPM
);
5779 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5781 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5784 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5786 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5789 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5791 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5792 ctx
->bc
->cf_last
->pop_count
= 1;
5794 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5795 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5799 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5802 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5803 R600_ERR("if/endif unbalanced in shader\n");
5807 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5808 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5809 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5811 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5815 callstack_pop(ctx
, FC_PUSH_VPM
);
5819 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5821 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5822 * limited to 4096 iterations, like the other LOOP_* instructions. */
5823 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5825 fc_pushlevel(ctx
, FC_LOOP
);
5827 /* check stack depth */
5828 callstack_push(ctx
, FC_LOOP
);
5832 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5836 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5838 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5839 R600_ERR("loop/endloop in shader code are not paired.\n");
5843 /* fixup loop pointers - from r600isa
5844 LOOP END points to CF after LOOP START,
5845 LOOP START point to CF after LOOP END
5846 BRK/CONT point to LOOP END CF
5848 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5850 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5852 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5853 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5855 /* XXX add LOOPRET support */
5857 callstack_pop(ctx
, FC_LOOP
);
5861 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5865 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5867 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5872 R600_ERR("Break not inside loop/endloop pair\n");
5876 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5878 fc_set_mid(ctx
, fscp
);
5883 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5885 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5886 struct r600_bytecode_alu alu
;
5888 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5891 for (i
= 0; i
< lasti
+ 1; i
++) {
5892 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5895 if (ctx
->bc
->chip_class
== CAYMAN
) {
5896 for (j
= 0 ; j
< 4; j
++) {
5897 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5899 alu
.op
= ALU_OP2_MULLO_UINT
;
5900 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5901 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5903 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5904 alu
.dst
.sel
= ctx
->temp_reg
;
5905 alu
.dst
.write
= (j
== i
);
5908 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5913 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5916 alu
.dst
.sel
= ctx
->temp_reg
;
5919 alu
.op
= ALU_OP2_MULLO_UINT
;
5920 for (j
= 0; j
< 2; j
++) {
5921 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5925 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5932 for (i
= 0; i
< lasti
+ 1; i
++) {
5933 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5936 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5937 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5939 alu
.op
= ALU_OP2_ADD_INT
;
5941 alu
.src
[0].sel
= ctx
->temp_reg
;
5942 alu
.src
[0].chan
= i
;
5944 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5948 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5955 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5956 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5957 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5958 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5961 * For state trackers other than OpenGL, we'll want to use
5962 * _RECIP_IEEE instead.
5964 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5966 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5967 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5968 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5969 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5970 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5971 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5972 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5973 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5974 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5975 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5976 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5977 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5978 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5979 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5980 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5981 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5983 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5984 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5986 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5987 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5988 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5989 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5990 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5991 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5992 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5993 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5994 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5995 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5997 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5998 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5999 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6000 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6001 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6002 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6003 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6004 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6005 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6006 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6007 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6008 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6009 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6010 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6011 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6012 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6013 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6014 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6015 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6016 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6017 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6018 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6019 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6020 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6021 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6022 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6023 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6024 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6025 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6026 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6027 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6028 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6029 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6030 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6031 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6032 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6033 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6034 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6035 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6036 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6037 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6038 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6039 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6040 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6041 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6042 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6043 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6045 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6046 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6047 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6048 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6049 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6050 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6051 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6052 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6053 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6055 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6056 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6057 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6058 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6059 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6060 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6061 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6062 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6063 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6064 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6065 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6066 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6067 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6068 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6069 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6070 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6072 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6073 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6074 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6075 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6078 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6079 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6080 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6081 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6082 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6084 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6085 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6086 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6087 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6089 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6090 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6091 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6092 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6093 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6094 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6095 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6096 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6097 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6098 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6099 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6100 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6101 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6102 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6103 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6104 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6105 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6106 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6107 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6108 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6109 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6110 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6111 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6112 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6114 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6115 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6116 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6117 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6118 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6119 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6120 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6121 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6122 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6123 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6124 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6125 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6126 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6127 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6128 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6129 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6130 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6131 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6132 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6133 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6134 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6135 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6136 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6137 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6138 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6139 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6140 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6141 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6142 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6143 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6144 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6145 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6146 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6147 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6148 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6149 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6150 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6151 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6154 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6155 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6156 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6157 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6158 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6159 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6160 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6161 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6162 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6163 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6164 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6165 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6166 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6167 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6168 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6169 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6170 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6171 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6172 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6173 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6174 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6176 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6177 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6179 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6180 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6181 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6182 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6183 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6184 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6185 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6186 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6187 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6188 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6190 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6191 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6192 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6193 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6194 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6195 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6196 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6197 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6198 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6199 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6200 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6201 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6202 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6203 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6204 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6205 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6206 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6207 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6208 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6209 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6210 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6211 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6212 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6213 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6214 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6215 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6216 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6217 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6218 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6219 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6220 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6221 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6222 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6223 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6224 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6225 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6226 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6227 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6228 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6229 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6230 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6231 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6232 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6233 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6234 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6235 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6236 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6238 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6239 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6240 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6241 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6242 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6243 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6244 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6245 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6246 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6248 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6249 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6250 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6251 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6252 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6253 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6254 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6255 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6256 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6257 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6258 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6259 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6260 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6261 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6262 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6263 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6265 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6266 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6267 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6268 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6270 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6271 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6272 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6273 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6274 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6275 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6277 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6278 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6279 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6280 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6282 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6283 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6284 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6285 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6286 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6287 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6288 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6289 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6290 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6291 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6292 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6293 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6294 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6295 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6296 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6297 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6298 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6299 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6300 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6301 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6302 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6303 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6304 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6305 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6306 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6307 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6308 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6309 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6310 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6311 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6312 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6313 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6314 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6315 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6316 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6317 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6318 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6319 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6320 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6321 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6322 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6323 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6324 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6325 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6326 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6327 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6328 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6329 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6330 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6331 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6332 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6333 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6334 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6335 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6336 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6337 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6338 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6339 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6340 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6341 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6342 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6343 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6344 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6347 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6348 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6349 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6350 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6351 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6352 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6353 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6354 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6355 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6356 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6357 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6358 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6359 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6360 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6361 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6362 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6363 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6364 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6365 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6366 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6367 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6369 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6370 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6372 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6373 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6374 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6375 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6376 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6377 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6378 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6379 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6380 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6381 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6383 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6384 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6385 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6386 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6387 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6388 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6389 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6390 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6391 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6392 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6393 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6394 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6395 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6396 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6397 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6398 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6399 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6400 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6401 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6402 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6403 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6404 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6405 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6406 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6407 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6408 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6409 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6410 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6411 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6412 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6413 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6414 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6415 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6416 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6417 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6418 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6419 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6420 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6421 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6422 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6423 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6424 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6425 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6426 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6427 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6428 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6429 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6431 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6432 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6433 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6434 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6435 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6436 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6437 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6438 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6439 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6441 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6442 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6443 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6444 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6445 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6446 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6447 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6448 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6449 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6450 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6451 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6452 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6453 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6454 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6455 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6456 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6458 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6459 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6460 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6461 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6463 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6464 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6465 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6467 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6468 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6470 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6471 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6472 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6473 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6475 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6476 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6477 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6478 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6479 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6480 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6481 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6482 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6483 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6484 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6485 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6486 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6487 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6488 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6489 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6490 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6491 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6492 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6493 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6494 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6495 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6496 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6497 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6498 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6499 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6500 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6501 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6502 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6503 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6504 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6505 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6506 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6507 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6508 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6509 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6510 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6511 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6512 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6513 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6514 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6515 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6516 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6517 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6518 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6519 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6520 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6521 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6522 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6523 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6524 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6525 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6526 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6527 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6528 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6529 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6530 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6531 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6532 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6533 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6534 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6535 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6536 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6537 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},