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"
38 #include "util/u_math.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
] = util_bswap32(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
);
294 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
296 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
299 if (i
->Instruction
.NumDstRegs
> 1) {
300 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
303 if (i
->Instruction
.Predicate
) {
304 R600_ERR("predicate unsupported\n");
308 if (i
->Instruction
.Label
) {
309 R600_ERR("label unsupported\n");
313 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
314 if (i
->Src
[j
].Register
.Dimension
) {
315 if (i
->Src
[j
].Register
.File
!= TGSI_FILE_CONSTANT
) {
316 R600_ERR("unsupported src %d (dimension %d)\n", j
,
317 i
->Src
[j
].Register
.Dimension
);
322 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
323 if (i
->Dst
[j
].Register
.Dimension
) {
324 R600_ERR("unsupported dst (dimension)\n");
331 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
336 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
337 if (ctx
->shader
->input
[input
].centroid
)
339 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
340 /* if we have perspective add one */
341 if (ctx
->input_perspective
) {
343 /* if we have perspective centroid */
344 if (ctx
->input_centroid
)
347 if (ctx
->shader
->input
[input
].centroid
)
351 ctx
->shader
->input
[input
].ij_index
= ij_index
;
354 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
357 struct r600_bytecode_alu alu
;
358 int gpr
= 0, base_chan
= 0;
359 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
361 /* work out gpr and base_chan from index */
363 base_chan
= (2 * (ij_index
% 2)) + 1;
365 for (i
= 0; i
< 8; i
++) {
366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
369 alu
.op
= ALU_OP2_INTERP_ZW
;
371 alu
.op
= ALU_OP2_INTERP_XY
;
373 if ((i
> 1) && (i
< 6)) {
374 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
378 alu
.dst
.chan
= i
% 4;
380 alu
.src
[0].sel
= gpr
;
381 alu
.src
[0].chan
= (base_chan
- (i
% 2));
383 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
385 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
388 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
395 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
398 struct r600_bytecode_alu alu
;
400 for (i
= 0; i
< 4; i
++) {
401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
403 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
405 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
410 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
415 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
423 * Special export handling in shaders
425 * shader export ARRAY_BASE for EXPORT_POS:
428 * 62, 63 are clip distance vectors
430 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
431 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
432 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
433 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
434 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
435 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
436 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
437 * exclusive from render target index)
438 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
441 * shader export ARRAY_BASE for EXPORT_PIXEL:
443 * 61 computed Z vector
445 * The use of the values exported in the computed Z vector are controlled
446 * by DB_SHADER_CONTROL:
447 * Z_EXPORT_ENABLE - Z as a float in RED
448 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
449 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
450 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
451 * DB_SOURCE_FORMAT - export control restrictions
456 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
457 static int r600_spi_sid(struct r600_shader_io
* io
)
459 int index
, name
= io
->name
;
461 /* These params are handled differently, they don't need
462 * semantic indices, so we'll use 0 for them.
464 if (name
== TGSI_SEMANTIC_POSITION
||
465 name
== TGSI_SEMANTIC_PSIZE
||
466 name
== TGSI_SEMANTIC_FACE
)
469 if (name
== TGSI_SEMANTIC_GENERIC
) {
470 /* For generic params simply use sid from tgsi */
473 /* For non-generic params - pack name and sid into 8 bits */
474 index
= 0x80 | (name
<<3) | (io
->sid
);
477 /* Make sure that all really used indices have nonzero value, so
478 * we can just compare it to 0 later instead of comparing the name
479 * with different values to detect special cases. */
486 /* turn input into interpolate on EG */
487 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
491 if (ctx
->shader
->input
[index
].spi_sid
) {
492 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
493 if (ctx
->shader
->input
[index
].interpolate
> 0) {
494 evergreen_interp_assign_ij_index(ctx
, index
);
496 r
= evergreen_interp_alu(ctx
, index
);
499 r
= evergreen_interp_flat(ctx
, index
);
505 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
507 struct r600_bytecode_alu alu
;
509 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
510 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
512 for (i
= 0; i
< 4; i
++) {
513 memset(&alu
, 0, sizeof(alu
));
514 alu
.op
= ALU_OP3_CNDGT
;
517 alu
.dst
.sel
= gpr_front
;
518 alu
.src
[0].sel
= ctx
->face_gpr
;
519 alu
.src
[1].sel
= gpr_front
;
520 alu
.src
[2].sel
= gpr_back
;
527 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
534 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
536 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
537 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
539 switch (d
->Declaration
.File
) {
540 case TGSI_FILE_INPUT
:
541 i
= ctx
->shader
->ninput
;
542 assert(i
< Elements(ctx
->shader
->input
));
543 ctx
->shader
->ninput
+= count
;
544 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
545 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
546 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
547 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
548 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
549 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
550 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
551 switch (ctx
->shader
->input
[i
].name
) {
552 case TGSI_SEMANTIC_FACE
:
553 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
555 case TGSI_SEMANTIC_COLOR
:
558 case TGSI_SEMANTIC_POSITION
:
559 ctx
->fragcoord_input
= i
;
562 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
563 if ((r
= evergreen_interp_input(ctx
, i
)))
567 for (j
= 1; j
< count
; ++j
) {
568 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
569 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
572 case TGSI_FILE_OUTPUT
:
573 i
= ctx
->shader
->noutput
++;
574 assert(i
< Elements(ctx
->shader
->output
));
575 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
576 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
577 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
578 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
579 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
580 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
) {
581 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
582 switch (d
->Semantic
.Name
) {
583 case TGSI_SEMANTIC_CLIPDIST
:
584 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
586 case TGSI_SEMANTIC_PSIZE
:
587 ctx
->shader
->vs_out_misc_write
= 1;
588 ctx
->shader
->vs_out_point_size
= 1;
590 case TGSI_SEMANTIC_CLIPVERTEX
:
591 ctx
->clip_vertex_write
= TRUE
;
595 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
596 switch (d
->Semantic
.Name
) {
597 case TGSI_SEMANTIC_COLOR
:
598 ctx
->shader
->nr_ps_max_color_exports
++;
603 case TGSI_FILE_TEMPORARY
:
604 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
605 if (d
->Array
.ArrayID
) {
606 r600_add_gpr_array(ctx
->shader
,
607 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
609 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
614 case TGSI_FILE_CONSTANT
:
615 case TGSI_FILE_SAMPLER
:
616 case TGSI_FILE_ADDRESS
:
619 case TGSI_FILE_SYSTEM_VALUE
:
620 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
621 if (!ctx
->native_integers
) {
622 struct r600_bytecode_alu alu
;
623 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
625 alu
.op
= ALU_OP1_INT_TO_FLT
;
634 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
638 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
641 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
647 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
649 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
653 * for evergreen we need to scan the shader to find the number of GPRs we need to
654 * reserve for interpolation.
656 * we need to know if we are going to emit
657 * any centroid inputs
658 * if perspective and linear are required
660 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
665 ctx
->input_linear
= FALSE
;
666 ctx
->input_perspective
= FALSE
;
667 ctx
->input_centroid
= FALSE
;
668 ctx
->num_interp_gpr
= 1;
670 /* any centroid inputs */
671 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
672 /* skip position/face */
673 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
674 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
676 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
677 ctx
->input_linear
= TRUE
;
678 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
679 ctx
->input_perspective
= TRUE
;
680 if (ctx
->info
.input_centroid
[i
])
681 ctx
->input_centroid
= TRUE
;
685 /* ignoring sample for now */
686 if (ctx
->input_perspective
)
688 if (ctx
->input_linear
)
690 if (ctx
->input_centroid
)
693 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
695 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
696 return ctx
->num_interp_gpr
;
699 static void tgsi_src(struct r600_shader_ctx
*ctx
,
700 const struct tgsi_full_src_register
*tgsi_src
,
701 struct r600_shader_src
*r600_src
)
703 memset(r600_src
, 0, sizeof(*r600_src
));
704 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
705 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
706 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
707 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
708 r600_src
->neg
= tgsi_src
->Register
.Negate
;
709 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
711 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
713 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
714 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
715 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
717 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
718 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
719 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
722 index
= tgsi_src
->Register
.Index
;
723 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
724 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
725 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
726 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
727 r600_src
->swizzle
[0] = 3;
728 r600_src
->swizzle
[1] = 3;
729 r600_src
->swizzle
[2] = 3;
730 r600_src
->swizzle
[3] = 3;
732 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
733 r600_src
->swizzle
[0] = 0;
734 r600_src
->swizzle
[1] = 0;
735 r600_src
->swizzle
[2] = 0;
736 r600_src
->swizzle
[3] = 0;
740 if (tgsi_src
->Register
.Indirect
)
741 r600_src
->rel
= V_SQ_REL_RELATIVE
;
742 r600_src
->sel
= tgsi_src
->Register
.Index
;
743 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
745 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
746 if (tgsi_src
->Register
.Dimension
) {
747 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
752 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
754 struct r600_bytecode_vtx vtx
;
759 struct r600_bytecode_alu alu
;
761 memset(&alu
, 0, sizeof(alu
));
763 alu
.op
= ALU_OP2_ADD_INT
;
764 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
766 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
767 alu
.src
[1].value
= offset
;
769 alu
.dst
.sel
= dst_reg
;
773 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
778 ar_reg
= ctx
->bc
->ar_reg
;
781 memset(&vtx
, 0, sizeof(vtx
));
782 vtx
.buffer_id
= cb_idx
;
783 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
784 vtx
.src_gpr
= ar_reg
;
785 vtx
.mega_fetch_count
= 16;
786 vtx
.dst_gpr
= dst_reg
;
787 vtx
.dst_sel_x
= 0; /* SEL_X */
788 vtx
.dst_sel_y
= 1; /* SEL_Y */
789 vtx
.dst_sel_z
= 2; /* SEL_Z */
790 vtx
.dst_sel_w
= 3; /* SEL_W */
791 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
792 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
793 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
794 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
795 vtx
.endian
= r600_endian_swap(32);
797 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
803 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
805 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
806 struct r600_bytecode_alu alu
;
807 int i
, j
, k
, nconst
, r
;
809 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
810 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
813 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
815 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
816 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
820 if (ctx
->src
[i
].rel
) {
821 int treg
= r600_get_temp(ctx
);
822 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
825 ctx
->src
[i
].kc_bank
= 0;
826 ctx
->src
[i
].sel
= treg
;
830 int treg
= r600_get_temp(ctx
);
831 for (k
= 0; k
< 4; k
++) {
832 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
833 alu
.op
= ALU_OP1_MOV
;
834 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
836 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
846 ctx
->src
[i
].sel
= treg
;
854 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
855 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
857 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
858 struct r600_bytecode_alu alu
;
859 int i
, j
, k
, nliteral
, r
;
861 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
862 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
866 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
867 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
868 int treg
= r600_get_temp(ctx
);
869 for (k
= 0; k
< 4; k
++) {
870 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
871 alu
.op
= ALU_OP1_MOV
;
872 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
874 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
880 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
884 ctx
->src
[i
].sel
= treg
;
891 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
893 int i
, r
, count
= ctx
->shader
->ninput
;
895 for (i
= 0; i
< count
; i
++) {
896 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
897 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
906 static int r600_shader_from_tgsi(struct r600_screen
*rscreen
,
907 struct r600_pipe_shader
*pipeshader
,
908 struct r600_shader_key key
)
910 struct r600_shader
*shader
= &pipeshader
->shader
;
911 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
912 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
913 struct tgsi_full_immediate
*immediate
;
914 struct tgsi_full_property
*property
;
915 struct r600_shader_ctx ctx
;
916 struct r600_bytecode_output output
[32];
917 unsigned output_done
, noutput
;
920 int next_pixel_base
= 0, next_pos_base
= 60, next_param_base
= 0;
921 /* Declarations used by llvm code */
922 bool use_llvm
= false;
926 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
928 ctx
.bc
= &shader
->bc
;
930 ctx
.native_integers
= true;
932 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
933 rscreen
->has_compressed_msaa_texturing
);
935 tgsi_scan_shader(tokens
, &ctx
.info
);
936 shader
->indirect_files
= ctx
.info
.indirect_files
;
937 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
938 tgsi_parse_init(&ctx
.parse
, tokens
);
939 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
940 shader
->processor_type
= ctx
.type
;
941 ctx
.bc
->type
= shader
->processor_type
;
944 ctx
.fragcoord_input
= -1;
946 ctx
.clip_vertex_write
= 0;
948 shader
->nr_ps_color_exports
= 0;
949 shader
->nr_ps_max_color_exports
= 0;
951 shader
->two_side
= key
.color_two_side
;
953 /* register allocations */
954 /* Values [0,127] correspond to GPR[0..127].
955 * Values [128,159] correspond to constant buffer bank 0
956 * Values [160,191] correspond to constant buffer bank 1
957 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
958 * Values [256,287] correspond to constant buffer bank 2 (EG)
959 * Values [288,319] correspond to constant buffer bank 3 (EG)
960 * Other special values are shown in the list below.
961 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
962 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
963 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
964 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
965 * 248 SQ_ALU_SRC_0: special constant 0.0.
966 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
967 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
968 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
969 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
970 * 253 SQ_ALU_SRC_LITERAL: literal constant.
971 * 254 SQ_ALU_SRC_PV: previous vector result.
972 * 255 SQ_ALU_SRC_PS: previous scalar result.
974 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
975 ctx
.file_offset
[i
] = 0;
979 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
980 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
981 "indirect adressing. Falling back to TGSI "
986 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
987 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
989 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
992 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
993 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
995 ctx
.use_llvm
= use_llvm
;
998 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
999 ctx
.file_offset
[TGSI_FILE_INPUT
];
1001 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1002 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1003 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1005 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1006 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1008 /* Outside the GPR range. This will be translated to one of the
1009 * kcache banks later. */
1010 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1012 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1013 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1014 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1015 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1017 if (indirect_gprs
) {
1018 shader
->max_arrays
= 0;
1019 shader
->num_arrays
= 0;
1021 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1022 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1023 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1024 ctx
.file_offset
[TGSI_FILE_INPUT
],
1027 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1028 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1029 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1030 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1036 ctx
.literals
= NULL
;
1037 shader
->fs_write_all
= FALSE
;
1038 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1039 tgsi_parse_token(&ctx
.parse
);
1040 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1041 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1042 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1043 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1044 if(ctx
.literals
== NULL
) {
1048 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1049 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1050 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1051 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1054 case TGSI_TOKEN_TYPE_DECLARATION
:
1055 r
= tgsi_declaration(&ctx
);
1059 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1061 case TGSI_TOKEN_TYPE_PROPERTY
:
1062 property
= &ctx
.parse
.FullToken
.FullProperty
;
1063 switch (property
->Property
.PropertyName
) {
1064 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1065 if (property
->u
[0].Data
== 1)
1066 shader
->fs_write_all
= TRUE
;
1068 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1069 /* we don't need this one */
1074 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1080 /* Process two side if needed */
1081 if (shader
->two_side
&& ctx
.colors_used
) {
1082 int i
, count
= ctx
.shader
->ninput
;
1083 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1085 /* additional inputs will be allocated right after the existing inputs,
1086 * we won't need them after the color selection, so we don't need to
1087 * reserve these gprs for the rest of the shader code and to adjust
1088 * output offsets etc. */
1089 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1090 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1092 if (ctx
.face_gpr
== -1) {
1093 i
= ctx
.shader
->ninput
++;
1094 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1095 ctx
.shader
->input
[i
].spi_sid
= 0;
1096 ctx
.shader
->input
[i
].gpr
= gpr
++;
1097 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1100 for (i
= 0; i
< count
; i
++) {
1101 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1102 int ni
= ctx
.shader
->ninput
++;
1103 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1104 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1105 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1106 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1107 // TGSI to LLVM needs to know the lds position of inputs.
1108 // Non LLVM path computes it later (in process_twoside_color)
1109 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1110 ctx
.shader
->input
[i
].back_color_input
= ni
;
1111 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1112 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1119 /* LLVM backend setup */
1120 #ifdef R600_USE_LLVM
1122 struct radeon_llvm_context radeon_llvm_ctx
;
1124 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1125 boolean use_kill
= false;
1127 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1128 radeon_llvm_ctx
.type
= ctx
.type
;
1129 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1130 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1131 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1132 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1133 radeon_llvm_ctx
.color_buffer_count
= MAX2(key
.nr_cbufs
, 1);
1134 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1135 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1136 radeon_llvm_ctx
.stream_outputs
= &so
;
1137 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1138 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1139 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1140 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1142 if (r600_llvm_compile(mod
, rscreen
->family
, ctx
.bc
, &use_kill
, dump
)) {
1143 radeon_llvm_dispose(&radeon_llvm_ctx
);
1145 fprintf(stderr
, "R600 LLVM backend failed to compile "
1146 "shader. Falling back to TGSI\n");
1148 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1149 ctx
.file_offset
[TGSI_FILE_INPUT
];
1152 ctx
.shader
->uses_kill
= use_kill
;
1153 radeon_llvm_dispose(&radeon_llvm_ctx
);
1156 /* End of LLVM backend setup */
1158 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1159 shader
->nr_ps_max_color_exports
= 8;
1162 if (ctx
.fragcoord_input
>= 0) {
1163 if (ctx
.bc
->chip_class
== CAYMAN
) {
1164 for (j
= 0 ; j
< 4; j
++) {
1165 struct r600_bytecode_alu alu
;
1166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1167 alu
.op
= ALU_OP1_RECIP_IEEE
;
1168 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1169 alu
.src
[0].chan
= 3;
1171 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1173 alu
.dst
.write
= (j
== 3);
1175 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1179 struct r600_bytecode_alu alu
;
1180 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1181 alu
.op
= ALU_OP1_RECIP_IEEE
;
1182 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1183 alu
.src
[0].chan
= 3;
1185 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1189 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1194 if (shader
->two_side
&& ctx
.colors_used
) {
1195 if ((r
= process_twoside_color_inputs(&ctx
)))
1199 tgsi_parse_init(&ctx
.parse
, tokens
);
1200 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1201 tgsi_parse_token(&ctx
.parse
);
1202 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1203 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1204 r
= tgsi_is_supported(&ctx
);
1207 ctx
.max_driver_temp_used
= 0;
1208 /* reserve first tmp for everyone */
1209 r600_get_temp(&ctx
);
1211 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1212 if ((r
= tgsi_split_constant(&ctx
)))
1214 if ((r
= tgsi_split_literal_constant(&ctx
)))
1216 if (ctx
.bc
->chip_class
== CAYMAN
)
1217 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1218 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1219 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1221 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1222 r
= ctx
.inst_info
->process(&ctx
);
1232 /* Reset the temporary register counter. */
1233 ctx
.max_driver_temp_used
= 0;
1235 noutput
= shader
->noutput
;
1237 if (ctx
.clip_vertex_write
) {
1238 unsigned clipdist_temp
[2];
1240 clipdist_temp
[0] = r600_get_temp(&ctx
);
1241 clipdist_temp
[1] = r600_get_temp(&ctx
);
1243 /* need to convert a clipvertex write into clipdistance writes and not export
1244 the clip vertex anymore */
1246 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1247 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1248 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1250 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1251 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1254 /* reset spi_sid for clipvertex output to avoid confusing spi */
1255 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1257 shader
->clip_dist_write
= 0xFF;
1259 for (i
= 0; i
< 8; i
++) {
1263 for (j
= 0; j
< 4; j
++) {
1264 struct r600_bytecode_alu alu
;
1265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1266 alu
.op
= ALU_OP2_DOT4
;
1267 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1268 alu
.src
[0].chan
= j
;
1270 alu
.src
[1].sel
= 512 + i
;
1271 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1272 alu
.src
[1].chan
= j
;
1274 alu
.dst
.sel
= clipdist_temp
[oreg
];
1276 alu
.dst
.write
= (j
== ochan
);
1280 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1287 /* Add stream outputs. */
1288 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1289 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1291 /* Sanity checking. */
1292 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1293 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1297 for (i
= 0; i
< so
.num_outputs
; i
++) {
1298 if (so
.output
[i
].output_buffer
>= 4) {
1299 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1300 so
.output
[i
].output_buffer
);
1306 /* Initialize locations where the outputs are stored. */
1307 for (i
= 0; i
< so
.num_outputs
; i
++) {
1308 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1310 /* Lower outputs with dst_offset < start_component.
1312 * We can only output 4D vectors with a write mask, e.g. we can
1313 * only output the W component at offset 3, etc. If we want
1314 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1315 * to move it to X and output X. */
1316 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1317 unsigned tmp
= r600_get_temp(&ctx
);
1319 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1320 struct r600_bytecode_alu alu
;
1321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1322 alu
.op
= ALU_OP1_MOV
;
1323 alu
.src
[0].sel
= so_gpr
[i
];
1324 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1329 if (j
== so
.output
[i
].num_components
- 1)
1331 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1335 so
.output
[i
].start_component
= 0;
1340 /* Write outputs to buffers. */
1341 for (i
= 0; i
< so
.num_outputs
; i
++) {
1342 struct r600_bytecode_output output
;
1344 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1345 output
.gpr
= so_gpr
[i
];
1346 output
.elem_size
= so
.output
[i
].num_components
;
1347 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1348 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1349 output
.burst_count
= 1;
1351 /* array_size is an upper limit for the burst_count
1352 * with MEM_STREAM instructions */
1353 output
.array_size
= 0xFFF;
1354 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1355 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1356 switch (so
.output
[i
].output_buffer
) {
1358 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1361 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1364 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1367 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1371 switch (so
.output
[i
].output_buffer
) {
1373 output
.op
= CF_OP_MEM_STREAM0
;
1376 output
.op
= CF_OP_MEM_STREAM1
;
1379 output
.op
= CF_OP_MEM_STREAM2
;
1382 output
.op
= CF_OP_MEM_STREAM3
;
1386 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1393 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1394 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1395 output
[j
].gpr
= shader
->output
[i
].gpr
;
1396 output
[j
].elem_size
= 3;
1397 output
[j
].swizzle_x
= 0;
1398 output
[j
].swizzle_y
= 1;
1399 output
[j
].swizzle_z
= 2;
1400 output
[j
].swizzle_w
= 3;
1401 output
[j
].burst_count
= 1;
1402 output
[j
].barrier
= 1;
1403 output
[j
].type
= -1;
1404 output
[j
].op
= CF_OP_EXPORT
;
1406 case TGSI_PROCESSOR_VERTEX
:
1407 switch (shader
->output
[i
].name
) {
1408 case TGSI_SEMANTIC_POSITION
:
1409 output
[j
].array_base
= next_pos_base
++;
1410 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1413 case TGSI_SEMANTIC_PSIZE
:
1414 output
[j
].array_base
= next_pos_base
++;
1415 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1417 case TGSI_SEMANTIC_CLIPVERTEX
:
1420 case TGSI_SEMANTIC_CLIPDIST
:
1421 output
[j
].array_base
= next_pos_base
++;
1422 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1423 /* spi_sid is 0 for clipdistance outputs that were generated
1424 * for clipvertex - we don't need to pass them to PS */
1425 if (shader
->output
[i
].spi_sid
) {
1427 /* duplicate it as PARAM to pass to the pixel shader */
1428 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1429 output
[j
].array_base
= next_param_base
++;
1430 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1433 case TGSI_SEMANTIC_FOG
:
1434 output
[j
].swizzle_y
= 4; /* 0 */
1435 output
[j
].swizzle_z
= 4; /* 0 */
1436 output
[j
].swizzle_w
= 5; /* 1 */
1440 case TGSI_PROCESSOR_FRAGMENT
:
1441 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1442 /* never export more colors than the number of CBs */
1443 if (next_pixel_base
&& next_pixel_base
>= key
.nr_cbufs
) {
1448 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1449 output
[j
].array_base
= next_pixel_base
++;
1450 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1451 shader
->nr_ps_color_exports
++;
1452 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1453 for (k
= 1; k
< key
.nr_cbufs
; k
++) {
1455 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1456 output
[j
].gpr
= shader
->output
[i
].gpr
;
1457 output
[j
].elem_size
= 3;
1458 output
[j
].swizzle_x
= 0;
1459 output
[j
].swizzle_y
= 1;
1460 output
[j
].swizzle_z
= 2;
1461 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1462 output
[j
].burst_count
= 1;
1463 output
[j
].barrier
= 1;
1464 output
[j
].array_base
= next_pixel_base
++;
1465 output
[j
].op
= CF_OP_EXPORT
;
1466 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1467 shader
->nr_ps_color_exports
++;
1470 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1471 output
[j
].array_base
= 61;
1472 output
[j
].swizzle_x
= 2;
1473 output
[j
].swizzle_y
= 7;
1474 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1475 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1476 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1477 output
[j
].array_base
= 61;
1478 output
[j
].swizzle_x
= 7;
1479 output
[j
].swizzle_y
= 1;
1480 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1481 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1483 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1489 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1494 if (output
[j
].type
==-1) {
1495 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1496 output
[j
].array_base
= next_param_base
++;
1500 /* add fake position export */
1501 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1502 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1504 output
[j
].elem_size
= 3;
1505 output
[j
].swizzle_x
= 7;
1506 output
[j
].swizzle_y
= 7;
1507 output
[j
].swizzle_z
= 7;
1508 output
[j
].swizzle_w
= 7;
1509 output
[j
].burst_count
= 1;
1510 output
[j
].barrier
= 1;
1511 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1512 output
[j
].array_base
= next_pos_base
;
1513 output
[j
].op
= CF_OP_EXPORT
;
1517 /* add fake param output for vertex shader if no param is exported */
1518 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1519 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1521 output
[j
].elem_size
= 3;
1522 output
[j
].swizzle_x
= 7;
1523 output
[j
].swizzle_y
= 7;
1524 output
[j
].swizzle_z
= 7;
1525 output
[j
].swizzle_w
= 7;
1526 output
[j
].burst_count
= 1;
1527 output
[j
].barrier
= 1;
1528 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1529 output
[j
].array_base
= 0;
1530 output
[j
].op
= CF_OP_EXPORT
;
1534 /* add fake pixel export */
1535 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& next_pixel_base
== 0) {
1536 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1538 output
[j
].elem_size
= 3;
1539 output
[j
].swizzle_x
= 7;
1540 output
[j
].swizzle_y
= 7;
1541 output
[j
].swizzle_z
= 7;
1542 output
[j
].swizzle_w
= 7;
1543 output
[j
].burst_count
= 1;
1544 output
[j
].barrier
= 1;
1545 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1546 output
[j
].array_base
= 0;
1547 output
[j
].op
= CF_OP_EXPORT
;
1553 /* set export done on last export of each type */
1554 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1555 if (ctx
.bc
->chip_class
< CAYMAN
) {
1556 if (i
== (noutput
- 1)) {
1557 output
[i
].end_of_program
= 1;
1560 if (!(output_done
& (1 << output
[i
].type
))) {
1561 output_done
|= (1 << output
[i
].type
);
1562 output
[i
].op
= CF_OP_EXPORT_DONE
;
1565 /* add output to bytecode */
1567 for (i
= 0; i
< noutput
; i
++) {
1568 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1573 /* add program end */
1574 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1575 cm_bytecode_add_cf_end(ctx
.bc
);
1577 /* check GPR limit - we have 124 = 128 - 4
1578 * (4 are reserved as alu clause temporary registers) */
1579 if (ctx
.bc
->ngpr
> 124) {
1580 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1586 tgsi_parse_free(&ctx
.parse
);
1590 tgsi_parse_free(&ctx
.parse
);
1594 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1596 R600_ERR("%s tgsi opcode unsupported\n",
1597 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1601 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1606 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1607 const struct r600_shader_src
*shader_src
,
1610 bc_src
->sel
= shader_src
->sel
;
1611 bc_src
->chan
= shader_src
->swizzle
[chan
];
1612 bc_src
->neg
= shader_src
->neg
;
1613 bc_src
->abs
= shader_src
->abs
;
1614 bc_src
->rel
= shader_src
->rel
;
1615 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1616 bc_src
->kc_bank
= shader_src
->kc_bank
;
1619 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1625 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1627 bc_src
->neg
= !bc_src
->neg
;
1630 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1631 const struct tgsi_full_dst_register
*tgsi_dst
,
1633 struct r600_bytecode_alu_dst
*r600_dst
)
1635 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1637 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1638 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1639 r600_dst
->chan
= swizzle
;
1640 r600_dst
->write
= 1;
1641 if (tgsi_dst
->Register
.Indirect
)
1642 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1643 if (inst
->Instruction
.Saturate
) {
1644 r600_dst
->clamp
= 1;
1648 static int tgsi_last_instruction(unsigned writemask
)
1652 for (i
= 0; i
< 4; i
++) {
1653 if (writemask
& (1 << i
)) {
1660 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1662 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1663 struct r600_bytecode_alu alu
;
1665 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1667 for (i
= 0; i
< lasti
+ 1; i
++) {
1668 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1671 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1672 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1674 alu
.op
= ctx
->inst_info
->op
;
1676 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1677 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
1680 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
1681 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1683 /* handle some special cases */
1684 switch (ctx
->inst_info
->tgsi_opcode
) {
1685 case TGSI_OPCODE_SUB
:
1686 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
1688 case TGSI_OPCODE_ABS
:
1689 r600_bytecode_src_set_abs(&alu
.src
[0]);
1694 if (i
== lasti
|| trans_only
) {
1697 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1704 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
1706 return tgsi_op2_s(ctx
, 0, 0);
1709 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
1711 return tgsi_op2_s(ctx
, 1, 0);
1714 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
1716 return tgsi_op2_s(ctx
, 0, 1);
1719 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
1721 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1722 struct r600_bytecode_alu alu
;
1724 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1726 for (i
= 0; i
< lasti
+ 1; i
++) {
1728 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1730 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1731 alu
.op
= ctx
->inst_info
->op
;
1733 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1735 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1737 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1742 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1750 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
1752 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1754 struct r600_bytecode_alu alu
;
1755 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1757 for (i
= 0 ; i
< last_slot
; i
++) {
1758 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1759 alu
.op
= ctx
->inst_info
->op
;
1760 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1761 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
1763 /* RSQ should take the absolute value of src */
1764 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
1765 r600_bytecode_src_set_abs(&alu
.src
[j
]);
1768 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1769 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1771 if (i
== last_slot
- 1)
1773 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1780 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
1782 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1784 struct r600_bytecode_alu alu
;
1785 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1786 for (k
= 0; k
< last_slot
; k
++) {
1787 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
1790 for (i
= 0 ; i
< 4; i
++) {
1791 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1792 alu
.op
= ctx
->inst_info
->op
;
1793 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1794 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
1796 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1797 alu
.dst
.write
= (i
== k
);
1800 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1809 * r600 - trunc to -PI..PI range
1810 * r700 - normalize by dividing by 2PI
1813 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
1815 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
1816 static float double_pi
= 3.1415926535 * 2;
1817 static float neg_pi
= -3.1415926535;
1820 struct r600_bytecode_alu alu
;
1822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1823 alu
.op
= ALU_OP3_MULADD
;
1827 alu
.dst
.sel
= ctx
->temp_reg
;
1830 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
1832 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1833 alu
.src
[1].chan
= 0;
1834 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
1835 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1836 alu
.src
[2].chan
= 0;
1838 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1842 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1843 alu
.op
= ALU_OP1_FRACT
;
1846 alu
.dst
.sel
= ctx
->temp_reg
;
1849 alu
.src
[0].sel
= ctx
->temp_reg
;
1850 alu
.src
[0].chan
= 0;
1852 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1857 alu
.op
= ALU_OP3_MULADD
;
1861 alu
.dst
.sel
= ctx
->temp_reg
;
1864 alu
.src
[0].sel
= ctx
->temp_reg
;
1865 alu
.src
[0].chan
= 0;
1867 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1868 alu
.src
[1].chan
= 0;
1869 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
1870 alu
.src
[2].chan
= 0;
1872 if (ctx
->bc
->chip_class
== R600
) {
1873 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
1874 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
1876 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
1877 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1882 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1888 static int cayman_trig(struct r600_shader_ctx
*ctx
)
1890 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1891 struct r600_bytecode_alu alu
;
1892 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1895 r
= tgsi_setup_trig(ctx
);
1900 for (i
= 0; i
< last_slot
; i
++) {
1901 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1902 alu
.op
= ctx
->inst_info
->op
;
1905 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1906 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1908 alu
.src
[0].sel
= ctx
->temp_reg
;
1909 alu
.src
[0].chan
= 0;
1910 if (i
== last_slot
- 1)
1912 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1919 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
1921 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1922 struct r600_bytecode_alu alu
;
1924 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1926 r
= tgsi_setup_trig(ctx
);
1930 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1931 alu
.op
= ctx
->inst_info
->op
;
1933 alu
.dst
.sel
= ctx
->temp_reg
;
1936 alu
.src
[0].sel
= ctx
->temp_reg
;
1937 alu
.src
[0].chan
= 0;
1939 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1943 /* replicate result */
1944 for (i
= 0; i
< lasti
+ 1; i
++) {
1945 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1948 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1949 alu
.op
= ALU_OP1_MOV
;
1951 alu
.src
[0].sel
= ctx
->temp_reg
;
1952 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1962 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
1964 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1965 struct r600_bytecode_alu alu
;
1968 /* We'll only need the trig stuff if we are going to write to the
1969 * X or Y components of the destination vector.
1971 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
1972 r
= tgsi_setup_trig(ctx
);
1978 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
1979 if (ctx
->bc
->chip_class
== CAYMAN
) {
1980 for (i
= 0 ; i
< 3; i
++) {
1981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1982 alu
.op
= ALU_OP1_COS
;
1983 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1989 alu
.src
[0].sel
= ctx
->temp_reg
;
1990 alu
.src
[0].chan
= 0;
1993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1999 alu
.op
= ALU_OP1_COS
;
2000 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2002 alu
.src
[0].sel
= ctx
->temp_reg
;
2003 alu
.src
[0].chan
= 0;
2005 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2012 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2013 if (ctx
->bc
->chip_class
== CAYMAN
) {
2014 for (i
= 0 ; i
< 3; i
++) {
2015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2016 alu
.op
= ALU_OP1_SIN
;
2017 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2022 alu
.src
[0].sel
= ctx
->temp_reg
;
2023 alu
.src
[0].chan
= 0;
2026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2031 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2032 alu
.op
= ALU_OP1_SIN
;
2033 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2035 alu
.src
[0].sel
= ctx
->temp_reg
;
2036 alu
.src
[0].chan
= 0;
2038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2045 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2048 alu
.op
= ALU_OP1_MOV
;
2050 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2052 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2053 alu
.src
[0].chan
= 0;
2057 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2063 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2066 alu
.op
= ALU_OP1_MOV
;
2068 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2070 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2071 alu
.src
[0].chan
= 0;
2075 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2083 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2085 struct r600_bytecode_alu alu
;
2088 for (i
= 0; i
< 4; i
++) {
2089 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2090 alu
.op
= ctx
->inst_info
->op
;
2094 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2096 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILP
) {
2097 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2100 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2105 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2110 /* kill must be last in ALU */
2111 ctx
->bc
->force_add_cf
= 1;
2112 ctx
->shader
->uses_kill
= TRUE
;
2116 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2118 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2119 struct r600_bytecode_alu alu
;
2122 /* tmp.x = max(src.y, 0.0) */
2123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2124 alu
.op
= ALU_OP2_MAX
;
2125 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2126 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2127 alu
.src
[1].chan
= 1;
2129 alu
.dst
.sel
= ctx
->temp_reg
;
2134 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2138 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2144 if (ctx
->bc
->chip_class
== CAYMAN
) {
2145 for (i
= 0; i
< 3; i
++) {
2146 /* tmp.z = log(tmp.x) */
2147 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2148 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2149 alu
.src
[0].sel
= ctx
->temp_reg
;
2150 alu
.src
[0].chan
= 0;
2151 alu
.dst
.sel
= ctx
->temp_reg
;
2159 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2164 /* tmp.z = log(tmp.x) */
2165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2166 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2167 alu
.src
[0].sel
= ctx
->temp_reg
;
2168 alu
.src
[0].chan
= 0;
2169 alu
.dst
.sel
= ctx
->temp_reg
;
2173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2178 chan
= alu
.dst
.chan
;
2181 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2182 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2183 alu
.op
= ALU_OP3_MUL_LIT
;
2184 alu
.src
[0].sel
= sel
;
2185 alu
.src
[0].chan
= chan
;
2186 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2187 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2188 alu
.dst
.sel
= ctx
->temp_reg
;
2193 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2197 if (ctx
->bc
->chip_class
== CAYMAN
) {
2198 for (i
= 0; i
< 3; i
++) {
2199 /* dst.z = exp(tmp.x) */
2200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2201 alu
.op
= ALU_OP1_EXP_IEEE
;
2202 alu
.src
[0].sel
= ctx
->temp_reg
;
2203 alu
.src
[0].chan
= 0;
2204 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2210 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2215 /* dst.z = exp(tmp.x) */
2216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2217 alu
.op
= ALU_OP1_EXP_IEEE
;
2218 alu
.src
[0].sel
= ctx
->temp_reg
;
2219 alu
.src
[0].chan
= 0;
2220 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2230 alu
.op
= ALU_OP1_MOV
;
2231 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2232 alu
.src
[0].chan
= 0;
2233 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2234 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2235 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2239 /* dst.y = max(src.x, 0.0) */
2240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2241 alu
.op
= ALU_OP2_MAX
;
2242 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2243 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2244 alu
.src
[1].chan
= 0;
2245 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2246 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2247 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2253 alu
.op
= ALU_OP1_MOV
;
2254 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2255 alu
.src
[0].chan
= 0;
2256 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2257 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2259 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2266 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2268 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2269 struct r600_bytecode_alu alu
;
2272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2275 * For state trackers other than OpenGL, we'll want to use
2276 * _RECIPSQRT_IEEE instead.
2278 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2280 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2281 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2282 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2284 alu
.dst
.sel
= ctx
->temp_reg
;
2287 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2290 /* replicate result */
2291 return tgsi_helper_tempx_replicate(ctx
);
2294 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2296 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2297 struct r600_bytecode_alu alu
;
2300 for (i
= 0; i
< 4; i
++) {
2301 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2302 alu
.src
[0].sel
= ctx
->temp_reg
;
2303 alu
.op
= ALU_OP1_MOV
;
2305 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2306 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2309 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2316 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2318 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2319 struct r600_bytecode_alu alu
;
2322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2323 alu
.op
= ctx
->inst_info
->op
;
2324 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2325 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2327 alu
.dst
.sel
= ctx
->temp_reg
;
2330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2333 /* replicate result */
2334 return tgsi_helper_tempx_replicate(ctx
);
2337 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2339 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2341 struct r600_bytecode_alu alu
;
2342 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2344 for (i
= 0; i
< 3; i
++) {
2345 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2346 alu
.op
= ALU_OP1_LOG_IEEE
;
2347 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2348 alu
.dst
.sel
= ctx
->temp_reg
;
2353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2359 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2360 alu
.op
= ALU_OP2_MUL
;
2361 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2362 alu
.src
[1].sel
= ctx
->temp_reg
;
2363 alu
.dst
.sel
= ctx
->temp_reg
;
2366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2370 for (i
= 0; i
< last_slot
; i
++) {
2371 /* POW(a,b) = EXP2(b * LOG2(a))*/
2372 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2373 alu
.op
= ALU_OP1_EXP_IEEE
;
2374 alu
.src
[0].sel
= ctx
->temp_reg
;
2376 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2377 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2378 if (i
== last_slot
- 1)
2380 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2387 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2389 struct r600_bytecode_alu alu
;
2393 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2394 alu
.op
= ALU_OP1_LOG_IEEE
;
2395 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2396 alu
.dst
.sel
= ctx
->temp_reg
;
2399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2404 alu
.op
= ALU_OP2_MUL
;
2405 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2406 alu
.src
[1].sel
= ctx
->temp_reg
;
2407 alu
.dst
.sel
= ctx
->temp_reg
;
2410 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2413 /* POW(a,b) = EXP2(b * LOG2(a))*/
2414 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2415 alu
.op
= ALU_OP1_EXP_IEEE
;
2416 alu
.src
[0].sel
= ctx
->temp_reg
;
2417 alu
.dst
.sel
= ctx
->temp_reg
;
2420 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2423 return tgsi_helper_tempx_replicate(ctx
);
2426 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2428 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2429 struct r600_bytecode_alu alu
;
2431 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2432 int tmp0
= ctx
->temp_reg
;
2433 int tmp1
= r600_get_temp(ctx
);
2434 int tmp2
= r600_get_temp(ctx
);
2435 int tmp3
= r600_get_temp(ctx
);
2438 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2440 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2441 * 2. tmp0.z = lo (tmp0.x * src2)
2442 * 3. tmp0.w = -tmp0.z
2443 * 4. tmp0.y = hi (tmp0.x * src2)
2444 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2445 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2446 * 7. tmp1.x = tmp0.x - tmp0.w
2447 * 8. tmp1.y = tmp0.x + tmp0.w
2448 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2449 * 10. tmp0.z = hi(tmp0.x * src1) = q
2450 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2452 * 12. tmp0.w = src1 - tmp0.y = r
2453 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2454 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2458 * 15. tmp1.z = tmp0.z + 1 = q + 1
2459 * 16. tmp1.w = tmp0.z - 1 = q - 1
2463 * 15. tmp1.z = tmp0.w - src2 = r - src2
2464 * 16. tmp1.w = tmp0.w + src2 = r + src2
2468 * 17. tmp1.x = tmp1.x & tmp1.y
2470 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2471 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2473 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2474 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2478 * Same as unsigned, using abs values of the operands,
2479 * and fixing the sign of the result in the end.
2482 for (i
= 0; i
< 4; i
++) {
2483 if (!(write_mask
& (1<<i
)))
2488 /* tmp2.x = -src0 */
2489 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2490 alu
.op
= ALU_OP2_SUB_INT
;
2496 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2498 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2501 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2504 /* tmp2.y = -src1 */
2505 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2506 alu
.op
= ALU_OP2_SUB_INT
;
2512 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2514 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2517 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2520 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2521 /* it will be a sign of the quotient */
2524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2525 alu
.op
= ALU_OP2_XOR_INT
;
2531 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2532 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2535 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2539 /* tmp2.x = |src0| */
2540 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2541 alu
.op
= ALU_OP3_CNDGE_INT
;
2548 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2549 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2550 alu
.src
[2].sel
= tmp2
;
2551 alu
.src
[2].chan
= 0;
2554 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2557 /* tmp2.y = |src1| */
2558 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2559 alu
.op
= ALU_OP3_CNDGE_INT
;
2566 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2567 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2568 alu
.src
[2].sel
= tmp2
;
2569 alu
.src
[2].chan
= 1;
2572 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2577 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2578 if (ctx
->bc
->chip_class
== CAYMAN
) {
2579 /* tmp3.x = u2f(src2) */
2580 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2581 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2588 alu
.src
[0].sel
= tmp2
;
2589 alu
.src
[0].chan
= 1;
2591 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2595 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2598 /* tmp0.x = recip(tmp3.x) */
2599 for (j
= 0 ; j
< 3; j
++) {
2600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2601 alu
.op
= ALU_OP1_RECIP_IEEE
;
2605 alu
.dst
.write
= (j
== 0);
2607 alu
.src
[0].sel
= tmp3
;
2608 alu
.src
[0].chan
= 0;
2612 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2617 alu
.op
= ALU_OP2_MUL
;
2619 alu
.src
[0].sel
= tmp0
;
2620 alu
.src
[0].chan
= 0;
2622 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2623 alu
.src
[1].value
= 0x4f800000;
2628 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2633 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2639 alu
.src
[0].sel
= tmp3
;
2640 alu
.src
[0].chan
= 0;
2643 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2648 alu
.op
= ALU_OP1_RECIP_UINT
;
2655 alu
.src
[0].sel
= tmp2
;
2656 alu
.src
[0].chan
= 1;
2658 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2662 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2666 /* 2. tmp0.z = lo (tmp0.x * src2) */
2667 if (ctx
->bc
->chip_class
== CAYMAN
) {
2668 for (j
= 0 ; j
< 4; j
++) {
2669 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2670 alu
.op
= ALU_OP2_MULLO_UINT
;
2674 alu
.dst
.write
= (j
== 2);
2676 alu
.src
[0].sel
= tmp0
;
2677 alu
.src
[0].chan
= 0;
2679 alu
.src
[1].sel
= tmp2
;
2680 alu
.src
[1].chan
= 1;
2682 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2685 alu
.last
= (j
== 3);
2686 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2690 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2691 alu
.op
= ALU_OP2_MULLO_UINT
;
2697 alu
.src
[0].sel
= tmp0
;
2698 alu
.src
[0].chan
= 0;
2700 alu
.src
[1].sel
= tmp2
;
2701 alu
.src
[1].chan
= 1;
2703 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2707 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2711 /* 3. tmp0.w = -tmp0.z */
2712 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2713 alu
.op
= ALU_OP2_SUB_INT
;
2719 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2720 alu
.src
[1].sel
= tmp0
;
2721 alu
.src
[1].chan
= 2;
2724 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2727 /* 4. tmp0.y = hi (tmp0.x * src2) */
2728 if (ctx
->bc
->chip_class
== CAYMAN
) {
2729 for (j
= 0 ; j
< 4; j
++) {
2730 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2731 alu
.op
= ALU_OP2_MULHI_UINT
;
2735 alu
.dst
.write
= (j
== 1);
2737 alu
.src
[0].sel
= tmp0
;
2738 alu
.src
[0].chan
= 0;
2741 alu
.src
[1].sel
= tmp2
;
2742 alu
.src
[1].chan
= 1;
2744 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2746 alu
.last
= (j
== 3);
2747 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2751 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2752 alu
.op
= ALU_OP2_MULHI_UINT
;
2758 alu
.src
[0].sel
= tmp0
;
2759 alu
.src
[0].chan
= 0;
2762 alu
.src
[1].sel
= tmp2
;
2763 alu
.src
[1].chan
= 1;
2765 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2769 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2773 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
2774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2775 alu
.op
= ALU_OP3_CNDE_INT
;
2782 alu
.src
[0].sel
= tmp0
;
2783 alu
.src
[0].chan
= 1;
2784 alu
.src
[1].sel
= tmp0
;
2785 alu
.src
[1].chan
= 3;
2786 alu
.src
[2].sel
= tmp0
;
2787 alu
.src
[2].chan
= 2;
2790 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2793 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
2794 if (ctx
->bc
->chip_class
== CAYMAN
) {
2795 for (j
= 0 ; j
< 4; j
++) {
2796 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2797 alu
.op
= ALU_OP2_MULHI_UINT
;
2801 alu
.dst
.write
= (j
== 3);
2803 alu
.src
[0].sel
= tmp0
;
2804 alu
.src
[0].chan
= 2;
2806 alu
.src
[1].sel
= tmp0
;
2807 alu
.src
[1].chan
= 0;
2809 alu
.last
= (j
== 3);
2810 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2815 alu
.op
= ALU_OP2_MULHI_UINT
;
2821 alu
.src
[0].sel
= tmp0
;
2822 alu
.src
[0].chan
= 2;
2824 alu
.src
[1].sel
= tmp0
;
2825 alu
.src
[1].chan
= 0;
2828 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2832 /* 7. tmp1.x = tmp0.x - tmp0.w */
2833 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2834 alu
.op
= ALU_OP2_SUB_INT
;
2840 alu
.src
[0].sel
= tmp0
;
2841 alu
.src
[0].chan
= 0;
2842 alu
.src
[1].sel
= tmp0
;
2843 alu
.src
[1].chan
= 3;
2846 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2849 /* 8. tmp1.y = tmp0.x + tmp0.w */
2850 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2851 alu
.op
= ALU_OP2_ADD_INT
;
2857 alu
.src
[0].sel
= tmp0
;
2858 alu
.src
[0].chan
= 0;
2859 alu
.src
[1].sel
= tmp0
;
2860 alu
.src
[1].chan
= 3;
2863 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2866 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
2867 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2868 alu
.op
= ALU_OP3_CNDE_INT
;
2875 alu
.src
[0].sel
= tmp0
;
2876 alu
.src
[0].chan
= 1;
2877 alu
.src
[1].sel
= tmp1
;
2878 alu
.src
[1].chan
= 1;
2879 alu
.src
[2].sel
= tmp1
;
2880 alu
.src
[2].chan
= 0;
2883 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2886 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
2887 if (ctx
->bc
->chip_class
== CAYMAN
) {
2888 for (j
= 0 ; j
< 4; j
++) {
2889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2890 alu
.op
= ALU_OP2_MULHI_UINT
;
2894 alu
.dst
.write
= (j
== 2);
2896 alu
.src
[0].sel
= tmp0
;
2897 alu
.src
[0].chan
= 0;
2900 alu
.src
[1].sel
= tmp2
;
2901 alu
.src
[1].chan
= 0;
2903 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2906 alu
.last
= (j
== 3);
2907 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2912 alu
.op
= ALU_OP2_MULHI_UINT
;
2918 alu
.src
[0].sel
= tmp0
;
2919 alu
.src
[0].chan
= 0;
2922 alu
.src
[1].sel
= tmp2
;
2923 alu
.src
[1].chan
= 0;
2925 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2929 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2933 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
2934 if (ctx
->bc
->chip_class
== CAYMAN
) {
2935 for (j
= 0 ; j
< 4; j
++) {
2936 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2937 alu
.op
= ALU_OP2_MULLO_UINT
;
2941 alu
.dst
.write
= (j
== 1);
2944 alu
.src
[0].sel
= tmp2
;
2945 alu
.src
[0].chan
= 1;
2947 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2950 alu
.src
[1].sel
= tmp0
;
2951 alu
.src
[1].chan
= 2;
2953 alu
.last
= (j
== 3);
2954 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2958 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2959 alu
.op
= ALU_OP2_MULLO_UINT
;
2966 alu
.src
[0].sel
= tmp2
;
2967 alu
.src
[0].chan
= 1;
2969 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2972 alu
.src
[1].sel
= tmp0
;
2973 alu
.src
[1].chan
= 2;
2976 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2980 /* 12. tmp0.w = src1 - tmp0.y = r */
2981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2982 alu
.op
= ALU_OP2_SUB_INT
;
2989 alu
.src
[0].sel
= tmp2
;
2990 alu
.src
[0].chan
= 0;
2992 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2995 alu
.src
[1].sel
= tmp0
;
2996 alu
.src
[1].chan
= 1;
2999 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3002 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3004 alu
.op
= ALU_OP2_SETGE_UINT
;
3010 alu
.src
[0].sel
= tmp0
;
3011 alu
.src
[0].chan
= 3;
3013 alu
.src
[1].sel
= tmp2
;
3014 alu
.src
[1].chan
= 1;
3016 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3020 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3023 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3025 alu
.op
= ALU_OP2_SETGE_UINT
;
3032 alu
.src
[0].sel
= tmp2
;
3033 alu
.src
[0].chan
= 0;
3035 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3038 alu
.src
[1].sel
= tmp0
;
3039 alu
.src
[1].chan
= 1;
3042 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3045 if (mod
) { /* UMOD */
3047 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3048 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3049 alu
.op
= ALU_OP2_SUB_INT
;
3055 alu
.src
[0].sel
= tmp0
;
3056 alu
.src
[0].chan
= 3;
3059 alu
.src
[1].sel
= tmp2
;
3060 alu
.src
[1].chan
= 1;
3062 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3066 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3069 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3070 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3071 alu
.op
= ALU_OP2_ADD_INT
;
3077 alu
.src
[0].sel
= tmp0
;
3078 alu
.src
[0].chan
= 3;
3080 alu
.src
[1].sel
= tmp2
;
3081 alu
.src
[1].chan
= 1;
3083 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3087 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3092 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3094 alu
.op
= ALU_OP2_ADD_INT
;
3100 alu
.src
[0].sel
= tmp0
;
3101 alu
.src
[0].chan
= 2;
3102 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3105 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3108 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3109 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3110 alu
.op
= ALU_OP2_ADD_INT
;
3116 alu
.src
[0].sel
= tmp0
;
3117 alu
.src
[0].chan
= 2;
3118 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3121 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3126 /* 17. tmp1.x = tmp1.x & tmp1.y */
3127 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3128 alu
.op
= ALU_OP2_AND_INT
;
3134 alu
.src
[0].sel
= tmp1
;
3135 alu
.src
[0].chan
= 0;
3136 alu
.src
[1].sel
= tmp1
;
3137 alu
.src
[1].chan
= 1;
3140 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3143 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3144 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3146 alu
.op
= ALU_OP3_CNDE_INT
;
3153 alu
.src
[0].sel
= tmp1
;
3154 alu
.src
[0].chan
= 0;
3155 alu
.src
[1].sel
= tmp0
;
3156 alu
.src
[1].chan
= mod
? 3 : 2;
3157 alu
.src
[2].sel
= tmp1
;
3158 alu
.src
[2].chan
= 2;
3161 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3164 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3166 alu
.op
= ALU_OP3_CNDE_INT
;
3174 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3177 alu
.src
[0].sel
= tmp1
;
3178 alu
.src
[0].chan
= 1;
3179 alu
.src
[1].sel
= tmp1
;
3180 alu
.src
[1].chan
= 3;
3181 alu
.src
[2].sel
= tmp0
;
3182 alu
.src
[2].chan
= 2;
3185 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3190 /* fix the sign of the result */
3194 /* tmp0.x = -tmp0.z */
3195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3196 alu
.op
= ALU_OP2_SUB_INT
;
3202 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3203 alu
.src
[1].sel
= tmp0
;
3204 alu
.src
[1].chan
= 2;
3207 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3210 /* sign of the remainder is the same as the sign of src0 */
3211 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3212 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3213 alu
.op
= ALU_OP3_CNDGE_INT
;
3216 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3218 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3219 alu
.src
[1].sel
= tmp0
;
3220 alu
.src
[1].chan
= 2;
3221 alu
.src
[2].sel
= tmp0
;
3222 alu
.src
[2].chan
= 0;
3225 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3230 /* tmp0.x = -tmp0.z */
3231 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3232 alu
.op
= ALU_OP2_SUB_INT
;
3238 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3239 alu
.src
[1].sel
= tmp0
;
3240 alu
.src
[1].chan
= 2;
3243 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3246 /* fix the quotient sign (same as the sign of src0*src1) */
3247 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3248 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3249 alu
.op
= ALU_OP3_CNDGE_INT
;
3252 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3254 alu
.src
[0].sel
= tmp2
;
3255 alu
.src
[0].chan
= 2;
3256 alu
.src
[1].sel
= tmp0
;
3257 alu
.src
[1].chan
= 2;
3258 alu
.src
[2].sel
= tmp0
;
3259 alu
.src
[2].chan
= 0;
3262 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3270 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3272 return tgsi_divmod(ctx
, 0, 0);
3275 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3277 return tgsi_divmod(ctx
, 1, 0);
3280 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3282 return tgsi_divmod(ctx
, 0, 1);
3285 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3287 return tgsi_divmod(ctx
, 1, 1);
3291 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3293 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3294 struct r600_bytecode_alu alu
;
3296 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3297 int last_inst
= tgsi_last_instruction(write_mask
);
3299 for (i
= 0; i
< 4; i
++) {
3300 if (!(write_mask
& (1<<i
)))
3303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3304 alu
.op
= ALU_OP1_TRUNC
;
3306 alu
.dst
.sel
= ctx
->temp_reg
;
3310 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3313 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3318 for (i
= 0; i
< 4; i
++) {
3319 if (!(write_mask
& (1<<i
)))
3322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3323 alu
.op
= ctx
->inst_info
->op
;
3325 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3327 alu
.src
[0].sel
= ctx
->temp_reg
;
3328 alu
.src
[0].chan
= i
;
3330 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3332 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3340 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3342 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3343 struct r600_bytecode_alu alu
;
3345 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3346 int last_inst
= tgsi_last_instruction(write_mask
);
3349 for (i
= 0; i
< 4; i
++) {
3350 if (!(write_mask
& (1<<i
)))
3353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3354 alu
.op
= ALU_OP2_SUB_INT
;
3356 alu
.dst
.sel
= ctx
->temp_reg
;
3360 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3361 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3370 /* dst = (src >= 0 ? src : tmp) */
3371 for (i
= 0; i
< 4; i
++) {
3372 if (!(write_mask
& (1<<i
)))
3375 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3376 alu
.op
= ALU_OP3_CNDGE_INT
;
3380 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3382 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3383 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3384 alu
.src
[2].sel
= ctx
->temp_reg
;
3385 alu
.src
[2].chan
= i
;
3389 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3396 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3398 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3399 struct r600_bytecode_alu alu
;
3401 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3402 int last_inst
= tgsi_last_instruction(write_mask
);
3404 /* tmp = (src >= 0 ? src : -1) */
3405 for (i
= 0; i
< 4; i
++) {
3406 if (!(write_mask
& (1<<i
)))
3409 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3410 alu
.op
= ALU_OP3_CNDGE_INT
;
3413 alu
.dst
.sel
= ctx
->temp_reg
;
3417 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3418 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3419 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3423 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3428 /* dst = (tmp > 0 ? 1 : tmp) */
3429 for (i
= 0; i
< 4; i
++) {
3430 if (!(write_mask
& (1<<i
)))
3433 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3434 alu
.op
= ALU_OP3_CNDGT_INT
;
3438 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3440 alu
.src
[0].sel
= ctx
->temp_reg
;
3441 alu
.src
[0].chan
= i
;
3443 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3445 alu
.src
[2].sel
= ctx
->temp_reg
;
3446 alu
.src
[2].chan
= i
;
3450 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3459 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3461 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3462 struct r600_bytecode_alu alu
;
3465 /* tmp = (src > 0 ? 1 : src) */
3466 for (i
= 0; i
< 4; i
++) {
3467 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3468 alu
.op
= ALU_OP3_CNDGT
;
3471 alu
.dst
.sel
= ctx
->temp_reg
;
3474 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3475 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3476 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3480 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3485 /* dst = (-tmp > 0 ? -1 : tmp) */
3486 for (i
= 0; i
< 4; i
++) {
3487 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3488 alu
.op
= ALU_OP3_CNDGT
;
3490 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3492 alu
.src
[0].sel
= ctx
->temp_reg
;
3493 alu
.src
[0].chan
= i
;
3496 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3499 alu
.src
[2].sel
= ctx
->temp_reg
;
3500 alu
.src
[2].chan
= i
;
3504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3511 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3513 struct r600_bytecode_alu alu
;
3516 for (i
= 0; i
< 4; i
++) {
3517 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3518 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3519 alu
.op
= ALU_OP0_NOP
;
3522 alu
.op
= ALU_OP1_MOV
;
3523 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3524 alu
.src
[0].sel
= ctx
->temp_reg
;
3525 alu
.src
[0].chan
= i
;
3530 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3537 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3539 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3540 struct r600_bytecode_alu alu
;
3542 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3544 for (i
= 0; i
< lasti
+ 1; i
++) {
3545 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3549 alu
.op
= ctx
->inst_info
->op
;
3550 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3551 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3554 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3568 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3570 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3571 struct r600_bytecode_alu alu
;
3574 for (i
= 0; i
< 4; i
++) {
3575 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3576 alu
.op
= ctx
->inst_info
->op
;
3577 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3578 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3581 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3583 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3584 /* handle some special cases */
3585 switch (ctx
->inst_info
->tgsi_opcode
) {
3586 case TGSI_OPCODE_DP2
:
3588 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3589 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3592 case TGSI_OPCODE_DP3
:
3594 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3595 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3598 case TGSI_OPCODE_DPH
:
3600 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3601 alu
.src
[0].chan
= 0;
3611 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3618 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3621 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3622 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3623 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3624 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3625 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3628 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3631 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3632 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3635 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3637 struct r600_bytecode_vtx vtx
;
3638 struct r600_bytecode_alu alu
;
3639 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3641 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3643 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3644 if (src_requires_loading
) {
3645 for (i
= 0; i
< 4; i
++) {
3646 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3647 alu
.op
= ALU_OP1_MOV
;
3648 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3649 alu
.dst
.sel
= ctx
->temp_reg
;
3654 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3658 src_gpr
= ctx
->temp_reg
;
3661 memset(&vtx
, 0, sizeof(vtx
));
3662 vtx
.op
= FETCH_OP_VFETCH
;
3663 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3664 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3665 vtx
.src_gpr
= src_gpr
;
3666 vtx
.mega_fetch_count
= 16;
3667 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3668 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3669 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3670 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
3671 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
3672 vtx
.use_const_fields
= 1;
3673 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
3675 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
3678 if (ctx
->bc
->chip_class
>= EVERGREEN
)
3681 for (i
= 0; i
< 4; i
++) {
3682 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3683 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3686 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3687 alu
.op
= ALU_OP2_AND_INT
;
3690 alu
.dst
.sel
= vtx
.dst_gpr
;
3693 alu
.src
[0].sel
= vtx
.dst_gpr
;
3694 alu
.src
[0].chan
= i
;
3696 alu
.src
[1].sel
= 512 + (id
* 2);
3697 alu
.src
[1].chan
= i
% 4;
3698 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3702 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3707 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
3708 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3709 alu
.op
= ALU_OP2_OR_INT
;
3712 alu
.dst
.sel
= vtx
.dst_gpr
;
3715 alu
.src
[0].sel
= vtx
.dst_gpr
;
3716 alu
.src
[0].chan
= 3;
3718 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
3719 alu
.src
[1].chan
= 0;
3720 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3723 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3730 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
3732 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3733 struct r600_bytecode_alu alu
;
3735 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3738 alu
.op
= ALU_OP1_MOV
;
3740 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
3741 alu
.src
[0].sel
= 512 + (id
/ 4);
3742 alu
.src
[0].chan
= id
% 4;
3744 /* r600 we have them at channel 2 of the second dword */
3745 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
3746 alu
.src
[0].chan
= 1;
3748 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3749 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3757 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
3759 static float one_point_five
= 1.5f
;
3760 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3761 struct r600_bytecode_tex tex
;
3762 struct r600_bytecode_alu alu
;
3766 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
3767 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
3768 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
3769 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
3771 /* Texture fetch instructions can only use gprs as source.
3772 * Also they cannot negate the source or take the absolute value */
3773 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
3774 tgsi_tex_src_requires_loading(ctx
, 0)) ||
3775 read_compressed_msaa
;
3776 boolean src_loaded
= FALSE
;
3777 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
3778 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
3779 boolean has_txq_cube_array_z
= false;
3781 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
3782 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3783 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
3784 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
3785 ctx
->shader
->has_txq_cube_array_z_comp
= true;
3786 has_txq_cube_array_z
= true;
3789 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
3790 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
3791 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
3792 sampler_src_reg
= 2;
3794 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3796 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
3797 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
3798 ctx
->shader
->uses_tex_buffers
= true;
3799 return r600_do_buffer_txq(ctx
);
3801 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3802 if (ctx
->bc
->chip_class
< EVERGREEN
)
3803 ctx
->shader
->uses_tex_buffers
= true;
3804 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
3808 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3809 /* get offset values */
3810 if (inst
->Texture
.NumOffsets
) {
3811 assert(inst
->Texture
.NumOffsets
== 1);
3813 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
3814 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
3815 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
3817 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
3818 /* TGSI moves the sampler to src reg 3 for TXD */
3819 sampler_src_reg
= 3;
3821 for (i
= 1; i
< 3; i
++) {
3822 /* set gradients h/v */
3823 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
3824 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
3825 FETCH_OP_SET_GRADIENTS_V
;
3826 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
3827 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
3829 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
3830 tex
.src_gpr
= r600_get_temp(ctx
);
3836 for (j
= 0; j
< 4; j
++) {
3837 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3838 alu
.op
= ALU_OP1_MOV
;
3839 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
3840 alu
.dst
.sel
= tex
.src_gpr
;
3845 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3851 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
3852 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
3853 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
3854 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
3855 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
3856 tex
.src_rel
= ctx
->src
[i
].rel
;
3858 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
3859 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
3860 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
3861 tex
.coord_type_x
= 1;
3862 tex
.coord_type_y
= 1;
3863 tex
.coord_type_z
= 1;
3864 tex
.coord_type_w
= 1;
3866 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
3870 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
3872 /* Add perspective divide */
3873 if (ctx
->bc
->chip_class
== CAYMAN
) {
3875 for (i
= 0; i
< 3; i
++) {
3876 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3877 alu
.op
= ALU_OP1_RECIP_IEEE
;
3878 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3880 alu
.dst
.sel
= ctx
->temp_reg
;
3886 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3893 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3894 alu
.op
= ALU_OP1_RECIP_IEEE
;
3895 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3897 alu
.dst
.sel
= ctx
->temp_reg
;
3898 alu
.dst
.chan
= out_chan
;
3901 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3906 for (i
= 0; i
< 3; i
++) {
3907 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3908 alu
.op
= ALU_OP2_MUL
;
3909 alu
.src
[0].sel
= ctx
->temp_reg
;
3910 alu
.src
[0].chan
= out_chan
;
3911 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3912 alu
.dst
.sel
= ctx
->temp_reg
;
3915 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3919 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3920 alu
.op
= ALU_OP1_MOV
;
3921 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3922 alu
.src
[0].chan
= 0;
3923 alu
.dst
.sel
= ctx
->temp_reg
;
3927 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3931 src_gpr
= ctx
->temp_reg
;
3934 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
3935 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3936 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
3937 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
3938 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
3939 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
3941 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
3942 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
3944 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
3945 for (i
= 0; i
< 4; i
++) {
3946 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3947 alu
.op
= ALU_OP2_CUBE
;
3948 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
3949 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
3950 alu
.dst
.sel
= ctx
->temp_reg
;
3955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3960 /* tmp1.z = RCP_e(|tmp1.z|) */
3961 if (ctx
->bc
->chip_class
== CAYMAN
) {
3962 for (i
= 0; i
< 3; i
++) {
3963 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3964 alu
.op
= ALU_OP1_RECIP_IEEE
;
3965 alu
.src
[0].sel
= ctx
->temp_reg
;
3966 alu
.src
[0].chan
= 2;
3968 alu
.dst
.sel
= ctx
->temp_reg
;
3974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3980 alu
.op
= ALU_OP1_RECIP_IEEE
;
3981 alu
.src
[0].sel
= ctx
->temp_reg
;
3982 alu
.src
[0].chan
= 2;
3984 alu
.dst
.sel
= ctx
->temp_reg
;
3988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3993 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
3994 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
3995 * muladd has no writemask, have to use another temp
3997 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3998 alu
.op
= ALU_OP3_MULADD
;
4001 alu
.src
[0].sel
= ctx
->temp_reg
;
4002 alu
.src
[0].chan
= 0;
4003 alu
.src
[1].sel
= ctx
->temp_reg
;
4004 alu
.src
[1].chan
= 2;
4006 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4007 alu
.src
[2].chan
= 0;
4008 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4010 alu
.dst
.sel
= ctx
->temp_reg
;
4014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4019 alu
.op
= ALU_OP3_MULADD
;
4022 alu
.src
[0].sel
= ctx
->temp_reg
;
4023 alu
.src
[0].chan
= 1;
4024 alu
.src
[1].sel
= ctx
->temp_reg
;
4025 alu
.src
[1].chan
= 2;
4027 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4028 alu
.src
[2].chan
= 0;
4029 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4031 alu
.dst
.sel
= ctx
->temp_reg
;
4036 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4039 /* write initial compare value into Z component
4040 - W src 0 for shadow cube
4041 - X src 1 for shadow cube array */
4042 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4043 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4045 alu
.op
= ALU_OP1_MOV
;
4046 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4047 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4049 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4050 alu
.dst
.sel
= ctx
->temp_reg
;
4054 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4059 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4060 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4061 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4062 int mytmp
= r600_get_temp(ctx
);
4063 static const float eight
= 8.0f
;
4064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4065 alu
.op
= ALU_OP1_MOV
;
4066 alu
.src
[0].sel
= ctx
->temp_reg
;
4067 alu
.src
[0].chan
= 3;
4068 alu
.dst
.sel
= mytmp
;
4072 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4076 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4078 alu
.op
= ALU_OP3_MULADD
;
4080 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4081 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4082 alu
.src
[1].chan
= 0;
4083 alu
.src
[1].value
= *(uint32_t *)&eight
;
4084 alu
.src
[2].sel
= mytmp
;
4085 alu
.src
[2].chan
= 0;
4086 alu
.dst
.sel
= ctx
->temp_reg
;
4090 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4093 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4094 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4095 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4096 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4097 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4098 tex
.src_gpr
= r600_get_temp(ctx
);
4103 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4104 tex
.coord_type_x
= 1;
4105 tex
.coord_type_y
= 1;
4106 tex
.coord_type_z
= 1;
4107 tex
.coord_type_w
= 1;
4108 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4109 alu
.op
= ALU_OP1_MOV
;
4110 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4111 alu
.dst
.sel
= tex
.src_gpr
;
4115 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4119 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4126 /* for cube forms of lod and bias we need to route things */
4127 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4128 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4129 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4130 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4131 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4132 alu
.op
= ALU_OP1_MOV
;
4133 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4134 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4135 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4138 alu
.dst
.sel
= ctx
->temp_reg
;
4142 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4148 src_gpr
= ctx
->temp_reg
;
4151 if (src_requires_loading
&& !src_loaded
) {
4152 for (i
= 0; i
< 4; i
++) {
4153 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4154 alu
.op
= ALU_OP1_MOV
;
4155 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4156 alu
.dst
.sel
= ctx
->temp_reg
;
4161 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4166 src_gpr
= ctx
->temp_reg
;
4169 /* Obtain the sample index for reading a compressed MSAA color texture.
4170 * To read the FMASK, we use the ldfptr instruction, which tells us
4171 * where the samples are stored.
4172 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4173 * which is the identity mapping. Each nibble says which physical sample
4174 * should be fetched to get that sample.
4176 * Assume src.z contains the sample index. It should be modified like this:
4177 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4178 * Then fetch the texel with src.
4180 if (read_compressed_msaa
) {
4181 unsigned sample_chan
= 3;
4182 unsigned temp
= r600_get_temp(ctx
);
4185 /* temp.w = ldfptr() */
4186 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4187 tex
.op
= FETCH_OP_LD
;
4188 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4189 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4190 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4191 tex
.src_gpr
= src_gpr
;
4193 tex
.dst_sel_x
= 7; /* mask out these components */
4196 tex
.dst_sel_w
= 0; /* store X */
4201 tex
.offset_x
= offset_x
;
4202 tex
.offset_y
= offset_y
;
4203 tex
.offset_z
= offset_z
;
4204 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4208 /* temp.x = sample_index*4 */
4209 if (ctx
->bc
->chip_class
== CAYMAN
) {
4210 for (i
= 0 ; i
< 4; i
++) {
4211 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4212 alu
.op
= ALU_OP2_MULLO_INT
;
4213 alu
.src
[0].sel
= src_gpr
;
4214 alu
.src
[0].chan
= sample_chan
;
4215 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4216 alu
.src
[1].value
= 4;
4219 alu
.dst
.write
= i
== 0;
4222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4227 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4228 alu
.op
= ALU_OP2_MULLO_INT
;
4229 alu
.src
[0].sel
= src_gpr
;
4230 alu
.src
[0].chan
= sample_chan
;
4231 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4232 alu
.src
[1].value
= 4;
4237 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4242 /* sample_index = temp.w >> temp.x */
4243 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4244 alu
.op
= ALU_OP2_LSHR_INT
;
4245 alu
.src
[0].sel
= temp
;
4246 alu
.src
[0].chan
= 3;
4247 alu
.src
[1].sel
= temp
;
4248 alu
.src
[1].chan
= 0;
4249 alu
.dst
.sel
= src_gpr
;
4250 alu
.dst
.chan
= sample_chan
;
4253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4257 /* sample_index & 0xF */
4258 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4259 alu
.op
= ALU_OP2_AND_INT
;
4260 alu
.src
[0].sel
= src_gpr
;
4261 alu
.src
[0].chan
= sample_chan
;
4262 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4263 alu
.src
[1].value
= 0xF;
4264 alu
.dst
.sel
= src_gpr
;
4265 alu
.dst
.chan
= sample_chan
;
4268 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4272 /* visualize the FMASK */
4273 for (i
= 0; i
< 4; i
++) {
4274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4275 alu
.op
= ALU_OP1_INT_TO_FLT
;
4276 alu
.src
[0].sel
= src_gpr
;
4277 alu
.src
[0].chan
= sample_chan
;
4278 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4282 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4290 /* does this shader want a num layers from TXQ for a cube array? */
4291 if (has_txq_cube_array_z
) {
4292 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4294 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4295 alu
.op
= ALU_OP1_MOV
;
4297 alu
.src
[0].sel
= 512 + (id
/ 4);
4298 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4299 alu
.src
[0].chan
= id
% 4;
4300 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4302 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4305 /* disable writemask from texture instruction */
4306 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4309 opcode
= ctx
->inst_info
->op
;
4310 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4311 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4312 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4313 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4314 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4315 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4316 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4318 case FETCH_OP_SAMPLE
:
4319 opcode
= FETCH_OP_SAMPLE_C
;
4321 case FETCH_OP_SAMPLE_L
:
4322 opcode
= FETCH_OP_SAMPLE_C_L
;
4324 case FETCH_OP_SAMPLE_LB
:
4325 opcode
= FETCH_OP_SAMPLE_C_LB
;
4327 case FETCH_OP_SAMPLE_G
:
4328 opcode
= FETCH_OP_SAMPLE_C_G
;
4333 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4336 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4337 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4338 tex
.src_gpr
= src_gpr
;
4339 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4340 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4341 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4342 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4343 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4345 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4350 } else if (src_loaded
) {
4356 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4357 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4358 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4359 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4360 tex
.src_rel
= ctx
->src
[0].rel
;
4363 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4364 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4365 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4366 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4370 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4373 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4374 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4375 tex
.coord_type_x
= 1;
4376 tex
.coord_type_y
= 1;
4378 tex
.coord_type_z
= 1;
4379 tex
.coord_type_w
= 1;
4381 tex
.offset_x
= offset_x
;
4382 tex
.offset_y
= offset_y
;
4383 tex
.offset_z
= offset_z
;
4385 /* Put the depth for comparison in W.
4386 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4387 * Some instructions expect the depth in Z. */
4388 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4389 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4390 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4391 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4392 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4393 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4394 tex
.src_sel_w
= tex
.src_sel_z
;
4397 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4398 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4399 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4400 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4401 /* the array index is read from Y */
4402 tex
.coord_type_y
= 0;
4404 /* the array index is read from Z */
4405 tex
.coord_type_z
= 0;
4406 tex
.src_sel_z
= tex
.src_sel_y
;
4408 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4409 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4410 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4411 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4412 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4413 /* the array index is read from Z */
4414 tex
.coord_type_z
= 0;
4416 /* mask unused source components */
4417 if (opcode
== FETCH_OP_SAMPLE
) {
4418 switch (inst
->Texture
.Texture
) {
4419 case TGSI_TEXTURE_2D
:
4420 case TGSI_TEXTURE_RECT
:
4424 case TGSI_TEXTURE_1D_ARRAY
:
4428 case TGSI_TEXTURE_1D
:
4436 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4440 /* add shadow ambient support - gallium doesn't do it yet */
4444 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4446 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4447 struct r600_bytecode_alu alu
;
4448 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4452 /* optimize if it's just an equal balance */
4453 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4454 for (i
= 0; i
< lasti
+ 1; i
++) {
4455 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4459 alu
.op
= ALU_OP2_ADD
;
4460 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4461 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4463 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4476 for (i
= 0; i
< lasti
+ 1; i
++) {
4477 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4481 alu
.op
= ALU_OP2_ADD
;
4482 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4483 alu
.src
[0].chan
= 0;
4484 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4485 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4486 alu
.dst
.sel
= ctx
->temp_reg
;
4492 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4497 /* (1 - src0) * src2 */
4498 for (i
= 0; i
< lasti
+ 1; i
++) {
4499 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4502 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4503 alu
.op
= ALU_OP2_MUL
;
4504 alu
.src
[0].sel
= ctx
->temp_reg
;
4505 alu
.src
[0].chan
= i
;
4506 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4507 alu
.dst
.sel
= ctx
->temp_reg
;
4513 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4518 /* src0 * src1 + (1 - src0) * src2 */
4519 for (i
= 0; i
< lasti
+ 1; i
++) {
4520 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4523 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4524 alu
.op
= ALU_OP3_MULADD
;
4526 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4527 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4528 alu
.src
[2].sel
= ctx
->temp_reg
;
4529 alu
.src
[2].chan
= i
;
4531 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4536 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4543 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4545 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4546 struct r600_bytecode_alu alu
;
4548 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4550 for (i
= 0; i
< lasti
+ 1; i
++) {
4551 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4555 alu
.op
= ALU_OP3_CNDGE
;
4556 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4557 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4558 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4559 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4565 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4572 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4574 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4575 struct r600_bytecode_alu alu
;
4577 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4579 for (i
= 0; i
< lasti
+ 1; i
++) {
4580 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4583 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4584 alu
.op
= ALU_OP3_CNDGE_INT
;
4585 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4586 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4587 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4588 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4594 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4601 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4603 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4604 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4605 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4606 struct r600_bytecode_alu alu
;
4607 uint32_t use_temp
= 0;
4610 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4613 for (i
= 0; i
< 4; i
++) {
4614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4615 alu
.op
= ALU_OP2_MUL
;
4617 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4618 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4620 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4621 alu
.src
[0].chan
= i
;
4622 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4623 alu
.src
[1].chan
= i
;
4626 alu
.dst
.sel
= ctx
->temp_reg
;
4632 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4637 for (i
= 0; i
< 4; i
++) {
4638 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4639 alu
.op
= ALU_OP3_MULADD
;
4642 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4643 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4645 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4646 alu
.src
[0].chan
= i
;
4647 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4648 alu
.src
[1].chan
= i
;
4651 alu
.src
[2].sel
= ctx
->temp_reg
;
4653 alu
.src
[2].chan
= i
;
4656 alu
.dst
.sel
= ctx
->temp_reg
;
4658 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4664 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4669 return tgsi_helper_copy(ctx
, inst
);
4673 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4675 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4676 struct r600_bytecode_alu alu
;
4680 /* result.x = 2^floor(src); */
4681 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4682 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4684 alu
.op
= ALU_OP1_FLOOR
;
4685 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4687 alu
.dst
.sel
= ctx
->temp_reg
;
4691 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4695 if (ctx
->bc
->chip_class
== CAYMAN
) {
4696 for (i
= 0; i
< 3; i
++) {
4697 alu
.op
= ALU_OP1_EXP_IEEE
;
4698 alu
.src
[0].sel
= ctx
->temp_reg
;
4699 alu
.src
[0].chan
= 0;
4701 alu
.dst
.sel
= ctx
->temp_reg
;
4703 alu
.dst
.write
= i
== 0;
4705 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4710 alu
.op
= ALU_OP1_EXP_IEEE
;
4711 alu
.src
[0].sel
= ctx
->temp_reg
;
4712 alu
.src
[0].chan
= 0;
4714 alu
.dst
.sel
= ctx
->temp_reg
;
4718 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4724 /* result.y = tmp - floor(tmp); */
4725 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4726 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4728 alu
.op
= ALU_OP1_FRACT
;
4729 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4731 alu
.dst
.sel
= ctx
->temp_reg
;
4733 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4742 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4747 /* result.z = RoughApprox2ToX(tmp);*/
4748 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
4749 if (ctx
->bc
->chip_class
== CAYMAN
) {
4750 for (i
= 0; i
< 3; i
++) {
4751 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4752 alu
.op
= ALU_OP1_EXP_IEEE
;
4753 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4755 alu
.dst
.sel
= ctx
->temp_reg
;
4762 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4767 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4768 alu
.op
= ALU_OP1_EXP_IEEE
;
4769 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4771 alu
.dst
.sel
= ctx
->temp_reg
;
4777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4783 /* result.w = 1.0;*/
4784 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
4785 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4787 alu
.op
= ALU_OP1_MOV
;
4788 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4789 alu
.src
[0].chan
= 0;
4791 alu
.dst
.sel
= ctx
->temp_reg
;
4795 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4799 return tgsi_helper_copy(ctx
, inst
);
4802 static int tgsi_log(struct r600_shader_ctx
*ctx
)
4804 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4805 struct r600_bytecode_alu alu
;
4809 /* result.x = floor(log2(|src|)); */
4810 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4811 if (ctx
->bc
->chip_class
== CAYMAN
) {
4812 for (i
= 0; i
< 3; i
++) {
4813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4815 alu
.op
= ALU_OP1_LOG_IEEE
;
4816 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4817 r600_bytecode_src_set_abs(&alu
.src
[0]);
4819 alu
.dst
.sel
= ctx
->temp_reg
;
4825 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4833 alu
.op
= ALU_OP1_LOG_IEEE
;
4834 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4835 r600_bytecode_src_set_abs(&alu
.src
[0]);
4837 alu
.dst
.sel
= ctx
->temp_reg
;
4841 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4846 alu
.op
= ALU_OP1_FLOOR
;
4847 alu
.src
[0].sel
= ctx
->temp_reg
;
4848 alu
.src
[0].chan
= 0;
4850 alu
.dst
.sel
= ctx
->temp_reg
;
4855 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4860 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
4861 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4863 if (ctx
->bc
->chip_class
== CAYMAN
) {
4864 for (i
= 0; i
< 3; i
++) {
4865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4867 alu
.op
= ALU_OP1_LOG_IEEE
;
4868 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4869 r600_bytecode_src_set_abs(&alu
.src
[0]);
4871 alu
.dst
.sel
= ctx
->temp_reg
;
4878 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4883 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4885 alu
.op
= ALU_OP1_LOG_IEEE
;
4886 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4887 r600_bytecode_src_set_abs(&alu
.src
[0]);
4889 alu
.dst
.sel
= ctx
->temp_reg
;
4894 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4901 alu
.op
= ALU_OP1_FLOOR
;
4902 alu
.src
[0].sel
= ctx
->temp_reg
;
4903 alu
.src
[0].chan
= 1;
4905 alu
.dst
.sel
= ctx
->temp_reg
;
4910 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4914 if (ctx
->bc
->chip_class
== CAYMAN
) {
4915 for (i
= 0; i
< 3; i
++) {
4916 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4917 alu
.op
= ALU_OP1_EXP_IEEE
;
4918 alu
.src
[0].sel
= ctx
->temp_reg
;
4919 alu
.src
[0].chan
= 1;
4921 alu
.dst
.sel
= ctx
->temp_reg
;
4928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4934 alu
.op
= ALU_OP1_EXP_IEEE
;
4935 alu
.src
[0].sel
= ctx
->temp_reg
;
4936 alu
.src
[0].chan
= 1;
4938 alu
.dst
.sel
= ctx
->temp_reg
;
4943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4948 if (ctx
->bc
->chip_class
== CAYMAN
) {
4949 for (i
= 0; i
< 3; i
++) {
4950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4951 alu
.op
= ALU_OP1_RECIP_IEEE
;
4952 alu
.src
[0].sel
= ctx
->temp_reg
;
4953 alu
.src
[0].chan
= 1;
4955 alu
.dst
.sel
= ctx
->temp_reg
;
4962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4967 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4968 alu
.op
= ALU_OP1_RECIP_IEEE
;
4969 alu
.src
[0].sel
= ctx
->temp_reg
;
4970 alu
.src
[0].chan
= 1;
4972 alu
.dst
.sel
= ctx
->temp_reg
;
4977 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4982 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4984 alu
.op
= ALU_OP2_MUL
;
4986 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4987 r600_bytecode_src_set_abs(&alu
.src
[0]);
4989 alu
.src
[1].sel
= ctx
->temp_reg
;
4990 alu
.src
[1].chan
= 1;
4992 alu
.dst
.sel
= ctx
->temp_reg
;
4997 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5002 /* result.z = log2(|src|);*/
5003 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5004 if (ctx
->bc
->chip_class
== CAYMAN
) {
5005 for (i
= 0; i
< 3; i
++) {
5006 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5008 alu
.op
= ALU_OP1_LOG_IEEE
;
5009 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5010 r600_bytecode_src_set_abs(&alu
.src
[0]);
5012 alu
.dst
.sel
= ctx
->temp_reg
;
5019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5026 alu
.op
= ALU_OP1_LOG_IEEE
;
5027 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5028 r600_bytecode_src_set_abs(&alu
.src
[0]);
5030 alu
.dst
.sel
= ctx
->temp_reg
;
5035 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5041 /* result.w = 1.0; */
5042 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5045 alu
.op
= ALU_OP1_MOV
;
5046 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5047 alu
.src
[0].chan
= 0;
5049 alu
.dst
.sel
= ctx
->temp_reg
;
5054 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5059 return tgsi_helper_copy(ctx
, inst
);
5062 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5064 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5065 struct r600_bytecode_alu alu
;
5068 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5070 switch (inst
->Instruction
.Opcode
) {
5071 case TGSI_OPCODE_ARL
:
5072 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5074 case TGSI_OPCODE_ARR
:
5075 alu
.op
= ALU_OP1_FLT_TO_INT
;
5077 case TGSI_OPCODE_UARL
:
5078 alu
.op
= ALU_OP1_MOV
;
5085 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5087 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5089 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5093 ctx
->bc
->ar_loaded
= 0;
5096 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5098 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5099 struct r600_bytecode_alu alu
;
5102 switch (inst
->Instruction
.Opcode
) {
5103 case TGSI_OPCODE_ARL
:
5104 memset(&alu
, 0, sizeof(alu
));
5105 alu
.op
= ALU_OP1_FLOOR
;
5106 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5107 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5111 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5114 memset(&alu
, 0, sizeof(alu
));
5115 alu
.op
= ALU_OP1_FLT_TO_INT
;
5116 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5117 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5121 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5124 case TGSI_OPCODE_ARR
:
5125 memset(&alu
, 0, sizeof(alu
));
5126 alu
.op
= ALU_OP1_FLT_TO_INT
;
5127 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5128 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5132 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5135 case TGSI_OPCODE_UARL
:
5136 memset(&alu
, 0, sizeof(alu
));
5137 alu
.op
= ALU_OP1_MOV
;
5138 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5139 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5143 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5151 ctx
->bc
->ar_loaded
= 0;
5155 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5157 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5158 struct r600_bytecode_alu alu
;
5161 for (i
= 0; i
< 4; i
++) {
5162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5164 alu
.op
= ALU_OP2_MUL
;
5165 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5167 if (i
== 0 || i
== 3) {
5168 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5170 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5173 if (i
== 0 || i
== 2) {
5174 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5176 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5180 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5187 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5189 struct r600_bytecode_alu alu
;
5192 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5194 alu
.execute_mask
= 1;
5195 alu
.update_pred
= 1;
5197 alu
.dst
.sel
= ctx
->temp_reg
;
5201 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5202 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5203 alu
.src
[1].chan
= 0;
5207 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5213 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5215 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5219 if (ctx
->bc
->cf_last
) {
5220 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5222 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5227 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5228 ctx
->bc
->force_add_cf
= 1;
5229 } else if (alu_pop
== 2) {
5230 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5231 ctx
->bc
->force_add_cf
= 1;
5238 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5239 ctx
->bc
->cf_last
->pop_count
= pops
;
5240 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5246 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5249 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5250 unsigned elements
, entries
;
5252 unsigned entry_size
= stack
->entry_size
;
5254 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5255 elements
+= stack
->push
;
5257 switch (ctx
->bc
->chip_class
) {
5260 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5261 * the stack must be reserved to hold the current active/continue
5263 if (reason
== FC_PUSH_VPM
) {
5269 /* r9xx: any stack operation on empty stack consumes 2 additional
5274 /* FIXME: do the two elements added above cover the cases for the
5278 /* r8xx+: 2 extra elements are not always required, but one extra
5279 * element must be added for each of the following cases:
5280 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5282 * (Currently we don't use ALU_ELSE_AFTER.)
5283 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5284 * PUSH instruction executed.
5286 * NOTE: it seems we also need to reserve additional element in some
5287 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5288 * then STACK_SIZE should be 2 instead of 1 */
5289 if (reason
== FC_PUSH_VPM
) {
5299 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5300 * for all chips, so we use 4 in the final formula, not the real entry_size
5304 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5306 if (entries
> stack
->max_entries
)
5307 stack
->max_entries
= entries
;
5310 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5314 --ctx
->bc
->stack
.push
;
5315 assert(ctx
->bc
->stack
.push
>= 0);
5318 --ctx
->bc
->stack
.push_wqm
;
5319 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5322 --ctx
->bc
->stack
.loop
;
5323 assert(ctx
->bc
->stack
.loop
>= 0);
5331 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5335 ++ctx
->bc
->stack
.push
;
5338 ++ctx
->bc
->stack
.push_wqm
;
5340 ++ctx
->bc
->stack
.loop
;
5346 callstack_update_max_depth(ctx
, reason
);
5349 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5351 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5353 sp
->mid
= realloc((void *)sp
->mid
,
5354 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5355 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5359 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5362 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5363 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5366 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5368 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5378 static int emit_return(struct r600_shader_ctx
*ctx
)
5380 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5384 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5387 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5388 ctx
->bc
->cf_last
->pop_count
= pops
;
5389 /* XXX work out offset */
5393 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5398 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5403 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5406 emit_jump_to_offset(ctx
, 1, 4);
5407 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5408 pops(ctx
, ifidx
+ 1);
5412 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5416 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5417 ctx
->bc
->cf_last
->pop_count
= 1;
5419 fc_set_mid(ctx
, fc_sp
);
5425 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5427 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5429 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5430 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5431 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5432 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5433 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5434 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5435 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5436 alu_type
= CF_OP_ALU
;
5439 emit_logic_pred(ctx
, opcode
, alu_type
);
5441 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5443 fc_pushlevel(ctx
, FC_IF
);
5445 callstack_push(ctx
, FC_PUSH_VPM
);
5449 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5451 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5454 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5456 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5459 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5461 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5462 ctx
->bc
->cf_last
->pop_count
= 1;
5464 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5465 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5469 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5472 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5473 R600_ERR("if/endif unbalanced in shader\n");
5477 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5478 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5479 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5481 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5485 callstack_pop(ctx
, FC_PUSH_VPM
);
5489 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5491 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5492 * limited to 4096 iterations, like the other LOOP_* instructions. */
5493 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5495 fc_pushlevel(ctx
, FC_LOOP
);
5497 /* check stack depth */
5498 callstack_push(ctx
, FC_LOOP
);
5502 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5506 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5508 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5509 R600_ERR("loop/endloop in shader code are not paired.\n");
5513 /* fixup loop pointers - from r600isa
5514 LOOP END points to CF after LOOP START,
5515 LOOP START point to CF after LOOP END
5516 BRK/CONT point to LOOP END CF
5518 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5520 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5522 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5523 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5525 /* XXX add LOOPRET support */
5527 callstack_pop(ctx
, FC_LOOP
);
5531 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5535 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5537 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5542 R600_ERR("Break not inside loop/endloop pair\n");
5546 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5548 fc_set_mid(ctx
, fscp
);
5553 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5555 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5556 struct r600_bytecode_alu alu
;
5558 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5561 for (i
= 0; i
< lasti
+ 1; i
++) {
5562 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5565 if (ctx
->bc
->chip_class
== CAYMAN
) {
5566 for (j
= 0 ; j
< 4; j
++) {
5567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5569 alu
.op
= ALU_OP2_MULLO_UINT
;
5570 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5571 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5573 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5574 alu
.dst
.sel
= ctx
->temp_reg
;
5575 alu
.dst
.write
= (j
== i
);
5578 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5583 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5586 alu
.dst
.sel
= ctx
->temp_reg
;
5589 alu
.op
= ALU_OP2_MULLO_UINT
;
5590 for (j
= 0; j
< 2; j
++) {
5591 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5595 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5602 for (i
= 0; i
< lasti
+ 1; i
++) {
5603 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5606 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5607 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5609 alu
.op
= ALU_OP2_ADD_INT
;
5611 alu
.src
[0].sel
= ctx
->temp_reg
;
5612 alu
.src
[0].chan
= i
;
5614 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5618 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5625 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5626 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5627 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5628 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5631 * For state trackers other than OpenGL, we'll want to use
5632 * _RECIP_IEEE instead.
5634 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5636 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5637 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5638 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5639 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5640 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5641 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5642 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5643 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5644 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5645 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5646 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5647 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5648 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5649 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5650 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5651 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5653 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5654 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5656 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5657 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5658 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5659 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5660 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5661 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5662 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5663 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5664 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5665 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5667 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5668 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5669 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5670 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5671 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5672 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5673 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5674 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5675 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5676 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5677 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5678 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5679 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5680 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5681 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5682 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5683 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5684 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5685 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5686 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5687 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5688 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5689 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5690 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5691 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5692 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5693 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5694 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5695 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5696 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5697 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5698 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5699 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5700 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5701 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5702 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5703 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5704 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5705 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5706 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5707 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5708 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5709 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5710 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5711 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5712 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5713 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5715 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5716 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5717 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5718 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5719 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5720 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5721 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5722 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5723 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
5725 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5726 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5727 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5728 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5729 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5730 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5731 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5732 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5733 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5734 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5735 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5736 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5737 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5738 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5739 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5740 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5742 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5743 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5744 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5745 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5747 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5748 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5749 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5750 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5751 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5752 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5754 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5755 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5756 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5757 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5759 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5760 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
5761 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5762 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5763 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5764 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5765 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5766 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
5767 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5768 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
5769 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5770 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5771 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5772 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5773 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5774 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5775 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5776 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5777 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5778 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5779 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
5780 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5781 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
5782 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5783 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5784 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5785 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5786 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5787 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5788 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5789 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5790 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5791 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5792 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5793 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5794 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5795 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5796 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5797 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5798 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
5799 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5800 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5801 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5802 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5803 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5804 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5805 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5806 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5807 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5808 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5809 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5810 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5811 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5812 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5813 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5814 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5815 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5816 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5817 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5818 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5819 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5820 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5821 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5824 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
5825 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5826 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5827 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5828 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
5829 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
5830 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5831 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5832 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5833 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5834 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5835 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5836 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5837 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5838 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5839 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5840 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5841 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5842 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5843 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5844 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5846 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5847 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5849 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5850 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5851 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5852 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5853 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5854 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5855 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5856 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5857 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5858 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5860 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5861 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5862 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5863 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5864 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5865 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5866 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5867 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
5868 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5869 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5870 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5871 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5872 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5873 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5874 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5875 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5876 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5877 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5878 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5879 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5880 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5881 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5882 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5883 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5884 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5885 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5886 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5887 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5888 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5889 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
5890 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5891 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5892 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5893 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5894 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5895 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5896 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5897 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5898 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5899 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5900 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5901 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5902 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5903 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5904 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5905 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5906 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5908 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5909 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5910 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5911 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5912 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5913 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5914 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5915 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5916 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
5918 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5919 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5920 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5921 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5922 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5923 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5924 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5925 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5926 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5927 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5928 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5929 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5930 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5931 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5932 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5933 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5935 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5936 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5937 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5938 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5940 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5941 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5942 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5943 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5944 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5945 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5947 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5948 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5949 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5950 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5952 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5953 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
5954 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5955 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5956 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5957 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5958 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5959 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
5960 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5961 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
5962 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5963 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5964 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5965 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5966 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5967 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5968 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5969 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5970 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5971 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5972 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
5973 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5974 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
5975 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5977 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5978 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5979 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5980 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5981 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5982 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5983 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5984 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5985 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5986 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5987 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5988 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5989 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5990 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5991 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
5992 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5993 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5994 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5995 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5996 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5997 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5998 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5999 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6000 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6001 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6002 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6003 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6004 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6005 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6006 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6007 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6008 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6009 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6010 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6011 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6012 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6013 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6014 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6017 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6018 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6019 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6020 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6021 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6022 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6023 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6024 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6025 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6026 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6027 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6028 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6029 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6030 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6031 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6032 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6033 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6034 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6035 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6036 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6037 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6039 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6040 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6042 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6043 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6044 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6045 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6046 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6047 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6048 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6049 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6050 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6051 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6053 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6054 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6055 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6056 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6057 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6058 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6059 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6060 {TGSI_OPCODE_KILP
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* predicated kill */
6061 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6062 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6063 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6064 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6065 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6066 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6067 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6068 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6069 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6070 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6071 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6072 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6073 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6074 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6075 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6076 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6078 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6079 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6080 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6081 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6082 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6083 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6084 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6085 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6086 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6087 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6088 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6089 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6090 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6091 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6092 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6093 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6094 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6095 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6096 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6097 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6098 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6099 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6101 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6102 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6103 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6105 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6106 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6107 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6108 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6109 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6111 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6112 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6113 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6114 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6115 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6116 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6117 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6118 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6119 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6120 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6121 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6122 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6123 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6124 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6125 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6126 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6128 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6129 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6130 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6131 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6133 {108, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6134 {109, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6135 {110, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6136 {111, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6137 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6138 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6140 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6141 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6142 {TGSI_OPCODE_KIL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6143 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6145 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6146 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6147 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6148 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6149 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6150 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6151 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6152 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6153 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6154 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6155 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6156 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6157 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6158 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6159 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6160 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6161 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6162 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6163 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6164 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6165 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6166 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6167 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6168 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6170 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6172 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6173 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6174 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6175 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6176 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6177 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6178 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6179 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6180 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6181 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6182 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6183 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6184 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6185 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6186 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6187 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6188 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6189 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6190 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6191 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6192 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6193 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6194 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6195 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6196 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6197 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6198 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6199 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6200 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6201 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6202 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6203 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6204 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6205 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6206 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6207 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},