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");
162 /* Check if the bytecode has already been built. When using the llvm
163 * backend, r600_shader_from_tgsi() will take care of building the
166 if (!shader
->shader
.bc
.bytecode
) {
167 r
= r600_bytecode_build(&shader
->shader
.bc
);
169 R600_ERR("building bytecode failed !\n");
174 if (dump
&& !sb_disasm
) {
175 fprintf(stderr
, "--------------------------------------------------------------\n");
176 r600_bytecode_disasm(&shader
->shader
.bc
);
177 fprintf(stderr
, "______________________________________________________________\n");
178 } else if ((dump
&& sb_disasm
) || use_sb
) {
179 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
182 R600_ERR("r600_sb_bytecode_process failed !\n");
187 /* Store the shader in a buffer. */
188 if (shader
->bo
== NULL
) {
189 shader
->bo
= (struct r600_resource
*)
190 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
191 if (shader
->bo
== NULL
) {
194 ptr
= r600_buffer_mmap_sync_with_rings(rctx
, shader
->bo
, PIPE_TRANSFER_WRITE
);
195 if (R600_BIG_ENDIAN
) {
196 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
197 ptr
[i
] = bswap_32(shader
->shader
.bc
.bytecode
[i
]);
200 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
202 rctx
->ws
->buffer_unmap(shader
->bo
->cs_buf
);
206 switch (shader
->shader
.processor_type
) {
207 case TGSI_PROCESSOR_VERTEX
:
208 if (rctx
->chip_class
>= EVERGREEN
) {
209 evergreen_update_vs_state(ctx
, shader
);
211 r600_update_vs_state(ctx
, shader
);
214 case TGSI_PROCESSOR_FRAGMENT
:
215 if (rctx
->chip_class
>= EVERGREEN
) {
216 evergreen_update_ps_state(ctx
, shader
);
218 r600_update_ps_state(ctx
, shader
);
227 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
229 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
230 r600_bytecode_clear(&shader
->shader
.bc
);
231 r600_release_command_buffer(&shader
->command_buffer
);
235 * tgsi -> r600 shader
237 struct r600_shader_tgsi_instruction
;
239 struct r600_shader_src
{
249 struct r600_shader_ctx
{
250 struct tgsi_shader_info info
;
251 struct tgsi_parse_context parse
;
252 const struct tgsi_token
*tokens
;
254 unsigned file_offset
[TGSI_FILE_COUNT
];
256 struct r600_shader_tgsi_instruction
*inst_info
;
257 struct r600_bytecode
*bc
;
258 struct r600_shader
*shader
;
259 struct r600_shader_src src
[4];
262 uint32_t max_driver_temp_used
;
264 /* needed for evergreen interpolation */
265 boolean input_centroid
;
266 boolean input_linear
;
267 boolean input_perspective
;
271 boolean clip_vertex_write
;
277 struct r600_shader_tgsi_instruction
{
278 unsigned tgsi_opcode
;
281 int (*process
)(struct r600_shader_ctx
*ctx
);
284 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
285 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
286 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
287 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
288 static int tgsi_else(struct r600_shader_ctx
*ctx
);
289 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
290 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
291 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
292 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
295 int r600_compute_shader_create(struct pipe_context
* ctx
,
296 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
)
298 struct r600_context
*r600_ctx
= (struct r600_context
*)ctx
;
299 struct r600_shader_ctx shader_ctx
;
300 boolean use_kill
= false;
301 bool dump
= (r600_ctx
->screen
->debug_flags
& DBG_CS
) != 0;
302 unsigned use_sb
= r600_ctx
->screen
->debug_flags
& DBG_SB_CS
;
303 unsigned sb_disasm
= use_sb
||
304 (r600_ctx
->screen
->debug_flags
& DBG_SB_DISASM
);
306 shader_ctx
.bc
= bytecode
;
307 r600_bytecode_init(shader_ctx
.bc
, r600_ctx
->chip_class
, r600_ctx
->family
,
308 r600_ctx
->screen
->has_compressed_msaa_texturing
);
309 shader_ctx
.bc
->type
= TGSI_PROCESSOR_COMPUTE
;
310 shader_ctx
.bc
->isa
= r600_ctx
->isa
;
311 r600_llvm_compile(mod
, r600_ctx
->family
,
312 shader_ctx
.bc
, &use_kill
, dump
);
314 if (dump
&& !sb_disasm
) {
315 r600_bytecode_disasm(shader_ctx
.bc
);
316 } else if ((dump
&& sb_disasm
) || use_sb
) {
317 if (r600_sb_bytecode_process(r600_ctx
, shader_ctx
.bc
, NULL
, dump
, use_sb
))
318 R600_ERR("r600_sb_bytecode_process failed!\n");
324 #endif /* HAVE_OPENCL */
326 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
328 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
331 if (i
->Instruction
.NumDstRegs
> 1) {
332 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
335 if (i
->Instruction
.Predicate
) {
336 R600_ERR("predicate unsupported\n");
340 if (i
->Instruction
.Label
) {
341 R600_ERR("label unsupported\n");
345 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
346 if (i
->Src
[j
].Register
.Dimension
) {
347 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
348 R600_ERR("unsupported src %d (dimension %d)\n", j
,
349 i
->Src
[j
].Register
.Dimension
);
354 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
355 if (i
->Dst
[j
].Register
.Dimension
) {
356 R600_ERR("unsupported dst (dimension)\n");
363 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
368 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
369 if (ctx
->shader
->input
[input
].centroid
)
371 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
372 /* if we have perspective add one */
373 if (ctx
->input_perspective
) {
375 /* if we have perspective centroid */
376 if (ctx
->input_centroid
)
379 if (ctx
->shader
->input
[input
].centroid
)
383 ctx
->shader
->input
[input
].ij_index
= ij_index
;
386 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
389 struct r600_bytecode_alu alu
;
390 int gpr
= 0, base_chan
= 0;
391 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
393 /* work out gpr and base_chan from index */
395 base_chan
= (2 * (ij_index
% 2)) + 1;
397 for (i
= 0; i
< 8; i
++) {
398 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
401 alu
.op
= ALU_OP2_INTERP_ZW
;
403 alu
.op
= ALU_OP2_INTERP_XY
;
405 if ((i
> 1) && (i
< 6)) {
406 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
410 alu
.dst
.chan
= i
% 4;
412 alu
.src
[0].sel
= gpr
;
413 alu
.src
[0].chan
= (base_chan
- (i
% 2));
415 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
417 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
420 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
427 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
430 struct r600_bytecode_alu alu
;
432 for (i
= 0; i
< 4; i
++) {
433 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
435 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
437 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
442 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
447 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
455 * Special export handling in shaders
457 * shader export ARRAY_BASE for EXPORT_POS:
460 * 62, 63 are clip distance vectors
462 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
463 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
464 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
465 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
466 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
467 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
468 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
469 * exclusive from render target index)
470 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
473 * shader export ARRAY_BASE for EXPORT_PIXEL:
475 * 61 computed Z vector
477 * The use of the values exported in the computed Z vector are controlled
478 * by DB_SHADER_CONTROL:
479 * Z_EXPORT_ENABLE - Z as a float in RED
480 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
481 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
482 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
483 * DB_SOURCE_FORMAT - export control restrictions
488 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
489 static int r600_spi_sid(struct r600_shader_io
* io
)
491 int index
, name
= io
->name
;
493 /* These params are handled differently, they don't need
494 * semantic indices, so we'll use 0 for them.
496 if (name
== TGSI_SEMANTIC_POSITION
||
497 name
== TGSI_SEMANTIC_PSIZE
||
498 name
== TGSI_SEMANTIC_FACE
)
501 if (name
== TGSI_SEMANTIC_GENERIC
) {
502 /* For generic params simply use sid from tgsi */
505 /* For non-generic params - pack name and sid into 8 bits */
506 index
= 0x80 | (name
<<3) | (io
->sid
);
509 /* Make sure that all really used indices have nonzero value, so
510 * we can just compare it to 0 later instead of comparing the name
511 * with different values to detect special cases. */
518 /* turn input into interpolate on EG */
519 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
523 if (ctx
->shader
->input
[index
].spi_sid
) {
524 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
525 if (ctx
->shader
->input
[index
].interpolate
> 0) {
526 evergreen_interp_assign_ij_index(ctx
, index
);
528 r
= evergreen_interp_alu(ctx
, index
);
531 r
= evergreen_interp_flat(ctx
, index
);
537 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
539 struct r600_bytecode_alu alu
;
541 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
542 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
544 for (i
= 0; i
< 4; i
++) {
545 memset(&alu
, 0, sizeof(alu
));
546 alu
.op
= ALU_OP3_CNDGT
;
549 alu
.dst
.sel
= gpr_front
;
550 alu
.src
[0].sel
= ctx
->face_gpr
;
551 alu
.src
[1].sel
= gpr_front
;
552 alu
.src
[2].sel
= gpr_back
;
559 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
566 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
568 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
569 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
571 switch (d
->Declaration
.File
) {
572 case TGSI_FILE_INPUT
:
573 i
= ctx
->shader
->ninput
;
574 assert(i
< Elements(ctx
->shader
->input
));
575 ctx
->shader
->ninput
+= count
;
576 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
577 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
578 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
579 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
580 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
581 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
582 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
583 switch (ctx
->shader
->input
[i
].name
) {
584 case TGSI_SEMANTIC_FACE
:
585 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
587 case TGSI_SEMANTIC_COLOR
:
590 case TGSI_SEMANTIC_POSITION
:
591 ctx
->fragcoord_input
= i
;
594 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
595 if ((r
= evergreen_interp_input(ctx
, i
)))
599 for (j
= 1; j
< count
; ++j
) {
600 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
601 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
604 case TGSI_FILE_OUTPUT
:
605 i
= ctx
->shader
->noutput
++;
606 assert(i
< Elements(ctx
->shader
->output
));
607 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
608 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
609 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
610 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
611 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
612 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
613 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
614 switch (d
->Semantic
.Name
) {
615 case TGSI_SEMANTIC_CLIPDIST
:
616 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
618 case TGSI_SEMANTIC_PSIZE
:
619 ctx
->shader
->vs_out_misc_write
= 1;
620 ctx
->shader
->vs_out_point_size
= 1;
622 case TGSI_SEMANTIC_CLIPVERTEX
:
623 ctx
->clip_vertex_write
= TRUE
;
627 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
628 switch (d
->Semantic
.Name
) {
629 case TGSI_SEMANTIC_COLOR
:
630 ctx
->shader
->nr_ps_max_color_exports
++;
635 case TGSI_FILE_TEMPORARY
:
636 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
637 if (d
->Array
.ArrayID
) {
638 r600_add_gpr_array(ctx
->shader
,
639 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
641 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
646 case TGSI_FILE_CONSTANT
:
647 case TGSI_FILE_SAMPLER
:
648 case TGSI_FILE_ADDRESS
:
651 case TGSI_FILE_SYSTEM_VALUE
:
652 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
653 if (!ctx
->native_integers
) {
654 struct r600_bytecode_alu alu
;
655 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
657 alu
.op
= ALU_OP1_INT_TO_FLT
;
666 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
670 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
673 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
679 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
681 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
685 * for evergreen we need to scan the shader to find the number of GPRs we need to
686 * reserve for interpolation.
688 * we need to know if we are going to emit
689 * any centroid inputs
690 * if perspective and linear are required
692 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
697 ctx
->input_linear
= FALSE
;
698 ctx
->input_perspective
= FALSE
;
699 ctx
->input_centroid
= FALSE
;
700 ctx
->num_interp_gpr
= 1;
702 /* any centroid inputs */
703 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
704 /* skip position/face */
705 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
706 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
708 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
709 ctx
->input_linear
= TRUE
;
710 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
711 ctx
->input_perspective
= TRUE
;
712 if (ctx
->info
.input_centroid
[i
])
713 ctx
->input_centroid
= TRUE
;
717 /* ignoring sample for now */
718 if (ctx
->input_perspective
)
720 if (ctx
->input_linear
)
722 if (ctx
->input_centroid
)
725 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
727 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
728 return ctx
->num_interp_gpr
;
731 static void tgsi_src(struct r600_shader_ctx
*ctx
,
732 const struct tgsi_full_src_register
*tgsi_src
,
733 struct r600_shader_src
*r600_src
)
735 memset(r600_src
, 0, sizeof(*r600_src
));
736 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
737 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
738 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
739 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
740 r600_src
->neg
= tgsi_src
->Register
.Negate
;
741 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
743 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
745 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
746 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
747 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
749 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
750 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
751 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
754 index
= tgsi_src
->Register
.Index
;
755 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
756 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
757 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
758 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
759 r600_src
->swizzle
[0] = 3;
760 r600_src
->swizzle
[1] = 3;
761 r600_src
->swizzle
[2] = 3;
762 r600_src
->swizzle
[3] = 3;
764 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
765 r600_src
->swizzle
[0] = 0;
766 r600_src
->swizzle
[1] = 0;
767 r600_src
->swizzle
[2] = 0;
768 r600_src
->swizzle
[3] = 0;
772 if (tgsi_src
->Register
.Indirect
)
773 r600_src
->rel
= V_SQ_REL_RELATIVE
;
774 r600_src
->sel
= tgsi_src
->Register
.Index
;
775 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
777 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
778 if (tgsi_src
->Register
.Dimension
) {
779 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
784 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
786 struct r600_bytecode_vtx vtx
;
791 struct r600_bytecode_alu alu
;
793 memset(&alu
, 0, sizeof(alu
));
795 alu
.op
= ALU_OP2_ADD_INT
;
796 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
798 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
799 alu
.src
[1].value
= offset
;
801 alu
.dst
.sel
= dst_reg
;
805 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
810 ar_reg
= ctx
->bc
->ar_reg
;
813 memset(&vtx
, 0, sizeof(vtx
));
814 vtx
.buffer_id
= cb_idx
;
815 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
816 vtx
.src_gpr
= ar_reg
;
817 vtx
.mega_fetch_count
= 16;
818 vtx
.dst_gpr
= dst_reg
;
819 vtx
.dst_sel_x
= 0; /* SEL_X */
820 vtx
.dst_sel_y
= 1; /* SEL_Y */
821 vtx
.dst_sel_z
= 2; /* SEL_Z */
822 vtx
.dst_sel_w
= 3; /* SEL_W */
823 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
824 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
825 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
826 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
827 vtx
.endian
= r600_endian_swap(32);
829 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
835 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
837 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
838 struct r600_bytecode_alu alu
;
839 int i
, j
, k
, nconst
, r
;
841 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
842 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
845 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
847 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
848 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
852 if (ctx
->src
[i
].rel
) {
853 int treg
= r600_get_temp(ctx
);
854 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
857 ctx
->src
[i
].kc_bank
= 0;
858 ctx
->src
[i
].sel
= treg
;
862 int treg
= r600_get_temp(ctx
);
863 for (k
= 0; k
< 4; k
++) {
864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
865 alu
.op
= ALU_OP1_MOV
;
866 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
868 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
874 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
878 ctx
->src
[i
].sel
= treg
;
886 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
887 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
889 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
890 struct r600_bytecode_alu alu
;
891 int i
, j
, k
, nliteral
, r
;
893 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
894 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
898 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
899 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
900 int treg
= r600_get_temp(ctx
);
901 for (k
= 0; k
< 4; k
++) {
902 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
903 alu
.op
= ALU_OP1_MOV
;
904 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
906 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
912 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
916 ctx
->src
[i
].sel
= treg
;
923 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
925 int i
, r
, count
= ctx
->shader
->ninput
;
927 for (i
= 0; i
< count
; i
++) {
928 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
929 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
938 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
939 struct r600_pipe_shader
*pipeshader
,
940 struct r600_shader_key key
)
942 struct r600_shader
*shader
= &pipeshader
->shader
;
943 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
944 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
945 struct tgsi_full_immediate
*immediate
;
946 struct tgsi_full_property
*property
;
947 struct r600_shader_ctx ctx
;
948 struct r600_bytecode_output output
[32];
949 unsigned output_done
, noutput
;
952 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
953 /* Declarations used by llvm code */
954 bool use_llvm
= false;
958 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
960 ctx
.bc
= &shader
->bc
;
962 ctx
.native_integers
= true;
964 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
965 rscreen
->has_compressed_msaa_texturing
);
967 tgsi_scan_shader(tokens
, &ctx
.info
);
968 shader
->indirect_files
= ctx
.info
.indirect_files
;
969 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
970 tgsi_parse_init(&ctx
.parse
, tokens
);
971 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
972 shader
->processor_type
= ctx
.type
;
973 ctx
.bc
->type
= shader
->processor_type
;
976 ctx
.fragcoord_input
= -1;
978 ctx
.clip_vertex_write
= 0;
980 shader
->nr_ps_color_exports
= 0;
981 shader
->nr_ps_max_color_exports
= 0;
983 shader
->two_side
= key
.color_two_side
;
985 /* register allocations */
986 /* Values [0,127] correspond to GPR[0..127].
987 * Values [128,159] correspond to constant buffer bank 0
988 * Values [160,191] correspond to constant buffer bank 1
989 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
990 * Values [256,287] correspond to constant buffer bank 2 (EG)
991 * Values [288,319] correspond to constant buffer bank 3 (EG)
992 * Other special values are shown in the list below.
993 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
994 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
995 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
996 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
997 * 248 SQ_ALU_SRC_0: special constant 0.0.
998 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
999 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1000 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1001 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1002 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1003 * 254 SQ_ALU_SRC_PV: previous vector result.
1004 * 255 SQ_ALU_SRC_PS: previous scalar result.
1006 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1007 ctx
.file_offset
[i
] = 0;
1010 #ifdef R600_USE_LLVM
1011 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1012 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1013 "indirect adressing. Falling back to TGSI "
1018 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1019 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1021 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1024 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1025 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1027 ctx
.use_llvm
= use_llvm
;
1030 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1031 ctx
.file_offset
[TGSI_FILE_INPUT
];
1033 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1034 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1035 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1037 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1038 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1040 /* Outside the GPR range. This will be translated to one of the
1041 * kcache banks later. */
1042 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1044 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1045 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1046 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1047 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1049 if (indirect_gprs
) {
1050 shader
->max_arrays
= 0;
1051 shader
->num_arrays
= 0;
1053 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1054 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1055 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1056 ctx
.file_offset
[TGSI_FILE_INPUT
],
1059 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1060 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1061 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1062 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1068 ctx
.literals
= NULL
;
1069 shader
->fs_write_all
= FALSE
;
1070 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1071 tgsi_parse_token(&ctx
.parse
);
1072 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1073 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1074 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1075 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1076 if(ctx
.literals
== NULL
) {
1080 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1081 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1082 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1083 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1086 case TGSI_TOKEN_TYPE_DECLARATION
:
1087 r
= tgsi_declaration(&ctx
);
1091 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1093 case TGSI_TOKEN_TYPE_PROPERTY
:
1094 property
= &ctx
.parse
.FullToken
.FullProperty
;
1095 switch (property
->Property
.PropertyName
) {
1096 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1097 if (property
->u
[0].Data
== 1)
1098 shader
->fs_write_all
= TRUE
;
1100 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1101 /* we don't need this one */
1106 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1112 /* Process two side if needed */
1113 if (shader
->two_side
&& ctx
.colors_used
) {
1114 int i
, count
= ctx
.shader
->ninput
;
1115 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1117 /* additional inputs will be allocated right after the existing inputs,
1118 * we won't need them after the color selection, so we don't need to
1119 * reserve these gprs for the rest of the shader code and to adjust
1120 * output offsets etc. */
1121 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1122 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1124 if (ctx
.face_gpr
== -1) {
1125 i
= ctx
.shader
->ninput
++;
1126 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1127 ctx
.shader
->input
[i
].spi_sid
= 0;
1128 ctx
.shader
->input
[i
].gpr
= gpr
++;
1129 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1132 for (i
= 0; i
< count
; i
++) {
1133 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1134 int ni
= ctx
.shader
->ninput
++;
1135 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1136 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1137 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1138 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1139 // TGSI to LLVM needs to know the lds position of inputs.
1140 // Non LLVM path computes it later (in process_twoside_color)
1141 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1142 ctx
.shader
->input
[i
].back_color_input
= ni
;
1143 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1144 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1151 /* LLVM backend setup */
1152 #ifdef R600_USE_LLVM
1154 struct radeon_llvm_context radeon_llvm_ctx
;
1156 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1157 boolean use_kill
= false;
1159 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1160 radeon_llvm_ctx
.type
= ctx
.type
;
1161 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1162 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1163 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1164 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1165 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1166 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1167 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1168 radeon_llvm_ctx
.stream_outputs
= &so
;
1169 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1170 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1171 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1173 if (r600_llvm_compile(mod
, rscreen
->family
, ctx
.bc
, &use_kill
, dump
)) {
1174 radeon_llvm_dispose(&radeon_llvm_ctx
);
1176 fprintf(stderr
, "R600 LLVM backend failed to compile "
1177 "shader. Falling back to TGSI\n");
1179 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1180 ctx
.file_offset
[TGSI_FILE_INPUT
];
1183 ctx
.shader
->uses_kill
= use_kill
;
1184 radeon_llvm_dispose(&radeon_llvm_ctx
);
1187 /* End of LLVM backend setup */
1189 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1190 shader
->nr_ps_max_color_exports
= 8;
1193 if (ctx
.fragcoord_input
>= 0) {
1194 if (ctx
.bc
->chip_class
== CAYMAN
) {
1195 for (j
= 0 ; j
< 4; j
++) {
1196 struct r600_bytecode_alu alu
;
1197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1198 alu
.op
= ALU_OP1_RECIP_IEEE
;
1199 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1200 alu
.src
[0].chan
= 3;
1202 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1204 alu
.dst
.write
= (j
== 3);
1206 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1210 struct r600_bytecode_alu alu
;
1211 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1212 alu
.op
= ALU_OP1_RECIP_IEEE
;
1213 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1214 alu
.src
[0].chan
= 3;
1216 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1220 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1225 if (shader
->two_side
&& ctx
.colors_used
) {
1226 if ((r
= process_twoside_color_inputs(&ctx
)))
1230 tgsi_parse_init(&ctx
.parse
, tokens
);
1231 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1232 tgsi_parse_token(&ctx
.parse
);
1233 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1234 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1235 r
= tgsi_is_supported(&ctx
);
1238 ctx
.max_driver_temp_used
= 0;
1239 /* reserve first tmp for everyone */
1240 r600_get_temp(&ctx
);
1242 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1243 if ((r
= tgsi_split_constant(&ctx
)))
1245 if ((r
= tgsi_split_literal_constant(&ctx
)))
1247 if (ctx
.bc
->chip_class
== CAYMAN
)
1248 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1249 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1250 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1252 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1253 r
= ctx
.inst_info
->process(&ctx
);
1263 /* Reset the temporary register counter. */
1264 ctx
.max_driver_temp_used
= 0;
1266 noutput
= shader
->noutput
;
1268 if (ctx
.clip_vertex_write
) {
1269 unsigned clipdist_temp
[2];
1271 clipdist_temp
[0] = r600_get_temp(&ctx
);
1272 clipdist_temp
[1] = r600_get_temp(&ctx
);
1274 /* need to convert a clipvertex write into clipdistance writes and not export
1275 the clip vertex anymore */
1277 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1278 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1279 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1281 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1282 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1285 /* reset spi_sid for clipvertex output to avoid confusing spi */
1286 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1288 shader
->clip_dist_write
= 0xFF;
1290 for (i
= 0; i
< 8; i
++) {
1294 for (j
= 0; j
< 4; j
++) {
1295 struct r600_bytecode_alu alu
;
1296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1297 alu
.op
= ALU_OP2_DOT4
;
1298 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1299 alu
.src
[0].chan
= j
;
1301 alu
.src
[1].sel
= 512 + i
;
1302 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1303 alu
.src
[1].chan
= j
;
1305 alu
.dst
.sel
= clipdist_temp
[oreg
];
1307 alu
.dst
.write
= (j
== ochan
);
1311 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1318 /* Add stream outputs. */
1319 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1320 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1322 /* Sanity checking. */
1323 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1324 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1328 for (i
= 0; i
< so
.num_outputs
; i
++) {
1329 if (so
.output
[i
].output_buffer
>= 4) {
1330 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1331 so
.output
[i
].output_buffer
);
1337 /* Initialize locations where the outputs are stored. */
1338 for (i
= 0; i
< so
.num_outputs
; i
++) {
1339 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1341 /* Lower outputs with dst_offset < start_component.
1343 * We can only output 4D vectors with a write mask, e.g. we can
1344 * only output the W component at offset 3, etc. If we want
1345 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1346 * to move it to X and output X. */
1347 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1348 unsigned tmp
= r600_get_temp(&ctx
);
1350 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1351 struct r600_bytecode_alu alu
;
1352 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1353 alu
.op
= ALU_OP1_MOV
;
1354 alu
.src
[0].sel
= so_gpr
[i
];
1355 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1360 if (j
== so
.output
[i
].num_components
- 1)
1362 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1366 so
.output
[i
].start_component
= 0;
1371 /* Write outputs to buffers. */
1372 for (i
= 0; i
< so
.num_outputs
; i
++) {
1373 struct r600_bytecode_output output
;
1375 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1376 output
.gpr
= so_gpr
[i
];
1377 output
.elem_size
= so
.output
[i
].num_components
;
1378 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1379 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1380 output
.burst_count
= 1;
1382 /* array_size is an upper limit for the burst_count
1383 * with MEM_STREAM instructions */
1384 output
.array_size
= 0xFFF;
1385 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1386 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1387 switch (so
.output
[i
].output_buffer
) {
1389 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1392 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1395 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1398 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1402 switch (so
.output
[i
].output_buffer
) {
1404 output
.op
= CF_OP_MEM_STREAM0
;
1407 output
.op
= CF_OP_MEM_STREAM1
;
1410 output
.op
= CF_OP_MEM_STREAM2
;
1413 output
.op
= CF_OP_MEM_STREAM3
;
1417 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1424 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1425 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1426 output
[j
].gpr
= shader
->output
[i
].gpr
;
1427 output
[j
].elem_size
= 3;
1428 output
[j
].swizzle_x
= 0;
1429 output
[j
].swizzle_y
= 1;
1430 output
[j
].swizzle_z
= 2;
1431 output
[j
].swizzle_w
= 3;
1432 output
[j
].burst_count
= 1;
1433 output
[j
].barrier
= 1;
1434 output
[j
].type
= -1;
1435 output
[j
].op
= CF_OP_EXPORT
;
1437 case TGSI_PROCESSOR_VERTEX
:
1438 switch (shader
->output
[i
].name
) {
1439 case TGSI_SEMANTIC_POSITION
:
1440 output
[j
].array_base
= next_pos_base
++;
1441 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1444 case TGSI_SEMANTIC_PSIZE
:
1445 output
[j
].array_base
= next_pos_base
++;
1446 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1448 case TGSI_SEMANTIC_CLIPVERTEX
:
1451 case TGSI_SEMANTIC_CLIPDIST
:
1452 output
[j
].array_base
= next_pos_base
++;
1453 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1454 /* spi_sid is 0 for clipdistance outputs that were generated
1455 * for clipvertex - we don't need to pass them to PS */
1456 if (shader
->output
[i
].spi_sid
) {
1458 /* duplicate it as PARAM to pass to the pixel shader */
1459 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1460 output
[j
].array_base
= next_param_base
++;
1461 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1464 case TGSI_SEMANTIC_FOG
:
1465 output
[j
].swizzle_y
= 4; /* 0 */
1466 output
[j
].swizzle_z
= 4; /* 0 */
1467 output
[j
].swizzle_w
= 5; /* 1 */
1471 case TGSI_PROCESSOR_FRAGMENT
:
1472 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1473 /* never export more colors than the number of CBs */
1474 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1479 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1480 output
[j
].array_base
= next_pixel_base
++;
1481 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1482 shader
->nr_ps_color_exports
++;
1483 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1484 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1486 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1487 output
[j
].gpr
= shader
->output
[i
].gpr
;
1488 output
[j
].elem_size
= 3;
1489 output
[j
].swizzle_x
= 0;
1490 output
[j
].swizzle_y
= 1;
1491 output
[j
].swizzle_z
= 2;
1492 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1493 output
[j
].burst_count
= 1;
1494 output
[j
].barrier
= 1;
1495 output
[j
].array_base
= next_pixel_base
++;
1496 output
[j
].op
= CF_OP_EXPORT
;
1497 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1498 shader
->nr_ps_color_exports
++;
1501 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1502 output
[j
].array_base
= 61;
1503 output
[j
].swizzle_x
= 2;
1504 output
[j
].swizzle_y
= 7;
1505 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1506 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1507 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1508 output
[j
].array_base
= 61;
1509 output
[j
].swizzle_x
= 7;
1510 output
[j
].swizzle_y
= 1;
1511 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1512 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1514 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1520 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1525 if (output
[j
].type
==-1) {
1526 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1527 output
[j
].array_base
= next_param_base
++;
1531 /* add fake position export */
1532 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1533 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1535 output
[j
].elem_size
= 3;
1536 output
[j
].swizzle_x
= 7;
1537 output
[j
].swizzle_y
= 7;
1538 output
[j
].swizzle_z
= 7;
1539 output
[j
].swizzle_w
= 7;
1540 output
[j
].burst_count
= 1;
1541 output
[j
].barrier
= 1;
1542 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1543 output
[j
].array_base
= next_pos_base
;
1544 output
[j
].op
= CF_OP_EXPORT
;
1548 /* add fake param output for vertex shader if no param is exported */
1549 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1550 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1552 output
[j
].elem_size
= 3;
1553 output
[j
].swizzle_x
= 7;
1554 output
[j
].swizzle_y
= 7;
1555 output
[j
].swizzle_z
= 7;
1556 output
[j
].swizzle_w
= 7;
1557 output
[j
].burst_count
= 1;
1558 output
[j
].barrier
= 1;
1559 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1560 output
[j
].array_base
= 0;
1561 output
[j
].op
= CF_OP_EXPORT
;
1565 /* add fake pixel export */
1566 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1567 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1569 output
[j
].elem_size
= 3;
1570 output
[j
].swizzle_x
= 7;
1571 output
[j
].swizzle_y
= 7;
1572 output
[j
].swizzle_z
= 7;
1573 output
[j
].swizzle_w
= 7;
1574 output
[j
].burst_count
= 1;
1575 output
[j
].barrier
= 1;
1576 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1577 output
[j
].array_base
= 0;
1578 output
[j
].op
= CF_OP_EXPORT
;
1584 /* set export done on last export of each type */
1585 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1586 if (ctx
.bc
->chip_class
< CAYMAN
) {
1587 if (i
== (noutput
- 1)) {
1588 output
[i
].end_of_program
= 1;
1591 if (!(output_done
& (1 << output
[i
].type
))) {
1592 output_done
|= (1 << output
[i
].type
);
1593 output
[i
].op
= CF_OP_EXPORT_DONE
;
1596 /* add output to bytecode */
1598 for (i
= 0; i
< noutput
; i
++) {
1599 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1604 /* add program end */
1605 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1606 cm_bytecode_add_cf_end(ctx
.bc
);
1608 /* check GPR limit - we have 124 = 128 - 4
1609 * (4 are reserved as alu clause temporary registers) */
1610 if (ctx
.bc
->ngpr
> 124) {
1611 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1617 tgsi_parse_free(&ctx
.parse
);
1621 tgsi_parse_free(&ctx
.parse
);
1625 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1627 R600_ERR("%s tgsi opcode unsupported\n",
1628 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1632 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1637 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1638 const struct r600_shader_src
*shader_src
,
1641 bc_src
->sel
= shader_src
->sel
;
1642 bc_src
->chan
= shader_src
->swizzle
[chan
];
1643 bc_src
->neg
= shader_src
->neg
;
1644 bc_src
->abs
= shader_src
->abs
;
1645 bc_src
->rel
= shader_src
->rel
;
1646 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1647 bc_src
->kc_bank
= shader_src
->kc_bank
;
1650 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1656 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1658 bc_src
->neg
= !bc_src
->neg
;
1661 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1662 const struct tgsi_full_dst_register
*tgsi_dst
,
1664 struct r600_bytecode_alu_dst
*r600_dst
)
1666 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1668 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1669 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1670 r600_dst
->chan
= swizzle
;
1671 r600_dst
->write
= 1;
1672 if (tgsi_dst
->Register
.Indirect
)
1673 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1674 if (inst
->Instruction
.Saturate
) {
1675 r600_dst
->clamp
= 1;
1679 static int tgsi_last_instruction(unsigned writemask
)
1683 for (i
= 0; i
< 4; i
++) {
1684 if (writemask
& (1 << i
)) {
1691 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1693 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1694 struct r600_bytecode_alu alu
;
1696 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1698 for (i
= 0; i
< lasti
+ 1; i
++) {
1699 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1702 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1703 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1705 alu
.op
= ctx
->inst_info
->op
;
1707 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1708 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
1711 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
1712 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1714 /* handle some special cases */
1715 switch (ctx
->inst_info
->tgsi_opcode
) {
1716 case TGSI_OPCODE_SUB
:
1717 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
1719 case TGSI_OPCODE_ABS
:
1720 r600_bytecode_src_set_abs(&alu
.src
[0]);
1725 if (i
== lasti
|| trans_only
) {
1728 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1735 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
1737 return tgsi_op2_s(ctx
, 0, 0);
1740 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
1742 return tgsi_op2_s(ctx
, 1, 0);
1745 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
1747 return tgsi_op2_s(ctx
, 0, 1);
1750 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
1752 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1753 struct r600_bytecode_alu alu
;
1755 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1757 for (i
= 0; i
< lasti
+ 1; i
++) {
1759 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1761 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1762 alu
.op
= ctx
->inst_info
->op
;
1764 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1766 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1768 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1773 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1781 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
1783 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1785 struct r600_bytecode_alu alu
;
1786 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1788 for (i
= 0 ; i
< last_slot
; i
++) {
1789 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1790 alu
.op
= ctx
->inst_info
->op
;
1791 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1792 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
1794 /* RSQ should take the absolute value of src */
1795 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
1796 r600_bytecode_src_set_abs(&alu
.src
[j
]);
1799 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1800 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1802 if (i
== last_slot
- 1)
1804 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1811 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
1813 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1815 struct r600_bytecode_alu alu
;
1816 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1817 for (k
= 0; k
< last_slot
; k
++) {
1818 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
1821 for (i
= 0 ; i
< 4; i
++) {
1822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1823 alu
.op
= ctx
->inst_info
->op
;
1824 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1825 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
1827 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1828 alu
.dst
.write
= (i
== k
);
1831 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1840 * r600 - trunc to -PI..PI range
1841 * r700 - normalize by dividing by 2PI
1844 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
1846 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
1847 static float double_pi
= 3.1415926535 * 2;
1848 static float neg_pi
= -3.1415926535;
1851 struct r600_bytecode_alu alu
;
1853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1854 alu
.op
= ALU_OP3_MULADD
;
1858 alu
.dst
.sel
= ctx
->temp_reg
;
1861 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
1863 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1864 alu
.src
[1].chan
= 0;
1865 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
1866 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1867 alu
.src
[2].chan
= 0;
1869 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1874 alu
.op
= ALU_OP1_FRACT
;
1877 alu
.dst
.sel
= ctx
->temp_reg
;
1880 alu
.src
[0].sel
= ctx
->temp_reg
;
1881 alu
.src
[0].chan
= 0;
1883 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1887 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1888 alu
.op
= ALU_OP3_MULADD
;
1892 alu
.dst
.sel
= ctx
->temp_reg
;
1895 alu
.src
[0].sel
= ctx
->temp_reg
;
1896 alu
.src
[0].chan
= 0;
1898 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1899 alu
.src
[1].chan
= 0;
1900 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
1901 alu
.src
[2].chan
= 0;
1903 if (ctx
->bc
->chip_class
== R600
) {
1904 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
1905 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
1907 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
1908 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1913 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1919 static int cayman_trig(struct r600_shader_ctx
*ctx
)
1921 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1922 struct r600_bytecode_alu alu
;
1923 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1926 r
= tgsi_setup_trig(ctx
);
1931 for (i
= 0; i
< last_slot
; i
++) {
1932 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1933 alu
.op
= ctx
->inst_info
->op
;
1936 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1937 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1939 alu
.src
[0].sel
= ctx
->temp_reg
;
1940 alu
.src
[0].chan
= 0;
1941 if (i
== last_slot
- 1)
1943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1950 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
1952 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1953 struct r600_bytecode_alu alu
;
1955 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1957 r
= tgsi_setup_trig(ctx
);
1961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1962 alu
.op
= ctx
->inst_info
->op
;
1964 alu
.dst
.sel
= ctx
->temp_reg
;
1967 alu
.src
[0].sel
= ctx
->temp_reg
;
1968 alu
.src
[0].chan
= 0;
1970 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1974 /* replicate result */
1975 for (i
= 0; i
< lasti
+ 1; i
++) {
1976 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1980 alu
.op
= ALU_OP1_MOV
;
1982 alu
.src
[0].sel
= ctx
->temp_reg
;
1983 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1986 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1993 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
1995 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1996 struct r600_bytecode_alu alu
;
1999 /* We'll only need the trig stuff if we are going to write to the
2000 * X or Y components of the destination vector.
2002 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2003 r
= tgsi_setup_trig(ctx
);
2009 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2010 if (ctx
->bc
->chip_class
== CAYMAN
) {
2011 for (i
= 0 ; i
< 3; i
++) {
2012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2013 alu
.op
= ALU_OP1_COS
;
2014 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2020 alu
.src
[0].sel
= ctx
->temp_reg
;
2021 alu
.src
[0].chan
= 0;
2024 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2029 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2030 alu
.op
= ALU_OP1_COS
;
2031 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2033 alu
.src
[0].sel
= ctx
->temp_reg
;
2034 alu
.src
[0].chan
= 0;
2036 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2043 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2044 if (ctx
->bc
->chip_class
== CAYMAN
) {
2045 for (i
= 0 ; i
< 3; i
++) {
2046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2047 alu
.op
= ALU_OP1_SIN
;
2048 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2053 alu
.src
[0].sel
= ctx
->temp_reg
;
2054 alu
.src
[0].chan
= 0;
2057 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2063 alu
.op
= ALU_OP1_SIN
;
2064 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2066 alu
.src
[0].sel
= ctx
->temp_reg
;
2067 alu
.src
[0].chan
= 0;
2069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2076 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2079 alu
.op
= ALU_OP1_MOV
;
2081 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2083 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2084 alu
.src
[0].chan
= 0;
2088 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2094 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2095 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2097 alu
.op
= ALU_OP1_MOV
;
2099 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2101 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2102 alu
.src
[0].chan
= 0;
2106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2114 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2116 struct r600_bytecode_alu alu
;
2119 for (i
= 0; i
< 4; i
++) {
2120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2121 alu
.op
= ctx
->inst_info
->op
;
2125 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2127 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2128 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2131 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2136 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2141 /* kill must be last in ALU */
2142 ctx
->bc
->force_add_cf
= 1;
2143 ctx
->shader
->uses_kill
= TRUE
;
2147 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2149 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2150 struct r600_bytecode_alu alu
;
2153 /* tmp.x = max(src.y, 0.0) */
2154 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2155 alu
.op
= ALU_OP2_MAX
;
2156 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2157 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2158 alu
.src
[1].chan
= 1;
2160 alu
.dst
.sel
= ctx
->temp_reg
;
2165 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2169 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2175 if (ctx
->bc
->chip_class
== CAYMAN
) {
2176 for (i
= 0; i
< 3; i
++) {
2177 /* tmp.z = log(tmp.x) */
2178 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2179 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2180 alu
.src
[0].sel
= ctx
->temp_reg
;
2181 alu
.src
[0].chan
= 0;
2182 alu
.dst
.sel
= ctx
->temp_reg
;
2190 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2195 /* tmp.z = log(tmp.x) */
2196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2197 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2198 alu
.src
[0].sel
= ctx
->temp_reg
;
2199 alu
.src
[0].chan
= 0;
2200 alu
.dst
.sel
= ctx
->temp_reg
;
2204 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2209 chan
= alu
.dst
.chan
;
2212 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2214 alu
.op
= ALU_OP3_MUL_LIT
;
2215 alu
.src
[0].sel
= sel
;
2216 alu
.src
[0].chan
= chan
;
2217 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2218 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2219 alu
.dst
.sel
= ctx
->temp_reg
;
2224 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2228 if (ctx
->bc
->chip_class
== CAYMAN
) {
2229 for (i
= 0; i
< 3; i
++) {
2230 /* dst.z = exp(tmp.x) */
2231 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2232 alu
.op
= ALU_OP1_EXP_IEEE
;
2233 alu
.src
[0].sel
= ctx
->temp_reg
;
2234 alu
.src
[0].chan
= 0;
2235 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2241 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2246 /* dst.z = exp(tmp.x) */
2247 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2248 alu
.op
= ALU_OP1_EXP_IEEE
;
2249 alu
.src
[0].sel
= ctx
->temp_reg
;
2250 alu
.src
[0].chan
= 0;
2251 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2261 alu
.op
= ALU_OP1_MOV
;
2262 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2263 alu
.src
[0].chan
= 0;
2264 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2265 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2270 /* dst.y = max(src.x, 0.0) */
2271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2272 alu
.op
= ALU_OP2_MAX
;
2273 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2274 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2275 alu
.src
[1].chan
= 0;
2276 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2277 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2283 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2284 alu
.op
= ALU_OP1_MOV
;
2285 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2286 alu
.src
[0].chan
= 0;
2287 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2288 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2290 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2297 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2299 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2300 struct r600_bytecode_alu alu
;
2303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2306 * For state trackers other than OpenGL, we'll want to use
2307 * _RECIPSQRT_IEEE instead.
2309 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2311 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2312 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2313 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2315 alu
.dst
.sel
= ctx
->temp_reg
;
2318 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2321 /* replicate result */
2322 return tgsi_helper_tempx_replicate(ctx
);
2325 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2327 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2328 struct r600_bytecode_alu alu
;
2331 for (i
= 0; i
< 4; i
++) {
2332 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2333 alu
.src
[0].sel
= ctx
->temp_reg
;
2334 alu
.op
= ALU_OP1_MOV
;
2336 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2337 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2340 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2347 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2349 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2350 struct r600_bytecode_alu alu
;
2353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2354 alu
.op
= ctx
->inst_info
->op
;
2355 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2356 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2358 alu
.dst
.sel
= ctx
->temp_reg
;
2361 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2364 /* replicate result */
2365 return tgsi_helper_tempx_replicate(ctx
);
2368 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2370 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2372 struct r600_bytecode_alu alu
;
2373 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2375 for (i
= 0; i
< 3; i
++) {
2376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2377 alu
.op
= ALU_OP1_LOG_IEEE
;
2378 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2379 alu
.dst
.sel
= ctx
->temp_reg
;
2384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2391 alu
.op
= ALU_OP2_MUL
;
2392 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2393 alu
.src
[1].sel
= ctx
->temp_reg
;
2394 alu
.dst
.sel
= ctx
->temp_reg
;
2397 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2401 for (i
= 0; i
< last_slot
; i
++) {
2402 /* POW(a,b) = EXP2(b * LOG2(a))*/
2403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2404 alu
.op
= ALU_OP1_EXP_IEEE
;
2405 alu
.src
[0].sel
= ctx
->temp_reg
;
2407 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2408 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2409 if (i
== last_slot
- 1)
2411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2418 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2420 struct r600_bytecode_alu alu
;
2424 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2425 alu
.op
= ALU_OP1_LOG_IEEE
;
2426 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2427 alu
.dst
.sel
= ctx
->temp_reg
;
2430 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2434 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2435 alu
.op
= ALU_OP2_MUL
;
2436 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2437 alu
.src
[1].sel
= ctx
->temp_reg
;
2438 alu
.dst
.sel
= ctx
->temp_reg
;
2441 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2444 /* POW(a,b) = EXP2(b * LOG2(a))*/
2445 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2446 alu
.op
= ALU_OP1_EXP_IEEE
;
2447 alu
.src
[0].sel
= ctx
->temp_reg
;
2448 alu
.dst
.sel
= ctx
->temp_reg
;
2451 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2454 return tgsi_helper_tempx_replicate(ctx
);
2457 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2459 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2460 struct r600_bytecode_alu alu
;
2462 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2463 int tmp0
= ctx
->temp_reg
;
2464 int tmp1
= r600_get_temp(ctx
);
2465 int tmp2
= r600_get_temp(ctx
);
2466 int tmp3
= r600_get_temp(ctx
);
2469 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2471 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2472 * 2. tmp0.z = lo (tmp0.x * src2)
2473 * 3. tmp0.w = -tmp0.z
2474 * 4. tmp0.y = hi (tmp0.x * src2)
2475 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2476 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2477 * 7. tmp1.x = tmp0.x - tmp0.w
2478 * 8. tmp1.y = tmp0.x + tmp0.w
2479 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2480 * 10. tmp0.z = hi(tmp0.x * src1) = q
2481 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2483 * 12. tmp0.w = src1 - tmp0.y = r
2484 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2485 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2489 * 15. tmp1.z = tmp0.z + 1 = q + 1
2490 * 16. tmp1.w = tmp0.z - 1 = q - 1
2494 * 15. tmp1.z = tmp0.w - src2 = r - src2
2495 * 16. tmp1.w = tmp0.w + src2 = r + src2
2499 * 17. tmp1.x = tmp1.x & tmp1.y
2501 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2502 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2504 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2505 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2509 * Same as unsigned, using abs values of the operands,
2510 * and fixing the sign of the result in the end.
2513 for (i
= 0; i
< 4; i
++) {
2514 if (!(write_mask
& (1<<i
)))
2519 /* tmp2.x = -src0 */
2520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2521 alu
.op
= ALU_OP2_SUB_INT
;
2527 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2529 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2532 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2535 /* tmp2.y = -src1 */
2536 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2537 alu
.op
= ALU_OP2_SUB_INT
;
2543 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2545 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2548 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2551 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2552 /* it will be a sign of the quotient */
2555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2556 alu
.op
= ALU_OP2_XOR_INT
;
2562 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2563 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2566 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2570 /* tmp2.x = |src0| */
2571 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2572 alu
.op
= ALU_OP3_CNDGE_INT
;
2579 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2580 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2581 alu
.src
[2].sel
= tmp2
;
2582 alu
.src
[2].chan
= 0;
2585 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2588 /* tmp2.y = |src1| */
2589 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2590 alu
.op
= ALU_OP3_CNDGE_INT
;
2597 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2598 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2599 alu
.src
[2].sel
= tmp2
;
2600 alu
.src
[2].chan
= 1;
2603 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2608 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2609 if (ctx
->bc
->chip_class
== CAYMAN
) {
2610 /* tmp3.x = u2f(src2) */
2611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2612 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2619 alu
.src
[0].sel
= tmp2
;
2620 alu
.src
[0].chan
= 1;
2622 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2626 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2629 /* tmp0.x = recip(tmp3.x) */
2630 for (j
= 0 ; j
< 3; j
++) {
2631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2632 alu
.op
= ALU_OP1_RECIP_IEEE
;
2636 alu
.dst
.write
= (j
== 0);
2638 alu
.src
[0].sel
= tmp3
;
2639 alu
.src
[0].chan
= 0;
2643 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2648 alu
.op
= ALU_OP2_MUL
;
2650 alu
.src
[0].sel
= tmp0
;
2651 alu
.src
[0].chan
= 0;
2653 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2654 alu
.src
[1].value
= 0x4f800000;
2659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2663 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2664 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2670 alu
.src
[0].sel
= tmp3
;
2671 alu
.src
[0].chan
= 0;
2674 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2678 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2679 alu
.op
= ALU_OP1_RECIP_UINT
;
2686 alu
.src
[0].sel
= tmp2
;
2687 alu
.src
[0].chan
= 1;
2689 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2693 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2697 /* 2. tmp0.z = lo (tmp0.x * src2) */
2698 if (ctx
->bc
->chip_class
== CAYMAN
) {
2699 for (j
= 0 ; j
< 4; j
++) {
2700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2701 alu
.op
= ALU_OP2_MULLO_UINT
;
2705 alu
.dst
.write
= (j
== 2);
2707 alu
.src
[0].sel
= tmp0
;
2708 alu
.src
[0].chan
= 0;
2710 alu
.src
[1].sel
= tmp2
;
2711 alu
.src
[1].chan
= 1;
2713 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2716 alu
.last
= (j
== 3);
2717 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2721 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2722 alu
.op
= ALU_OP2_MULLO_UINT
;
2728 alu
.src
[0].sel
= tmp0
;
2729 alu
.src
[0].chan
= 0;
2731 alu
.src
[1].sel
= tmp2
;
2732 alu
.src
[1].chan
= 1;
2734 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2738 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2742 /* 3. tmp0.w = -tmp0.z */
2743 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2744 alu
.op
= ALU_OP2_SUB_INT
;
2750 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2751 alu
.src
[1].sel
= tmp0
;
2752 alu
.src
[1].chan
= 2;
2755 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2758 /* 4. tmp0.y = hi (tmp0.x * src2) */
2759 if (ctx
->bc
->chip_class
== CAYMAN
) {
2760 for (j
= 0 ; j
< 4; j
++) {
2761 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2762 alu
.op
= ALU_OP2_MULHI_UINT
;
2766 alu
.dst
.write
= (j
== 1);
2768 alu
.src
[0].sel
= tmp0
;
2769 alu
.src
[0].chan
= 0;
2772 alu
.src
[1].sel
= tmp2
;
2773 alu
.src
[1].chan
= 1;
2775 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2777 alu
.last
= (j
== 3);
2778 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2783 alu
.op
= ALU_OP2_MULHI_UINT
;
2789 alu
.src
[0].sel
= tmp0
;
2790 alu
.src
[0].chan
= 0;
2793 alu
.src
[1].sel
= tmp2
;
2794 alu
.src
[1].chan
= 1;
2796 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2800 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2804 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
2805 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2806 alu
.op
= ALU_OP3_CNDE_INT
;
2813 alu
.src
[0].sel
= tmp0
;
2814 alu
.src
[0].chan
= 1;
2815 alu
.src
[1].sel
= tmp0
;
2816 alu
.src
[1].chan
= 3;
2817 alu
.src
[2].sel
= tmp0
;
2818 alu
.src
[2].chan
= 2;
2821 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2824 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
2825 if (ctx
->bc
->chip_class
== CAYMAN
) {
2826 for (j
= 0 ; j
< 4; j
++) {
2827 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2828 alu
.op
= ALU_OP2_MULHI_UINT
;
2832 alu
.dst
.write
= (j
== 3);
2834 alu
.src
[0].sel
= tmp0
;
2835 alu
.src
[0].chan
= 2;
2837 alu
.src
[1].sel
= tmp0
;
2838 alu
.src
[1].chan
= 0;
2840 alu
.last
= (j
== 3);
2841 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2845 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2846 alu
.op
= ALU_OP2_MULHI_UINT
;
2852 alu
.src
[0].sel
= tmp0
;
2853 alu
.src
[0].chan
= 2;
2855 alu
.src
[1].sel
= tmp0
;
2856 alu
.src
[1].chan
= 0;
2859 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2863 /* 7. tmp1.x = tmp0.x - tmp0.w */
2864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2865 alu
.op
= ALU_OP2_SUB_INT
;
2871 alu
.src
[0].sel
= tmp0
;
2872 alu
.src
[0].chan
= 0;
2873 alu
.src
[1].sel
= tmp0
;
2874 alu
.src
[1].chan
= 3;
2877 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2880 /* 8. tmp1.y = tmp0.x + tmp0.w */
2881 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2882 alu
.op
= ALU_OP2_ADD_INT
;
2888 alu
.src
[0].sel
= tmp0
;
2889 alu
.src
[0].chan
= 0;
2890 alu
.src
[1].sel
= tmp0
;
2891 alu
.src
[1].chan
= 3;
2894 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2897 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
2898 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2899 alu
.op
= ALU_OP3_CNDE_INT
;
2906 alu
.src
[0].sel
= tmp0
;
2907 alu
.src
[0].chan
= 1;
2908 alu
.src
[1].sel
= tmp1
;
2909 alu
.src
[1].chan
= 1;
2910 alu
.src
[2].sel
= tmp1
;
2911 alu
.src
[2].chan
= 0;
2914 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2917 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
2918 if (ctx
->bc
->chip_class
== CAYMAN
) {
2919 for (j
= 0 ; j
< 4; j
++) {
2920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2921 alu
.op
= ALU_OP2_MULHI_UINT
;
2925 alu
.dst
.write
= (j
== 2);
2927 alu
.src
[0].sel
= tmp0
;
2928 alu
.src
[0].chan
= 0;
2931 alu
.src
[1].sel
= tmp2
;
2932 alu
.src
[1].chan
= 0;
2934 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2937 alu
.last
= (j
== 3);
2938 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2943 alu
.op
= ALU_OP2_MULHI_UINT
;
2949 alu
.src
[0].sel
= tmp0
;
2950 alu
.src
[0].chan
= 0;
2953 alu
.src
[1].sel
= tmp2
;
2954 alu
.src
[1].chan
= 0;
2956 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2960 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2964 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
2965 if (ctx
->bc
->chip_class
== CAYMAN
) {
2966 for (j
= 0 ; j
< 4; j
++) {
2967 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2968 alu
.op
= ALU_OP2_MULLO_UINT
;
2972 alu
.dst
.write
= (j
== 1);
2975 alu
.src
[0].sel
= tmp2
;
2976 alu
.src
[0].chan
= 1;
2978 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2981 alu
.src
[1].sel
= tmp0
;
2982 alu
.src
[1].chan
= 2;
2984 alu
.last
= (j
== 3);
2985 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2990 alu
.op
= ALU_OP2_MULLO_UINT
;
2997 alu
.src
[0].sel
= tmp2
;
2998 alu
.src
[0].chan
= 1;
3000 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3003 alu
.src
[1].sel
= tmp0
;
3004 alu
.src
[1].chan
= 2;
3007 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3011 /* 12. tmp0.w = src1 - tmp0.y = r */
3012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3013 alu
.op
= ALU_OP2_SUB_INT
;
3020 alu
.src
[0].sel
= tmp2
;
3021 alu
.src
[0].chan
= 0;
3023 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3026 alu
.src
[1].sel
= tmp0
;
3027 alu
.src
[1].chan
= 1;
3030 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3033 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3034 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3035 alu
.op
= ALU_OP2_SETGE_UINT
;
3041 alu
.src
[0].sel
= tmp0
;
3042 alu
.src
[0].chan
= 3;
3044 alu
.src
[1].sel
= tmp2
;
3045 alu
.src
[1].chan
= 1;
3047 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3051 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3054 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3056 alu
.op
= ALU_OP2_SETGE_UINT
;
3063 alu
.src
[0].sel
= tmp2
;
3064 alu
.src
[0].chan
= 0;
3066 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3069 alu
.src
[1].sel
= tmp0
;
3070 alu
.src
[1].chan
= 1;
3073 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3076 if (mod
) { /* UMOD */
3078 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3080 alu
.op
= ALU_OP2_SUB_INT
;
3086 alu
.src
[0].sel
= tmp0
;
3087 alu
.src
[0].chan
= 3;
3090 alu
.src
[1].sel
= tmp2
;
3091 alu
.src
[1].chan
= 1;
3093 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3097 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3100 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3101 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3102 alu
.op
= ALU_OP2_ADD_INT
;
3108 alu
.src
[0].sel
= tmp0
;
3109 alu
.src
[0].chan
= 3;
3111 alu
.src
[1].sel
= tmp2
;
3112 alu
.src
[1].chan
= 1;
3114 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3118 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3123 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3124 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3125 alu
.op
= ALU_OP2_ADD_INT
;
3131 alu
.src
[0].sel
= tmp0
;
3132 alu
.src
[0].chan
= 2;
3133 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3136 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3139 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3140 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3141 alu
.op
= ALU_OP2_ADD_INT
;
3147 alu
.src
[0].sel
= tmp0
;
3148 alu
.src
[0].chan
= 2;
3149 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3152 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3157 /* 17. tmp1.x = tmp1.x & tmp1.y */
3158 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3159 alu
.op
= ALU_OP2_AND_INT
;
3165 alu
.src
[0].sel
= tmp1
;
3166 alu
.src
[0].chan
= 0;
3167 alu
.src
[1].sel
= tmp1
;
3168 alu
.src
[1].chan
= 1;
3171 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3174 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3175 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3177 alu
.op
= ALU_OP3_CNDE_INT
;
3184 alu
.src
[0].sel
= tmp1
;
3185 alu
.src
[0].chan
= 0;
3186 alu
.src
[1].sel
= tmp0
;
3187 alu
.src
[1].chan
= mod
? 3 : 2;
3188 alu
.src
[2].sel
= tmp1
;
3189 alu
.src
[2].chan
= 2;
3192 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3195 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3197 alu
.op
= ALU_OP3_CNDE_INT
;
3205 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3208 alu
.src
[0].sel
= tmp1
;
3209 alu
.src
[0].chan
= 1;
3210 alu
.src
[1].sel
= tmp1
;
3211 alu
.src
[1].chan
= 3;
3212 alu
.src
[2].sel
= tmp0
;
3213 alu
.src
[2].chan
= 2;
3216 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3221 /* fix the sign of the result */
3225 /* tmp0.x = -tmp0.z */
3226 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3227 alu
.op
= ALU_OP2_SUB_INT
;
3233 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3234 alu
.src
[1].sel
= tmp0
;
3235 alu
.src
[1].chan
= 2;
3238 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3241 /* sign of the remainder is the same as the sign of src0 */
3242 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3243 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3244 alu
.op
= ALU_OP3_CNDGE_INT
;
3247 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3249 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3250 alu
.src
[1].sel
= tmp0
;
3251 alu
.src
[1].chan
= 2;
3252 alu
.src
[2].sel
= tmp0
;
3253 alu
.src
[2].chan
= 0;
3256 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3261 /* tmp0.x = -tmp0.z */
3262 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3263 alu
.op
= ALU_OP2_SUB_INT
;
3269 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3270 alu
.src
[1].sel
= tmp0
;
3271 alu
.src
[1].chan
= 2;
3274 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3277 /* fix the quotient sign (same as the sign of src0*src1) */
3278 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3279 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3280 alu
.op
= ALU_OP3_CNDGE_INT
;
3283 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3285 alu
.src
[0].sel
= tmp2
;
3286 alu
.src
[0].chan
= 2;
3287 alu
.src
[1].sel
= tmp0
;
3288 alu
.src
[1].chan
= 2;
3289 alu
.src
[2].sel
= tmp0
;
3290 alu
.src
[2].chan
= 0;
3293 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3301 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3303 return tgsi_divmod(ctx
, 0, 0);
3306 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3308 return tgsi_divmod(ctx
, 1, 0);
3311 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3313 return tgsi_divmod(ctx
, 0, 1);
3316 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3318 return tgsi_divmod(ctx
, 1, 1);
3322 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3324 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3325 struct r600_bytecode_alu alu
;
3327 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3328 int last_inst
= tgsi_last_instruction(write_mask
);
3330 for (i
= 0; i
< 4; i
++) {
3331 if (!(write_mask
& (1<<i
)))
3334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3335 alu
.op
= ALU_OP1_TRUNC
;
3337 alu
.dst
.sel
= ctx
->temp_reg
;
3341 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3344 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3349 for (i
= 0; i
< 4; i
++) {
3350 if (!(write_mask
& (1<<i
)))
3353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3354 alu
.op
= ctx
->inst_info
->op
;
3356 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3358 alu
.src
[0].sel
= ctx
->temp_reg
;
3359 alu
.src
[0].chan
= i
;
3361 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3363 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3371 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3373 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3374 struct r600_bytecode_alu alu
;
3376 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3377 int last_inst
= tgsi_last_instruction(write_mask
);
3380 for (i
= 0; i
< 4; i
++) {
3381 if (!(write_mask
& (1<<i
)))
3384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3385 alu
.op
= ALU_OP2_SUB_INT
;
3387 alu
.dst
.sel
= ctx
->temp_reg
;
3391 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3392 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3396 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3401 /* dst = (src >= 0 ? src : tmp) */
3402 for (i
= 0; i
< 4; i
++) {
3403 if (!(write_mask
& (1<<i
)))
3406 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3407 alu
.op
= ALU_OP3_CNDGE_INT
;
3411 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3413 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3414 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3415 alu
.src
[2].sel
= ctx
->temp_reg
;
3416 alu
.src
[2].chan
= i
;
3420 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3427 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3429 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3430 struct r600_bytecode_alu alu
;
3432 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3433 int last_inst
= tgsi_last_instruction(write_mask
);
3435 /* tmp = (src >= 0 ? src : -1) */
3436 for (i
= 0; i
< 4; i
++) {
3437 if (!(write_mask
& (1<<i
)))
3440 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3441 alu
.op
= ALU_OP3_CNDGE_INT
;
3444 alu
.dst
.sel
= ctx
->temp_reg
;
3448 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3449 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3450 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3454 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3459 /* dst = (tmp > 0 ? 1 : tmp) */
3460 for (i
= 0; i
< 4; i
++) {
3461 if (!(write_mask
& (1<<i
)))
3464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3465 alu
.op
= ALU_OP3_CNDGT_INT
;
3469 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3471 alu
.src
[0].sel
= ctx
->temp_reg
;
3472 alu
.src
[0].chan
= i
;
3474 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3476 alu
.src
[2].sel
= ctx
->temp_reg
;
3477 alu
.src
[2].chan
= i
;
3481 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3490 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3492 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3493 struct r600_bytecode_alu alu
;
3496 /* tmp = (src > 0 ? 1 : src) */
3497 for (i
= 0; i
< 4; i
++) {
3498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3499 alu
.op
= ALU_OP3_CNDGT
;
3502 alu
.dst
.sel
= ctx
->temp_reg
;
3505 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3506 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3507 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3511 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3516 /* dst = (-tmp > 0 ? -1 : tmp) */
3517 for (i
= 0; i
< 4; i
++) {
3518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3519 alu
.op
= ALU_OP3_CNDGT
;
3521 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3523 alu
.src
[0].sel
= ctx
->temp_reg
;
3524 alu
.src
[0].chan
= i
;
3527 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3530 alu
.src
[2].sel
= ctx
->temp_reg
;
3531 alu
.src
[2].chan
= i
;
3535 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3542 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3544 struct r600_bytecode_alu alu
;
3547 for (i
= 0; i
< 4; i
++) {
3548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3549 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3550 alu
.op
= ALU_OP0_NOP
;
3553 alu
.op
= ALU_OP1_MOV
;
3554 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3555 alu
.src
[0].sel
= ctx
->temp_reg
;
3556 alu
.src
[0].chan
= i
;
3561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3568 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3570 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3571 struct r600_bytecode_alu alu
;
3573 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3575 for (i
= 0; i
< lasti
+ 1; i
++) {
3576 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3580 alu
.op
= ctx
->inst_info
->op
;
3581 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3582 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3585 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3592 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3599 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3601 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3602 struct r600_bytecode_alu alu
;
3605 for (i
= 0; i
< 4; i
++) {
3606 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3607 alu
.op
= ctx
->inst_info
->op
;
3608 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3609 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3612 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3614 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3615 /* handle some special cases */
3616 switch (ctx
->inst_info
->tgsi_opcode
) {
3617 case TGSI_OPCODE_DP2
:
3619 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3620 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3623 case TGSI_OPCODE_DP3
:
3625 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3626 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3629 case TGSI_OPCODE_DPH
:
3631 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3632 alu
.src
[0].chan
= 0;
3642 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3649 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3652 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3653 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3654 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3655 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3656 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3659 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3662 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3663 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3666 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3668 struct r600_bytecode_vtx vtx
;
3669 struct r600_bytecode_alu alu
;
3670 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3672 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3674 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3675 if (src_requires_loading
) {
3676 for (i
= 0; i
< 4; i
++) {
3677 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3678 alu
.op
= ALU_OP1_MOV
;
3679 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3680 alu
.dst
.sel
= ctx
->temp_reg
;
3685 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3689 src_gpr
= ctx
->temp_reg
;
3692 memset(&vtx
, 0, sizeof(vtx
));
3693 vtx
.op
= FETCH_OP_VFETCH
;
3694 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3695 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3696 vtx
.src_gpr
= src_gpr
;
3697 vtx
.mega_fetch_count
= 16;
3698 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3699 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3700 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3701 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
3702 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
3703 vtx
.use_const_fields
= 1;
3704 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
3706 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
3709 if (ctx
->bc
->chip_class
>= EVERGREEN
)
3712 for (i
= 0; i
< 4; i
++) {
3713 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3714 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3717 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3718 alu
.op
= ALU_OP2_AND_INT
;
3721 alu
.dst
.sel
= vtx
.dst_gpr
;
3724 alu
.src
[0].sel
= vtx
.dst_gpr
;
3725 alu
.src
[0].chan
= i
;
3727 alu
.src
[1].sel
= 512 + (id
* 2);
3728 alu
.src
[1].chan
= i
% 4;
3729 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3733 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3738 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
3739 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3740 alu
.op
= ALU_OP2_OR_INT
;
3743 alu
.dst
.sel
= vtx
.dst_gpr
;
3746 alu
.src
[0].sel
= vtx
.dst_gpr
;
3747 alu
.src
[0].chan
= 3;
3749 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
3750 alu
.src
[1].chan
= 0;
3751 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3754 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3761 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
3763 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3764 struct r600_bytecode_alu alu
;
3766 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3768 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3769 alu
.op
= ALU_OP1_MOV
;
3771 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
3772 alu
.src
[0].sel
= 512 + (id
/ 4);
3773 alu
.src
[0].chan
= id
% 4;
3775 /* r600 we have them at channel 2 of the second dword */
3776 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
3777 alu
.src
[0].chan
= 1;
3779 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3780 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3782 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3788 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
3790 static float one_point_five
= 1.5f
;
3791 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3792 struct r600_bytecode_tex tex
;
3793 struct r600_bytecode_alu alu
;
3797 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
3798 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
3799 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
3800 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
3802 /* Texture fetch instructions can only use gprs as source.
3803 * Also they cannot negate the source or take the absolute value */
3804 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
3805 tgsi_tex_src_requires_loading(ctx
, 0)) ||
3806 read_compressed_msaa
;
3807 boolean src_loaded
= FALSE
;
3808 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
3809 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
3810 boolean has_txq_cube_array_z
= false;
3812 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
3813 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3814 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
3815 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
3816 ctx
->shader
->has_txq_cube_array_z_comp
= true;
3817 has_txq_cube_array_z
= true;
3820 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
3821 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
3822 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
3823 sampler_src_reg
= 2;
3825 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3827 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
3828 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
3829 ctx
->shader
->uses_tex_buffers
= true;
3830 return r600_do_buffer_txq(ctx
);
3832 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3833 if (ctx
->bc
->chip_class
< EVERGREEN
)
3834 ctx
->shader
->uses_tex_buffers
= true;
3835 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
3839 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3840 /* get offset values */
3841 if (inst
->Texture
.NumOffsets
) {
3842 assert(inst
->Texture
.NumOffsets
== 1);
3844 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
3845 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
3846 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
3848 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
3849 /* TGSI moves the sampler to src reg 3 for TXD */
3850 sampler_src_reg
= 3;
3852 for (i
= 1; i
< 3; i
++) {
3853 /* set gradients h/v */
3854 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
3855 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
3856 FETCH_OP_SET_GRADIENTS_V
;
3857 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
3858 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
3860 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
3861 tex
.src_gpr
= r600_get_temp(ctx
);
3867 for (j
= 0; j
< 4; j
++) {
3868 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3869 alu
.op
= ALU_OP1_MOV
;
3870 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
3871 alu
.dst
.sel
= tex
.src_gpr
;
3876 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3882 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
3883 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
3884 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
3885 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
3886 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
3887 tex
.src_rel
= ctx
->src
[i
].rel
;
3889 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
3890 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
3891 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
3892 tex
.coord_type_x
= 1;
3893 tex
.coord_type_y
= 1;
3894 tex
.coord_type_z
= 1;
3895 tex
.coord_type_w
= 1;
3897 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
3901 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
3903 /* Add perspective divide */
3904 if (ctx
->bc
->chip_class
== CAYMAN
) {
3906 for (i
= 0; i
< 3; i
++) {
3907 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3908 alu
.op
= ALU_OP1_RECIP_IEEE
;
3909 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3911 alu
.dst
.sel
= ctx
->temp_reg
;
3917 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3925 alu
.op
= ALU_OP1_RECIP_IEEE
;
3926 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3928 alu
.dst
.sel
= ctx
->temp_reg
;
3929 alu
.dst
.chan
= out_chan
;
3932 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3937 for (i
= 0; i
< 3; i
++) {
3938 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3939 alu
.op
= ALU_OP2_MUL
;
3940 alu
.src
[0].sel
= ctx
->temp_reg
;
3941 alu
.src
[0].chan
= out_chan
;
3942 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3943 alu
.dst
.sel
= ctx
->temp_reg
;
3946 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3951 alu
.op
= ALU_OP1_MOV
;
3952 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3953 alu
.src
[0].chan
= 0;
3954 alu
.dst
.sel
= ctx
->temp_reg
;
3958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3962 src_gpr
= ctx
->temp_reg
;
3965 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
3966 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3967 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
3968 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
3969 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
3970 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
3972 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
3973 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
3975 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
3976 for (i
= 0; i
< 4; i
++) {
3977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3978 alu
.op
= ALU_OP2_CUBE
;
3979 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
3980 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
3981 alu
.dst
.sel
= ctx
->temp_reg
;
3986 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3991 /* tmp1.z = RCP_e(|tmp1.z|) */
3992 if (ctx
->bc
->chip_class
== CAYMAN
) {
3993 for (i
= 0; i
< 3; i
++) {
3994 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3995 alu
.op
= ALU_OP1_RECIP_IEEE
;
3996 alu
.src
[0].sel
= ctx
->temp_reg
;
3997 alu
.src
[0].chan
= 2;
3999 alu
.dst
.sel
= ctx
->temp_reg
;
4005 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4010 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4011 alu
.op
= ALU_OP1_RECIP_IEEE
;
4012 alu
.src
[0].sel
= ctx
->temp_reg
;
4013 alu
.src
[0].chan
= 2;
4015 alu
.dst
.sel
= ctx
->temp_reg
;
4019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4024 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4025 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4026 * muladd has no writemask, have to use another temp
4028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4029 alu
.op
= ALU_OP3_MULADD
;
4032 alu
.src
[0].sel
= ctx
->temp_reg
;
4033 alu
.src
[0].chan
= 0;
4034 alu
.src
[1].sel
= ctx
->temp_reg
;
4035 alu
.src
[1].chan
= 2;
4037 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4038 alu
.src
[2].chan
= 0;
4039 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4041 alu
.dst
.sel
= ctx
->temp_reg
;
4045 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4050 alu
.op
= ALU_OP3_MULADD
;
4053 alu
.src
[0].sel
= ctx
->temp_reg
;
4054 alu
.src
[0].chan
= 1;
4055 alu
.src
[1].sel
= ctx
->temp_reg
;
4056 alu
.src
[1].chan
= 2;
4058 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4059 alu
.src
[2].chan
= 0;
4060 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4062 alu
.dst
.sel
= ctx
->temp_reg
;
4067 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4070 /* write initial compare value into Z component
4071 - W src 0 for shadow cube
4072 - X src 1 for shadow cube array */
4073 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4074 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4075 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4076 alu
.op
= ALU_OP1_MOV
;
4077 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4078 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4080 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4081 alu
.dst
.sel
= ctx
->temp_reg
;
4085 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4090 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4091 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4092 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4093 int mytmp
= r600_get_temp(ctx
);
4094 static const float eight
= 8.0f
;
4095 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4096 alu
.op
= ALU_OP1_MOV
;
4097 alu
.src
[0].sel
= ctx
->temp_reg
;
4098 alu
.src
[0].chan
= 3;
4099 alu
.dst
.sel
= mytmp
;
4103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4107 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4108 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4109 alu
.op
= ALU_OP3_MULADD
;
4111 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4112 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4113 alu
.src
[1].chan
= 0;
4114 alu
.src
[1].value
= *(uint32_t *)&eight
;
4115 alu
.src
[2].sel
= mytmp
;
4116 alu
.src
[2].chan
= 0;
4117 alu
.dst
.sel
= ctx
->temp_reg
;
4121 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4124 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4125 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4126 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4127 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4128 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4129 tex
.src_gpr
= r600_get_temp(ctx
);
4134 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4135 tex
.coord_type_x
= 1;
4136 tex
.coord_type_y
= 1;
4137 tex
.coord_type_z
= 1;
4138 tex
.coord_type_w
= 1;
4139 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4140 alu
.op
= ALU_OP1_MOV
;
4141 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4142 alu
.dst
.sel
= tex
.src_gpr
;
4146 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4150 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4157 /* for cube forms of lod and bias we need to route things */
4158 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4159 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4160 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4161 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4163 alu
.op
= ALU_OP1_MOV
;
4164 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4165 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4166 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4168 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4169 alu
.dst
.sel
= ctx
->temp_reg
;
4173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4179 src_gpr
= ctx
->temp_reg
;
4182 if (src_requires_loading
&& !src_loaded
) {
4183 for (i
= 0; i
< 4; i
++) {
4184 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4185 alu
.op
= ALU_OP1_MOV
;
4186 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4187 alu
.dst
.sel
= ctx
->temp_reg
;
4192 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4197 src_gpr
= ctx
->temp_reg
;
4200 /* Obtain the sample index for reading a compressed MSAA color texture.
4201 * To read the FMASK, we use the ldfptr instruction, which tells us
4202 * where the samples are stored.
4203 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4204 * which is the identity mapping. Each nibble says which physical sample
4205 * should be fetched to get that sample.
4207 * Assume src.z contains the sample index. It should be modified like this:
4208 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4209 * Then fetch the texel with src.
4211 if (read_compressed_msaa
) {
4212 unsigned sample_chan
= 3;
4213 unsigned temp
= r600_get_temp(ctx
);
4216 /* temp.w = ldfptr() */
4217 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4218 tex
.op
= FETCH_OP_LD
;
4219 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4220 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4221 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4222 tex
.src_gpr
= src_gpr
;
4224 tex
.dst_sel_x
= 7; /* mask out these components */
4227 tex
.dst_sel_w
= 0; /* store X */
4232 tex
.offset_x
= offset_x
;
4233 tex
.offset_y
= offset_y
;
4234 tex
.offset_z
= offset_z
;
4235 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4239 /* temp.x = sample_index*4 */
4240 if (ctx
->bc
->chip_class
== CAYMAN
) {
4241 for (i
= 0 ; i
< 4; i
++) {
4242 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4243 alu
.op
= ALU_OP2_MULLO_INT
;
4244 alu
.src
[0].sel
= src_gpr
;
4245 alu
.src
[0].chan
= sample_chan
;
4246 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4247 alu
.src
[1].value
= 4;
4250 alu
.dst
.write
= i
== 0;
4253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4258 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4259 alu
.op
= ALU_OP2_MULLO_INT
;
4260 alu
.src
[0].sel
= src_gpr
;
4261 alu
.src
[0].chan
= sample_chan
;
4262 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4263 alu
.src
[1].value
= 4;
4268 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4273 /* sample_index = temp.w >> temp.x */
4274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4275 alu
.op
= ALU_OP2_LSHR_INT
;
4276 alu
.src
[0].sel
= temp
;
4277 alu
.src
[0].chan
= 3;
4278 alu
.src
[1].sel
= temp
;
4279 alu
.src
[1].chan
= 0;
4280 alu
.dst
.sel
= src_gpr
;
4281 alu
.dst
.chan
= sample_chan
;
4284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4288 /* sample_index & 0xF */
4289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4290 alu
.op
= ALU_OP2_AND_INT
;
4291 alu
.src
[0].sel
= src_gpr
;
4292 alu
.src
[0].chan
= sample_chan
;
4293 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4294 alu
.src
[1].value
= 0xF;
4295 alu
.dst
.sel
= src_gpr
;
4296 alu
.dst
.chan
= sample_chan
;
4299 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4303 /* visualize the FMASK */
4304 for (i
= 0; i
< 4; i
++) {
4305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4306 alu
.op
= ALU_OP1_INT_TO_FLT
;
4307 alu
.src
[0].sel
= src_gpr
;
4308 alu
.src
[0].chan
= sample_chan
;
4309 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4313 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4321 /* does this shader want a num layers from TXQ for a cube array? */
4322 if (has_txq_cube_array_z
) {
4323 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4326 alu
.op
= ALU_OP1_MOV
;
4328 alu
.src
[0].sel
= 512 + (id
/ 4);
4329 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4330 alu
.src
[0].chan
= id
% 4;
4331 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4333 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4336 /* disable writemask from texture instruction */
4337 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4340 opcode
= ctx
->inst_info
->op
;
4341 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4342 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4343 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4344 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4345 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4346 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4347 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4349 case FETCH_OP_SAMPLE
:
4350 opcode
= FETCH_OP_SAMPLE_C
;
4352 case FETCH_OP_SAMPLE_L
:
4353 opcode
= FETCH_OP_SAMPLE_C_L
;
4355 case FETCH_OP_SAMPLE_LB
:
4356 opcode
= FETCH_OP_SAMPLE_C_LB
;
4358 case FETCH_OP_SAMPLE_G
:
4359 opcode
= FETCH_OP_SAMPLE_C_G
;
4364 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4367 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4368 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4369 tex
.src_gpr
= src_gpr
;
4370 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4371 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4372 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4373 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4374 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4376 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4381 } else if (src_loaded
) {
4387 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4388 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4389 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4390 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4391 tex
.src_rel
= ctx
->src
[0].rel
;
4394 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4395 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4396 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4397 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4401 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4404 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4405 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4406 tex
.coord_type_x
= 1;
4407 tex
.coord_type_y
= 1;
4409 tex
.coord_type_z
= 1;
4410 tex
.coord_type_w
= 1;
4412 tex
.offset_x
= offset_x
;
4413 tex
.offset_y
= offset_y
;
4414 tex
.offset_z
= offset_z
;
4416 /* Put the depth for comparison in W.
4417 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4418 * Some instructions expect the depth in Z. */
4419 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4420 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4421 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4422 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4423 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4424 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4425 tex
.src_sel_w
= tex
.src_sel_z
;
4428 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4429 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4430 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4431 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4432 /* the array index is read from Y */
4433 tex
.coord_type_y
= 0;
4435 /* the array index is read from Z */
4436 tex
.coord_type_z
= 0;
4437 tex
.src_sel_z
= tex
.src_sel_y
;
4439 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4440 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4441 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4442 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4443 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4444 /* the array index is read from Z */
4445 tex
.coord_type_z
= 0;
4447 /* mask unused source components */
4448 if (opcode
== FETCH_OP_SAMPLE
) {
4449 switch (inst
->Texture
.Texture
) {
4450 case TGSI_TEXTURE_2D
:
4451 case TGSI_TEXTURE_RECT
:
4455 case TGSI_TEXTURE_1D_ARRAY
:
4459 case TGSI_TEXTURE_1D
:
4467 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4471 /* add shadow ambient support - gallium doesn't do it yet */
4475 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4477 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4478 struct r600_bytecode_alu alu
;
4479 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4483 /* optimize if it's just an equal balance */
4484 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4485 for (i
= 0; i
< lasti
+ 1; i
++) {
4486 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4489 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4490 alu
.op
= ALU_OP2_ADD
;
4491 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4492 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4494 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4499 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4507 for (i
= 0; i
< lasti
+ 1; i
++) {
4508 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4512 alu
.op
= ALU_OP2_ADD
;
4513 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4514 alu
.src
[0].chan
= 0;
4515 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4516 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4517 alu
.dst
.sel
= ctx
->temp_reg
;
4523 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4528 /* (1 - src0) * src2 */
4529 for (i
= 0; i
< lasti
+ 1; i
++) {
4530 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4533 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4534 alu
.op
= ALU_OP2_MUL
;
4535 alu
.src
[0].sel
= ctx
->temp_reg
;
4536 alu
.src
[0].chan
= i
;
4537 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4538 alu
.dst
.sel
= ctx
->temp_reg
;
4544 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4549 /* src0 * src1 + (1 - src0) * src2 */
4550 for (i
= 0; i
< lasti
+ 1; i
++) {
4551 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4555 alu
.op
= ALU_OP3_MULADD
;
4557 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4558 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4559 alu
.src
[2].sel
= ctx
->temp_reg
;
4560 alu
.src
[2].chan
= i
;
4562 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4567 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4574 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4576 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4577 struct r600_bytecode_alu alu
;
4579 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4581 for (i
= 0; i
< lasti
+ 1; i
++) {
4582 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4585 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4586 alu
.op
= ALU_OP3_CNDGE
;
4587 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4588 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4589 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4590 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4596 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4603 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4605 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4606 struct r600_bytecode_alu alu
;
4608 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4610 for (i
= 0; i
< lasti
+ 1; i
++) {
4611 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4615 alu
.op
= ALU_OP3_CNDGE_INT
;
4616 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4617 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4618 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4619 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4625 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4632 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4634 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4635 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4636 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4637 struct r600_bytecode_alu alu
;
4638 uint32_t use_temp
= 0;
4641 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4644 for (i
= 0; i
< 4; i
++) {
4645 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4646 alu
.op
= ALU_OP2_MUL
;
4648 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4649 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4651 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4652 alu
.src
[0].chan
= i
;
4653 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4654 alu
.src
[1].chan
= i
;
4657 alu
.dst
.sel
= ctx
->temp_reg
;
4663 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4668 for (i
= 0; i
< 4; i
++) {
4669 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4670 alu
.op
= ALU_OP3_MULADD
;
4673 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4674 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4676 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4677 alu
.src
[0].chan
= i
;
4678 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4679 alu
.src
[1].chan
= i
;
4682 alu
.src
[2].sel
= ctx
->temp_reg
;
4684 alu
.src
[2].chan
= i
;
4687 alu
.dst
.sel
= ctx
->temp_reg
;
4689 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4695 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4700 return tgsi_helper_copy(ctx
, inst
);
4704 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4706 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4707 struct r600_bytecode_alu alu
;
4711 /* result.x = 2^floor(src); */
4712 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4715 alu
.op
= ALU_OP1_FLOOR
;
4716 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4718 alu
.dst
.sel
= ctx
->temp_reg
;
4722 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4726 if (ctx
->bc
->chip_class
== CAYMAN
) {
4727 for (i
= 0; i
< 3; i
++) {
4728 alu
.op
= ALU_OP1_EXP_IEEE
;
4729 alu
.src
[0].sel
= ctx
->temp_reg
;
4730 alu
.src
[0].chan
= 0;
4732 alu
.dst
.sel
= ctx
->temp_reg
;
4734 alu
.dst
.write
= i
== 0;
4736 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4741 alu
.op
= ALU_OP1_EXP_IEEE
;
4742 alu
.src
[0].sel
= ctx
->temp_reg
;
4743 alu
.src
[0].chan
= 0;
4745 alu
.dst
.sel
= ctx
->temp_reg
;
4749 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4755 /* result.y = tmp - floor(tmp); */
4756 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4759 alu
.op
= ALU_OP1_FRACT
;
4760 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4762 alu
.dst
.sel
= ctx
->temp_reg
;
4764 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4773 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4778 /* result.z = RoughApprox2ToX(tmp);*/
4779 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
4780 if (ctx
->bc
->chip_class
== CAYMAN
) {
4781 for (i
= 0; i
< 3; i
++) {
4782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4783 alu
.op
= ALU_OP1_EXP_IEEE
;
4784 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4786 alu
.dst
.sel
= ctx
->temp_reg
;
4793 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4798 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4799 alu
.op
= ALU_OP1_EXP_IEEE
;
4800 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4802 alu
.dst
.sel
= ctx
->temp_reg
;
4808 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4814 /* result.w = 1.0;*/
4815 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
4816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4818 alu
.op
= ALU_OP1_MOV
;
4819 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4820 alu
.src
[0].chan
= 0;
4822 alu
.dst
.sel
= ctx
->temp_reg
;
4826 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4830 return tgsi_helper_copy(ctx
, inst
);
4833 static int tgsi_log(struct r600_shader_ctx
*ctx
)
4835 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4836 struct r600_bytecode_alu alu
;
4840 /* result.x = floor(log2(|src|)); */
4841 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4842 if (ctx
->bc
->chip_class
== CAYMAN
) {
4843 for (i
= 0; i
< 3; i
++) {
4844 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4846 alu
.op
= ALU_OP1_LOG_IEEE
;
4847 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4848 r600_bytecode_src_set_abs(&alu
.src
[0]);
4850 alu
.dst
.sel
= ctx
->temp_reg
;
4856 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4864 alu
.op
= ALU_OP1_LOG_IEEE
;
4865 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4866 r600_bytecode_src_set_abs(&alu
.src
[0]);
4868 alu
.dst
.sel
= ctx
->temp_reg
;
4872 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4877 alu
.op
= ALU_OP1_FLOOR
;
4878 alu
.src
[0].sel
= ctx
->temp_reg
;
4879 alu
.src
[0].chan
= 0;
4881 alu
.dst
.sel
= ctx
->temp_reg
;
4886 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4891 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
4892 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4894 if (ctx
->bc
->chip_class
== CAYMAN
) {
4895 for (i
= 0; i
< 3; i
++) {
4896 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4898 alu
.op
= ALU_OP1_LOG_IEEE
;
4899 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4900 r600_bytecode_src_set_abs(&alu
.src
[0]);
4902 alu
.dst
.sel
= ctx
->temp_reg
;
4909 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4914 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4916 alu
.op
= ALU_OP1_LOG_IEEE
;
4917 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4918 r600_bytecode_src_set_abs(&alu
.src
[0]);
4920 alu
.dst
.sel
= ctx
->temp_reg
;
4925 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4930 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4932 alu
.op
= ALU_OP1_FLOOR
;
4933 alu
.src
[0].sel
= ctx
->temp_reg
;
4934 alu
.src
[0].chan
= 1;
4936 alu
.dst
.sel
= ctx
->temp_reg
;
4941 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4945 if (ctx
->bc
->chip_class
== CAYMAN
) {
4946 for (i
= 0; i
< 3; i
++) {
4947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4948 alu
.op
= ALU_OP1_EXP_IEEE
;
4949 alu
.src
[0].sel
= ctx
->temp_reg
;
4950 alu
.src
[0].chan
= 1;
4952 alu
.dst
.sel
= ctx
->temp_reg
;
4959 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4964 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4965 alu
.op
= ALU_OP1_EXP_IEEE
;
4966 alu
.src
[0].sel
= ctx
->temp_reg
;
4967 alu
.src
[0].chan
= 1;
4969 alu
.dst
.sel
= ctx
->temp_reg
;
4974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4979 if (ctx
->bc
->chip_class
== CAYMAN
) {
4980 for (i
= 0; i
< 3; i
++) {
4981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4982 alu
.op
= ALU_OP1_RECIP_IEEE
;
4983 alu
.src
[0].sel
= ctx
->temp_reg
;
4984 alu
.src
[0].chan
= 1;
4986 alu
.dst
.sel
= ctx
->temp_reg
;
4993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4999 alu
.op
= ALU_OP1_RECIP_IEEE
;
5000 alu
.src
[0].sel
= ctx
->temp_reg
;
5001 alu
.src
[0].chan
= 1;
5003 alu
.dst
.sel
= ctx
->temp_reg
;
5008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5015 alu
.op
= ALU_OP2_MUL
;
5017 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5018 r600_bytecode_src_set_abs(&alu
.src
[0]);
5020 alu
.src
[1].sel
= ctx
->temp_reg
;
5021 alu
.src
[1].chan
= 1;
5023 alu
.dst
.sel
= ctx
->temp_reg
;
5028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5033 /* result.z = log2(|src|);*/
5034 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5035 if (ctx
->bc
->chip_class
== CAYMAN
) {
5036 for (i
= 0; i
< 3; i
++) {
5037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5039 alu
.op
= ALU_OP1_LOG_IEEE
;
5040 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5041 r600_bytecode_src_set_abs(&alu
.src
[0]);
5043 alu
.dst
.sel
= ctx
->temp_reg
;
5050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5057 alu
.op
= ALU_OP1_LOG_IEEE
;
5058 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5059 r600_bytecode_src_set_abs(&alu
.src
[0]);
5061 alu
.dst
.sel
= ctx
->temp_reg
;
5066 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5072 /* result.w = 1.0; */
5073 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5074 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5076 alu
.op
= ALU_OP1_MOV
;
5077 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5078 alu
.src
[0].chan
= 0;
5080 alu
.dst
.sel
= ctx
->temp_reg
;
5085 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5090 return tgsi_helper_copy(ctx
, inst
);
5093 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5095 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5096 struct r600_bytecode_alu alu
;
5099 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5101 switch (inst
->Instruction
.Opcode
) {
5102 case TGSI_OPCODE_ARL
:
5103 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5105 case TGSI_OPCODE_ARR
:
5106 alu
.op
= ALU_OP1_FLT_TO_INT
;
5108 case TGSI_OPCODE_UARL
:
5109 alu
.op
= ALU_OP1_MOV
;
5116 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5118 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5120 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5124 ctx
->bc
->ar_loaded
= 0;
5127 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5129 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5130 struct r600_bytecode_alu alu
;
5133 switch (inst
->Instruction
.Opcode
) {
5134 case TGSI_OPCODE_ARL
:
5135 memset(&alu
, 0, sizeof(alu
));
5136 alu
.op
= ALU_OP1_FLOOR
;
5137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5138 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5142 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5145 memset(&alu
, 0, sizeof(alu
));
5146 alu
.op
= ALU_OP1_FLT_TO_INT
;
5147 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5148 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5152 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5155 case TGSI_OPCODE_ARR
:
5156 memset(&alu
, 0, sizeof(alu
));
5157 alu
.op
= ALU_OP1_FLT_TO_INT
;
5158 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5159 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5163 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5166 case TGSI_OPCODE_UARL
:
5167 memset(&alu
, 0, sizeof(alu
));
5168 alu
.op
= ALU_OP1_MOV
;
5169 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5170 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5174 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5182 ctx
->bc
->ar_loaded
= 0;
5186 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5188 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5189 struct r600_bytecode_alu alu
;
5192 for (i
= 0; i
< 4; i
++) {
5193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5195 alu
.op
= ALU_OP2_MUL
;
5196 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5198 if (i
== 0 || i
== 3) {
5199 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5201 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5204 if (i
== 0 || i
== 2) {
5205 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5207 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5211 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5218 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5220 struct r600_bytecode_alu alu
;
5223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5225 alu
.execute_mask
= 1;
5226 alu
.update_pred
= 1;
5228 alu
.dst
.sel
= ctx
->temp_reg
;
5232 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5233 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5234 alu
.src
[1].chan
= 0;
5238 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5244 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5246 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5250 if (ctx
->bc
->cf_last
) {
5251 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5253 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5258 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5259 ctx
->bc
->force_add_cf
= 1;
5260 } else if (alu_pop
== 2) {
5261 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5262 ctx
->bc
->force_add_cf
= 1;
5269 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5270 ctx
->bc
->cf_last
->pop_count
= pops
;
5271 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5277 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5280 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5281 unsigned elements
, entries
;
5283 unsigned entry_size
= stack
->entry_size
;
5285 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5286 elements
+= stack
->push
;
5288 switch (ctx
->bc
->chip_class
) {
5291 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5292 * the stack must be reserved to hold the current active/continue
5294 if (reason
== FC_PUSH_VPM
) {
5300 /* r9xx: any stack operation on empty stack consumes 2 additional
5305 /* FIXME: do the two elements added above cover the cases for the
5309 /* r8xx+: 2 extra elements are not always required, but one extra
5310 * element must be added for each of the following cases:
5311 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5313 * (Currently we don't use ALU_ELSE_AFTER.)
5314 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5315 * PUSH instruction executed.
5317 * NOTE: it seems we also need to reserve additional element in some
5318 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5319 * then STACK_SIZE should be 2 instead of 1 */
5320 if (reason
== FC_PUSH_VPM
) {
5330 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5331 * for all chips, so we use 4 in the final formula, not the real entry_size
5335 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5337 if (entries
> stack
->max_entries
)
5338 stack
->max_entries
= entries
;
5341 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5345 --ctx
->bc
->stack
.push
;
5346 assert(ctx
->bc
->stack
.push
>= 0);
5349 --ctx
->bc
->stack
.push_wqm
;
5350 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5353 --ctx
->bc
->stack
.loop
;
5354 assert(ctx
->bc
->stack
.loop
>= 0);
5362 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5366 ++ctx
->bc
->stack
.push
;
5369 ++ctx
->bc
->stack
.push_wqm
;
5371 ++ctx
->bc
->stack
.loop
;
5377 callstack_update_max_depth(ctx
, reason
);
5380 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5382 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5384 sp
->mid
= realloc((void *)sp
->mid
,
5385 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5386 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5390 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5393 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5394 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5397 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5399 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5409 static int emit_return(struct r600_shader_ctx
*ctx
)
5411 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5415 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5418 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5419 ctx
->bc
->cf_last
->pop_count
= pops
;
5420 /* XXX work out offset */
5424 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5429 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5434 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5437 emit_jump_to_offset(ctx
, 1, 4);
5438 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5439 pops(ctx
, ifidx
+ 1);
5443 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5447 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5448 ctx
->bc
->cf_last
->pop_count
= 1;
5450 fc_set_mid(ctx
, fc_sp
);
5456 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5458 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5460 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5461 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5462 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5463 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5464 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5465 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5466 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5467 alu_type
= CF_OP_ALU
;
5470 emit_logic_pred(ctx
, opcode
, alu_type
);
5472 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5474 fc_pushlevel(ctx
, FC_IF
);
5476 callstack_push(ctx
, FC_PUSH_VPM
);
5480 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5482 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5485 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5487 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5490 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5492 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5493 ctx
->bc
->cf_last
->pop_count
= 1;
5495 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5496 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5500 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5503 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5504 R600_ERR("if/endif unbalanced in shader\n");
5508 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5509 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5510 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5512 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5516 callstack_pop(ctx
, FC_PUSH_VPM
);
5520 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5522 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5523 * limited to 4096 iterations, like the other LOOP_* instructions. */
5524 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5526 fc_pushlevel(ctx
, FC_LOOP
);
5528 /* check stack depth */
5529 callstack_push(ctx
, FC_LOOP
);
5533 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5537 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5539 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5540 R600_ERR("loop/endloop in shader code are not paired.\n");
5544 /* fixup loop pointers - from r600isa
5545 LOOP END points to CF after LOOP START,
5546 LOOP START point to CF after LOOP END
5547 BRK/CONT point to LOOP END CF
5549 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5551 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5553 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5554 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5556 /* XXX add LOOPRET support */
5558 callstack_pop(ctx
, FC_LOOP
);
5562 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5566 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5568 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5573 R600_ERR("Break not inside loop/endloop pair\n");
5577 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5579 fc_set_mid(ctx
, fscp
);
5584 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5586 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5587 struct r600_bytecode_alu alu
;
5589 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5592 for (i
= 0; i
< lasti
+ 1; i
++) {
5593 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5596 if (ctx
->bc
->chip_class
== CAYMAN
) {
5597 for (j
= 0 ; j
< 4; j
++) {
5598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5600 alu
.op
= ALU_OP2_MULLO_UINT
;
5601 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5602 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5604 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5605 alu
.dst
.sel
= ctx
->temp_reg
;
5606 alu
.dst
.write
= (j
== i
);
5609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5617 alu
.dst
.sel
= ctx
->temp_reg
;
5620 alu
.op
= ALU_OP2_MULLO_UINT
;
5621 for (j
= 0; j
< 2; j
++) {
5622 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5626 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5633 for (i
= 0; i
< lasti
+ 1; i
++) {
5634 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5637 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5638 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5640 alu
.op
= ALU_OP2_ADD_INT
;
5642 alu
.src
[0].sel
= ctx
->temp_reg
;
5643 alu
.src
[0].chan
= i
;
5645 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5649 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5656 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5657 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5658 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5659 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5662 * For state trackers other than OpenGL, we'll want to use
5663 * _RECIP_IEEE instead.
5665 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5667 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5668 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5669 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5670 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5671 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5672 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5673 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5674 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5675 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5676 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5677 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5678 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5679 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5680 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5681 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5682 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5684 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5685 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5687 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5688 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5689 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5690 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5691 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5692 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5693 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5694 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5695 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5696 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5698 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5699 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5700 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5701 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5702 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5703 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5704 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5705 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5706 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5707 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5708 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5709 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5710 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5711 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5712 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5713 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5714 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5715 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5716 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5717 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5718 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5719 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5720 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5721 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5722 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5723 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5724 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5725 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5726 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5727 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5728 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5729 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5730 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5731 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5732 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5733 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5734 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5735 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5736 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5737 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5738 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5739 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5740 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5741 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5742 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5743 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5744 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5746 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5747 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5748 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5749 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5750 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5751 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5752 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5753 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5754 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
5756 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5757 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5758 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5759 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5760 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5761 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5762 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5763 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5764 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5765 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5766 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5767 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5768 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5769 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5770 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5771 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5773 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5774 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5775 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5776 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5778 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5779 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5780 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5781 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5782 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5783 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5785 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5786 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5787 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5788 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5790 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5791 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
5792 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5793 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5794 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5795 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5796 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5797 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
5798 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5799 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
5800 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5801 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5802 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5803 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5804 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5805 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5806 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5807 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5808 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5809 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5810 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
5811 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5812 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
5813 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5814 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5815 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5816 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5817 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5818 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5819 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5820 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5821 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5822 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5823 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5824 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5825 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5826 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5827 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5828 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5829 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
5830 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5831 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5832 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5833 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5834 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5835 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5836 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5837 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5838 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5839 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5840 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5841 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5842 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5843 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5844 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5845 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5846 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5847 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5848 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5849 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5850 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5851 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5852 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5855 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
5856 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5857 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5858 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5859 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
5860 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
5861 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5862 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5863 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5864 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5865 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5866 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5867 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5868 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5869 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5870 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5871 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5872 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5873 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5874 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5875 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5877 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5878 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5880 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5881 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5882 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5883 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5884 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5885 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5886 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5887 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5888 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5889 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5891 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5892 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5893 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5894 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5895 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5896 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5897 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5898 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5899 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5900 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5901 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5902 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5903 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5904 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5905 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5906 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5907 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5908 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5909 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5910 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5911 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5912 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5913 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5914 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5915 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5916 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5917 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5918 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5919 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5920 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5921 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5922 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5923 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5924 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5925 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5926 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5927 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5928 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5929 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5930 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5931 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5932 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5933 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5934 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5935 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5936 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5937 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5939 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5940 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5941 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5942 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5943 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5944 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5945 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5946 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5947 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
5949 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5950 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5951 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5952 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5953 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5954 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5955 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5956 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5957 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5958 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5959 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5960 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5961 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5962 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5963 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5964 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5966 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5967 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5968 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5969 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5971 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5972 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5973 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5974 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5975 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5978 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5979 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5980 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5981 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5983 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5984 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
5985 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5986 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5987 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5988 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5989 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5990 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
5991 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5992 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
5993 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5994 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5995 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5996 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5997 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5998 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5999 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6000 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6001 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6002 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6003 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6004 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6005 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6006 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6007 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6008 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6009 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6010 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6011 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6012 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6013 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6014 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6015 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6016 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6017 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6018 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6019 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6020 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6021 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6022 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6023 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6024 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6025 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6026 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6027 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6028 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6029 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6030 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6031 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6032 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6033 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6034 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6035 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6036 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6037 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6038 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6039 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6040 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6041 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6042 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6043 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6044 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6045 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6048 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6049 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6050 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6051 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6052 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6053 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6054 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6055 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6056 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6057 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6058 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6059 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6060 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6061 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6062 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6063 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6064 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6065 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6066 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6067 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6068 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6070 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6071 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6073 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6074 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6075 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6076 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6078 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6079 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6080 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6081 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6082 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6084 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6085 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6086 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6087 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6088 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6089 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6090 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6091 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6092 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6093 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6094 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6095 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6096 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6097 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6098 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6099 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6100 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6101 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6102 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6103 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6105 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6106 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6107 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6108 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6109 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6110 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6111 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6112 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6114 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6115 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6116 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6117 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6118 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6119 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6120 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6121 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6122 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6123 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6124 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6125 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6126 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6127 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6128 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6129 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6130 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6132 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6133 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6134 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6135 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6136 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6137 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6138 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6139 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6140 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6142 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6143 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6144 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6145 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6146 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6147 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6148 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6149 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6150 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6151 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6152 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6153 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6154 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6155 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6156 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6157 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6159 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6160 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6161 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6162 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6164 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6165 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6166 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6167 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6168 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6172 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6173 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6174 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6176 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6177 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6178 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6179 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6180 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6181 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6182 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6183 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6184 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6185 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6186 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6187 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6188 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6189 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6190 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6191 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6192 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6193 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6194 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6195 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6196 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6197 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6198 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6199 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6200 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6201 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6202 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6203 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6204 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6205 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6206 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6207 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6208 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6209 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6210 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6211 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6212 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6213 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6214 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6215 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6216 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6217 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6218 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6219 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6220 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6221 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6222 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6223 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6224 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6225 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6226 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6227 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6228 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6229 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6230 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6231 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6232 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6233 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6234 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6235 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6236 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6237 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6238 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},