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
->msaa_texture_support
);
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 ctx
->shader
->ninput
+= count
;
575 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
576 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
577 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
578 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
579 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
580 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
581 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
582 switch (ctx
->shader
->input
[i
].name
) {
583 case TGSI_SEMANTIC_FACE
:
584 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
586 case TGSI_SEMANTIC_COLOR
:
589 case TGSI_SEMANTIC_POSITION
:
590 ctx
->fragcoord_input
= i
;
593 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
594 if ((r
= evergreen_interp_input(ctx
, i
)))
598 for (j
= 1; j
< count
; ++j
) {
599 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
600 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
603 case TGSI_FILE_OUTPUT
:
604 i
= ctx
->shader
->noutput
++;
605 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
606 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
607 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
608 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
609 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
610 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
611 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
612 switch (d
->Semantic
.Name
) {
613 case TGSI_SEMANTIC_CLIPDIST
:
614 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
616 case TGSI_SEMANTIC_PSIZE
:
617 ctx
->shader
->vs_out_misc_write
= 1;
618 ctx
->shader
->vs_out_point_size
= 1;
620 case TGSI_SEMANTIC_CLIPVERTEX
:
621 ctx
->clip_vertex_write
= TRUE
;
625 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
626 switch (d
->Semantic
.Name
) {
627 case TGSI_SEMANTIC_COLOR
:
628 ctx
->shader
->nr_ps_max_color_exports
++;
633 case TGSI_FILE_TEMPORARY
:
634 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
635 if (d
->Array
.ArrayID
) {
636 r600_add_gpr_array(ctx
->shader
,
637 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
639 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
644 case TGSI_FILE_CONSTANT
:
645 case TGSI_FILE_SAMPLER
:
646 case TGSI_FILE_ADDRESS
:
649 case TGSI_FILE_SYSTEM_VALUE
:
650 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
651 if (!ctx
->native_integers
) {
652 struct r600_bytecode_alu alu
;
653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
655 alu
.op
= ALU_OP1_INT_TO_FLT
;
664 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
668 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
671 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
677 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
679 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
683 * for evergreen we need to scan the shader to find the number of GPRs we need to
684 * reserve for interpolation.
686 * we need to know if we are going to emit
687 * any centroid inputs
688 * if perspective and linear are required
690 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
695 ctx
->input_linear
= FALSE
;
696 ctx
->input_perspective
= FALSE
;
697 ctx
->input_centroid
= FALSE
;
698 ctx
->num_interp_gpr
= 1;
700 /* any centroid inputs */
701 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
702 /* skip position/face */
703 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
704 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
706 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
707 ctx
->input_linear
= TRUE
;
708 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
709 ctx
->input_perspective
= TRUE
;
710 if (ctx
->info
.input_centroid
[i
])
711 ctx
->input_centroid
= TRUE
;
715 /* ignoring sample for now */
716 if (ctx
->input_perspective
)
718 if (ctx
->input_linear
)
720 if (ctx
->input_centroid
)
723 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
725 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
726 return ctx
->num_interp_gpr
;
729 static void tgsi_src(struct r600_shader_ctx
*ctx
,
730 const struct tgsi_full_src_register
*tgsi_src
,
731 struct r600_shader_src
*r600_src
)
733 memset(r600_src
, 0, sizeof(*r600_src
));
734 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
735 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
736 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
737 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
738 r600_src
->neg
= tgsi_src
->Register
.Negate
;
739 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
741 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
743 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
744 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
745 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
747 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
748 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
749 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
752 index
= tgsi_src
->Register
.Index
;
753 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
754 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
755 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
756 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
757 r600_src
->swizzle
[0] = 3;
758 r600_src
->swizzle
[1] = 3;
759 r600_src
->swizzle
[2] = 3;
760 r600_src
->swizzle
[3] = 3;
762 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
763 r600_src
->swizzle
[0] = 0;
764 r600_src
->swizzle
[1] = 0;
765 r600_src
->swizzle
[2] = 0;
766 r600_src
->swizzle
[3] = 0;
770 if (tgsi_src
->Register
.Indirect
)
771 r600_src
->rel
= V_SQ_REL_RELATIVE
;
772 r600_src
->sel
= tgsi_src
->Register
.Index
;
773 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
775 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
776 if (tgsi_src
->Register
.Dimension
) {
777 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
782 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
784 struct r600_bytecode_vtx vtx
;
789 struct r600_bytecode_alu alu
;
791 memset(&alu
, 0, sizeof(alu
));
793 alu
.op
= ALU_OP2_ADD_INT
;
794 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
796 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
797 alu
.src
[1].value
= offset
;
799 alu
.dst
.sel
= dst_reg
;
803 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
808 ar_reg
= ctx
->bc
->ar_reg
;
811 memset(&vtx
, 0, sizeof(vtx
));
812 vtx
.buffer_id
= cb_idx
;
813 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
814 vtx
.src_gpr
= ar_reg
;
815 vtx
.mega_fetch_count
= 16;
816 vtx
.dst_gpr
= dst_reg
;
817 vtx
.dst_sel_x
= 0; /* SEL_X */
818 vtx
.dst_sel_y
= 1; /* SEL_Y */
819 vtx
.dst_sel_z
= 2; /* SEL_Z */
820 vtx
.dst_sel_w
= 3; /* SEL_W */
821 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
822 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
823 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
824 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
825 vtx
.endian
= r600_endian_swap(32);
827 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
833 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
835 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
836 struct r600_bytecode_alu alu
;
837 int i
, j
, k
, nconst
, r
;
839 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
840 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
843 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
845 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
846 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
850 if (ctx
->src
[i
].rel
) {
851 int treg
= r600_get_temp(ctx
);
852 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
855 ctx
->src
[i
].kc_bank
= 0;
856 ctx
->src
[i
].sel
= treg
;
860 int treg
= r600_get_temp(ctx
);
861 for (k
= 0; k
< 4; k
++) {
862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
863 alu
.op
= ALU_OP1_MOV
;
864 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
866 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
872 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
876 ctx
->src
[i
].sel
= treg
;
884 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
885 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
887 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
888 struct r600_bytecode_alu alu
;
889 int i
, j
, k
, nliteral
, r
;
891 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
892 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
896 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
897 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
898 int treg
= r600_get_temp(ctx
);
899 for (k
= 0; k
< 4; k
++) {
900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
901 alu
.op
= ALU_OP1_MOV
;
902 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
904 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
910 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
914 ctx
->src
[i
].sel
= treg
;
921 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
923 int i
, r
, count
= ctx
->shader
->ninput
;
925 for (i
= 0; i
< count
; i
++) {
926 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
927 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
936 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
937 struct r600_pipe_shader
*pipeshader
,
938 struct r600_shader_key key
)
940 struct r600_shader
*shader
= &pipeshader
->shader
;
941 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
942 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
943 struct tgsi_full_immediate
*immediate
;
944 struct tgsi_full_property
*property
;
945 struct r600_shader_ctx ctx
;
946 struct r600_bytecode_output output
[32];
947 unsigned output_done
, noutput
;
950 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
951 /* Declarations used by llvm code */
952 bool use_llvm
= false;
956 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
958 ctx
.bc
= &shader
->bc
;
960 ctx
.native_integers
= true;
962 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
963 rscreen
->msaa_texture_support
);
965 tgsi_scan_shader(tokens
, &ctx
.info
);
966 shader
->indirect_files
= ctx
.info
.indirect_files
;
967 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
968 tgsi_parse_init(&ctx
.parse
, tokens
);
969 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
970 shader
->processor_type
= ctx
.type
;
971 ctx
.bc
->type
= shader
->processor_type
;
974 ctx
.fragcoord_input
= -1;
976 ctx
.clip_vertex_write
= 0;
978 shader
->nr_ps_color_exports
= 0;
979 shader
->nr_ps_max_color_exports
= 0;
981 shader
->two_side
= key
.color_two_side
;
983 /* register allocations */
984 /* Values [0,127] correspond to GPR[0..127].
985 * Values [128,159] correspond to constant buffer bank 0
986 * Values [160,191] correspond to constant buffer bank 1
987 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
988 * Values [256,287] correspond to constant buffer bank 2 (EG)
989 * Values [288,319] correspond to constant buffer bank 3 (EG)
990 * Other special values are shown in the list below.
991 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
992 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
993 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
994 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
995 * 248 SQ_ALU_SRC_0: special constant 0.0.
996 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
997 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
998 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
999 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1000 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1001 * 254 SQ_ALU_SRC_PV: previous vector result.
1002 * 255 SQ_ALU_SRC_PS: previous scalar result.
1004 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1005 ctx
.file_offset
[i
] = 0;
1008 #ifdef R600_USE_LLVM
1009 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1010 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1011 "indirect adressing. Falling back to TGSI "
1016 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1017 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1019 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1022 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1023 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1025 ctx
.use_llvm
= use_llvm
;
1028 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1029 ctx
.file_offset
[TGSI_FILE_INPUT
];
1031 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1032 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1033 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1035 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1036 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1038 /* Outside the GPR range. This will be translated to one of the
1039 * kcache banks later. */
1040 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1042 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1043 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1044 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1045 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1047 if (indirect_gprs
) {
1048 shader
->max_arrays
= 0;
1049 shader
->num_arrays
= 0;
1051 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1052 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1053 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1054 ctx
.file_offset
[TGSI_FILE_INPUT
],
1057 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1058 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1059 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1060 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1066 ctx
.literals
= NULL
;
1067 shader
->fs_write_all
= FALSE
;
1068 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1069 tgsi_parse_token(&ctx
.parse
);
1070 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1071 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1072 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1073 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1074 if(ctx
.literals
== NULL
) {
1078 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1079 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1080 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1081 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1084 case TGSI_TOKEN_TYPE_DECLARATION
:
1085 r
= tgsi_declaration(&ctx
);
1089 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1091 case TGSI_TOKEN_TYPE_PROPERTY
:
1092 property
= &ctx
.parse
.FullToken
.FullProperty
;
1093 switch (property
->Property
.PropertyName
) {
1094 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1095 if (property
->u
[0].Data
== 1)
1096 shader
->fs_write_all
= TRUE
;
1098 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1099 /* we don't need this one */
1104 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1110 /* Process two side if needed */
1111 if (shader
->two_side
&& ctx
.colors_used
) {
1112 int i
, count
= ctx
.shader
->ninput
;
1113 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1115 /* additional inputs will be allocated right after the existing inputs,
1116 * we won't need them after the color selection, so we don't need to
1117 * reserve these gprs for the rest of the shader code and to adjust
1118 * output offsets etc. */
1119 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1120 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1122 if (ctx
.face_gpr
== -1) {
1123 i
= ctx
.shader
->ninput
++;
1124 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1125 ctx
.shader
->input
[i
].spi_sid
= 0;
1126 ctx
.shader
->input
[i
].gpr
= gpr
++;
1127 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1130 for (i
= 0; i
< count
; i
++) {
1131 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1132 int ni
= ctx
.shader
->ninput
++;
1133 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1134 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1135 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1136 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1137 // TGSI to LLVM needs to know the lds position of inputs.
1138 // Non LLVM path computes it later (in process_twoside_color)
1139 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1140 ctx
.shader
->input
[i
].back_color_input
= ni
;
1141 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1142 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1149 /* LLVM backend setup */
1150 #ifdef R600_USE_LLVM
1152 struct radeon_llvm_context radeon_llvm_ctx
;
1154 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1155 boolean use_kill
= false;
1157 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1158 radeon_llvm_ctx
.type
= ctx
.type
;
1159 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1160 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1161 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1162 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1163 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1164 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1165 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1166 radeon_llvm_ctx
.stream_outputs
= &so
;
1167 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1168 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1169 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1171 if (r600_llvm_compile(mod
, rscreen
->family
, ctx
.bc
, &use_kill
, dump
)) {
1172 radeon_llvm_dispose(&radeon_llvm_ctx
);
1174 fprintf(stderr
, "R600 LLVM backend failed to compile "
1175 "shader. Falling back to TGSI\n");
1177 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1178 ctx
.file_offset
[TGSI_FILE_INPUT
];
1181 ctx
.shader
->uses_kill
= use_kill
;
1182 radeon_llvm_dispose(&radeon_llvm_ctx
);
1185 /* End of LLVM backend setup */
1187 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1188 shader
->nr_ps_max_color_exports
= 8;
1191 if (ctx
.fragcoord_input
>= 0) {
1192 if (ctx
.bc
->chip_class
== CAYMAN
) {
1193 for (j
= 0 ; j
< 4; j
++) {
1194 struct r600_bytecode_alu alu
;
1195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1196 alu
.op
= ALU_OP1_RECIP_IEEE
;
1197 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1198 alu
.src
[0].chan
= 3;
1200 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1202 alu
.dst
.write
= (j
== 3);
1204 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1208 struct r600_bytecode_alu alu
;
1209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1210 alu
.op
= ALU_OP1_RECIP_IEEE
;
1211 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1212 alu
.src
[0].chan
= 3;
1214 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1218 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1223 if (shader
->two_side
&& ctx
.colors_used
) {
1224 if ((r
= process_twoside_color_inputs(&ctx
)))
1228 tgsi_parse_init(&ctx
.parse
, tokens
);
1229 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1230 tgsi_parse_token(&ctx
.parse
);
1231 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1232 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1233 r
= tgsi_is_supported(&ctx
);
1236 ctx
.max_driver_temp_used
= 0;
1237 /* reserve first tmp for everyone */
1238 r600_get_temp(&ctx
);
1240 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1241 if ((r
= tgsi_split_constant(&ctx
)))
1243 if ((r
= tgsi_split_literal_constant(&ctx
)))
1245 if (ctx
.bc
->chip_class
== CAYMAN
)
1246 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1247 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1248 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1250 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1251 r
= ctx
.inst_info
->process(&ctx
);
1261 /* Reset the temporary register counter. */
1262 ctx
.max_driver_temp_used
= 0;
1264 noutput
= shader
->noutput
;
1266 if (ctx
.clip_vertex_write
) {
1267 unsigned clipdist_temp
[2];
1269 clipdist_temp
[0] = r600_get_temp(&ctx
);
1270 clipdist_temp
[1] = r600_get_temp(&ctx
);
1272 /* need to convert a clipvertex write into clipdistance writes and not export
1273 the clip vertex anymore */
1275 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1276 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1277 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1279 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1280 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1283 /* reset spi_sid for clipvertex output to avoid confusing spi */
1284 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1286 shader
->clip_dist_write
= 0xFF;
1288 for (i
= 0; i
< 8; i
++) {
1292 for (j
= 0; j
< 4; j
++) {
1293 struct r600_bytecode_alu alu
;
1294 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1295 alu
.op
= ALU_OP2_DOT4
;
1296 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1297 alu
.src
[0].chan
= j
;
1299 alu
.src
[1].sel
= 512 + i
;
1300 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1301 alu
.src
[1].chan
= j
;
1303 alu
.dst
.sel
= clipdist_temp
[oreg
];
1305 alu
.dst
.write
= (j
== ochan
);
1309 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1316 /* Add stream outputs. */
1317 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1318 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1320 /* Sanity checking. */
1321 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1322 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1326 for (i
= 0; i
< so
.num_outputs
; i
++) {
1327 if (so
.output
[i
].output_buffer
>= 4) {
1328 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1329 so
.output
[i
].output_buffer
);
1335 /* Initialize locations where the outputs are stored. */
1336 for (i
= 0; i
< so
.num_outputs
; i
++) {
1337 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1339 /* Lower outputs with dst_offset < start_component.
1341 * We can only output 4D vectors with a write mask, e.g. we can
1342 * only output the W component at offset 3, etc. If we want
1343 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1344 * to move it to X and output X. */
1345 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1346 unsigned tmp
= r600_get_temp(&ctx
);
1348 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1349 struct r600_bytecode_alu alu
;
1350 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1351 alu
.op
= ALU_OP1_MOV
;
1352 alu
.src
[0].sel
= so_gpr
[i
];
1353 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1358 if (j
== so
.output
[i
].num_components
- 1)
1360 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1364 so
.output
[i
].start_component
= 0;
1369 /* Write outputs to buffers. */
1370 for (i
= 0; i
< so
.num_outputs
; i
++) {
1371 struct r600_bytecode_output output
;
1373 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1374 output
.gpr
= so_gpr
[i
];
1375 output
.elem_size
= so
.output
[i
].num_components
;
1376 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1377 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1378 output
.burst_count
= 1;
1380 /* array_size is an upper limit for the burst_count
1381 * with MEM_STREAM instructions */
1382 output
.array_size
= 0xFFF;
1383 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1384 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1385 switch (so
.output
[i
].output_buffer
) {
1387 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1390 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1393 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1396 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1400 switch (so
.output
[i
].output_buffer
) {
1402 output
.op
= CF_OP_MEM_STREAM0
;
1405 output
.op
= CF_OP_MEM_STREAM1
;
1408 output
.op
= CF_OP_MEM_STREAM2
;
1411 output
.op
= CF_OP_MEM_STREAM3
;
1415 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1422 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1423 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1424 output
[j
].gpr
= shader
->output
[i
].gpr
;
1425 output
[j
].elem_size
= 3;
1426 output
[j
].swizzle_x
= 0;
1427 output
[j
].swizzle_y
= 1;
1428 output
[j
].swizzle_z
= 2;
1429 output
[j
].swizzle_w
= 3;
1430 output
[j
].burst_count
= 1;
1431 output
[j
].barrier
= 1;
1432 output
[j
].type
= -1;
1433 output
[j
].op
= CF_OP_EXPORT
;
1435 case TGSI_PROCESSOR_VERTEX
:
1436 switch (shader
->output
[i
].name
) {
1437 case TGSI_SEMANTIC_POSITION
:
1438 output
[j
].array_base
= next_pos_base
++;
1439 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1442 case TGSI_SEMANTIC_PSIZE
:
1443 output
[j
].array_base
= next_pos_base
++;
1444 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1446 case TGSI_SEMANTIC_CLIPVERTEX
:
1449 case TGSI_SEMANTIC_CLIPDIST
:
1450 output
[j
].array_base
= next_pos_base
++;
1451 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1452 /* spi_sid is 0 for clipdistance outputs that were generated
1453 * for clipvertex - we don't need to pass them to PS */
1454 if (shader
->output
[i
].spi_sid
) {
1456 /* duplicate it as PARAM to pass to the pixel shader */
1457 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1458 output
[j
].array_base
= next_param_base
++;
1459 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1462 case TGSI_SEMANTIC_FOG
:
1463 output
[j
].swizzle_y
= 4; /* 0 */
1464 output
[j
].swizzle_z
= 4; /* 0 */
1465 output
[j
].swizzle_w
= 5; /* 1 */
1469 case TGSI_PROCESSOR_FRAGMENT
:
1470 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1471 /* never export more colors than the number of CBs */
1472 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1477 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1478 output
[j
].array_base
= next_pixel_base
++;
1479 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1480 shader
->nr_ps_color_exports
++;
1481 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1482 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1484 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1485 output
[j
].gpr
= shader
->output
[i
].gpr
;
1486 output
[j
].elem_size
= 3;
1487 output
[j
].swizzle_x
= 0;
1488 output
[j
].swizzle_y
= 1;
1489 output
[j
].swizzle_z
= 2;
1490 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1491 output
[j
].burst_count
= 1;
1492 output
[j
].barrier
= 1;
1493 output
[j
].array_base
= next_pixel_base
++;
1494 output
[j
].op
= CF_OP_EXPORT
;
1495 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1496 shader
->nr_ps_color_exports
++;
1499 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1500 output
[j
].array_base
= 61;
1501 output
[j
].swizzle_x
= 2;
1502 output
[j
].swizzle_y
= 7;
1503 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1504 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1505 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1506 output
[j
].array_base
= 61;
1507 output
[j
].swizzle_x
= 7;
1508 output
[j
].swizzle_y
= 1;
1509 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1510 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1512 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1518 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1523 if (output
[j
].type
==-1) {
1524 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1525 output
[j
].array_base
= next_param_base
++;
1529 /* add fake position export */
1530 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1531 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1533 output
[j
].elem_size
= 3;
1534 output
[j
].swizzle_x
= 7;
1535 output
[j
].swizzle_y
= 7;
1536 output
[j
].swizzle_z
= 7;
1537 output
[j
].swizzle_w
= 7;
1538 output
[j
].burst_count
= 1;
1539 output
[j
].barrier
= 1;
1540 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1541 output
[j
].array_base
= next_pos_base
;
1542 output
[j
].op
= CF_OP_EXPORT
;
1546 /* add fake param output for vertex shader if no param is exported */
1547 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1548 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1550 output
[j
].elem_size
= 3;
1551 output
[j
].swizzle_x
= 7;
1552 output
[j
].swizzle_y
= 7;
1553 output
[j
].swizzle_z
= 7;
1554 output
[j
].swizzle_w
= 7;
1555 output
[j
].burst_count
= 1;
1556 output
[j
].barrier
= 1;
1557 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1558 output
[j
].array_base
= 0;
1559 output
[j
].op
= CF_OP_EXPORT
;
1563 /* add fake pixel export */
1564 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1565 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1567 output
[j
].elem_size
= 3;
1568 output
[j
].swizzle_x
= 7;
1569 output
[j
].swizzle_y
= 7;
1570 output
[j
].swizzle_z
= 7;
1571 output
[j
].swizzle_w
= 7;
1572 output
[j
].burst_count
= 1;
1573 output
[j
].barrier
= 1;
1574 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1575 output
[j
].array_base
= 0;
1576 output
[j
].op
= CF_OP_EXPORT
;
1582 /* set export done on last export of each type */
1583 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1584 if (ctx
.bc
->chip_class
< CAYMAN
) {
1585 if (i
== (noutput
- 1)) {
1586 output
[i
].end_of_program
= 1;
1589 if (!(output_done
& (1 << output
[i
].type
))) {
1590 output_done
|= (1 << output
[i
].type
);
1591 output
[i
].op
= CF_OP_EXPORT_DONE
;
1594 /* add output to bytecode */
1596 for (i
= 0; i
< noutput
; i
++) {
1597 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1602 /* add program end */
1603 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1604 cm_bytecode_add_cf_end(ctx
.bc
);
1606 /* check GPR limit - we have 124 = 128 - 4
1607 * (4 are reserved as alu clause temporary registers) */
1608 if (ctx
.bc
->ngpr
> 124) {
1609 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1615 tgsi_parse_free(&ctx
.parse
);
1619 tgsi_parse_free(&ctx
.parse
);
1623 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1625 R600_ERR("%s tgsi opcode unsupported\n",
1626 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1630 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1635 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1636 const struct r600_shader_src
*shader_src
,
1639 bc_src
->sel
= shader_src
->sel
;
1640 bc_src
->chan
= shader_src
->swizzle
[chan
];
1641 bc_src
->neg
= shader_src
->neg
;
1642 bc_src
->abs
= shader_src
->abs
;
1643 bc_src
->rel
= shader_src
->rel
;
1644 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1645 bc_src
->kc_bank
= shader_src
->kc_bank
;
1648 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1654 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1656 bc_src
->neg
= !bc_src
->neg
;
1659 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1660 const struct tgsi_full_dst_register
*tgsi_dst
,
1662 struct r600_bytecode_alu_dst
*r600_dst
)
1664 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1666 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1667 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1668 r600_dst
->chan
= swizzle
;
1669 r600_dst
->write
= 1;
1670 if (tgsi_dst
->Register
.Indirect
)
1671 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1672 if (inst
->Instruction
.Saturate
) {
1673 r600_dst
->clamp
= 1;
1677 static int tgsi_last_instruction(unsigned writemask
)
1681 for (i
= 0; i
< 4; i
++) {
1682 if (writemask
& (1 << i
)) {
1689 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1691 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1692 struct r600_bytecode_alu alu
;
1694 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1696 for (i
= 0; i
< lasti
+ 1; i
++) {
1697 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1701 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1703 alu
.op
= ctx
->inst_info
->op
;
1705 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1706 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
1709 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
1710 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1712 /* handle some special cases */
1713 switch (ctx
->inst_info
->tgsi_opcode
) {
1714 case TGSI_OPCODE_SUB
:
1715 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
1717 case TGSI_OPCODE_ABS
:
1718 r600_bytecode_src_set_abs(&alu
.src
[0]);
1723 if (i
== lasti
|| trans_only
) {
1726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1733 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
1735 return tgsi_op2_s(ctx
, 0, 0);
1738 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
1740 return tgsi_op2_s(ctx
, 1, 0);
1743 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
1745 return tgsi_op2_s(ctx
, 0, 1);
1748 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
1750 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1751 struct r600_bytecode_alu alu
;
1753 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1755 for (i
= 0; i
< lasti
+ 1; i
++) {
1757 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1760 alu
.op
= ctx
->inst_info
->op
;
1762 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1764 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1766 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1771 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1779 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
1781 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1783 struct r600_bytecode_alu alu
;
1784 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1786 for (i
= 0 ; i
< last_slot
; i
++) {
1787 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1788 alu
.op
= ctx
->inst_info
->op
;
1789 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1790 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
1792 /* RSQ should take the absolute value of src */
1793 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
1794 r600_bytecode_src_set_abs(&alu
.src
[j
]);
1797 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1798 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1800 if (i
== last_slot
- 1)
1802 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1809 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
1811 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1813 struct r600_bytecode_alu alu
;
1814 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1815 for (k
= 0; k
< last_slot
; k
++) {
1816 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
1819 for (i
= 0 ; i
< 4; i
++) {
1820 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1821 alu
.op
= ctx
->inst_info
->op
;
1822 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1823 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
1825 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1826 alu
.dst
.write
= (i
== k
);
1829 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1838 * r600 - trunc to -PI..PI range
1839 * r700 - normalize by dividing by 2PI
1842 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
1844 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
1845 static float double_pi
= 3.1415926535 * 2;
1846 static float neg_pi
= -3.1415926535;
1849 struct r600_bytecode_alu alu
;
1851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1852 alu
.op
= ALU_OP3_MULADD
;
1856 alu
.dst
.sel
= ctx
->temp_reg
;
1859 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
1861 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1862 alu
.src
[1].chan
= 0;
1863 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
1864 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1865 alu
.src
[2].chan
= 0;
1867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1872 alu
.op
= ALU_OP1_FRACT
;
1875 alu
.dst
.sel
= ctx
->temp_reg
;
1878 alu
.src
[0].sel
= ctx
->temp_reg
;
1879 alu
.src
[0].chan
= 0;
1881 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1885 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1886 alu
.op
= ALU_OP3_MULADD
;
1890 alu
.dst
.sel
= ctx
->temp_reg
;
1893 alu
.src
[0].sel
= ctx
->temp_reg
;
1894 alu
.src
[0].chan
= 0;
1896 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1897 alu
.src
[1].chan
= 0;
1898 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
1899 alu
.src
[2].chan
= 0;
1901 if (ctx
->bc
->chip_class
== R600
) {
1902 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
1903 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
1905 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
1906 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1911 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1917 static int cayman_trig(struct r600_shader_ctx
*ctx
)
1919 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1920 struct r600_bytecode_alu alu
;
1921 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1924 r
= tgsi_setup_trig(ctx
);
1929 for (i
= 0; i
< last_slot
; i
++) {
1930 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1931 alu
.op
= ctx
->inst_info
->op
;
1934 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1935 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1937 alu
.src
[0].sel
= ctx
->temp_reg
;
1938 alu
.src
[0].chan
= 0;
1939 if (i
== last_slot
- 1)
1941 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1948 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
1950 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1951 struct r600_bytecode_alu alu
;
1953 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1955 r
= tgsi_setup_trig(ctx
);
1959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1960 alu
.op
= ctx
->inst_info
->op
;
1962 alu
.dst
.sel
= ctx
->temp_reg
;
1965 alu
.src
[0].sel
= ctx
->temp_reg
;
1966 alu
.src
[0].chan
= 0;
1968 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1972 /* replicate result */
1973 for (i
= 0; i
< lasti
+ 1; i
++) {
1974 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1978 alu
.op
= ALU_OP1_MOV
;
1980 alu
.src
[0].sel
= ctx
->temp_reg
;
1981 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1984 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1991 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
1993 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1994 struct r600_bytecode_alu alu
;
1997 /* We'll only need the trig stuff if we are going to write to the
1998 * X or Y components of the destination vector.
2000 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2001 r
= tgsi_setup_trig(ctx
);
2007 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2008 if (ctx
->bc
->chip_class
== CAYMAN
) {
2009 for (i
= 0 ; i
< 3; i
++) {
2010 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2011 alu
.op
= ALU_OP1_COS
;
2012 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2018 alu
.src
[0].sel
= ctx
->temp_reg
;
2019 alu
.src
[0].chan
= 0;
2022 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2027 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2028 alu
.op
= ALU_OP1_COS
;
2029 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2031 alu
.src
[0].sel
= ctx
->temp_reg
;
2032 alu
.src
[0].chan
= 0;
2034 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2041 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2042 if (ctx
->bc
->chip_class
== CAYMAN
) {
2043 for (i
= 0 ; i
< 3; i
++) {
2044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2045 alu
.op
= ALU_OP1_SIN
;
2046 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2051 alu
.src
[0].sel
= ctx
->temp_reg
;
2052 alu
.src
[0].chan
= 0;
2055 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2060 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2061 alu
.op
= ALU_OP1_SIN
;
2062 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2064 alu
.src
[0].sel
= ctx
->temp_reg
;
2065 alu
.src
[0].chan
= 0;
2067 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2074 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2075 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2077 alu
.op
= ALU_OP1_MOV
;
2079 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2081 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2082 alu
.src
[0].chan
= 0;
2086 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2092 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2095 alu
.op
= ALU_OP1_MOV
;
2097 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2099 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2100 alu
.src
[0].chan
= 0;
2104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2112 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2114 struct r600_bytecode_alu alu
;
2117 for (i
= 0; i
< 4; i
++) {
2118 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2119 alu
.op
= ctx
->inst_info
->op
;
2123 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2125 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2126 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2129 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2134 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2139 /* kill must be last in ALU */
2140 ctx
->bc
->force_add_cf
= 1;
2141 ctx
->shader
->uses_kill
= TRUE
;
2145 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2147 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2148 struct r600_bytecode_alu alu
;
2151 /* tmp.x = max(src.y, 0.0) */
2152 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2153 alu
.op
= ALU_OP2_MAX
;
2154 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2155 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2156 alu
.src
[1].chan
= 1;
2158 alu
.dst
.sel
= ctx
->temp_reg
;
2163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2167 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2173 if (ctx
->bc
->chip_class
== CAYMAN
) {
2174 for (i
= 0; i
< 3; i
++) {
2175 /* tmp.z = log(tmp.x) */
2176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2177 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2178 alu
.src
[0].sel
= ctx
->temp_reg
;
2179 alu
.src
[0].chan
= 0;
2180 alu
.dst
.sel
= ctx
->temp_reg
;
2188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2193 /* tmp.z = log(tmp.x) */
2194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2195 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2196 alu
.src
[0].sel
= ctx
->temp_reg
;
2197 alu
.src
[0].chan
= 0;
2198 alu
.dst
.sel
= ctx
->temp_reg
;
2202 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2207 chan
= alu
.dst
.chan
;
2210 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2211 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2212 alu
.op
= ALU_OP3_MUL_LIT
;
2213 alu
.src
[0].sel
= sel
;
2214 alu
.src
[0].chan
= chan
;
2215 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2216 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2217 alu
.dst
.sel
= ctx
->temp_reg
;
2222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2226 if (ctx
->bc
->chip_class
== CAYMAN
) {
2227 for (i
= 0; i
< 3; i
++) {
2228 /* dst.z = exp(tmp.x) */
2229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2230 alu
.op
= ALU_OP1_EXP_IEEE
;
2231 alu
.src
[0].sel
= ctx
->temp_reg
;
2232 alu
.src
[0].chan
= 0;
2233 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2239 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2244 /* dst.z = exp(tmp.x) */
2245 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2246 alu
.op
= ALU_OP1_EXP_IEEE
;
2247 alu
.src
[0].sel
= ctx
->temp_reg
;
2248 alu
.src
[0].chan
= 0;
2249 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2251 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2258 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2259 alu
.op
= ALU_OP1_MOV
;
2260 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2261 alu
.src
[0].chan
= 0;
2262 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2263 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2268 /* dst.y = max(src.x, 0.0) */
2269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2270 alu
.op
= ALU_OP2_MAX
;
2271 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2272 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2273 alu
.src
[1].chan
= 0;
2274 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2275 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2276 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2281 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2282 alu
.op
= ALU_OP1_MOV
;
2283 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2284 alu
.src
[0].chan
= 0;
2285 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2286 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2295 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2297 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2298 struct r600_bytecode_alu alu
;
2301 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2304 * For state trackers other than OpenGL, we'll want to use
2305 * _RECIPSQRT_IEEE instead.
2307 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2309 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2310 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2311 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2313 alu
.dst
.sel
= ctx
->temp_reg
;
2316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2319 /* replicate result */
2320 return tgsi_helper_tempx_replicate(ctx
);
2323 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2325 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2326 struct r600_bytecode_alu alu
;
2329 for (i
= 0; i
< 4; i
++) {
2330 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2331 alu
.src
[0].sel
= ctx
->temp_reg
;
2332 alu
.op
= ALU_OP1_MOV
;
2334 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2335 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2338 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2345 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2347 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2348 struct r600_bytecode_alu alu
;
2351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2352 alu
.op
= ctx
->inst_info
->op
;
2353 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2354 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2356 alu
.dst
.sel
= ctx
->temp_reg
;
2359 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2362 /* replicate result */
2363 return tgsi_helper_tempx_replicate(ctx
);
2366 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2368 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2370 struct r600_bytecode_alu alu
;
2371 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2373 for (i
= 0; i
< 3; i
++) {
2374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2375 alu
.op
= ALU_OP1_LOG_IEEE
;
2376 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2377 alu
.dst
.sel
= ctx
->temp_reg
;
2382 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2388 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2389 alu
.op
= ALU_OP2_MUL
;
2390 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2391 alu
.src
[1].sel
= ctx
->temp_reg
;
2392 alu
.dst
.sel
= ctx
->temp_reg
;
2395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2399 for (i
= 0; i
< last_slot
; i
++) {
2400 /* POW(a,b) = EXP2(b * LOG2(a))*/
2401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2402 alu
.op
= ALU_OP1_EXP_IEEE
;
2403 alu
.src
[0].sel
= ctx
->temp_reg
;
2405 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2406 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2407 if (i
== last_slot
- 1)
2409 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2416 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2418 struct r600_bytecode_alu alu
;
2422 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2423 alu
.op
= ALU_OP1_LOG_IEEE
;
2424 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2425 alu
.dst
.sel
= ctx
->temp_reg
;
2428 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2432 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2433 alu
.op
= ALU_OP2_MUL
;
2434 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2435 alu
.src
[1].sel
= ctx
->temp_reg
;
2436 alu
.dst
.sel
= ctx
->temp_reg
;
2439 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2442 /* POW(a,b) = EXP2(b * LOG2(a))*/
2443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2444 alu
.op
= ALU_OP1_EXP_IEEE
;
2445 alu
.src
[0].sel
= ctx
->temp_reg
;
2446 alu
.dst
.sel
= ctx
->temp_reg
;
2449 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2452 return tgsi_helper_tempx_replicate(ctx
);
2455 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2457 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2458 struct r600_bytecode_alu alu
;
2460 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2461 int tmp0
= ctx
->temp_reg
;
2462 int tmp1
= r600_get_temp(ctx
);
2463 int tmp2
= r600_get_temp(ctx
);
2464 int tmp3
= r600_get_temp(ctx
);
2467 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2469 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2470 * 2. tmp0.z = lo (tmp0.x * src2)
2471 * 3. tmp0.w = -tmp0.z
2472 * 4. tmp0.y = hi (tmp0.x * src2)
2473 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2474 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2475 * 7. tmp1.x = tmp0.x - tmp0.w
2476 * 8. tmp1.y = tmp0.x + tmp0.w
2477 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2478 * 10. tmp0.z = hi(tmp0.x * src1) = q
2479 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2481 * 12. tmp0.w = src1 - tmp0.y = r
2482 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2483 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2487 * 15. tmp1.z = tmp0.z + 1 = q + 1
2488 * 16. tmp1.w = tmp0.z - 1 = q - 1
2492 * 15. tmp1.z = tmp0.w - src2 = r - src2
2493 * 16. tmp1.w = tmp0.w + src2 = r + src2
2497 * 17. tmp1.x = tmp1.x & tmp1.y
2499 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2500 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2502 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2503 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2507 * Same as unsigned, using abs values of the operands,
2508 * and fixing the sign of the result in the end.
2511 for (i
= 0; i
< 4; i
++) {
2512 if (!(write_mask
& (1<<i
)))
2517 /* tmp2.x = -src0 */
2518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2519 alu
.op
= ALU_OP2_SUB_INT
;
2525 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2527 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2530 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2533 /* tmp2.y = -src1 */
2534 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2535 alu
.op
= ALU_OP2_SUB_INT
;
2541 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2543 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2546 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2549 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2550 /* it will be a sign of the quotient */
2553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2554 alu
.op
= ALU_OP2_XOR_INT
;
2560 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2561 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2564 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2568 /* tmp2.x = |src0| */
2569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2570 alu
.op
= ALU_OP3_CNDGE_INT
;
2577 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2578 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2579 alu
.src
[2].sel
= tmp2
;
2580 alu
.src
[2].chan
= 0;
2583 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2586 /* tmp2.y = |src1| */
2587 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2588 alu
.op
= ALU_OP3_CNDGE_INT
;
2595 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2596 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2597 alu
.src
[2].sel
= tmp2
;
2598 alu
.src
[2].chan
= 1;
2601 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2606 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2607 if (ctx
->bc
->chip_class
== CAYMAN
) {
2608 /* tmp3.x = u2f(src2) */
2609 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2610 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2617 alu
.src
[0].sel
= tmp2
;
2618 alu
.src
[0].chan
= 1;
2620 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2624 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2627 /* tmp0.x = recip(tmp3.x) */
2628 for (j
= 0 ; j
< 3; j
++) {
2629 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2630 alu
.op
= ALU_OP1_RECIP_IEEE
;
2634 alu
.dst
.write
= (j
== 0);
2636 alu
.src
[0].sel
= tmp3
;
2637 alu
.src
[0].chan
= 0;
2641 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2645 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2646 alu
.op
= ALU_OP2_MUL
;
2648 alu
.src
[0].sel
= tmp0
;
2649 alu
.src
[0].chan
= 0;
2651 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2652 alu
.src
[1].value
= 0x4f800000;
2657 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2661 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2662 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2668 alu
.src
[0].sel
= tmp3
;
2669 alu
.src
[0].chan
= 0;
2672 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2676 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2677 alu
.op
= ALU_OP1_RECIP_UINT
;
2684 alu
.src
[0].sel
= tmp2
;
2685 alu
.src
[0].chan
= 1;
2687 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2691 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2695 /* 2. tmp0.z = lo (tmp0.x * src2) */
2696 if (ctx
->bc
->chip_class
== CAYMAN
) {
2697 for (j
= 0 ; j
< 4; j
++) {
2698 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2699 alu
.op
= ALU_OP2_MULLO_UINT
;
2703 alu
.dst
.write
= (j
== 2);
2705 alu
.src
[0].sel
= tmp0
;
2706 alu
.src
[0].chan
= 0;
2708 alu
.src
[1].sel
= tmp2
;
2709 alu
.src
[1].chan
= 1;
2711 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2714 alu
.last
= (j
== 3);
2715 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2719 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2720 alu
.op
= ALU_OP2_MULLO_UINT
;
2726 alu
.src
[0].sel
= tmp0
;
2727 alu
.src
[0].chan
= 0;
2729 alu
.src
[1].sel
= tmp2
;
2730 alu
.src
[1].chan
= 1;
2732 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2736 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2740 /* 3. tmp0.w = -tmp0.z */
2741 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2742 alu
.op
= ALU_OP2_SUB_INT
;
2748 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2749 alu
.src
[1].sel
= tmp0
;
2750 alu
.src
[1].chan
= 2;
2753 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2756 /* 4. tmp0.y = hi (tmp0.x * src2) */
2757 if (ctx
->bc
->chip_class
== CAYMAN
) {
2758 for (j
= 0 ; j
< 4; j
++) {
2759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2760 alu
.op
= ALU_OP2_MULHI_UINT
;
2764 alu
.dst
.write
= (j
== 1);
2766 alu
.src
[0].sel
= tmp0
;
2767 alu
.src
[0].chan
= 0;
2770 alu
.src
[1].sel
= tmp2
;
2771 alu
.src
[1].chan
= 1;
2773 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2775 alu
.last
= (j
== 3);
2776 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2780 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2781 alu
.op
= ALU_OP2_MULHI_UINT
;
2787 alu
.src
[0].sel
= tmp0
;
2788 alu
.src
[0].chan
= 0;
2791 alu
.src
[1].sel
= tmp2
;
2792 alu
.src
[1].chan
= 1;
2794 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2798 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2802 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
2803 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2804 alu
.op
= ALU_OP3_CNDE_INT
;
2811 alu
.src
[0].sel
= tmp0
;
2812 alu
.src
[0].chan
= 1;
2813 alu
.src
[1].sel
= tmp0
;
2814 alu
.src
[1].chan
= 3;
2815 alu
.src
[2].sel
= tmp0
;
2816 alu
.src
[2].chan
= 2;
2819 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2822 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
2823 if (ctx
->bc
->chip_class
== CAYMAN
) {
2824 for (j
= 0 ; j
< 4; j
++) {
2825 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2826 alu
.op
= ALU_OP2_MULHI_UINT
;
2830 alu
.dst
.write
= (j
== 3);
2832 alu
.src
[0].sel
= tmp0
;
2833 alu
.src
[0].chan
= 2;
2835 alu
.src
[1].sel
= tmp0
;
2836 alu
.src
[1].chan
= 0;
2838 alu
.last
= (j
== 3);
2839 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2843 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2844 alu
.op
= ALU_OP2_MULHI_UINT
;
2850 alu
.src
[0].sel
= tmp0
;
2851 alu
.src
[0].chan
= 2;
2853 alu
.src
[1].sel
= tmp0
;
2854 alu
.src
[1].chan
= 0;
2857 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2861 /* 7. tmp1.x = tmp0.x - tmp0.w */
2862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2863 alu
.op
= ALU_OP2_SUB_INT
;
2869 alu
.src
[0].sel
= tmp0
;
2870 alu
.src
[0].chan
= 0;
2871 alu
.src
[1].sel
= tmp0
;
2872 alu
.src
[1].chan
= 3;
2875 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2878 /* 8. tmp1.y = tmp0.x + tmp0.w */
2879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2880 alu
.op
= ALU_OP2_ADD_INT
;
2886 alu
.src
[0].sel
= tmp0
;
2887 alu
.src
[0].chan
= 0;
2888 alu
.src
[1].sel
= tmp0
;
2889 alu
.src
[1].chan
= 3;
2892 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2895 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
2896 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2897 alu
.op
= ALU_OP3_CNDE_INT
;
2904 alu
.src
[0].sel
= tmp0
;
2905 alu
.src
[0].chan
= 1;
2906 alu
.src
[1].sel
= tmp1
;
2907 alu
.src
[1].chan
= 1;
2908 alu
.src
[2].sel
= tmp1
;
2909 alu
.src
[2].chan
= 0;
2912 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2915 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
2916 if (ctx
->bc
->chip_class
== CAYMAN
) {
2917 for (j
= 0 ; j
< 4; j
++) {
2918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2919 alu
.op
= ALU_OP2_MULHI_UINT
;
2923 alu
.dst
.write
= (j
== 2);
2925 alu
.src
[0].sel
= tmp0
;
2926 alu
.src
[0].chan
= 0;
2929 alu
.src
[1].sel
= tmp2
;
2930 alu
.src
[1].chan
= 0;
2932 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2935 alu
.last
= (j
== 3);
2936 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2940 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2941 alu
.op
= ALU_OP2_MULHI_UINT
;
2947 alu
.src
[0].sel
= tmp0
;
2948 alu
.src
[0].chan
= 0;
2951 alu
.src
[1].sel
= tmp2
;
2952 alu
.src
[1].chan
= 0;
2954 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2958 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2962 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
2963 if (ctx
->bc
->chip_class
== CAYMAN
) {
2964 for (j
= 0 ; j
< 4; j
++) {
2965 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2966 alu
.op
= ALU_OP2_MULLO_UINT
;
2970 alu
.dst
.write
= (j
== 1);
2973 alu
.src
[0].sel
= tmp2
;
2974 alu
.src
[0].chan
= 1;
2976 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2979 alu
.src
[1].sel
= tmp0
;
2980 alu
.src
[1].chan
= 2;
2982 alu
.last
= (j
== 3);
2983 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2987 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2988 alu
.op
= ALU_OP2_MULLO_UINT
;
2995 alu
.src
[0].sel
= tmp2
;
2996 alu
.src
[0].chan
= 1;
2998 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3001 alu
.src
[1].sel
= tmp0
;
3002 alu
.src
[1].chan
= 2;
3005 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3009 /* 12. tmp0.w = src1 - tmp0.y = r */
3010 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3011 alu
.op
= ALU_OP2_SUB_INT
;
3018 alu
.src
[0].sel
= tmp2
;
3019 alu
.src
[0].chan
= 0;
3021 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3024 alu
.src
[1].sel
= tmp0
;
3025 alu
.src
[1].chan
= 1;
3028 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3031 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3033 alu
.op
= ALU_OP2_SETGE_UINT
;
3039 alu
.src
[0].sel
= tmp0
;
3040 alu
.src
[0].chan
= 3;
3042 alu
.src
[1].sel
= tmp2
;
3043 alu
.src
[1].chan
= 1;
3045 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3049 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3052 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3053 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3054 alu
.op
= ALU_OP2_SETGE_UINT
;
3061 alu
.src
[0].sel
= tmp2
;
3062 alu
.src
[0].chan
= 0;
3064 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3067 alu
.src
[1].sel
= tmp0
;
3068 alu
.src
[1].chan
= 1;
3071 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3074 if (mod
) { /* UMOD */
3076 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3078 alu
.op
= ALU_OP2_SUB_INT
;
3084 alu
.src
[0].sel
= tmp0
;
3085 alu
.src
[0].chan
= 3;
3088 alu
.src
[1].sel
= tmp2
;
3089 alu
.src
[1].chan
= 1;
3091 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3095 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3098 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3099 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3100 alu
.op
= ALU_OP2_ADD_INT
;
3106 alu
.src
[0].sel
= tmp0
;
3107 alu
.src
[0].chan
= 3;
3109 alu
.src
[1].sel
= tmp2
;
3110 alu
.src
[1].chan
= 1;
3112 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3116 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3121 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3123 alu
.op
= ALU_OP2_ADD_INT
;
3129 alu
.src
[0].sel
= tmp0
;
3130 alu
.src
[0].chan
= 2;
3131 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3134 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3137 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3138 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3139 alu
.op
= ALU_OP2_ADD_INT
;
3145 alu
.src
[0].sel
= tmp0
;
3146 alu
.src
[0].chan
= 2;
3147 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3150 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3155 /* 17. tmp1.x = tmp1.x & tmp1.y */
3156 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3157 alu
.op
= ALU_OP2_AND_INT
;
3163 alu
.src
[0].sel
= tmp1
;
3164 alu
.src
[0].chan
= 0;
3165 alu
.src
[1].sel
= tmp1
;
3166 alu
.src
[1].chan
= 1;
3169 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3172 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3173 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3174 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3175 alu
.op
= ALU_OP3_CNDE_INT
;
3182 alu
.src
[0].sel
= tmp1
;
3183 alu
.src
[0].chan
= 0;
3184 alu
.src
[1].sel
= tmp0
;
3185 alu
.src
[1].chan
= mod
? 3 : 2;
3186 alu
.src
[2].sel
= tmp1
;
3187 alu
.src
[2].chan
= 2;
3190 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3193 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3195 alu
.op
= ALU_OP3_CNDE_INT
;
3203 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3206 alu
.src
[0].sel
= tmp1
;
3207 alu
.src
[0].chan
= 1;
3208 alu
.src
[1].sel
= tmp1
;
3209 alu
.src
[1].chan
= 3;
3210 alu
.src
[2].sel
= tmp0
;
3211 alu
.src
[2].chan
= 2;
3214 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3219 /* fix the sign of the result */
3223 /* tmp0.x = -tmp0.z */
3224 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3225 alu
.op
= ALU_OP2_SUB_INT
;
3231 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3232 alu
.src
[1].sel
= tmp0
;
3233 alu
.src
[1].chan
= 2;
3236 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3239 /* sign of the remainder is the same as the sign of src0 */
3240 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3241 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3242 alu
.op
= ALU_OP3_CNDGE_INT
;
3245 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3247 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3248 alu
.src
[1].sel
= tmp0
;
3249 alu
.src
[1].chan
= 2;
3250 alu
.src
[2].sel
= tmp0
;
3251 alu
.src
[2].chan
= 0;
3254 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3259 /* tmp0.x = -tmp0.z */
3260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3261 alu
.op
= ALU_OP2_SUB_INT
;
3267 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3268 alu
.src
[1].sel
= tmp0
;
3269 alu
.src
[1].chan
= 2;
3272 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3275 /* fix the quotient sign (same as the sign of src0*src1) */
3276 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3278 alu
.op
= ALU_OP3_CNDGE_INT
;
3281 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3283 alu
.src
[0].sel
= tmp2
;
3284 alu
.src
[0].chan
= 2;
3285 alu
.src
[1].sel
= tmp0
;
3286 alu
.src
[1].chan
= 2;
3287 alu
.src
[2].sel
= tmp0
;
3288 alu
.src
[2].chan
= 0;
3291 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3299 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3301 return tgsi_divmod(ctx
, 0, 0);
3304 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3306 return tgsi_divmod(ctx
, 1, 0);
3309 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3311 return tgsi_divmod(ctx
, 0, 1);
3314 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3316 return tgsi_divmod(ctx
, 1, 1);
3320 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3322 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3323 struct r600_bytecode_alu alu
;
3325 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3326 int last_inst
= tgsi_last_instruction(write_mask
);
3328 for (i
= 0; i
< 4; i
++) {
3329 if (!(write_mask
& (1<<i
)))
3332 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3333 alu
.op
= ALU_OP1_TRUNC
;
3335 alu
.dst
.sel
= ctx
->temp_reg
;
3339 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3342 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3347 for (i
= 0; i
< 4; i
++) {
3348 if (!(write_mask
& (1<<i
)))
3351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3352 alu
.op
= ctx
->inst_info
->op
;
3354 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3356 alu
.src
[0].sel
= ctx
->temp_reg
;
3357 alu
.src
[0].chan
= i
;
3359 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3361 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3369 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3371 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3372 struct r600_bytecode_alu alu
;
3374 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3375 int last_inst
= tgsi_last_instruction(write_mask
);
3378 for (i
= 0; i
< 4; i
++) {
3379 if (!(write_mask
& (1<<i
)))
3382 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3383 alu
.op
= ALU_OP2_SUB_INT
;
3385 alu
.dst
.sel
= ctx
->temp_reg
;
3389 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3390 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3394 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3399 /* dst = (src >= 0 ? src : tmp) */
3400 for (i
= 0; i
< 4; i
++) {
3401 if (!(write_mask
& (1<<i
)))
3404 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3405 alu
.op
= ALU_OP3_CNDGE_INT
;
3409 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3411 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3412 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3413 alu
.src
[2].sel
= ctx
->temp_reg
;
3414 alu
.src
[2].chan
= i
;
3418 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3425 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3427 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3428 struct r600_bytecode_alu alu
;
3430 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3431 int last_inst
= tgsi_last_instruction(write_mask
);
3433 /* tmp = (src >= 0 ? src : -1) */
3434 for (i
= 0; i
< 4; i
++) {
3435 if (!(write_mask
& (1<<i
)))
3438 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3439 alu
.op
= ALU_OP3_CNDGE_INT
;
3442 alu
.dst
.sel
= ctx
->temp_reg
;
3446 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3447 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3448 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3457 /* dst = (tmp > 0 ? 1 : tmp) */
3458 for (i
= 0; i
< 4; i
++) {
3459 if (!(write_mask
& (1<<i
)))
3462 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3463 alu
.op
= ALU_OP3_CNDGT_INT
;
3467 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3469 alu
.src
[0].sel
= ctx
->temp_reg
;
3470 alu
.src
[0].chan
= i
;
3472 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3474 alu
.src
[2].sel
= ctx
->temp_reg
;
3475 alu
.src
[2].chan
= i
;
3479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3488 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3490 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3491 struct r600_bytecode_alu alu
;
3494 /* tmp = (src > 0 ? 1 : src) */
3495 for (i
= 0; i
< 4; i
++) {
3496 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3497 alu
.op
= ALU_OP3_CNDGT
;
3500 alu
.dst
.sel
= ctx
->temp_reg
;
3503 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3504 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3505 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3509 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3514 /* dst = (-tmp > 0 ? -1 : tmp) */
3515 for (i
= 0; i
< 4; i
++) {
3516 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3517 alu
.op
= ALU_OP3_CNDGT
;
3519 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3521 alu
.src
[0].sel
= ctx
->temp_reg
;
3522 alu
.src
[0].chan
= i
;
3525 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3528 alu
.src
[2].sel
= ctx
->temp_reg
;
3529 alu
.src
[2].chan
= i
;
3533 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3540 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3542 struct r600_bytecode_alu alu
;
3545 for (i
= 0; i
< 4; i
++) {
3546 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3547 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3548 alu
.op
= ALU_OP0_NOP
;
3551 alu
.op
= ALU_OP1_MOV
;
3552 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3553 alu
.src
[0].sel
= ctx
->temp_reg
;
3554 alu
.src
[0].chan
= i
;
3559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3566 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3568 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3569 struct r600_bytecode_alu alu
;
3571 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3573 for (i
= 0; i
< lasti
+ 1; i
++) {
3574 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3577 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3578 alu
.op
= ctx
->inst_info
->op
;
3579 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3580 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3583 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3590 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3597 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3599 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3600 struct r600_bytecode_alu alu
;
3603 for (i
= 0; i
< 4; i
++) {
3604 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3605 alu
.op
= ctx
->inst_info
->op
;
3606 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3607 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3610 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3612 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3613 /* handle some special cases */
3614 switch (ctx
->inst_info
->tgsi_opcode
) {
3615 case TGSI_OPCODE_DP2
:
3617 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3618 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3621 case TGSI_OPCODE_DP3
:
3623 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3624 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3627 case TGSI_OPCODE_DPH
:
3629 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3630 alu
.src
[0].chan
= 0;
3640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3647 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3650 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3651 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3652 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3653 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3654 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3657 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3660 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3661 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3664 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3666 struct r600_bytecode_vtx vtx
;
3667 struct r600_bytecode_alu alu
;
3668 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3670 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3672 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3673 if (src_requires_loading
) {
3674 for (i
= 0; i
< 4; i
++) {
3675 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3676 alu
.op
= ALU_OP1_MOV
;
3677 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3678 alu
.dst
.sel
= ctx
->temp_reg
;
3683 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3687 src_gpr
= ctx
->temp_reg
;
3690 memset(&vtx
, 0, sizeof(vtx
));
3691 vtx
.op
= FETCH_OP_VFETCH
;
3692 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3693 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3694 vtx
.src_gpr
= src_gpr
;
3695 vtx
.mega_fetch_count
= 16;
3696 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3697 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3698 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3699 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
3700 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
3701 vtx
.use_const_fields
= 1;
3702 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
3704 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
3707 if (ctx
->bc
->chip_class
>= EVERGREEN
)
3710 for (i
= 0; i
< 4; i
++) {
3711 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3712 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3715 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3716 alu
.op
= ALU_OP2_AND_INT
;
3719 alu
.dst
.sel
= vtx
.dst_gpr
;
3722 alu
.src
[0].sel
= vtx
.dst_gpr
;
3723 alu
.src
[0].chan
= i
;
3725 alu
.src
[1].sel
= 512 + (id
* 2);
3726 alu
.src
[1].chan
= i
% 4;
3727 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3731 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3736 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
3737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3738 alu
.op
= ALU_OP2_OR_INT
;
3741 alu
.dst
.sel
= vtx
.dst_gpr
;
3744 alu
.src
[0].sel
= vtx
.dst_gpr
;
3745 alu
.src
[0].chan
= 3;
3747 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
3748 alu
.src
[1].chan
= 0;
3749 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3759 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
3761 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3762 struct r600_bytecode_alu alu
;
3764 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3767 alu
.op
= ALU_OP1_MOV
;
3769 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
3770 alu
.src
[0].sel
= 512 + (id
/ 4);
3771 alu
.src
[0].chan
= id
% 4;
3773 /* r600 we have them at channel 2 of the second dword */
3774 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
3775 alu
.src
[0].chan
= 1;
3777 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3778 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3780 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3786 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
3788 static float one_point_five
= 1.5f
;
3789 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3790 struct r600_bytecode_tex tex
;
3791 struct r600_bytecode_alu alu
;
3795 bool read_compressed_msaa
= ctx
->bc
->msaa_texture_mode
== MSAA_TEXTURE_COMPRESSED
&&
3796 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
3797 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
3798 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
3799 /* Texture fetch instructions can only use gprs as source.
3800 * Also they cannot negate the source or take the absolute value */
3801 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
3802 tgsi_tex_src_requires_loading(ctx
, 0)) ||
3803 read_compressed_msaa
;
3804 boolean src_loaded
= FALSE
;
3805 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
3806 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
3807 boolean has_txq_cube_array_z
= false;
3809 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
3810 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3811 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
3812 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
3813 ctx
->shader
->has_txq_cube_array_z_comp
= true;
3814 has_txq_cube_array_z
= true;
3817 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
3818 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
3819 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
3820 sampler_src_reg
= 2;
3822 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3824 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
3825 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
3826 ctx
->shader
->uses_tex_buffers
= true;
3827 return r600_do_buffer_txq(ctx
);
3829 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3830 if (ctx
->bc
->chip_class
< EVERGREEN
)
3831 ctx
->shader
->uses_tex_buffers
= true;
3832 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
3836 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3837 /* get offset values */
3838 if (inst
->Texture
.NumOffsets
) {
3839 assert(inst
->Texture
.NumOffsets
== 1);
3841 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
3842 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
3843 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
3845 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
3846 /* TGSI moves the sampler to src reg 3 for TXD */
3847 sampler_src_reg
= 3;
3849 for (i
= 1; i
< 3; i
++) {
3850 /* set gradients h/v */
3851 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
3852 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
3853 FETCH_OP_SET_GRADIENTS_V
;
3854 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
3855 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
3857 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
3858 tex
.src_gpr
= r600_get_temp(ctx
);
3864 for (j
= 0; j
< 4; j
++) {
3865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3866 alu
.op
= ALU_OP1_MOV
;
3867 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
3868 alu
.dst
.sel
= tex
.src_gpr
;
3873 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3879 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
3880 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
3881 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
3882 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
3883 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
3884 tex
.src_rel
= ctx
->src
[i
].rel
;
3886 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
3887 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
3888 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
3889 tex
.coord_type_x
= 1;
3890 tex
.coord_type_y
= 1;
3891 tex
.coord_type_z
= 1;
3892 tex
.coord_type_w
= 1;
3894 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
3898 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
3900 /* Add perspective divide */
3901 if (ctx
->bc
->chip_class
== CAYMAN
) {
3903 for (i
= 0; i
< 3; i
++) {
3904 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3905 alu
.op
= ALU_OP1_RECIP_IEEE
;
3906 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3908 alu
.dst
.sel
= ctx
->temp_reg
;
3914 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3922 alu
.op
= ALU_OP1_RECIP_IEEE
;
3923 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3925 alu
.dst
.sel
= ctx
->temp_reg
;
3926 alu
.dst
.chan
= out_chan
;
3929 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3934 for (i
= 0; i
< 3; i
++) {
3935 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3936 alu
.op
= ALU_OP2_MUL
;
3937 alu
.src
[0].sel
= ctx
->temp_reg
;
3938 alu
.src
[0].chan
= out_chan
;
3939 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3940 alu
.dst
.sel
= ctx
->temp_reg
;
3943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3948 alu
.op
= ALU_OP1_MOV
;
3949 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3950 alu
.src
[0].chan
= 0;
3951 alu
.dst
.sel
= ctx
->temp_reg
;
3955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3959 src_gpr
= ctx
->temp_reg
;
3962 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
3963 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3964 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
3965 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
3966 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
3967 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
3969 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
3970 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
3972 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
3973 for (i
= 0; i
< 4; i
++) {
3974 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3975 alu
.op
= ALU_OP2_CUBE
;
3976 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
3977 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
3978 alu
.dst
.sel
= ctx
->temp_reg
;
3983 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3988 /* tmp1.z = RCP_e(|tmp1.z|) */
3989 if (ctx
->bc
->chip_class
== CAYMAN
) {
3990 for (i
= 0; i
< 3; i
++) {
3991 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3992 alu
.op
= ALU_OP1_RECIP_IEEE
;
3993 alu
.src
[0].sel
= ctx
->temp_reg
;
3994 alu
.src
[0].chan
= 2;
3996 alu
.dst
.sel
= ctx
->temp_reg
;
4002 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4007 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4008 alu
.op
= ALU_OP1_RECIP_IEEE
;
4009 alu
.src
[0].sel
= ctx
->temp_reg
;
4010 alu
.src
[0].chan
= 2;
4012 alu
.dst
.sel
= ctx
->temp_reg
;
4016 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4021 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4022 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4023 * muladd has no writemask, have to use another temp
4025 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4026 alu
.op
= ALU_OP3_MULADD
;
4029 alu
.src
[0].sel
= ctx
->temp_reg
;
4030 alu
.src
[0].chan
= 0;
4031 alu
.src
[1].sel
= ctx
->temp_reg
;
4032 alu
.src
[1].chan
= 2;
4034 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4035 alu
.src
[2].chan
= 0;
4036 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4038 alu
.dst
.sel
= ctx
->temp_reg
;
4042 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4047 alu
.op
= ALU_OP3_MULADD
;
4050 alu
.src
[0].sel
= ctx
->temp_reg
;
4051 alu
.src
[0].chan
= 1;
4052 alu
.src
[1].sel
= ctx
->temp_reg
;
4053 alu
.src
[1].chan
= 2;
4055 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4056 alu
.src
[2].chan
= 0;
4057 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4059 alu
.dst
.sel
= ctx
->temp_reg
;
4064 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4067 /* write initial compare value into Z component
4068 - W src 0 for shadow cube
4069 - X src 1 for shadow cube array */
4070 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4071 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4073 alu
.op
= ALU_OP1_MOV
;
4074 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4075 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4077 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4078 alu
.dst
.sel
= ctx
->temp_reg
;
4082 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4087 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4088 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4089 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4090 int mytmp
= r600_get_temp(ctx
);
4091 static const float eight
= 8.0f
;
4092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4093 alu
.op
= ALU_OP1_MOV
;
4094 alu
.src
[0].sel
= ctx
->temp_reg
;
4095 alu
.src
[0].chan
= 3;
4096 alu
.dst
.sel
= mytmp
;
4100 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4104 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4105 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4106 alu
.op
= ALU_OP3_MULADD
;
4108 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4109 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4110 alu
.src
[1].chan
= 0;
4111 alu
.src
[1].value
= *(uint32_t *)&eight
;
4112 alu
.src
[2].sel
= mytmp
;
4113 alu
.src
[2].chan
= 0;
4114 alu
.dst
.sel
= ctx
->temp_reg
;
4118 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4121 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4122 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4123 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4124 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4125 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4126 tex
.src_gpr
= r600_get_temp(ctx
);
4131 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4132 tex
.coord_type_x
= 1;
4133 tex
.coord_type_y
= 1;
4134 tex
.coord_type_z
= 1;
4135 tex
.coord_type_w
= 1;
4136 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4137 alu
.op
= ALU_OP1_MOV
;
4138 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4139 alu
.dst
.sel
= tex
.src_gpr
;
4143 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4147 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4154 /* for cube forms of lod and bias we need to route things */
4155 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4156 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4157 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4158 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4159 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4160 alu
.op
= ALU_OP1_MOV
;
4161 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4162 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4163 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4165 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4166 alu
.dst
.sel
= ctx
->temp_reg
;
4170 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4176 src_gpr
= ctx
->temp_reg
;
4179 if (src_requires_loading
&& !src_loaded
) {
4180 for (i
= 0; i
< 4; i
++) {
4181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4182 alu
.op
= ALU_OP1_MOV
;
4183 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4184 alu
.dst
.sel
= ctx
->temp_reg
;
4189 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4194 src_gpr
= ctx
->temp_reg
;
4197 /* Obtain the sample index for reading a compressed MSAA color texture.
4198 * To read the FMASK, we use the ldfptr instruction, which tells us
4199 * where the samples are stored.
4200 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4201 * which is the identity mapping. Each nibble says which physical sample
4202 * should be fetched to get that sample.
4204 * Assume src.z contains the sample index. It should be modified like this:
4205 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4206 * Then fetch the texel with src.
4208 if (read_compressed_msaa
) {
4209 unsigned sample_chan
= 3;
4210 unsigned temp
= r600_get_temp(ctx
);
4213 /* temp.w = ldfptr() */
4214 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4215 tex
.op
= FETCH_OP_LD
;
4216 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4217 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4218 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4219 tex
.src_gpr
= src_gpr
;
4221 tex
.dst_sel_x
= 7; /* mask out these components */
4224 tex
.dst_sel_w
= 0; /* store X */
4229 tex
.offset_x
= offset_x
;
4230 tex
.offset_y
= offset_y
;
4231 tex
.offset_z
= offset_z
;
4232 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4236 /* temp.x = sample_index*4 */
4237 if (ctx
->bc
->chip_class
== CAYMAN
) {
4238 for (i
= 0 ; i
< 4; i
++) {
4239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4240 alu
.op
= ALU_OP2_MULLO_INT
;
4241 alu
.src
[0].sel
= src_gpr
;
4242 alu
.src
[0].chan
= sample_chan
;
4243 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4244 alu
.src
[1].value
= 4;
4247 alu
.dst
.write
= i
== 0;
4250 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4255 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4256 alu
.op
= ALU_OP2_MULLO_INT
;
4257 alu
.src
[0].sel
= src_gpr
;
4258 alu
.src
[0].chan
= sample_chan
;
4259 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4260 alu
.src
[1].value
= 4;
4265 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4270 /* sample_index = temp.w >> temp.x */
4271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4272 alu
.op
= ALU_OP2_LSHR_INT
;
4273 alu
.src
[0].sel
= temp
;
4274 alu
.src
[0].chan
= 3;
4275 alu
.src
[1].sel
= temp
;
4276 alu
.src
[1].chan
= 0;
4277 alu
.dst
.sel
= src_gpr
;
4278 alu
.dst
.chan
= sample_chan
;
4281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4285 /* sample_index & 0xF */
4286 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4287 alu
.op
= ALU_OP2_AND_INT
;
4288 alu
.src
[0].sel
= src_gpr
;
4289 alu
.src
[0].chan
= sample_chan
;
4290 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4291 alu
.src
[1].value
= 0xF;
4292 alu
.dst
.sel
= src_gpr
;
4293 alu
.dst
.chan
= sample_chan
;
4296 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4300 /* visualize the FMASK */
4301 for (i
= 0; i
< 4; i
++) {
4302 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4303 alu
.op
= ALU_OP1_INT_TO_FLT
;
4304 alu
.src
[0].sel
= src_gpr
;
4305 alu
.src
[0].chan
= sample_chan
;
4306 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4310 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4318 /* does this shader want a num layers from TXQ for a cube array? */
4319 if (has_txq_cube_array_z
) {
4320 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4323 alu
.op
= ALU_OP1_MOV
;
4325 alu
.src
[0].sel
= 512 + (id
/ 4);
4326 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4327 alu
.src
[0].chan
= id
% 4;
4328 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4333 /* disable writemask from texture instruction */
4334 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4337 opcode
= ctx
->inst_info
->op
;
4338 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4339 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4340 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4341 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4342 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4343 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4344 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4346 case FETCH_OP_SAMPLE
:
4347 opcode
= FETCH_OP_SAMPLE_C
;
4349 case FETCH_OP_SAMPLE_L
:
4350 opcode
= FETCH_OP_SAMPLE_C_L
;
4352 case FETCH_OP_SAMPLE_LB
:
4353 opcode
= FETCH_OP_SAMPLE_C_LB
;
4355 case FETCH_OP_SAMPLE_G
:
4356 opcode
= FETCH_OP_SAMPLE_C_G
;
4361 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4364 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4365 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4366 tex
.src_gpr
= src_gpr
;
4367 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4368 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4369 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4370 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4371 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4373 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4378 } else if (src_loaded
) {
4384 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4385 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4386 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4387 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4388 tex
.src_rel
= ctx
->src
[0].rel
;
4391 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4392 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4393 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4394 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4398 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4401 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4402 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4403 tex
.coord_type_x
= 1;
4404 tex
.coord_type_y
= 1;
4406 tex
.coord_type_z
= 1;
4407 tex
.coord_type_w
= 1;
4409 tex
.offset_x
= offset_x
;
4410 tex
.offset_y
= offset_y
;
4411 tex
.offset_z
= offset_z
;
4413 /* Put the depth for comparison in W.
4414 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4415 * Some instructions expect the depth in Z. */
4416 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4417 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4418 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4419 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4420 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4421 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4422 tex
.src_sel_w
= tex
.src_sel_z
;
4425 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4426 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4427 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4428 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4429 /* the array index is read from Y */
4430 tex
.coord_type_y
= 0;
4432 /* the array index is read from Z */
4433 tex
.coord_type_z
= 0;
4434 tex
.src_sel_z
= tex
.src_sel_y
;
4436 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4437 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4438 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4439 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4440 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4441 /* the array index is read from Z */
4442 tex
.coord_type_z
= 0;
4444 /* mask unused source components */
4445 if (opcode
== FETCH_OP_SAMPLE
) {
4446 switch (inst
->Texture
.Texture
) {
4447 case TGSI_TEXTURE_2D
:
4448 case TGSI_TEXTURE_RECT
:
4452 case TGSI_TEXTURE_1D_ARRAY
:
4456 case TGSI_TEXTURE_1D
:
4464 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4468 /* add shadow ambient support - gallium doesn't do it yet */
4472 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4474 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4475 struct r600_bytecode_alu alu
;
4476 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4480 /* optimize if it's just an equal balance */
4481 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4482 for (i
= 0; i
< lasti
+ 1; i
++) {
4483 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4486 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4487 alu
.op
= ALU_OP2_ADD
;
4488 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4489 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4491 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4496 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4504 for (i
= 0; i
< lasti
+ 1; i
++) {
4505 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4508 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4509 alu
.op
= ALU_OP2_ADD
;
4510 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4511 alu
.src
[0].chan
= 0;
4512 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4513 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4514 alu
.dst
.sel
= ctx
->temp_reg
;
4520 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4525 /* (1 - src0) * src2 */
4526 for (i
= 0; i
< lasti
+ 1; i
++) {
4527 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4530 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4531 alu
.op
= ALU_OP2_MUL
;
4532 alu
.src
[0].sel
= ctx
->temp_reg
;
4533 alu
.src
[0].chan
= i
;
4534 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4535 alu
.dst
.sel
= ctx
->temp_reg
;
4541 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4546 /* src0 * src1 + (1 - src0) * src2 */
4547 for (i
= 0; i
< lasti
+ 1; i
++) {
4548 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4552 alu
.op
= ALU_OP3_MULADD
;
4554 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4555 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4556 alu
.src
[2].sel
= ctx
->temp_reg
;
4557 alu
.src
[2].chan
= i
;
4559 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4564 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4571 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4573 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4574 struct r600_bytecode_alu alu
;
4576 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4578 for (i
= 0; i
< lasti
+ 1; i
++) {
4579 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4583 alu
.op
= ALU_OP3_CNDGE
;
4584 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4585 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4586 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4587 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4593 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4600 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4602 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4603 struct r600_bytecode_alu alu
;
4605 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4607 for (i
= 0; i
< lasti
+ 1; i
++) {
4608 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4612 alu
.op
= ALU_OP3_CNDGE_INT
;
4613 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4614 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4615 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4616 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4622 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4629 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4631 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4632 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4633 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4634 struct r600_bytecode_alu alu
;
4635 uint32_t use_temp
= 0;
4638 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4641 for (i
= 0; i
< 4; i
++) {
4642 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4643 alu
.op
= ALU_OP2_MUL
;
4645 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4646 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4648 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4649 alu
.src
[0].chan
= i
;
4650 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4651 alu
.src
[1].chan
= i
;
4654 alu
.dst
.sel
= ctx
->temp_reg
;
4660 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4665 for (i
= 0; i
< 4; i
++) {
4666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4667 alu
.op
= ALU_OP3_MULADD
;
4670 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4671 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4673 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4674 alu
.src
[0].chan
= i
;
4675 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4676 alu
.src
[1].chan
= i
;
4679 alu
.src
[2].sel
= ctx
->temp_reg
;
4681 alu
.src
[2].chan
= i
;
4684 alu
.dst
.sel
= ctx
->temp_reg
;
4686 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4692 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4697 return tgsi_helper_copy(ctx
, inst
);
4701 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4703 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4704 struct r600_bytecode_alu alu
;
4708 /* result.x = 2^floor(src); */
4709 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4710 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4712 alu
.op
= ALU_OP1_FLOOR
;
4713 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4715 alu
.dst
.sel
= ctx
->temp_reg
;
4719 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4723 if (ctx
->bc
->chip_class
== CAYMAN
) {
4724 for (i
= 0; i
< 3; i
++) {
4725 alu
.op
= ALU_OP1_EXP_IEEE
;
4726 alu
.src
[0].sel
= ctx
->temp_reg
;
4727 alu
.src
[0].chan
= 0;
4729 alu
.dst
.sel
= ctx
->temp_reg
;
4731 alu
.dst
.write
= i
== 0;
4733 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4738 alu
.op
= ALU_OP1_EXP_IEEE
;
4739 alu
.src
[0].sel
= ctx
->temp_reg
;
4740 alu
.src
[0].chan
= 0;
4742 alu
.dst
.sel
= ctx
->temp_reg
;
4746 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4752 /* result.y = tmp - floor(tmp); */
4753 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4754 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4756 alu
.op
= ALU_OP1_FRACT
;
4757 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4759 alu
.dst
.sel
= ctx
->temp_reg
;
4761 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4770 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4775 /* result.z = RoughApprox2ToX(tmp);*/
4776 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
4777 if (ctx
->bc
->chip_class
== CAYMAN
) {
4778 for (i
= 0; i
< 3; i
++) {
4779 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4780 alu
.op
= ALU_OP1_EXP_IEEE
;
4781 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4783 alu
.dst
.sel
= ctx
->temp_reg
;
4790 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4795 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4796 alu
.op
= ALU_OP1_EXP_IEEE
;
4797 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4799 alu
.dst
.sel
= ctx
->temp_reg
;
4805 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4811 /* result.w = 1.0;*/
4812 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
4813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4815 alu
.op
= ALU_OP1_MOV
;
4816 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4817 alu
.src
[0].chan
= 0;
4819 alu
.dst
.sel
= ctx
->temp_reg
;
4823 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4827 return tgsi_helper_copy(ctx
, inst
);
4830 static int tgsi_log(struct r600_shader_ctx
*ctx
)
4832 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4833 struct r600_bytecode_alu alu
;
4837 /* result.x = floor(log2(|src|)); */
4838 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4839 if (ctx
->bc
->chip_class
== CAYMAN
) {
4840 for (i
= 0; i
< 3; i
++) {
4841 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4843 alu
.op
= ALU_OP1_LOG_IEEE
;
4844 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4845 r600_bytecode_src_set_abs(&alu
.src
[0]);
4847 alu
.dst
.sel
= ctx
->temp_reg
;
4853 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4859 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4861 alu
.op
= ALU_OP1_LOG_IEEE
;
4862 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4863 r600_bytecode_src_set_abs(&alu
.src
[0]);
4865 alu
.dst
.sel
= ctx
->temp_reg
;
4869 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4874 alu
.op
= ALU_OP1_FLOOR
;
4875 alu
.src
[0].sel
= ctx
->temp_reg
;
4876 alu
.src
[0].chan
= 0;
4878 alu
.dst
.sel
= ctx
->temp_reg
;
4883 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4888 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
4889 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4891 if (ctx
->bc
->chip_class
== CAYMAN
) {
4892 for (i
= 0; i
< 3; i
++) {
4893 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4895 alu
.op
= ALU_OP1_LOG_IEEE
;
4896 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4897 r600_bytecode_src_set_abs(&alu
.src
[0]);
4899 alu
.dst
.sel
= ctx
->temp_reg
;
4906 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4913 alu
.op
= ALU_OP1_LOG_IEEE
;
4914 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4915 r600_bytecode_src_set_abs(&alu
.src
[0]);
4917 alu
.dst
.sel
= ctx
->temp_reg
;
4922 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4927 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4929 alu
.op
= ALU_OP1_FLOOR
;
4930 alu
.src
[0].sel
= ctx
->temp_reg
;
4931 alu
.src
[0].chan
= 1;
4933 alu
.dst
.sel
= ctx
->temp_reg
;
4938 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4942 if (ctx
->bc
->chip_class
== CAYMAN
) {
4943 for (i
= 0; i
< 3; i
++) {
4944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4945 alu
.op
= ALU_OP1_EXP_IEEE
;
4946 alu
.src
[0].sel
= ctx
->temp_reg
;
4947 alu
.src
[0].chan
= 1;
4949 alu
.dst
.sel
= ctx
->temp_reg
;
4956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4962 alu
.op
= ALU_OP1_EXP_IEEE
;
4963 alu
.src
[0].sel
= ctx
->temp_reg
;
4964 alu
.src
[0].chan
= 1;
4966 alu
.dst
.sel
= ctx
->temp_reg
;
4971 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4976 if (ctx
->bc
->chip_class
== CAYMAN
) {
4977 for (i
= 0; i
< 3; i
++) {
4978 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4979 alu
.op
= ALU_OP1_RECIP_IEEE
;
4980 alu
.src
[0].sel
= ctx
->temp_reg
;
4981 alu
.src
[0].chan
= 1;
4983 alu
.dst
.sel
= ctx
->temp_reg
;
4990 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4996 alu
.op
= ALU_OP1_RECIP_IEEE
;
4997 alu
.src
[0].sel
= ctx
->temp_reg
;
4998 alu
.src
[0].chan
= 1;
5000 alu
.dst
.sel
= ctx
->temp_reg
;
5005 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5010 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5012 alu
.op
= ALU_OP2_MUL
;
5014 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5015 r600_bytecode_src_set_abs(&alu
.src
[0]);
5017 alu
.src
[1].sel
= ctx
->temp_reg
;
5018 alu
.src
[1].chan
= 1;
5020 alu
.dst
.sel
= ctx
->temp_reg
;
5025 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5030 /* result.z = log2(|src|);*/
5031 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5032 if (ctx
->bc
->chip_class
== CAYMAN
) {
5033 for (i
= 0; i
< 3; i
++) {
5034 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5036 alu
.op
= ALU_OP1_LOG_IEEE
;
5037 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5038 r600_bytecode_src_set_abs(&alu
.src
[0]);
5040 alu
.dst
.sel
= ctx
->temp_reg
;
5047 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5054 alu
.op
= ALU_OP1_LOG_IEEE
;
5055 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5056 r600_bytecode_src_set_abs(&alu
.src
[0]);
5058 alu
.dst
.sel
= ctx
->temp_reg
;
5063 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5069 /* result.w = 1.0; */
5070 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5071 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5073 alu
.op
= ALU_OP1_MOV
;
5074 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5075 alu
.src
[0].chan
= 0;
5077 alu
.dst
.sel
= ctx
->temp_reg
;
5082 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5087 return tgsi_helper_copy(ctx
, inst
);
5090 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5092 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5093 struct r600_bytecode_alu alu
;
5096 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5098 switch (inst
->Instruction
.Opcode
) {
5099 case TGSI_OPCODE_ARL
:
5100 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5102 case TGSI_OPCODE_ARR
:
5103 alu
.op
= ALU_OP1_FLT_TO_INT
;
5105 case TGSI_OPCODE_UARL
:
5106 alu
.op
= ALU_OP1_MOV
;
5113 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5115 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5117 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5121 ctx
->bc
->ar_loaded
= 0;
5124 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5126 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5127 struct r600_bytecode_alu alu
;
5130 switch (inst
->Instruction
.Opcode
) {
5131 case TGSI_OPCODE_ARL
:
5132 memset(&alu
, 0, sizeof(alu
));
5133 alu
.op
= ALU_OP1_FLOOR
;
5134 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5135 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5139 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5142 memset(&alu
, 0, sizeof(alu
));
5143 alu
.op
= ALU_OP1_FLT_TO_INT
;
5144 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5145 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5149 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5152 case TGSI_OPCODE_ARR
:
5153 memset(&alu
, 0, sizeof(alu
));
5154 alu
.op
= ALU_OP1_FLT_TO_INT
;
5155 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5156 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5160 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5163 case TGSI_OPCODE_UARL
:
5164 memset(&alu
, 0, sizeof(alu
));
5165 alu
.op
= ALU_OP1_MOV
;
5166 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5167 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5171 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5179 ctx
->bc
->ar_loaded
= 0;
5183 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5185 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5186 struct r600_bytecode_alu alu
;
5189 for (i
= 0; i
< 4; i
++) {
5190 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5192 alu
.op
= ALU_OP2_MUL
;
5193 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5195 if (i
== 0 || i
== 3) {
5196 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5198 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5201 if (i
== 0 || i
== 2) {
5202 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5204 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5208 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5215 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5217 struct r600_bytecode_alu alu
;
5220 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5222 alu
.execute_mask
= 1;
5223 alu
.update_pred
= 1;
5225 alu
.dst
.sel
= ctx
->temp_reg
;
5229 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5230 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5231 alu
.src
[1].chan
= 0;
5235 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5241 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5243 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5247 if (ctx
->bc
->cf_last
) {
5248 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5250 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5255 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5256 ctx
->bc
->force_add_cf
= 1;
5257 } else if (alu_pop
== 2) {
5258 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5259 ctx
->bc
->force_add_cf
= 1;
5266 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5267 ctx
->bc
->cf_last
->pop_count
= pops
;
5268 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5274 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5277 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5278 unsigned elements
, entries
;
5280 unsigned entry_size
= stack
->entry_size
;
5282 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5283 elements
+= stack
->push
;
5285 switch (ctx
->bc
->chip_class
) {
5288 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5289 * the stack must be reserved to hold the current active/continue
5291 if (reason
== FC_PUSH_VPM
) {
5297 /* r9xx: any stack operation on empty stack consumes 2 additional
5302 /* FIXME: do the two elements added above cover the cases for the
5306 /* r8xx+: 2 extra elements are not always required, but one extra
5307 * element must be added for each of the following cases:
5308 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5310 * (Currently we don't use ALU_ELSE_AFTER.)
5311 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5312 * PUSH instruction executed.
5314 * NOTE: it seems we also need to reserve additional element in some
5315 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5316 * then STACK_SIZE should be 2 instead of 1 */
5317 if (reason
== FC_PUSH_VPM
) {
5327 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5328 * for all chips, so we use 4 in the final formula, not the real entry_size
5332 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5334 if (entries
> stack
->max_entries
)
5335 stack
->max_entries
= entries
;
5338 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5342 --ctx
->bc
->stack
.push
;
5343 assert(ctx
->bc
->stack
.push
>= 0);
5346 --ctx
->bc
->stack
.push_wqm
;
5347 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5350 --ctx
->bc
->stack
.loop
;
5351 assert(ctx
->bc
->stack
.loop
>= 0);
5359 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5363 ++ctx
->bc
->stack
.push
;
5366 ++ctx
->bc
->stack
.push_wqm
;
5368 ++ctx
->bc
->stack
.loop
;
5374 callstack_update_max_depth(ctx
, reason
);
5377 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5379 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5381 sp
->mid
= realloc((void *)sp
->mid
,
5382 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5383 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5387 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5390 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5391 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5394 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5396 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5406 static int emit_return(struct r600_shader_ctx
*ctx
)
5408 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5412 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5415 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5416 ctx
->bc
->cf_last
->pop_count
= pops
;
5417 /* XXX work out offset */
5421 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5426 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5431 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5434 emit_jump_to_offset(ctx
, 1, 4);
5435 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5436 pops(ctx
, ifidx
+ 1);
5440 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5444 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5445 ctx
->bc
->cf_last
->pop_count
= 1;
5447 fc_set_mid(ctx
, fc_sp
);
5453 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5455 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5457 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5458 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5459 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5460 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5461 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5462 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5463 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5464 alu_type
= CF_OP_ALU
;
5467 emit_logic_pred(ctx
, opcode
, alu_type
);
5469 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5471 fc_pushlevel(ctx
, FC_IF
);
5473 callstack_push(ctx
, FC_PUSH_VPM
);
5477 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5479 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5482 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5484 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5487 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5489 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5490 ctx
->bc
->cf_last
->pop_count
= 1;
5492 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5493 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5497 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5500 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5501 R600_ERR("if/endif unbalanced in shader\n");
5505 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5506 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5507 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5509 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5513 callstack_pop(ctx
, FC_PUSH_VPM
);
5517 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5519 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5520 * limited to 4096 iterations, like the other LOOP_* instructions. */
5521 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5523 fc_pushlevel(ctx
, FC_LOOP
);
5525 /* check stack depth */
5526 callstack_push(ctx
, FC_LOOP
);
5530 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5534 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5536 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5537 R600_ERR("loop/endloop in shader code are not paired.\n");
5541 /* fixup loop pointers - from r600isa
5542 LOOP END points to CF after LOOP START,
5543 LOOP START point to CF after LOOP END
5544 BRK/CONT point to LOOP END CF
5546 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5548 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5550 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5551 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5553 /* XXX add LOOPRET support */
5555 callstack_pop(ctx
, FC_LOOP
);
5559 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5563 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5565 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5570 R600_ERR("Break not inside loop/endloop pair\n");
5574 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5576 fc_set_mid(ctx
, fscp
);
5581 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5583 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5584 struct r600_bytecode_alu alu
;
5586 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5589 for (i
= 0; i
< lasti
+ 1; i
++) {
5590 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5593 if (ctx
->bc
->chip_class
== CAYMAN
) {
5594 for (j
= 0 ; j
< 4; j
++) {
5595 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5597 alu
.op
= ALU_OP2_MULLO_UINT
;
5598 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5599 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5601 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5602 alu
.dst
.sel
= ctx
->temp_reg
;
5603 alu
.dst
.write
= (j
== i
);
5606 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5614 alu
.dst
.sel
= ctx
->temp_reg
;
5617 alu
.op
= ALU_OP2_MULLO_UINT
;
5618 for (j
= 0; j
< 2; j
++) {
5619 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5623 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5630 for (i
= 0; i
< lasti
+ 1; i
++) {
5631 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5634 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5635 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5637 alu
.op
= ALU_OP2_ADD_INT
;
5639 alu
.src
[0].sel
= ctx
->temp_reg
;
5640 alu
.src
[0].chan
= i
;
5642 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5646 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5653 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5654 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5655 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5656 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5659 * For state trackers other than OpenGL, we'll want to use
5660 * _RECIP_IEEE instead.
5662 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5664 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5665 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5666 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5667 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5668 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5669 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5670 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5671 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5672 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5673 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5674 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5675 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5676 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5677 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5678 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5679 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5681 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5682 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5684 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5685 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5686 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5687 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5688 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5689 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5690 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5691 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5692 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5693 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5695 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5696 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5697 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5698 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5699 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5700 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5701 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5702 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5703 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5704 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5705 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5706 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5707 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5708 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5709 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5710 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5711 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5712 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5713 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5714 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5715 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5716 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5717 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5718 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5719 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5720 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5721 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5722 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5723 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5724 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5725 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5726 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5727 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5728 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5729 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5730 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5731 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5732 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5733 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5734 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5735 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5736 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5737 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5738 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5739 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5740 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5741 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5743 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5744 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5745 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5746 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5747 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5748 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5749 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5750 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5751 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
5753 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5754 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5755 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5756 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5757 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5758 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5759 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5760 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5761 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5762 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5763 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5764 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5765 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5766 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5767 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5768 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5770 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5771 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5772 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5773 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5775 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5776 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5777 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5778 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5779 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5780 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5782 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5783 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5784 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5785 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5787 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5788 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
5789 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5790 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5791 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5792 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5793 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5794 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
5795 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5796 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
5797 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5798 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5799 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5800 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5801 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5802 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5803 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5804 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5805 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5806 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5807 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
5808 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5809 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
5810 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5811 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5812 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5813 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5814 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5815 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5816 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5817 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5818 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5819 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5820 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5821 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5822 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5823 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5824 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5825 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5826 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
5827 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5828 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5829 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5830 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5831 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5832 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5833 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5834 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5835 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5836 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5837 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5838 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5839 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5840 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5841 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5842 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5843 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5844 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5845 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5846 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5847 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5848 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5849 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5852 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
5853 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5854 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5855 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5856 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
5857 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
5858 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5859 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5860 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5861 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5862 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5863 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5864 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5865 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5866 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5867 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5868 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5869 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5870 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5871 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5872 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5874 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5875 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5877 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5878 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5879 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5880 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5881 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5882 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5883 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5884 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5885 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5886 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5888 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5889 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5890 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5891 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5892 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5893 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5894 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5895 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5896 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5897 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5898 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5899 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5900 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5901 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5902 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5903 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5904 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5905 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5906 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5907 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5908 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5909 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5910 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5911 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5912 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5913 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5914 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5915 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5916 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5917 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5918 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5919 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5920 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5921 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5922 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5923 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5924 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5925 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5926 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5927 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5928 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5929 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5930 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5931 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5932 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5933 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5934 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5936 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5937 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5938 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5939 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5940 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5941 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5942 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5943 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5944 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
5946 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5947 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5948 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5949 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5950 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5951 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5952 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5953 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5954 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5955 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5956 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5957 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5958 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5959 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5960 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5961 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5963 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5964 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5965 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5966 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5968 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5969 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5970 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5971 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5972 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5973 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5975 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5977 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5978 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5980 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5981 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
5982 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5983 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5984 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5985 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5986 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5987 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
5988 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5989 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
5990 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5991 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5992 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5993 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5994 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5995 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5996 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5997 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5998 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5999 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6000 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6001 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6002 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6003 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6004 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6005 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6006 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6007 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6008 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6009 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6010 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6011 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6012 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6013 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6014 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6015 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6016 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6017 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6018 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6019 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6020 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6021 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6022 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6023 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6024 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6025 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6026 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6027 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6028 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6029 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6030 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6031 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6032 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6033 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6034 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6035 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6036 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6037 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6038 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6039 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6040 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6041 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6042 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6045 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6046 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6047 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6048 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6049 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6050 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6051 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6052 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6053 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6054 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6055 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6056 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6057 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6058 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6059 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6060 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6061 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6062 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6063 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6064 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6065 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6067 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6068 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6070 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6071 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6072 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6073 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6074 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6075 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6076 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6077 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6078 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6079 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6081 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6082 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6083 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6084 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6085 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6086 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6087 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6088 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6089 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6090 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6091 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6092 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6093 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6094 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6095 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6096 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6097 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6098 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6099 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6100 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6101 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6102 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6103 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6104 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6105 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6106 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6107 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6108 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6109 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6110 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6111 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6112 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6113 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6114 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6115 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6116 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6117 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6118 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6119 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6120 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6121 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6122 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6123 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6124 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6125 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6126 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6127 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6129 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6130 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6131 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6132 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6133 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6134 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6135 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6136 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6137 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6139 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6140 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6141 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6142 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6143 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6144 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6145 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6146 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6147 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6148 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6149 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6150 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6151 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6152 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6153 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6154 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6156 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6157 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6158 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6159 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6161 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6162 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6163 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6164 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6165 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6166 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6168 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6170 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6171 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6173 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6174 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6175 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6176 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6177 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6178 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6179 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6180 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6181 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6182 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6183 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6184 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6185 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6186 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6187 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6188 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6189 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6190 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6191 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6192 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6193 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6194 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6195 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6196 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6197 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6198 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6199 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6200 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6201 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6202 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6203 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6204 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6205 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6206 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6207 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6208 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6209 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6210 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6211 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6212 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6213 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6214 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6215 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6216 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6217 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6218 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6219 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6220 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6221 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6222 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6223 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6224 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6225 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6226 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6227 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6228 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6229 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6230 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6231 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6232 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6233 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6234 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6235 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},