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 bool dump
= (r600_ctx
->screen
->debug_flags
& DBG_CS
) != 0;
276 r600_llvm_compile(mod
, &bytes
, &byte_count
, r600_ctx
->family
, dump
);
277 shader_ctx
.bc
= bytecode
;
278 r600_bytecode_init(shader_ctx
.bc
, r600_ctx
->chip_class
, r600_ctx
->family
,
279 r600_ctx
->screen
->msaa_texture_support
);
280 shader_ctx
.bc
->type
= TGSI_PROCESSOR_COMPUTE
;
281 shader_ctx
.bc
->isa
= r600_ctx
->isa
;
282 r600_bytecode_from_byte_stream(&shader_ctx
, bytes
, byte_count
);
283 if (shader_ctx
.bc
->chip_class
== CAYMAN
) {
284 cm_bytecode_add_cf_end(shader_ctx
.bc
);
286 r600_bytecode_build(shader_ctx
.bc
);
288 r600_bytecode_disasm(shader_ctx
.bc
);
294 #endif /* HAVE_OPENCL */
296 static uint32_t i32_from_byte_stream(unsigned char * bytes
,
297 unsigned * bytes_read
)
301 for (i
= 0; i
< 4; i
++) {
302 out
|= bytes
[(*bytes_read
)++] << (8 * i
);
307 static unsigned r600_src_from_byte_stream(unsigned char * bytes
,
308 unsigned bytes_read
, struct r600_bytecode_alu
* alu
, unsigned src_idx
)
312 sel0
= bytes
[bytes_read
++];
313 sel1
= bytes
[bytes_read
++];
314 alu
->src
[src_idx
].sel
= sel0
| (sel1
<< 8);
315 alu
->src
[src_idx
].chan
= bytes
[bytes_read
++];
316 alu
->src
[src_idx
].neg
= bytes
[bytes_read
++];
317 alu
->src
[src_idx
].abs
= bytes
[bytes_read
++];
318 alu
->src
[src_idx
].rel
= bytes
[bytes_read
++];
319 alu
->src
[src_idx
].kc_bank
= bytes
[bytes_read
++];
320 for (i
= 0; i
< 4; i
++) {
321 alu
->src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
326 static unsigned r600_alu_from_byte_stream(struct r600_shader_ctx
*ctx
,
327 unsigned char * bytes
, unsigned bytes_read
)
329 unsigned src_idx
, src_num
;
330 struct r600_bytecode_alu alu
;
331 unsigned src_use_sel
[3];
332 const struct alu_op_info
*alu_op
;
333 unsigned src_sel
[3] = {};
334 uint32_t word0
, word1
;
336 src_num
= bytes
[bytes_read
++];
338 memset(&alu
, 0, sizeof(alu
));
339 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
341 src_use_sel
[src_idx
] = bytes
[bytes_read
++];
342 for (i
= 0; i
< 4; i
++) {
343 src_sel
[src_idx
] |= bytes
[bytes_read
++] << (i
* 8);
345 for (i
= 0; i
< 4; i
++) {
346 alu
.src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
350 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
351 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
353 switch(ctx
->bc
->chip_class
) {
356 r600_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
361 r700_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
365 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
366 if (src_use_sel
[src_idx
]) {
367 unsigned sel
= src_sel
[src_idx
];
369 alu
.src
[src_idx
].chan
= sel
& 3;
372 if (sel
>=512) { /* constant */
374 alu
.src
[src_idx
].kc_bank
= sel
>> 12;
375 alu
.src
[src_idx
].sel
= (sel
& 4095) + 512;
378 alu
.src
[src_idx
].sel
= sel
;
383 alu_op
= r600_isa_alu(alu
.op
);
385 #if HAVE_LLVM < 0x0302
386 if ((alu_op
->flags
& AF_PRED
) && alu_op
->src_count
== 2) {
389 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
395 if (alu_op
->flags
& AF_MOVA
) {
396 ctx
->bc
->ar_reg
= alu
.src
[0].sel
;
397 ctx
->bc
->ar_chan
= alu
.src
[0].chan
;
398 ctx
->bc
->ar_loaded
= 0;
402 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, ctx
->bc
->cf_last
->op
);
404 /* XXX: Handle other KILL instructions */
405 if (alu_op
->flags
& AF_KILL
) {
406 ctx
->shader
->uses_kill
= 1;
407 /* XXX: This should be enforced in the LLVM backend. */
408 ctx
->bc
->force_add_cf
= 1;
413 static void llvm_if(struct r600_shader_ctx
*ctx
)
415 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
416 fc_pushlevel(ctx
, FC_IF
);
417 callstack_push(ctx
, FC_PUSH_VPM
);
420 static void r600_break_from_byte_stream(struct r600_shader_ctx
*ctx
)
422 unsigned opcode
= TGSI_OPCODE_BRK
;
423 if (ctx
->bc
->chip_class
== CAYMAN
)
424 ctx
->inst_info
= &cm_shader_tgsi_instruction
[opcode
];
425 else if (ctx
->bc
->chip_class
>= EVERGREEN
)
426 ctx
->inst_info
= &eg_shader_tgsi_instruction
[opcode
];
428 ctx
->inst_info
= &r600_shader_tgsi_instruction
[opcode
];
430 tgsi_loop_brk_cont(ctx
);
434 static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx
*ctx
,
435 unsigned char * bytes
, unsigned bytes_read
)
437 struct r600_bytecode_alu alu
;
439 memset(&alu
, 0, sizeof(alu
));
440 bytes_read
= r600_src_from_byte_stream(bytes
, bytes_read
, &alu
, 0);
441 inst
= bytes
[bytes_read
++];
443 case 0: /* IF_PREDICATED */
452 case 3: /* BGNLOOP */
455 case 4: /* ENDLOOP */
458 case 5: /* PREDICATED_BREAK */
459 r600_break_from_byte_stream(ctx
);
461 case 6: /* CONTINUE */
463 unsigned opcode
= TGSI_OPCODE_CONT
;
464 if (ctx
->bc
->chip_class
== CAYMAN
) {
466 &cm_shader_tgsi_instruction
[opcode
];
467 } else if (ctx
->bc
->chip_class
>= EVERGREEN
) {
469 &eg_shader_tgsi_instruction
[opcode
];
472 &r600_shader_tgsi_instruction
[opcode
];
474 tgsi_loop_brk_cont(ctx
);
482 static unsigned r600_tex_from_byte_stream(struct r600_shader_ctx
*ctx
,
483 unsigned char * bytes
, unsigned bytes_read
)
485 struct r600_bytecode_tex tex
;
487 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
488 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
489 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
491 tex
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
, G_SQ_TEX_WORD0_TEX_INST(word0
));
492 tex
.resource_id
= G_SQ_TEX_WORD0_RESOURCE_ID(word0
);
493 tex
.src_gpr
= G_SQ_TEX_WORD0_SRC_GPR(word0
);
494 tex
.src_rel
= G_SQ_TEX_WORD0_SRC_REL(word0
);
495 tex
.dst_gpr
= G_SQ_TEX_WORD1_DST_GPR(word1
);
496 tex
.dst_rel
= G_SQ_TEX_WORD1_DST_REL(word1
);
497 tex
.dst_sel_x
= G_SQ_TEX_WORD1_DST_SEL_X(word1
);
498 tex
.dst_sel_y
= G_SQ_TEX_WORD1_DST_SEL_Y(word1
);
499 tex
.dst_sel_z
= G_SQ_TEX_WORD1_DST_SEL_Z(word1
);
500 tex
.dst_sel_w
= G_SQ_TEX_WORD1_DST_SEL_W(word1
);
501 tex
.lod_bias
= G_SQ_TEX_WORD1_LOD_BIAS(word1
);
502 tex
.coord_type_x
= G_SQ_TEX_WORD1_COORD_TYPE_X(word1
);
503 tex
.coord_type_y
= G_SQ_TEX_WORD1_COORD_TYPE_Y(word1
);
504 tex
.coord_type_z
= G_SQ_TEX_WORD1_COORD_TYPE_Z(word1
);
505 tex
.coord_type_w
= G_SQ_TEX_WORD1_COORD_TYPE_W(word1
);
506 tex
.offset_x
= G_SQ_TEX_WORD2_OFFSET_X(word2
);
507 tex
.offset_y
= G_SQ_TEX_WORD2_OFFSET_Y(word2
);
508 tex
.offset_z
= G_SQ_TEX_WORD2_OFFSET_Z(word2
);
509 tex
.sampler_id
= G_SQ_TEX_WORD2_SAMPLER_ID(word2
);
510 tex
.src_sel_x
= G_SQ_TEX_WORD2_SRC_SEL_X(word2
);
511 tex
.src_sel_y
= G_SQ_TEX_WORD2_SRC_SEL_Y(word2
);
512 tex
.src_sel_z
= G_SQ_TEX_WORD2_SRC_SEL_Z(word2
);
513 tex
.src_sel_w
= G_SQ_TEX_WORD2_SRC_SEL_W(word2
);
520 r600_bytecode_add_tex(ctx
->bc
, &tex
);
525 static int r600_vtx_from_byte_stream(struct r600_shader_ctx
*ctx
,
526 unsigned char * bytes
, unsigned bytes_read
)
528 struct r600_bytecode_vtx vtx
;
530 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
531 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
532 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
534 memset(&vtx
, 0, sizeof(vtx
));
537 vtx
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
,
538 G_SQ_VTX_WORD0_VTX_INST(word0
));
539 vtx
.fetch_type
= G_SQ_VTX_WORD0_FETCH_TYPE(word0
);
540 vtx
.buffer_id
= G_SQ_VTX_WORD0_BUFFER_ID(word0
);
541 vtx
.src_gpr
= G_SQ_VTX_WORD0_SRC_GPR(word0
);
542 vtx
.src_sel_x
= G_SQ_VTX_WORD0_SRC_SEL_X(word0
);
543 vtx
.mega_fetch_count
= G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(word0
);
546 vtx
.dst_gpr
= G_SQ_VTX_WORD1_GPR_DST_GPR(word1
);
547 vtx
.dst_sel_x
= G_SQ_VTX_WORD1_DST_SEL_X(word1
);
548 vtx
.dst_sel_y
= G_SQ_VTX_WORD1_DST_SEL_Y(word1
);
549 vtx
.dst_sel_z
= G_SQ_VTX_WORD1_DST_SEL_Z(word1
);
550 vtx
.dst_sel_w
= G_SQ_VTX_WORD1_DST_SEL_W(word1
);
551 vtx
.use_const_fields
= G_SQ_VTX_WORD1_USE_CONST_FIELDS(word1
);
552 vtx
.data_format
= G_SQ_VTX_WORD1_DATA_FORMAT(word1
);
553 vtx
.num_format_all
= G_SQ_VTX_WORD1_NUM_FORMAT_ALL(word1
);
554 vtx
.format_comp_all
= G_SQ_VTX_WORD1_FORMAT_COMP_ALL(word1
);
555 vtx
.srf_mode_all
= G_SQ_VTX_WORD1_SRF_MODE_ALL(word1
);
558 vtx
.offset
= G_SQ_VTX_WORD2_OFFSET(word2
);
559 vtx
.endian
= G_SQ_VTX_WORD2_ENDIAN_SWAP(word2
);
561 if (r600_bytecode_add_vtx(ctx
->bc
, &vtx
)) {
562 fprintf(stderr
, "Error adding vtx\n");
565 /* Use the Texture Cache for compute shaders*/
566 if (ctx
->bc
->chip_class
>= EVERGREEN
&&
567 ctx
->bc
->type
== TGSI_PROCESSOR_COMPUTE
) {
568 ctx
->bc
->cf_last
->op
= CF_OP_TEX
;
573 static int r600_export_from_byte_stream(struct r600_shader_ctx
*ctx
,
574 unsigned char * bytes
, unsigned bytes_read
)
576 uint32_t word0
= 0, word1
= 0;
577 struct r600_bytecode_output output
;
578 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
579 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
580 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
581 if (ctx
->bc
->chip_class
>= EVERGREEN
)
582 eg_bytecode_export_read(ctx
->bc
, &output
, word0
,word1
);
584 r600_bytecode_export_read(ctx
->bc
, &output
, word0
,word1
);
585 r600_bytecode_add_output(ctx
->bc
, &output
);
589 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
590 unsigned char * bytes
, unsigned num_bytes
)
592 unsigned bytes_read
= 0;
593 ctx
->bc
->nstack
= bytes
[bytes_read
++];
595 while (bytes_read
< num_bytes
) {
596 char inst_type
= bytes
[bytes_read
++];
599 bytes_read
= r600_alu_from_byte_stream(ctx
, bytes
,
603 bytes_read
= r600_tex_from_byte_stream(ctx
, bytes
,
607 bytes_read
= r600_fc_from_byte_stream(ctx
, bytes
,
611 r600_bytecode_add_cfinst(ctx
->bc
, CF_NATIVE
);
612 for (i
= 0; i
< 2; i
++) {
613 for (byte
= 0 ; byte
< 4; byte
++) {
614 ctx
->bc
->cf_last
->isa
[i
] |=
615 (bytes
[bytes_read
++] << (byte
* 8));
621 bytes_read
= r600_vtx_from_byte_stream(ctx
, bytes
,
625 bytes_read
= r600_export_from_byte_stream(ctx
, bytes
,
629 int32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
630 int32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
632 r600_bytecode_add_cf(ctx
->bc
);
633 ctx
->bc
->cf_last
->op
= r600_isa_cf_by_opcode(ctx
->bc
->isa
, G_SQ_CF_ALU_WORD1_CF_INST(word1
), 1);
634 ctx
->bc
->cf_last
->kcache
[0].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK0(word0
);
635 ctx
->bc
->cf_last
->kcache
[0].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(word1
);
636 ctx
->bc
->cf_last
->kcache
[0].mode
= G_SQ_CF_ALU_WORD0_KCACHE_MODE0(word0
);
637 ctx
->bc
->cf_last
->kcache
[1].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK1(word0
);
638 ctx
->bc
->cf_last
->kcache
[1].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(word1
);
639 ctx
->bc
->cf_last
->kcache
[1].mode
= G_SQ_CF_ALU_WORD1_KCACHE_MODE1(word1
);
643 /* XXX: Error here */
649 /* End bytestream -> r600 shader functions*/
651 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
653 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
656 if (i
->Instruction
.NumDstRegs
> 1) {
657 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
660 if (i
->Instruction
.Predicate
) {
661 R600_ERR("predicate unsupported\n");
665 if (i
->Instruction
.Label
) {
666 R600_ERR("label unsupported\n");
670 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
671 if (i
->Src
[j
].Register
.Dimension
) {
672 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
673 R600_ERR("unsupported src %d (dimension %d)\n", j
,
674 i
->Src
[j
].Register
.Dimension
);
679 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
680 if (i
->Dst
[j
].Register
.Dimension
) {
681 R600_ERR("unsupported dst (dimension)\n");
688 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
693 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
694 if (ctx
->shader
->input
[input
].centroid
)
696 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
697 /* if we have perspective add one */
698 if (ctx
->input_perspective
) {
700 /* if we have perspective centroid */
701 if (ctx
->input_centroid
)
704 if (ctx
->shader
->input
[input
].centroid
)
708 ctx
->shader
->input
[input
].ij_index
= ij_index
;
711 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
714 struct r600_bytecode_alu alu
;
715 int gpr
= 0, base_chan
= 0;
716 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
718 /* work out gpr and base_chan from index */
720 base_chan
= (2 * (ij_index
% 2)) + 1;
722 for (i
= 0; i
< 8; i
++) {
723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
726 alu
.op
= ALU_OP2_INTERP_ZW
;
728 alu
.op
= ALU_OP2_INTERP_XY
;
730 if ((i
> 1) && (i
< 6)) {
731 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
735 alu
.dst
.chan
= i
% 4;
737 alu
.src
[0].sel
= gpr
;
738 alu
.src
[0].chan
= (base_chan
- (i
% 2));
740 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
742 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
745 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
752 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
755 struct r600_bytecode_alu alu
;
757 for (i
= 0; i
< 4; i
++) {
758 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
760 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
762 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
767 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
772 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
780 * Special export handling in shaders
782 * shader export ARRAY_BASE for EXPORT_POS:
785 * 62, 63 are clip distance vectors
787 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
788 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
789 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
790 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
791 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
792 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
793 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
794 * exclusive from render target index)
795 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
798 * shader export ARRAY_BASE for EXPORT_PIXEL:
800 * 61 computed Z vector
802 * The use of the values exported in the computed Z vector are controlled
803 * by DB_SHADER_CONTROL:
804 * Z_EXPORT_ENABLE - Z as a float in RED
805 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
806 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
807 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
808 * DB_SOURCE_FORMAT - export control restrictions
813 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
814 static int r600_spi_sid(struct r600_shader_io
* io
)
816 int index
, name
= io
->name
;
818 /* These params are handled differently, they don't need
819 * semantic indices, so we'll use 0 for them.
821 if (name
== TGSI_SEMANTIC_POSITION
||
822 name
== TGSI_SEMANTIC_PSIZE
||
823 name
== TGSI_SEMANTIC_FACE
)
826 if (name
== TGSI_SEMANTIC_GENERIC
) {
827 /* For generic params simply use sid from tgsi */
830 /* For non-generic params - pack name and sid into 8 bits */
831 index
= 0x80 | (name
<<3) | (io
->sid
);
834 /* Make sure that all really used indices have nonzero value, so
835 * we can just compare it to 0 later instead of comparing the name
836 * with different values to detect special cases. */
843 /* turn input into interpolate on EG */
844 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
848 if (ctx
->shader
->input
[index
].spi_sid
) {
849 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
850 if (ctx
->shader
->input
[index
].interpolate
> 0) {
851 evergreen_interp_assign_ij_index(ctx
, index
);
853 r
= evergreen_interp_alu(ctx
, index
);
856 r
= evergreen_interp_flat(ctx
, index
);
862 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
864 struct r600_bytecode_alu alu
;
866 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
867 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
869 for (i
= 0; i
< 4; i
++) {
870 memset(&alu
, 0, sizeof(alu
));
871 alu
.op
= ALU_OP3_CNDGT
;
874 alu
.dst
.sel
= gpr_front
;
875 alu
.src
[0].sel
= ctx
->face_gpr
;
876 alu
.src
[1].sel
= gpr_front
;
877 alu
.src
[2].sel
= gpr_back
;
884 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
891 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
893 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
894 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
896 switch (d
->Declaration
.File
) {
897 case TGSI_FILE_INPUT
:
898 i
= ctx
->shader
->ninput
;
899 ctx
->shader
->ninput
+= count
;
900 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
901 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
902 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
903 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
904 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
905 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
906 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
907 switch (ctx
->shader
->input
[i
].name
) {
908 case TGSI_SEMANTIC_FACE
:
909 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
911 case TGSI_SEMANTIC_COLOR
:
914 case TGSI_SEMANTIC_POSITION
:
915 ctx
->fragcoord_input
= i
;
918 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
919 if ((r
= evergreen_interp_input(ctx
, i
)))
923 for (j
= 1; j
< count
; ++j
) {
924 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
925 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
928 case TGSI_FILE_OUTPUT
:
929 i
= ctx
->shader
->noutput
++;
930 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
931 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
932 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
933 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
934 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
935 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
936 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
937 switch (d
->Semantic
.Name
) {
938 case TGSI_SEMANTIC_CLIPDIST
:
939 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
941 case TGSI_SEMANTIC_PSIZE
:
942 ctx
->shader
->vs_out_misc_write
= 1;
943 ctx
->shader
->vs_out_point_size
= 1;
945 case TGSI_SEMANTIC_CLIPVERTEX
:
946 ctx
->clip_vertex_write
= TRUE
;
950 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
951 switch (d
->Semantic
.Name
) {
952 case TGSI_SEMANTIC_COLOR
:
953 ctx
->shader
->nr_ps_max_color_exports
++;
958 case TGSI_FILE_CONSTANT
:
959 case TGSI_FILE_TEMPORARY
:
960 case TGSI_FILE_SAMPLER
:
961 case TGSI_FILE_ADDRESS
:
964 case TGSI_FILE_SYSTEM_VALUE
:
965 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
966 if (!ctx
->native_integers
) {
967 struct r600_bytecode_alu alu
;
968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
970 alu
.op
= ALU_OP1_INT_TO_FLT
;
979 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
983 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
986 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
992 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
994 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
998 * for evergreen we need to scan the shader to find the number of GPRs we need to
999 * reserve for interpolation.
1001 * we need to know if we are going to emit
1002 * any centroid inputs
1003 * if perspective and linear are required
1005 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1010 ctx
->input_linear
= FALSE
;
1011 ctx
->input_perspective
= FALSE
;
1012 ctx
->input_centroid
= FALSE
;
1013 ctx
->num_interp_gpr
= 1;
1015 /* any centroid inputs */
1016 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1017 /* skip position/face */
1018 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1019 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
1021 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
1022 ctx
->input_linear
= TRUE
;
1023 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
1024 ctx
->input_perspective
= TRUE
;
1025 if (ctx
->info
.input_centroid
[i
])
1026 ctx
->input_centroid
= TRUE
;
1030 /* ignoring sample for now */
1031 if (ctx
->input_perspective
)
1033 if (ctx
->input_linear
)
1035 if (ctx
->input_centroid
)
1038 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
1040 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
1041 return ctx
->num_interp_gpr
;
1044 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1045 const struct tgsi_full_src_register
*tgsi_src
,
1046 struct r600_shader_src
*r600_src
)
1048 memset(r600_src
, 0, sizeof(*r600_src
));
1049 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1050 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1051 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1052 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1053 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1054 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1056 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1058 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1059 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1060 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1062 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1063 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
1064 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1067 index
= tgsi_src
->Register
.Index
;
1068 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1069 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1070 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1071 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1072 r600_src
->swizzle
[0] = 3;
1073 r600_src
->swizzle
[1] = 3;
1074 r600_src
->swizzle
[2] = 3;
1075 r600_src
->swizzle
[3] = 3;
1077 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1078 r600_src
->swizzle
[0] = 0;
1079 r600_src
->swizzle
[1] = 0;
1080 r600_src
->swizzle
[2] = 0;
1081 r600_src
->swizzle
[3] = 0;
1085 if (tgsi_src
->Register
.Indirect
)
1086 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1087 r600_src
->sel
= tgsi_src
->Register
.Index
;
1088 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1090 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1091 if (tgsi_src
->Register
.Dimension
) {
1092 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1097 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
1099 struct r600_bytecode_vtx vtx
;
1100 unsigned int ar_reg
;
1104 struct r600_bytecode_alu alu
;
1106 memset(&alu
, 0, sizeof(alu
));
1108 alu
.op
= ALU_OP2_ADD_INT
;
1109 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1111 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1112 alu
.src
[1].value
= offset
;
1114 alu
.dst
.sel
= dst_reg
;
1118 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1123 ar_reg
= ctx
->bc
->ar_reg
;
1126 memset(&vtx
, 0, sizeof(vtx
));
1127 vtx
.buffer_id
= cb_idx
;
1128 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
1129 vtx
.src_gpr
= ar_reg
;
1130 vtx
.mega_fetch_count
= 16;
1131 vtx
.dst_gpr
= dst_reg
;
1132 vtx
.dst_sel_x
= 0; /* SEL_X */
1133 vtx
.dst_sel_y
= 1; /* SEL_Y */
1134 vtx
.dst_sel_z
= 2; /* SEL_Z */
1135 vtx
.dst_sel_w
= 3; /* SEL_W */
1136 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1137 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1138 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1139 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1140 vtx
.endian
= r600_endian_swap(32);
1142 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1148 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1150 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1151 struct r600_bytecode_alu alu
;
1152 int i
, j
, k
, nconst
, r
;
1154 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1155 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1158 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1160 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1161 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1165 if (ctx
->src
[i
].rel
) {
1166 int treg
= r600_get_temp(ctx
);
1167 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
1170 ctx
->src
[i
].kc_bank
= 0;
1171 ctx
->src
[i
].sel
= treg
;
1172 ctx
->src
[i
].rel
= 0;
1175 int treg
= r600_get_temp(ctx
);
1176 for (k
= 0; k
< 4; k
++) {
1177 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1178 alu
.op
= ALU_OP1_MOV
;
1179 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1180 alu
.src
[0].chan
= k
;
1181 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1187 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1191 ctx
->src
[i
].sel
= treg
;
1199 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1200 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1202 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1203 struct r600_bytecode_alu alu
;
1204 int i
, j
, k
, nliteral
, r
;
1206 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1207 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1211 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1212 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1213 int treg
= r600_get_temp(ctx
);
1214 for (k
= 0; k
< 4; k
++) {
1215 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1216 alu
.op
= ALU_OP1_MOV
;
1217 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1218 alu
.src
[0].chan
= k
;
1219 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1229 ctx
->src
[i
].sel
= treg
;
1236 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1238 int i
, r
, count
= ctx
->shader
->ninput
;
1240 for (i
= 0; i
< count
; i
++) {
1241 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1242 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1250 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
1251 struct r600_pipe_shader
*pipeshader
,
1252 struct r600_shader_key key
)
1254 struct r600_shader
*shader
= &pipeshader
->shader
;
1255 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1256 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1257 struct tgsi_full_immediate
*immediate
;
1258 struct tgsi_full_property
*property
;
1259 struct r600_shader_ctx ctx
;
1260 struct r600_bytecode_output output
[32];
1261 unsigned output_done
, noutput
;
1264 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
1265 /* Declarations used by llvm code */
1266 bool use_llvm
= false;
1267 unsigned char * inst_bytes
= NULL
;
1268 unsigned inst_byte_count
= 0;
1270 #ifdef R600_USE_LLVM
1271 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
1273 ctx
.bc
= &shader
->bc
;
1274 ctx
.shader
= shader
;
1275 ctx
.native_integers
= true;
1277 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
1278 rscreen
->msaa_texture_support
);
1279 ctx
.tokens
= tokens
;
1280 tgsi_scan_shader(tokens
, &ctx
.info
);
1281 tgsi_parse_init(&ctx
.parse
, tokens
);
1282 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1283 shader
->processor_type
= ctx
.type
;
1284 ctx
.bc
->type
= shader
->processor_type
;
1287 ctx
.fragcoord_input
= -1;
1288 ctx
.colors_used
= 0;
1289 ctx
.clip_vertex_write
= 0;
1291 shader
->nr_ps_color_exports
= 0;
1292 shader
->nr_ps_max_color_exports
= 0;
1294 shader
->two_side
= key
.color_two_side
;
1296 /* register allocations */
1297 /* Values [0,127] correspond to GPR[0..127].
1298 * Values [128,159] correspond to constant buffer bank 0
1299 * Values [160,191] correspond to constant buffer bank 1
1300 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1301 * Values [256,287] correspond to constant buffer bank 2 (EG)
1302 * Values [288,319] correspond to constant buffer bank 3 (EG)
1303 * Other special values are shown in the list below.
1304 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1305 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1306 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1307 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1308 * 248 SQ_ALU_SRC_0: special constant 0.0.
1309 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1310 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1311 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1312 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1313 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1314 * 254 SQ_ALU_SRC_PV: previous vector result.
1315 * 255 SQ_ALU_SRC_PS: previous scalar result.
1317 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1318 ctx
.file_offset
[i
] = 0;
1320 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1321 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1322 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1324 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1325 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1328 #ifdef R600_USE_LLVM
1329 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1330 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1331 "indirect adressing. Falling back to TGSI "
1336 ctx
.use_llvm
= use_llvm
;
1339 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1340 ctx
.file_offset
[TGSI_FILE_INPUT
];
1342 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1343 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1344 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1346 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1347 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1349 /* Outside the GPR range. This will be translated to one of the
1350 * kcache banks later. */
1351 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1353 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1354 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1355 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1356 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1359 ctx
.literals
= NULL
;
1360 shader
->fs_write_all
= FALSE
;
1361 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1362 tgsi_parse_token(&ctx
.parse
);
1363 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1364 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1365 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1366 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1367 if(ctx
.literals
== NULL
) {
1371 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1372 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1373 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1374 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1377 case TGSI_TOKEN_TYPE_DECLARATION
:
1378 r
= tgsi_declaration(&ctx
);
1382 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1384 case TGSI_TOKEN_TYPE_PROPERTY
:
1385 property
= &ctx
.parse
.FullToken
.FullProperty
;
1386 switch (property
->Property
.PropertyName
) {
1387 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1388 if (property
->u
[0].Data
== 1)
1389 shader
->fs_write_all
= TRUE
;
1391 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1392 /* we don't need this one */
1397 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1403 /* Process two side if needed */
1404 if (shader
->two_side
&& ctx
.colors_used
) {
1405 int i
, count
= ctx
.shader
->ninput
;
1406 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1408 /* additional inputs will be allocated right after the existing inputs,
1409 * we won't need them after the color selection, so we don't need to
1410 * reserve these gprs for the rest of the shader code and to adjust
1411 * output offsets etc. */
1412 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1413 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1415 if (ctx
.face_gpr
== -1) {
1416 i
= ctx
.shader
->ninput
++;
1417 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1418 ctx
.shader
->input
[i
].spi_sid
= 0;
1419 ctx
.shader
->input
[i
].gpr
= gpr
++;
1420 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1423 for (i
= 0; i
< count
; i
++) {
1424 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1425 int ni
= ctx
.shader
->ninput
++;
1426 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1427 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1428 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1429 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1430 // TGSI to LLVM needs to know the lds position of inputs.
1431 // Non LLVM path computes it later (in process_twoside_color)
1432 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1433 ctx
.shader
->input
[i
].back_color_input
= ni
;
1434 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1435 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1442 /* LLVM backend setup */
1443 #ifdef R600_USE_LLVM
1445 struct radeon_llvm_context radeon_llvm_ctx
;
1447 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1449 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1450 radeon_llvm_ctx
.type
= ctx
.type
;
1451 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1452 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1453 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1454 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1455 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1456 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1457 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1458 radeon_llvm_ctx
.stream_outputs
= &so
;
1459 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1460 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1461 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1463 if (r600_llvm_compile(mod
, &inst_bytes
, &inst_byte_count
,
1464 rscreen
->family
, dump
)) {
1466 radeon_llvm_dispose(&radeon_llvm_ctx
);
1468 fprintf(stderr
, "R600 LLVM backend failed to compile "
1469 "shader. Falling back to TGSI\n");
1471 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1472 ctx
.file_offset
[TGSI_FILE_INPUT
];
1474 radeon_llvm_dispose(&radeon_llvm_ctx
);
1477 /* End of LLVM backend setup */
1479 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1480 shader
->nr_ps_max_color_exports
= 8;
1483 if (ctx
.fragcoord_input
>= 0) {
1484 if (ctx
.bc
->chip_class
== CAYMAN
) {
1485 for (j
= 0 ; j
< 4; j
++) {
1486 struct r600_bytecode_alu alu
;
1487 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1488 alu
.op
= ALU_OP1_RECIP_IEEE
;
1489 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1490 alu
.src
[0].chan
= 3;
1492 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1494 alu
.dst
.write
= (j
== 3);
1496 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1500 struct r600_bytecode_alu alu
;
1501 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1502 alu
.op
= ALU_OP1_RECIP_IEEE
;
1503 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1504 alu
.src
[0].chan
= 3;
1506 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1510 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1515 if (shader
->two_side
&& ctx
.colors_used
) {
1516 if ((r
= process_twoside_color_inputs(&ctx
)))
1520 tgsi_parse_init(&ctx
.parse
, tokens
);
1521 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1522 tgsi_parse_token(&ctx
.parse
);
1523 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1524 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1525 r
= tgsi_is_supported(&ctx
);
1528 ctx
.max_driver_temp_used
= 0;
1529 /* reserve first tmp for everyone */
1530 r600_get_temp(&ctx
);
1532 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1533 if ((r
= tgsi_split_constant(&ctx
)))
1535 if ((r
= tgsi_split_literal_constant(&ctx
)))
1537 if (ctx
.bc
->chip_class
== CAYMAN
)
1538 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1539 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1540 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1542 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1543 r
= ctx
.inst_info
->process(&ctx
);
1553 /* Reset the temporary register counter. */
1554 ctx
.max_driver_temp_used
= 0;
1556 /* Get instructions if we are using the LLVM backend. */
1558 r600_bytecode_from_byte_stream(&ctx
, inst_bytes
, inst_byte_count
);
1562 noutput
= shader
->noutput
;
1564 if (ctx
.clip_vertex_write
) {
1565 unsigned clipdist_temp
[2];
1567 clipdist_temp
[0] = r600_get_temp(&ctx
);
1568 clipdist_temp
[1] = r600_get_temp(&ctx
);
1570 /* need to convert a clipvertex write into clipdistance writes and not export
1571 the clip vertex anymore */
1573 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1574 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1575 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1577 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1578 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1581 /* reset spi_sid for clipvertex output to avoid confusing spi */
1582 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1584 shader
->clip_dist_write
= 0xFF;
1586 for (i
= 0; i
< 8; i
++) {
1590 for (j
= 0; j
< 4; j
++) {
1591 struct r600_bytecode_alu alu
;
1592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1593 alu
.op
= ALU_OP2_DOT4
;
1594 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1595 alu
.src
[0].chan
= j
;
1597 alu
.src
[1].sel
= 512 + i
;
1598 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1599 alu
.src
[1].chan
= j
;
1601 alu
.dst
.sel
= clipdist_temp
[oreg
];
1603 alu
.dst
.write
= (j
== ochan
);
1607 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1614 /* Add stream outputs. */
1615 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1616 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1618 /* Sanity checking. */
1619 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1620 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1624 for (i
= 0; i
< so
.num_outputs
; i
++) {
1625 if (so
.output
[i
].output_buffer
>= 4) {
1626 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1627 so
.output
[i
].output_buffer
);
1633 /* Initialize locations where the outputs are stored. */
1634 for (i
= 0; i
< so
.num_outputs
; i
++) {
1635 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1637 /* Lower outputs with dst_offset < start_component.
1639 * We can only output 4D vectors with a write mask, e.g. we can
1640 * only output the W component at offset 3, etc. If we want
1641 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1642 * to move it to X and output X. */
1643 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1644 unsigned tmp
= r600_get_temp(&ctx
);
1646 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1647 struct r600_bytecode_alu alu
;
1648 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1649 alu
.op
= ALU_OP1_MOV
;
1650 alu
.src
[0].sel
= so_gpr
[i
];
1651 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1656 if (j
== so
.output
[i
].num_components
- 1)
1658 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1662 so
.output
[i
].start_component
= 0;
1667 /* Write outputs to buffers. */
1668 for (i
= 0; i
< so
.num_outputs
; i
++) {
1669 struct r600_bytecode_output output
;
1671 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1672 output
.gpr
= so_gpr
[i
];
1673 output
.elem_size
= so
.output
[i
].num_components
;
1674 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1675 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1676 output
.burst_count
= 1;
1678 /* array_size is an upper limit for the burst_count
1679 * with MEM_STREAM instructions */
1680 output
.array_size
= 0xFFF;
1681 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1682 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1683 switch (so
.output
[i
].output_buffer
) {
1685 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1688 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1691 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1694 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1698 switch (so
.output
[i
].output_buffer
) {
1700 output
.op
= CF_OP_MEM_STREAM0
;
1703 output
.op
= CF_OP_MEM_STREAM1
;
1706 output
.op
= CF_OP_MEM_STREAM2
;
1709 output
.op
= CF_OP_MEM_STREAM3
;
1713 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1720 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1721 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1722 output
[j
].gpr
= shader
->output
[i
].gpr
;
1723 output
[j
].elem_size
= 3;
1724 output
[j
].swizzle_x
= 0;
1725 output
[j
].swizzle_y
= 1;
1726 output
[j
].swizzle_z
= 2;
1727 output
[j
].swizzle_w
= 3;
1728 output
[j
].burst_count
= 1;
1729 output
[j
].barrier
= 1;
1730 output
[j
].type
= -1;
1731 output
[j
].op
= CF_OP_EXPORT
;
1733 case TGSI_PROCESSOR_VERTEX
:
1734 switch (shader
->output
[i
].name
) {
1735 case TGSI_SEMANTIC_POSITION
:
1736 output
[j
].array_base
= next_pos_base
++;
1737 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1740 case TGSI_SEMANTIC_PSIZE
:
1741 output
[j
].array_base
= next_pos_base
++;
1742 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1744 case TGSI_SEMANTIC_CLIPVERTEX
:
1747 case TGSI_SEMANTIC_CLIPDIST
:
1748 output
[j
].array_base
= next_pos_base
++;
1749 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1750 /* spi_sid is 0 for clipdistance outputs that were generated
1751 * for clipvertex - we don't need to pass them to PS */
1752 if (shader
->output
[i
].spi_sid
) {
1754 /* duplicate it as PARAM to pass to the pixel shader */
1755 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1756 output
[j
].array_base
= next_param_base
++;
1757 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1760 case TGSI_SEMANTIC_FOG
:
1761 output
[j
].swizzle_y
= 4; /* 0 */
1762 output
[j
].swizzle_z
= 4; /* 0 */
1763 output
[j
].swizzle_w
= 5; /* 1 */
1767 case TGSI_PROCESSOR_FRAGMENT
:
1768 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1769 /* never export more colors than the number of CBs */
1770 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1775 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1776 output
[j
].array_base
= next_pixel_base
++;
1777 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1778 shader
->nr_ps_color_exports
++;
1779 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1780 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1782 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1783 output
[j
].gpr
= shader
->output
[i
].gpr
;
1784 output
[j
].elem_size
= 3;
1785 output
[j
].swizzle_x
= 0;
1786 output
[j
].swizzle_y
= 1;
1787 output
[j
].swizzle_z
= 2;
1788 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1789 output
[j
].burst_count
= 1;
1790 output
[j
].barrier
= 1;
1791 output
[j
].array_base
= next_pixel_base
++;
1792 output
[j
].op
= CF_OP_EXPORT
;
1793 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1794 shader
->nr_ps_color_exports
++;
1797 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1798 output
[j
].array_base
= 61;
1799 output
[j
].swizzle_x
= 2;
1800 output
[j
].swizzle_y
= 7;
1801 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1802 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1803 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1804 output
[j
].array_base
= 61;
1805 output
[j
].swizzle_x
= 7;
1806 output
[j
].swizzle_y
= 1;
1807 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1808 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1810 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1816 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1821 if (output
[j
].type
==-1) {
1822 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1823 output
[j
].array_base
= next_param_base
++;
1827 /* add fake position export */
1828 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1829 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1831 output
[j
].elem_size
= 3;
1832 output
[j
].swizzle_x
= 7;
1833 output
[j
].swizzle_y
= 7;
1834 output
[j
].swizzle_z
= 7;
1835 output
[j
].swizzle_w
= 7;
1836 output
[j
].burst_count
= 1;
1837 output
[j
].barrier
= 1;
1838 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1839 output
[j
].array_base
= next_pos_base
;
1840 output
[j
].op
= CF_OP_EXPORT
;
1844 /* add fake param output for vertex shader if no param is exported */
1845 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1846 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1848 output
[j
].elem_size
= 3;
1849 output
[j
].swizzle_x
= 7;
1850 output
[j
].swizzle_y
= 7;
1851 output
[j
].swizzle_z
= 7;
1852 output
[j
].swizzle_w
= 7;
1853 output
[j
].burst_count
= 1;
1854 output
[j
].barrier
= 1;
1855 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1856 output
[j
].array_base
= 0;
1857 output
[j
].op
= CF_OP_EXPORT
;
1861 /* add fake pixel export */
1862 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1863 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1865 output
[j
].elem_size
= 3;
1866 output
[j
].swizzle_x
= 7;
1867 output
[j
].swizzle_y
= 7;
1868 output
[j
].swizzle_z
= 7;
1869 output
[j
].swizzle_w
= 7;
1870 output
[j
].burst_count
= 1;
1871 output
[j
].barrier
= 1;
1872 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1873 output
[j
].array_base
= 0;
1874 output
[j
].op
= CF_OP_EXPORT
;
1880 /* set export done on last export of each type */
1881 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1882 if (ctx
.bc
->chip_class
< CAYMAN
) {
1883 if (i
== (noutput
- 1)) {
1884 output
[i
].end_of_program
= 1;
1887 if (!(output_done
& (1 << output
[i
].type
))) {
1888 output_done
|= (1 << output
[i
].type
);
1889 output
[i
].op
= CF_OP_EXPORT_DONE
;
1892 /* add output to bytecode */
1894 for (i
= 0; i
< noutput
; i
++) {
1895 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1900 /* add program end */
1901 if (ctx
.bc
->chip_class
== CAYMAN
)
1902 cm_bytecode_add_cf_end(ctx
.bc
);
1904 /* check GPR limit - we have 124 = 128 - 4
1905 * (4 are reserved as alu clause temporary registers) */
1906 if (ctx
.bc
->ngpr
> 124) {
1907 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1913 tgsi_parse_free(&ctx
.parse
);
1917 tgsi_parse_free(&ctx
.parse
);
1921 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1923 R600_ERR("%s tgsi opcode unsupported\n",
1924 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1928 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1933 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1934 const struct r600_shader_src
*shader_src
,
1937 bc_src
->sel
= shader_src
->sel
;
1938 bc_src
->chan
= shader_src
->swizzle
[chan
];
1939 bc_src
->neg
= shader_src
->neg
;
1940 bc_src
->abs
= shader_src
->abs
;
1941 bc_src
->rel
= shader_src
->rel
;
1942 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1943 bc_src
->kc_bank
= shader_src
->kc_bank
;
1946 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1952 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1954 bc_src
->neg
= !bc_src
->neg
;
1957 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1958 const struct tgsi_full_dst_register
*tgsi_dst
,
1960 struct r600_bytecode_alu_dst
*r600_dst
)
1962 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1964 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1965 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1966 r600_dst
->chan
= swizzle
;
1967 r600_dst
->write
= 1;
1968 if (tgsi_dst
->Register
.Indirect
)
1969 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1970 if (inst
->Instruction
.Saturate
) {
1971 r600_dst
->clamp
= 1;
1975 static int tgsi_last_instruction(unsigned writemask
)
1979 for (i
= 0; i
< 4; i
++) {
1980 if (writemask
& (1 << i
)) {
1987 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1989 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1990 struct r600_bytecode_alu alu
;
1992 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1994 for (i
= 0; i
< lasti
+ 1; i
++) {
1995 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1999 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2001 alu
.op
= ctx
->inst_info
->op
;
2003 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2004 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2007 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2008 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2010 /* handle some special cases */
2011 switch (ctx
->inst_info
->tgsi_opcode
) {
2012 case TGSI_OPCODE_SUB
:
2013 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2015 case TGSI_OPCODE_ABS
:
2016 r600_bytecode_src_set_abs(&alu
.src
[0]);
2021 if (i
== lasti
|| trans_only
) {
2024 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2031 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2033 return tgsi_op2_s(ctx
, 0, 0);
2036 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2038 return tgsi_op2_s(ctx
, 1, 0);
2041 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2043 return tgsi_op2_s(ctx
, 0, 1);
2046 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2048 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2049 struct r600_bytecode_alu alu
;
2051 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2053 for (i
= 0; i
< lasti
+ 1; i
++) {
2055 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2058 alu
.op
= ctx
->inst_info
->op
;
2060 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2062 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2064 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2077 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2079 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2081 struct r600_bytecode_alu alu
;
2082 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2084 for (i
= 0 ; i
< last_slot
; i
++) {
2085 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2086 alu
.op
= ctx
->inst_info
->op
;
2087 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2088 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2090 /* RSQ should take the absolute value of src */
2091 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2092 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2095 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2096 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2098 if (i
== last_slot
- 1)
2100 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2107 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2109 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2111 struct r600_bytecode_alu alu
;
2112 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2113 for (k
= 0; k
< last_slot
; k
++) {
2114 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2117 for (i
= 0 ; i
< 4; i
++) {
2118 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2119 alu
.op
= ctx
->inst_info
->op
;
2120 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2121 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2123 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2124 alu
.dst
.write
= (i
== k
);
2127 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2136 * r600 - trunc to -PI..PI range
2137 * r700 - normalize by dividing by 2PI
2140 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2142 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2143 static float double_pi
= 3.1415926535 * 2;
2144 static float neg_pi
= -3.1415926535;
2147 struct r600_bytecode_alu alu
;
2149 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2150 alu
.op
= ALU_OP3_MULADD
;
2154 alu
.dst
.sel
= ctx
->temp_reg
;
2157 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2159 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2160 alu
.src
[1].chan
= 0;
2161 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2162 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2163 alu
.src
[2].chan
= 0;
2165 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2169 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2170 alu
.op
= ALU_OP1_FRACT
;
2173 alu
.dst
.sel
= ctx
->temp_reg
;
2176 alu
.src
[0].sel
= ctx
->temp_reg
;
2177 alu
.src
[0].chan
= 0;
2179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2183 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2184 alu
.op
= ALU_OP3_MULADD
;
2188 alu
.dst
.sel
= ctx
->temp_reg
;
2191 alu
.src
[0].sel
= ctx
->temp_reg
;
2192 alu
.src
[0].chan
= 0;
2194 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2195 alu
.src
[1].chan
= 0;
2196 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2197 alu
.src
[2].chan
= 0;
2199 if (ctx
->bc
->chip_class
== R600
) {
2200 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2201 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2203 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2204 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2209 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2215 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2217 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2218 struct r600_bytecode_alu alu
;
2219 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2222 r
= tgsi_setup_trig(ctx
);
2227 for (i
= 0; i
< last_slot
; i
++) {
2228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2229 alu
.op
= ctx
->inst_info
->op
;
2232 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2233 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2235 alu
.src
[0].sel
= ctx
->temp_reg
;
2236 alu
.src
[0].chan
= 0;
2237 if (i
== last_slot
- 1)
2239 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2246 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2248 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2249 struct r600_bytecode_alu alu
;
2251 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2253 r
= tgsi_setup_trig(ctx
);
2257 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2258 alu
.op
= ctx
->inst_info
->op
;
2260 alu
.dst
.sel
= ctx
->temp_reg
;
2263 alu
.src
[0].sel
= ctx
->temp_reg
;
2264 alu
.src
[0].chan
= 0;
2266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2270 /* replicate result */
2271 for (i
= 0; i
< lasti
+ 1; i
++) {
2272 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2276 alu
.op
= ALU_OP1_MOV
;
2278 alu
.src
[0].sel
= ctx
->temp_reg
;
2279 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2282 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2289 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2291 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2292 struct r600_bytecode_alu alu
;
2295 /* We'll only need the trig stuff if we are going to write to the
2296 * X or Y components of the destination vector.
2298 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2299 r
= tgsi_setup_trig(ctx
);
2305 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2306 if (ctx
->bc
->chip_class
== CAYMAN
) {
2307 for (i
= 0 ; i
< 3; i
++) {
2308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2309 alu
.op
= ALU_OP1_COS
;
2310 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2316 alu
.src
[0].sel
= ctx
->temp_reg
;
2317 alu
.src
[0].chan
= 0;
2320 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2326 alu
.op
= ALU_OP1_COS
;
2327 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2329 alu
.src
[0].sel
= ctx
->temp_reg
;
2330 alu
.src
[0].chan
= 0;
2332 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2339 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2340 if (ctx
->bc
->chip_class
== CAYMAN
) {
2341 for (i
= 0 ; i
< 3; i
++) {
2342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2343 alu
.op
= ALU_OP1_SIN
;
2344 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2349 alu
.src
[0].sel
= ctx
->temp_reg
;
2350 alu
.src
[0].chan
= 0;
2353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2358 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2359 alu
.op
= ALU_OP1_SIN
;
2360 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2362 alu
.src
[0].sel
= ctx
->temp_reg
;
2363 alu
.src
[0].chan
= 0;
2365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2372 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2373 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2375 alu
.op
= ALU_OP1_MOV
;
2377 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2379 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2380 alu
.src
[0].chan
= 0;
2384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2390 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2391 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2393 alu
.op
= ALU_OP1_MOV
;
2395 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2397 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2398 alu
.src
[0].chan
= 0;
2402 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2410 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2412 struct r600_bytecode_alu alu
;
2415 for (i
= 0; i
< 4; i
++) {
2416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2417 alu
.op
= ctx
->inst_info
->op
;
2421 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2423 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2424 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2427 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2432 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2437 /* kill must be last in ALU */
2438 ctx
->bc
->force_add_cf
= 1;
2439 ctx
->shader
->uses_kill
= TRUE
;
2443 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2445 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2446 struct r600_bytecode_alu alu
;
2449 /* tmp.x = max(src.y, 0.0) */
2450 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2451 alu
.op
= ALU_OP2_MAX
;
2452 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2453 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2454 alu
.src
[1].chan
= 1;
2456 alu
.dst
.sel
= ctx
->temp_reg
;
2461 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2465 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2471 if (ctx
->bc
->chip_class
== CAYMAN
) {
2472 for (i
= 0; i
< 3; i
++) {
2473 /* tmp.z = log(tmp.x) */
2474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2475 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2476 alu
.src
[0].sel
= ctx
->temp_reg
;
2477 alu
.src
[0].chan
= 0;
2478 alu
.dst
.sel
= ctx
->temp_reg
;
2486 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2491 /* tmp.z = log(tmp.x) */
2492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2493 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2494 alu
.src
[0].sel
= ctx
->temp_reg
;
2495 alu
.src
[0].chan
= 0;
2496 alu
.dst
.sel
= ctx
->temp_reg
;
2500 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2505 chan
= alu
.dst
.chan
;
2508 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2509 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2510 alu
.op
= ALU_OP3_MUL_LIT
;
2511 alu
.src
[0].sel
= sel
;
2512 alu
.src
[0].chan
= chan
;
2513 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2514 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2515 alu
.dst
.sel
= ctx
->temp_reg
;
2520 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2524 if (ctx
->bc
->chip_class
== CAYMAN
) {
2525 for (i
= 0; i
< 3; i
++) {
2526 /* dst.z = exp(tmp.x) */
2527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2528 alu
.op
= ALU_OP1_EXP_IEEE
;
2529 alu
.src
[0].sel
= ctx
->temp_reg
;
2530 alu
.src
[0].chan
= 0;
2531 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2537 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2542 /* dst.z = exp(tmp.x) */
2543 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2544 alu
.op
= ALU_OP1_EXP_IEEE
;
2545 alu
.src
[0].sel
= ctx
->temp_reg
;
2546 alu
.src
[0].chan
= 0;
2547 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2549 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2556 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2557 alu
.op
= ALU_OP1_MOV
;
2558 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2559 alu
.src
[0].chan
= 0;
2560 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2561 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2566 /* dst.y = max(src.x, 0.0) */
2567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2568 alu
.op
= ALU_OP2_MAX
;
2569 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2570 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2571 alu
.src
[1].chan
= 0;
2572 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2573 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2574 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2580 alu
.op
= ALU_OP1_MOV
;
2581 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2582 alu
.src
[0].chan
= 0;
2583 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2584 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2586 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2593 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2595 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2596 struct r600_bytecode_alu alu
;
2599 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2602 * For state trackers other than OpenGL, we'll want to use
2603 * _RECIPSQRT_IEEE instead.
2605 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2607 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2608 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2609 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2611 alu
.dst
.sel
= ctx
->temp_reg
;
2614 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2617 /* replicate result */
2618 return tgsi_helper_tempx_replicate(ctx
);
2621 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2623 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2624 struct r600_bytecode_alu alu
;
2627 for (i
= 0; i
< 4; i
++) {
2628 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2629 alu
.src
[0].sel
= ctx
->temp_reg
;
2630 alu
.op
= ALU_OP1_MOV
;
2632 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2633 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2636 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2643 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2645 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2646 struct r600_bytecode_alu alu
;
2649 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2650 alu
.op
= ctx
->inst_info
->op
;
2651 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2652 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2654 alu
.dst
.sel
= ctx
->temp_reg
;
2657 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2660 /* replicate result */
2661 return tgsi_helper_tempx_replicate(ctx
);
2664 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2666 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2668 struct r600_bytecode_alu alu
;
2669 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2671 for (i
= 0; i
< 3; i
++) {
2672 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2673 alu
.op
= ALU_OP1_LOG_IEEE
;
2674 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2675 alu
.dst
.sel
= ctx
->temp_reg
;
2680 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2686 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2687 alu
.op
= ALU_OP2_MUL
;
2688 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2689 alu
.src
[1].sel
= ctx
->temp_reg
;
2690 alu
.dst
.sel
= ctx
->temp_reg
;
2693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2697 for (i
= 0; i
< last_slot
; i
++) {
2698 /* POW(a,b) = EXP2(b * LOG2(a))*/
2699 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2700 alu
.op
= ALU_OP1_EXP_IEEE
;
2701 alu
.src
[0].sel
= ctx
->temp_reg
;
2703 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2704 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2705 if (i
== last_slot
- 1)
2707 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2714 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2716 struct r600_bytecode_alu alu
;
2720 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2721 alu
.op
= ALU_OP1_LOG_IEEE
;
2722 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2723 alu
.dst
.sel
= ctx
->temp_reg
;
2726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2730 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2731 alu
.op
= ALU_OP2_MUL
;
2732 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2733 alu
.src
[1].sel
= ctx
->temp_reg
;
2734 alu
.dst
.sel
= ctx
->temp_reg
;
2737 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2740 /* POW(a,b) = EXP2(b * LOG2(a))*/
2741 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2742 alu
.op
= ALU_OP1_EXP_IEEE
;
2743 alu
.src
[0].sel
= ctx
->temp_reg
;
2744 alu
.dst
.sel
= ctx
->temp_reg
;
2747 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2750 return tgsi_helper_tempx_replicate(ctx
);
2753 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2755 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2756 struct r600_bytecode_alu alu
;
2758 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2759 int tmp0
= ctx
->temp_reg
;
2760 int tmp1
= r600_get_temp(ctx
);
2761 int tmp2
= r600_get_temp(ctx
);
2762 int tmp3
= r600_get_temp(ctx
);
2765 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2767 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2768 * 2. tmp0.z = lo (tmp0.x * src2)
2769 * 3. tmp0.w = -tmp0.z
2770 * 4. tmp0.y = hi (tmp0.x * src2)
2771 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2772 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2773 * 7. tmp1.x = tmp0.x - tmp0.w
2774 * 8. tmp1.y = tmp0.x + tmp0.w
2775 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2776 * 10. tmp0.z = hi(tmp0.x * src1) = q
2777 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2779 * 12. tmp0.w = src1 - tmp0.y = r
2780 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2781 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2785 * 15. tmp1.z = tmp0.z + 1 = q + 1
2786 * 16. tmp1.w = tmp0.z - 1 = q - 1
2790 * 15. tmp1.z = tmp0.w - src2 = r - src2
2791 * 16. tmp1.w = tmp0.w + src2 = r + src2
2795 * 17. tmp1.x = tmp1.x & tmp1.y
2797 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2798 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2800 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2801 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2805 * Same as unsigned, using abs values of the operands,
2806 * and fixing the sign of the result in the end.
2809 for (i
= 0; i
< 4; i
++) {
2810 if (!(write_mask
& (1<<i
)))
2815 /* tmp2.x = -src0 */
2816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2817 alu
.op
= ALU_OP2_SUB_INT
;
2823 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2825 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2828 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2831 /* tmp2.y = -src1 */
2832 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2833 alu
.op
= ALU_OP2_SUB_INT
;
2839 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2841 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2844 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2847 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2848 /* it will be a sign of the quotient */
2851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2852 alu
.op
= ALU_OP2_XOR_INT
;
2858 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2859 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2862 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2866 /* tmp2.x = |src0| */
2867 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2868 alu
.op
= ALU_OP3_CNDGE_INT
;
2875 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2876 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2877 alu
.src
[2].sel
= tmp2
;
2878 alu
.src
[2].chan
= 0;
2881 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2884 /* tmp2.y = |src1| */
2885 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2886 alu
.op
= ALU_OP3_CNDGE_INT
;
2893 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2894 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2895 alu
.src
[2].sel
= tmp2
;
2896 alu
.src
[2].chan
= 1;
2899 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2904 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2905 if (ctx
->bc
->chip_class
== CAYMAN
) {
2906 /* tmp3.x = u2f(src2) */
2907 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2908 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2915 alu
.src
[0].sel
= tmp2
;
2916 alu
.src
[0].chan
= 1;
2918 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2922 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2925 /* tmp0.x = recip(tmp3.x) */
2926 for (j
= 0 ; j
< 3; j
++) {
2927 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2928 alu
.op
= ALU_OP1_RECIP_IEEE
;
2932 alu
.dst
.write
= (j
== 0);
2934 alu
.src
[0].sel
= tmp3
;
2935 alu
.src
[0].chan
= 0;
2939 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2943 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2944 alu
.op
= ALU_OP2_MUL
;
2946 alu
.src
[0].sel
= tmp0
;
2947 alu
.src
[0].chan
= 0;
2949 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2950 alu
.src
[1].value
= 0x4f800000;
2955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2960 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2966 alu
.src
[0].sel
= tmp3
;
2967 alu
.src
[0].chan
= 0;
2970 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2974 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2975 alu
.op
= ALU_OP1_RECIP_UINT
;
2982 alu
.src
[0].sel
= tmp2
;
2983 alu
.src
[0].chan
= 1;
2985 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2989 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2993 /* 2. tmp0.z = lo (tmp0.x * src2) */
2994 if (ctx
->bc
->chip_class
== CAYMAN
) {
2995 for (j
= 0 ; j
< 4; j
++) {
2996 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2997 alu
.op
= ALU_OP2_MULLO_UINT
;
3001 alu
.dst
.write
= (j
== 2);
3003 alu
.src
[0].sel
= tmp0
;
3004 alu
.src
[0].chan
= 0;
3006 alu
.src
[1].sel
= tmp2
;
3007 alu
.src
[1].chan
= 1;
3009 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3012 alu
.last
= (j
== 3);
3013 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3017 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3018 alu
.op
= ALU_OP2_MULLO_UINT
;
3024 alu
.src
[0].sel
= tmp0
;
3025 alu
.src
[0].chan
= 0;
3027 alu
.src
[1].sel
= tmp2
;
3028 alu
.src
[1].chan
= 1;
3030 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3034 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3038 /* 3. tmp0.w = -tmp0.z */
3039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3040 alu
.op
= ALU_OP2_SUB_INT
;
3046 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3047 alu
.src
[1].sel
= tmp0
;
3048 alu
.src
[1].chan
= 2;
3051 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3054 /* 4. tmp0.y = hi (tmp0.x * src2) */
3055 if (ctx
->bc
->chip_class
== CAYMAN
) {
3056 for (j
= 0 ; j
< 4; j
++) {
3057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3058 alu
.op
= ALU_OP2_MULHI_UINT
;
3062 alu
.dst
.write
= (j
== 1);
3064 alu
.src
[0].sel
= tmp0
;
3065 alu
.src
[0].chan
= 0;
3068 alu
.src
[1].sel
= tmp2
;
3069 alu
.src
[1].chan
= 1;
3071 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3073 alu
.last
= (j
== 3);
3074 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3079 alu
.op
= ALU_OP2_MULHI_UINT
;
3085 alu
.src
[0].sel
= tmp0
;
3086 alu
.src
[0].chan
= 0;
3089 alu
.src
[1].sel
= tmp2
;
3090 alu
.src
[1].chan
= 1;
3092 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3096 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3100 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3101 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3102 alu
.op
= ALU_OP3_CNDE_INT
;
3109 alu
.src
[0].sel
= tmp0
;
3110 alu
.src
[0].chan
= 1;
3111 alu
.src
[1].sel
= tmp0
;
3112 alu
.src
[1].chan
= 3;
3113 alu
.src
[2].sel
= tmp0
;
3114 alu
.src
[2].chan
= 2;
3117 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3120 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3121 if (ctx
->bc
->chip_class
== CAYMAN
) {
3122 for (j
= 0 ; j
< 4; j
++) {
3123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3124 alu
.op
= ALU_OP2_MULHI_UINT
;
3128 alu
.dst
.write
= (j
== 3);
3130 alu
.src
[0].sel
= tmp0
;
3131 alu
.src
[0].chan
= 2;
3133 alu
.src
[1].sel
= tmp0
;
3134 alu
.src
[1].chan
= 0;
3136 alu
.last
= (j
== 3);
3137 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3142 alu
.op
= ALU_OP2_MULHI_UINT
;
3148 alu
.src
[0].sel
= tmp0
;
3149 alu
.src
[0].chan
= 2;
3151 alu
.src
[1].sel
= tmp0
;
3152 alu
.src
[1].chan
= 0;
3155 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3159 /* 7. tmp1.x = tmp0.x - tmp0.w */
3160 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3161 alu
.op
= ALU_OP2_SUB_INT
;
3167 alu
.src
[0].sel
= tmp0
;
3168 alu
.src
[0].chan
= 0;
3169 alu
.src
[1].sel
= tmp0
;
3170 alu
.src
[1].chan
= 3;
3173 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3176 /* 8. tmp1.y = tmp0.x + tmp0.w */
3177 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3178 alu
.op
= ALU_OP2_ADD_INT
;
3184 alu
.src
[0].sel
= tmp0
;
3185 alu
.src
[0].chan
= 0;
3186 alu
.src
[1].sel
= tmp0
;
3187 alu
.src
[1].chan
= 3;
3190 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3193 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3195 alu
.op
= ALU_OP3_CNDE_INT
;
3202 alu
.src
[0].sel
= tmp0
;
3203 alu
.src
[0].chan
= 1;
3204 alu
.src
[1].sel
= tmp1
;
3205 alu
.src
[1].chan
= 1;
3206 alu
.src
[2].sel
= tmp1
;
3207 alu
.src
[2].chan
= 0;
3210 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3213 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3214 if (ctx
->bc
->chip_class
== CAYMAN
) {
3215 for (j
= 0 ; j
< 4; j
++) {
3216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3217 alu
.op
= ALU_OP2_MULHI_UINT
;
3221 alu
.dst
.write
= (j
== 2);
3223 alu
.src
[0].sel
= tmp0
;
3224 alu
.src
[0].chan
= 0;
3227 alu
.src
[1].sel
= tmp2
;
3228 alu
.src
[1].chan
= 0;
3230 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3233 alu
.last
= (j
== 3);
3234 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3238 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3239 alu
.op
= ALU_OP2_MULHI_UINT
;
3245 alu
.src
[0].sel
= tmp0
;
3246 alu
.src
[0].chan
= 0;
3249 alu
.src
[1].sel
= tmp2
;
3250 alu
.src
[1].chan
= 0;
3252 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3256 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3260 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3261 if (ctx
->bc
->chip_class
== CAYMAN
) {
3262 for (j
= 0 ; j
< 4; j
++) {
3263 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3264 alu
.op
= ALU_OP2_MULLO_UINT
;
3268 alu
.dst
.write
= (j
== 1);
3271 alu
.src
[0].sel
= tmp2
;
3272 alu
.src
[0].chan
= 1;
3274 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3277 alu
.src
[1].sel
= tmp0
;
3278 alu
.src
[1].chan
= 2;
3280 alu
.last
= (j
== 3);
3281 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3285 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3286 alu
.op
= ALU_OP2_MULLO_UINT
;
3293 alu
.src
[0].sel
= tmp2
;
3294 alu
.src
[0].chan
= 1;
3296 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3299 alu
.src
[1].sel
= tmp0
;
3300 alu
.src
[1].chan
= 2;
3303 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3307 /* 12. tmp0.w = src1 - tmp0.y = r */
3308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3309 alu
.op
= ALU_OP2_SUB_INT
;
3316 alu
.src
[0].sel
= tmp2
;
3317 alu
.src
[0].chan
= 0;
3319 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3322 alu
.src
[1].sel
= tmp0
;
3323 alu
.src
[1].chan
= 1;
3326 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3329 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3330 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3331 alu
.op
= ALU_OP2_SETGE_UINT
;
3337 alu
.src
[0].sel
= tmp0
;
3338 alu
.src
[0].chan
= 3;
3340 alu
.src
[1].sel
= tmp2
;
3341 alu
.src
[1].chan
= 1;
3343 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3347 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3350 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3352 alu
.op
= ALU_OP2_SETGE_UINT
;
3359 alu
.src
[0].sel
= tmp2
;
3360 alu
.src
[0].chan
= 0;
3362 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3365 alu
.src
[1].sel
= tmp0
;
3366 alu
.src
[1].chan
= 1;
3369 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3372 if (mod
) { /* UMOD */
3374 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3375 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3376 alu
.op
= ALU_OP2_SUB_INT
;
3382 alu
.src
[0].sel
= tmp0
;
3383 alu
.src
[0].chan
= 3;
3386 alu
.src
[1].sel
= tmp2
;
3387 alu
.src
[1].chan
= 1;
3389 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3393 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3396 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3397 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3398 alu
.op
= ALU_OP2_ADD_INT
;
3404 alu
.src
[0].sel
= tmp0
;
3405 alu
.src
[0].chan
= 3;
3407 alu
.src
[1].sel
= tmp2
;
3408 alu
.src
[1].chan
= 1;
3410 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3414 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3419 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3421 alu
.op
= ALU_OP2_ADD_INT
;
3427 alu
.src
[0].sel
= tmp0
;
3428 alu
.src
[0].chan
= 2;
3429 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3432 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3435 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3436 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3437 alu
.op
= ALU_OP2_ADD_INT
;
3443 alu
.src
[0].sel
= tmp0
;
3444 alu
.src
[0].chan
= 2;
3445 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3448 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3453 /* 17. tmp1.x = tmp1.x & tmp1.y */
3454 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3455 alu
.op
= ALU_OP2_AND_INT
;
3461 alu
.src
[0].sel
= tmp1
;
3462 alu
.src
[0].chan
= 0;
3463 alu
.src
[1].sel
= tmp1
;
3464 alu
.src
[1].chan
= 1;
3467 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3470 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3471 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3472 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3473 alu
.op
= ALU_OP3_CNDE_INT
;
3480 alu
.src
[0].sel
= tmp1
;
3481 alu
.src
[0].chan
= 0;
3482 alu
.src
[1].sel
= tmp0
;
3483 alu
.src
[1].chan
= mod
? 3 : 2;
3484 alu
.src
[2].sel
= tmp1
;
3485 alu
.src
[2].chan
= 2;
3488 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3491 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3493 alu
.op
= ALU_OP3_CNDE_INT
;
3501 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3504 alu
.src
[0].sel
= tmp1
;
3505 alu
.src
[0].chan
= 1;
3506 alu
.src
[1].sel
= tmp1
;
3507 alu
.src
[1].chan
= 3;
3508 alu
.src
[2].sel
= tmp0
;
3509 alu
.src
[2].chan
= 2;
3512 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3517 /* fix the sign of the result */
3521 /* tmp0.x = -tmp0.z */
3522 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3523 alu
.op
= ALU_OP2_SUB_INT
;
3529 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3530 alu
.src
[1].sel
= tmp0
;
3531 alu
.src
[1].chan
= 2;
3534 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3537 /* sign of the remainder is the same as the sign of src0 */
3538 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3539 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3540 alu
.op
= ALU_OP3_CNDGE_INT
;
3543 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3545 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3546 alu
.src
[1].sel
= tmp0
;
3547 alu
.src
[1].chan
= 2;
3548 alu
.src
[2].sel
= tmp0
;
3549 alu
.src
[2].chan
= 0;
3552 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3557 /* tmp0.x = -tmp0.z */
3558 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3559 alu
.op
= ALU_OP2_SUB_INT
;
3565 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3566 alu
.src
[1].sel
= tmp0
;
3567 alu
.src
[1].chan
= 2;
3570 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3573 /* fix the quotient sign (same as the sign of src0*src1) */
3574 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3575 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3576 alu
.op
= ALU_OP3_CNDGE_INT
;
3579 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3581 alu
.src
[0].sel
= tmp2
;
3582 alu
.src
[0].chan
= 2;
3583 alu
.src
[1].sel
= tmp0
;
3584 alu
.src
[1].chan
= 2;
3585 alu
.src
[2].sel
= tmp0
;
3586 alu
.src
[2].chan
= 0;
3589 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3597 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3599 return tgsi_divmod(ctx
, 0, 0);
3602 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3604 return tgsi_divmod(ctx
, 1, 0);
3607 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3609 return tgsi_divmod(ctx
, 0, 1);
3612 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3614 return tgsi_divmod(ctx
, 1, 1);
3618 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3620 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3621 struct r600_bytecode_alu alu
;
3623 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3624 int last_inst
= tgsi_last_instruction(write_mask
);
3626 for (i
= 0; i
< 4; i
++) {
3627 if (!(write_mask
& (1<<i
)))
3630 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3631 alu
.op
= ALU_OP1_TRUNC
;
3633 alu
.dst
.sel
= ctx
->temp_reg
;
3637 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3645 for (i
= 0; i
< 4; i
++) {
3646 if (!(write_mask
& (1<<i
)))
3649 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3650 alu
.op
= ctx
->inst_info
->op
;
3652 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3654 alu
.src
[0].sel
= ctx
->temp_reg
;
3655 alu
.src
[0].chan
= i
;
3657 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3667 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3669 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3670 struct r600_bytecode_alu alu
;
3672 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3673 int last_inst
= tgsi_last_instruction(write_mask
);
3676 for (i
= 0; i
< 4; i
++) {
3677 if (!(write_mask
& (1<<i
)))
3680 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3681 alu
.op
= ALU_OP2_SUB_INT
;
3683 alu
.dst
.sel
= ctx
->temp_reg
;
3687 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3688 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3692 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3697 /* dst = (src >= 0 ? src : tmp) */
3698 for (i
= 0; i
< 4; i
++) {
3699 if (!(write_mask
& (1<<i
)))
3702 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3703 alu
.op
= ALU_OP3_CNDGE_INT
;
3707 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3709 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3710 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3711 alu
.src
[2].sel
= ctx
->temp_reg
;
3712 alu
.src
[2].chan
= i
;
3716 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3723 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3725 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3726 struct r600_bytecode_alu alu
;
3728 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3729 int last_inst
= tgsi_last_instruction(write_mask
);
3731 /* tmp = (src >= 0 ? src : -1) */
3732 for (i
= 0; i
< 4; i
++) {
3733 if (!(write_mask
& (1<<i
)))
3736 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3737 alu
.op
= ALU_OP3_CNDGE_INT
;
3740 alu
.dst
.sel
= ctx
->temp_reg
;
3744 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3745 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3746 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3755 /* dst = (tmp > 0 ? 1 : tmp) */
3756 for (i
= 0; i
< 4; i
++) {
3757 if (!(write_mask
& (1<<i
)))
3760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3761 alu
.op
= ALU_OP3_CNDGT_INT
;
3765 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3767 alu
.src
[0].sel
= ctx
->temp_reg
;
3768 alu
.src
[0].chan
= i
;
3770 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3772 alu
.src
[2].sel
= ctx
->temp_reg
;
3773 alu
.src
[2].chan
= i
;
3777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3786 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3788 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3789 struct r600_bytecode_alu alu
;
3792 /* tmp = (src > 0 ? 1 : src) */
3793 for (i
= 0; i
< 4; i
++) {
3794 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3795 alu
.op
= ALU_OP3_CNDGT
;
3798 alu
.dst
.sel
= ctx
->temp_reg
;
3801 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3802 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3803 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3807 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3812 /* dst = (-tmp > 0 ? -1 : tmp) */
3813 for (i
= 0; i
< 4; i
++) {
3814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3815 alu
.op
= ALU_OP3_CNDGT
;
3817 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3819 alu
.src
[0].sel
= ctx
->temp_reg
;
3820 alu
.src
[0].chan
= i
;
3823 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3826 alu
.src
[2].sel
= ctx
->temp_reg
;
3827 alu
.src
[2].chan
= i
;
3831 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3838 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3840 struct r600_bytecode_alu alu
;
3843 for (i
= 0; i
< 4; i
++) {
3844 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3845 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3846 alu
.op
= ALU_OP0_NOP
;
3849 alu
.op
= ALU_OP1_MOV
;
3850 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3851 alu
.src
[0].sel
= ctx
->temp_reg
;
3852 alu
.src
[0].chan
= i
;
3857 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3864 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3866 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3867 struct r600_bytecode_alu alu
;
3869 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3871 for (i
= 0; i
< lasti
+ 1; i
++) {
3872 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3875 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3876 alu
.op
= ctx
->inst_info
->op
;
3877 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3878 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3881 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3888 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3895 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3897 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3898 struct r600_bytecode_alu alu
;
3901 for (i
= 0; i
< 4; i
++) {
3902 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3903 alu
.op
= ctx
->inst_info
->op
;
3904 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3905 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3908 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3910 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3911 /* handle some special cases */
3912 switch (ctx
->inst_info
->tgsi_opcode
) {
3913 case TGSI_OPCODE_DP2
:
3915 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3916 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3919 case TGSI_OPCODE_DP3
:
3921 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3922 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3925 case TGSI_OPCODE_DPH
:
3927 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3928 alu
.src
[0].chan
= 0;
3938 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3945 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3948 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3949 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3950 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3951 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3952 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3955 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3958 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3959 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3962 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3964 struct r600_bytecode_vtx vtx
;
3965 struct r600_bytecode_alu alu
;
3966 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3968 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3970 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3971 if (src_requires_loading
) {
3972 for (i
= 0; i
< 4; i
++) {
3973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3974 alu
.op
= ALU_OP1_MOV
;
3975 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3976 alu
.dst
.sel
= ctx
->temp_reg
;
3981 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3985 src_gpr
= ctx
->temp_reg
;
3988 memset(&vtx
, 0, sizeof(vtx
));
3989 vtx
.op
= FETCH_OP_VFETCH
;
3990 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3991 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3992 vtx
.src_gpr
= src_gpr
;
3993 vtx
.mega_fetch_count
= 16;
3994 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3995 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3996 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3997 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
3998 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
3999 vtx
.use_const_fields
= 1;
4000 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4002 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4005 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4008 for (i
= 0; i
< 4; i
++) {
4009 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4010 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4014 alu
.op
= ALU_OP2_AND_INT
;
4017 alu
.dst
.sel
= vtx
.dst_gpr
;
4020 alu
.src
[0].sel
= vtx
.dst_gpr
;
4021 alu
.src
[0].chan
= i
;
4023 alu
.src
[1].sel
= 512 + (id
* 2);
4024 alu
.src
[1].chan
= i
% 4;
4025 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4029 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4034 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4035 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4036 alu
.op
= ALU_OP2_OR_INT
;
4039 alu
.dst
.sel
= vtx
.dst_gpr
;
4042 alu
.src
[0].sel
= vtx
.dst_gpr
;
4043 alu
.src
[0].chan
= 3;
4045 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4046 alu
.src
[1].chan
= 0;
4047 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4057 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4059 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4060 struct r600_bytecode_alu alu
;
4062 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4065 alu
.op
= ALU_OP1_MOV
;
4067 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4068 alu
.src
[0].sel
= 512 + (id
/ 4);
4069 alu
.src
[0].chan
= id
% 4;
4071 /* r600 we have them at channel 2 of the second dword */
4072 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4073 alu
.src
[0].chan
= 1;
4075 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4076 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4078 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4084 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4086 static float one_point_five
= 1.5f
;
4087 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4088 struct r600_bytecode_tex tex
;
4089 struct r600_bytecode_alu alu
;
4093 bool read_compressed_msaa
= ctx
->bc
->msaa_texture_mode
== MSAA_TEXTURE_COMPRESSED
&&
4094 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4095 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4096 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4097 /* Texture fetch instructions can only use gprs as source.
4098 * Also they cannot negate the source or take the absolute value */
4099 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4100 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4101 read_compressed_msaa
;
4102 boolean src_loaded
= FALSE
;
4103 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4104 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4105 boolean has_txq_cube_array_z
= false;
4107 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4108 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4109 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4110 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4111 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4112 has_txq_cube_array_z
= true;
4115 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4116 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4117 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4118 sampler_src_reg
= 2;
4120 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4122 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4123 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4124 ctx
->shader
->uses_tex_buffers
= true;
4125 return r600_do_buffer_txq(ctx
);
4127 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4128 if (ctx
->bc
->chip_class
< EVERGREEN
)
4129 ctx
->shader
->uses_tex_buffers
= true;
4130 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4134 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4135 /* get offset values */
4136 if (inst
->Texture
.NumOffsets
) {
4137 assert(inst
->Texture
.NumOffsets
== 1);
4139 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4140 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4141 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4143 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4144 /* TGSI moves the sampler to src reg 3 for TXD */
4145 sampler_src_reg
= 3;
4147 for (i
= 1; i
< 3; i
++) {
4148 /* set gradients h/v */
4149 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4150 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4151 FETCH_OP_SET_GRADIENTS_V
;
4152 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4153 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4155 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4156 tex
.src_gpr
= r600_get_temp(ctx
);
4162 for (j
= 0; j
< 4; j
++) {
4163 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4164 alu
.op
= ALU_OP1_MOV
;
4165 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4166 alu
.dst
.sel
= tex
.src_gpr
;
4171 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4177 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4178 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4179 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4180 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4181 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4182 tex
.src_rel
= ctx
->src
[i
].rel
;
4184 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4185 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4186 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4187 tex
.coord_type_x
= 1;
4188 tex
.coord_type_y
= 1;
4189 tex
.coord_type_z
= 1;
4190 tex
.coord_type_w
= 1;
4192 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4196 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4198 /* Add perspective divide */
4199 if (ctx
->bc
->chip_class
== CAYMAN
) {
4201 for (i
= 0; i
< 3; i
++) {
4202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4203 alu
.op
= ALU_OP1_RECIP_IEEE
;
4204 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4206 alu
.dst
.sel
= ctx
->temp_reg
;
4212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4220 alu
.op
= ALU_OP1_RECIP_IEEE
;
4221 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4223 alu
.dst
.sel
= ctx
->temp_reg
;
4224 alu
.dst
.chan
= out_chan
;
4227 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4232 for (i
= 0; i
< 3; i
++) {
4233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4234 alu
.op
= ALU_OP2_MUL
;
4235 alu
.src
[0].sel
= ctx
->temp_reg
;
4236 alu
.src
[0].chan
= out_chan
;
4237 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4238 alu
.dst
.sel
= ctx
->temp_reg
;
4241 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4245 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4246 alu
.op
= ALU_OP1_MOV
;
4247 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4248 alu
.src
[0].chan
= 0;
4249 alu
.dst
.sel
= ctx
->temp_reg
;
4253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4257 src_gpr
= ctx
->temp_reg
;
4260 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4261 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4262 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4263 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4264 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4265 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4267 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4268 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4270 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4271 for (i
= 0; i
< 4; i
++) {
4272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4273 alu
.op
= ALU_OP2_CUBE
;
4274 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4275 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4276 alu
.dst
.sel
= ctx
->temp_reg
;
4281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4286 /* tmp1.z = RCP_e(|tmp1.z|) */
4287 if (ctx
->bc
->chip_class
== CAYMAN
) {
4288 for (i
= 0; i
< 3; i
++) {
4289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4290 alu
.op
= ALU_OP1_RECIP_IEEE
;
4291 alu
.src
[0].sel
= ctx
->temp_reg
;
4292 alu
.src
[0].chan
= 2;
4294 alu
.dst
.sel
= ctx
->temp_reg
;
4300 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4306 alu
.op
= ALU_OP1_RECIP_IEEE
;
4307 alu
.src
[0].sel
= ctx
->temp_reg
;
4308 alu
.src
[0].chan
= 2;
4310 alu
.dst
.sel
= ctx
->temp_reg
;
4314 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4319 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4320 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4321 * muladd has no writemask, have to use another temp
4323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4324 alu
.op
= ALU_OP3_MULADD
;
4327 alu
.src
[0].sel
= ctx
->temp_reg
;
4328 alu
.src
[0].chan
= 0;
4329 alu
.src
[1].sel
= ctx
->temp_reg
;
4330 alu
.src
[1].chan
= 2;
4332 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4333 alu
.src
[2].chan
= 0;
4334 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4336 alu
.dst
.sel
= ctx
->temp_reg
;
4340 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4344 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4345 alu
.op
= ALU_OP3_MULADD
;
4348 alu
.src
[0].sel
= ctx
->temp_reg
;
4349 alu
.src
[0].chan
= 1;
4350 alu
.src
[1].sel
= ctx
->temp_reg
;
4351 alu
.src
[1].chan
= 2;
4353 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4354 alu
.src
[2].chan
= 0;
4355 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4357 alu
.dst
.sel
= ctx
->temp_reg
;
4362 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4365 /* write initial compare value into Z component
4366 - W src 0 for shadow cube
4367 - X src 1 for shadow cube array */
4368 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4369 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4370 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4371 alu
.op
= ALU_OP1_MOV
;
4372 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4373 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4375 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4376 alu
.dst
.sel
= ctx
->temp_reg
;
4380 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4385 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4386 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4387 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4388 int mytmp
= r600_get_temp(ctx
);
4389 static const float eight
= 8.0f
;
4390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4391 alu
.op
= ALU_OP1_MOV
;
4392 alu
.src
[0].sel
= ctx
->temp_reg
;
4393 alu
.src
[0].chan
= 3;
4394 alu
.dst
.sel
= mytmp
;
4398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4402 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4404 alu
.op
= ALU_OP3_MULADD
;
4406 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4407 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4408 alu
.src
[1].chan
= 0;
4409 alu
.src
[1].value
= *(uint32_t *)&eight
;
4410 alu
.src
[2].sel
= mytmp
;
4411 alu
.src
[2].chan
= 0;
4412 alu
.dst
.sel
= ctx
->temp_reg
;
4416 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4419 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4420 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4421 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4422 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4423 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4424 tex
.src_gpr
= r600_get_temp(ctx
);
4429 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4430 tex
.coord_type_x
= 1;
4431 tex
.coord_type_y
= 1;
4432 tex
.coord_type_z
= 1;
4433 tex
.coord_type_w
= 1;
4434 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4435 alu
.op
= ALU_OP1_MOV
;
4436 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4437 alu
.dst
.sel
= tex
.src_gpr
;
4441 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4445 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4452 /* for cube forms of lod and bias we need to route things */
4453 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4454 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4455 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4456 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4457 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4458 alu
.op
= ALU_OP1_MOV
;
4459 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4460 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4461 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4463 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4464 alu
.dst
.sel
= ctx
->temp_reg
;
4468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4474 src_gpr
= ctx
->temp_reg
;
4477 if (src_requires_loading
&& !src_loaded
) {
4478 for (i
= 0; i
< 4; i
++) {
4479 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4480 alu
.op
= ALU_OP1_MOV
;
4481 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4482 alu
.dst
.sel
= ctx
->temp_reg
;
4487 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4492 src_gpr
= ctx
->temp_reg
;
4495 /* Obtain the sample index for reading a compressed MSAA color texture.
4496 * To read the FMASK, we use the ldfptr instruction, which tells us
4497 * where the samples are stored.
4498 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4499 * which is the identity mapping. Each nibble says which physical sample
4500 * should be fetched to get that sample.
4502 * Assume src.z contains the sample index. It should be modified like this:
4503 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4504 * Then fetch the texel with src.
4506 if (read_compressed_msaa
) {
4507 unsigned sample_chan
= 3;
4508 unsigned temp
= r600_get_temp(ctx
);
4511 /* temp.w = ldfptr() */
4512 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4513 tex
.op
= FETCH_OP_LD
;
4514 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4515 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4516 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4517 tex
.src_gpr
= src_gpr
;
4519 tex
.dst_sel_x
= 7; /* mask out these components */
4522 tex
.dst_sel_w
= 0; /* store X */
4527 tex
.offset_x
= offset_x
;
4528 tex
.offset_y
= offset_y
;
4529 tex
.offset_z
= offset_z
;
4530 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4534 /* temp.x = sample_index*4 */
4535 if (ctx
->bc
->chip_class
== CAYMAN
) {
4536 for (i
= 0 ; i
< 4; i
++) {
4537 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4538 alu
.op
= ALU_OP2_MULLO_INT
;
4539 alu
.src
[0].sel
= src_gpr
;
4540 alu
.src
[0].chan
= sample_chan
;
4541 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4542 alu
.src
[1].value
= 4;
4545 alu
.dst
.write
= i
== 0;
4548 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4554 alu
.op
= ALU_OP2_MULLO_INT
;
4555 alu
.src
[0].sel
= src_gpr
;
4556 alu
.src
[0].chan
= sample_chan
;
4557 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4558 alu
.src
[1].value
= 4;
4563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4568 /* sample_index = temp.w >> temp.x */
4569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4570 alu
.op
= ALU_OP2_LSHR_INT
;
4571 alu
.src
[0].sel
= temp
;
4572 alu
.src
[0].chan
= 3;
4573 alu
.src
[1].sel
= temp
;
4574 alu
.src
[1].chan
= 0;
4575 alu
.dst
.sel
= src_gpr
;
4576 alu
.dst
.chan
= sample_chan
;
4579 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4583 /* sample_index & 0xF */
4584 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4585 alu
.op
= ALU_OP2_AND_INT
;
4586 alu
.src
[0].sel
= src_gpr
;
4587 alu
.src
[0].chan
= sample_chan
;
4588 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4589 alu
.src
[1].value
= 0xF;
4590 alu
.dst
.sel
= src_gpr
;
4591 alu
.dst
.chan
= sample_chan
;
4594 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4598 /* visualize the FMASK */
4599 for (i
= 0; i
< 4; i
++) {
4600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4601 alu
.op
= ALU_OP1_INT_TO_FLT
;
4602 alu
.src
[0].sel
= src_gpr
;
4603 alu
.src
[0].chan
= sample_chan
;
4604 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4608 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4616 /* does this shader want a num layers from TXQ for a cube array? */
4617 if (has_txq_cube_array_z
) {
4618 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4620 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4621 alu
.op
= ALU_OP1_MOV
;
4623 alu
.src
[0].sel
= 512 + (id
/ 4);
4624 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4625 alu
.src
[0].chan
= id
% 4;
4626 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4628 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4631 /* disable writemask from texture instruction */
4632 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4635 opcode
= ctx
->inst_info
->op
;
4636 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4637 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4638 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4639 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4640 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4641 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4642 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4644 case FETCH_OP_SAMPLE
:
4645 opcode
= FETCH_OP_SAMPLE_C
;
4647 case FETCH_OP_SAMPLE_L
:
4648 opcode
= FETCH_OP_SAMPLE_C_L
;
4650 case FETCH_OP_SAMPLE_LB
:
4651 opcode
= FETCH_OP_SAMPLE_C_LB
;
4653 case FETCH_OP_SAMPLE_G
:
4654 opcode
= FETCH_OP_SAMPLE_C_G
;
4659 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4662 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4663 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4664 tex
.src_gpr
= src_gpr
;
4665 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4666 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4667 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4668 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4669 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4671 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4676 } else if (src_loaded
) {
4682 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4683 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4684 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4685 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4686 tex
.src_rel
= ctx
->src
[0].rel
;
4689 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4690 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4691 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4692 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4696 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4699 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4700 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4701 tex
.coord_type_x
= 1;
4702 tex
.coord_type_y
= 1;
4704 tex
.coord_type_z
= 1;
4705 tex
.coord_type_w
= 1;
4707 tex
.offset_x
= offset_x
;
4708 tex
.offset_y
= offset_y
;
4709 tex
.offset_z
= offset_z
;
4711 /* Put the depth for comparison in W.
4712 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4713 * Some instructions expect the depth in Z. */
4714 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4715 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4716 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4717 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4718 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4719 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4720 tex
.src_sel_w
= tex
.src_sel_z
;
4723 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4724 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4725 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4726 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4727 /* the array index is read from Y */
4728 tex
.coord_type_y
= 0;
4730 /* the array index is read from Z */
4731 tex
.coord_type_z
= 0;
4732 tex
.src_sel_z
= tex
.src_sel_y
;
4734 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4735 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4736 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4737 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4738 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4739 /* the array index is read from Z */
4740 tex
.coord_type_z
= 0;
4742 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4746 /* add shadow ambient support - gallium doesn't do it yet */
4750 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4752 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4753 struct r600_bytecode_alu alu
;
4754 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4758 /* optimize if it's just an equal balance */
4759 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4760 for (i
= 0; i
< lasti
+ 1; i
++) {
4761 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4764 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4765 alu
.op
= ALU_OP2_ADD
;
4766 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4767 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4769 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4774 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4782 for (i
= 0; i
< lasti
+ 1; i
++) {
4783 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4787 alu
.op
= ALU_OP2_ADD
;
4788 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4789 alu
.src
[0].chan
= 0;
4790 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4791 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4792 alu
.dst
.sel
= ctx
->temp_reg
;
4798 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4803 /* (1 - src0) * src2 */
4804 for (i
= 0; i
< lasti
+ 1; i
++) {
4805 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4808 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4809 alu
.op
= ALU_OP2_MUL
;
4810 alu
.src
[0].sel
= ctx
->temp_reg
;
4811 alu
.src
[0].chan
= i
;
4812 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4813 alu
.dst
.sel
= ctx
->temp_reg
;
4819 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4824 /* src0 * src1 + (1 - src0) * src2 */
4825 for (i
= 0; i
< lasti
+ 1; i
++) {
4826 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4829 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4830 alu
.op
= ALU_OP3_MULADD
;
4832 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4833 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4834 alu
.src
[2].sel
= ctx
->temp_reg
;
4835 alu
.src
[2].chan
= i
;
4837 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4849 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4851 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4852 struct r600_bytecode_alu alu
;
4854 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4856 for (i
= 0; i
< lasti
+ 1; i
++) {
4857 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4860 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4861 alu
.op
= ALU_OP3_CNDGE
;
4862 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4863 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4864 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4865 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4878 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4880 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4881 struct r600_bytecode_alu alu
;
4883 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4885 for (i
= 0; i
< lasti
+ 1; i
++) {
4886 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4890 alu
.op
= ALU_OP3_CNDGE_INT
;
4891 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4892 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4893 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4894 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4907 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4909 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4910 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4911 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4912 struct r600_bytecode_alu alu
;
4913 uint32_t use_temp
= 0;
4916 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4919 for (i
= 0; i
< 4; i
++) {
4920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4921 alu
.op
= ALU_OP2_MUL
;
4923 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4924 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4926 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4927 alu
.src
[0].chan
= i
;
4928 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4929 alu
.src
[1].chan
= i
;
4932 alu
.dst
.sel
= ctx
->temp_reg
;
4938 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4943 for (i
= 0; i
< 4; i
++) {
4944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4945 alu
.op
= ALU_OP3_MULADD
;
4948 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4949 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4951 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4952 alu
.src
[0].chan
= i
;
4953 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4954 alu
.src
[1].chan
= i
;
4957 alu
.src
[2].sel
= ctx
->temp_reg
;
4959 alu
.src
[2].chan
= i
;
4962 alu
.dst
.sel
= ctx
->temp_reg
;
4964 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4970 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4975 return tgsi_helper_copy(ctx
, inst
);
4979 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4981 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4982 struct r600_bytecode_alu alu
;
4986 /* result.x = 2^floor(src); */
4987 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4988 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4990 alu
.op
= ALU_OP1_FLOOR
;
4991 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4993 alu
.dst
.sel
= ctx
->temp_reg
;
4997 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5001 if (ctx
->bc
->chip_class
== CAYMAN
) {
5002 for (i
= 0; i
< 3; i
++) {
5003 alu
.op
= ALU_OP1_EXP_IEEE
;
5004 alu
.src
[0].sel
= ctx
->temp_reg
;
5005 alu
.src
[0].chan
= 0;
5007 alu
.dst
.sel
= ctx
->temp_reg
;
5009 alu
.dst
.write
= i
== 0;
5011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5016 alu
.op
= ALU_OP1_EXP_IEEE
;
5017 alu
.src
[0].sel
= ctx
->temp_reg
;
5018 alu
.src
[0].chan
= 0;
5020 alu
.dst
.sel
= ctx
->temp_reg
;
5024 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5030 /* result.y = tmp - floor(tmp); */
5031 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5034 alu
.op
= ALU_OP1_FRACT
;
5035 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5037 alu
.dst
.sel
= ctx
->temp_reg
;
5039 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5053 /* result.z = RoughApprox2ToX(tmp);*/
5054 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5055 if (ctx
->bc
->chip_class
== CAYMAN
) {
5056 for (i
= 0; i
< 3; i
++) {
5057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5058 alu
.op
= ALU_OP1_EXP_IEEE
;
5059 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5061 alu
.dst
.sel
= ctx
->temp_reg
;
5068 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5074 alu
.op
= ALU_OP1_EXP_IEEE
;
5075 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5077 alu
.dst
.sel
= ctx
->temp_reg
;
5083 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5089 /* result.w = 1.0;*/
5090 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5091 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5093 alu
.op
= ALU_OP1_MOV
;
5094 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5095 alu
.src
[0].chan
= 0;
5097 alu
.dst
.sel
= ctx
->temp_reg
;
5101 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5105 return tgsi_helper_copy(ctx
, inst
);
5108 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5110 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5111 struct r600_bytecode_alu alu
;
5115 /* result.x = floor(log2(|src|)); */
5116 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5117 if (ctx
->bc
->chip_class
== CAYMAN
) {
5118 for (i
= 0; i
< 3; i
++) {
5119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5121 alu
.op
= ALU_OP1_LOG_IEEE
;
5122 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5123 r600_bytecode_src_set_abs(&alu
.src
[0]);
5125 alu
.dst
.sel
= ctx
->temp_reg
;
5131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5137 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5139 alu
.op
= ALU_OP1_LOG_IEEE
;
5140 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5141 r600_bytecode_src_set_abs(&alu
.src
[0]);
5143 alu
.dst
.sel
= ctx
->temp_reg
;
5147 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5152 alu
.op
= ALU_OP1_FLOOR
;
5153 alu
.src
[0].sel
= ctx
->temp_reg
;
5154 alu
.src
[0].chan
= 0;
5156 alu
.dst
.sel
= ctx
->temp_reg
;
5161 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5166 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5167 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5169 if (ctx
->bc
->chip_class
== CAYMAN
) {
5170 for (i
= 0; i
< 3; i
++) {
5171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5173 alu
.op
= ALU_OP1_LOG_IEEE
;
5174 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5175 r600_bytecode_src_set_abs(&alu
.src
[0]);
5177 alu
.dst
.sel
= ctx
->temp_reg
;
5184 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5189 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5191 alu
.op
= ALU_OP1_LOG_IEEE
;
5192 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5193 r600_bytecode_src_set_abs(&alu
.src
[0]);
5195 alu
.dst
.sel
= ctx
->temp_reg
;
5200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5207 alu
.op
= ALU_OP1_FLOOR
;
5208 alu
.src
[0].sel
= ctx
->temp_reg
;
5209 alu
.src
[0].chan
= 1;
5211 alu
.dst
.sel
= ctx
->temp_reg
;
5216 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5220 if (ctx
->bc
->chip_class
== CAYMAN
) {
5221 for (i
= 0; i
< 3; i
++) {
5222 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5223 alu
.op
= ALU_OP1_EXP_IEEE
;
5224 alu
.src
[0].sel
= ctx
->temp_reg
;
5225 alu
.src
[0].chan
= 1;
5227 alu
.dst
.sel
= ctx
->temp_reg
;
5234 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5240 alu
.op
= ALU_OP1_EXP_IEEE
;
5241 alu
.src
[0].sel
= ctx
->temp_reg
;
5242 alu
.src
[0].chan
= 1;
5244 alu
.dst
.sel
= ctx
->temp_reg
;
5249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5254 if (ctx
->bc
->chip_class
== CAYMAN
) {
5255 for (i
= 0; i
< 3; i
++) {
5256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5257 alu
.op
= ALU_OP1_RECIP_IEEE
;
5258 alu
.src
[0].sel
= ctx
->temp_reg
;
5259 alu
.src
[0].chan
= 1;
5261 alu
.dst
.sel
= ctx
->temp_reg
;
5268 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5273 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5274 alu
.op
= ALU_OP1_RECIP_IEEE
;
5275 alu
.src
[0].sel
= ctx
->temp_reg
;
5276 alu
.src
[0].chan
= 1;
5278 alu
.dst
.sel
= ctx
->temp_reg
;
5283 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5290 alu
.op
= ALU_OP2_MUL
;
5292 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5293 r600_bytecode_src_set_abs(&alu
.src
[0]);
5295 alu
.src
[1].sel
= ctx
->temp_reg
;
5296 alu
.src
[1].chan
= 1;
5298 alu
.dst
.sel
= ctx
->temp_reg
;
5303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5308 /* result.z = log2(|src|);*/
5309 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5310 if (ctx
->bc
->chip_class
== CAYMAN
) {
5311 for (i
= 0; i
< 3; i
++) {
5312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5314 alu
.op
= ALU_OP1_LOG_IEEE
;
5315 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5316 r600_bytecode_src_set_abs(&alu
.src
[0]);
5318 alu
.dst
.sel
= ctx
->temp_reg
;
5325 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5330 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5332 alu
.op
= ALU_OP1_LOG_IEEE
;
5333 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5334 r600_bytecode_src_set_abs(&alu
.src
[0]);
5336 alu
.dst
.sel
= ctx
->temp_reg
;
5341 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5347 /* result.w = 1.0; */
5348 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5349 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5351 alu
.op
= ALU_OP1_MOV
;
5352 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5353 alu
.src
[0].chan
= 0;
5355 alu
.dst
.sel
= ctx
->temp_reg
;
5360 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5365 return tgsi_helper_copy(ctx
, inst
);
5368 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5370 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5371 struct r600_bytecode_alu alu
;
5374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5376 switch (inst
->Instruction
.Opcode
) {
5377 case TGSI_OPCODE_ARL
:
5378 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5380 case TGSI_OPCODE_ARR
:
5381 alu
.op
= ALU_OP1_FLT_TO_INT
;
5383 case TGSI_OPCODE_UARL
:
5384 alu
.op
= ALU_OP1_MOV
;
5391 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5393 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5399 ctx
->bc
->ar_loaded
= 0;
5402 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5404 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5405 struct r600_bytecode_alu alu
;
5408 switch (inst
->Instruction
.Opcode
) {
5409 case TGSI_OPCODE_ARL
:
5410 memset(&alu
, 0, sizeof(alu
));
5411 alu
.op
= ALU_OP1_FLOOR
;
5412 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5413 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5417 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5420 memset(&alu
, 0, sizeof(alu
));
5421 alu
.op
= ALU_OP1_FLT_TO_INT
;
5422 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5423 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5427 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5430 case TGSI_OPCODE_ARR
:
5431 memset(&alu
, 0, sizeof(alu
));
5432 alu
.op
= ALU_OP1_FLT_TO_INT
;
5433 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5434 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5438 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5441 case TGSI_OPCODE_UARL
:
5442 memset(&alu
, 0, sizeof(alu
));
5443 alu
.op
= ALU_OP1_MOV
;
5444 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5445 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5449 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5457 ctx
->bc
->ar_loaded
= 0;
5461 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5463 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5464 struct r600_bytecode_alu alu
;
5467 for (i
= 0; i
< 4; i
++) {
5468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5470 alu
.op
= ALU_OP2_MUL
;
5471 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5473 if (i
== 0 || i
== 3) {
5474 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5476 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5479 if (i
== 0 || i
== 2) {
5480 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5482 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5486 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5493 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5495 struct r600_bytecode_alu alu
;
5498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5500 alu
.execute_mask
= 1;
5501 alu
.update_pred
= 1;
5503 alu
.dst
.sel
= ctx
->temp_reg
;
5507 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5508 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5509 alu
.src
[1].chan
= 0;
5513 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5519 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5521 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5525 if (ctx
->bc
->cf_last
) {
5526 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5528 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5533 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5534 ctx
->bc
->force_add_cf
= 1;
5535 } else if (alu_pop
== 2) {
5536 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5537 ctx
->bc
->force_add_cf
= 1;
5544 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5545 ctx
->bc
->cf_last
->pop_count
= pops
;
5546 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5552 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5555 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5556 unsigned elements
, entries
;
5558 unsigned entry_size
= stack
->entry_size
;
5560 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5561 elements
+= stack
->push
;
5563 switch (ctx
->bc
->chip_class
) {
5566 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5567 * the stack must be reserved to hold the current active/continue
5569 if (reason
== FC_PUSH_VPM
) {
5575 /* r9xx: any stack operation on empty stack consumes 2 additional
5580 /* FIXME: do the two elements added above cover the cases for the
5584 /* r8xx+: 2 extra elements are not always required, but one extra
5585 * element must be added for each of the following cases:
5586 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5588 * (Currently we don't use ALU_ELSE_AFTER.)
5589 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5590 * PUSH instruction executed.
5592 * NOTE: it seems we also need to reserve additional element in some
5593 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5594 * then STACK_SIZE should be 2 instead of 1 */
5595 if (reason
== FC_PUSH_VPM
) {
5605 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5606 * for all chips, so we use 4 in the final formula, not the real entry_size
5610 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5612 if (entries
> stack
->max_entries
)
5613 stack
->max_entries
= entries
;
5616 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5620 --ctx
->bc
->stack
.push
;
5621 assert(ctx
->bc
->stack
.push
>= 0);
5624 --ctx
->bc
->stack
.push_wqm
;
5625 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5628 --ctx
->bc
->stack
.loop
;
5629 assert(ctx
->bc
->stack
.loop
>= 0);
5637 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5641 ++ctx
->bc
->stack
.push
;
5644 ++ctx
->bc
->stack
.push_wqm
;
5646 ++ctx
->bc
->stack
.loop
;
5652 callstack_update_max_depth(ctx
, reason
);
5655 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5657 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5659 sp
->mid
= realloc((void *)sp
->mid
,
5660 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5661 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5665 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5668 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5669 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5672 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5674 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5684 static int emit_return(struct r600_shader_ctx
*ctx
)
5686 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5690 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5693 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5694 ctx
->bc
->cf_last
->pop_count
= pops
;
5695 /* XXX work out offset */
5699 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5704 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5709 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5712 emit_jump_to_offset(ctx
, 1, 4);
5713 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5714 pops(ctx
, ifidx
+ 1);
5718 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5722 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5723 ctx
->bc
->cf_last
->pop_count
= 1;
5725 fc_set_mid(ctx
, fc_sp
);
5731 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5733 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5735 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5736 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5737 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5738 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5739 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5740 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5741 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5742 alu_type
= CF_OP_ALU
;
5745 emit_logic_pred(ctx
, ALU_OP2_PRED_SETNE_INT
, alu_type
);
5747 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5749 fc_pushlevel(ctx
, FC_IF
);
5751 callstack_push(ctx
, FC_PUSH_VPM
);
5755 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5757 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5758 ctx
->bc
->cf_last
->pop_count
= 1;
5760 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5761 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5765 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5768 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5769 R600_ERR("if/endif unbalanced in shader\n");
5773 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5774 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5775 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5777 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5781 callstack_pop(ctx
, FC_PUSH_VPM
);
5785 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5787 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5788 * limited to 4096 iterations, like the other LOOP_* instructions. */
5789 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5791 fc_pushlevel(ctx
, FC_LOOP
);
5793 /* check stack depth */
5794 callstack_push(ctx
, FC_LOOP
);
5798 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5802 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5804 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5805 R600_ERR("loop/endloop in shader code are not paired.\n");
5809 /* fixup loop pointers - from r600isa
5810 LOOP END points to CF after LOOP START,
5811 LOOP START point to CF after LOOP END
5812 BRK/CONT point to LOOP END CF
5814 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5816 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5818 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5819 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5821 /* XXX add LOOPRET support */
5823 callstack_pop(ctx
, FC_LOOP
);
5827 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5831 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5833 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5838 R600_ERR("Break not inside loop/endloop pair\n");
5842 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5844 fc_set_mid(ctx
, fscp
);
5849 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5851 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5852 struct r600_bytecode_alu alu
;
5854 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5857 for (i
= 0; i
< lasti
+ 1; i
++) {
5858 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5861 if (ctx
->bc
->chip_class
== CAYMAN
) {
5862 for (j
= 0 ; j
< 4; j
++) {
5863 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5865 alu
.op
= ALU_OP2_MULLO_UINT
;
5866 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5867 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5869 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5870 alu
.dst
.sel
= ctx
->temp_reg
;
5871 alu
.dst
.write
= (j
== i
);
5874 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5882 alu
.dst
.sel
= ctx
->temp_reg
;
5885 alu
.op
= ALU_OP2_MULLO_UINT
;
5886 for (j
= 0; j
< 2; j
++) {
5887 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5891 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5898 for (i
= 0; i
< lasti
+ 1; i
++) {
5899 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5902 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5903 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5905 alu
.op
= ALU_OP2_ADD_INT
;
5907 alu
.src
[0].sel
= ctx
->temp_reg
;
5908 alu
.src
[0].chan
= i
;
5910 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5914 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5921 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5922 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5923 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5924 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5927 * For state trackers other than OpenGL, we'll want to use
5928 * _RECIP_IEEE instead.
5930 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5932 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5933 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5934 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5935 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5936 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5937 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5938 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5939 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5940 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5941 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5942 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5943 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5944 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5945 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5946 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5947 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5949 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5950 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5952 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5953 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5954 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5955 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5956 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5957 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5958 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5959 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5960 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5961 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5963 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5964 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5965 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5966 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5967 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5968 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5969 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5970 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5971 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5972 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5973 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5974 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5975 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5977 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5978 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5979 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5980 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5981 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5982 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5983 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5984 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5985 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5986 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5987 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5988 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5989 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5990 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5991 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5992 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5993 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5994 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5995 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5996 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5997 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5998 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5999 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6000 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6001 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6002 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6003 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6004 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6005 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6007 {75, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6008 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6009 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6010 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6012 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6013 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6014 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6015 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6016 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6017 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6018 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6019 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6020 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6022 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6023 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6024 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6025 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6026 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6027 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6028 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6029 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6030 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6031 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6032 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6033 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6034 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6035 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6036 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6037 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6039 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6040 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6041 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6042 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6044 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6045 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6046 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6047 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6048 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6049 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6050 {TGSI_OPCODE_IFC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6051 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6052 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6053 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6055 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6056 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6057 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6058 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6059 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6060 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6061 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6062 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6063 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6064 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6065 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6066 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6067 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6068 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6069 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6070 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6071 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6072 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6073 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6074 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6075 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6076 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6077 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6078 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6079 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6080 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6081 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6082 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6083 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6084 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6085 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6086 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6087 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6088 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6089 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6090 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6091 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6092 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6093 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6094 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6095 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6096 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6097 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6098 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6099 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6100 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6101 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6102 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6103 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6105 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6106 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6107 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6108 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6109 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6110 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6111 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6112 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6114 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6115 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6116 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6117 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6120 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6121 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6122 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6123 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6124 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6125 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6126 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6127 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6128 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6129 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6130 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6131 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6132 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6133 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6134 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6135 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6136 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6137 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6138 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6139 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6140 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6142 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6143 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6145 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6146 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6147 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6148 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6149 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6150 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6151 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6152 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6153 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6154 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6156 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6157 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6158 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6159 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6160 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6161 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6162 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6163 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6164 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6165 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6166 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6167 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6168 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6170 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6172 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6173 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6174 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6175 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6176 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6177 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6178 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6179 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6180 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6181 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6182 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6183 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6184 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6185 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6186 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6187 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6188 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6189 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6190 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6191 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6192 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6193 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6194 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6195 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6196 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6197 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6198 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6200 {75, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6201 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6202 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6203 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6205 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6206 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6207 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6208 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6209 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6210 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6211 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6212 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6213 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6215 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6216 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6217 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6218 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6219 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6220 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6221 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6222 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6223 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6224 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6225 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6226 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6227 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6228 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6229 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6230 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6232 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6233 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6234 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6235 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6237 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6238 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6239 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6240 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6241 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6242 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6243 {TGSI_OPCODE_IFC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6244 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6245 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6246 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6248 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6249 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6250 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6251 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6252 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6253 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6254 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6255 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6256 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6257 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6258 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6259 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6260 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6261 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6262 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6263 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6264 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6265 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6266 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6267 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6268 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6269 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6270 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6271 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6272 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6273 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6274 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6275 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6276 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6277 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6278 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6279 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6280 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6281 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6282 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6283 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6284 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6285 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6286 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6287 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6288 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6289 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6290 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6291 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6292 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6293 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6294 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6295 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6296 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6297 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6298 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6299 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6300 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6301 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6302 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6303 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6304 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6305 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6306 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6307 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6308 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6309 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6310 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6313 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6314 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6315 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6316 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6317 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6318 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6319 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6320 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6321 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6322 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6323 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6324 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6325 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6326 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6327 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6328 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6329 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6330 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6331 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6332 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6333 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6335 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6336 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6338 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6339 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6340 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6341 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6342 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6343 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6344 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6345 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6346 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6347 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6349 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6350 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6351 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6352 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6353 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6354 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6355 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6356 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6357 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6358 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6359 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6360 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6361 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6362 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6363 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6364 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6365 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6366 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6367 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6368 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6369 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6370 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6371 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6372 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6373 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6374 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6375 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6376 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6377 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6378 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6379 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6380 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6381 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6382 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6383 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6384 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6385 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6386 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6387 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6388 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6389 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6390 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6391 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6393 {75, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6394 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6395 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6396 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6398 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6399 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6400 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6401 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6402 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6403 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6404 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6405 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6406 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6408 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6409 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6410 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6411 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6412 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6413 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6414 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6415 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6416 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6417 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6418 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6419 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6420 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6421 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6422 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6423 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6425 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6426 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6427 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6428 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6430 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6431 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6432 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6433 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6434 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6435 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6436 {TGSI_OPCODE_IFC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6437 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6438 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6439 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6441 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6442 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6443 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6444 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6445 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6446 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6447 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6448 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6449 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6450 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6451 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6452 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6453 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6454 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6455 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6456 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6457 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6458 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6459 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6460 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6461 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6462 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6463 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6464 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6465 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6467 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6468 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6469 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6470 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6471 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6472 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6473 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6474 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6475 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6476 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6477 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6478 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6479 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6480 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6481 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6482 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6483 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6484 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6485 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6486 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6487 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6488 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6489 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6490 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6491 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6492 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6493 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6494 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6495 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6496 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6497 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6498 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6499 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6500 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6501 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6502 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6503 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},