2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_llvm.h"
25 #include "r600_formats.h"
26 #include "r600_opcodes.h"
27 #include "r600_shader.h"
30 #include "sb/sb_public.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "tgsi/tgsi_info.h"
34 #include "tgsi/tgsi_parse.h"
35 #include "tgsi/tgsi_scan.h"
36 #include "tgsi/tgsi_dump.h"
37 #include "util/u_memory.h"
43 Why CAYMAN got loops for lots of instructions is explained here.
45 -These 8xx t-slot only ops are implemented in all vector slots.
46 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
47 These 8xx t-slot only opcodes become vector ops, with all four
48 slots expecting the arguments on sources a and b. Result is
49 broadcast to all channels.
50 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT
51 These 8xx t-slot only opcodes become vector ops in the z, y, and
53 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
54 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
57 The w slot may have an independent co-issued operation, or if the
58 result is required to be in the w slot, the opcode above may be
59 issued in the w slot as well.
60 The compiler must issue the source argument to slots z, y, and x
63 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
64 struct r600_pipe_shader
*pipeshader
,
65 struct r600_shader_key key
);
67 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
68 int size
, unsigned comp_mask
) {
73 if (ps
->num_arrays
== ps
->max_arrays
) {
75 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
76 sizeof(struct r600_shader_array
));
79 int n
= ps
->num_arrays
;
82 ps
->arrays
[n
].comp_mask
= comp_mask
;
83 ps
->arrays
[n
].gpr_start
= start_gpr
;
84 ps
->arrays
[n
].gpr_count
= size
;
87 static unsigned tgsi_get_processor_type(const struct tgsi_token
*tokens
)
89 struct tgsi_parse_context parse
;
91 if (tgsi_parse_init( &parse
, tokens
) != TGSI_PARSE_OK
) {
92 debug_printf("tgsi_parse_init() failed in %s:%i!\n", __func__
, __LINE__
);
95 return parse
.FullHeader
.Processor
.Processor
;
98 static bool r600_can_dump_shader(struct r600_screen
*rscreen
, unsigned processor_type
)
100 switch (processor_type
) {
101 case TGSI_PROCESSOR_VERTEX
:
102 return (rscreen
->debug_flags
& DBG_VS
) != 0;
103 case TGSI_PROCESSOR_GEOMETRY
:
104 return (rscreen
->debug_flags
& DBG_GS
) != 0;
105 case TGSI_PROCESSOR_FRAGMENT
:
106 return (rscreen
->debug_flags
& DBG_PS
) != 0;
107 case TGSI_PROCESSOR_COMPUTE
:
108 return (rscreen
->debug_flags
& DBG_CS
) != 0;
114 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
118 fprintf(stderr
, "STREAMOUT\n");
119 for (i
= 0; i
< so
->num_outputs
; i
++) {
120 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
121 so
->output
[i
].start_component
;
122 fprintf(stderr
, " %i: MEM_STREAM0_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
123 i
, so
->output
[i
].output_buffer
,
124 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
125 so
->output
[i
].register_index
,
130 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
134 int r600_pipe_shader_create(struct pipe_context
*ctx
,
135 struct r600_pipe_shader
*shader
,
136 struct r600_shader_key key
)
138 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
139 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
142 bool dump
= r600_can_dump_shader(rctx
->screen
, tgsi_get_processor_type(sel
->tokens
));
143 unsigned use_sb
= rctx
->screen
->debug_flags
& DBG_SB
;
144 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->debug_flags
& DBG_SB_DISASM
);
146 shader
->shader
.bc
.isa
= rctx
->isa
;
149 fprintf(stderr
, "--------------------------------------------------------------\n");
150 tgsi_dump(sel
->tokens
, 0);
152 if (sel
->so
.num_outputs
) {
153 r600_dump_streamout(&sel
->so
);
156 r
= r600_shader_from_tgsi(rctx
->screen
, shader
, key
);
158 R600_ERR("translation from TGSI failed !\n");
161 r
= r600_bytecode_build(&shader
->shader
.bc
);
163 R600_ERR("building bytecode failed !\n");
167 if (dump
&& !sb_disasm
) {
168 fprintf(stderr
, "--------------------------------------------------------------\n");
169 r600_bytecode_disasm(&shader
->shader
.bc
);
170 fprintf(stderr
, "______________________________________________________________\n");
171 } else if ((dump
&& sb_disasm
) || use_sb
) {
172 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
175 R600_ERR("r600_sb_bytecode_process failed !\n");
180 /* Store the shader in a buffer. */
181 if (shader
->bo
== NULL
) {
182 shader
->bo
= (struct r600_resource
*)
183 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
184 if (shader
->bo
== NULL
) {
187 ptr
= r600_buffer_mmap_sync_with_rings(rctx
, shader
->bo
, PIPE_TRANSFER_WRITE
);
188 if (R600_BIG_ENDIAN
) {
189 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
190 ptr
[i
] = bswap_32(shader
->shader
.bc
.bytecode
[i
]);
193 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
195 rctx
->ws
->buffer_unmap(shader
->bo
->cs_buf
);
199 switch (shader
->shader
.processor_type
) {
200 case TGSI_PROCESSOR_VERTEX
:
201 if (rctx
->chip_class
>= EVERGREEN
) {
202 evergreen_update_vs_state(ctx
, shader
);
204 r600_update_vs_state(ctx
, shader
);
207 case TGSI_PROCESSOR_FRAGMENT
:
208 if (rctx
->chip_class
>= EVERGREEN
) {
209 evergreen_update_ps_state(ctx
, shader
);
211 r600_update_ps_state(ctx
, shader
);
220 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
222 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
223 r600_bytecode_clear(&shader
->shader
.bc
);
224 r600_release_command_buffer(&shader
->command_buffer
);
228 * tgsi -> r600 shader
230 struct r600_shader_tgsi_instruction
;
232 struct r600_shader_src
{
242 struct r600_shader_ctx
{
243 struct tgsi_shader_info info
;
244 struct tgsi_parse_context parse
;
245 const struct tgsi_token
*tokens
;
247 unsigned file_offset
[TGSI_FILE_COUNT
];
249 struct r600_shader_tgsi_instruction
*inst_info
;
250 struct r600_bytecode
*bc
;
251 struct r600_shader
*shader
;
252 struct r600_shader_src src
[4];
255 uint32_t max_driver_temp_used
;
257 /* needed for evergreen interpolation */
258 boolean input_centroid
;
259 boolean input_linear
;
260 boolean input_perspective
;
264 boolean clip_vertex_write
;
270 struct r600_shader_tgsi_instruction
{
271 unsigned tgsi_opcode
;
274 int (*process
)(struct r600_shader_ctx
*ctx
);
277 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
278 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
279 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
280 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
281 static int tgsi_else(struct r600_shader_ctx
*ctx
);
282 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
283 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
284 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
285 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
288 * bytestream -> r600 shader
290 * These functions are used to transform the output of the LLVM backend into
291 * struct r600_bytecode.
294 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
295 unsigned char * bytes
, unsigned num_bytes
);
298 int r600_compute_shader_create(struct pipe_context
* ctx
,
299 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
)
301 struct r600_context
*r600_ctx
= (struct r600_context
*)ctx
;
302 unsigned char * bytes
;
304 struct r600_shader_ctx shader_ctx
;
305 boolean use_kill
= false;
306 bool dump
= (r600_ctx
->screen
->debug_flags
& DBG_CS
) != 0;
307 unsigned use_sb
= r600_ctx
->screen
->debug_flags
& DBG_SB_CS
;
308 unsigned sb_disasm
= use_sb
||
309 (r600_ctx
->screen
->debug_flags
& DBG_SB_DISASM
);
311 shader_ctx
.bc
= bytecode
;
312 r600_bytecode_init(shader_ctx
.bc
, r600_ctx
->chip_class
, r600_ctx
->family
,
313 r600_ctx
->screen
->msaa_texture_support
);
314 shader_ctx
.bc
->type
= TGSI_PROCESSOR_COMPUTE
;
315 shader_ctx
.bc
->isa
= r600_ctx
->isa
;
316 r600_llvm_compile(mod
, &bytes
, &byte_count
, r600_ctx
->family
,
317 shader_ctx
.bc
, &use_kill
, dump
);
318 r600_bytecode_from_byte_stream(&shader_ctx
, bytes
, byte_count
);
319 if (shader_ctx
.bc
->chip_class
== CAYMAN
) {
320 cm_bytecode_add_cf_end(shader_ctx
.bc
);
322 r600_bytecode_build(shader_ctx
.bc
);
324 if (dump
&& !sb_disasm
) {
325 r600_bytecode_disasm(shader_ctx
.bc
);
326 } else if ((dump
&& sb_disasm
) || use_sb
) {
327 if (r600_sb_bytecode_process(r600_ctx
, shader_ctx
.bc
, NULL
, dump
, use_sb
))
328 R600_ERR("r600_sb_bytecode_process failed!\n");
335 #endif /* HAVE_OPENCL */
337 static uint32_t i32_from_byte_stream(unsigned char * bytes
,
338 unsigned * bytes_read
)
342 for (i
= 0; i
< 4; i
++) {
343 out
|= bytes
[(*bytes_read
)++] << (8 * i
);
348 static unsigned r600_src_from_byte_stream(unsigned char * bytes
,
349 unsigned bytes_read
, struct r600_bytecode_alu
* alu
, unsigned src_idx
)
353 sel0
= bytes
[bytes_read
++];
354 sel1
= bytes
[bytes_read
++];
355 alu
->src
[src_idx
].sel
= sel0
| (sel1
<< 8);
356 alu
->src
[src_idx
].chan
= bytes
[bytes_read
++];
357 alu
->src
[src_idx
].neg
= bytes
[bytes_read
++];
358 alu
->src
[src_idx
].abs
= bytes
[bytes_read
++];
359 alu
->src
[src_idx
].rel
= bytes
[bytes_read
++];
360 alu
->src
[src_idx
].kc_bank
= bytes
[bytes_read
++];
361 for (i
= 0; i
< 4; i
++) {
362 alu
->src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
367 static unsigned r600_alu_from_byte_stream(struct r600_shader_ctx
*ctx
,
368 unsigned char * bytes
, unsigned bytes_read
)
370 unsigned src_idx
, src_num
;
371 struct r600_bytecode_alu alu
;
372 unsigned src_use_sel
[3];
373 const struct alu_op_info
*alu_op
;
374 unsigned src_sel
[3] = {};
375 uint32_t word0
, word1
;
377 src_num
= bytes
[bytes_read
++];
379 memset(&alu
, 0, sizeof(alu
));
380 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
382 src_use_sel
[src_idx
] = bytes
[bytes_read
++];
383 for (i
= 0; i
< 4; i
++) {
384 src_sel
[src_idx
] |= bytes
[bytes_read
++] << (i
* 8);
386 for (i
= 0; i
< 4; i
++) {
387 alu
.src
[src_idx
].value
|= bytes
[bytes_read
++] << (i
* 8);
391 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
392 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
394 switch(ctx
->bc
->chip_class
) {
397 r600_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
402 r700_bytecode_alu_read(ctx
->bc
, &alu
, word0
, word1
);
406 for(src_idx
= 0; src_idx
< src_num
; src_idx
++) {
407 if (src_use_sel
[src_idx
]) {
408 unsigned sel
= src_sel
[src_idx
];
410 alu
.src
[src_idx
].chan
= sel
& 3;
413 if (sel
>=512) { /* constant */
415 alu
.src
[src_idx
].kc_bank
= sel
>> 12;
416 alu
.src
[src_idx
].sel
= (sel
& 4095) + 512;
419 alu
.src
[src_idx
].sel
= sel
;
424 alu_op
= r600_isa_alu(alu
.op
);
426 #if HAVE_LLVM < 0x0302
427 if ((alu_op
->flags
& AF_PRED
) && alu_op
->src_count
== 2) {
430 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
436 if (alu_op
->flags
& AF_MOVA
) {
437 ctx
->bc
->ar_reg
= alu
.src
[0].sel
;
438 ctx
->bc
->ar_chan
= alu
.src
[0].chan
;
439 ctx
->bc
->ar_loaded
= 0;
443 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, ctx
->bc
->cf_last
->op
);
445 /* XXX: Handle other KILL instructions */
446 if (alu_op
->flags
& AF_KILL
) {
447 ctx
->shader
->uses_kill
= 1;
448 /* XXX: This should be enforced in the LLVM backend. */
449 ctx
->bc
->force_add_cf
= 1;
454 static void llvm_if(struct r600_shader_ctx
*ctx
)
456 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
457 fc_pushlevel(ctx
, FC_IF
);
458 callstack_push(ctx
, FC_PUSH_VPM
);
461 static void r600_break_from_byte_stream(struct r600_shader_ctx
*ctx
)
463 unsigned opcode
= TGSI_OPCODE_BRK
;
464 if (ctx
->bc
->chip_class
== CAYMAN
)
465 ctx
->inst_info
= &cm_shader_tgsi_instruction
[opcode
];
466 else if (ctx
->bc
->chip_class
>= EVERGREEN
)
467 ctx
->inst_info
= &eg_shader_tgsi_instruction
[opcode
];
469 ctx
->inst_info
= &r600_shader_tgsi_instruction
[opcode
];
471 tgsi_loop_brk_cont(ctx
);
475 static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx
*ctx
,
476 unsigned char * bytes
, unsigned bytes_read
)
478 struct r600_bytecode_alu alu
;
480 memset(&alu
, 0, sizeof(alu
));
481 bytes_read
= r600_src_from_byte_stream(bytes
, bytes_read
, &alu
, 0);
482 inst
= bytes
[bytes_read
++];
484 case 0: /* IF_PREDICATED */
493 case 3: /* BGNLOOP */
496 case 4: /* ENDLOOP */
499 case 5: /* PREDICATED_BREAK */
500 r600_break_from_byte_stream(ctx
);
502 case 6: /* CONTINUE */
504 unsigned opcode
= TGSI_OPCODE_CONT
;
505 if (ctx
->bc
->chip_class
== CAYMAN
) {
507 &cm_shader_tgsi_instruction
[opcode
];
508 } else if (ctx
->bc
->chip_class
>= EVERGREEN
) {
510 &eg_shader_tgsi_instruction
[opcode
];
513 &r600_shader_tgsi_instruction
[opcode
];
515 tgsi_loop_brk_cont(ctx
);
523 static unsigned r600_tex_from_byte_stream(struct r600_shader_ctx
*ctx
,
524 unsigned char * bytes
, unsigned bytes_read
)
526 struct r600_bytecode_tex tex
;
528 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
529 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
530 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
532 tex
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
, G_SQ_TEX_WORD0_TEX_INST(word0
));
533 tex
.resource_id
= G_SQ_TEX_WORD0_RESOURCE_ID(word0
);
534 tex
.src_gpr
= G_SQ_TEX_WORD0_SRC_GPR(word0
);
535 tex
.src_rel
= G_SQ_TEX_WORD0_SRC_REL(word0
);
536 tex
.dst_gpr
= G_SQ_TEX_WORD1_DST_GPR(word1
);
537 tex
.dst_rel
= G_SQ_TEX_WORD1_DST_REL(word1
);
538 tex
.dst_sel_x
= G_SQ_TEX_WORD1_DST_SEL_X(word1
);
539 tex
.dst_sel_y
= G_SQ_TEX_WORD1_DST_SEL_Y(word1
);
540 tex
.dst_sel_z
= G_SQ_TEX_WORD1_DST_SEL_Z(word1
);
541 tex
.dst_sel_w
= G_SQ_TEX_WORD1_DST_SEL_W(word1
);
542 tex
.lod_bias
= G_SQ_TEX_WORD1_LOD_BIAS(word1
);
543 tex
.coord_type_x
= G_SQ_TEX_WORD1_COORD_TYPE_X(word1
);
544 tex
.coord_type_y
= G_SQ_TEX_WORD1_COORD_TYPE_Y(word1
);
545 tex
.coord_type_z
= G_SQ_TEX_WORD1_COORD_TYPE_Z(word1
);
546 tex
.coord_type_w
= G_SQ_TEX_WORD1_COORD_TYPE_W(word1
);
547 tex
.offset_x
= G_SQ_TEX_WORD2_OFFSET_X(word2
);
548 tex
.offset_y
= G_SQ_TEX_WORD2_OFFSET_Y(word2
);
549 tex
.offset_z
= G_SQ_TEX_WORD2_OFFSET_Z(word2
);
550 tex
.sampler_id
= G_SQ_TEX_WORD2_SAMPLER_ID(word2
);
551 tex
.src_sel_x
= G_SQ_TEX_WORD2_SRC_SEL_X(word2
);
552 tex
.src_sel_y
= G_SQ_TEX_WORD2_SRC_SEL_Y(word2
);
553 tex
.src_sel_z
= G_SQ_TEX_WORD2_SRC_SEL_Z(word2
);
554 tex
.src_sel_w
= G_SQ_TEX_WORD2_SRC_SEL_W(word2
);
561 r600_bytecode_add_tex(ctx
->bc
, &tex
);
566 static int r600_vtx_from_byte_stream(struct r600_shader_ctx
*ctx
,
567 unsigned char * bytes
, unsigned bytes_read
)
569 struct r600_bytecode_vtx vtx
;
571 uint32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
572 uint32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
573 uint32_t word2
= i32_from_byte_stream(bytes
, &bytes_read
);
575 memset(&vtx
, 0, sizeof(vtx
));
578 vtx
.op
= r600_isa_fetch_by_opcode(ctx
->bc
->isa
,
579 G_SQ_VTX_WORD0_VTX_INST(word0
));
580 vtx
.fetch_type
= G_SQ_VTX_WORD0_FETCH_TYPE(word0
);
581 vtx
.buffer_id
= G_SQ_VTX_WORD0_BUFFER_ID(word0
);
582 vtx
.src_gpr
= G_SQ_VTX_WORD0_SRC_GPR(word0
);
583 vtx
.src_sel_x
= G_SQ_VTX_WORD0_SRC_SEL_X(word0
);
584 vtx
.mega_fetch_count
= G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(word0
);
587 vtx
.dst_gpr
= G_SQ_VTX_WORD1_GPR_DST_GPR(word1
);
588 vtx
.dst_sel_x
= G_SQ_VTX_WORD1_DST_SEL_X(word1
);
589 vtx
.dst_sel_y
= G_SQ_VTX_WORD1_DST_SEL_Y(word1
);
590 vtx
.dst_sel_z
= G_SQ_VTX_WORD1_DST_SEL_Z(word1
);
591 vtx
.dst_sel_w
= G_SQ_VTX_WORD1_DST_SEL_W(word1
);
592 vtx
.use_const_fields
= G_SQ_VTX_WORD1_USE_CONST_FIELDS(word1
);
593 vtx
.data_format
= G_SQ_VTX_WORD1_DATA_FORMAT(word1
);
594 vtx
.num_format_all
= G_SQ_VTX_WORD1_NUM_FORMAT_ALL(word1
);
595 vtx
.format_comp_all
= G_SQ_VTX_WORD1_FORMAT_COMP_ALL(word1
);
596 vtx
.srf_mode_all
= G_SQ_VTX_WORD1_SRF_MODE_ALL(word1
);
599 vtx
.offset
= G_SQ_VTX_WORD2_OFFSET(word2
);
600 vtx
.endian
= G_SQ_VTX_WORD2_ENDIAN_SWAP(word2
);
602 if (r600_bytecode_add_vtx(ctx
->bc
, &vtx
)) {
603 fprintf(stderr
, "Error adding vtx\n");
606 /* Use the Texture Cache for compute shaders*/
607 if (ctx
->bc
->chip_class
>= EVERGREEN
&&
608 ctx
->bc
->type
== TGSI_PROCESSOR_COMPUTE
) {
609 ctx
->bc
->cf_last
->op
= CF_OP_TEX
;
614 static int r600_export_from_byte_stream(struct r600_shader_ctx
*ctx
,
615 unsigned char * bytes
, unsigned bytes_read
)
617 uint32_t word0
= 0, word1
= 0;
618 struct r600_bytecode_output output
;
619 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
620 word0
= i32_from_byte_stream(bytes
, &bytes_read
);
621 word1
= i32_from_byte_stream(bytes
, &bytes_read
);
622 if (ctx
->bc
->chip_class
>= EVERGREEN
)
623 eg_bytecode_export_read(ctx
->bc
, &output
, word0
,word1
);
625 r600_bytecode_export_read(ctx
->bc
, &output
, word0
,word1
);
626 r600_bytecode_add_output(ctx
->bc
, &output
);
630 static void r600_bytecode_from_byte_stream(struct r600_shader_ctx
*ctx
,
631 unsigned char * bytes
, unsigned num_bytes
)
633 unsigned bytes_read
= 0;
635 while (bytes_read
< num_bytes
) {
636 char inst_type
= bytes
[bytes_read
++];
639 bytes_read
= r600_alu_from_byte_stream(ctx
, bytes
,
643 bytes_read
= r600_tex_from_byte_stream(ctx
, bytes
,
647 bytes_read
= r600_fc_from_byte_stream(ctx
, bytes
,
651 r600_bytecode_add_cfinst(ctx
->bc
, CF_NATIVE
);
652 for (i
= 0; i
< 2; i
++) {
653 for (byte
= 0 ; byte
< 4; byte
++) {
654 ctx
->bc
->cf_last
->isa
[i
] |=
655 (bytes
[bytes_read
++] << (byte
* 8));
661 bytes_read
= r600_vtx_from_byte_stream(ctx
, bytes
,
665 bytes_read
= r600_export_from_byte_stream(ctx
, bytes
,
669 int32_t word0
= i32_from_byte_stream(bytes
, &bytes_read
);
670 int32_t word1
= i32_from_byte_stream(bytes
, &bytes_read
);
672 r600_bytecode_add_cf(ctx
->bc
);
673 ctx
->bc
->cf_last
->op
= r600_isa_cf_by_opcode(ctx
->bc
->isa
, G_SQ_CF_ALU_WORD1_CF_INST(word1
), 1);
674 ctx
->bc
->cf_last
->kcache
[0].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK0(word0
);
675 ctx
->bc
->cf_last
->kcache
[0].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(word1
);
676 ctx
->bc
->cf_last
->kcache
[0].mode
= G_SQ_CF_ALU_WORD0_KCACHE_MODE0(word0
);
677 ctx
->bc
->cf_last
->kcache
[1].bank
= G_SQ_CF_ALU_WORD0_KCACHE_BANK1(word0
);
678 ctx
->bc
->cf_last
->kcache
[1].addr
= G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(word1
);
679 ctx
->bc
->cf_last
->kcache
[1].mode
= G_SQ_CF_ALU_WORD1_KCACHE_MODE1(word1
);
683 /* XXX: Error here */
689 /* End bytestream -> r600 shader functions*/
691 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
693 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
696 if (i
->Instruction
.NumDstRegs
> 1) {
697 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
700 if (i
->Instruction
.Predicate
) {
701 R600_ERR("predicate unsupported\n");
705 if (i
->Instruction
.Label
) {
706 R600_ERR("label unsupported\n");
710 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
711 if (i
->Src
[j
].Register
.Dimension
) {
712 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
713 R600_ERR("unsupported src %d (dimension %d)\n", j
,
714 i
->Src
[j
].Register
.Dimension
);
719 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
720 if (i
->Dst
[j
].Register
.Dimension
) {
721 R600_ERR("unsupported dst (dimension)\n");
728 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
733 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
734 if (ctx
->shader
->input
[input
].centroid
)
736 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
737 /* if we have perspective add one */
738 if (ctx
->input_perspective
) {
740 /* if we have perspective centroid */
741 if (ctx
->input_centroid
)
744 if (ctx
->shader
->input
[input
].centroid
)
748 ctx
->shader
->input
[input
].ij_index
= ij_index
;
751 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
754 struct r600_bytecode_alu alu
;
755 int gpr
= 0, base_chan
= 0;
756 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
758 /* work out gpr and base_chan from index */
760 base_chan
= (2 * (ij_index
% 2)) + 1;
762 for (i
= 0; i
< 8; i
++) {
763 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
766 alu
.op
= ALU_OP2_INTERP_ZW
;
768 alu
.op
= ALU_OP2_INTERP_XY
;
770 if ((i
> 1) && (i
< 6)) {
771 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
775 alu
.dst
.chan
= i
% 4;
777 alu
.src
[0].sel
= gpr
;
778 alu
.src
[0].chan
= (base_chan
- (i
% 2));
780 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
782 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
785 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
792 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
795 struct r600_bytecode_alu alu
;
797 for (i
= 0; i
< 4; i
++) {
798 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
800 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
802 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
807 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
812 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
820 * Special export handling in shaders
822 * shader export ARRAY_BASE for EXPORT_POS:
825 * 62, 63 are clip distance vectors
827 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
828 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
829 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
830 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
831 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
832 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
833 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
834 * exclusive from render target index)
835 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
838 * shader export ARRAY_BASE for EXPORT_PIXEL:
840 * 61 computed Z vector
842 * The use of the values exported in the computed Z vector are controlled
843 * by DB_SHADER_CONTROL:
844 * Z_EXPORT_ENABLE - Z as a float in RED
845 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
846 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
847 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
848 * DB_SOURCE_FORMAT - export control restrictions
853 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
854 static int r600_spi_sid(struct r600_shader_io
* io
)
856 int index
, name
= io
->name
;
858 /* These params are handled differently, they don't need
859 * semantic indices, so we'll use 0 for them.
861 if (name
== TGSI_SEMANTIC_POSITION
||
862 name
== TGSI_SEMANTIC_PSIZE
||
863 name
== TGSI_SEMANTIC_FACE
)
866 if (name
== TGSI_SEMANTIC_GENERIC
) {
867 /* For generic params simply use sid from tgsi */
870 /* For non-generic params - pack name and sid into 8 bits */
871 index
= 0x80 | (name
<<3) | (io
->sid
);
874 /* Make sure that all really used indices have nonzero value, so
875 * we can just compare it to 0 later instead of comparing the name
876 * with different values to detect special cases. */
883 /* turn input into interpolate on EG */
884 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
888 if (ctx
->shader
->input
[index
].spi_sid
) {
889 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
890 if (ctx
->shader
->input
[index
].interpolate
> 0) {
891 evergreen_interp_assign_ij_index(ctx
, index
);
893 r
= evergreen_interp_alu(ctx
, index
);
896 r
= evergreen_interp_flat(ctx
, index
);
902 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
904 struct r600_bytecode_alu alu
;
906 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
907 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
909 for (i
= 0; i
< 4; i
++) {
910 memset(&alu
, 0, sizeof(alu
));
911 alu
.op
= ALU_OP3_CNDGT
;
914 alu
.dst
.sel
= gpr_front
;
915 alu
.src
[0].sel
= ctx
->face_gpr
;
916 alu
.src
[1].sel
= gpr_front
;
917 alu
.src
[2].sel
= gpr_back
;
924 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
931 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
933 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
934 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
936 switch (d
->Declaration
.File
) {
937 case TGSI_FILE_INPUT
:
938 i
= ctx
->shader
->ninput
;
939 ctx
->shader
->ninput
+= count
;
940 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
941 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
942 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
943 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
944 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
945 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
946 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
947 switch (ctx
->shader
->input
[i
].name
) {
948 case TGSI_SEMANTIC_FACE
:
949 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
951 case TGSI_SEMANTIC_COLOR
:
954 case TGSI_SEMANTIC_POSITION
:
955 ctx
->fragcoord_input
= i
;
958 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
959 if ((r
= evergreen_interp_input(ctx
, i
)))
963 for (j
= 1; j
< count
; ++j
) {
964 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
965 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
968 case TGSI_FILE_OUTPUT
:
969 i
= ctx
->shader
->noutput
++;
970 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
971 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
972 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
973 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
974 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
975 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
976 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
977 switch (d
->Semantic
.Name
) {
978 case TGSI_SEMANTIC_CLIPDIST
:
979 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
981 case TGSI_SEMANTIC_PSIZE
:
982 ctx
->shader
->vs_out_misc_write
= 1;
983 ctx
->shader
->vs_out_point_size
= 1;
985 case TGSI_SEMANTIC_CLIPVERTEX
:
986 ctx
->clip_vertex_write
= TRUE
;
990 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
991 switch (d
->Semantic
.Name
) {
992 case TGSI_SEMANTIC_COLOR
:
993 ctx
->shader
->nr_ps_max_color_exports
++;
998 case TGSI_FILE_TEMPORARY
:
999 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
1000 if (d
->Array
.ArrayID
) {
1001 r600_add_gpr_array(ctx
->shader
,
1002 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
1004 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
1009 case TGSI_FILE_CONSTANT
:
1010 case TGSI_FILE_SAMPLER
:
1011 case TGSI_FILE_ADDRESS
:
1014 case TGSI_FILE_SYSTEM_VALUE
:
1015 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
1016 if (!ctx
->native_integers
) {
1017 struct r600_bytecode_alu alu
;
1018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1020 alu
.op
= ALU_OP1_INT_TO_FLT
;
1022 alu
.src
[0].chan
= 3;
1029 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1033 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1036 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1042 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
1044 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
1048 * for evergreen we need to scan the shader to find the number of GPRs we need to
1049 * reserve for interpolation.
1051 * we need to know if we are going to emit
1052 * any centroid inputs
1053 * if perspective and linear are required
1055 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1060 ctx
->input_linear
= FALSE
;
1061 ctx
->input_perspective
= FALSE
;
1062 ctx
->input_centroid
= FALSE
;
1063 ctx
->num_interp_gpr
= 1;
1065 /* any centroid inputs */
1066 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1067 /* skip position/face */
1068 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1069 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
1071 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
1072 ctx
->input_linear
= TRUE
;
1073 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
1074 ctx
->input_perspective
= TRUE
;
1075 if (ctx
->info
.input_centroid
[i
])
1076 ctx
->input_centroid
= TRUE
;
1080 /* ignoring sample for now */
1081 if (ctx
->input_perspective
)
1083 if (ctx
->input_linear
)
1085 if (ctx
->input_centroid
)
1088 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
1090 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
1091 return ctx
->num_interp_gpr
;
1094 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1095 const struct tgsi_full_src_register
*tgsi_src
,
1096 struct r600_shader_src
*r600_src
)
1098 memset(r600_src
, 0, sizeof(*r600_src
));
1099 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1100 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1101 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1102 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1103 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1104 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1106 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1108 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1109 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1110 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1112 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1113 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
1114 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1117 index
= tgsi_src
->Register
.Index
;
1118 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1119 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1120 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1121 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1122 r600_src
->swizzle
[0] = 3;
1123 r600_src
->swizzle
[1] = 3;
1124 r600_src
->swizzle
[2] = 3;
1125 r600_src
->swizzle
[3] = 3;
1127 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1128 r600_src
->swizzle
[0] = 0;
1129 r600_src
->swizzle
[1] = 0;
1130 r600_src
->swizzle
[2] = 0;
1131 r600_src
->swizzle
[3] = 0;
1135 if (tgsi_src
->Register
.Indirect
)
1136 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1137 r600_src
->sel
= tgsi_src
->Register
.Index
;
1138 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1140 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1141 if (tgsi_src
->Register
.Dimension
) {
1142 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1147 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
1149 struct r600_bytecode_vtx vtx
;
1150 unsigned int ar_reg
;
1154 struct r600_bytecode_alu alu
;
1156 memset(&alu
, 0, sizeof(alu
));
1158 alu
.op
= ALU_OP2_ADD_INT
;
1159 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1161 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1162 alu
.src
[1].value
= offset
;
1164 alu
.dst
.sel
= dst_reg
;
1168 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1173 ar_reg
= ctx
->bc
->ar_reg
;
1176 memset(&vtx
, 0, sizeof(vtx
));
1177 vtx
.buffer_id
= cb_idx
;
1178 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
1179 vtx
.src_gpr
= ar_reg
;
1180 vtx
.mega_fetch_count
= 16;
1181 vtx
.dst_gpr
= dst_reg
;
1182 vtx
.dst_sel_x
= 0; /* SEL_X */
1183 vtx
.dst_sel_y
= 1; /* SEL_Y */
1184 vtx
.dst_sel_z
= 2; /* SEL_Z */
1185 vtx
.dst_sel_w
= 3; /* SEL_W */
1186 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1187 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1188 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1189 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1190 vtx
.endian
= r600_endian_swap(32);
1192 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1198 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1200 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1201 struct r600_bytecode_alu alu
;
1202 int i
, j
, k
, nconst
, r
;
1204 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1205 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1208 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1210 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1211 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1215 if (ctx
->src
[i
].rel
) {
1216 int treg
= r600_get_temp(ctx
);
1217 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
1220 ctx
->src
[i
].kc_bank
= 0;
1221 ctx
->src
[i
].sel
= treg
;
1222 ctx
->src
[i
].rel
= 0;
1225 int treg
= r600_get_temp(ctx
);
1226 for (k
= 0; k
< 4; k
++) {
1227 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1228 alu
.op
= ALU_OP1_MOV
;
1229 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1230 alu
.src
[0].chan
= k
;
1231 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1237 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1241 ctx
->src
[i
].sel
= treg
;
1249 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1250 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1252 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1253 struct r600_bytecode_alu alu
;
1254 int i
, j
, k
, nliteral
, r
;
1256 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1257 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1261 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1262 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1263 int treg
= r600_get_temp(ctx
);
1264 for (k
= 0; k
< 4; k
++) {
1265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1266 alu
.op
= ALU_OP1_MOV
;
1267 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1268 alu
.src
[0].chan
= k
;
1269 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1275 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1279 ctx
->src
[i
].sel
= treg
;
1286 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1288 int i
, r
, count
= ctx
->shader
->ninput
;
1290 for (i
= 0; i
< count
; i
++) {
1291 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1292 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1301 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
1302 struct r600_pipe_shader
*pipeshader
,
1303 struct r600_shader_key key
)
1305 struct r600_shader
*shader
= &pipeshader
->shader
;
1306 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1307 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1308 struct tgsi_full_immediate
*immediate
;
1309 struct tgsi_full_property
*property
;
1310 struct r600_shader_ctx ctx
;
1311 struct r600_bytecode_output output
[32];
1312 unsigned output_done
, noutput
;
1315 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
1316 /* Declarations used by llvm code */
1317 bool use_llvm
= false;
1318 unsigned char * inst_bytes
= NULL
;
1319 unsigned inst_byte_count
= 0;
1322 #ifdef R600_USE_LLVM
1323 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
1325 ctx
.bc
= &shader
->bc
;
1326 ctx
.shader
= shader
;
1327 ctx
.native_integers
= true;
1329 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
1330 rscreen
->msaa_texture_support
);
1331 ctx
.tokens
= tokens
;
1332 tgsi_scan_shader(tokens
, &ctx
.info
);
1333 shader
->indirect_files
= ctx
.info
.indirect_files
;
1334 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
1335 tgsi_parse_init(&ctx
.parse
, tokens
);
1336 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1337 shader
->processor_type
= ctx
.type
;
1338 ctx
.bc
->type
= shader
->processor_type
;
1341 ctx
.fragcoord_input
= -1;
1342 ctx
.colors_used
= 0;
1343 ctx
.clip_vertex_write
= 0;
1345 shader
->nr_ps_color_exports
= 0;
1346 shader
->nr_ps_max_color_exports
= 0;
1348 shader
->two_side
= key
.color_two_side
;
1350 /* register allocations */
1351 /* Values [0,127] correspond to GPR[0..127].
1352 * Values [128,159] correspond to constant buffer bank 0
1353 * Values [160,191] correspond to constant buffer bank 1
1354 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1355 * Values [256,287] correspond to constant buffer bank 2 (EG)
1356 * Values [288,319] correspond to constant buffer bank 3 (EG)
1357 * Other special values are shown in the list below.
1358 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1359 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1360 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1361 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1362 * 248 SQ_ALU_SRC_0: special constant 0.0.
1363 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1364 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1365 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1366 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1367 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1368 * 254 SQ_ALU_SRC_PV: previous vector result.
1369 * 255 SQ_ALU_SRC_PS: previous scalar result.
1371 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1372 ctx
.file_offset
[i
] = 0;
1374 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1375 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1376 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1378 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1379 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1382 #ifdef R600_USE_LLVM
1383 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1384 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1385 "indirect adressing. Falling back to TGSI "
1390 ctx
.use_llvm
= use_llvm
;
1393 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1394 ctx
.file_offset
[TGSI_FILE_INPUT
];
1396 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1397 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1398 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1400 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1401 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1403 /* Outside the GPR range. This will be translated to one of the
1404 * kcache banks later. */
1405 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1407 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1408 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1409 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1410 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1412 if (indirect_gprs
) {
1413 shader
->max_arrays
= 0;
1414 shader
->num_arrays
= 0;
1416 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1417 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1418 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1419 ctx
.file_offset
[TGSI_FILE_INPUT
],
1422 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1423 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1424 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1425 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1431 ctx
.literals
= NULL
;
1432 shader
->fs_write_all
= FALSE
;
1433 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1434 tgsi_parse_token(&ctx
.parse
);
1435 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1436 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1437 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1438 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1439 if(ctx
.literals
== NULL
) {
1443 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1444 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1445 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1446 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1449 case TGSI_TOKEN_TYPE_DECLARATION
:
1450 r
= tgsi_declaration(&ctx
);
1454 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1456 case TGSI_TOKEN_TYPE_PROPERTY
:
1457 property
= &ctx
.parse
.FullToken
.FullProperty
;
1458 switch (property
->Property
.PropertyName
) {
1459 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1460 if (property
->u
[0].Data
== 1)
1461 shader
->fs_write_all
= TRUE
;
1463 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1464 /* we don't need this one */
1469 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1475 /* Process two side if needed */
1476 if (shader
->two_side
&& ctx
.colors_used
) {
1477 int i
, count
= ctx
.shader
->ninput
;
1478 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1480 /* additional inputs will be allocated right after the existing inputs,
1481 * we won't need them after the color selection, so we don't need to
1482 * reserve these gprs for the rest of the shader code and to adjust
1483 * output offsets etc. */
1484 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1485 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1487 if (ctx
.face_gpr
== -1) {
1488 i
= ctx
.shader
->ninput
++;
1489 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1490 ctx
.shader
->input
[i
].spi_sid
= 0;
1491 ctx
.shader
->input
[i
].gpr
= gpr
++;
1492 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1495 for (i
= 0; i
< count
; i
++) {
1496 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1497 int ni
= ctx
.shader
->ninput
++;
1498 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1499 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1500 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1501 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1502 // TGSI to LLVM needs to know the lds position of inputs.
1503 // Non LLVM path computes it later (in process_twoside_color)
1504 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1505 ctx
.shader
->input
[i
].back_color_input
= ni
;
1506 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1507 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1514 /* LLVM backend setup */
1515 #ifdef R600_USE_LLVM
1517 struct radeon_llvm_context radeon_llvm_ctx
;
1519 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1520 boolean use_kill
= false;
1522 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1523 radeon_llvm_ctx
.type
= ctx
.type
;
1524 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1525 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1526 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1527 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1528 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1529 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1530 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1531 radeon_llvm_ctx
.stream_outputs
= &so
;
1532 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1533 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1534 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1536 if (r600_llvm_compile(mod
, &inst_bytes
, &inst_byte_count
,
1537 rscreen
->family
, ctx
.bc
, &use_kill
, dump
)) {
1539 radeon_llvm_dispose(&radeon_llvm_ctx
);
1541 fprintf(stderr
, "R600 LLVM backend failed to compile "
1542 "shader. Falling back to TGSI\n");
1544 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1545 ctx
.file_offset
[TGSI_FILE_INPUT
];
1548 ctx
.shader
->uses_kill
= use_kill
;
1549 radeon_llvm_dispose(&radeon_llvm_ctx
);
1552 /* End of LLVM backend setup */
1554 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1555 shader
->nr_ps_max_color_exports
= 8;
1558 if (ctx
.fragcoord_input
>= 0) {
1559 if (ctx
.bc
->chip_class
== CAYMAN
) {
1560 for (j
= 0 ; j
< 4; j
++) {
1561 struct r600_bytecode_alu alu
;
1562 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1563 alu
.op
= ALU_OP1_RECIP_IEEE
;
1564 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1565 alu
.src
[0].chan
= 3;
1567 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1569 alu
.dst
.write
= (j
== 3);
1571 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1575 struct r600_bytecode_alu alu
;
1576 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1577 alu
.op
= ALU_OP1_RECIP_IEEE
;
1578 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1579 alu
.src
[0].chan
= 3;
1581 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1585 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1590 if (shader
->two_side
&& ctx
.colors_used
) {
1591 if ((r
= process_twoside_color_inputs(&ctx
)))
1595 tgsi_parse_init(&ctx
.parse
, tokens
);
1596 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1597 tgsi_parse_token(&ctx
.parse
);
1598 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1599 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1600 r
= tgsi_is_supported(&ctx
);
1603 ctx
.max_driver_temp_used
= 0;
1604 /* reserve first tmp for everyone */
1605 r600_get_temp(&ctx
);
1607 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1608 if ((r
= tgsi_split_constant(&ctx
)))
1610 if ((r
= tgsi_split_literal_constant(&ctx
)))
1612 if (ctx
.bc
->chip_class
== CAYMAN
)
1613 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1614 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1615 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1617 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1618 r
= ctx
.inst_info
->process(&ctx
);
1628 /* Reset the temporary register counter. */
1629 ctx
.max_driver_temp_used
= 0;
1631 /* Get instructions if we are using the LLVM backend. */
1633 r600_bytecode_from_byte_stream(&ctx
, inst_bytes
, inst_byte_count
);
1637 noutput
= shader
->noutput
;
1639 if (ctx
.clip_vertex_write
) {
1640 unsigned clipdist_temp
[2];
1642 clipdist_temp
[0] = r600_get_temp(&ctx
);
1643 clipdist_temp
[1] = r600_get_temp(&ctx
);
1645 /* need to convert a clipvertex write into clipdistance writes and not export
1646 the clip vertex anymore */
1648 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1649 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1650 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1652 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1653 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1656 /* reset spi_sid for clipvertex output to avoid confusing spi */
1657 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1659 shader
->clip_dist_write
= 0xFF;
1661 for (i
= 0; i
< 8; i
++) {
1665 for (j
= 0; j
< 4; j
++) {
1666 struct r600_bytecode_alu alu
;
1667 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1668 alu
.op
= ALU_OP2_DOT4
;
1669 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1670 alu
.src
[0].chan
= j
;
1672 alu
.src
[1].sel
= 512 + i
;
1673 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1674 alu
.src
[1].chan
= j
;
1676 alu
.dst
.sel
= clipdist_temp
[oreg
];
1678 alu
.dst
.write
= (j
== ochan
);
1682 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1689 /* Add stream outputs. */
1690 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1691 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1693 /* Sanity checking. */
1694 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1695 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1699 for (i
= 0; i
< so
.num_outputs
; i
++) {
1700 if (so
.output
[i
].output_buffer
>= 4) {
1701 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1702 so
.output
[i
].output_buffer
);
1708 /* Initialize locations where the outputs are stored. */
1709 for (i
= 0; i
< so
.num_outputs
; i
++) {
1710 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1712 /* Lower outputs with dst_offset < start_component.
1714 * We can only output 4D vectors with a write mask, e.g. we can
1715 * only output the W component at offset 3, etc. If we want
1716 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1717 * to move it to X and output X. */
1718 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1719 unsigned tmp
= r600_get_temp(&ctx
);
1721 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1722 struct r600_bytecode_alu alu
;
1723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1724 alu
.op
= ALU_OP1_MOV
;
1725 alu
.src
[0].sel
= so_gpr
[i
];
1726 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1731 if (j
== so
.output
[i
].num_components
- 1)
1733 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1737 so
.output
[i
].start_component
= 0;
1742 /* Write outputs to buffers. */
1743 for (i
= 0; i
< so
.num_outputs
; i
++) {
1744 struct r600_bytecode_output output
;
1746 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1747 output
.gpr
= so_gpr
[i
];
1748 output
.elem_size
= so
.output
[i
].num_components
;
1749 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1750 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1751 output
.burst_count
= 1;
1753 /* array_size is an upper limit for the burst_count
1754 * with MEM_STREAM instructions */
1755 output
.array_size
= 0xFFF;
1756 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1757 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1758 switch (so
.output
[i
].output_buffer
) {
1760 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1763 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1766 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1769 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1773 switch (so
.output
[i
].output_buffer
) {
1775 output
.op
= CF_OP_MEM_STREAM0
;
1778 output
.op
= CF_OP_MEM_STREAM1
;
1781 output
.op
= CF_OP_MEM_STREAM2
;
1784 output
.op
= CF_OP_MEM_STREAM3
;
1788 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1795 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1796 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1797 output
[j
].gpr
= shader
->output
[i
].gpr
;
1798 output
[j
].elem_size
= 3;
1799 output
[j
].swizzle_x
= 0;
1800 output
[j
].swizzle_y
= 1;
1801 output
[j
].swizzle_z
= 2;
1802 output
[j
].swizzle_w
= 3;
1803 output
[j
].burst_count
= 1;
1804 output
[j
].barrier
= 1;
1805 output
[j
].type
= -1;
1806 output
[j
].op
= CF_OP_EXPORT
;
1808 case TGSI_PROCESSOR_VERTEX
:
1809 switch (shader
->output
[i
].name
) {
1810 case TGSI_SEMANTIC_POSITION
:
1811 output
[j
].array_base
= next_pos_base
++;
1812 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1815 case TGSI_SEMANTIC_PSIZE
:
1816 output
[j
].array_base
= next_pos_base
++;
1817 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1819 case TGSI_SEMANTIC_CLIPVERTEX
:
1822 case TGSI_SEMANTIC_CLIPDIST
:
1823 output
[j
].array_base
= next_pos_base
++;
1824 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1825 /* spi_sid is 0 for clipdistance outputs that were generated
1826 * for clipvertex - we don't need to pass them to PS */
1827 if (shader
->output
[i
].spi_sid
) {
1829 /* duplicate it as PARAM to pass to the pixel shader */
1830 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1831 output
[j
].array_base
= next_param_base
++;
1832 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1835 case TGSI_SEMANTIC_FOG
:
1836 output
[j
].swizzle_y
= 4; /* 0 */
1837 output
[j
].swizzle_z
= 4; /* 0 */
1838 output
[j
].swizzle_w
= 5; /* 1 */
1842 case TGSI_PROCESSOR_FRAGMENT
:
1843 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1844 /* never export more colors than the number of CBs */
1845 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1850 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1851 output
[j
].array_base
= next_pixel_base
++;
1852 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1853 shader
->nr_ps_color_exports
++;
1854 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1855 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1857 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1858 output
[j
].gpr
= shader
->output
[i
].gpr
;
1859 output
[j
].elem_size
= 3;
1860 output
[j
].swizzle_x
= 0;
1861 output
[j
].swizzle_y
= 1;
1862 output
[j
].swizzle_z
= 2;
1863 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1864 output
[j
].burst_count
= 1;
1865 output
[j
].barrier
= 1;
1866 output
[j
].array_base
= next_pixel_base
++;
1867 output
[j
].op
= CF_OP_EXPORT
;
1868 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1869 shader
->nr_ps_color_exports
++;
1872 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1873 output
[j
].array_base
= 61;
1874 output
[j
].swizzle_x
= 2;
1875 output
[j
].swizzle_y
= 7;
1876 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1877 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1878 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1879 output
[j
].array_base
= 61;
1880 output
[j
].swizzle_x
= 7;
1881 output
[j
].swizzle_y
= 1;
1882 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1883 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1885 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1891 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1896 if (output
[j
].type
==-1) {
1897 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1898 output
[j
].array_base
= next_param_base
++;
1902 /* add fake position export */
1903 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1904 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1906 output
[j
].elem_size
= 3;
1907 output
[j
].swizzle_x
= 7;
1908 output
[j
].swizzle_y
= 7;
1909 output
[j
].swizzle_z
= 7;
1910 output
[j
].swizzle_w
= 7;
1911 output
[j
].burst_count
= 1;
1912 output
[j
].barrier
= 1;
1913 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1914 output
[j
].array_base
= next_pos_base
;
1915 output
[j
].op
= CF_OP_EXPORT
;
1919 /* add fake param output for vertex shader if no param is exported */
1920 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1921 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1923 output
[j
].elem_size
= 3;
1924 output
[j
].swizzle_x
= 7;
1925 output
[j
].swizzle_y
= 7;
1926 output
[j
].swizzle_z
= 7;
1927 output
[j
].swizzle_w
= 7;
1928 output
[j
].burst_count
= 1;
1929 output
[j
].barrier
= 1;
1930 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1931 output
[j
].array_base
= 0;
1932 output
[j
].op
= CF_OP_EXPORT
;
1936 /* add fake pixel export */
1937 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1938 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1940 output
[j
].elem_size
= 3;
1941 output
[j
].swizzle_x
= 7;
1942 output
[j
].swizzle_y
= 7;
1943 output
[j
].swizzle_z
= 7;
1944 output
[j
].swizzle_w
= 7;
1945 output
[j
].burst_count
= 1;
1946 output
[j
].barrier
= 1;
1947 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1948 output
[j
].array_base
= 0;
1949 output
[j
].op
= CF_OP_EXPORT
;
1955 /* set export done on last export of each type */
1956 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1957 if (ctx
.bc
->chip_class
< CAYMAN
) {
1958 if (i
== (noutput
- 1)) {
1959 output
[i
].end_of_program
= 1;
1962 if (!(output_done
& (1 << output
[i
].type
))) {
1963 output_done
|= (1 << output
[i
].type
);
1964 output
[i
].op
= CF_OP_EXPORT_DONE
;
1967 /* add output to bytecode */
1969 for (i
= 0; i
< noutput
; i
++) {
1970 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1975 /* add program end */
1976 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1977 cm_bytecode_add_cf_end(ctx
.bc
);
1979 /* check GPR limit - we have 124 = 128 - 4
1980 * (4 are reserved as alu clause temporary registers) */
1981 if (ctx
.bc
->ngpr
> 124) {
1982 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1988 tgsi_parse_free(&ctx
.parse
);
1992 tgsi_parse_free(&ctx
.parse
);
1996 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1998 R600_ERR("%s tgsi opcode unsupported\n",
1999 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
2003 static int tgsi_end(struct r600_shader_ctx
*ctx
)
2008 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
2009 const struct r600_shader_src
*shader_src
,
2012 bc_src
->sel
= shader_src
->sel
;
2013 bc_src
->chan
= shader_src
->swizzle
[chan
];
2014 bc_src
->neg
= shader_src
->neg
;
2015 bc_src
->abs
= shader_src
->abs
;
2016 bc_src
->rel
= shader_src
->rel
;
2017 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
2018 bc_src
->kc_bank
= shader_src
->kc_bank
;
2021 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2027 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2029 bc_src
->neg
= !bc_src
->neg
;
2032 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2033 const struct tgsi_full_dst_register
*tgsi_dst
,
2035 struct r600_bytecode_alu_dst
*r600_dst
)
2037 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2039 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2040 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2041 r600_dst
->chan
= swizzle
;
2042 r600_dst
->write
= 1;
2043 if (tgsi_dst
->Register
.Indirect
)
2044 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2045 if (inst
->Instruction
.Saturate
) {
2046 r600_dst
->clamp
= 1;
2050 static int tgsi_last_instruction(unsigned writemask
)
2054 for (i
= 0; i
< 4; i
++) {
2055 if (writemask
& (1 << i
)) {
2062 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
2064 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2065 struct r600_bytecode_alu alu
;
2067 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2069 for (i
= 0; i
< lasti
+ 1; i
++) {
2070 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2074 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2076 alu
.op
= ctx
->inst_info
->op
;
2078 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2079 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2082 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2083 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2085 /* handle some special cases */
2086 switch (ctx
->inst_info
->tgsi_opcode
) {
2087 case TGSI_OPCODE_SUB
:
2088 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2090 case TGSI_OPCODE_ABS
:
2091 r600_bytecode_src_set_abs(&alu
.src
[0]);
2096 if (i
== lasti
|| trans_only
) {
2099 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2106 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2108 return tgsi_op2_s(ctx
, 0, 0);
2111 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2113 return tgsi_op2_s(ctx
, 1, 0);
2116 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2118 return tgsi_op2_s(ctx
, 0, 1);
2121 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2123 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2124 struct r600_bytecode_alu alu
;
2126 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2128 for (i
= 0; i
< lasti
+ 1; i
++) {
2130 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2133 alu
.op
= ctx
->inst_info
->op
;
2135 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2137 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2139 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2144 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2152 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2154 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2156 struct r600_bytecode_alu alu
;
2157 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2159 for (i
= 0 ; i
< last_slot
; i
++) {
2160 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2161 alu
.op
= ctx
->inst_info
->op
;
2162 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2163 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2165 /* RSQ should take the absolute value of src */
2166 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2167 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2170 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2171 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2173 if (i
== last_slot
- 1)
2175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2182 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2184 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2186 struct r600_bytecode_alu alu
;
2187 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2188 for (k
= 0; k
< last_slot
; k
++) {
2189 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2192 for (i
= 0 ; i
< 4; i
++) {
2193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2194 alu
.op
= ctx
->inst_info
->op
;
2195 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2196 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2198 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2199 alu
.dst
.write
= (i
== k
);
2202 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2211 * r600 - trunc to -PI..PI range
2212 * r700 - normalize by dividing by 2PI
2215 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2217 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2218 static float double_pi
= 3.1415926535 * 2;
2219 static float neg_pi
= -3.1415926535;
2222 struct r600_bytecode_alu alu
;
2224 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2225 alu
.op
= ALU_OP3_MULADD
;
2229 alu
.dst
.sel
= ctx
->temp_reg
;
2232 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2234 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2235 alu
.src
[1].chan
= 0;
2236 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2237 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2238 alu
.src
[2].chan
= 0;
2240 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2244 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2245 alu
.op
= ALU_OP1_FRACT
;
2248 alu
.dst
.sel
= ctx
->temp_reg
;
2251 alu
.src
[0].sel
= ctx
->temp_reg
;
2252 alu
.src
[0].chan
= 0;
2254 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2258 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2259 alu
.op
= ALU_OP3_MULADD
;
2263 alu
.dst
.sel
= ctx
->temp_reg
;
2266 alu
.src
[0].sel
= ctx
->temp_reg
;
2267 alu
.src
[0].chan
= 0;
2269 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2270 alu
.src
[1].chan
= 0;
2271 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2272 alu
.src
[2].chan
= 0;
2274 if (ctx
->bc
->chip_class
== R600
) {
2275 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2276 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2278 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2279 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2290 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2292 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2293 struct r600_bytecode_alu alu
;
2294 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2297 r
= tgsi_setup_trig(ctx
);
2302 for (i
= 0; i
< last_slot
; i
++) {
2303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2304 alu
.op
= ctx
->inst_info
->op
;
2307 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2308 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2310 alu
.src
[0].sel
= ctx
->temp_reg
;
2311 alu
.src
[0].chan
= 0;
2312 if (i
== last_slot
- 1)
2314 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2321 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2323 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2324 struct r600_bytecode_alu alu
;
2326 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2328 r
= tgsi_setup_trig(ctx
);
2332 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2333 alu
.op
= ctx
->inst_info
->op
;
2335 alu
.dst
.sel
= ctx
->temp_reg
;
2338 alu
.src
[0].sel
= ctx
->temp_reg
;
2339 alu
.src
[0].chan
= 0;
2341 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2345 /* replicate result */
2346 for (i
= 0; i
< lasti
+ 1; i
++) {
2347 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2350 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2351 alu
.op
= ALU_OP1_MOV
;
2353 alu
.src
[0].sel
= ctx
->temp_reg
;
2354 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2364 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2366 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2367 struct r600_bytecode_alu alu
;
2370 /* We'll only need the trig stuff if we are going to write to the
2371 * X or Y components of the destination vector.
2373 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2374 r
= tgsi_setup_trig(ctx
);
2380 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2381 if (ctx
->bc
->chip_class
== CAYMAN
) {
2382 for (i
= 0 ; i
< 3; i
++) {
2383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2384 alu
.op
= ALU_OP1_COS
;
2385 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2391 alu
.src
[0].sel
= ctx
->temp_reg
;
2392 alu
.src
[0].chan
= 0;
2395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2400 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2401 alu
.op
= ALU_OP1_COS
;
2402 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2404 alu
.src
[0].sel
= ctx
->temp_reg
;
2405 alu
.src
[0].chan
= 0;
2407 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2414 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2415 if (ctx
->bc
->chip_class
== CAYMAN
) {
2416 for (i
= 0 ; i
< 3; i
++) {
2417 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2418 alu
.op
= ALU_OP1_SIN
;
2419 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2424 alu
.src
[0].sel
= ctx
->temp_reg
;
2425 alu
.src
[0].chan
= 0;
2428 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2433 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2434 alu
.op
= ALU_OP1_SIN
;
2435 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2437 alu
.src
[0].sel
= ctx
->temp_reg
;
2438 alu
.src
[0].chan
= 0;
2440 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2447 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2448 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2450 alu
.op
= ALU_OP1_MOV
;
2452 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2454 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2455 alu
.src
[0].chan
= 0;
2459 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2465 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2466 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2468 alu
.op
= ALU_OP1_MOV
;
2470 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2472 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2473 alu
.src
[0].chan
= 0;
2477 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2485 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2487 struct r600_bytecode_alu alu
;
2490 for (i
= 0; i
< 4; i
++) {
2491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2492 alu
.op
= ctx
->inst_info
->op
;
2496 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2498 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2499 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2502 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2507 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2512 /* kill must be last in ALU */
2513 ctx
->bc
->force_add_cf
= 1;
2514 ctx
->shader
->uses_kill
= TRUE
;
2518 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2520 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2521 struct r600_bytecode_alu alu
;
2524 /* tmp.x = max(src.y, 0.0) */
2525 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2526 alu
.op
= ALU_OP2_MAX
;
2527 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2528 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2529 alu
.src
[1].chan
= 1;
2531 alu
.dst
.sel
= ctx
->temp_reg
;
2536 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2540 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2546 if (ctx
->bc
->chip_class
== CAYMAN
) {
2547 for (i
= 0; i
< 3; i
++) {
2548 /* tmp.z = log(tmp.x) */
2549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2550 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2551 alu
.src
[0].sel
= ctx
->temp_reg
;
2552 alu
.src
[0].chan
= 0;
2553 alu
.dst
.sel
= ctx
->temp_reg
;
2561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2566 /* tmp.z = log(tmp.x) */
2567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2568 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2569 alu
.src
[0].sel
= ctx
->temp_reg
;
2570 alu
.src
[0].chan
= 0;
2571 alu
.dst
.sel
= ctx
->temp_reg
;
2575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2580 chan
= alu
.dst
.chan
;
2583 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2584 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2585 alu
.op
= ALU_OP3_MUL_LIT
;
2586 alu
.src
[0].sel
= sel
;
2587 alu
.src
[0].chan
= chan
;
2588 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2589 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2590 alu
.dst
.sel
= ctx
->temp_reg
;
2595 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2599 if (ctx
->bc
->chip_class
== CAYMAN
) {
2600 for (i
= 0; i
< 3; i
++) {
2601 /* dst.z = exp(tmp.x) */
2602 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2603 alu
.op
= ALU_OP1_EXP_IEEE
;
2604 alu
.src
[0].sel
= ctx
->temp_reg
;
2605 alu
.src
[0].chan
= 0;
2606 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2612 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2617 /* dst.z = exp(tmp.x) */
2618 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2619 alu
.op
= ALU_OP1_EXP_IEEE
;
2620 alu
.src
[0].sel
= ctx
->temp_reg
;
2621 alu
.src
[0].chan
= 0;
2622 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2624 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2632 alu
.op
= ALU_OP1_MOV
;
2633 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2634 alu
.src
[0].chan
= 0;
2635 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2636 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2637 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2641 /* dst.y = max(src.x, 0.0) */
2642 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2643 alu
.op
= ALU_OP2_MAX
;
2644 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2645 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2646 alu
.src
[1].chan
= 0;
2647 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2648 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2649 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2655 alu
.op
= ALU_OP1_MOV
;
2656 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2657 alu
.src
[0].chan
= 0;
2658 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2659 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2661 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2668 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2670 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2671 struct r600_bytecode_alu alu
;
2674 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2677 * For state trackers other than OpenGL, we'll want to use
2678 * _RECIPSQRT_IEEE instead.
2680 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2682 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2683 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2684 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2686 alu
.dst
.sel
= ctx
->temp_reg
;
2689 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2692 /* replicate result */
2693 return tgsi_helper_tempx_replicate(ctx
);
2696 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2698 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2699 struct r600_bytecode_alu alu
;
2702 for (i
= 0; i
< 4; i
++) {
2703 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2704 alu
.src
[0].sel
= ctx
->temp_reg
;
2705 alu
.op
= ALU_OP1_MOV
;
2707 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2708 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2711 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2718 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2720 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2721 struct r600_bytecode_alu alu
;
2724 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2725 alu
.op
= ctx
->inst_info
->op
;
2726 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2727 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2729 alu
.dst
.sel
= ctx
->temp_reg
;
2732 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2735 /* replicate result */
2736 return tgsi_helper_tempx_replicate(ctx
);
2739 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2741 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2743 struct r600_bytecode_alu alu
;
2744 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2746 for (i
= 0; i
< 3; i
++) {
2747 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2748 alu
.op
= ALU_OP1_LOG_IEEE
;
2749 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2750 alu
.dst
.sel
= ctx
->temp_reg
;
2755 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2761 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2762 alu
.op
= ALU_OP2_MUL
;
2763 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2764 alu
.src
[1].sel
= ctx
->temp_reg
;
2765 alu
.dst
.sel
= ctx
->temp_reg
;
2768 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2772 for (i
= 0; i
< last_slot
; i
++) {
2773 /* POW(a,b) = EXP2(b * LOG2(a))*/
2774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2775 alu
.op
= ALU_OP1_EXP_IEEE
;
2776 alu
.src
[0].sel
= ctx
->temp_reg
;
2778 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2779 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2780 if (i
== last_slot
- 1)
2782 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2789 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2791 struct r600_bytecode_alu alu
;
2795 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2796 alu
.op
= ALU_OP1_LOG_IEEE
;
2797 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2798 alu
.dst
.sel
= ctx
->temp_reg
;
2801 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2805 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2806 alu
.op
= ALU_OP2_MUL
;
2807 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2808 alu
.src
[1].sel
= ctx
->temp_reg
;
2809 alu
.dst
.sel
= ctx
->temp_reg
;
2812 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2815 /* POW(a,b) = EXP2(b * LOG2(a))*/
2816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2817 alu
.op
= ALU_OP1_EXP_IEEE
;
2818 alu
.src
[0].sel
= ctx
->temp_reg
;
2819 alu
.dst
.sel
= ctx
->temp_reg
;
2822 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2825 return tgsi_helper_tempx_replicate(ctx
);
2828 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2830 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2831 struct r600_bytecode_alu alu
;
2833 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2834 int tmp0
= ctx
->temp_reg
;
2835 int tmp1
= r600_get_temp(ctx
);
2836 int tmp2
= r600_get_temp(ctx
);
2837 int tmp3
= r600_get_temp(ctx
);
2840 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2842 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2843 * 2. tmp0.z = lo (tmp0.x * src2)
2844 * 3. tmp0.w = -tmp0.z
2845 * 4. tmp0.y = hi (tmp0.x * src2)
2846 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2847 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2848 * 7. tmp1.x = tmp0.x - tmp0.w
2849 * 8. tmp1.y = tmp0.x + tmp0.w
2850 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2851 * 10. tmp0.z = hi(tmp0.x * src1) = q
2852 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2854 * 12. tmp0.w = src1 - tmp0.y = r
2855 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2856 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2860 * 15. tmp1.z = tmp0.z + 1 = q + 1
2861 * 16. tmp1.w = tmp0.z - 1 = q - 1
2865 * 15. tmp1.z = tmp0.w - src2 = r - src2
2866 * 16. tmp1.w = tmp0.w + src2 = r + src2
2870 * 17. tmp1.x = tmp1.x & tmp1.y
2872 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2873 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2875 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2876 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2880 * Same as unsigned, using abs values of the operands,
2881 * and fixing the sign of the result in the end.
2884 for (i
= 0; i
< 4; i
++) {
2885 if (!(write_mask
& (1<<i
)))
2890 /* tmp2.x = -src0 */
2891 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2892 alu
.op
= ALU_OP2_SUB_INT
;
2898 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2900 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2903 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2906 /* tmp2.y = -src1 */
2907 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2908 alu
.op
= ALU_OP2_SUB_INT
;
2914 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2916 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2919 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2922 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2923 /* it will be a sign of the quotient */
2926 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2927 alu
.op
= ALU_OP2_XOR_INT
;
2933 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2934 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2937 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2941 /* tmp2.x = |src0| */
2942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2943 alu
.op
= ALU_OP3_CNDGE_INT
;
2950 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2951 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2952 alu
.src
[2].sel
= tmp2
;
2953 alu
.src
[2].chan
= 0;
2956 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2959 /* tmp2.y = |src1| */
2960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2961 alu
.op
= ALU_OP3_CNDGE_INT
;
2968 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2969 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2970 alu
.src
[2].sel
= tmp2
;
2971 alu
.src
[2].chan
= 1;
2974 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2979 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2980 if (ctx
->bc
->chip_class
== CAYMAN
) {
2981 /* tmp3.x = u2f(src2) */
2982 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2983 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2990 alu
.src
[0].sel
= tmp2
;
2991 alu
.src
[0].chan
= 1;
2993 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2997 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3000 /* tmp0.x = recip(tmp3.x) */
3001 for (j
= 0 ; j
< 3; j
++) {
3002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3003 alu
.op
= ALU_OP1_RECIP_IEEE
;
3007 alu
.dst
.write
= (j
== 0);
3009 alu
.src
[0].sel
= tmp3
;
3010 alu
.src
[0].chan
= 0;
3014 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3019 alu
.op
= ALU_OP2_MUL
;
3021 alu
.src
[0].sel
= tmp0
;
3022 alu
.src
[0].chan
= 0;
3024 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3025 alu
.src
[1].value
= 0x4f800000;
3030 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3034 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3035 alu
.op
= ALU_OP1_FLT_TO_UINT
;
3041 alu
.src
[0].sel
= tmp3
;
3042 alu
.src
[0].chan
= 0;
3045 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3050 alu
.op
= ALU_OP1_RECIP_UINT
;
3057 alu
.src
[0].sel
= tmp2
;
3058 alu
.src
[0].chan
= 1;
3060 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3064 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3068 /* 2. tmp0.z = lo (tmp0.x * src2) */
3069 if (ctx
->bc
->chip_class
== CAYMAN
) {
3070 for (j
= 0 ; j
< 4; j
++) {
3071 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3072 alu
.op
= ALU_OP2_MULLO_UINT
;
3076 alu
.dst
.write
= (j
== 2);
3078 alu
.src
[0].sel
= tmp0
;
3079 alu
.src
[0].chan
= 0;
3081 alu
.src
[1].sel
= tmp2
;
3082 alu
.src
[1].chan
= 1;
3084 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3087 alu
.last
= (j
== 3);
3088 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3093 alu
.op
= ALU_OP2_MULLO_UINT
;
3099 alu
.src
[0].sel
= tmp0
;
3100 alu
.src
[0].chan
= 0;
3102 alu
.src
[1].sel
= tmp2
;
3103 alu
.src
[1].chan
= 1;
3105 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3109 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3113 /* 3. tmp0.w = -tmp0.z */
3114 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3115 alu
.op
= ALU_OP2_SUB_INT
;
3121 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3122 alu
.src
[1].sel
= tmp0
;
3123 alu
.src
[1].chan
= 2;
3126 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3129 /* 4. tmp0.y = hi (tmp0.x * src2) */
3130 if (ctx
->bc
->chip_class
== CAYMAN
) {
3131 for (j
= 0 ; j
< 4; j
++) {
3132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3133 alu
.op
= ALU_OP2_MULHI_UINT
;
3137 alu
.dst
.write
= (j
== 1);
3139 alu
.src
[0].sel
= tmp0
;
3140 alu
.src
[0].chan
= 0;
3143 alu
.src
[1].sel
= tmp2
;
3144 alu
.src
[1].chan
= 1;
3146 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3148 alu
.last
= (j
== 3);
3149 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3153 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3154 alu
.op
= ALU_OP2_MULHI_UINT
;
3160 alu
.src
[0].sel
= tmp0
;
3161 alu
.src
[0].chan
= 0;
3164 alu
.src
[1].sel
= tmp2
;
3165 alu
.src
[1].chan
= 1;
3167 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3171 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3175 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3177 alu
.op
= ALU_OP3_CNDE_INT
;
3184 alu
.src
[0].sel
= tmp0
;
3185 alu
.src
[0].chan
= 1;
3186 alu
.src
[1].sel
= tmp0
;
3187 alu
.src
[1].chan
= 3;
3188 alu
.src
[2].sel
= tmp0
;
3189 alu
.src
[2].chan
= 2;
3192 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3195 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3196 if (ctx
->bc
->chip_class
== CAYMAN
) {
3197 for (j
= 0 ; j
< 4; j
++) {
3198 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3199 alu
.op
= ALU_OP2_MULHI_UINT
;
3203 alu
.dst
.write
= (j
== 3);
3205 alu
.src
[0].sel
= tmp0
;
3206 alu
.src
[0].chan
= 2;
3208 alu
.src
[1].sel
= tmp0
;
3209 alu
.src
[1].chan
= 0;
3211 alu
.last
= (j
== 3);
3212 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3217 alu
.op
= ALU_OP2_MULHI_UINT
;
3223 alu
.src
[0].sel
= tmp0
;
3224 alu
.src
[0].chan
= 2;
3226 alu
.src
[1].sel
= tmp0
;
3227 alu
.src
[1].chan
= 0;
3230 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3234 /* 7. tmp1.x = tmp0.x - tmp0.w */
3235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3236 alu
.op
= ALU_OP2_SUB_INT
;
3242 alu
.src
[0].sel
= tmp0
;
3243 alu
.src
[0].chan
= 0;
3244 alu
.src
[1].sel
= tmp0
;
3245 alu
.src
[1].chan
= 3;
3248 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3251 /* 8. tmp1.y = tmp0.x + tmp0.w */
3252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3253 alu
.op
= ALU_OP2_ADD_INT
;
3259 alu
.src
[0].sel
= tmp0
;
3260 alu
.src
[0].chan
= 0;
3261 alu
.src
[1].sel
= tmp0
;
3262 alu
.src
[1].chan
= 3;
3265 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3268 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3270 alu
.op
= ALU_OP3_CNDE_INT
;
3277 alu
.src
[0].sel
= tmp0
;
3278 alu
.src
[0].chan
= 1;
3279 alu
.src
[1].sel
= tmp1
;
3280 alu
.src
[1].chan
= 1;
3281 alu
.src
[2].sel
= tmp1
;
3282 alu
.src
[2].chan
= 0;
3285 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3288 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3289 if (ctx
->bc
->chip_class
== CAYMAN
) {
3290 for (j
= 0 ; j
< 4; j
++) {
3291 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3292 alu
.op
= ALU_OP2_MULHI_UINT
;
3296 alu
.dst
.write
= (j
== 2);
3298 alu
.src
[0].sel
= tmp0
;
3299 alu
.src
[0].chan
= 0;
3302 alu
.src
[1].sel
= tmp2
;
3303 alu
.src
[1].chan
= 0;
3305 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3308 alu
.last
= (j
== 3);
3309 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3313 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3314 alu
.op
= ALU_OP2_MULHI_UINT
;
3320 alu
.src
[0].sel
= tmp0
;
3321 alu
.src
[0].chan
= 0;
3324 alu
.src
[1].sel
= tmp2
;
3325 alu
.src
[1].chan
= 0;
3327 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3331 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3335 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3336 if (ctx
->bc
->chip_class
== CAYMAN
) {
3337 for (j
= 0 ; j
< 4; j
++) {
3338 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3339 alu
.op
= ALU_OP2_MULLO_UINT
;
3343 alu
.dst
.write
= (j
== 1);
3346 alu
.src
[0].sel
= tmp2
;
3347 alu
.src
[0].chan
= 1;
3349 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3352 alu
.src
[1].sel
= tmp0
;
3353 alu
.src
[1].chan
= 2;
3355 alu
.last
= (j
== 3);
3356 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3360 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3361 alu
.op
= ALU_OP2_MULLO_UINT
;
3368 alu
.src
[0].sel
= tmp2
;
3369 alu
.src
[0].chan
= 1;
3371 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3374 alu
.src
[1].sel
= tmp0
;
3375 alu
.src
[1].chan
= 2;
3378 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3382 /* 12. tmp0.w = src1 - tmp0.y = r */
3383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3384 alu
.op
= ALU_OP2_SUB_INT
;
3391 alu
.src
[0].sel
= tmp2
;
3392 alu
.src
[0].chan
= 0;
3394 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3397 alu
.src
[1].sel
= tmp0
;
3398 alu
.src
[1].chan
= 1;
3401 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3404 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3406 alu
.op
= ALU_OP2_SETGE_UINT
;
3412 alu
.src
[0].sel
= tmp0
;
3413 alu
.src
[0].chan
= 3;
3415 alu
.src
[1].sel
= tmp2
;
3416 alu
.src
[1].chan
= 1;
3418 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3422 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3425 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3426 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3427 alu
.op
= ALU_OP2_SETGE_UINT
;
3434 alu
.src
[0].sel
= tmp2
;
3435 alu
.src
[0].chan
= 0;
3437 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3440 alu
.src
[1].sel
= tmp0
;
3441 alu
.src
[1].chan
= 1;
3444 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3447 if (mod
) { /* UMOD */
3449 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3450 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3451 alu
.op
= ALU_OP2_SUB_INT
;
3457 alu
.src
[0].sel
= tmp0
;
3458 alu
.src
[0].chan
= 3;
3461 alu
.src
[1].sel
= tmp2
;
3462 alu
.src
[1].chan
= 1;
3464 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3468 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3471 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3472 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3473 alu
.op
= ALU_OP2_ADD_INT
;
3479 alu
.src
[0].sel
= tmp0
;
3480 alu
.src
[0].chan
= 3;
3482 alu
.src
[1].sel
= tmp2
;
3483 alu
.src
[1].chan
= 1;
3485 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3489 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3494 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3495 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3496 alu
.op
= ALU_OP2_ADD_INT
;
3502 alu
.src
[0].sel
= tmp0
;
3503 alu
.src
[0].chan
= 2;
3504 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3507 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3510 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3512 alu
.op
= ALU_OP2_ADD_INT
;
3518 alu
.src
[0].sel
= tmp0
;
3519 alu
.src
[0].chan
= 2;
3520 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3523 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3528 /* 17. tmp1.x = tmp1.x & tmp1.y */
3529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3530 alu
.op
= ALU_OP2_AND_INT
;
3536 alu
.src
[0].sel
= tmp1
;
3537 alu
.src
[0].chan
= 0;
3538 alu
.src
[1].sel
= tmp1
;
3539 alu
.src
[1].chan
= 1;
3542 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3545 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3546 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3547 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3548 alu
.op
= ALU_OP3_CNDE_INT
;
3555 alu
.src
[0].sel
= tmp1
;
3556 alu
.src
[0].chan
= 0;
3557 alu
.src
[1].sel
= tmp0
;
3558 alu
.src
[1].chan
= mod
? 3 : 2;
3559 alu
.src
[2].sel
= tmp1
;
3560 alu
.src
[2].chan
= 2;
3563 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3566 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3568 alu
.op
= ALU_OP3_CNDE_INT
;
3576 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3579 alu
.src
[0].sel
= tmp1
;
3580 alu
.src
[0].chan
= 1;
3581 alu
.src
[1].sel
= tmp1
;
3582 alu
.src
[1].chan
= 3;
3583 alu
.src
[2].sel
= tmp0
;
3584 alu
.src
[2].chan
= 2;
3587 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3592 /* fix the sign of the result */
3596 /* tmp0.x = -tmp0.z */
3597 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3598 alu
.op
= ALU_OP2_SUB_INT
;
3604 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3605 alu
.src
[1].sel
= tmp0
;
3606 alu
.src
[1].chan
= 2;
3609 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3612 /* sign of the remainder is the same as the sign of src0 */
3613 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3615 alu
.op
= ALU_OP3_CNDGE_INT
;
3618 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3620 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3621 alu
.src
[1].sel
= tmp0
;
3622 alu
.src
[1].chan
= 2;
3623 alu
.src
[2].sel
= tmp0
;
3624 alu
.src
[2].chan
= 0;
3627 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3632 /* tmp0.x = -tmp0.z */
3633 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3634 alu
.op
= ALU_OP2_SUB_INT
;
3640 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3641 alu
.src
[1].sel
= tmp0
;
3642 alu
.src
[1].chan
= 2;
3645 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3648 /* fix the quotient sign (same as the sign of src0*src1) */
3649 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3651 alu
.op
= ALU_OP3_CNDGE_INT
;
3654 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3656 alu
.src
[0].sel
= tmp2
;
3657 alu
.src
[0].chan
= 2;
3658 alu
.src
[1].sel
= tmp0
;
3659 alu
.src
[1].chan
= 2;
3660 alu
.src
[2].sel
= tmp0
;
3661 alu
.src
[2].chan
= 0;
3664 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3672 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3674 return tgsi_divmod(ctx
, 0, 0);
3677 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3679 return tgsi_divmod(ctx
, 1, 0);
3682 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3684 return tgsi_divmod(ctx
, 0, 1);
3687 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3689 return tgsi_divmod(ctx
, 1, 1);
3693 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3695 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3696 struct r600_bytecode_alu alu
;
3698 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3699 int last_inst
= tgsi_last_instruction(write_mask
);
3701 for (i
= 0; i
< 4; i
++) {
3702 if (!(write_mask
& (1<<i
)))
3705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3706 alu
.op
= ALU_OP1_TRUNC
;
3708 alu
.dst
.sel
= ctx
->temp_reg
;
3712 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3715 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3720 for (i
= 0; i
< 4; i
++) {
3721 if (!(write_mask
& (1<<i
)))
3724 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3725 alu
.op
= ctx
->inst_info
->op
;
3727 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3729 alu
.src
[0].sel
= ctx
->temp_reg
;
3730 alu
.src
[0].chan
= i
;
3732 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3734 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3742 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3744 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3745 struct r600_bytecode_alu alu
;
3747 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3748 int last_inst
= tgsi_last_instruction(write_mask
);
3751 for (i
= 0; i
< 4; i
++) {
3752 if (!(write_mask
& (1<<i
)))
3755 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3756 alu
.op
= ALU_OP2_SUB_INT
;
3758 alu
.dst
.sel
= ctx
->temp_reg
;
3762 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3763 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3767 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3772 /* dst = (src >= 0 ? src : tmp) */
3773 for (i
= 0; i
< 4; i
++) {
3774 if (!(write_mask
& (1<<i
)))
3777 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3778 alu
.op
= ALU_OP3_CNDGE_INT
;
3782 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3784 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3785 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3786 alu
.src
[2].sel
= ctx
->temp_reg
;
3787 alu
.src
[2].chan
= i
;
3791 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3798 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3800 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3801 struct r600_bytecode_alu alu
;
3803 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3804 int last_inst
= tgsi_last_instruction(write_mask
);
3806 /* tmp = (src >= 0 ? src : -1) */
3807 for (i
= 0; i
< 4; i
++) {
3808 if (!(write_mask
& (1<<i
)))
3811 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3812 alu
.op
= ALU_OP3_CNDGE_INT
;
3815 alu
.dst
.sel
= ctx
->temp_reg
;
3819 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3820 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3821 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3825 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3830 /* dst = (tmp > 0 ? 1 : tmp) */
3831 for (i
= 0; i
< 4; i
++) {
3832 if (!(write_mask
& (1<<i
)))
3835 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3836 alu
.op
= ALU_OP3_CNDGT_INT
;
3840 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3842 alu
.src
[0].sel
= ctx
->temp_reg
;
3843 alu
.src
[0].chan
= i
;
3845 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3847 alu
.src
[2].sel
= ctx
->temp_reg
;
3848 alu
.src
[2].chan
= i
;
3852 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3861 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3863 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3864 struct r600_bytecode_alu alu
;
3867 /* tmp = (src > 0 ? 1 : src) */
3868 for (i
= 0; i
< 4; i
++) {
3869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3870 alu
.op
= ALU_OP3_CNDGT
;
3873 alu
.dst
.sel
= ctx
->temp_reg
;
3876 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3877 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3878 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3882 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3887 /* dst = (-tmp > 0 ? -1 : tmp) */
3888 for (i
= 0; i
< 4; i
++) {
3889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3890 alu
.op
= ALU_OP3_CNDGT
;
3892 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3894 alu
.src
[0].sel
= ctx
->temp_reg
;
3895 alu
.src
[0].chan
= i
;
3898 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3901 alu
.src
[2].sel
= ctx
->temp_reg
;
3902 alu
.src
[2].chan
= i
;
3906 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3913 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3915 struct r600_bytecode_alu alu
;
3918 for (i
= 0; i
< 4; i
++) {
3919 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3920 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3921 alu
.op
= ALU_OP0_NOP
;
3924 alu
.op
= ALU_OP1_MOV
;
3925 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3926 alu
.src
[0].sel
= ctx
->temp_reg
;
3927 alu
.src
[0].chan
= i
;
3932 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3939 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3941 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3942 struct r600_bytecode_alu alu
;
3944 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3946 for (i
= 0; i
< lasti
+ 1; i
++) {
3947 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3951 alu
.op
= ctx
->inst_info
->op
;
3952 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3953 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3956 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3963 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3970 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3972 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3973 struct r600_bytecode_alu alu
;
3976 for (i
= 0; i
< 4; i
++) {
3977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3978 alu
.op
= ctx
->inst_info
->op
;
3979 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3980 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3983 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3985 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3986 /* handle some special cases */
3987 switch (ctx
->inst_info
->tgsi_opcode
) {
3988 case TGSI_OPCODE_DP2
:
3990 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3991 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3994 case TGSI_OPCODE_DP3
:
3996 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3997 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4000 case TGSI_OPCODE_DPH
:
4002 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4003 alu
.src
[0].chan
= 0;
4013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4020 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
4023 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4024 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
4025 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
4026 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
4027 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
4030 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
4033 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4034 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
4037 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
4039 struct r600_bytecode_vtx vtx
;
4040 struct r600_bytecode_alu alu
;
4041 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4043 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4045 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4046 if (src_requires_loading
) {
4047 for (i
= 0; i
< 4; i
++) {
4048 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4049 alu
.op
= ALU_OP1_MOV
;
4050 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4051 alu
.dst
.sel
= ctx
->temp_reg
;
4056 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4060 src_gpr
= ctx
->temp_reg
;
4063 memset(&vtx
, 0, sizeof(vtx
));
4064 vtx
.op
= FETCH_OP_VFETCH
;
4065 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
4066 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
4067 vtx
.src_gpr
= src_gpr
;
4068 vtx
.mega_fetch_count
= 16;
4069 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4070 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
4071 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
4072 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4073 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4074 vtx
.use_const_fields
= 1;
4075 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4077 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4080 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4083 for (i
= 0; i
< 4; i
++) {
4084 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4085 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4088 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4089 alu
.op
= ALU_OP2_AND_INT
;
4092 alu
.dst
.sel
= vtx
.dst_gpr
;
4095 alu
.src
[0].sel
= vtx
.dst_gpr
;
4096 alu
.src
[0].chan
= i
;
4098 alu
.src
[1].sel
= 512 + (id
* 2);
4099 alu
.src
[1].chan
= i
% 4;
4100 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4109 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4110 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4111 alu
.op
= ALU_OP2_OR_INT
;
4114 alu
.dst
.sel
= vtx
.dst_gpr
;
4117 alu
.src
[0].sel
= vtx
.dst_gpr
;
4118 alu
.src
[0].chan
= 3;
4120 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4121 alu
.src
[1].chan
= 0;
4122 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4125 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4132 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4134 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4135 struct r600_bytecode_alu alu
;
4137 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4139 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4140 alu
.op
= ALU_OP1_MOV
;
4142 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4143 alu
.src
[0].sel
= 512 + (id
/ 4);
4144 alu
.src
[0].chan
= id
% 4;
4146 /* r600 we have them at channel 2 of the second dword */
4147 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4148 alu
.src
[0].chan
= 1;
4150 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4151 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4153 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4159 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4161 static float one_point_five
= 1.5f
;
4162 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4163 struct r600_bytecode_tex tex
;
4164 struct r600_bytecode_alu alu
;
4168 bool read_compressed_msaa
= ctx
->bc
->msaa_texture_mode
== MSAA_TEXTURE_COMPRESSED
&&
4169 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4170 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4171 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4172 /* Texture fetch instructions can only use gprs as source.
4173 * Also they cannot negate the source or take the absolute value */
4174 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4175 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4176 read_compressed_msaa
;
4177 boolean src_loaded
= FALSE
;
4178 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4179 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4180 boolean has_txq_cube_array_z
= false;
4182 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4183 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4184 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4185 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4186 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4187 has_txq_cube_array_z
= true;
4190 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4191 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4192 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4193 sampler_src_reg
= 2;
4195 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4197 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4198 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4199 ctx
->shader
->uses_tex_buffers
= true;
4200 return r600_do_buffer_txq(ctx
);
4202 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4203 if (ctx
->bc
->chip_class
< EVERGREEN
)
4204 ctx
->shader
->uses_tex_buffers
= true;
4205 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4209 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4210 /* get offset values */
4211 if (inst
->Texture
.NumOffsets
) {
4212 assert(inst
->Texture
.NumOffsets
== 1);
4214 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4215 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4216 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4218 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4219 /* TGSI moves the sampler to src reg 3 for TXD */
4220 sampler_src_reg
= 3;
4222 for (i
= 1; i
< 3; i
++) {
4223 /* set gradients h/v */
4224 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4225 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4226 FETCH_OP_SET_GRADIENTS_V
;
4227 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4228 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4230 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4231 tex
.src_gpr
= r600_get_temp(ctx
);
4237 for (j
= 0; j
< 4; j
++) {
4238 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4239 alu
.op
= ALU_OP1_MOV
;
4240 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4241 alu
.dst
.sel
= tex
.src_gpr
;
4246 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4252 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4253 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4254 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4255 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4256 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4257 tex
.src_rel
= ctx
->src
[i
].rel
;
4259 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4260 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4261 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4262 tex
.coord_type_x
= 1;
4263 tex
.coord_type_y
= 1;
4264 tex
.coord_type_z
= 1;
4265 tex
.coord_type_w
= 1;
4267 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4271 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4273 /* Add perspective divide */
4274 if (ctx
->bc
->chip_class
== CAYMAN
) {
4276 for (i
= 0; i
< 3; i
++) {
4277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4278 alu
.op
= ALU_OP1_RECIP_IEEE
;
4279 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4281 alu
.dst
.sel
= ctx
->temp_reg
;
4287 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4294 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4295 alu
.op
= ALU_OP1_RECIP_IEEE
;
4296 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4298 alu
.dst
.sel
= ctx
->temp_reg
;
4299 alu
.dst
.chan
= out_chan
;
4302 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4307 for (i
= 0; i
< 3; i
++) {
4308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4309 alu
.op
= ALU_OP2_MUL
;
4310 alu
.src
[0].sel
= ctx
->temp_reg
;
4311 alu
.src
[0].chan
= out_chan
;
4312 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4313 alu
.dst
.sel
= ctx
->temp_reg
;
4316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4320 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4321 alu
.op
= ALU_OP1_MOV
;
4322 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4323 alu
.src
[0].chan
= 0;
4324 alu
.dst
.sel
= ctx
->temp_reg
;
4328 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4332 src_gpr
= ctx
->temp_reg
;
4335 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4336 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4337 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4338 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4339 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4340 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4342 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4343 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4345 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4346 for (i
= 0; i
< 4; i
++) {
4347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4348 alu
.op
= ALU_OP2_CUBE
;
4349 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4350 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4351 alu
.dst
.sel
= ctx
->temp_reg
;
4356 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4361 /* tmp1.z = RCP_e(|tmp1.z|) */
4362 if (ctx
->bc
->chip_class
== CAYMAN
) {
4363 for (i
= 0; i
< 3; i
++) {
4364 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4365 alu
.op
= ALU_OP1_RECIP_IEEE
;
4366 alu
.src
[0].sel
= ctx
->temp_reg
;
4367 alu
.src
[0].chan
= 2;
4369 alu
.dst
.sel
= ctx
->temp_reg
;
4375 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4380 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4381 alu
.op
= ALU_OP1_RECIP_IEEE
;
4382 alu
.src
[0].sel
= ctx
->temp_reg
;
4383 alu
.src
[0].chan
= 2;
4385 alu
.dst
.sel
= ctx
->temp_reg
;
4389 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4394 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4395 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4396 * muladd has no writemask, have to use another temp
4398 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4399 alu
.op
= ALU_OP3_MULADD
;
4402 alu
.src
[0].sel
= ctx
->temp_reg
;
4403 alu
.src
[0].chan
= 0;
4404 alu
.src
[1].sel
= ctx
->temp_reg
;
4405 alu
.src
[1].chan
= 2;
4407 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4408 alu
.src
[2].chan
= 0;
4409 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4411 alu
.dst
.sel
= ctx
->temp_reg
;
4415 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4419 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4420 alu
.op
= ALU_OP3_MULADD
;
4423 alu
.src
[0].sel
= ctx
->temp_reg
;
4424 alu
.src
[0].chan
= 1;
4425 alu
.src
[1].sel
= ctx
->temp_reg
;
4426 alu
.src
[1].chan
= 2;
4428 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4429 alu
.src
[2].chan
= 0;
4430 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4432 alu
.dst
.sel
= ctx
->temp_reg
;
4437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4440 /* write initial compare value into Z component
4441 - W src 0 for shadow cube
4442 - X src 1 for shadow cube array */
4443 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4444 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4445 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4446 alu
.op
= ALU_OP1_MOV
;
4447 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4448 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4450 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4451 alu
.dst
.sel
= ctx
->temp_reg
;
4455 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4460 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4461 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4462 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4463 int mytmp
= r600_get_temp(ctx
);
4464 static const float eight
= 8.0f
;
4465 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4466 alu
.op
= ALU_OP1_MOV
;
4467 alu
.src
[0].sel
= ctx
->temp_reg
;
4468 alu
.src
[0].chan
= 3;
4469 alu
.dst
.sel
= mytmp
;
4473 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4477 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4478 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4479 alu
.op
= ALU_OP3_MULADD
;
4481 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4482 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4483 alu
.src
[1].chan
= 0;
4484 alu
.src
[1].value
= *(uint32_t *)&eight
;
4485 alu
.src
[2].sel
= mytmp
;
4486 alu
.src
[2].chan
= 0;
4487 alu
.dst
.sel
= ctx
->temp_reg
;
4491 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4494 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4495 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4496 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4497 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4498 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4499 tex
.src_gpr
= r600_get_temp(ctx
);
4504 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4505 tex
.coord_type_x
= 1;
4506 tex
.coord_type_y
= 1;
4507 tex
.coord_type_z
= 1;
4508 tex
.coord_type_w
= 1;
4509 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4510 alu
.op
= ALU_OP1_MOV
;
4511 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4512 alu
.dst
.sel
= tex
.src_gpr
;
4516 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4520 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4527 /* for cube forms of lod and bias we need to route things */
4528 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4529 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4530 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4531 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4533 alu
.op
= ALU_OP1_MOV
;
4534 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4535 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4536 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4538 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4539 alu
.dst
.sel
= ctx
->temp_reg
;
4543 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4549 src_gpr
= ctx
->temp_reg
;
4552 if (src_requires_loading
&& !src_loaded
) {
4553 for (i
= 0; i
< 4; i
++) {
4554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4555 alu
.op
= ALU_OP1_MOV
;
4556 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4557 alu
.dst
.sel
= ctx
->temp_reg
;
4562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4567 src_gpr
= ctx
->temp_reg
;
4570 /* Obtain the sample index for reading a compressed MSAA color texture.
4571 * To read the FMASK, we use the ldfptr instruction, which tells us
4572 * where the samples are stored.
4573 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4574 * which is the identity mapping. Each nibble says which physical sample
4575 * should be fetched to get that sample.
4577 * Assume src.z contains the sample index. It should be modified like this:
4578 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4579 * Then fetch the texel with src.
4581 if (read_compressed_msaa
) {
4582 unsigned sample_chan
= 3;
4583 unsigned temp
= r600_get_temp(ctx
);
4586 /* temp.w = ldfptr() */
4587 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4588 tex
.op
= FETCH_OP_LD
;
4589 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4590 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4591 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4592 tex
.src_gpr
= src_gpr
;
4594 tex
.dst_sel_x
= 7; /* mask out these components */
4597 tex
.dst_sel_w
= 0; /* store X */
4602 tex
.offset_x
= offset_x
;
4603 tex
.offset_y
= offset_y
;
4604 tex
.offset_z
= offset_z
;
4605 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4609 /* temp.x = sample_index*4 */
4610 if (ctx
->bc
->chip_class
== CAYMAN
) {
4611 for (i
= 0 ; i
< 4; i
++) {
4612 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4613 alu
.op
= ALU_OP2_MULLO_INT
;
4614 alu
.src
[0].sel
= src_gpr
;
4615 alu
.src
[0].chan
= sample_chan
;
4616 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4617 alu
.src
[1].value
= 4;
4620 alu
.dst
.write
= i
== 0;
4623 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4628 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4629 alu
.op
= ALU_OP2_MULLO_INT
;
4630 alu
.src
[0].sel
= src_gpr
;
4631 alu
.src
[0].chan
= sample_chan
;
4632 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4633 alu
.src
[1].value
= 4;
4638 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4643 /* sample_index = temp.w >> temp.x */
4644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4645 alu
.op
= ALU_OP2_LSHR_INT
;
4646 alu
.src
[0].sel
= temp
;
4647 alu
.src
[0].chan
= 3;
4648 alu
.src
[1].sel
= temp
;
4649 alu
.src
[1].chan
= 0;
4650 alu
.dst
.sel
= src_gpr
;
4651 alu
.dst
.chan
= sample_chan
;
4654 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4658 /* sample_index & 0xF */
4659 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4660 alu
.op
= ALU_OP2_AND_INT
;
4661 alu
.src
[0].sel
= src_gpr
;
4662 alu
.src
[0].chan
= sample_chan
;
4663 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4664 alu
.src
[1].value
= 0xF;
4665 alu
.dst
.sel
= src_gpr
;
4666 alu
.dst
.chan
= sample_chan
;
4669 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4673 /* visualize the FMASK */
4674 for (i
= 0; i
< 4; i
++) {
4675 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4676 alu
.op
= ALU_OP1_INT_TO_FLT
;
4677 alu
.src
[0].sel
= src_gpr
;
4678 alu
.src
[0].chan
= sample_chan
;
4679 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4683 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4691 /* does this shader want a num layers from TXQ for a cube array? */
4692 if (has_txq_cube_array_z
) {
4693 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4695 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4696 alu
.op
= ALU_OP1_MOV
;
4698 alu
.src
[0].sel
= 512 + (id
/ 4);
4699 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4700 alu
.src
[0].chan
= id
% 4;
4701 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4703 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4706 /* disable writemask from texture instruction */
4707 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4710 opcode
= ctx
->inst_info
->op
;
4711 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4712 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4713 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4714 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4715 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4716 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4717 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4719 case FETCH_OP_SAMPLE
:
4720 opcode
= FETCH_OP_SAMPLE_C
;
4722 case FETCH_OP_SAMPLE_L
:
4723 opcode
= FETCH_OP_SAMPLE_C_L
;
4725 case FETCH_OP_SAMPLE_LB
:
4726 opcode
= FETCH_OP_SAMPLE_C_LB
;
4728 case FETCH_OP_SAMPLE_G
:
4729 opcode
= FETCH_OP_SAMPLE_C_G
;
4734 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4737 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4738 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4739 tex
.src_gpr
= src_gpr
;
4740 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4741 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4742 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4743 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4744 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4746 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4751 } else if (src_loaded
) {
4757 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4758 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4759 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4760 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4761 tex
.src_rel
= ctx
->src
[0].rel
;
4764 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4765 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4766 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4767 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4771 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4774 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4775 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4776 tex
.coord_type_x
= 1;
4777 tex
.coord_type_y
= 1;
4779 tex
.coord_type_z
= 1;
4780 tex
.coord_type_w
= 1;
4782 tex
.offset_x
= offset_x
;
4783 tex
.offset_y
= offset_y
;
4784 tex
.offset_z
= offset_z
;
4786 /* Put the depth for comparison in W.
4787 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4788 * Some instructions expect the depth in Z. */
4789 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4790 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4791 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4792 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4793 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4794 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4795 tex
.src_sel_w
= tex
.src_sel_z
;
4798 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4799 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4800 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4801 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4802 /* the array index is read from Y */
4803 tex
.coord_type_y
= 0;
4805 /* the array index is read from Z */
4806 tex
.coord_type_z
= 0;
4807 tex
.src_sel_z
= tex
.src_sel_y
;
4809 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4810 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4811 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4812 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4813 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4814 /* the array index is read from Z */
4815 tex
.coord_type_z
= 0;
4817 /* mask unused source components */
4818 if (opcode
== FETCH_OP_SAMPLE
) {
4819 switch (inst
->Texture
.Texture
) {
4820 case TGSI_TEXTURE_2D
:
4821 case TGSI_TEXTURE_RECT
:
4825 case TGSI_TEXTURE_1D_ARRAY
:
4829 case TGSI_TEXTURE_1D
:
4837 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4841 /* add shadow ambient support - gallium doesn't do it yet */
4845 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4847 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4848 struct r600_bytecode_alu alu
;
4849 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4853 /* optimize if it's just an equal balance */
4854 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4855 for (i
= 0; i
< lasti
+ 1; i
++) {
4856 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4859 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4860 alu
.op
= ALU_OP2_ADD
;
4861 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4862 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4864 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4869 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4877 for (i
= 0; i
< lasti
+ 1; i
++) {
4878 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4881 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4882 alu
.op
= ALU_OP2_ADD
;
4883 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4884 alu
.src
[0].chan
= 0;
4885 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4886 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4887 alu
.dst
.sel
= ctx
->temp_reg
;
4893 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4898 /* (1 - src0) * src2 */
4899 for (i
= 0; i
< lasti
+ 1; i
++) {
4900 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4903 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4904 alu
.op
= ALU_OP2_MUL
;
4905 alu
.src
[0].sel
= ctx
->temp_reg
;
4906 alu
.src
[0].chan
= i
;
4907 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4908 alu
.dst
.sel
= ctx
->temp_reg
;
4914 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4919 /* src0 * src1 + (1 - src0) * src2 */
4920 for (i
= 0; i
< lasti
+ 1; i
++) {
4921 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4925 alu
.op
= ALU_OP3_MULADD
;
4927 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4928 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4929 alu
.src
[2].sel
= ctx
->temp_reg
;
4930 alu
.src
[2].chan
= i
;
4932 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4944 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4946 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4947 struct r600_bytecode_alu alu
;
4949 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4951 for (i
= 0; i
< lasti
+ 1; i
++) {
4952 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4955 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4956 alu
.op
= ALU_OP3_CNDGE
;
4957 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4958 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4959 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4960 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4966 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4973 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4975 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4976 struct r600_bytecode_alu alu
;
4978 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4980 for (i
= 0; i
< lasti
+ 1; i
++) {
4981 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4985 alu
.op
= ALU_OP3_CNDGE_INT
;
4986 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4987 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4988 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4989 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4995 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5002 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
5004 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5005 static const unsigned int src0_swizzle
[] = {2, 0, 1};
5006 static const unsigned int src1_swizzle
[] = {1, 2, 0};
5007 struct r600_bytecode_alu alu
;
5008 uint32_t use_temp
= 0;
5011 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
5014 for (i
= 0; i
< 4; i
++) {
5015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5016 alu
.op
= ALU_OP2_MUL
;
5018 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5019 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
5021 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5022 alu
.src
[0].chan
= i
;
5023 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5024 alu
.src
[1].chan
= i
;
5027 alu
.dst
.sel
= ctx
->temp_reg
;
5033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5038 for (i
= 0; i
< 4; i
++) {
5039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5040 alu
.op
= ALU_OP3_MULADD
;
5043 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
5044 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
5046 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5047 alu
.src
[0].chan
= i
;
5048 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5049 alu
.src
[1].chan
= i
;
5052 alu
.src
[2].sel
= ctx
->temp_reg
;
5054 alu
.src
[2].chan
= i
;
5057 alu
.dst
.sel
= ctx
->temp_reg
;
5059 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5065 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5070 return tgsi_helper_copy(ctx
, inst
);
5074 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
5076 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5077 struct r600_bytecode_alu alu
;
5081 /* result.x = 2^floor(src); */
5082 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5085 alu
.op
= ALU_OP1_FLOOR
;
5086 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5088 alu
.dst
.sel
= ctx
->temp_reg
;
5092 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5096 if (ctx
->bc
->chip_class
== CAYMAN
) {
5097 for (i
= 0; i
< 3; i
++) {
5098 alu
.op
= ALU_OP1_EXP_IEEE
;
5099 alu
.src
[0].sel
= ctx
->temp_reg
;
5100 alu
.src
[0].chan
= 0;
5102 alu
.dst
.sel
= ctx
->temp_reg
;
5104 alu
.dst
.write
= i
== 0;
5106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5111 alu
.op
= ALU_OP1_EXP_IEEE
;
5112 alu
.src
[0].sel
= ctx
->temp_reg
;
5113 alu
.src
[0].chan
= 0;
5115 alu
.dst
.sel
= ctx
->temp_reg
;
5119 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5125 /* result.y = tmp - floor(tmp); */
5126 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5127 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5129 alu
.op
= ALU_OP1_FRACT
;
5130 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5132 alu
.dst
.sel
= ctx
->temp_reg
;
5134 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5143 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5148 /* result.z = RoughApprox2ToX(tmp);*/
5149 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5150 if (ctx
->bc
->chip_class
== CAYMAN
) {
5151 for (i
= 0; i
< 3; i
++) {
5152 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5153 alu
.op
= ALU_OP1_EXP_IEEE
;
5154 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5156 alu
.dst
.sel
= ctx
->temp_reg
;
5163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5168 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5169 alu
.op
= ALU_OP1_EXP_IEEE
;
5170 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5172 alu
.dst
.sel
= ctx
->temp_reg
;
5178 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5184 /* result.w = 1.0;*/
5185 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5186 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5188 alu
.op
= ALU_OP1_MOV
;
5189 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5190 alu
.src
[0].chan
= 0;
5192 alu
.dst
.sel
= ctx
->temp_reg
;
5196 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5200 return tgsi_helper_copy(ctx
, inst
);
5203 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5205 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5206 struct r600_bytecode_alu alu
;
5210 /* result.x = floor(log2(|src|)); */
5211 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5212 if (ctx
->bc
->chip_class
== CAYMAN
) {
5213 for (i
= 0; i
< 3; i
++) {
5214 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5216 alu
.op
= ALU_OP1_LOG_IEEE
;
5217 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5218 r600_bytecode_src_set_abs(&alu
.src
[0]);
5220 alu
.dst
.sel
= ctx
->temp_reg
;
5226 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5234 alu
.op
= ALU_OP1_LOG_IEEE
;
5235 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5236 r600_bytecode_src_set_abs(&alu
.src
[0]);
5238 alu
.dst
.sel
= ctx
->temp_reg
;
5242 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5247 alu
.op
= ALU_OP1_FLOOR
;
5248 alu
.src
[0].sel
= ctx
->temp_reg
;
5249 alu
.src
[0].chan
= 0;
5251 alu
.dst
.sel
= ctx
->temp_reg
;
5256 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5261 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5262 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5264 if (ctx
->bc
->chip_class
== CAYMAN
) {
5265 for (i
= 0; i
< 3; i
++) {
5266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5268 alu
.op
= ALU_OP1_LOG_IEEE
;
5269 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5270 r600_bytecode_src_set_abs(&alu
.src
[0]);
5272 alu
.dst
.sel
= ctx
->temp_reg
;
5279 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5284 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5286 alu
.op
= ALU_OP1_LOG_IEEE
;
5287 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5288 r600_bytecode_src_set_abs(&alu
.src
[0]);
5290 alu
.dst
.sel
= ctx
->temp_reg
;
5295 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5302 alu
.op
= ALU_OP1_FLOOR
;
5303 alu
.src
[0].sel
= ctx
->temp_reg
;
5304 alu
.src
[0].chan
= 1;
5306 alu
.dst
.sel
= ctx
->temp_reg
;
5311 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5315 if (ctx
->bc
->chip_class
== CAYMAN
) {
5316 for (i
= 0; i
< 3; i
++) {
5317 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5318 alu
.op
= ALU_OP1_EXP_IEEE
;
5319 alu
.src
[0].sel
= ctx
->temp_reg
;
5320 alu
.src
[0].chan
= 1;
5322 alu
.dst
.sel
= ctx
->temp_reg
;
5329 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5335 alu
.op
= ALU_OP1_EXP_IEEE
;
5336 alu
.src
[0].sel
= ctx
->temp_reg
;
5337 alu
.src
[0].chan
= 1;
5339 alu
.dst
.sel
= ctx
->temp_reg
;
5344 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5349 if (ctx
->bc
->chip_class
== CAYMAN
) {
5350 for (i
= 0; i
< 3; i
++) {
5351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5352 alu
.op
= ALU_OP1_RECIP_IEEE
;
5353 alu
.src
[0].sel
= ctx
->temp_reg
;
5354 alu
.src
[0].chan
= 1;
5356 alu
.dst
.sel
= ctx
->temp_reg
;
5363 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5368 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5369 alu
.op
= ALU_OP1_RECIP_IEEE
;
5370 alu
.src
[0].sel
= ctx
->temp_reg
;
5371 alu
.src
[0].chan
= 1;
5373 alu
.dst
.sel
= ctx
->temp_reg
;
5378 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5385 alu
.op
= ALU_OP2_MUL
;
5387 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5388 r600_bytecode_src_set_abs(&alu
.src
[0]);
5390 alu
.src
[1].sel
= ctx
->temp_reg
;
5391 alu
.src
[1].chan
= 1;
5393 alu
.dst
.sel
= ctx
->temp_reg
;
5398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5403 /* result.z = log2(|src|);*/
5404 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5405 if (ctx
->bc
->chip_class
== CAYMAN
) {
5406 for (i
= 0; i
< 3; i
++) {
5407 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5409 alu
.op
= ALU_OP1_LOG_IEEE
;
5410 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5411 r600_bytecode_src_set_abs(&alu
.src
[0]);
5413 alu
.dst
.sel
= ctx
->temp_reg
;
5420 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5425 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5427 alu
.op
= ALU_OP1_LOG_IEEE
;
5428 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5429 r600_bytecode_src_set_abs(&alu
.src
[0]);
5431 alu
.dst
.sel
= ctx
->temp_reg
;
5436 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5442 /* result.w = 1.0; */
5443 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5444 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5446 alu
.op
= ALU_OP1_MOV
;
5447 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5448 alu
.src
[0].chan
= 0;
5450 alu
.dst
.sel
= ctx
->temp_reg
;
5455 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5460 return tgsi_helper_copy(ctx
, inst
);
5463 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5465 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5466 struct r600_bytecode_alu alu
;
5469 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5471 switch (inst
->Instruction
.Opcode
) {
5472 case TGSI_OPCODE_ARL
:
5473 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5475 case TGSI_OPCODE_ARR
:
5476 alu
.op
= ALU_OP1_FLT_TO_INT
;
5478 case TGSI_OPCODE_UARL
:
5479 alu
.op
= ALU_OP1_MOV
;
5486 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5488 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5490 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5494 ctx
->bc
->ar_loaded
= 0;
5497 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5499 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5500 struct r600_bytecode_alu alu
;
5503 switch (inst
->Instruction
.Opcode
) {
5504 case TGSI_OPCODE_ARL
:
5505 memset(&alu
, 0, sizeof(alu
));
5506 alu
.op
= ALU_OP1_FLOOR
;
5507 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5508 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5512 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5515 memset(&alu
, 0, sizeof(alu
));
5516 alu
.op
= ALU_OP1_FLT_TO_INT
;
5517 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5518 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5522 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5525 case TGSI_OPCODE_ARR
:
5526 memset(&alu
, 0, sizeof(alu
));
5527 alu
.op
= ALU_OP1_FLT_TO_INT
;
5528 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5529 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5533 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5536 case TGSI_OPCODE_UARL
:
5537 memset(&alu
, 0, sizeof(alu
));
5538 alu
.op
= ALU_OP1_MOV
;
5539 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5540 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5544 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5552 ctx
->bc
->ar_loaded
= 0;
5556 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5558 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5559 struct r600_bytecode_alu alu
;
5562 for (i
= 0; i
< 4; i
++) {
5563 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5565 alu
.op
= ALU_OP2_MUL
;
5566 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5568 if (i
== 0 || i
== 3) {
5569 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5571 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5574 if (i
== 0 || i
== 2) {
5575 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5577 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5581 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5588 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5590 struct r600_bytecode_alu alu
;
5593 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5595 alu
.execute_mask
= 1;
5596 alu
.update_pred
= 1;
5598 alu
.dst
.sel
= ctx
->temp_reg
;
5602 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5603 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5604 alu
.src
[1].chan
= 0;
5608 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5614 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5616 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5620 if (ctx
->bc
->cf_last
) {
5621 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5623 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5628 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5629 ctx
->bc
->force_add_cf
= 1;
5630 } else if (alu_pop
== 2) {
5631 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5632 ctx
->bc
->force_add_cf
= 1;
5639 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5640 ctx
->bc
->cf_last
->pop_count
= pops
;
5641 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5647 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5650 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5651 unsigned elements
, entries
;
5653 unsigned entry_size
= stack
->entry_size
;
5655 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5656 elements
+= stack
->push
;
5658 switch (ctx
->bc
->chip_class
) {
5661 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5662 * the stack must be reserved to hold the current active/continue
5664 if (reason
== FC_PUSH_VPM
) {
5670 /* r9xx: any stack operation on empty stack consumes 2 additional
5675 /* FIXME: do the two elements added above cover the cases for the
5679 /* r8xx+: 2 extra elements are not always required, but one extra
5680 * element must be added for each of the following cases:
5681 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5683 * (Currently we don't use ALU_ELSE_AFTER.)
5684 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5685 * PUSH instruction executed.
5687 * NOTE: it seems we also need to reserve additional element in some
5688 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5689 * then STACK_SIZE should be 2 instead of 1 */
5690 if (reason
== FC_PUSH_VPM
) {
5700 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5701 * for all chips, so we use 4 in the final formula, not the real entry_size
5705 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5707 if (entries
> stack
->max_entries
)
5708 stack
->max_entries
= entries
;
5711 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5715 --ctx
->bc
->stack
.push
;
5716 assert(ctx
->bc
->stack
.push
>= 0);
5719 --ctx
->bc
->stack
.push_wqm
;
5720 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5723 --ctx
->bc
->stack
.loop
;
5724 assert(ctx
->bc
->stack
.loop
>= 0);
5732 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5736 ++ctx
->bc
->stack
.push
;
5739 ++ctx
->bc
->stack
.push_wqm
;
5741 ++ctx
->bc
->stack
.loop
;
5747 callstack_update_max_depth(ctx
, reason
);
5750 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5752 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5754 sp
->mid
= realloc((void *)sp
->mid
,
5755 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5756 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5760 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5763 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5764 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5767 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5769 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5779 static int emit_return(struct r600_shader_ctx
*ctx
)
5781 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5785 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5788 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5789 ctx
->bc
->cf_last
->pop_count
= pops
;
5790 /* XXX work out offset */
5794 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5799 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5804 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5807 emit_jump_to_offset(ctx
, 1, 4);
5808 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5809 pops(ctx
, ifidx
+ 1);
5813 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5817 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5818 ctx
->bc
->cf_last
->pop_count
= 1;
5820 fc_set_mid(ctx
, fc_sp
);
5826 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5828 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5830 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5831 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5832 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5833 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5834 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5835 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5836 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5837 alu_type
= CF_OP_ALU
;
5840 emit_logic_pred(ctx
, opcode
, alu_type
);
5842 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5844 fc_pushlevel(ctx
, FC_IF
);
5846 callstack_push(ctx
, FC_PUSH_VPM
);
5850 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5852 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5855 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5857 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5860 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5862 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5863 ctx
->bc
->cf_last
->pop_count
= 1;
5865 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5866 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5870 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5873 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5874 R600_ERR("if/endif unbalanced in shader\n");
5878 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5879 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5880 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5882 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5886 callstack_pop(ctx
, FC_PUSH_VPM
);
5890 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5892 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5893 * limited to 4096 iterations, like the other LOOP_* instructions. */
5894 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5896 fc_pushlevel(ctx
, FC_LOOP
);
5898 /* check stack depth */
5899 callstack_push(ctx
, FC_LOOP
);
5903 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5907 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5909 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5910 R600_ERR("loop/endloop in shader code are not paired.\n");
5914 /* fixup loop pointers - from r600isa
5915 LOOP END points to CF after LOOP START,
5916 LOOP START point to CF after LOOP END
5917 BRK/CONT point to LOOP END CF
5919 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5921 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5923 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5924 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5926 /* XXX add LOOPRET support */
5928 callstack_pop(ctx
, FC_LOOP
);
5932 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5936 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5938 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5943 R600_ERR("Break not inside loop/endloop pair\n");
5947 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5949 fc_set_mid(ctx
, fscp
);
5954 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5956 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5957 struct r600_bytecode_alu alu
;
5959 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5962 for (i
= 0; i
< lasti
+ 1; i
++) {
5963 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5966 if (ctx
->bc
->chip_class
== CAYMAN
) {
5967 for (j
= 0 ; j
< 4; j
++) {
5968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5970 alu
.op
= ALU_OP2_MULLO_UINT
;
5971 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5972 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5974 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5975 alu
.dst
.sel
= ctx
->temp_reg
;
5976 alu
.dst
.write
= (j
== i
);
5979 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5987 alu
.dst
.sel
= ctx
->temp_reg
;
5990 alu
.op
= ALU_OP2_MULLO_UINT
;
5991 for (j
= 0; j
< 2; j
++) {
5992 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5996 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6003 for (i
= 0; i
< lasti
+ 1; i
++) {
6004 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6007 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6008 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6010 alu
.op
= ALU_OP2_ADD_INT
;
6012 alu
.src
[0].sel
= ctx
->temp_reg
;
6013 alu
.src
[0].chan
= i
;
6015 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6026 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
6027 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6028 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6029 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6032 * For state trackers other than OpenGL, we'll want to use
6033 * _RECIP_IEEE instead.
6035 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
6037 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
6038 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6039 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6040 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6041 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6042 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6043 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6044 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6045 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6046 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6047 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6048 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6049 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6050 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6051 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6052 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6054 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6055 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6057 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6058 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6059 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6060 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6061 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6062 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6063 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6064 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6065 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6066 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6068 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6069 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6070 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6071 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6072 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6073 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6074 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6075 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6076 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6078 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6079 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6080 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6081 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6082 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6083 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6084 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6085 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6086 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6087 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6088 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6089 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6090 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6091 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6092 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6093 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6094 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6095 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6096 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6097 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6098 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6099 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6100 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6101 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6102 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6103 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6104 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6105 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6106 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6107 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6108 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6109 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6110 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6111 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6112 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6114 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6116 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6117 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6118 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6119 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6120 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6121 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6122 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6123 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6124 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6126 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6127 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6128 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6129 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6130 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6131 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6132 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6133 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6134 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6135 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6136 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6137 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6138 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6139 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6140 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6141 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6143 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6144 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6145 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6146 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6148 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6149 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6150 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6151 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6152 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6153 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6155 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6156 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6157 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6158 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6160 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6161 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6162 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6163 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6164 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6165 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6166 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6167 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6168 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6169 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6170 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6171 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6172 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6173 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6174 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6175 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6176 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6177 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6178 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6179 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6180 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6181 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6182 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6183 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6184 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6185 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6186 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6187 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6188 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6189 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6190 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6191 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6192 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6193 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6194 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6195 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6196 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6197 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6198 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6199 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6200 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6201 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6202 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6203 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6204 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6205 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6206 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6207 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6208 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6209 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6210 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6211 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6212 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6213 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6214 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6215 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6216 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6217 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6218 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6219 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6220 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6221 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6222 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6225 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6226 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6227 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6228 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6229 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6230 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6231 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6232 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6233 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6234 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6235 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6236 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6237 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6238 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6239 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6240 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6241 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6242 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6243 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6244 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6245 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6247 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6248 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6250 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6251 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6252 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6253 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6254 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6255 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6256 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6257 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6258 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6259 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6261 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6262 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6263 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6264 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6265 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6266 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6267 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6268 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6269 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6270 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6271 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6272 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6273 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6274 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6275 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6276 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6277 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6278 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6279 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6280 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6281 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6282 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6283 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6284 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6285 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6286 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6287 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6288 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6289 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6290 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6291 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6292 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6293 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6294 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6295 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6296 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6297 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6298 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6299 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6300 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6301 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6302 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6303 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6304 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6305 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6306 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6307 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6309 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6310 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6311 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6312 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6313 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6314 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6315 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6316 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6317 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6319 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6320 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6321 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6322 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6323 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6324 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6325 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6326 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6327 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6328 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6329 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6330 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6331 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6332 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6333 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6334 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6336 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6337 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6338 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6339 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6341 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6342 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6343 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6344 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6345 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6346 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6348 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6349 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6350 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6351 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6353 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6354 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6355 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6356 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6357 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6358 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6359 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6360 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6361 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6362 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6363 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6364 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6365 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6366 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6367 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6368 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6369 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6370 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6371 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6372 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6373 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6374 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6375 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6376 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6377 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6378 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6379 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6380 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6381 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6382 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6383 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6384 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6385 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6386 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6387 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6388 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6389 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6390 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6391 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6392 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6393 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6394 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6395 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6396 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6397 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6398 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6399 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6400 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6401 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6402 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6403 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6404 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6405 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6406 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6407 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6408 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6409 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6410 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6411 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6412 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6413 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6414 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6415 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6418 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6419 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6420 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6421 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6422 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6423 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6424 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6425 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6426 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6427 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6428 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6429 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6430 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6431 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6432 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6433 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6434 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6435 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6436 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6437 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6438 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6440 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6441 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6443 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6444 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6445 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6446 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6447 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6448 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6449 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6450 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6451 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6452 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6454 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6455 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6456 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6457 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6458 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6459 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6460 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6461 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6462 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6463 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6464 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6465 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6467 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6468 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6469 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6470 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6471 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6472 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6473 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6474 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6475 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6476 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6477 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6478 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6479 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6480 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6481 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6482 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6483 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6484 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6485 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6486 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6487 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6488 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6489 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6490 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6491 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6492 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6493 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6494 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6495 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6496 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6497 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6498 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6499 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6500 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6502 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6503 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6504 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6505 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6506 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6507 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6508 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6509 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6510 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6512 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6513 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6514 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6515 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6516 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6517 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6518 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6519 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6520 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6521 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6522 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6523 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6524 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6525 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6526 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6527 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6529 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6530 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6531 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6532 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6534 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6535 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6536 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6537 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6538 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6539 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6541 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6542 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6543 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6544 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6546 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6547 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6548 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6549 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6550 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6551 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6552 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6553 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6554 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6555 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6556 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6557 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6558 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6559 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6560 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6561 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6562 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6563 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6564 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6565 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6566 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6567 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6568 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6569 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6570 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6571 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6572 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6573 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6574 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6575 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6576 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6577 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6578 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6579 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6580 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6581 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6582 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6583 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6584 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6585 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6586 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6587 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6588 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6589 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6590 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6591 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6592 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6593 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6594 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6595 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6596 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6597 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6598 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6599 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6600 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6601 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6602 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6603 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6604 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6605 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6606 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6607 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6608 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},