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_NO_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_pos_base
= 60, next_param_base
= 0;
921 int max_color_exports
= MAX2(key
.nr_cbufs
, 1);
922 /* Declarations used by llvm code */
923 bool use_llvm
= false;
927 use_llvm
= !(rscreen
->debug_flags
& DBG_NO_LLVM
);
929 ctx
.bc
= &shader
->bc
;
931 ctx
.native_integers
= true;
933 r600_bytecode_init(ctx
.bc
, rscreen
->chip_class
, rscreen
->family
,
934 rscreen
->has_compressed_msaa_texturing
);
936 tgsi_scan_shader(tokens
, &ctx
.info
);
937 shader
->indirect_files
= ctx
.info
.indirect_files
;
938 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
939 tgsi_parse_init(&ctx
.parse
, tokens
);
940 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
941 shader
->processor_type
= ctx
.type
;
942 ctx
.bc
->type
= shader
->processor_type
;
945 ctx
.fragcoord_input
= -1;
947 ctx
.clip_vertex_write
= 0;
949 shader
->nr_ps_color_exports
= 0;
950 shader
->nr_ps_max_color_exports
= 0;
952 shader
->two_side
= key
.color_two_side
;
954 /* register allocations */
955 /* Values [0,127] correspond to GPR[0..127].
956 * Values [128,159] correspond to constant buffer bank 0
957 * Values [160,191] correspond to constant buffer bank 1
958 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
959 * Values [256,287] correspond to constant buffer bank 2 (EG)
960 * Values [288,319] correspond to constant buffer bank 3 (EG)
961 * Other special values are shown in the list below.
962 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
963 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
964 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
965 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
966 * 248 SQ_ALU_SRC_0: special constant 0.0.
967 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
968 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
969 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
970 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
971 * 253 SQ_ALU_SRC_LITERAL: literal constant.
972 * 254 SQ_ALU_SRC_PV: previous vector result.
973 * 255 SQ_ALU_SRC_PS: previous scalar result.
975 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
976 ctx
.file_offset
[i
] = 0;
980 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
981 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
982 "indirect adressing. Falling back to TGSI "
987 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
988 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
990 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
993 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
994 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
996 ctx
.use_llvm
= use_llvm
;
999 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1000 ctx
.file_offset
[TGSI_FILE_INPUT
];
1002 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1003 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1004 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1006 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1007 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1009 /* Outside the GPR range. This will be translated to one of the
1010 * kcache banks later. */
1011 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1013 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1014 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1015 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1016 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1018 if (indirect_gprs
) {
1019 shader
->max_arrays
= 0;
1020 shader
->num_arrays
= 0;
1022 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1023 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1024 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1025 ctx
.file_offset
[TGSI_FILE_INPUT
],
1028 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1029 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1030 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1031 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1037 ctx
.literals
= NULL
;
1038 shader
->fs_write_all
= FALSE
;
1039 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1040 tgsi_parse_token(&ctx
.parse
);
1041 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1042 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1043 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1044 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1045 if(ctx
.literals
== NULL
) {
1049 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1050 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1051 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1052 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1055 case TGSI_TOKEN_TYPE_DECLARATION
:
1056 r
= tgsi_declaration(&ctx
);
1060 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1062 case TGSI_TOKEN_TYPE_PROPERTY
:
1063 property
= &ctx
.parse
.FullToken
.FullProperty
;
1064 switch (property
->Property
.PropertyName
) {
1065 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1066 if (property
->u
[0].Data
== 1)
1067 shader
->fs_write_all
= TRUE
;
1069 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1070 /* we don't need this one */
1075 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1081 /* Process two side if needed */
1082 if (shader
->two_side
&& ctx
.colors_used
) {
1083 int i
, count
= ctx
.shader
->ninput
;
1084 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1086 /* additional inputs will be allocated right after the existing inputs,
1087 * we won't need them after the color selection, so we don't need to
1088 * reserve these gprs for the rest of the shader code and to adjust
1089 * output offsets etc. */
1090 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1091 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1093 if (ctx
.face_gpr
== -1) {
1094 i
= ctx
.shader
->ninput
++;
1095 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1096 ctx
.shader
->input
[i
].spi_sid
= 0;
1097 ctx
.shader
->input
[i
].gpr
= gpr
++;
1098 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1101 for (i
= 0; i
< count
; i
++) {
1102 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1103 int ni
= ctx
.shader
->ninput
++;
1104 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1105 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1106 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1107 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1108 // TGSI to LLVM needs to know the lds position of inputs.
1109 // Non LLVM path computes it later (in process_twoside_color)
1110 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1111 ctx
.shader
->input
[i
].back_color_input
= ni
;
1112 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1113 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1120 /* LLVM backend setup */
1121 #ifdef R600_USE_LLVM
1123 struct radeon_llvm_context radeon_llvm_ctx
;
1125 bool dump
= r600_can_dump_shader(rscreen
, ctx
.type
);
1126 boolean use_kill
= false;
1128 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1129 radeon_llvm_ctx
.type
= ctx
.type
;
1130 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1131 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1132 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1133 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1134 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
1135 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1136 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
);
1137 radeon_llvm_ctx
.stream_outputs
= &so
;
1138 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1139 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1140 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1141 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1143 if (r600_llvm_compile(mod
, rscreen
->family
, ctx
.bc
, &use_kill
, dump
)) {
1144 radeon_llvm_dispose(&radeon_llvm_ctx
);
1146 fprintf(stderr
, "R600 LLVM backend failed to compile "
1147 "shader. Falling back to TGSI\n");
1149 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1150 ctx
.file_offset
[TGSI_FILE_INPUT
];
1153 ctx
.shader
->uses_kill
= use_kill
;
1154 radeon_llvm_dispose(&radeon_llvm_ctx
);
1157 /* End of LLVM backend setup */
1159 if (shader
->fs_write_all
&& rscreen
->chip_class
>= EVERGREEN
)
1160 shader
->nr_ps_max_color_exports
= 8;
1163 if (ctx
.fragcoord_input
>= 0) {
1164 if (ctx
.bc
->chip_class
== CAYMAN
) {
1165 for (j
= 0 ; j
< 4; j
++) {
1166 struct r600_bytecode_alu alu
;
1167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1168 alu
.op
= ALU_OP1_RECIP_IEEE
;
1169 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1170 alu
.src
[0].chan
= 3;
1172 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1174 alu
.dst
.write
= (j
== 3);
1176 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1180 struct r600_bytecode_alu alu
;
1181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1182 alu
.op
= ALU_OP1_RECIP_IEEE
;
1183 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1184 alu
.src
[0].chan
= 3;
1186 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1190 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1195 if (shader
->two_side
&& ctx
.colors_used
) {
1196 if ((r
= process_twoside_color_inputs(&ctx
)))
1200 tgsi_parse_init(&ctx
.parse
, tokens
);
1201 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1202 tgsi_parse_token(&ctx
.parse
);
1203 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1204 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1205 r
= tgsi_is_supported(&ctx
);
1208 ctx
.max_driver_temp_used
= 0;
1209 /* reserve first tmp for everyone */
1210 r600_get_temp(&ctx
);
1212 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1213 if ((r
= tgsi_split_constant(&ctx
)))
1215 if ((r
= tgsi_split_literal_constant(&ctx
)))
1217 if (ctx
.bc
->chip_class
== CAYMAN
)
1218 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1219 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1220 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1222 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1223 r
= ctx
.inst_info
->process(&ctx
);
1233 /* Reset the temporary register counter. */
1234 ctx
.max_driver_temp_used
= 0;
1236 noutput
= shader
->noutput
;
1238 if (ctx
.clip_vertex_write
) {
1239 unsigned clipdist_temp
[2];
1241 clipdist_temp
[0] = r600_get_temp(&ctx
);
1242 clipdist_temp
[1] = r600_get_temp(&ctx
);
1244 /* need to convert a clipvertex write into clipdistance writes and not export
1245 the clip vertex anymore */
1247 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1248 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1249 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1251 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1252 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1255 /* reset spi_sid for clipvertex output to avoid confusing spi */
1256 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1258 shader
->clip_dist_write
= 0xFF;
1260 for (i
= 0; i
< 8; i
++) {
1264 for (j
= 0; j
< 4; j
++) {
1265 struct r600_bytecode_alu alu
;
1266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1267 alu
.op
= ALU_OP2_DOT4
;
1268 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1269 alu
.src
[0].chan
= j
;
1271 alu
.src
[1].sel
= 512 + i
;
1272 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1273 alu
.src
[1].chan
= j
;
1275 alu
.dst
.sel
= clipdist_temp
[oreg
];
1277 alu
.dst
.write
= (j
== ochan
);
1281 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1288 /* Add stream outputs. */
1289 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& so
.num_outputs
&& !use_llvm
) {
1290 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1292 /* Sanity checking. */
1293 if (so
.num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1294 R600_ERR("Too many stream outputs: %d\n", so
.num_outputs
);
1298 for (i
= 0; i
< so
.num_outputs
; i
++) {
1299 if (so
.output
[i
].output_buffer
>= 4) {
1300 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1301 so
.output
[i
].output_buffer
);
1307 /* Initialize locations where the outputs are stored. */
1308 for (i
= 0; i
< so
.num_outputs
; i
++) {
1309 so_gpr
[i
] = shader
->output
[so
.output
[i
].register_index
].gpr
;
1311 /* Lower outputs with dst_offset < start_component.
1313 * We can only output 4D vectors with a write mask, e.g. we can
1314 * only output the W component at offset 3, etc. If we want
1315 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1316 * to move it to X and output X. */
1317 if (so
.output
[i
].dst_offset
< so
.output
[i
].start_component
) {
1318 unsigned tmp
= r600_get_temp(&ctx
);
1320 for (j
= 0; j
< so
.output
[i
].num_components
; j
++) {
1321 struct r600_bytecode_alu alu
;
1322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1323 alu
.op
= ALU_OP1_MOV
;
1324 alu
.src
[0].sel
= so_gpr
[i
];
1325 alu
.src
[0].chan
= so
.output
[i
].start_component
+ j
;
1330 if (j
== so
.output
[i
].num_components
- 1)
1332 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1336 so
.output
[i
].start_component
= 0;
1341 /* Write outputs to buffers. */
1342 for (i
= 0; i
< so
.num_outputs
; i
++) {
1343 struct r600_bytecode_output output
;
1345 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1346 output
.gpr
= so_gpr
[i
];
1347 output
.elem_size
= so
.output
[i
].num_components
;
1348 output
.array_base
= so
.output
[i
].dst_offset
- so
.output
[i
].start_component
;
1349 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1350 output
.burst_count
= 1;
1352 /* array_size is an upper limit for the burst_count
1353 * with MEM_STREAM instructions */
1354 output
.array_size
= 0xFFF;
1355 output
.comp_mask
= ((1 << so
.output
[i
].num_components
) - 1) << so
.output
[i
].start_component
;
1356 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1357 switch (so
.output
[i
].output_buffer
) {
1359 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1362 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1365 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1368 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1372 switch (so
.output
[i
].output_buffer
) {
1374 output
.op
= CF_OP_MEM_STREAM0
;
1377 output
.op
= CF_OP_MEM_STREAM1
;
1380 output
.op
= CF_OP_MEM_STREAM2
;
1383 output
.op
= CF_OP_MEM_STREAM3
;
1387 r
= r600_bytecode_add_output(ctx
.bc
, &output
);
1394 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1395 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1396 output
[j
].gpr
= shader
->output
[i
].gpr
;
1397 output
[j
].elem_size
= 3;
1398 output
[j
].swizzle_x
= 0;
1399 output
[j
].swizzle_y
= 1;
1400 output
[j
].swizzle_z
= 2;
1401 output
[j
].swizzle_w
= 3;
1402 output
[j
].burst_count
= 1;
1403 output
[j
].barrier
= 1;
1404 output
[j
].type
= -1;
1405 output
[j
].op
= CF_OP_EXPORT
;
1407 case TGSI_PROCESSOR_VERTEX
:
1408 switch (shader
->output
[i
].name
) {
1409 case TGSI_SEMANTIC_POSITION
:
1410 output
[j
].array_base
= next_pos_base
++;
1411 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1414 case TGSI_SEMANTIC_PSIZE
:
1415 output
[j
].array_base
= next_pos_base
++;
1416 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1418 case TGSI_SEMANTIC_CLIPVERTEX
:
1421 case TGSI_SEMANTIC_CLIPDIST
:
1422 output
[j
].array_base
= next_pos_base
++;
1423 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1424 /* spi_sid is 0 for clipdistance outputs that were generated
1425 * for clipvertex - we don't need to pass them to PS */
1426 if (shader
->output
[i
].spi_sid
) {
1428 /* duplicate it as PARAM to pass to the pixel shader */
1429 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1430 output
[j
].array_base
= next_param_base
++;
1431 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1434 case TGSI_SEMANTIC_FOG
:
1435 output
[j
].swizzle_y
= 4; /* 0 */
1436 output
[j
].swizzle_z
= 4; /* 0 */
1437 output
[j
].swizzle_w
= 5; /* 1 */
1441 case TGSI_PROCESSOR_FRAGMENT
:
1442 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1443 /* never export more colors than the number of CBs */
1444 if (shader
->output
[i
].sid
>= max_color_exports
) {
1449 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1450 output
[j
].array_base
= shader
->output
[i
].sid
;
1451 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1452 shader
->nr_ps_color_exports
++;
1453 if (shader
->fs_write_all
&& (rscreen
->chip_class
>= EVERGREEN
)) {
1454 for (k
= 1; k
< max_color_exports
; k
++) {
1456 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1457 output
[j
].gpr
= shader
->output
[i
].gpr
;
1458 output
[j
].elem_size
= 3;
1459 output
[j
].swizzle_x
= 0;
1460 output
[j
].swizzle_y
= 1;
1461 output
[j
].swizzle_z
= 2;
1462 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1463 output
[j
].burst_count
= 1;
1464 output
[j
].barrier
= 1;
1465 output
[j
].array_base
= k
;
1466 output
[j
].op
= CF_OP_EXPORT
;
1467 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1468 shader
->nr_ps_color_exports
++;
1471 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1472 output
[j
].array_base
= 61;
1473 output
[j
].swizzle_x
= 2;
1474 output
[j
].swizzle_y
= 7;
1475 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1476 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1477 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1478 output
[j
].array_base
= 61;
1479 output
[j
].swizzle_x
= 7;
1480 output
[j
].swizzle_y
= 1;
1481 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1482 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1484 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1490 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1495 if (output
[j
].type
==-1) {
1496 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1497 output
[j
].array_base
= next_param_base
++;
1501 /* add fake position export */
1502 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1503 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1505 output
[j
].elem_size
= 3;
1506 output
[j
].swizzle_x
= 7;
1507 output
[j
].swizzle_y
= 7;
1508 output
[j
].swizzle_z
= 7;
1509 output
[j
].swizzle_w
= 7;
1510 output
[j
].burst_count
= 1;
1511 output
[j
].barrier
= 1;
1512 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1513 output
[j
].array_base
= next_pos_base
;
1514 output
[j
].op
= CF_OP_EXPORT
;
1518 /* add fake param output for vertex shader if no param is exported */
1519 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1520 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1522 output
[j
].elem_size
= 3;
1523 output
[j
].swizzle_x
= 7;
1524 output
[j
].swizzle_y
= 7;
1525 output
[j
].swizzle_z
= 7;
1526 output
[j
].swizzle_w
= 7;
1527 output
[j
].burst_count
= 1;
1528 output
[j
].barrier
= 1;
1529 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1530 output
[j
].array_base
= 0;
1531 output
[j
].op
= CF_OP_EXPORT
;
1535 /* add fake pixel export */
1536 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
1537 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1539 output
[j
].elem_size
= 3;
1540 output
[j
].swizzle_x
= 7;
1541 output
[j
].swizzle_y
= 7;
1542 output
[j
].swizzle_z
= 7;
1543 output
[j
].swizzle_w
= 7;
1544 output
[j
].burst_count
= 1;
1545 output
[j
].barrier
= 1;
1546 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1547 output
[j
].array_base
= 0;
1548 output
[j
].op
= CF_OP_EXPORT
;
1554 /* set export done on last export of each type */
1555 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1556 if (ctx
.bc
->chip_class
< CAYMAN
) {
1557 if (i
== (noutput
- 1)) {
1558 output
[i
].end_of_program
= 1;
1561 if (!(output_done
& (1 << output
[i
].type
))) {
1562 output_done
|= (1 << output
[i
].type
);
1563 output
[i
].op
= CF_OP_EXPORT_DONE
;
1566 /* add output to bytecode */
1568 for (i
= 0; i
< noutput
; i
++) {
1569 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1574 /* add program end */
1575 if (!use_llvm
&& ctx
.bc
->chip_class
== CAYMAN
)
1576 cm_bytecode_add_cf_end(ctx
.bc
);
1578 /* check GPR limit - we have 124 = 128 - 4
1579 * (4 are reserved as alu clause temporary registers) */
1580 if (ctx
.bc
->ngpr
> 124) {
1581 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1587 tgsi_parse_free(&ctx
.parse
);
1591 tgsi_parse_free(&ctx
.parse
);
1595 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1597 R600_ERR("%s tgsi opcode unsupported\n",
1598 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1602 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1607 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1608 const struct r600_shader_src
*shader_src
,
1611 bc_src
->sel
= shader_src
->sel
;
1612 bc_src
->chan
= shader_src
->swizzle
[chan
];
1613 bc_src
->neg
= shader_src
->neg
;
1614 bc_src
->abs
= shader_src
->abs
;
1615 bc_src
->rel
= shader_src
->rel
;
1616 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1617 bc_src
->kc_bank
= shader_src
->kc_bank
;
1620 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
1626 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
1628 bc_src
->neg
= !bc_src
->neg
;
1631 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
1632 const struct tgsi_full_dst_register
*tgsi_dst
,
1634 struct r600_bytecode_alu_dst
*r600_dst
)
1636 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1638 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
1639 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
1640 r600_dst
->chan
= swizzle
;
1641 r600_dst
->write
= 1;
1642 if (tgsi_dst
->Register
.Indirect
)
1643 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
1644 if (inst
->Instruction
.Saturate
) {
1645 r600_dst
->clamp
= 1;
1649 static int tgsi_last_instruction(unsigned writemask
)
1653 for (i
= 0; i
< 4; i
++) {
1654 if (writemask
& (1 << i
)) {
1661 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
1663 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1664 struct r600_bytecode_alu alu
;
1666 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1668 for (i
= 0; i
< lasti
+ 1; i
++) {
1669 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1672 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1673 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1675 alu
.op
= ctx
->inst_info
->op
;
1677 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1678 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
1681 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
1682 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1684 /* handle some special cases */
1685 switch (ctx
->inst_info
->tgsi_opcode
) {
1686 case TGSI_OPCODE_SUB
:
1687 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
1689 case TGSI_OPCODE_ABS
:
1690 r600_bytecode_src_set_abs(&alu
.src
[0]);
1695 if (i
== lasti
|| trans_only
) {
1698 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1705 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
1707 return tgsi_op2_s(ctx
, 0, 0);
1710 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
1712 return tgsi_op2_s(ctx
, 1, 0);
1715 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
1717 return tgsi_op2_s(ctx
, 0, 1);
1720 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
1722 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1723 struct r600_bytecode_alu alu
;
1725 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1727 for (i
= 0; i
< lasti
+ 1; i
++) {
1729 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1732 alu
.op
= ctx
->inst_info
->op
;
1734 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1736 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
1738 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1743 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1751 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
1753 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1755 struct r600_bytecode_alu alu
;
1756 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1758 for (i
= 0 ; i
< last_slot
; i
++) {
1759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1760 alu
.op
= ctx
->inst_info
->op
;
1761 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1762 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
1764 /* RSQ should take the absolute value of src */
1765 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
1766 r600_bytecode_src_set_abs(&alu
.src
[j
]);
1769 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1770 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1772 if (i
== last_slot
- 1)
1774 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1781 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
1783 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1785 struct r600_bytecode_alu alu
;
1786 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1787 for (k
= 0; k
< last_slot
; k
++) {
1788 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
1791 for (i
= 0 ; i
< 4; i
++) {
1792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1793 alu
.op
= ctx
->inst_info
->op
;
1794 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
1795 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
1797 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1798 alu
.dst
.write
= (i
== k
);
1801 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1810 * r600 - trunc to -PI..PI range
1811 * r700 - normalize by dividing by 2PI
1814 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
1816 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
1817 static float double_pi
= 3.1415926535 * 2;
1818 static float neg_pi
= -3.1415926535;
1821 struct r600_bytecode_alu alu
;
1823 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1824 alu
.op
= ALU_OP3_MULADD
;
1828 alu
.dst
.sel
= ctx
->temp_reg
;
1831 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
1833 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1834 alu
.src
[1].chan
= 0;
1835 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
1836 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1837 alu
.src
[2].chan
= 0;
1839 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1843 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1844 alu
.op
= ALU_OP1_FRACT
;
1847 alu
.dst
.sel
= ctx
->temp_reg
;
1850 alu
.src
[0].sel
= ctx
->temp_reg
;
1851 alu
.src
[0].chan
= 0;
1853 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1857 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1858 alu
.op
= ALU_OP3_MULADD
;
1862 alu
.dst
.sel
= ctx
->temp_reg
;
1865 alu
.src
[0].sel
= ctx
->temp_reg
;
1866 alu
.src
[0].chan
= 0;
1868 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1869 alu
.src
[1].chan
= 0;
1870 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
1871 alu
.src
[2].chan
= 0;
1873 if (ctx
->bc
->chip_class
== R600
) {
1874 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
1875 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
1877 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
1878 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
1883 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1889 static int cayman_trig(struct r600_shader_ctx
*ctx
)
1891 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1892 struct r600_bytecode_alu alu
;
1893 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
1896 r
= tgsi_setup_trig(ctx
);
1901 for (i
= 0; i
< last_slot
; i
++) {
1902 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1903 alu
.op
= ctx
->inst_info
->op
;
1906 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1907 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
1909 alu
.src
[0].sel
= ctx
->temp_reg
;
1910 alu
.src
[0].chan
= 0;
1911 if (i
== last_slot
- 1)
1913 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1920 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
1922 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1923 struct r600_bytecode_alu alu
;
1925 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
1927 r
= tgsi_setup_trig(ctx
);
1931 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1932 alu
.op
= ctx
->inst_info
->op
;
1934 alu
.dst
.sel
= ctx
->temp_reg
;
1937 alu
.src
[0].sel
= ctx
->temp_reg
;
1938 alu
.src
[0].chan
= 0;
1940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1944 /* replicate result */
1945 for (i
= 0; i
< lasti
+ 1; i
++) {
1946 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
1949 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1950 alu
.op
= ALU_OP1_MOV
;
1952 alu
.src
[0].sel
= ctx
->temp_reg
;
1953 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1963 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
1965 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1966 struct r600_bytecode_alu alu
;
1969 /* We'll only need the trig stuff if we are going to write to the
1970 * X or Y components of the destination vector.
1972 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
1973 r
= tgsi_setup_trig(ctx
);
1979 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
1980 if (ctx
->bc
->chip_class
== CAYMAN
) {
1981 for (i
= 0 ; i
< 3; i
++) {
1982 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1983 alu
.op
= ALU_OP1_COS
;
1984 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
1990 alu
.src
[0].sel
= ctx
->temp_reg
;
1991 alu
.src
[0].chan
= 0;
1994 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1999 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2000 alu
.op
= ALU_OP1_COS
;
2001 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2003 alu
.src
[0].sel
= ctx
->temp_reg
;
2004 alu
.src
[0].chan
= 0;
2006 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2013 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2014 if (ctx
->bc
->chip_class
== CAYMAN
) {
2015 for (i
= 0 ; i
< 3; i
++) {
2016 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2017 alu
.op
= ALU_OP1_SIN
;
2018 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2023 alu
.src
[0].sel
= ctx
->temp_reg
;
2024 alu
.src
[0].chan
= 0;
2027 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2033 alu
.op
= ALU_OP1_SIN
;
2034 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2036 alu
.src
[0].sel
= ctx
->temp_reg
;
2037 alu
.src
[0].chan
= 0;
2039 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2046 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2047 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2049 alu
.op
= ALU_OP1_MOV
;
2051 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2053 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2054 alu
.src
[0].chan
= 0;
2058 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2064 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2065 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2067 alu
.op
= ALU_OP1_MOV
;
2069 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2071 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2072 alu
.src
[0].chan
= 0;
2076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2084 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2086 struct r600_bytecode_alu alu
;
2089 for (i
= 0; i
< 4; i
++) {
2090 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2091 alu
.op
= ctx
->inst_info
->op
;
2095 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2097 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILL
) {
2098 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2101 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2111 /* kill must be last in ALU */
2112 ctx
->bc
->force_add_cf
= 1;
2113 ctx
->shader
->uses_kill
= TRUE
;
2117 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2119 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2120 struct r600_bytecode_alu alu
;
2123 /* tmp.x = max(src.y, 0.0) */
2124 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2125 alu
.op
= ALU_OP2_MAX
;
2126 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2127 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2128 alu
.src
[1].chan
= 1;
2130 alu
.dst
.sel
= ctx
->temp_reg
;
2135 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2139 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2145 if (ctx
->bc
->chip_class
== CAYMAN
) {
2146 for (i
= 0; i
< 3; i
++) {
2147 /* tmp.z = log(tmp.x) */
2148 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2149 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2150 alu
.src
[0].sel
= ctx
->temp_reg
;
2151 alu
.src
[0].chan
= 0;
2152 alu
.dst
.sel
= ctx
->temp_reg
;
2160 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2165 /* tmp.z = log(tmp.x) */
2166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2167 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2168 alu
.src
[0].sel
= ctx
->temp_reg
;
2169 alu
.src
[0].chan
= 0;
2170 alu
.dst
.sel
= ctx
->temp_reg
;
2174 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2179 chan
= alu
.dst
.chan
;
2182 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2183 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2184 alu
.op
= ALU_OP3_MUL_LIT
;
2185 alu
.src
[0].sel
= sel
;
2186 alu
.src
[0].chan
= chan
;
2187 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2188 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2189 alu
.dst
.sel
= ctx
->temp_reg
;
2194 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2198 if (ctx
->bc
->chip_class
== CAYMAN
) {
2199 for (i
= 0; i
< 3; i
++) {
2200 /* dst.z = exp(tmp.x) */
2201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2202 alu
.op
= ALU_OP1_EXP_IEEE
;
2203 alu
.src
[0].sel
= ctx
->temp_reg
;
2204 alu
.src
[0].chan
= 0;
2205 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2211 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2216 /* dst.z = exp(tmp.x) */
2217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2218 alu
.op
= ALU_OP1_EXP_IEEE
;
2219 alu
.src
[0].sel
= ctx
->temp_reg
;
2220 alu
.src
[0].chan
= 0;
2221 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2223 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2231 alu
.op
= ALU_OP1_MOV
;
2232 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2233 alu
.src
[0].chan
= 0;
2234 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2235 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2236 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2240 /* dst.y = max(src.x, 0.0) */
2241 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2242 alu
.op
= ALU_OP2_MAX
;
2243 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2244 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2245 alu
.src
[1].chan
= 0;
2246 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2247 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2248 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2254 alu
.op
= ALU_OP1_MOV
;
2255 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2256 alu
.src
[0].chan
= 0;
2257 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2258 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2260 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2267 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2269 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2270 struct r600_bytecode_alu alu
;
2273 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2276 * For state trackers other than OpenGL, we'll want to use
2277 * _RECIPSQRT_IEEE instead.
2279 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2281 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2282 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2283 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2285 alu
.dst
.sel
= ctx
->temp_reg
;
2288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2291 /* replicate result */
2292 return tgsi_helper_tempx_replicate(ctx
);
2295 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2297 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2298 struct r600_bytecode_alu alu
;
2301 for (i
= 0; i
< 4; i
++) {
2302 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2303 alu
.src
[0].sel
= ctx
->temp_reg
;
2304 alu
.op
= ALU_OP1_MOV
;
2306 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2307 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2310 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2317 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2319 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2320 struct r600_bytecode_alu alu
;
2323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2324 alu
.op
= ctx
->inst_info
->op
;
2325 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2326 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2328 alu
.dst
.sel
= ctx
->temp_reg
;
2331 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2334 /* replicate result */
2335 return tgsi_helper_tempx_replicate(ctx
);
2338 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2340 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2342 struct r600_bytecode_alu alu
;
2343 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2345 for (i
= 0; i
< 3; i
++) {
2346 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2347 alu
.op
= ALU_OP1_LOG_IEEE
;
2348 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2349 alu
.dst
.sel
= ctx
->temp_reg
;
2354 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2360 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2361 alu
.op
= ALU_OP2_MUL
;
2362 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2363 alu
.src
[1].sel
= ctx
->temp_reg
;
2364 alu
.dst
.sel
= ctx
->temp_reg
;
2367 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2371 for (i
= 0; i
< last_slot
; i
++) {
2372 /* POW(a,b) = EXP2(b * LOG2(a))*/
2373 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2374 alu
.op
= ALU_OP1_EXP_IEEE
;
2375 alu
.src
[0].sel
= ctx
->temp_reg
;
2377 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2378 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2379 if (i
== last_slot
- 1)
2381 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2388 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2390 struct r600_bytecode_alu alu
;
2394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2395 alu
.op
= ALU_OP1_LOG_IEEE
;
2396 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2397 alu
.dst
.sel
= ctx
->temp_reg
;
2400 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2404 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2405 alu
.op
= ALU_OP2_MUL
;
2406 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2407 alu
.src
[1].sel
= ctx
->temp_reg
;
2408 alu
.dst
.sel
= ctx
->temp_reg
;
2411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2414 /* POW(a,b) = EXP2(b * LOG2(a))*/
2415 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2416 alu
.op
= ALU_OP1_EXP_IEEE
;
2417 alu
.src
[0].sel
= ctx
->temp_reg
;
2418 alu
.dst
.sel
= ctx
->temp_reg
;
2421 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2424 return tgsi_helper_tempx_replicate(ctx
);
2427 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2429 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2430 struct r600_bytecode_alu alu
;
2432 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2433 int tmp0
= ctx
->temp_reg
;
2434 int tmp1
= r600_get_temp(ctx
);
2435 int tmp2
= r600_get_temp(ctx
);
2436 int tmp3
= r600_get_temp(ctx
);
2439 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2441 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2442 * 2. tmp0.z = lo (tmp0.x * src2)
2443 * 3. tmp0.w = -tmp0.z
2444 * 4. tmp0.y = hi (tmp0.x * src2)
2445 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2446 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2447 * 7. tmp1.x = tmp0.x - tmp0.w
2448 * 8. tmp1.y = tmp0.x + tmp0.w
2449 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2450 * 10. tmp0.z = hi(tmp0.x * src1) = q
2451 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2453 * 12. tmp0.w = src1 - tmp0.y = r
2454 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2455 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2459 * 15. tmp1.z = tmp0.z + 1 = q + 1
2460 * 16. tmp1.w = tmp0.z - 1 = q - 1
2464 * 15. tmp1.z = tmp0.w - src2 = r - src2
2465 * 16. tmp1.w = tmp0.w + src2 = r + src2
2469 * 17. tmp1.x = tmp1.x & tmp1.y
2471 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2472 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2474 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2475 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2479 * Same as unsigned, using abs values of the operands,
2480 * and fixing the sign of the result in the end.
2483 for (i
= 0; i
< 4; i
++) {
2484 if (!(write_mask
& (1<<i
)))
2489 /* tmp2.x = -src0 */
2490 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2491 alu
.op
= ALU_OP2_SUB_INT
;
2497 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2499 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2502 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2505 /* tmp2.y = -src1 */
2506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2507 alu
.op
= ALU_OP2_SUB_INT
;
2513 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2515 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2518 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2521 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2522 /* it will be a sign of the quotient */
2525 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2526 alu
.op
= ALU_OP2_XOR_INT
;
2532 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2533 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2536 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2540 /* tmp2.x = |src0| */
2541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2542 alu
.op
= ALU_OP3_CNDGE_INT
;
2549 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2550 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2551 alu
.src
[2].sel
= tmp2
;
2552 alu
.src
[2].chan
= 0;
2555 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2558 /* tmp2.y = |src1| */
2559 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2560 alu
.op
= ALU_OP3_CNDGE_INT
;
2567 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2568 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2569 alu
.src
[2].sel
= tmp2
;
2570 alu
.src
[2].chan
= 1;
2573 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2578 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2579 if (ctx
->bc
->chip_class
== CAYMAN
) {
2580 /* tmp3.x = u2f(src2) */
2581 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2582 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2589 alu
.src
[0].sel
= tmp2
;
2590 alu
.src
[0].chan
= 1;
2592 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2596 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2599 /* tmp0.x = recip(tmp3.x) */
2600 for (j
= 0 ; j
< 3; j
++) {
2601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2602 alu
.op
= ALU_OP1_RECIP_IEEE
;
2606 alu
.dst
.write
= (j
== 0);
2608 alu
.src
[0].sel
= tmp3
;
2609 alu
.src
[0].chan
= 0;
2613 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2617 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2618 alu
.op
= ALU_OP2_MUL
;
2620 alu
.src
[0].sel
= tmp0
;
2621 alu
.src
[0].chan
= 0;
2623 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2624 alu
.src
[1].value
= 0x4f800000;
2629 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2633 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2634 alu
.op
= ALU_OP1_FLT_TO_UINT
;
2640 alu
.src
[0].sel
= tmp3
;
2641 alu
.src
[0].chan
= 0;
2644 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2648 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2649 alu
.op
= ALU_OP1_RECIP_UINT
;
2656 alu
.src
[0].sel
= tmp2
;
2657 alu
.src
[0].chan
= 1;
2659 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2663 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2667 /* 2. tmp0.z = lo (tmp0.x * src2) */
2668 if (ctx
->bc
->chip_class
== CAYMAN
) {
2669 for (j
= 0 ; j
< 4; j
++) {
2670 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2671 alu
.op
= ALU_OP2_MULLO_UINT
;
2675 alu
.dst
.write
= (j
== 2);
2677 alu
.src
[0].sel
= tmp0
;
2678 alu
.src
[0].chan
= 0;
2680 alu
.src
[1].sel
= tmp2
;
2681 alu
.src
[1].chan
= 1;
2683 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2686 alu
.last
= (j
== 3);
2687 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2691 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2692 alu
.op
= ALU_OP2_MULLO_UINT
;
2698 alu
.src
[0].sel
= tmp0
;
2699 alu
.src
[0].chan
= 0;
2701 alu
.src
[1].sel
= tmp2
;
2702 alu
.src
[1].chan
= 1;
2704 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2708 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2712 /* 3. tmp0.w = -tmp0.z */
2713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2714 alu
.op
= ALU_OP2_SUB_INT
;
2720 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2721 alu
.src
[1].sel
= tmp0
;
2722 alu
.src
[1].chan
= 2;
2725 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2728 /* 4. tmp0.y = hi (tmp0.x * src2) */
2729 if (ctx
->bc
->chip_class
== CAYMAN
) {
2730 for (j
= 0 ; j
< 4; j
++) {
2731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2732 alu
.op
= ALU_OP2_MULHI_UINT
;
2736 alu
.dst
.write
= (j
== 1);
2738 alu
.src
[0].sel
= tmp0
;
2739 alu
.src
[0].chan
= 0;
2742 alu
.src
[1].sel
= tmp2
;
2743 alu
.src
[1].chan
= 1;
2745 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2747 alu
.last
= (j
== 3);
2748 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2752 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2753 alu
.op
= ALU_OP2_MULHI_UINT
;
2759 alu
.src
[0].sel
= tmp0
;
2760 alu
.src
[0].chan
= 0;
2763 alu
.src
[1].sel
= tmp2
;
2764 alu
.src
[1].chan
= 1;
2766 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2770 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2774 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
2775 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2776 alu
.op
= ALU_OP3_CNDE_INT
;
2783 alu
.src
[0].sel
= tmp0
;
2784 alu
.src
[0].chan
= 1;
2785 alu
.src
[1].sel
= tmp0
;
2786 alu
.src
[1].chan
= 3;
2787 alu
.src
[2].sel
= tmp0
;
2788 alu
.src
[2].chan
= 2;
2791 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2794 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
2795 if (ctx
->bc
->chip_class
== CAYMAN
) {
2796 for (j
= 0 ; j
< 4; j
++) {
2797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2798 alu
.op
= ALU_OP2_MULHI_UINT
;
2802 alu
.dst
.write
= (j
== 3);
2804 alu
.src
[0].sel
= tmp0
;
2805 alu
.src
[0].chan
= 2;
2807 alu
.src
[1].sel
= tmp0
;
2808 alu
.src
[1].chan
= 0;
2810 alu
.last
= (j
== 3);
2811 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2815 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2816 alu
.op
= ALU_OP2_MULHI_UINT
;
2822 alu
.src
[0].sel
= tmp0
;
2823 alu
.src
[0].chan
= 2;
2825 alu
.src
[1].sel
= tmp0
;
2826 alu
.src
[1].chan
= 0;
2829 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2833 /* 7. tmp1.x = tmp0.x - tmp0.w */
2834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2835 alu
.op
= ALU_OP2_SUB_INT
;
2841 alu
.src
[0].sel
= tmp0
;
2842 alu
.src
[0].chan
= 0;
2843 alu
.src
[1].sel
= tmp0
;
2844 alu
.src
[1].chan
= 3;
2847 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2850 /* 8. tmp1.y = tmp0.x + tmp0.w */
2851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2852 alu
.op
= ALU_OP2_ADD_INT
;
2858 alu
.src
[0].sel
= tmp0
;
2859 alu
.src
[0].chan
= 0;
2860 alu
.src
[1].sel
= tmp0
;
2861 alu
.src
[1].chan
= 3;
2864 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2867 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
2868 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2869 alu
.op
= ALU_OP3_CNDE_INT
;
2876 alu
.src
[0].sel
= tmp0
;
2877 alu
.src
[0].chan
= 1;
2878 alu
.src
[1].sel
= tmp1
;
2879 alu
.src
[1].chan
= 1;
2880 alu
.src
[2].sel
= tmp1
;
2881 alu
.src
[2].chan
= 0;
2884 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2887 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
2888 if (ctx
->bc
->chip_class
== CAYMAN
) {
2889 for (j
= 0 ; j
< 4; j
++) {
2890 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2891 alu
.op
= ALU_OP2_MULHI_UINT
;
2895 alu
.dst
.write
= (j
== 2);
2897 alu
.src
[0].sel
= tmp0
;
2898 alu
.src
[0].chan
= 0;
2901 alu
.src
[1].sel
= tmp2
;
2902 alu
.src
[1].chan
= 0;
2904 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2907 alu
.last
= (j
== 3);
2908 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2912 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2913 alu
.op
= ALU_OP2_MULHI_UINT
;
2919 alu
.src
[0].sel
= tmp0
;
2920 alu
.src
[0].chan
= 0;
2923 alu
.src
[1].sel
= tmp2
;
2924 alu
.src
[1].chan
= 0;
2926 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2930 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2934 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
2935 if (ctx
->bc
->chip_class
== CAYMAN
) {
2936 for (j
= 0 ; j
< 4; j
++) {
2937 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2938 alu
.op
= ALU_OP2_MULLO_UINT
;
2942 alu
.dst
.write
= (j
== 1);
2945 alu
.src
[0].sel
= tmp2
;
2946 alu
.src
[0].chan
= 1;
2948 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2951 alu
.src
[1].sel
= tmp0
;
2952 alu
.src
[1].chan
= 2;
2954 alu
.last
= (j
== 3);
2955 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2960 alu
.op
= ALU_OP2_MULLO_UINT
;
2967 alu
.src
[0].sel
= tmp2
;
2968 alu
.src
[0].chan
= 1;
2970 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2973 alu
.src
[1].sel
= tmp0
;
2974 alu
.src
[1].chan
= 2;
2977 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2981 /* 12. tmp0.w = src1 - tmp0.y = r */
2982 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2983 alu
.op
= ALU_OP2_SUB_INT
;
2990 alu
.src
[0].sel
= tmp2
;
2991 alu
.src
[0].chan
= 0;
2993 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2996 alu
.src
[1].sel
= tmp0
;
2997 alu
.src
[1].chan
= 1;
3000 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3003 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3004 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3005 alu
.op
= ALU_OP2_SETGE_UINT
;
3011 alu
.src
[0].sel
= tmp0
;
3012 alu
.src
[0].chan
= 3;
3014 alu
.src
[1].sel
= tmp2
;
3015 alu
.src
[1].chan
= 1;
3017 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3021 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3024 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3025 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3026 alu
.op
= ALU_OP2_SETGE_UINT
;
3033 alu
.src
[0].sel
= tmp2
;
3034 alu
.src
[0].chan
= 0;
3036 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3039 alu
.src
[1].sel
= tmp0
;
3040 alu
.src
[1].chan
= 1;
3043 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3046 if (mod
) { /* UMOD */
3048 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3050 alu
.op
= ALU_OP2_SUB_INT
;
3056 alu
.src
[0].sel
= tmp0
;
3057 alu
.src
[0].chan
= 3;
3060 alu
.src
[1].sel
= tmp2
;
3061 alu
.src
[1].chan
= 1;
3063 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3067 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3070 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3071 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3072 alu
.op
= ALU_OP2_ADD_INT
;
3078 alu
.src
[0].sel
= tmp0
;
3079 alu
.src
[0].chan
= 3;
3081 alu
.src
[1].sel
= tmp2
;
3082 alu
.src
[1].chan
= 1;
3084 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3088 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3093 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3094 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3095 alu
.op
= ALU_OP2_ADD_INT
;
3101 alu
.src
[0].sel
= tmp0
;
3102 alu
.src
[0].chan
= 2;
3103 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3106 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3109 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3110 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3111 alu
.op
= ALU_OP2_ADD_INT
;
3117 alu
.src
[0].sel
= tmp0
;
3118 alu
.src
[0].chan
= 2;
3119 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3122 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3127 /* 17. tmp1.x = tmp1.x & tmp1.y */
3128 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3129 alu
.op
= ALU_OP2_AND_INT
;
3135 alu
.src
[0].sel
= tmp1
;
3136 alu
.src
[0].chan
= 0;
3137 alu
.src
[1].sel
= tmp1
;
3138 alu
.src
[1].chan
= 1;
3141 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3144 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3145 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3146 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3147 alu
.op
= ALU_OP3_CNDE_INT
;
3154 alu
.src
[0].sel
= tmp1
;
3155 alu
.src
[0].chan
= 0;
3156 alu
.src
[1].sel
= tmp0
;
3157 alu
.src
[1].chan
= mod
? 3 : 2;
3158 alu
.src
[2].sel
= tmp1
;
3159 alu
.src
[2].chan
= 2;
3162 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3165 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3167 alu
.op
= ALU_OP3_CNDE_INT
;
3175 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3178 alu
.src
[0].sel
= tmp1
;
3179 alu
.src
[0].chan
= 1;
3180 alu
.src
[1].sel
= tmp1
;
3181 alu
.src
[1].chan
= 3;
3182 alu
.src
[2].sel
= tmp0
;
3183 alu
.src
[2].chan
= 2;
3186 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3191 /* fix the sign of the result */
3195 /* tmp0.x = -tmp0.z */
3196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3197 alu
.op
= ALU_OP2_SUB_INT
;
3203 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3204 alu
.src
[1].sel
= tmp0
;
3205 alu
.src
[1].chan
= 2;
3208 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3211 /* sign of the remainder is the same as the sign of src0 */
3212 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3213 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3214 alu
.op
= ALU_OP3_CNDGE_INT
;
3217 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3219 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3220 alu
.src
[1].sel
= tmp0
;
3221 alu
.src
[1].chan
= 2;
3222 alu
.src
[2].sel
= tmp0
;
3223 alu
.src
[2].chan
= 0;
3226 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3231 /* tmp0.x = -tmp0.z */
3232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3233 alu
.op
= ALU_OP2_SUB_INT
;
3239 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3240 alu
.src
[1].sel
= tmp0
;
3241 alu
.src
[1].chan
= 2;
3244 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3247 /* fix the quotient sign (same as the sign of src0*src1) */
3248 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3250 alu
.op
= ALU_OP3_CNDGE_INT
;
3253 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3255 alu
.src
[0].sel
= tmp2
;
3256 alu
.src
[0].chan
= 2;
3257 alu
.src
[1].sel
= tmp0
;
3258 alu
.src
[1].chan
= 2;
3259 alu
.src
[2].sel
= tmp0
;
3260 alu
.src
[2].chan
= 0;
3263 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3271 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3273 return tgsi_divmod(ctx
, 0, 0);
3276 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3278 return tgsi_divmod(ctx
, 1, 0);
3281 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3283 return tgsi_divmod(ctx
, 0, 1);
3286 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3288 return tgsi_divmod(ctx
, 1, 1);
3292 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3294 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3295 struct r600_bytecode_alu alu
;
3297 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3298 int last_inst
= tgsi_last_instruction(write_mask
);
3300 for (i
= 0; i
< 4; i
++) {
3301 if (!(write_mask
& (1<<i
)))
3304 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3305 alu
.op
= ALU_OP1_TRUNC
;
3307 alu
.dst
.sel
= ctx
->temp_reg
;
3311 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3314 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3319 for (i
= 0; i
< 4; i
++) {
3320 if (!(write_mask
& (1<<i
)))
3323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3324 alu
.op
= ctx
->inst_info
->op
;
3326 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3328 alu
.src
[0].sel
= ctx
->temp_reg
;
3329 alu
.src
[0].chan
= i
;
3331 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3333 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3341 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3343 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3344 struct r600_bytecode_alu alu
;
3346 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3347 int last_inst
= tgsi_last_instruction(write_mask
);
3350 for (i
= 0; i
< 4; i
++) {
3351 if (!(write_mask
& (1<<i
)))
3354 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3355 alu
.op
= ALU_OP2_SUB_INT
;
3357 alu
.dst
.sel
= ctx
->temp_reg
;
3361 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3362 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3371 /* dst = (src >= 0 ? src : tmp) */
3372 for (i
= 0; i
< 4; i
++) {
3373 if (!(write_mask
& (1<<i
)))
3376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3377 alu
.op
= ALU_OP3_CNDGE_INT
;
3381 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3383 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3384 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3385 alu
.src
[2].sel
= ctx
->temp_reg
;
3386 alu
.src
[2].chan
= i
;
3390 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3397 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3399 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3400 struct r600_bytecode_alu alu
;
3402 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3403 int last_inst
= tgsi_last_instruction(write_mask
);
3405 /* tmp = (src >= 0 ? src : -1) */
3406 for (i
= 0; i
< 4; i
++) {
3407 if (!(write_mask
& (1<<i
)))
3410 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3411 alu
.op
= ALU_OP3_CNDGE_INT
;
3414 alu
.dst
.sel
= ctx
->temp_reg
;
3418 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3419 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3420 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3429 /* dst = (tmp > 0 ? 1 : tmp) */
3430 for (i
= 0; i
< 4; i
++) {
3431 if (!(write_mask
& (1<<i
)))
3434 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3435 alu
.op
= ALU_OP3_CNDGT_INT
;
3439 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3441 alu
.src
[0].sel
= ctx
->temp_reg
;
3442 alu
.src
[0].chan
= i
;
3444 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3446 alu
.src
[2].sel
= ctx
->temp_reg
;
3447 alu
.src
[2].chan
= i
;
3451 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3460 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3462 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3463 struct r600_bytecode_alu alu
;
3466 /* tmp = (src > 0 ? 1 : src) */
3467 for (i
= 0; i
< 4; i
++) {
3468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3469 alu
.op
= ALU_OP3_CNDGT
;
3472 alu
.dst
.sel
= ctx
->temp_reg
;
3475 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3476 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3477 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3481 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3486 /* dst = (-tmp > 0 ? -1 : tmp) */
3487 for (i
= 0; i
< 4; i
++) {
3488 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3489 alu
.op
= ALU_OP3_CNDGT
;
3491 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3493 alu
.src
[0].sel
= ctx
->temp_reg
;
3494 alu
.src
[0].chan
= i
;
3497 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3500 alu
.src
[2].sel
= ctx
->temp_reg
;
3501 alu
.src
[2].chan
= i
;
3505 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3512 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3514 struct r600_bytecode_alu alu
;
3517 for (i
= 0; i
< 4; i
++) {
3518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3519 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3520 alu
.op
= ALU_OP0_NOP
;
3523 alu
.op
= ALU_OP1_MOV
;
3524 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3525 alu
.src
[0].sel
= ctx
->temp_reg
;
3526 alu
.src
[0].chan
= i
;
3531 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3538 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3540 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3541 struct r600_bytecode_alu alu
;
3543 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3545 for (i
= 0; i
< lasti
+ 1; i
++) {
3546 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3550 alu
.op
= ctx
->inst_info
->op
;
3551 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3552 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3555 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3569 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3571 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3572 struct r600_bytecode_alu alu
;
3575 for (i
= 0; i
< 4; i
++) {
3576 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3577 alu
.op
= ctx
->inst_info
->op
;
3578 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3579 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3582 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3584 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3585 /* handle some special cases */
3586 switch (ctx
->inst_info
->tgsi_opcode
) {
3587 case TGSI_OPCODE_DP2
:
3589 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3590 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3593 case TGSI_OPCODE_DP3
:
3595 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3596 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3599 case TGSI_OPCODE_DPH
:
3601 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3602 alu
.src
[0].chan
= 0;
3612 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3619 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
3622 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3623 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
3624 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
3625 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
3626 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
3629 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
3632 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3633 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
3636 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
3638 struct r600_bytecode_vtx vtx
;
3639 struct r600_bytecode_alu alu
;
3640 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3642 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3644 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3645 if (src_requires_loading
) {
3646 for (i
= 0; i
< 4; i
++) {
3647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3648 alu
.op
= ALU_OP1_MOV
;
3649 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3650 alu
.dst
.sel
= ctx
->temp_reg
;
3655 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3659 src_gpr
= ctx
->temp_reg
;
3662 memset(&vtx
, 0, sizeof(vtx
));
3663 vtx
.op
= FETCH_OP_VFETCH
;
3664 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
3665 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
3666 vtx
.src_gpr
= src_gpr
;
3667 vtx
.mega_fetch_count
= 16;
3668 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
3669 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
3670 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
3671 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
3672 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
3673 vtx
.use_const_fields
= 1;
3674 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
3676 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
3679 if (ctx
->bc
->chip_class
>= EVERGREEN
)
3682 for (i
= 0; i
< 4; i
++) {
3683 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3684 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3688 alu
.op
= ALU_OP2_AND_INT
;
3691 alu
.dst
.sel
= vtx
.dst_gpr
;
3694 alu
.src
[0].sel
= vtx
.dst_gpr
;
3695 alu
.src
[0].chan
= i
;
3697 alu
.src
[1].sel
= 512 + (id
* 2);
3698 alu
.src
[1].chan
= i
% 4;
3699 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3703 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3708 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
3709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3710 alu
.op
= ALU_OP2_OR_INT
;
3713 alu
.dst
.sel
= vtx
.dst_gpr
;
3716 alu
.src
[0].sel
= vtx
.dst_gpr
;
3717 alu
.src
[0].chan
= 3;
3719 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
3720 alu
.src
[1].chan
= 0;
3721 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3724 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3731 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
3733 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3734 struct r600_bytecode_alu alu
;
3736 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
3738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3739 alu
.op
= ALU_OP1_MOV
;
3741 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
3742 alu
.src
[0].sel
= 512 + (id
/ 4);
3743 alu
.src
[0].chan
= id
% 4;
3745 /* r600 we have them at channel 2 of the second dword */
3746 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
3747 alu
.src
[0].chan
= 1;
3749 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3750 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3758 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
3760 static float one_point_five
= 1.5f
;
3761 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3762 struct r600_bytecode_tex tex
;
3763 struct r600_bytecode_alu alu
;
3767 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
3768 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
3769 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
3770 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
3772 /* Texture fetch instructions can only use gprs as source.
3773 * Also they cannot negate the source or take the absolute value */
3774 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
3775 tgsi_tex_src_requires_loading(ctx
, 0)) ||
3776 read_compressed_msaa
;
3777 boolean src_loaded
= FALSE
;
3778 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
3779 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
3780 boolean has_txq_cube_array_z
= false;
3782 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
3783 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3784 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
3785 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
3786 ctx
->shader
->has_txq_cube_array_z_comp
= true;
3787 has_txq_cube_array_z
= true;
3790 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
3791 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
3792 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
3793 sampler_src_reg
= 2;
3795 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
3797 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
3798 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
3799 ctx
->shader
->uses_tex_buffers
= true;
3800 return r600_do_buffer_txq(ctx
);
3802 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3803 if (ctx
->bc
->chip_class
< EVERGREEN
)
3804 ctx
->shader
->uses_tex_buffers
= true;
3805 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
3809 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
3810 /* get offset values */
3811 if (inst
->Texture
.NumOffsets
) {
3812 assert(inst
->Texture
.NumOffsets
== 1);
3814 offset_x
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
3815 offset_y
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
3816 offset_z
= ctx
->literals
[inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
3818 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
3819 /* TGSI moves the sampler to src reg 3 for TXD */
3820 sampler_src_reg
= 3;
3822 for (i
= 1; i
< 3; i
++) {
3823 /* set gradients h/v */
3824 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
3825 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
3826 FETCH_OP_SET_GRADIENTS_V
;
3827 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
3828 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
3830 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
3831 tex
.src_gpr
= r600_get_temp(ctx
);
3837 for (j
= 0; j
< 4; j
++) {
3838 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3839 alu
.op
= ALU_OP1_MOV
;
3840 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
3841 alu
.dst
.sel
= tex
.src_gpr
;
3846 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3852 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
3853 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
3854 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
3855 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
3856 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
3857 tex
.src_rel
= ctx
->src
[i
].rel
;
3859 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
3860 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
3861 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
3862 tex
.coord_type_x
= 1;
3863 tex
.coord_type_y
= 1;
3864 tex
.coord_type_z
= 1;
3865 tex
.coord_type_w
= 1;
3867 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
3871 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
3873 /* Add perspective divide */
3874 if (ctx
->bc
->chip_class
== CAYMAN
) {
3876 for (i
= 0; i
< 3; i
++) {
3877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3878 alu
.op
= ALU_OP1_RECIP_IEEE
;
3879 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3881 alu
.dst
.sel
= ctx
->temp_reg
;
3887 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3894 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3895 alu
.op
= ALU_OP1_RECIP_IEEE
;
3896 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
3898 alu
.dst
.sel
= ctx
->temp_reg
;
3899 alu
.dst
.chan
= out_chan
;
3902 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3907 for (i
= 0; i
< 3; i
++) {
3908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3909 alu
.op
= ALU_OP2_MUL
;
3910 alu
.src
[0].sel
= ctx
->temp_reg
;
3911 alu
.src
[0].chan
= out_chan
;
3912 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3913 alu
.dst
.sel
= ctx
->temp_reg
;
3916 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3921 alu
.op
= ALU_OP1_MOV
;
3922 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3923 alu
.src
[0].chan
= 0;
3924 alu
.dst
.sel
= ctx
->temp_reg
;
3928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3932 src_gpr
= ctx
->temp_reg
;
3935 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
3936 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
3937 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
3938 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
3939 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
3940 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
3942 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
3943 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
3945 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
3946 for (i
= 0; i
< 4; i
++) {
3947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3948 alu
.op
= ALU_OP2_CUBE
;
3949 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
3950 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
3951 alu
.dst
.sel
= ctx
->temp_reg
;
3956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3961 /* tmp1.z = RCP_e(|tmp1.z|) */
3962 if (ctx
->bc
->chip_class
== CAYMAN
) {
3963 for (i
= 0; i
< 3; i
++) {
3964 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3965 alu
.op
= ALU_OP1_RECIP_IEEE
;
3966 alu
.src
[0].sel
= ctx
->temp_reg
;
3967 alu
.src
[0].chan
= 2;
3969 alu
.dst
.sel
= ctx
->temp_reg
;
3975 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3981 alu
.op
= ALU_OP1_RECIP_IEEE
;
3982 alu
.src
[0].sel
= ctx
->temp_reg
;
3983 alu
.src
[0].chan
= 2;
3985 alu
.dst
.sel
= ctx
->temp_reg
;
3989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3994 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
3995 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
3996 * muladd has no writemask, have to use another temp
3998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3999 alu
.op
= ALU_OP3_MULADD
;
4002 alu
.src
[0].sel
= ctx
->temp_reg
;
4003 alu
.src
[0].chan
= 0;
4004 alu
.src
[1].sel
= ctx
->temp_reg
;
4005 alu
.src
[1].chan
= 2;
4007 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4008 alu
.src
[2].chan
= 0;
4009 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4011 alu
.dst
.sel
= ctx
->temp_reg
;
4015 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4020 alu
.op
= ALU_OP3_MULADD
;
4023 alu
.src
[0].sel
= ctx
->temp_reg
;
4024 alu
.src
[0].chan
= 1;
4025 alu
.src
[1].sel
= ctx
->temp_reg
;
4026 alu
.src
[1].chan
= 2;
4028 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4029 alu
.src
[2].chan
= 0;
4030 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4032 alu
.dst
.sel
= ctx
->temp_reg
;
4037 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4040 /* write initial compare value into Z component
4041 - W src 0 for shadow cube
4042 - X src 1 for shadow cube array */
4043 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4044 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4046 alu
.op
= ALU_OP1_MOV
;
4047 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4048 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4050 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4051 alu
.dst
.sel
= ctx
->temp_reg
;
4055 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4060 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4061 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4062 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4063 int mytmp
= r600_get_temp(ctx
);
4064 static const float eight
= 8.0f
;
4065 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4066 alu
.op
= ALU_OP1_MOV
;
4067 alu
.src
[0].sel
= ctx
->temp_reg
;
4068 alu
.src
[0].chan
= 3;
4069 alu
.dst
.sel
= mytmp
;
4073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4077 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4079 alu
.op
= ALU_OP3_MULADD
;
4081 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4082 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4083 alu
.src
[1].chan
= 0;
4084 alu
.src
[1].value
= *(uint32_t *)&eight
;
4085 alu
.src
[2].sel
= mytmp
;
4086 alu
.src
[2].chan
= 0;
4087 alu
.dst
.sel
= ctx
->temp_reg
;
4091 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4094 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4095 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4096 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4097 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4098 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4099 tex
.src_gpr
= r600_get_temp(ctx
);
4104 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4105 tex
.coord_type_x
= 1;
4106 tex
.coord_type_y
= 1;
4107 tex
.coord_type_z
= 1;
4108 tex
.coord_type_w
= 1;
4109 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4110 alu
.op
= ALU_OP1_MOV
;
4111 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4112 alu
.dst
.sel
= tex
.src_gpr
;
4116 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4120 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4127 /* for cube forms of lod and bias we need to route things */
4128 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4129 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4130 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4131 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4133 alu
.op
= ALU_OP1_MOV
;
4134 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4135 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4136 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4138 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4139 alu
.dst
.sel
= ctx
->temp_reg
;
4143 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4149 src_gpr
= ctx
->temp_reg
;
4152 if (src_requires_loading
&& !src_loaded
) {
4153 for (i
= 0; i
< 4; i
++) {
4154 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4155 alu
.op
= ALU_OP1_MOV
;
4156 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4157 alu
.dst
.sel
= ctx
->temp_reg
;
4162 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4167 src_gpr
= ctx
->temp_reg
;
4170 /* Obtain the sample index for reading a compressed MSAA color texture.
4171 * To read the FMASK, we use the ldfptr instruction, which tells us
4172 * where the samples are stored.
4173 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4174 * which is the identity mapping. Each nibble says which physical sample
4175 * should be fetched to get that sample.
4177 * Assume src.z contains the sample index. It should be modified like this:
4178 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4179 * Then fetch the texel with src.
4181 if (read_compressed_msaa
) {
4182 unsigned sample_chan
= 3;
4183 unsigned temp
= r600_get_temp(ctx
);
4186 /* temp.w = ldfptr() */
4187 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4188 tex
.op
= FETCH_OP_LD
;
4189 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4190 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4191 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4192 tex
.src_gpr
= src_gpr
;
4194 tex
.dst_sel_x
= 7; /* mask out these components */
4197 tex
.dst_sel_w
= 0; /* store X */
4202 tex
.offset_x
= offset_x
;
4203 tex
.offset_y
= offset_y
;
4204 tex
.offset_z
= offset_z
;
4205 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4209 /* temp.x = sample_index*4 */
4210 if (ctx
->bc
->chip_class
== CAYMAN
) {
4211 for (i
= 0 ; i
< 4; i
++) {
4212 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4213 alu
.op
= ALU_OP2_MULLO_INT
;
4214 alu
.src
[0].sel
= src_gpr
;
4215 alu
.src
[0].chan
= sample_chan
;
4216 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4217 alu
.src
[1].value
= 4;
4220 alu
.dst
.write
= i
== 0;
4223 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4229 alu
.op
= ALU_OP2_MULLO_INT
;
4230 alu
.src
[0].sel
= src_gpr
;
4231 alu
.src
[0].chan
= sample_chan
;
4232 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4233 alu
.src
[1].value
= 4;
4238 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4243 /* sample_index = temp.w >> temp.x */
4244 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4245 alu
.op
= ALU_OP2_LSHR_INT
;
4246 alu
.src
[0].sel
= temp
;
4247 alu
.src
[0].chan
= 3;
4248 alu
.src
[1].sel
= temp
;
4249 alu
.src
[1].chan
= 0;
4250 alu
.dst
.sel
= src_gpr
;
4251 alu
.dst
.chan
= sample_chan
;
4254 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4258 /* sample_index & 0xF */
4259 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4260 alu
.op
= ALU_OP2_AND_INT
;
4261 alu
.src
[0].sel
= src_gpr
;
4262 alu
.src
[0].chan
= sample_chan
;
4263 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4264 alu
.src
[1].value
= 0xF;
4265 alu
.dst
.sel
= src_gpr
;
4266 alu
.dst
.chan
= sample_chan
;
4269 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4273 /* visualize the FMASK */
4274 for (i
= 0; i
< 4; i
++) {
4275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4276 alu
.op
= ALU_OP1_INT_TO_FLT
;
4277 alu
.src
[0].sel
= src_gpr
;
4278 alu
.src
[0].chan
= sample_chan
;
4279 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4283 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4291 /* does this shader want a num layers from TXQ for a cube array? */
4292 if (has_txq_cube_array_z
) {
4293 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4295 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4296 alu
.op
= ALU_OP1_MOV
;
4298 alu
.src
[0].sel
= 512 + (id
/ 4);
4299 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4300 alu
.src
[0].chan
= id
% 4;
4301 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4306 /* disable writemask from texture instruction */
4307 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4310 opcode
= ctx
->inst_info
->op
;
4311 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4312 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4313 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4314 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4315 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4316 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4317 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4319 case FETCH_OP_SAMPLE
:
4320 opcode
= FETCH_OP_SAMPLE_C
;
4322 case FETCH_OP_SAMPLE_L
:
4323 opcode
= FETCH_OP_SAMPLE_C_L
;
4325 case FETCH_OP_SAMPLE_LB
:
4326 opcode
= FETCH_OP_SAMPLE_C_LB
;
4328 case FETCH_OP_SAMPLE_G
:
4329 opcode
= FETCH_OP_SAMPLE_C_G
;
4334 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4337 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4338 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4339 tex
.src_gpr
= src_gpr
;
4340 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4341 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4342 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4343 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4344 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4346 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4351 } else if (src_loaded
) {
4357 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4358 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4359 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4360 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4361 tex
.src_rel
= ctx
->src
[0].rel
;
4364 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4365 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4366 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4367 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4371 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4374 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4375 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4376 tex
.coord_type_x
= 1;
4377 tex
.coord_type_y
= 1;
4379 tex
.coord_type_z
= 1;
4380 tex
.coord_type_w
= 1;
4382 tex
.offset_x
= offset_x
;
4383 tex
.offset_y
= offset_y
;
4384 tex
.offset_z
= offset_z
;
4386 /* Put the depth for comparison in W.
4387 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4388 * Some instructions expect the depth in Z. */
4389 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4390 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4391 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4392 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4393 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4394 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4395 tex
.src_sel_w
= tex
.src_sel_z
;
4398 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4399 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4400 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4401 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4402 /* the array index is read from Y */
4403 tex
.coord_type_y
= 0;
4405 /* the array index is read from Z */
4406 tex
.coord_type_z
= 0;
4407 tex
.src_sel_z
= tex
.src_sel_y
;
4409 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4410 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4411 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4412 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4413 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4414 /* the array index is read from Z */
4415 tex
.coord_type_z
= 0;
4417 /* mask unused source components */
4418 if (opcode
== FETCH_OP_SAMPLE
) {
4419 switch (inst
->Texture
.Texture
) {
4420 case TGSI_TEXTURE_2D
:
4421 case TGSI_TEXTURE_RECT
:
4425 case TGSI_TEXTURE_1D_ARRAY
:
4429 case TGSI_TEXTURE_1D
:
4437 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4441 /* add shadow ambient support - gallium doesn't do it yet */
4445 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4447 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4448 struct r600_bytecode_alu alu
;
4449 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4453 /* optimize if it's just an equal balance */
4454 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4455 for (i
= 0; i
< lasti
+ 1; i
++) {
4456 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4459 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4460 alu
.op
= ALU_OP2_ADD
;
4461 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4462 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4464 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4469 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4477 for (i
= 0; i
< lasti
+ 1; i
++) {
4478 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4482 alu
.op
= ALU_OP2_ADD
;
4483 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4484 alu
.src
[0].chan
= 0;
4485 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4486 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4487 alu
.dst
.sel
= ctx
->temp_reg
;
4493 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4498 /* (1 - src0) * src2 */
4499 for (i
= 0; i
< lasti
+ 1; i
++) {
4500 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4503 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4504 alu
.op
= ALU_OP2_MUL
;
4505 alu
.src
[0].sel
= ctx
->temp_reg
;
4506 alu
.src
[0].chan
= i
;
4507 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4508 alu
.dst
.sel
= ctx
->temp_reg
;
4514 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4519 /* src0 * src1 + (1 - src0) * src2 */
4520 for (i
= 0; i
< lasti
+ 1; i
++) {
4521 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4525 alu
.op
= ALU_OP3_MULADD
;
4527 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4528 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4529 alu
.src
[2].sel
= ctx
->temp_reg
;
4530 alu
.src
[2].chan
= i
;
4532 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4537 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4544 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4546 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4547 struct r600_bytecode_alu alu
;
4549 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4551 for (i
= 0; i
< lasti
+ 1; i
++) {
4552 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4556 alu
.op
= ALU_OP3_CNDGE
;
4557 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4558 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4559 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4560 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4566 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4573 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4575 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4576 struct r600_bytecode_alu alu
;
4578 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4580 for (i
= 0; i
< lasti
+ 1; i
++) {
4581 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4584 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4585 alu
.op
= ALU_OP3_CNDGE_INT
;
4586 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4587 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4588 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4589 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4595 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4602 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
4604 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4605 static const unsigned int src0_swizzle
[] = {2, 0, 1};
4606 static const unsigned int src1_swizzle
[] = {1, 2, 0};
4607 struct r600_bytecode_alu alu
;
4608 uint32_t use_temp
= 0;
4611 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
4614 for (i
= 0; i
< 4; i
++) {
4615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4616 alu
.op
= ALU_OP2_MUL
;
4618 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4619 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
4621 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4622 alu
.src
[0].chan
= i
;
4623 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4624 alu
.src
[1].chan
= i
;
4627 alu
.dst
.sel
= ctx
->temp_reg
;
4633 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4638 for (i
= 0; i
< 4; i
++) {
4639 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4640 alu
.op
= ALU_OP3_MULADD
;
4643 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
4644 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
4646 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4647 alu
.src
[0].chan
= i
;
4648 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4649 alu
.src
[1].chan
= i
;
4652 alu
.src
[2].sel
= ctx
->temp_reg
;
4654 alu
.src
[2].chan
= i
;
4657 alu
.dst
.sel
= ctx
->temp_reg
;
4659 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4665 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4670 return tgsi_helper_copy(ctx
, inst
);
4674 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
4676 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4677 struct r600_bytecode_alu alu
;
4681 /* result.x = 2^floor(src); */
4682 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4685 alu
.op
= ALU_OP1_FLOOR
;
4686 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4688 alu
.dst
.sel
= ctx
->temp_reg
;
4692 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4696 if (ctx
->bc
->chip_class
== CAYMAN
) {
4697 for (i
= 0; i
< 3; i
++) {
4698 alu
.op
= ALU_OP1_EXP_IEEE
;
4699 alu
.src
[0].sel
= ctx
->temp_reg
;
4700 alu
.src
[0].chan
= 0;
4702 alu
.dst
.sel
= ctx
->temp_reg
;
4704 alu
.dst
.write
= i
== 0;
4706 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4711 alu
.op
= ALU_OP1_EXP_IEEE
;
4712 alu
.src
[0].sel
= ctx
->temp_reg
;
4713 alu
.src
[0].chan
= 0;
4715 alu
.dst
.sel
= ctx
->temp_reg
;
4719 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4725 /* result.y = tmp - floor(tmp); */
4726 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4727 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4729 alu
.op
= ALU_OP1_FRACT
;
4730 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4732 alu
.dst
.sel
= ctx
->temp_reg
;
4734 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4743 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4748 /* result.z = RoughApprox2ToX(tmp);*/
4749 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
4750 if (ctx
->bc
->chip_class
== CAYMAN
) {
4751 for (i
= 0; i
< 3; i
++) {
4752 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4753 alu
.op
= ALU_OP1_EXP_IEEE
;
4754 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4756 alu
.dst
.sel
= ctx
->temp_reg
;
4763 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4768 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4769 alu
.op
= ALU_OP1_EXP_IEEE
;
4770 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4772 alu
.dst
.sel
= ctx
->temp_reg
;
4778 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4784 /* result.w = 1.0;*/
4785 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
4786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4788 alu
.op
= ALU_OP1_MOV
;
4789 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4790 alu
.src
[0].chan
= 0;
4792 alu
.dst
.sel
= ctx
->temp_reg
;
4796 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4800 return tgsi_helper_copy(ctx
, inst
);
4803 static int tgsi_log(struct r600_shader_ctx
*ctx
)
4805 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4806 struct r600_bytecode_alu alu
;
4810 /* result.x = floor(log2(|src|)); */
4811 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
4812 if (ctx
->bc
->chip_class
== CAYMAN
) {
4813 for (i
= 0; i
< 3; i
++) {
4814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4816 alu
.op
= ALU_OP1_LOG_IEEE
;
4817 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4818 r600_bytecode_src_set_abs(&alu
.src
[0]);
4820 alu
.dst
.sel
= ctx
->temp_reg
;
4826 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4832 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4834 alu
.op
= ALU_OP1_LOG_IEEE
;
4835 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4836 r600_bytecode_src_set_abs(&alu
.src
[0]);
4838 alu
.dst
.sel
= ctx
->temp_reg
;
4842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4847 alu
.op
= ALU_OP1_FLOOR
;
4848 alu
.src
[0].sel
= ctx
->temp_reg
;
4849 alu
.src
[0].chan
= 0;
4851 alu
.dst
.sel
= ctx
->temp_reg
;
4856 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4861 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
4862 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
4864 if (ctx
->bc
->chip_class
== CAYMAN
) {
4865 for (i
= 0; i
< 3; i
++) {
4866 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4868 alu
.op
= ALU_OP1_LOG_IEEE
;
4869 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4870 r600_bytecode_src_set_abs(&alu
.src
[0]);
4872 alu
.dst
.sel
= ctx
->temp_reg
;
4879 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4884 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4886 alu
.op
= ALU_OP1_LOG_IEEE
;
4887 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4888 r600_bytecode_src_set_abs(&alu
.src
[0]);
4890 alu
.dst
.sel
= ctx
->temp_reg
;
4895 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4902 alu
.op
= ALU_OP1_FLOOR
;
4903 alu
.src
[0].sel
= ctx
->temp_reg
;
4904 alu
.src
[0].chan
= 1;
4906 alu
.dst
.sel
= ctx
->temp_reg
;
4911 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4915 if (ctx
->bc
->chip_class
== CAYMAN
) {
4916 for (i
= 0; i
< 3; i
++) {
4917 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4918 alu
.op
= ALU_OP1_EXP_IEEE
;
4919 alu
.src
[0].sel
= ctx
->temp_reg
;
4920 alu
.src
[0].chan
= 1;
4922 alu
.dst
.sel
= ctx
->temp_reg
;
4929 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4934 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4935 alu
.op
= ALU_OP1_EXP_IEEE
;
4936 alu
.src
[0].sel
= ctx
->temp_reg
;
4937 alu
.src
[0].chan
= 1;
4939 alu
.dst
.sel
= ctx
->temp_reg
;
4944 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4949 if (ctx
->bc
->chip_class
== CAYMAN
) {
4950 for (i
= 0; i
< 3; i
++) {
4951 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4952 alu
.op
= ALU_OP1_RECIP_IEEE
;
4953 alu
.src
[0].sel
= ctx
->temp_reg
;
4954 alu
.src
[0].chan
= 1;
4956 alu
.dst
.sel
= ctx
->temp_reg
;
4963 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4969 alu
.op
= ALU_OP1_RECIP_IEEE
;
4970 alu
.src
[0].sel
= ctx
->temp_reg
;
4971 alu
.src
[0].chan
= 1;
4973 alu
.dst
.sel
= ctx
->temp_reg
;
4978 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4983 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4985 alu
.op
= ALU_OP2_MUL
;
4987 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4988 r600_bytecode_src_set_abs(&alu
.src
[0]);
4990 alu
.src
[1].sel
= ctx
->temp_reg
;
4991 alu
.src
[1].chan
= 1;
4993 alu
.dst
.sel
= ctx
->temp_reg
;
4998 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5003 /* result.z = log2(|src|);*/
5004 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5005 if (ctx
->bc
->chip_class
== CAYMAN
) {
5006 for (i
= 0; i
< 3; i
++) {
5007 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5009 alu
.op
= ALU_OP1_LOG_IEEE
;
5010 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5011 r600_bytecode_src_set_abs(&alu
.src
[0]);
5013 alu
.dst
.sel
= ctx
->temp_reg
;
5020 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5025 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5027 alu
.op
= ALU_OP1_LOG_IEEE
;
5028 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5029 r600_bytecode_src_set_abs(&alu
.src
[0]);
5031 alu
.dst
.sel
= ctx
->temp_reg
;
5036 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5042 /* result.w = 1.0; */
5043 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5046 alu
.op
= ALU_OP1_MOV
;
5047 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5048 alu
.src
[0].chan
= 0;
5050 alu
.dst
.sel
= ctx
->temp_reg
;
5055 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5060 return tgsi_helper_copy(ctx
, inst
);
5063 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5065 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5066 struct r600_bytecode_alu alu
;
5069 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5071 switch (inst
->Instruction
.Opcode
) {
5072 case TGSI_OPCODE_ARL
:
5073 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5075 case TGSI_OPCODE_ARR
:
5076 alu
.op
= ALU_OP1_FLT_TO_INT
;
5078 case TGSI_OPCODE_UARL
:
5079 alu
.op
= ALU_OP1_MOV
;
5086 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5088 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5090 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5094 ctx
->bc
->ar_loaded
= 0;
5097 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5099 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5100 struct r600_bytecode_alu alu
;
5103 switch (inst
->Instruction
.Opcode
) {
5104 case TGSI_OPCODE_ARL
:
5105 memset(&alu
, 0, sizeof(alu
));
5106 alu
.op
= ALU_OP1_FLOOR
;
5107 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5108 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5112 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5115 memset(&alu
, 0, sizeof(alu
));
5116 alu
.op
= ALU_OP1_FLT_TO_INT
;
5117 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5118 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5122 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5125 case TGSI_OPCODE_ARR
:
5126 memset(&alu
, 0, sizeof(alu
));
5127 alu
.op
= ALU_OP1_FLT_TO_INT
;
5128 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5129 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5133 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5136 case TGSI_OPCODE_UARL
:
5137 memset(&alu
, 0, sizeof(alu
));
5138 alu
.op
= ALU_OP1_MOV
;
5139 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5140 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5144 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5152 ctx
->bc
->ar_loaded
= 0;
5156 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5158 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5159 struct r600_bytecode_alu alu
;
5162 for (i
= 0; i
< 4; i
++) {
5163 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5165 alu
.op
= ALU_OP2_MUL
;
5166 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5168 if (i
== 0 || i
== 3) {
5169 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5171 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5174 if (i
== 0 || i
== 2) {
5175 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5177 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5188 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5190 struct r600_bytecode_alu alu
;
5193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5195 alu
.execute_mask
= 1;
5196 alu
.update_pred
= 1;
5198 alu
.dst
.sel
= ctx
->temp_reg
;
5202 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5203 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5204 alu
.src
[1].chan
= 0;
5208 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5214 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5216 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5220 if (ctx
->bc
->cf_last
) {
5221 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5223 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5228 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5229 ctx
->bc
->force_add_cf
= 1;
5230 } else if (alu_pop
== 2) {
5231 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5232 ctx
->bc
->force_add_cf
= 1;
5239 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5240 ctx
->bc
->cf_last
->pop_count
= pops
;
5241 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5247 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5250 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5251 unsigned elements
, entries
;
5253 unsigned entry_size
= stack
->entry_size
;
5255 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5256 elements
+= stack
->push
;
5258 switch (ctx
->bc
->chip_class
) {
5261 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5262 * the stack must be reserved to hold the current active/continue
5264 if (reason
== FC_PUSH_VPM
) {
5270 /* r9xx: any stack operation on empty stack consumes 2 additional
5275 /* FIXME: do the two elements added above cover the cases for the
5279 /* r8xx+: 2 extra elements are not always required, but one extra
5280 * element must be added for each of the following cases:
5281 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5283 * (Currently we don't use ALU_ELSE_AFTER.)
5284 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5285 * PUSH instruction executed.
5287 * NOTE: it seems we also need to reserve additional element in some
5288 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5289 * then STACK_SIZE should be 2 instead of 1 */
5290 if (reason
== FC_PUSH_VPM
) {
5300 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5301 * for all chips, so we use 4 in the final formula, not the real entry_size
5305 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5307 if (entries
> stack
->max_entries
)
5308 stack
->max_entries
= entries
;
5311 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5315 --ctx
->bc
->stack
.push
;
5316 assert(ctx
->bc
->stack
.push
>= 0);
5319 --ctx
->bc
->stack
.push_wqm
;
5320 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5323 --ctx
->bc
->stack
.loop
;
5324 assert(ctx
->bc
->stack
.loop
>= 0);
5332 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5336 ++ctx
->bc
->stack
.push
;
5339 ++ctx
->bc
->stack
.push_wqm
;
5341 ++ctx
->bc
->stack
.loop
;
5347 callstack_update_max_depth(ctx
, reason
);
5350 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5352 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5354 sp
->mid
= realloc((void *)sp
->mid
,
5355 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5356 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5360 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5363 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5364 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5367 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5369 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5379 static int emit_return(struct r600_shader_ctx
*ctx
)
5381 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5385 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5388 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5389 ctx
->bc
->cf_last
->pop_count
= pops
;
5390 /* XXX work out offset */
5394 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5399 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5404 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5407 emit_jump_to_offset(ctx
, 1, 4);
5408 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5409 pops(ctx
, ifidx
+ 1);
5413 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5417 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5418 ctx
->bc
->cf_last
->pop_count
= 1;
5420 fc_set_mid(ctx
, fc_sp
);
5426 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5428 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5430 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5431 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5432 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5433 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5434 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5435 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5436 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5437 alu_type
= CF_OP_ALU
;
5440 emit_logic_pred(ctx
, opcode
, alu_type
);
5442 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5444 fc_pushlevel(ctx
, FC_IF
);
5446 callstack_push(ctx
, FC_PUSH_VPM
);
5450 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5452 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5455 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5457 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5460 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5462 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5463 ctx
->bc
->cf_last
->pop_count
= 1;
5465 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5466 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5470 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5473 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5474 R600_ERR("if/endif unbalanced in shader\n");
5478 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5479 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5480 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5482 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5486 callstack_pop(ctx
, FC_PUSH_VPM
);
5490 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5492 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5493 * limited to 4096 iterations, like the other LOOP_* instructions. */
5494 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5496 fc_pushlevel(ctx
, FC_LOOP
);
5498 /* check stack depth */
5499 callstack_push(ctx
, FC_LOOP
);
5503 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5507 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5509 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5510 R600_ERR("loop/endloop in shader code are not paired.\n");
5514 /* fixup loop pointers - from r600isa
5515 LOOP END points to CF after LOOP START,
5516 LOOP START point to CF after LOOP END
5517 BRK/CONT point to LOOP END CF
5519 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5521 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5523 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5524 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5526 /* XXX add LOOPRET support */
5528 callstack_pop(ctx
, FC_LOOP
);
5532 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5536 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5538 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5543 R600_ERR("Break not inside loop/endloop pair\n");
5547 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5549 fc_set_mid(ctx
, fscp
);
5554 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5556 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5557 struct r600_bytecode_alu alu
;
5559 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5562 for (i
= 0; i
< lasti
+ 1; i
++) {
5563 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5566 if (ctx
->bc
->chip_class
== CAYMAN
) {
5567 for (j
= 0 ; j
< 4; j
++) {
5568 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5570 alu
.op
= ALU_OP2_MULLO_UINT
;
5571 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5572 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5574 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5575 alu
.dst
.sel
= ctx
->temp_reg
;
5576 alu
.dst
.write
= (j
== i
);
5579 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5584 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5587 alu
.dst
.sel
= ctx
->temp_reg
;
5590 alu
.op
= ALU_OP2_MULLO_UINT
;
5591 for (j
= 0; j
< 2; j
++) {
5592 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5596 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5603 for (i
= 0; i
< lasti
+ 1; i
++) {
5604 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5607 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5608 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5610 alu
.op
= ALU_OP2_ADD_INT
;
5612 alu
.src
[0].sel
= ctx
->temp_reg
;
5613 alu
.src
[0].chan
= i
;
5615 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5626 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
5627 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5628 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
5629 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
5632 * For state trackers other than OpenGL, we'll want to use
5633 * _RECIP_IEEE instead.
5635 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
5637 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
5638 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
5639 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
5640 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
5641 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
5642 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5643 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5644 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
5645 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
5646 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
5647 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
5648 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
5649 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
5650 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
5651 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
5652 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5654 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5655 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5657 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5658 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5659 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
5660 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5661 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
5662 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
5663 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
5664 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
5665 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
5666 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
5668 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5669 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
5670 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5671 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5672 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
5673 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
5674 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
5675 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
5676 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5677 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5678 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5679 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5680 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5681 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
5682 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5683 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
5684 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
5685 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
5686 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
5687 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5688 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5689 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
5690 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
5691 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5692 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5693 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5694 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5695 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5696 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5697 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
5698 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5699 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5700 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5701 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
5702 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
5703 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
5704 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
5705 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5706 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5707 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
5708 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
5709 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
5710 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
5711 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
5712 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5713 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
5714 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
5716 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5717 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5718 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5719 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5720 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
5721 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
5722 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
5723 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
5724 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
5726 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5727 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
5728 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
5729 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
5730 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
5731 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5732 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
5733 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5734 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
5735 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5736 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5737 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
5738 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5739 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
5740 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5741 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
5743 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5744 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5745 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5746 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5747 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
5748 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
5749 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
5750 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
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_KILL_IF
, 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_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional 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
},
5939 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
5940 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
5941 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
5942 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
5943 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5944 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5946 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5947 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5948 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
5949 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
5951 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5952 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
5953 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
5954 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
5955 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
5956 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
5957 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
5958 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
5959 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
5960 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
5961 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
5962 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
5963 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
5964 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
5965 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
5966 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
5967 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
5968 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
5969 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
5970 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
5971 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
5972 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
5973 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
5974 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5975 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5976 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5977 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5978 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
5979 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
5980 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
5981 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
5982 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
5983 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
5984 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
5985 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
5986 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
5987 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
5988 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
5989 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
5990 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
5991 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
5992 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
5993 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
5994 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5995 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5996 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5997 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5998 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
5999 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6000 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6001 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6002 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6003 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6004 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6005 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6006 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6007 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6008 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6009 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6010 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6011 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6012 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6013 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6016 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6017 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6018 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6019 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6020 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6021 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6022 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6023 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6024 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6025 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6026 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6027 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6028 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6029 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6030 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6031 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6032 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6033 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6034 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6035 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6036 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6038 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6039 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6041 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6042 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6043 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6044 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6045 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6046 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6047 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6048 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6049 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6050 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6052 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6053 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6054 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6055 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6056 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6057 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6058 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6059 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6060 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6061 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6062 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6063 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6064 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6065 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6066 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6067 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6068 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6069 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6070 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6071 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6072 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6073 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6074 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6075 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6076 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6077 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6078 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6079 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6080 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6081 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6082 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6083 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6084 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6085 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6086 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6087 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6088 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6089 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6090 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6091 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6092 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6093 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6094 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6095 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6096 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6097 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6098 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6100 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6101 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6102 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6103 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6105 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6106 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6107 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6108 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6110 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6111 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6112 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6113 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6114 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6115 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6116 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6117 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6118 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6119 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6120 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6121 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6122 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6123 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6124 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6125 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6127 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6128 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6129 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6130 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6132 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6133 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6134 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6135 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6136 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6137 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6139 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6140 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6141 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6142 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6144 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6145 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6146 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6147 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6148 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6149 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6150 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6151 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6152 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6153 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6154 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6155 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6156 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6157 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6158 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6159 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6160 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6161 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6162 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6163 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6164 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6165 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6166 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6167 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6168 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6169 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6170 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6172 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6173 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6174 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6175 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6176 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6177 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6178 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6179 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6180 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6181 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6182 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6183 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6184 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6185 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6186 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6187 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6188 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6189 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6190 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6191 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6192 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6193 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6194 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6195 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6196 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6197 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6198 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6199 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6200 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6201 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6202 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6203 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6204 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6205 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6206 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},