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_context
*rctx
,
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 void r600_dump_streamout(struct pipe_stream_output_info
*so
)
91 fprintf(stderr
, "STREAMOUT\n");
92 for (i
= 0; i
< so
->num_outputs
; i
++) {
93 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
94 so
->output
[i
].start_component
;
95 fprintf(stderr
, " %i: MEM_STREAM0_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
96 i
, so
->output
[i
].output_buffer
,
97 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
98 so
->output
[i
].register_index
,
103 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
107 static int store_shader(struct pipe_context
*ctx
,
108 struct r600_pipe_shader
*shader
)
110 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
113 if (shader
->bo
== NULL
) {
114 shader
->bo
= (struct r600_resource
*)
115 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
116 if (shader
->bo
== NULL
) {
119 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
120 if (R600_BIG_ENDIAN
) {
121 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
122 ptr
[i
] = util_bswap32(shader
->shader
.bc
.bytecode
[i
]);
125 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
127 rctx
->b
.ws
->buffer_unmap(shader
->bo
->cs_buf
);
133 int r600_pipe_shader_create(struct pipe_context
*ctx
,
134 struct r600_pipe_shader
*shader
,
135 struct r600_shader_key key
)
137 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
140 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
, sel
->tokens
);
141 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
142 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
143 unsigned export_shader
= key
.vs_as_es
;
145 shader
->shader
.bc
.isa
= rctx
->isa
;
148 fprintf(stderr
, "--------------------------------------------------------------\n");
149 tgsi_dump(sel
->tokens
, 0);
151 if (sel
->so
.num_outputs
) {
152 r600_dump_streamout(&sel
->so
);
155 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
157 R600_ERR("translation from TGSI failed !\n");
161 /* disable SB for geom shaders - it can't handle the CF_EMIT instructions */
162 use_sb
&= (shader
->shader
.processor_type
!= TGSI_PROCESSOR_GEOMETRY
);
164 /* Check if the bytecode has already been built. When using the llvm
165 * backend, r600_shader_from_tgsi() will take care of building the
168 if (!shader
->shader
.bc
.bytecode
) {
169 r
= r600_bytecode_build(&shader
->shader
.bc
);
171 R600_ERR("building bytecode failed !\n");
176 if (dump
&& !sb_disasm
) {
177 fprintf(stderr
, "--------------------------------------------------------------\n");
178 r600_bytecode_disasm(&shader
->shader
.bc
);
179 fprintf(stderr
, "______________________________________________________________\n");
180 } else if ((dump
&& sb_disasm
) || use_sb
) {
181 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
184 R600_ERR("r600_sb_bytecode_process failed !\n");
189 if (shader
->gs_copy_shader
) {
192 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
193 &shader
->gs_copy_shader
->shader
, dump
, 0);
198 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
202 /* Store the shader in a buffer. */
203 if ((r
= store_shader(ctx
, shader
)))
207 switch (shader
->shader
.processor_type
) {
208 case TGSI_PROCESSOR_GEOMETRY
:
209 if (rctx
->b
.chip_class
>= EVERGREEN
) {
210 evergreen_update_gs_state(ctx
, shader
);
211 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
213 assert(!"not suported yet");
216 case TGSI_PROCESSOR_VERTEX
:
217 if (rctx
->b
.chip_class
>= EVERGREEN
) {
219 evergreen_update_es_state(ctx
, shader
);
221 evergreen_update_vs_state(ctx
, shader
);
223 r600_update_vs_state(ctx
, shader
);
226 case TGSI_PROCESSOR_FRAGMENT
:
227 if (rctx
->b
.chip_class
>= EVERGREEN
) {
228 evergreen_update_ps_state(ctx
, shader
);
230 r600_update_ps_state(ctx
, shader
);
239 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
241 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
242 r600_bytecode_clear(&shader
->shader
.bc
);
243 r600_release_command_buffer(&shader
->command_buffer
);
247 * tgsi -> r600 shader
249 struct r600_shader_tgsi_instruction
;
251 struct r600_shader_src
{
261 struct r600_shader_ctx
{
262 struct tgsi_shader_info info
;
263 struct tgsi_parse_context parse
;
264 const struct tgsi_token
*tokens
;
266 unsigned file_offset
[TGSI_FILE_COUNT
];
268 struct r600_shader_tgsi_instruction
*inst_info
;
269 struct r600_bytecode
*bc
;
270 struct r600_shader
*shader
;
271 struct r600_shader_src src
[4];
274 uint32_t max_driver_temp_used
;
276 /* needed for evergreen interpolation */
277 boolean input_centroid
;
278 boolean input_linear
;
279 boolean input_perspective
;
283 boolean clip_vertex_write
;
287 int next_ring_offset
;
289 struct r600_shader
*gs_for_vs
;
292 struct r600_shader_tgsi_instruction
{
293 unsigned tgsi_opcode
;
296 int (*process
)(struct r600_shader_ctx
*ctx
);
299 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
);
300 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
301 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
302 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
303 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
304 static int tgsi_else(struct r600_shader_ctx
*ctx
);
305 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
306 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
307 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
308 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
310 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
312 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
315 if (i
->Instruction
.NumDstRegs
> 1) {
316 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
319 if (i
->Instruction
.Predicate
) {
320 R600_ERR("predicate unsupported\n");
324 if (i
->Instruction
.Label
) {
325 R600_ERR("label unsupported\n");
329 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
330 if (i
->Src
[j
].Register
.Dimension
) {
331 switch (i
->Src
[j
].Register
.File
) {
332 case TGSI_FILE_CONSTANT
:
334 case TGSI_FILE_INPUT
:
335 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
)
338 R600_ERR("unsupported src %d (dimension %d)\n", j
,
339 i
->Src
[j
].Register
.Dimension
);
344 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
345 if (i
->Dst
[j
].Register
.Dimension
) {
346 R600_ERR("unsupported dst (dimension)\n");
353 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
358 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
359 if (ctx
->shader
->input
[input
].centroid
)
361 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
362 /* if we have perspective add one */
363 if (ctx
->input_perspective
) {
365 /* if we have perspective centroid */
366 if (ctx
->input_centroid
)
369 if (ctx
->shader
->input
[input
].centroid
)
373 ctx
->shader
->input
[input
].ij_index
= ij_index
;
376 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
379 struct r600_bytecode_alu alu
;
380 int gpr
= 0, base_chan
= 0;
381 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
383 /* work out gpr and base_chan from index */
385 base_chan
= (2 * (ij_index
% 2)) + 1;
387 for (i
= 0; i
< 8; i
++) {
388 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
391 alu
.op
= ALU_OP2_INTERP_ZW
;
393 alu
.op
= ALU_OP2_INTERP_XY
;
395 if ((i
> 1) && (i
< 6)) {
396 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
400 alu
.dst
.chan
= i
% 4;
402 alu
.src
[0].sel
= gpr
;
403 alu
.src
[0].chan
= (base_chan
- (i
% 2));
405 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
407 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
410 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
417 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
420 struct r600_bytecode_alu alu
;
422 for (i
= 0; i
< 4; i
++) {
423 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
425 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
427 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
432 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
445 * Special export handling in shaders
447 * shader export ARRAY_BASE for EXPORT_POS:
450 * 62, 63 are clip distance vectors
452 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
453 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
454 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
455 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
456 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
457 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
458 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
459 * exclusive from render target index)
460 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
463 * shader export ARRAY_BASE for EXPORT_PIXEL:
465 * 61 computed Z vector
467 * The use of the values exported in the computed Z vector are controlled
468 * by DB_SHADER_CONTROL:
469 * Z_EXPORT_ENABLE - Z as a float in RED
470 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
471 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
472 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
473 * DB_SOURCE_FORMAT - export control restrictions
478 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
479 static int r600_spi_sid(struct r600_shader_io
* io
)
481 int index
, name
= io
->name
;
483 /* These params are handled differently, they don't need
484 * semantic indices, so we'll use 0 for them.
486 if (name
== TGSI_SEMANTIC_POSITION
||
487 name
== TGSI_SEMANTIC_PSIZE
||
488 name
== TGSI_SEMANTIC_FACE
)
491 if (name
== TGSI_SEMANTIC_GENERIC
) {
492 /* For generic params simply use sid from tgsi */
495 /* For non-generic params - pack name and sid into 8 bits */
496 index
= 0x80 | (name
<<3) | (io
->sid
);
499 /* Make sure that all really used indices have nonzero value, so
500 * we can just compare it to 0 later instead of comparing the name
501 * with different values to detect special cases. */
508 /* turn input into interpolate on EG */
509 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
513 if (ctx
->shader
->input
[index
].spi_sid
) {
514 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
515 if (ctx
->shader
->input
[index
].interpolate
> 0) {
516 evergreen_interp_assign_ij_index(ctx
, index
);
518 r
= evergreen_interp_alu(ctx
, index
);
521 r
= evergreen_interp_flat(ctx
, index
);
527 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
529 struct r600_bytecode_alu alu
;
531 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
532 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
534 for (i
= 0; i
< 4; i
++) {
535 memset(&alu
, 0, sizeof(alu
));
536 alu
.op
= ALU_OP3_CNDGT
;
539 alu
.dst
.sel
= gpr_front
;
540 alu
.src
[0].sel
= ctx
->face_gpr
;
541 alu
.src
[1].sel
= gpr_front
;
542 alu
.src
[2].sel
= gpr_back
;
549 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
556 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
558 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
559 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
561 switch (d
->Declaration
.File
) {
562 case TGSI_FILE_INPUT
:
563 i
= ctx
->shader
->ninput
;
564 assert(i
< Elements(ctx
->shader
->input
));
565 ctx
->shader
->ninput
+= count
;
566 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
567 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
568 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
569 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
570 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
571 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
572 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
573 switch (ctx
->shader
->input
[i
].name
) {
574 case TGSI_SEMANTIC_FACE
:
575 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
577 case TGSI_SEMANTIC_COLOR
:
580 case TGSI_SEMANTIC_POSITION
:
581 ctx
->fragcoord_input
= i
;
584 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
585 if ((r
= evergreen_interp_input(ctx
, i
)))
588 } else if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
589 /* FIXME probably skip inputs if they aren't passed in the ring */
590 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
591 ctx
->next_ring_offset
+= 16;
593 for (j
= 1; j
< count
; ++j
) {
594 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
595 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
598 case TGSI_FILE_OUTPUT
:
599 i
= ctx
->shader
->noutput
++;
600 assert(i
< Elements(ctx
->shader
->output
));
601 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
602 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
603 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
604 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
605 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
606 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
||
607 ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
608 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
609 switch (d
->Semantic
.Name
) {
610 case TGSI_SEMANTIC_CLIPDIST
:
611 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
613 case TGSI_SEMANTIC_PSIZE
:
614 ctx
->shader
->vs_out_misc_write
= 1;
615 ctx
->shader
->vs_out_point_size
= 1;
617 case TGSI_SEMANTIC_CLIPVERTEX
:
618 ctx
->clip_vertex_write
= TRUE
;
622 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
623 switch (d
->Semantic
.Name
) {
624 case TGSI_SEMANTIC_COLOR
:
625 ctx
->shader
->nr_ps_max_color_exports
++;
630 case TGSI_FILE_TEMPORARY
:
631 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
632 if (d
->Array
.ArrayID
) {
633 r600_add_gpr_array(ctx
->shader
,
634 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
636 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
641 case TGSI_FILE_CONSTANT
:
642 case TGSI_FILE_SAMPLER
:
643 case TGSI_FILE_ADDRESS
:
646 case TGSI_FILE_SYSTEM_VALUE
:
647 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
648 if (!ctx
->native_integers
) {
649 struct r600_bytecode_alu alu
;
650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
652 alu
.op
= ALU_OP1_INT_TO_FLT
;
661 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
665 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
668 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
674 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
676 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
680 * for evergreen we need to scan the shader to find the number of GPRs we need to
681 * reserve for interpolation.
683 * we need to know if we are going to emit
684 * any centroid inputs
685 * if perspective and linear are required
687 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
692 ctx
->input_linear
= FALSE
;
693 ctx
->input_perspective
= FALSE
;
694 ctx
->input_centroid
= FALSE
;
695 ctx
->num_interp_gpr
= 1;
697 /* any centroid inputs */
698 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
699 /* skip position/face */
700 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
701 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
703 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
704 ctx
->input_linear
= TRUE
;
705 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
706 ctx
->input_perspective
= TRUE
;
707 if (ctx
->info
.input_centroid
[i
])
708 ctx
->input_centroid
= TRUE
;
712 /* ignoring sample for now */
713 if (ctx
->input_perspective
)
715 if (ctx
->input_linear
)
717 if (ctx
->input_centroid
)
720 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
722 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
723 return ctx
->num_interp_gpr
;
726 static void tgsi_src(struct r600_shader_ctx
*ctx
,
727 const struct tgsi_full_src_register
*tgsi_src
,
728 struct r600_shader_src
*r600_src
)
730 memset(r600_src
, 0, sizeof(*r600_src
));
731 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
732 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
733 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
734 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
735 r600_src
->neg
= tgsi_src
->Register
.Negate
;
736 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
738 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
740 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
741 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
742 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
744 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
745 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
746 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
749 index
= tgsi_src
->Register
.Index
;
750 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
751 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
752 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
753 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
754 r600_src
->swizzle
[0] = 3;
755 r600_src
->swizzle
[1] = 3;
756 r600_src
->swizzle
[2] = 3;
757 r600_src
->swizzle
[3] = 3;
759 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
760 r600_src
->swizzle
[0] = 0;
761 r600_src
->swizzle
[1] = 0;
762 r600_src
->swizzle
[2] = 0;
763 r600_src
->swizzle
[3] = 0;
767 if (tgsi_src
->Register
.Indirect
)
768 r600_src
->rel
= V_SQ_REL_RELATIVE
;
769 r600_src
->sel
= tgsi_src
->Register
.Index
;
770 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
772 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
773 if (tgsi_src
->Register
.Dimension
) {
774 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
779 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
781 struct r600_bytecode_vtx vtx
;
786 struct r600_bytecode_alu alu
;
788 memset(&alu
, 0, sizeof(alu
));
790 alu
.op
= ALU_OP2_ADD_INT
;
791 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
793 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
794 alu
.src
[1].value
= offset
;
796 alu
.dst
.sel
= dst_reg
;
800 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
805 ar_reg
= ctx
->bc
->ar_reg
;
808 memset(&vtx
, 0, sizeof(vtx
));
809 vtx
.buffer_id
= cb_idx
;
810 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
811 vtx
.src_gpr
= ar_reg
;
812 vtx
.mega_fetch_count
= 16;
813 vtx
.dst_gpr
= dst_reg
;
814 vtx
.dst_sel_x
= 0; /* SEL_X */
815 vtx
.dst_sel_y
= 1; /* SEL_Y */
816 vtx
.dst_sel_z
= 2; /* SEL_Z */
817 vtx
.dst_sel_w
= 3; /* SEL_W */
818 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
819 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
820 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
821 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
822 vtx
.endian
= r600_endian_swap(32);
824 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
830 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, unsigned index
, unsigned vtx_id
, unsigned int dst_reg
)
832 struct r600_bytecode_vtx vtx
;
834 int offset_reg
= vtx_id
/ 3;
835 int offset_chan
= vtx_id
% 3;
837 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
838 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
840 if (offset_reg
== 0 && offset_chan
== 2)
843 memset(&vtx
, 0, sizeof(vtx
));
844 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
845 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
846 vtx
.src_gpr
= offset_reg
;
847 vtx
.src_sel_x
= offset_chan
;
848 vtx
.offset
= index
* 16; /*bytes*/
849 vtx
.mega_fetch_count
= 16;
850 vtx
.dst_gpr
= dst_reg
;
851 vtx
.dst_sel_x
= 0; /* SEL_X */
852 vtx
.dst_sel_y
= 1; /* SEL_Y */
853 vtx
.dst_sel_z
= 2; /* SEL_Z */
854 vtx
.dst_sel_w
= 3; /* SEL_W */
855 vtx
.use_const_fields
= 1;
857 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
863 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
865 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
868 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
869 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
871 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
872 int treg
= r600_get_temp(ctx
);
873 int index
= src
->Register
.Index
;
874 int vtx_id
= src
->Dimension
.Index
;
876 fetch_gs_input(ctx
, index
, vtx_id
, treg
);
877 ctx
->src
[i
].sel
= treg
;
883 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
885 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
886 struct r600_bytecode_alu alu
;
887 int i
, j
, k
, nconst
, r
;
889 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
890 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
893 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
895 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
896 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
900 if (ctx
->src
[i
].rel
) {
901 int treg
= r600_get_temp(ctx
);
902 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
905 ctx
->src
[i
].kc_bank
= 0;
906 ctx
->src
[i
].sel
= treg
;
910 int treg
= r600_get_temp(ctx
);
911 for (k
= 0; k
< 4; k
++) {
912 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
913 alu
.op
= ALU_OP1_MOV
;
914 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
916 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
922 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
926 ctx
->src
[i
].sel
= treg
;
934 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
935 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
937 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
938 struct r600_bytecode_alu alu
;
939 int i
, j
, k
, nliteral
, r
;
941 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
942 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
946 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
947 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
948 int treg
= r600_get_temp(ctx
);
949 for (k
= 0; k
< 4; k
++) {
950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
951 alu
.op
= ALU_OP1_MOV
;
952 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
954 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
960 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
964 ctx
->src
[i
].sel
= treg
;
971 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
973 int i
, r
, count
= ctx
->shader
->ninput
;
975 for (i
= 0; i
< count
; i
++) {
976 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
977 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
985 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
)
987 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
990 /* Sanity checking. */
991 if (so
->num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
992 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
996 for (i
= 0; i
< so
->num_outputs
; i
++) {
997 if (so
->output
[i
].output_buffer
>= 4) {
998 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
999 so
->output
[i
].output_buffer
);
1005 /* Initialize locations where the outputs are stored. */
1006 for (i
= 0; i
< so
->num_outputs
; i
++) {
1007 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
1009 /* Lower outputs with dst_offset < start_component.
1011 * We can only output 4D vectors with a write mask, e.g. we can
1012 * only output the W component at offset 3, etc. If we want
1013 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1014 * to move it to X and output X. */
1015 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
1016 unsigned tmp
= r600_get_temp(ctx
);
1018 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
1019 struct r600_bytecode_alu alu
;
1020 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1021 alu
.op
= ALU_OP1_MOV
;
1022 alu
.src
[0].sel
= so_gpr
[i
];
1023 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
1028 if (j
== so
->output
[i
].num_components
- 1)
1030 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1034 so
->output
[i
].start_component
= 0;
1039 /* Write outputs to buffers. */
1040 for (i
= 0; i
< so
->num_outputs
; i
++) {
1041 struct r600_bytecode_output output
;
1043 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1044 output
.gpr
= so_gpr
[i
];
1045 output
.elem_size
= so
->output
[i
].num_components
;
1046 output
.array_base
= so
->output
[i
].dst_offset
- so
->output
[i
].start_component
;
1047 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1048 output
.burst_count
= 1;
1049 /* array_size is an upper limit for the burst_count
1050 * with MEM_STREAM instructions */
1051 output
.array_size
= 0xFFF;
1052 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << so
->output
[i
].start_component
;
1053 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1054 switch (so
->output
[i
].output_buffer
) {
1056 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1059 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1062 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1065 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1069 switch (so
->output
[i
].output_buffer
) {
1071 output
.op
= CF_OP_MEM_STREAM0
;
1074 output
.op
= CF_OP_MEM_STREAM1
;
1077 output
.op
= CF_OP_MEM_STREAM2
;
1080 output
.op
= CF_OP_MEM_STREAM3
;
1084 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
1093 static int generate_gs_copy_shader(struct r600_context
*rctx
,
1094 struct r600_pipe_shader
*gs
)
1096 struct r600_shader_ctx ctx
= {};
1097 struct r600_shader
*gs_shader
= &gs
->shader
;
1098 struct r600_pipe_shader
*cshader
;
1099 int ocnt
= gs_shader
->noutput
;
1100 struct r600_bytecode_alu alu
;
1101 struct r600_bytecode_vtx vtx
;
1102 struct r600_bytecode_output output
;
1103 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
1104 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
1105 int i
, next_pos
= 60, next_param
= 0;
1107 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
1111 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
1112 sizeof(struct r600_shader_io
));
1114 cshader
->shader
.noutput
= ocnt
;
1116 ctx
.shader
= &cshader
->shader
;
1117 ctx
.bc
= &ctx
.shader
->bc
;
1118 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
1120 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
1121 rctx
->screen
->has_compressed_msaa_texturing
);
1123 ctx
.bc
->isa
= rctx
->isa
;
1125 /* R0.x = R0.x & 0x3fffffff */
1126 memset(&alu
, 0, sizeof(alu
));
1127 alu
.op
= ALU_OP2_AND_INT
;
1128 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1129 alu
.src
[1].value
= 0x3fffffff;
1131 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1133 /* R0.y = R0.x >> 30 */
1134 memset(&alu
, 0, sizeof(alu
));
1135 alu
.op
= ALU_OP2_LSHR_INT
;
1136 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1137 alu
.src
[1].value
= 0x1e;
1141 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1143 /* PRED_SETE_INT __, R0.y, 0 */
1144 memset(&alu
, 0, sizeof(alu
));
1145 alu
.op
= ALU_OP2_PRED_SETE_INT
;
1146 alu
.src
[0].chan
= 1;
1147 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1148 alu
.execute_mask
= 1;
1149 alu
.update_pred
= 1;
1151 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
1153 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
1154 cf_jump
= ctx
.bc
->cf_last
;
1156 /* fetch vertex data from GSVS ring */
1157 for (i
= 0; i
< ocnt
; ++i
) {
1158 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1160 out
->ring_offset
= i
* 16;
1162 memset(&vtx
, 0, sizeof(vtx
));
1163 vtx
.op
= FETCH_OP_VFETCH
;
1164 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1166 vtx
.offset
= out
->ring_offset
;
1167 vtx
.dst_gpr
= out
->gpr
;
1172 vtx
.use_const_fields
= 1;
1174 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
1177 /* XXX handle clipvertex, streamout? */
1179 /* export vertex data */
1180 /* XXX factor out common code with r600_shader_from_tgsi ? */
1181 for (i
= 0; i
< ocnt
; ++i
) {
1182 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1184 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
1187 memset(&output
, 0, sizeof(output
));
1188 output
.gpr
= out
->gpr
;
1189 output
.elem_size
= 3;
1190 output
.swizzle_x
= 0;
1191 output
.swizzle_y
= 1;
1192 output
.swizzle_z
= 2;
1193 output
.swizzle_w
= 3;
1194 output
.burst_count
= 1;
1195 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1196 output
.op
= CF_OP_EXPORT
;
1197 switch (out
->name
) {
1198 case TGSI_SEMANTIC_POSITION
:
1199 output
.array_base
= next_pos
++;
1200 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1203 case TGSI_SEMANTIC_PSIZE
:
1204 output
.array_base
= next_pos
++;
1205 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1207 case TGSI_SEMANTIC_CLIPDIST
:
1208 /* spi_sid is 0 for clipdistance outputs that were generated
1209 * for clipvertex - we don't need to pass them to PS */
1211 /* duplicate it as PARAM to pass to the pixel shader */
1212 output
.array_base
= next_param
++;
1213 r600_bytecode_add_output(ctx
.bc
, &output
);
1214 last_exp_param
= ctx
.bc
->cf_last
;
1216 output
.array_base
= next_pos
++;
1217 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1219 case TGSI_SEMANTIC_FOG
:
1220 output
.swizzle_y
= 4; /* 0 */
1221 output
.swizzle_z
= 4; /* 0 */
1222 output
.swizzle_w
= 5; /* 1 */
1225 output
.array_base
= next_param
++;
1228 r600_bytecode_add_output(ctx
.bc
, &output
);
1229 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
1230 last_exp_param
= ctx
.bc
->cf_last
;
1232 last_exp_pos
= ctx
.bc
->cf_last
;
1235 if (!last_exp_pos
) {
1236 memset(&output
, 0, sizeof(output
));
1238 output
.elem_size
= 3;
1239 output
.swizzle_x
= 7;
1240 output
.swizzle_y
= 7;
1241 output
.swizzle_z
= 7;
1242 output
.swizzle_w
= 7;
1243 output
.burst_count
= 1;
1245 output
.op
= CF_OP_EXPORT
;
1246 output
.array_base
= next_pos
++;
1247 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1248 r600_bytecode_add_output(ctx
.bc
, &output
);
1249 last_exp_pos
= ctx
.bc
->cf_last
;
1252 if (!last_exp_param
) {
1253 memset(&output
, 0, sizeof(output
));
1255 output
.elem_size
= 3;
1256 output
.swizzle_x
= 7;
1257 output
.swizzle_y
= 7;
1258 output
.swizzle_z
= 7;
1259 output
.swizzle_w
= 7;
1260 output
.burst_count
= 1;
1262 output
.op
= CF_OP_EXPORT
;
1263 output
.array_base
= next_param
++;
1264 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1265 r600_bytecode_add_output(ctx
.bc
, &output
);
1266 last_exp_param
= ctx
.bc
->cf_last
;
1269 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
1270 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
1272 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1273 cf_pop
= ctx
.bc
->cf_last
;
1275 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1276 cf_jump
->pop_count
= 1;
1277 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1278 cf_pop
->pop_count
= 1;
1280 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1281 ctx
.bc
->cf_last
->end_of_program
= 1;
1283 gs
->gs_copy_shader
= cshader
;
1286 cshader
->shader
.ring_item_size
= ocnt
* 16;
1288 return r600_bytecode_build(ctx
.bc
);
1291 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
)
1293 struct r600_bytecode_output output
;
1294 int i
, k
, ring_offset
;
1296 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
1297 if (ctx
->gs_for_vs
) {
1298 /* for ES we need to lookup corresponding ring offset expected by GS
1299 * (map this output to GS input by name and sid) */
1300 /* FIXME precompute offsets */
1302 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
1303 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
1304 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
1305 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
1306 ring_offset
= in
->ring_offset
;
1309 if (ring_offset
== -1)
1312 ring_offset
= i
* 16;
1314 /* next_ring_offset after parsing input decls contains total size of
1315 * single vertex data, gs_next_vertex - current vertex index */
1316 ring_offset
+= ctx
->next_ring_offset
* ctx
->gs_next_vertex
;
1318 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1319 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
1320 output
.elem_size
= 3;
1321 output
.comp_mask
= 0xF;
1322 output
.burst_count
= 1;
1323 output
.op
= CF_OP_MEM_RING
;
1324 output
.array_base
= ring_offset
>> 2; /* in dwords */
1325 r600_bytecode_add_output(ctx
->bc
, &output
);
1327 ++ctx
->gs_next_vertex
;
1331 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
1332 struct r600_pipe_shader
*pipeshader
,
1333 struct r600_shader_key key
)
1335 struct r600_screen
*rscreen
= rctx
->screen
;
1336 struct r600_shader
*shader
= &pipeshader
->shader
;
1337 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1338 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1339 struct tgsi_full_immediate
*immediate
;
1340 struct tgsi_full_property
*property
;
1341 struct r600_shader_ctx ctx
;
1342 struct r600_bytecode_output output
[32];
1343 unsigned output_done
, noutput
;
1346 int next_pos_base
= 60, next_param_base
= 0;
1347 int max_color_exports
= MAX2(key
.nr_cbufs
, 1);
1348 /* Declarations used by llvm code */
1349 bool use_llvm
= false;
1351 bool ring_outputs
= false;
1353 #ifdef R600_USE_LLVM
1354 use_llvm
= !(rscreen
->b
.debug_flags
& DBG_NO_LLVM
);
1356 ctx
.bc
= &shader
->bc
;
1357 ctx
.shader
= shader
;
1358 ctx
.native_integers
= true;
1360 shader
->vs_as_es
= key
.vs_as_es
;
1362 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
1363 rscreen
->has_compressed_msaa_texturing
);
1364 ctx
.tokens
= tokens
;
1365 tgsi_scan_shader(tokens
, &ctx
.info
);
1366 shader
->indirect_files
= ctx
.info
.indirect_files
;
1367 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
1368 tgsi_parse_init(&ctx
.parse
, tokens
);
1369 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1370 shader
->processor_type
= ctx
.type
;
1371 ctx
.bc
->type
= shader
->processor_type
;
1373 ring_outputs
= key
.vs_as_es
|| (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
);
1376 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
1378 ctx
.gs_for_vs
= NULL
;
1381 ctx
.next_ring_offset
= 0;
1382 ctx
.gs_next_vertex
= 0;
1385 ctx
.fragcoord_input
= -1;
1386 ctx
.colors_used
= 0;
1387 ctx
.clip_vertex_write
= 0;
1389 shader
->nr_ps_color_exports
= 0;
1390 shader
->nr_ps_max_color_exports
= 0;
1392 shader
->two_side
= key
.color_two_side
;
1394 /* register allocations */
1395 /* Values [0,127] correspond to GPR[0..127].
1396 * Values [128,159] correspond to constant buffer bank 0
1397 * Values [160,191] correspond to constant buffer bank 1
1398 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1399 * Values [256,287] correspond to constant buffer bank 2 (EG)
1400 * Values [288,319] correspond to constant buffer bank 3 (EG)
1401 * Other special values are shown in the list below.
1402 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1403 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1404 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1405 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1406 * 248 SQ_ALU_SRC_0: special constant 0.0.
1407 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1408 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1409 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1410 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1411 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1412 * 254 SQ_ALU_SRC_PV: previous vector result.
1413 * 255 SQ_ALU_SRC_PS: previous scalar result.
1415 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1416 ctx
.file_offset
[i
] = 0;
1419 #ifdef R600_USE_LLVM
1420 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1421 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1422 "indirect adressing. Falling back to TGSI "
1427 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1428 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1430 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1433 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1434 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1436 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1437 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
1438 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
1440 ctx
.use_llvm
= use_llvm
;
1443 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1444 ctx
.file_offset
[TGSI_FILE_INPUT
];
1446 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1447 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1448 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1450 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1451 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1453 /* Outside the GPR range. This will be translated to one of the
1454 * kcache banks later. */
1455 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1457 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1458 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1459 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1460 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1462 if (indirect_gprs
) {
1463 shader
->max_arrays
= 0;
1464 shader
->num_arrays
= 0;
1466 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1467 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1468 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1469 ctx
.file_offset
[TGSI_FILE_INPUT
],
1472 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1473 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1474 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1475 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1481 ctx
.literals
= NULL
;
1482 shader
->fs_write_all
= FALSE
;
1483 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1484 tgsi_parse_token(&ctx
.parse
);
1485 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1486 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1487 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1488 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1489 if(ctx
.literals
== NULL
) {
1493 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1494 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1495 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1496 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1499 case TGSI_TOKEN_TYPE_DECLARATION
:
1500 r
= tgsi_declaration(&ctx
);
1504 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1506 case TGSI_TOKEN_TYPE_PROPERTY
:
1507 property
= &ctx
.parse
.FullToken
.FullProperty
;
1508 switch (property
->Property
.PropertyName
) {
1509 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1510 if (property
->u
[0].Data
== 1)
1511 shader
->fs_write_all
= TRUE
;
1513 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1514 /* we don't need this one */
1516 case TGSI_PROPERTY_GS_INPUT_PRIM
:
1517 shader
->gs_input_prim
= property
->u
[0].Data
;
1519 case TGSI_PROPERTY_GS_OUTPUT_PRIM
:
1520 shader
->gs_output_prim
= property
->u
[0].Data
;
1522 case TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
:
1523 shader
->gs_max_out_vertices
= property
->u
[0].Data
;
1528 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1534 shader
->ring_item_size
= ctx
.next_ring_offset
;
1536 /* Process two side if needed */
1537 if (shader
->two_side
&& ctx
.colors_used
) {
1538 int i
, count
= ctx
.shader
->ninput
;
1539 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1541 /* additional inputs will be allocated right after the existing inputs,
1542 * we won't need them after the color selection, so we don't need to
1543 * reserve these gprs for the rest of the shader code and to adjust
1544 * output offsets etc. */
1545 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1546 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1548 if (ctx
.face_gpr
== -1) {
1549 i
= ctx
.shader
->ninput
++;
1550 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1551 ctx
.shader
->input
[i
].spi_sid
= 0;
1552 ctx
.shader
->input
[i
].gpr
= gpr
++;
1553 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1556 for (i
= 0; i
< count
; i
++) {
1557 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1558 int ni
= ctx
.shader
->ninput
++;
1559 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1560 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1561 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1562 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1563 // TGSI to LLVM needs to know the lds position of inputs.
1564 // Non LLVM path computes it later (in process_twoside_color)
1565 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1566 ctx
.shader
->input
[i
].back_color_input
= ni
;
1567 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1568 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1575 /* LLVM backend setup */
1576 #ifdef R600_USE_LLVM
1578 struct radeon_llvm_context radeon_llvm_ctx
;
1580 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
1581 boolean use_kill
= false;
1583 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1584 radeon_llvm_ctx
.type
= ctx
.type
;
1585 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1586 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1587 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
1588 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1589 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1590 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
1591 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1592 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
1593 radeon_llvm_ctx
.stream_outputs
= &so
;
1594 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1595 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1596 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
1597 ctx
.bc
->has_compressed_msaa_texturing
;
1598 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1599 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1600 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
1602 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
1603 radeon_llvm_dispose(&radeon_llvm_ctx
);
1605 fprintf(stderr
, "R600 LLVM backend failed to compile "
1606 "shader. Falling back to TGSI\n");
1608 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1609 ctx
.file_offset
[TGSI_FILE_INPUT
];
1612 ctx
.shader
->uses_kill
= use_kill
;
1613 radeon_llvm_dispose(&radeon_llvm_ctx
);
1616 /* End of LLVM backend setup */
1618 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
1619 shader
->nr_ps_max_color_exports
= 8;
1622 if (ctx
.fragcoord_input
>= 0) {
1623 if (ctx
.bc
->chip_class
== CAYMAN
) {
1624 for (j
= 0 ; j
< 4; j
++) {
1625 struct r600_bytecode_alu alu
;
1626 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1627 alu
.op
= ALU_OP1_RECIP_IEEE
;
1628 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1629 alu
.src
[0].chan
= 3;
1631 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1633 alu
.dst
.write
= (j
== 3);
1635 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1639 struct r600_bytecode_alu alu
;
1640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1641 alu
.op
= ALU_OP1_RECIP_IEEE
;
1642 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1643 alu
.src
[0].chan
= 3;
1645 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1649 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1654 if (shader
->two_side
&& ctx
.colors_used
) {
1655 if ((r
= process_twoside_color_inputs(&ctx
)))
1659 tgsi_parse_init(&ctx
.parse
, tokens
);
1660 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1661 tgsi_parse_token(&ctx
.parse
);
1662 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1663 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1664 r
= tgsi_is_supported(&ctx
);
1667 ctx
.max_driver_temp_used
= 0;
1668 /* reserve first tmp for everyone */
1669 r600_get_temp(&ctx
);
1671 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1672 if ((r
= tgsi_split_constant(&ctx
)))
1674 if ((r
= tgsi_split_literal_constant(&ctx
)))
1676 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
)
1677 if ((r
= tgsi_split_gs_inputs(&ctx
)))
1679 if (ctx
.bc
->chip_class
== CAYMAN
)
1680 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1681 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1682 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1684 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1685 r
= ctx
.inst_info
->process(&ctx
);
1695 /* Reset the temporary register counter. */
1696 ctx
.max_driver_temp_used
= 0;
1698 noutput
= shader
->noutput
;
1700 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
1701 unsigned clipdist_temp
[2];
1703 clipdist_temp
[0] = r600_get_temp(&ctx
);
1704 clipdist_temp
[1] = r600_get_temp(&ctx
);
1706 /* need to convert a clipvertex write into clipdistance writes and not export
1707 the clip vertex anymore */
1709 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1710 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1711 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1713 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1714 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1717 /* reset spi_sid for clipvertex output to avoid confusing spi */
1718 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1720 shader
->clip_dist_write
= 0xFF;
1722 for (i
= 0; i
< 8; i
++) {
1726 for (j
= 0; j
< 4; j
++) {
1727 struct r600_bytecode_alu alu
;
1728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1729 alu
.op
= ALU_OP2_DOT4
;
1730 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1731 alu
.src
[0].chan
= j
;
1733 alu
.src
[1].sel
= 512 + i
;
1734 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1735 alu
.src
[1].chan
= j
;
1737 alu
.dst
.sel
= clipdist_temp
[oreg
];
1739 alu
.dst
.write
= (j
== ochan
);
1743 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1750 /* Add stream outputs. */
1751 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
&&
1752 so
.num_outputs
&& !use_llvm
)
1753 emit_streamout(&ctx
, &so
);
1757 emit_gs_ring_writes(&ctx
);
1760 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1761 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1762 output
[j
].gpr
= shader
->output
[i
].gpr
;
1763 output
[j
].elem_size
= 3;
1764 output
[j
].swizzle_x
= 0;
1765 output
[j
].swizzle_y
= 1;
1766 output
[j
].swizzle_z
= 2;
1767 output
[j
].swizzle_w
= 3;
1768 output
[j
].burst_count
= 1;
1769 output
[j
].type
= -1;
1770 output
[j
].op
= CF_OP_EXPORT
;
1772 case TGSI_PROCESSOR_VERTEX
:
1773 switch (shader
->output
[i
].name
) {
1774 case TGSI_SEMANTIC_POSITION
:
1775 output
[j
].array_base
= next_pos_base
++;
1776 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1779 case TGSI_SEMANTIC_PSIZE
:
1780 output
[j
].array_base
= next_pos_base
++;
1781 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1783 case TGSI_SEMANTIC_CLIPVERTEX
:
1786 case TGSI_SEMANTIC_CLIPDIST
:
1787 output
[j
].array_base
= next_pos_base
++;
1788 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1789 /* spi_sid is 0 for clipdistance outputs that were generated
1790 * for clipvertex - we don't need to pass them to PS */
1791 if (shader
->output
[i
].spi_sid
) {
1793 /* duplicate it as PARAM to pass to the pixel shader */
1794 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1795 output
[j
].array_base
= next_param_base
++;
1796 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1799 case TGSI_SEMANTIC_FOG
:
1800 output
[j
].swizzle_y
= 4; /* 0 */
1801 output
[j
].swizzle_z
= 4; /* 0 */
1802 output
[j
].swizzle_w
= 5; /* 1 */
1806 case TGSI_PROCESSOR_FRAGMENT
:
1807 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1808 /* never export more colors than the number of CBs */
1809 if (shader
->output
[i
].sid
>= max_color_exports
) {
1814 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1815 output
[j
].array_base
= shader
->output
[i
].sid
;
1816 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1817 shader
->nr_ps_color_exports
++;
1818 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
1819 for (k
= 1; k
< max_color_exports
; k
++) {
1821 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1822 output
[j
].gpr
= shader
->output
[i
].gpr
;
1823 output
[j
].elem_size
= 3;
1824 output
[j
].swizzle_x
= 0;
1825 output
[j
].swizzle_y
= 1;
1826 output
[j
].swizzle_z
= 2;
1827 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1828 output
[j
].burst_count
= 1;
1829 output
[j
].array_base
= k
;
1830 output
[j
].op
= CF_OP_EXPORT
;
1831 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1832 shader
->nr_ps_color_exports
++;
1835 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
1836 output
[j
].array_base
= 61;
1837 output
[j
].swizzle_x
= 2;
1838 output
[j
].swizzle_y
= 7;
1839 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1840 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1841 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
1842 output
[j
].array_base
= 61;
1843 output
[j
].swizzle_x
= 7;
1844 output
[j
].swizzle_y
= 1;
1845 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
1846 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1848 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
1854 R600_ERR("unsupported processor type %d\n", ctx
.type
);
1859 if (output
[j
].type
==-1) {
1860 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1861 output
[j
].array_base
= next_param_base
++;
1865 /* add fake position export */
1866 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_pos_base
== 60) {
1867 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1869 output
[j
].elem_size
= 3;
1870 output
[j
].swizzle_x
= 7;
1871 output
[j
].swizzle_y
= 7;
1872 output
[j
].swizzle_z
= 7;
1873 output
[j
].swizzle_w
= 7;
1874 output
[j
].burst_count
= 1;
1875 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1876 output
[j
].array_base
= next_pos_base
;
1877 output
[j
].op
= CF_OP_EXPORT
;
1881 /* add fake param output for vertex shader if no param is exported */
1882 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
1883 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1885 output
[j
].elem_size
= 3;
1886 output
[j
].swizzle_x
= 7;
1887 output
[j
].swizzle_y
= 7;
1888 output
[j
].swizzle_z
= 7;
1889 output
[j
].swizzle_w
= 7;
1890 output
[j
].burst_count
= 1;
1891 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1892 output
[j
].array_base
= 0;
1893 output
[j
].op
= CF_OP_EXPORT
;
1897 /* add fake pixel export */
1898 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
1899 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1901 output
[j
].elem_size
= 3;
1902 output
[j
].swizzle_x
= 7;
1903 output
[j
].swizzle_y
= 7;
1904 output
[j
].swizzle_z
= 7;
1905 output
[j
].swizzle_w
= 7;
1906 output
[j
].burst_count
= 1;
1907 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1908 output
[j
].array_base
= 0;
1909 output
[j
].op
= CF_OP_EXPORT
;
1915 /* set export done on last export of each type */
1916 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
1917 if (!(output_done
& (1 << output
[i
].type
))) {
1918 output_done
|= (1 << output
[i
].type
);
1919 output
[i
].op
= CF_OP_EXPORT_DONE
;
1922 /* add output to bytecode */
1924 for (i
= 0; i
< noutput
; i
++) {
1925 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
1932 /* add program end */
1934 if (ctx
.bc
->chip_class
== CAYMAN
)
1935 cm_bytecode_add_cf_end(ctx
.bc
);
1937 const struct cf_op_info
*last
= NULL
;
1939 if (ctx
.bc
->cf_last
)
1940 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
1942 /* alu clause instructions don't have EOP bit, so add NOP */
1943 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
)
1944 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1946 ctx
.bc
->cf_last
->end_of_program
= 1;
1950 /* check GPR limit - we have 124 = 128 - 4
1951 * (4 are reserved as alu clause temporary registers) */
1952 if (ctx
.bc
->ngpr
> 124) {
1953 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
1958 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1959 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
)))
1964 tgsi_parse_free(&ctx
.parse
);
1968 tgsi_parse_free(&ctx
.parse
);
1972 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
1974 R600_ERR("%s tgsi opcode unsupported\n",
1975 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
1979 static int tgsi_end(struct r600_shader_ctx
*ctx
)
1984 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
1985 const struct r600_shader_src
*shader_src
,
1988 bc_src
->sel
= shader_src
->sel
;
1989 bc_src
->chan
= shader_src
->swizzle
[chan
];
1990 bc_src
->neg
= shader_src
->neg
;
1991 bc_src
->abs
= shader_src
->abs
;
1992 bc_src
->rel
= shader_src
->rel
;
1993 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
1994 bc_src
->kc_bank
= shader_src
->kc_bank
;
1997 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2003 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2005 bc_src
->neg
= !bc_src
->neg
;
2008 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2009 const struct tgsi_full_dst_register
*tgsi_dst
,
2011 struct r600_bytecode_alu_dst
*r600_dst
)
2013 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2015 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2016 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2017 r600_dst
->chan
= swizzle
;
2018 r600_dst
->write
= 1;
2019 if (tgsi_dst
->Register
.Indirect
)
2020 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2021 if (inst
->Instruction
.Saturate
) {
2022 r600_dst
->clamp
= 1;
2026 static int tgsi_last_instruction(unsigned writemask
)
2030 for (i
= 0; i
< 4; i
++) {
2031 if (writemask
& (1 << i
)) {
2038 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
2040 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2041 struct r600_bytecode_alu alu
;
2042 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2043 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2044 /* use temp register if trans_only and more than one dst component */
2045 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
2047 for (i
= 0; i
<= lasti
; i
++) {
2048 if (!(write_mask
& (1 << i
)))
2051 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2053 alu
.dst
.sel
= ctx
->temp_reg
;
2057 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2059 alu
.op
= ctx
->inst_info
->op
;
2061 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2062 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2065 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2066 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2068 /* handle some special cases */
2069 switch (ctx
->inst_info
->tgsi_opcode
) {
2070 case TGSI_OPCODE_SUB
:
2071 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2073 case TGSI_OPCODE_ABS
:
2074 r600_bytecode_src_set_abs(&alu
.src
[0]);
2079 if (i
== lasti
|| trans_only
) {
2082 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2088 /* move result from temp to dst */
2089 for (i
= 0; i
<= lasti
; i
++) {
2090 if (!(write_mask
& (1 << i
)))
2093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2094 alu
.op
= ALU_OP1_MOV
;
2095 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2096 alu
.src
[0].sel
= ctx
->temp_reg
;
2097 alu
.src
[0].chan
= i
;
2098 alu
.last
= (i
== lasti
);
2100 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2108 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2110 return tgsi_op2_s(ctx
, 0, 0);
2113 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2115 return tgsi_op2_s(ctx
, 1, 0);
2118 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2120 return tgsi_op2_s(ctx
, 0, 1);
2123 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2125 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2126 struct r600_bytecode_alu alu
;
2128 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2130 for (i
= 0; i
< lasti
+ 1; i
++) {
2132 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2134 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2135 alu
.op
= ctx
->inst_info
->op
;
2137 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2139 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2141 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2146 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2154 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2156 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2158 struct r600_bytecode_alu alu
;
2159 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2161 for (i
= 0 ; i
< last_slot
; i
++) {
2162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2163 alu
.op
= ctx
->inst_info
->op
;
2164 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2165 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2167 /* RSQ should take the absolute value of src */
2168 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2169 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2172 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2173 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2175 if (i
== last_slot
- 1)
2177 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2184 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2186 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2188 struct r600_bytecode_alu alu
;
2189 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2190 for (k
= 0; k
< last_slot
; k
++) {
2191 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2194 for (i
= 0 ; i
< 4; i
++) {
2195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2196 alu
.op
= ctx
->inst_info
->op
;
2197 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2198 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2200 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2201 alu
.dst
.write
= (i
== k
);
2204 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2213 * r600 - trunc to -PI..PI range
2214 * r700 - normalize by dividing by 2PI
2217 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2219 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2220 static float double_pi
= 3.1415926535 * 2;
2221 static float neg_pi
= -3.1415926535;
2224 struct r600_bytecode_alu alu
;
2226 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2227 alu
.op
= ALU_OP3_MULADD
;
2231 alu
.dst
.sel
= ctx
->temp_reg
;
2234 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2236 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2237 alu
.src
[1].chan
= 0;
2238 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2239 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2240 alu
.src
[2].chan
= 0;
2242 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2246 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2247 alu
.op
= ALU_OP1_FRACT
;
2250 alu
.dst
.sel
= ctx
->temp_reg
;
2253 alu
.src
[0].sel
= ctx
->temp_reg
;
2254 alu
.src
[0].chan
= 0;
2256 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2261 alu
.op
= ALU_OP3_MULADD
;
2265 alu
.dst
.sel
= ctx
->temp_reg
;
2268 alu
.src
[0].sel
= ctx
->temp_reg
;
2269 alu
.src
[0].chan
= 0;
2271 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2272 alu
.src
[1].chan
= 0;
2273 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2274 alu
.src
[2].chan
= 0;
2276 if (ctx
->bc
->chip_class
== R600
) {
2277 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2278 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2280 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2281 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2286 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2292 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2294 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2295 struct r600_bytecode_alu alu
;
2296 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2299 r
= tgsi_setup_trig(ctx
);
2304 for (i
= 0; i
< last_slot
; i
++) {
2305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2306 alu
.op
= ctx
->inst_info
->op
;
2309 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2310 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2312 alu
.src
[0].sel
= ctx
->temp_reg
;
2313 alu
.src
[0].chan
= 0;
2314 if (i
== last_slot
- 1)
2316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2323 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2325 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2326 struct r600_bytecode_alu alu
;
2328 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2330 r
= tgsi_setup_trig(ctx
);
2334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2335 alu
.op
= ctx
->inst_info
->op
;
2337 alu
.dst
.sel
= ctx
->temp_reg
;
2340 alu
.src
[0].sel
= ctx
->temp_reg
;
2341 alu
.src
[0].chan
= 0;
2343 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2347 /* replicate result */
2348 for (i
= 0; i
< lasti
+ 1; i
++) {
2349 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2352 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2353 alu
.op
= ALU_OP1_MOV
;
2355 alu
.src
[0].sel
= ctx
->temp_reg
;
2356 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2359 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2366 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2368 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2369 struct r600_bytecode_alu alu
;
2372 /* We'll only need the trig stuff if we are going to write to the
2373 * X or Y components of the destination vector.
2375 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2376 r
= tgsi_setup_trig(ctx
);
2382 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2383 if (ctx
->bc
->chip_class
== CAYMAN
) {
2384 for (i
= 0 ; i
< 3; i
++) {
2385 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2386 alu
.op
= ALU_OP1_COS
;
2387 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2393 alu
.src
[0].sel
= ctx
->temp_reg
;
2394 alu
.src
[0].chan
= 0;
2397 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2402 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2403 alu
.op
= ALU_OP1_COS
;
2404 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2406 alu
.src
[0].sel
= ctx
->temp_reg
;
2407 alu
.src
[0].chan
= 0;
2409 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2416 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2417 if (ctx
->bc
->chip_class
== CAYMAN
) {
2418 for (i
= 0 ; i
< 3; i
++) {
2419 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2420 alu
.op
= ALU_OP1_SIN
;
2421 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2426 alu
.src
[0].sel
= ctx
->temp_reg
;
2427 alu
.src
[0].chan
= 0;
2430 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2436 alu
.op
= ALU_OP1_SIN
;
2437 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2439 alu
.src
[0].sel
= ctx
->temp_reg
;
2440 alu
.src
[0].chan
= 0;
2442 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2449 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2450 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2452 alu
.op
= ALU_OP1_MOV
;
2454 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2456 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2457 alu
.src
[0].chan
= 0;
2461 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2467 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2470 alu
.op
= ALU_OP1_MOV
;
2472 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2474 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2475 alu
.src
[0].chan
= 0;
2479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2487 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2489 struct r600_bytecode_alu alu
;
2492 for (i
= 0; i
< 4; i
++) {
2493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2494 alu
.op
= ctx
->inst_info
->op
;
2498 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2500 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILL
) {
2501 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2504 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2509 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2514 /* kill must be last in ALU */
2515 ctx
->bc
->force_add_cf
= 1;
2516 ctx
->shader
->uses_kill
= TRUE
;
2520 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2522 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2523 struct r600_bytecode_alu alu
;
2526 /* tmp.x = max(src.y, 0.0) */
2527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2528 alu
.op
= ALU_OP2_MAX
;
2529 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2530 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2531 alu
.src
[1].chan
= 1;
2533 alu
.dst
.sel
= ctx
->temp_reg
;
2538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2542 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2548 if (ctx
->bc
->chip_class
== CAYMAN
) {
2549 for (i
= 0; i
< 3; i
++) {
2550 /* tmp.z = log(tmp.x) */
2551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2552 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2553 alu
.src
[0].sel
= ctx
->temp_reg
;
2554 alu
.src
[0].chan
= 0;
2555 alu
.dst
.sel
= ctx
->temp_reg
;
2563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2568 /* tmp.z = log(tmp.x) */
2569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2570 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2571 alu
.src
[0].sel
= ctx
->temp_reg
;
2572 alu
.src
[0].chan
= 0;
2573 alu
.dst
.sel
= ctx
->temp_reg
;
2577 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2582 chan
= alu
.dst
.chan
;
2585 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2586 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2587 alu
.op
= ALU_OP3_MUL_LIT
;
2588 alu
.src
[0].sel
= sel
;
2589 alu
.src
[0].chan
= chan
;
2590 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2591 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2592 alu
.dst
.sel
= ctx
->temp_reg
;
2597 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2601 if (ctx
->bc
->chip_class
== CAYMAN
) {
2602 for (i
= 0; i
< 3; i
++) {
2603 /* dst.z = exp(tmp.x) */
2604 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2605 alu
.op
= ALU_OP1_EXP_IEEE
;
2606 alu
.src
[0].sel
= ctx
->temp_reg
;
2607 alu
.src
[0].chan
= 0;
2608 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2614 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2619 /* dst.z = exp(tmp.x) */
2620 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2621 alu
.op
= ALU_OP1_EXP_IEEE
;
2622 alu
.src
[0].sel
= ctx
->temp_reg
;
2623 alu
.src
[0].chan
= 0;
2624 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2626 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2633 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2634 alu
.op
= ALU_OP1_MOV
;
2635 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2636 alu
.src
[0].chan
= 0;
2637 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2638 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2639 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2643 /* dst.y = max(src.x, 0.0) */
2644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2645 alu
.op
= ALU_OP2_MAX
;
2646 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2647 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2648 alu
.src
[1].chan
= 0;
2649 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2650 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2651 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2657 alu
.op
= ALU_OP1_MOV
;
2658 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2659 alu
.src
[0].chan
= 0;
2660 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2661 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2663 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2670 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2672 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2673 struct r600_bytecode_alu alu
;
2676 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2679 * For state trackers other than OpenGL, we'll want to use
2680 * _RECIPSQRT_IEEE instead.
2682 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2684 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2685 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2686 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2688 alu
.dst
.sel
= ctx
->temp_reg
;
2691 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2694 /* replicate result */
2695 return tgsi_helper_tempx_replicate(ctx
);
2698 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2700 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2701 struct r600_bytecode_alu alu
;
2704 for (i
= 0; i
< 4; i
++) {
2705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2706 alu
.src
[0].sel
= ctx
->temp_reg
;
2707 alu
.op
= ALU_OP1_MOV
;
2709 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2710 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2713 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2720 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2722 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2723 struct r600_bytecode_alu alu
;
2726 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2727 alu
.op
= ctx
->inst_info
->op
;
2728 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2729 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2731 alu
.dst
.sel
= ctx
->temp_reg
;
2734 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2737 /* replicate result */
2738 return tgsi_helper_tempx_replicate(ctx
);
2741 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2743 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2745 struct r600_bytecode_alu alu
;
2746 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2748 for (i
= 0; i
< 3; i
++) {
2749 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2750 alu
.op
= ALU_OP1_LOG_IEEE
;
2751 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2752 alu
.dst
.sel
= ctx
->temp_reg
;
2757 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2763 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2764 alu
.op
= ALU_OP2_MUL
;
2765 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2766 alu
.src
[1].sel
= ctx
->temp_reg
;
2767 alu
.dst
.sel
= ctx
->temp_reg
;
2770 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2774 for (i
= 0; i
< last_slot
; i
++) {
2775 /* POW(a,b) = EXP2(b * LOG2(a))*/
2776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2777 alu
.op
= ALU_OP1_EXP_IEEE
;
2778 alu
.src
[0].sel
= ctx
->temp_reg
;
2780 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2781 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2782 if (i
== last_slot
- 1)
2784 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2791 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2793 struct r600_bytecode_alu alu
;
2797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2798 alu
.op
= ALU_OP1_LOG_IEEE
;
2799 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2800 alu
.dst
.sel
= ctx
->temp_reg
;
2803 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2807 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2808 alu
.op
= ALU_OP2_MUL
;
2809 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2810 alu
.src
[1].sel
= ctx
->temp_reg
;
2811 alu
.dst
.sel
= ctx
->temp_reg
;
2814 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2817 /* POW(a,b) = EXP2(b * LOG2(a))*/
2818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2819 alu
.op
= ALU_OP1_EXP_IEEE
;
2820 alu
.src
[0].sel
= ctx
->temp_reg
;
2821 alu
.dst
.sel
= ctx
->temp_reg
;
2824 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2827 return tgsi_helper_tempx_replicate(ctx
);
2830 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2832 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2833 struct r600_bytecode_alu alu
;
2835 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2836 int tmp0
= ctx
->temp_reg
;
2837 int tmp1
= r600_get_temp(ctx
);
2838 int tmp2
= r600_get_temp(ctx
);
2839 int tmp3
= r600_get_temp(ctx
);
2842 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
2844 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
2845 * 2. tmp0.z = lo (tmp0.x * src2)
2846 * 3. tmp0.w = -tmp0.z
2847 * 4. tmp0.y = hi (tmp0.x * src2)
2848 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
2849 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
2850 * 7. tmp1.x = tmp0.x - tmp0.w
2851 * 8. tmp1.y = tmp0.x + tmp0.w
2852 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
2853 * 10. tmp0.z = hi(tmp0.x * src1) = q
2854 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
2856 * 12. tmp0.w = src1 - tmp0.y = r
2857 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
2858 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
2862 * 15. tmp1.z = tmp0.z + 1 = q + 1
2863 * 16. tmp1.w = tmp0.z - 1 = q - 1
2867 * 15. tmp1.z = tmp0.w - src2 = r - src2
2868 * 16. tmp1.w = tmp0.w + src2 = r + src2
2872 * 17. tmp1.x = tmp1.x & tmp1.y
2874 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
2875 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
2877 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
2878 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
2882 * Same as unsigned, using abs values of the operands,
2883 * and fixing the sign of the result in the end.
2886 for (i
= 0; i
< 4; i
++) {
2887 if (!(write_mask
& (1<<i
)))
2892 /* tmp2.x = -src0 */
2893 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2894 alu
.op
= ALU_OP2_SUB_INT
;
2900 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2902 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2905 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2908 /* tmp2.y = -src1 */
2909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2910 alu
.op
= ALU_OP2_SUB_INT
;
2916 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2918 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2921 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2924 /* tmp2.z sign bit is set if src0 and src2 signs are different */
2925 /* it will be a sign of the quotient */
2928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2929 alu
.op
= ALU_OP2_XOR_INT
;
2935 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2936 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2939 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2943 /* tmp2.x = |src0| */
2944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2945 alu
.op
= ALU_OP3_CNDGE_INT
;
2952 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2953 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2954 alu
.src
[2].sel
= tmp2
;
2955 alu
.src
[2].chan
= 0;
2958 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2961 /* tmp2.y = |src1| */
2962 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2963 alu
.op
= ALU_OP3_CNDGE_INT
;
2970 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2971 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
2972 alu
.src
[2].sel
= tmp2
;
2973 alu
.src
[2].chan
= 1;
2976 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
2981 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
2982 if (ctx
->bc
->chip_class
== CAYMAN
) {
2983 /* tmp3.x = u2f(src2) */
2984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2985 alu
.op
= ALU_OP1_UINT_TO_FLT
;
2992 alu
.src
[0].sel
= tmp2
;
2993 alu
.src
[0].chan
= 1;
2995 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2999 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3002 /* tmp0.x = recip(tmp3.x) */
3003 for (j
= 0 ; j
< 3; j
++) {
3004 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3005 alu
.op
= ALU_OP1_RECIP_IEEE
;
3009 alu
.dst
.write
= (j
== 0);
3011 alu
.src
[0].sel
= tmp3
;
3012 alu
.src
[0].chan
= 0;
3016 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3020 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3021 alu
.op
= ALU_OP2_MUL
;
3023 alu
.src
[0].sel
= tmp0
;
3024 alu
.src
[0].chan
= 0;
3026 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3027 alu
.src
[1].value
= 0x4f800000;
3032 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3037 alu
.op
= ALU_OP1_FLT_TO_UINT
;
3043 alu
.src
[0].sel
= tmp3
;
3044 alu
.src
[0].chan
= 0;
3047 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3051 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3052 alu
.op
= ALU_OP1_RECIP_UINT
;
3059 alu
.src
[0].sel
= tmp2
;
3060 alu
.src
[0].chan
= 1;
3062 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3066 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3070 /* 2. tmp0.z = lo (tmp0.x * src2) */
3071 if (ctx
->bc
->chip_class
== CAYMAN
) {
3072 for (j
= 0 ; j
< 4; j
++) {
3073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3074 alu
.op
= ALU_OP2_MULLO_UINT
;
3078 alu
.dst
.write
= (j
== 2);
3080 alu
.src
[0].sel
= tmp0
;
3081 alu
.src
[0].chan
= 0;
3083 alu
.src
[1].sel
= tmp2
;
3084 alu
.src
[1].chan
= 1;
3086 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3089 alu
.last
= (j
== 3);
3090 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3094 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3095 alu
.op
= ALU_OP2_MULLO_UINT
;
3101 alu
.src
[0].sel
= tmp0
;
3102 alu
.src
[0].chan
= 0;
3104 alu
.src
[1].sel
= tmp2
;
3105 alu
.src
[1].chan
= 1;
3107 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3111 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3115 /* 3. tmp0.w = -tmp0.z */
3116 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3117 alu
.op
= ALU_OP2_SUB_INT
;
3123 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3124 alu
.src
[1].sel
= tmp0
;
3125 alu
.src
[1].chan
= 2;
3128 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3131 /* 4. tmp0.y = hi (tmp0.x * src2) */
3132 if (ctx
->bc
->chip_class
== CAYMAN
) {
3133 for (j
= 0 ; j
< 4; j
++) {
3134 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3135 alu
.op
= ALU_OP2_MULHI_UINT
;
3139 alu
.dst
.write
= (j
== 1);
3141 alu
.src
[0].sel
= tmp0
;
3142 alu
.src
[0].chan
= 0;
3145 alu
.src
[1].sel
= tmp2
;
3146 alu
.src
[1].chan
= 1;
3148 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3150 alu
.last
= (j
== 3);
3151 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3155 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3156 alu
.op
= ALU_OP2_MULHI_UINT
;
3162 alu
.src
[0].sel
= tmp0
;
3163 alu
.src
[0].chan
= 0;
3166 alu
.src
[1].sel
= tmp2
;
3167 alu
.src
[1].chan
= 1;
3169 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3173 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3177 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3178 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3179 alu
.op
= ALU_OP3_CNDE_INT
;
3186 alu
.src
[0].sel
= tmp0
;
3187 alu
.src
[0].chan
= 1;
3188 alu
.src
[1].sel
= tmp0
;
3189 alu
.src
[1].chan
= 3;
3190 alu
.src
[2].sel
= tmp0
;
3191 alu
.src
[2].chan
= 2;
3194 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3197 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3198 if (ctx
->bc
->chip_class
== CAYMAN
) {
3199 for (j
= 0 ; j
< 4; j
++) {
3200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3201 alu
.op
= ALU_OP2_MULHI_UINT
;
3205 alu
.dst
.write
= (j
== 3);
3207 alu
.src
[0].sel
= tmp0
;
3208 alu
.src
[0].chan
= 2;
3210 alu
.src
[1].sel
= tmp0
;
3211 alu
.src
[1].chan
= 0;
3213 alu
.last
= (j
== 3);
3214 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3218 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3219 alu
.op
= ALU_OP2_MULHI_UINT
;
3225 alu
.src
[0].sel
= tmp0
;
3226 alu
.src
[0].chan
= 2;
3228 alu
.src
[1].sel
= tmp0
;
3229 alu
.src
[1].chan
= 0;
3232 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3236 /* 7. tmp1.x = tmp0.x - tmp0.w */
3237 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3238 alu
.op
= ALU_OP2_SUB_INT
;
3244 alu
.src
[0].sel
= tmp0
;
3245 alu
.src
[0].chan
= 0;
3246 alu
.src
[1].sel
= tmp0
;
3247 alu
.src
[1].chan
= 3;
3250 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3253 /* 8. tmp1.y = tmp0.x + tmp0.w */
3254 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3255 alu
.op
= ALU_OP2_ADD_INT
;
3261 alu
.src
[0].sel
= tmp0
;
3262 alu
.src
[0].chan
= 0;
3263 alu
.src
[1].sel
= tmp0
;
3264 alu
.src
[1].chan
= 3;
3267 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3270 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3272 alu
.op
= ALU_OP3_CNDE_INT
;
3279 alu
.src
[0].sel
= tmp0
;
3280 alu
.src
[0].chan
= 1;
3281 alu
.src
[1].sel
= tmp1
;
3282 alu
.src
[1].chan
= 1;
3283 alu
.src
[2].sel
= tmp1
;
3284 alu
.src
[2].chan
= 0;
3287 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3290 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3291 if (ctx
->bc
->chip_class
== CAYMAN
) {
3292 for (j
= 0 ; j
< 4; j
++) {
3293 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3294 alu
.op
= ALU_OP2_MULHI_UINT
;
3298 alu
.dst
.write
= (j
== 2);
3300 alu
.src
[0].sel
= tmp0
;
3301 alu
.src
[0].chan
= 0;
3304 alu
.src
[1].sel
= tmp2
;
3305 alu
.src
[1].chan
= 0;
3307 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3310 alu
.last
= (j
== 3);
3311 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3315 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3316 alu
.op
= ALU_OP2_MULHI_UINT
;
3322 alu
.src
[0].sel
= tmp0
;
3323 alu
.src
[0].chan
= 0;
3326 alu
.src
[1].sel
= tmp2
;
3327 alu
.src
[1].chan
= 0;
3329 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3333 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3337 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3338 if (ctx
->bc
->chip_class
== CAYMAN
) {
3339 for (j
= 0 ; j
< 4; j
++) {
3340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3341 alu
.op
= ALU_OP2_MULLO_UINT
;
3345 alu
.dst
.write
= (j
== 1);
3348 alu
.src
[0].sel
= tmp2
;
3349 alu
.src
[0].chan
= 1;
3351 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3354 alu
.src
[1].sel
= tmp0
;
3355 alu
.src
[1].chan
= 2;
3357 alu
.last
= (j
== 3);
3358 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3363 alu
.op
= ALU_OP2_MULLO_UINT
;
3370 alu
.src
[0].sel
= tmp2
;
3371 alu
.src
[0].chan
= 1;
3373 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3376 alu
.src
[1].sel
= tmp0
;
3377 alu
.src
[1].chan
= 2;
3380 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3384 /* 12. tmp0.w = src1 - tmp0.y = r */
3385 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3386 alu
.op
= ALU_OP2_SUB_INT
;
3393 alu
.src
[0].sel
= tmp2
;
3394 alu
.src
[0].chan
= 0;
3396 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3399 alu
.src
[1].sel
= tmp0
;
3400 alu
.src
[1].chan
= 1;
3403 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3406 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3407 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3408 alu
.op
= ALU_OP2_SETGE_UINT
;
3414 alu
.src
[0].sel
= tmp0
;
3415 alu
.src
[0].chan
= 3;
3417 alu
.src
[1].sel
= tmp2
;
3418 alu
.src
[1].chan
= 1;
3420 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3424 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3427 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3428 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3429 alu
.op
= ALU_OP2_SETGE_UINT
;
3436 alu
.src
[0].sel
= tmp2
;
3437 alu
.src
[0].chan
= 0;
3439 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3442 alu
.src
[1].sel
= tmp0
;
3443 alu
.src
[1].chan
= 1;
3446 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3449 if (mod
) { /* UMOD */
3451 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3452 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3453 alu
.op
= ALU_OP2_SUB_INT
;
3459 alu
.src
[0].sel
= tmp0
;
3460 alu
.src
[0].chan
= 3;
3463 alu
.src
[1].sel
= tmp2
;
3464 alu
.src
[1].chan
= 1;
3466 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3470 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3473 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3475 alu
.op
= ALU_OP2_ADD_INT
;
3481 alu
.src
[0].sel
= tmp0
;
3482 alu
.src
[0].chan
= 3;
3484 alu
.src
[1].sel
= tmp2
;
3485 alu
.src
[1].chan
= 1;
3487 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3491 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3496 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3497 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3498 alu
.op
= ALU_OP2_ADD_INT
;
3504 alu
.src
[0].sel
= tmp0
;
3505 alu
.src
[0].chan
= 2;
3506 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3509 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3512 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3513 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3514 alu
.op
= ALU_OP2_ADD_INT
;
3520 alu
.src
[0].sel
= tmp0
;
3521 alu
.src
[0].chan
= 2;
3522 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3525 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3530 /* 17. tmp1.x = tmp1.x & tmp1.y */
3531 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3532 alu
.op
= ALU_OP2_AND_INT
;
3538 alu
.src
[0].sel
= tmp1
;
3539 alu
.src
[0].chan
= 0;
3540 alu
.src
[1].sel
= tmp1
;
3541 alu
.src
[1].chan
= 1;
3544 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3547 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3548 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3550 alu
.op
= ALU_OP3_CNDE_INT
;
3557 alu
.src
[0].sel
= tmp1
;
3558 alu
.src
[0].chan
= 0;
3559 alu
.src
[1].sel
= tmp0
;
3560 alu
.src
[1].chan
= mod
? 3 : 2;
3561 alu
.src
[2].sel
= tmp1
;
3562 alu
.src
[2].chan
= 2;
3565 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3568 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3570 alu
.op
= ALU_OP3_CNDE_INT
;
3578 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3581 alu
.src
[0].sel
= tmp1
;
3582 alu
.src
[0].chan
= 1;
3583 alu
.src
[1].sel
= tmp1
;
3584 alu
.src
[1].chan
= 3;
3585 alu
.src
[2].sel
= tmp0
;
3586 alu
.src
[2].chan
= 2;
3589 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3594 /* fix the sign of the result */
3598 /* tmp0.x = -tmp0.z */
3599 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3600 alu
.op
= ALU_OP2_SUB_INT
;
3606 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3607 alu
.src
[1].sel
= tmp0
;
3608 alu
.src
[1].chan
= 2;
3611 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3614 /* sign of the remainder is the same as the sign of src0 */
3615 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3617 alu
.op
= ALU_OP3_CNDGE_INT
;
3620 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3622 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3623 alu
.src
[1].sel
= tmp0
;
3624 alu
.src
[1].chan
= 2;
3625 alu
.src
[2].sel
= tmp0
;
3626 alu
.src
[2].chan
= 0;
3629 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3634 /* tmp0.x = -tmp0.z */
3635 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3636 alu
.op
= ALU_OP2_SUB_INT
;
3642 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3643 alu
.src
[1].sel
= tmp0
;
3644 alu
.src
[1].chan
= 2;
3647 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3650 /* fix the quotient sign (same as the sign of src0*src1) */
3651 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3652 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3653 alu
.op
= ALU_OP3_CNDGE_INT
;
3656 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3658 alu
.src
[0].sel
= tmp2
;
3659 alu
.src
[0].chan
= 2;
3660 alu
.src
[1].sel
= tmp0
;
3661 alu
.src
[1].chan
= 2;
3662 alu
.src
[2].sel
= tmp0
;
3663 alu
.src
[2].chan
= 0;
3666 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3674 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3676 return tgsi_divmod(ctx
, 0, 0);
3679 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3681 return tgsi_divmod(ctx
, 1, 0);
3684 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3686 return tgsi_divmod(ctx
, 0, 1);
3689 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3691 return tgsi_divmod(ctx
, 1, 1);
3695 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3697 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3698 struct r600_bytecode_alu alu
;
3700 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3701 int last_inst
= tgsi_last_instruction(write_mask
);
3703 for (i
= 0; i
< 4; i
++) {
3704 if (!(write_mask
& (1<<i
)))
3707 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3708 alu
.op
= ALU_OP1_TRUNC
;
3710 alu
.dst
.sel
= ctx
->temp_reg
;
3714 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3722 for (i
= 0; i
< 4; i
++) {
3723 if (!(write_mask
& (1<<i
)))
3726 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3727 alu
.op
= ctx
->inst_info
->op
;
3729 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3731 alu
.src
[0].sel
= ctx
->temp_reg
;
3732 alu
.src
[0].chan
= i
;
3734 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3736 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3744 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3746 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3747 struct r600_bytecode_alu alu
;
3749 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3750 int last_inst
= tgsi_last_instruction(write_mask
);
3753 for (i
= 0; i
< 4; i
++) {
3754 if (!(write_mask
& (1<<i
)))
3757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3758 alu
.op
= ALU_OP2_SUB_INT
;
3760 alu
.dst
.sel
= ctx
->temp_reg
;
3764 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3765 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3769 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3774 /* dst = (src >= 0 ? src : tmp) */
3775 for (i
= 0; i
< 4; i
++) {
3776 if (!(write_mask
& (1<<i
)))
3779 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3780 alu
.op
= ALU_OP3_CNDGE_INT
;
3784 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3786 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3787 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3788 alu
.src
[2].sel
= ctx
->temp_reg
;
3789 alu
.src
[2].chan
= i
;
3793 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3800 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3802 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3803 struct r600_bytecode_alu alu
;
3805 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3806 int last_inst
= tgsi_last_instruction(write_mask
);
3808 /* tmp = (src >= 0 ? src : -1) */
3809 for (i
= 0; i
< 4; i
++) {
3810 if (!(write_mask
& (1<<i
)))
3813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3814 alu
.op
= ALU_OP3_CNDGE_INT
;
3817 alu
.dst
.sel
= ctx
->temp_reg
;
3821 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3822 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3823 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3827 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3832 /* dst = (tmp > 0 ? 1 : tmp) */
3833 for (i
= 0; i
< 4; i
++) {
3834 if (!(write_mask
& (1<<i
)))
3837 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3838 alu
.op
= ALU_OP3_CNDGT_INT
;
3842 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3844 alu
.src
[0].sel
= ctx
->temp_reg
;
3845 alu
.src
[0].chan
= i
;
3847 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3849 alu
.src
[2].sel
= ctx
->temp_reg
;
3850 alu
.src
[2].chan
= i
;
3854 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3863 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
3865 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3866 struct r600_bytecode_alu alu
;
3869 /* tmp = (src > 0 ? 1 : src) */
3870 for (i
= 0; i
< 4; i
++) {
3871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3872 alu
.op
= ALU_OP3_CNDGT
;
3875 alu
.dst
.sel
= ctx
->temp_reg
;
3878 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3879 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3880 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
3884 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3889 /* dst = (-tmp > 0 ? -1 : tmp) */
3890 for (i
= 0; i
< 4; i
++) {
3891 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3892 alu
.op
= ALU_OP3_CNDGT
;
3894 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3896 alu
.src
[0].sel
= ctx
->temp_reg
;
3897 alu
.src
[0].chan
= i
;
3900 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3903 alu
.src
[2].sel
= ctx
->temp_reg
;
3904 alu
.src
[2].chan
= i
;
3908 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3915 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
3917 struct r600_bytecode_alu alu
;
3920 for (i
= 0; i
< 4; i
++) {
3921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3922 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
3923 alu
.op
= ALU_OP0_NOP
;
3926 alu
.op
= ALU_OP1_MOV
;
3927 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3928 alu
.src
[0].sel
= ctx
->temp_reg
;
3929 alu
.src
[0].chan
= i
;
3934 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3941 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
3943 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3944 struct r600_bytecode_alu alu
;
3946 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3948 for (i
= 0; i
< lasti
+ 1; i
++) {
3949 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3953 alu
.op
= ctx
->inst_info
->op
;
3954 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3955 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3958 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3965 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3972 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
3974 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3975 struct r600_bytecode_alu alu
;
3978 for (i
= 0; i
< 4; i
++) {
3979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3980 alu
.op
= ctx
->inst_info
->op
;
3981 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3982 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
3985 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3987 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3988 /* handle some special cases */
3989 switch (ctx
->inst_info
->tgsi_opcode
) {
3990 case TGSI_OPCODE_DP2
:
3992 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3993 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
3996 case TGSI_OPCODE_DP3
:
3998 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
3999 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4002 case TGSI_OPCODE_DPH
:
4004 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4005 alu
.src
[0].chan
= 0;
4015 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4022 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
4025 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4026 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
4027 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
4028 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
4029 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
4032 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
4035 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4036 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
4039 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
4041 struct r600_bytecode_vtx vtx
;
4042 struct r600_bytecode_alu alu
;
4043 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4045 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4047 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4048 if (src_requires_loading
) {
4049 for (i
= 0; i
< 4; i
++) {
4050 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4051 alu
.op
= ALU_OP1_MOV
;
4052 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4053 alu
.dst
.sel
= ctx
->temp_reg
;
4058 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4062 src_gpr
= ctx
->temp_reg
;
4065 memset(&vtx
, 0, sizeof(vtx
));
4066 vtx
.op
= FETCH_OP_VFETCH
;
4067 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
4068 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
4069 vtx
.src_gpr
= src_gpr
;
4070 vtx
.mega_fetch_count
= 16;
4071 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4072 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
4073 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
4074 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4075 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4076 vtx
.use_const_fields
= 1;
4077 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4079 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4082 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4085 for (i
= 0; i
< 4; i
++) {
4086 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4087 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4090 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4091 alu
.op
= ALU_OP2_AND_INT
;
4094 alu
.dst
.sel
= vtx
.dst_gpr
;
4097 alu
.src
[0].sel
= vtx
.dst_gpr
;
4098 alu
.src
[0].chan
= i
;
4100 alu
.src
[1].sel
= 512 + (id
* 2);
4101 alu
.src
[1].chan
= i
% 4;
4102 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4111 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4112 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4113 alu
.op
= ALU_OP2_OR_INT
;
4116 alu
.dst
.sel
= vtx
.dst_gpr
;
4119 alu
.src
[0].sel
= vtx
.dst_gpr
;
4120 alu
.src
[0].chan
= 3;
4122 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4123 alu
.src
[1].chan
= 0;
4124 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4127 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4134 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4136 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4137 struct r600_bytecode_alu alu
;
4139 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4142 alu
.op
= ALU_OP1_MOV
;
4144 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4145 alu
.src
[0].sel
= 512 + (id
/ 4);
4146 alu
.src
[0].chan
= id
% 4;
4148 /* r600 we have them at channel 2 of the second dword */
4149 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4150 alu
.src
[0].chan
= 1;
4152 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4153 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4161 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4163 static float one_point_five
= 1.5f
;
4164 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4165 struct r600_bytecode_tex tex
;
4166 struct r600_bytecode_alu alu
;
4170 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
4171 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4172 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4173 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4175 /* Texture fetch instructions can only use gprs as source.
4176 * Also they cannot negate the source or take the absolute value */
4177 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4178 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4179 read_compressed_msaa
;
4180 boolean src_loaded
= FALSE
;
4181 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4182 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4183 boolean has_txq_cube_array_z
= false;
4185 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4186 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4187 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4188 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4189 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4190 has_txq_cube_array_z
= true;
4193 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4194 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4195 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4196 sampler_src_reg
= 2;
4198 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4200 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4201 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4202 ctx
->shader
->uses_tex_buffers
= true;
4203 return r600_do_buffer_txq(ctx
);
4205 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4206 if (ctx
->bc
->chip_class
< EVERGREEN
)
4207 ctx
->shader
->uses_tex_buffers
= true;
4208 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4212 /* get offset values */
4213 if (inst
->Texture
.NumOffsets
) {
4214 assert(inst
->Texture
.NumOffsets
== 1);
4216 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4217 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4218 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4221 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4222 /* TGSI moves the sampler to src reg 3 for TXD */
4223 sampler_src_reg
= 3;
4225 for (i
= 1; i
< 3; i
++) {
4226 /* set gradients h/v */
4227 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4228 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4229 FETCH_OP_SET_GRADIENTS_V
;
4230 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4231 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4233 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4234 tex
.src_gpr
= r600_get_temp(ctx
);
4240 for (j
= 0; j
< 4; j
++) {
4241 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4242 alu
.op
= ALU_OP1_MOV
;
4243 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4244 alu
.dst
.sel
= tex
.src_gpr
;
4249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4255 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4256 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4257 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4258 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4259 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4260 tex
.src_rel
= ctx
->src
[i
].rel
;
4262 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4263 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4264 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4265 tex
.coord_type_x
= 1;
4266 tex
.coord_type_y
= 1;
4267 tex
.coord_type_z
= 1;
4268 tex
.coord_type_w
= 1;
4270 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4274 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4276 /* Add perspective divide */
4277 if (ctx
->bc
->chip_class
== CAYMAN
) {
4279 for (i
= 0; i
< 3; i
++) {
4280 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4281 alu
.op
= ALU_OP1_RECIP_IEEE
;
4282 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4284 alu
.dst
.sel
= ctx
->temp_reg
;
4290 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4298 alu
.op
= ALU_OP1_RECIP_IEEE
;
4299 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4301 alu
.dst
.sel
= ctx
->temp_reg
;
4302 alu
.dst
.chan
= out_chan
;
4305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4310 for (i
= 0; i
< 3; i
++) {
4311 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4312 alu
.op
= ALU_OP2_MUL
;
4313 alu
.src
[0].sel
= ctx
->temp_reg
;
4314 alu
.src
[0].chan
= out_chan
;
4315 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4316 alu
.dst
.sel
= ctx
->temp_reg
;
4319 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4324 alu
.op
= ALU_OP1_MOV
;
4325 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4326 alu
.src
[0].chan
= 0;
4327 alu
.dst
.sel
= ctx
->temp_reg
;
4331 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4335 src_gpr
= ctx
->temp_reg
;
4338 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4339 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4340 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4341 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4342 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4343 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4345 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4346 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4348 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4349 for (i
= 0; i
< 4; i
++) {
4350 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4351 alu
.op
= ALU_OP2_CUBE
;
4352 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4353 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4354 alu
.dst
.sel
= ctx
->temp_reg
;
4359 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4364 /* tmp1.z = RCP_e(|tmp1.z|) */
4365 if (ctx
->bc
->chip_class
== CAYMAN
) {
4366 for (i
= 0; i
< 3; i
++) {
4367 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4368 alu
.op
= ALU_OP1_RECIP_IEEE
;
4369 alu
.src
[0].sel
= ctx
->temp_reg
;
4370 alu
.src
[0].chan
= 2;
4372 alu
.dst
.sel
= ctx
->temp_reg
;
4378 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4384 alu
.op
= ALU_OP1_RECIP_IEEE
;
4385 alu
.src
[0].sel
= ctx
->temp_reg
;
4386 alu
.src
[0].chan
= 2;
4388 alu
.dst
.sel
= ctx
->temp_reg
;
4392 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4397 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4398 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4399 * muladd has no writemask, have to use another temp
4401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4402 alu
.op
= ALU_OP3_MULADD
;
4405 alu
.src
[0].sel
= ctx
->temp_reg
;
4406 alu
.src
[0].chan
= 0;
4407 alu
.src
[1].sel
= ctx
->temp_reg
;
4408 alu
.src
[1].chan
= 2;
4410 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4411 alu
.src
[2].chan
= 0;
4412 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4414 alu
.dst
.sel
= ctx
->temp_reg
;
4418 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4422 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4423 alu
.op
= ALU_OP3_MULADD
;
4426 alu
.src
[0].sel
= ctx
->temp_reg
;
4427 alu
.src
[0].chan
= 1;
4428 alu
.src
[1].sel
= ctx
->temp_reg
;
4429 alu
.src
[1].chan
= 2;
4431 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4432 alu
.src
[2].chan
= 0;
4433 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4435 alu
.dst
.sel
= ctx
->temp_reg
;
4440 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4443 /* write initial compare value into Z component
4444 - W src 0 for shadow cube
4445 - X src 1 for shadow cube array */
4446 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4447 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4448 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4449 alu
.op
= ALU_OP1_MOV
;
4450 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4451 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4453 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4454 alu
.dst
.sel
= ctx
->temp_reg
;
4458 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4463 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4464 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4465 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4466 int mytmp
= r600_get_temp(ctx
);
4467 static const float eight
= 8.0f
;
4468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4469 alu
.op
= ALU_OP1_MOV
;
4470 alu
.src
[0].sel
= ctx
->temp_reg
;
4471 alu
.src
[0].chan
= 3;
4472 alu
.dst
.sel
= mytmp
;
4476 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4480 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4482 alu
.op
= ALU_OP3_MULADD
;
4484 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4485 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4486 alu
.src
[1].chan
= 0;
4487 alu
.src
[1].value
= *(uint32_t *)&eight
;
4488 alu
.src
[2].sel
= mytmp
;
4489 alu
.src
[2].chan
= 0;
4490 alu
.dst
.sel
= ctx
->temp_reg
;
4494 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4497 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4498 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4499 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4500 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4501 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4502 tex
.src_gpr
= r600_get_temp(ctx
);
4507 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4508 tex
.coord_type_x
= 1;
4509 tex
.coord_type_y
= 1;
4510 tex
.coord_type_z
= 1;
4511 tex
.coord_type_w
= 1;
4512 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4513 alu
.op
= ALU_OP1_MOV
;
4514 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4515 alu
.dst
.sel
= tex
.src_gpr
;
4519 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4523 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4530 /* for cube forms of lod and bias we need to route things */
4531 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4532 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4533 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4534 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4535 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4536 alu
.op
= ALU_OP1_MOV
;
4537 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4538 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4539 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4541 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4542 alu
.dst
.sel
= ctx
->temp_reg
;
4546 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4552 src_gpr
= ctx
->temp_reg
;
4555 if (src_requires_loading
&& !src_loaded
) {
4556 for (i
= 0; i
< 4; i
++) {
4557 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4558 alu
.op
= ALU_OP1_MOV
;
4559 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4560 alu
.dst
.sel
= ctx
->temp_reg
;
4565 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4570 src_gpr
= ctx
->temp_reg
;
4573 /* Obtain the sample index for reading a compressed MSAA color texture.
4574 * To read the FMASK, we use the ldfptr instruction, which tells us
4575 * where the samples are stored.
4576 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4577 * which is the identity mapping. Each nibble says which physical sample
4578 * should be fetched to get that sample.
4580 * Assume src.z contains the sample index. It should be modified like this:
4581 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4582 * Then fetch the texel with src.
4584 if (read_compressed_msaa
) {
4585 unsigned sample_chan
= 3;
4586 unsigned temp
= r600_get_temp(ctx
);
4589 /* temp.w = ldfptr() */
4590 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4591 tex
.op
= FETCH_OP_LD
;
4592 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4593 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4594 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4595 tex
.src_gpr
= src_gpr
;
4597 tex
.dst_sel_x
= 7; /* mask out these components */
4600 tex
.dst_sel_w
= 0; /* store X */
4605 tex
.offset_x
= offset_x
;
4606 tex
.offset_y
= offset_y
;
4607 tex
.offset_z
= offset_z
;
4608 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4612 /* temp.x = sample_index*4 */
4613 if (ctx
->bc
->chip_class
== CAYMAN
) {
4614 for (i
= 0 ; i
< 4; i
++) {
4615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4616 alu
.op
= ALU_OP2_MULLO_INT
;
4617 alu
.src
[0].sel
= src_gpr
;
4618 alu
.src
[0].chan
= sample_chan
;
4619 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4620 alu
.src
[1].value
= 4;
4623 alu
.dst
.write
= i
== 0;
4626 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4632 alu
.op
= ALU_OP2_MULLO_INT
;
4633 alu
.src
[0].sel
= src_gpr
;
4634 alu
.src
[0].chan
= sample_chan
;
4635 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4636 alu
.src
[1].value
= 4;
4641 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4646 /* sample_index = temp.w >> temp.x */
4647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4648 alu
.op
= ALU_OP2_LSHR_INT
;
4649 alu
.src
[0].sel
= temp
;
4650 alu
.src
[0].chan
= 3;
4651 alu
.src
[1].sel
= temp
;
4652 alu
.src
[1].chan
= 0;
4653 alu
.dst
.sel
= src_gpr
;
4654 alu
.dst
.chan
= sample_chan
;
4657 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4661 /* sample_index & 0xF */
4662 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4663 alu
.op
= ALU_OP2_AND_INT
;
4664 alu
.src
[0].sel
= src_gpr
;
4665 alu
.src
[0].chan
= sample_chan
;
4666 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4667 alu
.src
[1].value
= 0xF;
4668 alu
.dst
.sel
= src_gpr
;
4669 alu
.dst
.chan
= sample_chan
;
4672 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4676 /* visualize the FMASK */
4677 for (i
= 0; i
< 4; i
++) {
4678 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4679 alu
.op
= ALU_OP1_INT_TO_FLT
;
4680 alu
.src
[0].sel
= src_gpr
;
4681 alu
.src
[0].chan
= sample_chan
;
4682 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4686 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4694 /* does this shader want a num layers from TXQ for a cube array? */
4695 if (has_txq_cube_array_z
) {
4696 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4698 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4699 alu
.op
= ALU_OP1_MOV
;
4701 alu
.src
[0].sel
= 512 + (id
/ 4);
4702 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4703 alu
.src
[0].chan
= id
% 4;
4704 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4706 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4709 /* disable writemask from texture instruction */
4710 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4713 opcode
= ctx
->inst_info
->op
;
4714 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4715 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4716 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4717 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4718 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4719 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4720 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4722 case FETCH_OP_SAMPLE
:
4723 opcode
= FETCH_OP_SAMPLE_C
;
4725 case FETCH_OP_SAMPLE_L
:
4726 opcode
= FETCH_OP_SAMPLE_C_L
;
4728 case FETCH_OP_SAMPLE_LB
:
4729 opcode
= FETCH_OP_SAMPLE_C_LB
;
4731 case FETCH_OP_SAMPLE_G
:
4732 opcode
= FETCH_OP_SAMPLE_C_G
;
4737 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4740 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4741 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4742 tex
.src_gpr
= src_gpr
;
4743 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4744 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4745 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4746 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4747 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4749 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4754 } else if (src_loaded
) {
4760 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4761 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4762 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4763 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4764 tex
.src_rel
= ctx
->src
[0].rel
;
4767 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4768 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4769 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4770 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4774 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4777 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4778 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4779 tex
.coord_type_x
= 1;
4780 tex
.coord_type_y
= 1;
4782 tex
.coord_type_z
= 1;
4783 tex
.coord_type_w
= 1;
4785 tex
.offset_x
= offset_x
;
4786 tex
.offset_y
= offset_y
;
4787 tex
.offset_z
= offset_z
;
4789 /* Put the depth for comparison in W.
4790 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4791 * Some instructions expect the depth in Z. */
4792 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4793 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4794 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4795 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4796 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4797 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4798 tex
.src_sel_w
= tex
.src_sel_z
;
4801 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4802 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4803 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4804 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4805 /* the array index is read from Y */
4806 tex
.coord_type_y
= 0;
4808 /* the array index is read from Z */
4809 tex
.coord_type_z
= 0;
4810 tex
.src_sel_z
= tex
.src_sel_y
;
4812 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4813 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4814 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4815 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4816 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4817 /* the array index is read from Z */
4818 tex
.coord_type_z
= 0;
4820 /* mask unused source components */
4821 if (opcode
== FETCH_OP_SAMPLE
) {
4822 switch (inst
->Texture
.Texture
) {
4823 case TGSI_TEXTURE_2D
:
4824 case TGSI_TEXTURE_RECT
:
4828 case TGSI_TEXTURE_1D_ARRAY
:
4832 case TGSI_TEXTURE_1D
:
4840 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4844 /* add shadow ambient support - gallium doesn't do it yet */
4848 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
4850 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4851 struct r600_bytecode_alu alu
;
4852 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4856 /* optimize if it's just an equal balance */
4857 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
4858 for (i
= 0; i
< lasti
+ 1; i
++) {
4859 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4863 alu
.op
= ALU_OP2_ADD
;
4864 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4865 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4867 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4872 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4880 for (i
= 0; i
< lasti
+ 1; i
++) {
4881 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4884 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4885 alu
.op
= ALU_OP2_ADD
;
4886 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4887 alu
.src
[0].chan
= 0;
4888 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4889 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4890 alu
.dst
.sel
= ctx
->temp_reg
;
4896 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4901 /* (1 - src0) * src2 */
4902 for (i
= 0; i
< lasti
+ 1; i
++) {
4903 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4906 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4907 alu
.op
= ALU_OP2_MUL
;
4908 alu
.src
[0].sel
= ctx
->temp_reg
;
4909 alu
.src
[0].chan
= i
;
4910 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4911 alu
.dst
.sel
= ctx
->temp_reg
;
4917 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4922 /* src0 * src1 + (1 - src0) * src2 */
4923 for (i
= 0; i
< lasti
+ 1; i
++) {
4924 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4927 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4928 alu
.op
= ALU_OP3_MULADD
;
4930 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4931 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4932 alu
.src
[2].sel
= ctx
->temp_reg
;
4933 alu
.src
[2].chan
= i
;
4935 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4947 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
4949 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4950 struct r600_bytecode_alu alu
;
4952 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4954 for (i
= 0; i
< lasti
+ 1; i
++) {
4955 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4958 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4959 alu
.op
= ALU_OP3_CNDGE
;
4960 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4961 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4962 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4963 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4969 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4976 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
4978 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4979 struct r600_bytecode_alu alu
;
4981 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4983 for (i
= 0; i
< lasti
+ 1; i
++) {
4984 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4987 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4988 alu
.op
= ALU_OP3_CNDGE_INT
;
4989 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4990 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
4991 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
4992 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4998 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5005 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
5007 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5008 static const unsigned int src0_swizzle
[] = {2, 0, 1};
5009 static const unsigned int src1_swizzle
[] = {1, 2, 0};
5010 struct r600_bytecode_alu alu
;
5011 uint32_t use_temp
= 0;
5014 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
5017 for (i
= 0; i
< 4; i
++) {
5018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5019 alu
.op
= ALU_OP2_MUL
;
5021 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5022 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
5024 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5025 alu
.src
[0].chan
= i
;
5026 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5027 alu
.src
[1].chan
= i
;
5030 alu
.dst
.sel
= ctx
->temp_reg
;
5036 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5041 for (i
= 0; i
< 4; i
++) {
5042 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5043 alu
.op
= ALU_OP3_MULADD
;
5046 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
5047 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
5049 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5050 alu
.src
[0].chan
= i
;
5051 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5052 alu
.src
[1].chan
= i
;
5055 alu
.src
[2].sel
= ctx
->temp_reg
;
5057 alu
.src
[2].chan
= i
;
5060 alu
.dst
.sel
= ctx
->temp_reg
;
5062 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5068 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5073 return tgsi_helper_copy(ctx
, inst
);
5077 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
5079 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5080 struct r600_bytecode_alu alu
;
5084 /* result.x = 2^floor(src); */
5085 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5086 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5088 alu
.op
= ALU_OP1_FLOOR
;
5089 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5091 alu
.dst
.sel
= ctx
->temp_reg
;
5095 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5099 if (ctx
->bc
->chip_class
== CAYMAN
) {
5100 for (i
= 0; i
< 3; i
++) {
5101 alu
.op
= ALU_OP1_EXP_IEEE
;
5102 alu
.src
[0].sel
= ctx
->temp_reg
;
5103 alu
.src
[0].chan
= 0;
5105 alu
.dst
.sel
= ctx
->temp_reg
;
5107 alu
.dst
.write
= i
== 0;
5109 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5114 alu
.op
= ALU_OP1_EXP_IEEE
;
5115 alu
.src
[0].sel
= ctx
->temp_reg
;
5116 alu
.src
[0].chan
= 0;
5118 alu
.dst
.sel
= ctx
->temp_reg
;
5122 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5128 /* result.y = tmp - floor(tmp); */
5129 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5130 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5132 alu
.op
= ALU_OP1_FRACT
;
5133 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5135 alu
.dst
.sel
= ctx
->temp_reg
;
5137 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5146 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5151 /* result.z = RoughApprox2ToX(tmp);*/
5152 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5153 if (ctx
->bc
->chip_class
== CAYMAN
) {
5154 for (i
= 0; i
< 3; i
++) {
5155 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5156 alu
.op
= ALU_OP1_EXP_IEEE
;
5157 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5159 alu
.dst
.sel
= ctx
->temp_reg
;
5166 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5172 alu
.op
= ALU_OP1_EXP_IEEE
;
5173 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5175 alu
.dst
.sel
= ctx
->temp_reg
;
5181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5187 /* result.w = 1.0;*/
5188 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5189 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5191 alu
.op
= ALU_OP1_MOV
;
5192 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5193 alu
.src
[0].chan
= 0;
5195 alu
.dst
.sel
= ctx
->temp_reg
;
5199 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5203 return tgsi_helper_copy(ctx
, inst
);
5206 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5208 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5209 struct r600_bytecode_alu alu
;
5213 /* result.x = floor(log2(|src|)); */
5214 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5215 if (ctx
->bc
->chip_class
== CAYMAN
) {
5216 for (i
= 0; i
< 3; i
++) {
5217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5219 alu
.op
= ALU_OP1_LOG_IEEE
;
5220 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5221 r600_bytecode_src_set_abs(&alu
.src
[0]);
5223 alu
.dst
.sel
= ctx
->temp_reg
;
5229 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5237 alu
.op
= ALU_OP1_LOG_IEEE
;
5238 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5239 r600_bytecode_src_set_abs(&alu
.src
[0]);
5241 alu
.dst
.sel
= ctx
->temp_reg
;
5245 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5250 alu
.op
= ALU_OP1_FLOOR
;
5251 alu
.src
[0].sel
= ctx
->temp_reg
;
5252 alu
.src
[0].chan
= 0;
5254 alu
.dst
.sel
= ctx
->temp_reg
;
5259 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5264 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5265 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5267 if (ctx
->bc
->chip_class
== CAYMAN
) {
5268 for (i
= 0; i
< 3; i
++) {
5269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5271 alu
.op
= ALU_OP1_LOG_IEEE
;
5272 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5273 r600_bytecode_src_set_abs(&alu
.src
[0]);
5275 alu
.dst
.sel
= ctx
->temp_reg
;
5282 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5287 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5289 alu
.op
= ALU_OP1_LOG_IEEE
;
5290 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5291 r600_bytecode_src_set_abs(&alu
.src
[0]);
5293 alu
.dst
.sel
= ctx
->temp_reg
;
5298 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5305 alu
.op
= ALU_OP1_FLOOR
;
5306 alu
.src
[0].sel
= ctx
->temp_reg
;
5307 alu
.src
[0].chan
= 1;
5309 alu
.dst
.sel
= ctx
->temp_reg
;
5314 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5318 if (ctx
->bc
->chip_class
== CAYMAN
) {
5319 for (i
= 0; i
< 3; i
++) {
5320 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5321 alu
.op
= ALU_OP1_EXP_IEEE
;
5322 alu
.src
[0].sel
= ctx
->temp_reg
;
5323 alu
.src
[0].chan
= 1;
5325 alu
.dst
.sel
= ctx
->temp_reg
;
5332 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5337 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5338 alu
.op
= ALU_OP1_EXP_IEEE
;
5339 alu
.src
[0].sel
= ctx
->temp_reg
;
5340 alu
.src
[0].chan
= 1;
5342 alu
.dst
.sel
= ctx
->temp_reg
;
5347 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5352 if (ctx
->bc
->chip_class
== CAYMAN
) {
5353 for (i
= 0; i
< 3; i
++) {
5354 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5355 alu
.op
= ALU_OP1_RECIP_IEEE
;
5356 alu
.src
[0].sel
= ctx
->temp_reg
;
5357 alu
.src
[0].chan
= 1;
5359 alu
.dst
.sel
= ctx
->temp_reg
;
5366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5371 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5372 alu
.op
= ALU_OP1_RECIP_IEEE
;
5373 alu
.src
[0].sel
= ctx
->temp_reg
;
5374 alu
.src
[0].chan
= 1;
5376 alu
.dst
.sel
= ctx
->temp_reg
;
5381 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5386 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5388 alu
.op
= ALU_OP2_MUL
;
5390 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5391 r600_bytecode_src_set_abs(&alu
.src
[0]);
5393 alu
.src
[1].sel
= ctx
->temp_reg
;
5394 alu
.src
[1].chan
= 1;
5396 alu
.dst
.sel
= ctx
->temp_reg
;
5401 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5406 /* result.z = log2(|src|);*/
5407 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5408 if (ctx
->bc
->chip_class
== CAYMAN
) {
5409 for (i
= 0; i
< 3; i
++) {
5410 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5412 alu
.op
= ALU_OP1_LOG_IEEE
;
5413 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5414 r600_bytecode_src_set_abs(&alu
.src
[0]);
5416 alu
.dst
.sel
= ctx
->temp_reg
;
5423 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5428 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5430 alu
.op
= ALU_OP1_LOG_IEEE
;
5431 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5432 r600_bytecode_src_set_abs(&alu
.src
[0]);
5434 alu
.dst
.sel
= ctx
->temp_reg
;
5439 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5445 /* result.w = 1.0; */
5446 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5447 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5449 alu
.op
= ALU_OP1_MOV
;
5450 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5451 alu
.src
[0].chan
= 0;
5453 alu
.dst
.sel
= ctx
->temp_reg
;
5458 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5463 return tgsi_helper_copy(ctx
, inst
);
5466 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5468 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5469 struct r600_bytecode_alu alu
;
5472 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5474 switch (inst
->Instruction
.Opcode
) {
5475 case TGSI_OPCODE_ARL
:
5476 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5478 case TGSI_OPCODE_ARR
:
5479 alu
.op
= ALU_OP1_FLT_TO_INT
;
5481 case TGSI_OPCODE_UARL
:
5482 alu
.op
= ALU_OP1_MOV
;
5489 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5491 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5493 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5497 ctx
->bc
->ar_loaded
= 0;
5500 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5502 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5503 struct r600_bytecode_alu alu
;
5506 switch (inst
->Instruction
.Opcode
) {
5507 case TGSI_OPCODE_ARL
:
5508 memset(&alu
, 0, sizeof(alu
));
5509 alu
.op
= ALU_OP1_FLOOR
;
5510 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5511 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5515 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5518 memset(&alu
, 0, sizeof(alu
));
5519 alu
.op
= ALU_OP1_FLT_TO_INT
;
5520 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5521 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5525 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5528 case TGSI_OPCODE_ARR
:
5529 memset(&alu
, 0, sizeof(alu
));
5530 alu
.op
= ALU_OP1_FLT_TO_INT
;
5531 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5532 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5536 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5539 case TGSI_OPCODE_UARL
:
5540 memset(&alu
, 0, sizeof(alu
));
5541 alu
.op
= ALU_OP1_MOV
;
5542 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5543 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5547 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5555 ctx
->bc
->ar_loaded
= 0;
5559 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5561 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5562 struct r600_bytecode_alu alu
;
5565 for (i
= 0; i
< 4; i
++) {
5566 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5568 alu
.op
= ALU_OP2_MUL
;
5569 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5571 if (i
== 0 || i
== 3) {
5572 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5574 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5577 if (i
== 0 || i
== 2) {
5578 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5580 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5584 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5591 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5593 struct r600_bytecode_alu alu
;
5596 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5598 alu
.execute_mask
= 1;
5599 alu
.update_pred
= 1;
5601 alu
.dst
.sel
= ctx
->temp_reg
;
5605 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5606 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5607 alu
.src
[1].chan
= 0;
5611 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5617 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5619 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5623 if (ctx
->bc
->cf_last
) {
5624 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5626 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5631 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5632 ctx
->bc
->force_add_cf
= 1;
5633 } else if (alu_pop
== 2) {
5634 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5635 ctx
->bc
->force_add_cf
= 1;
5642 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5643 ctx
->bc
->cf_last
->pop_count
= pops
;
5644 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5650 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5653 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5654 unsigned elements
, entries
;
5656 unsigned entry_size
= stack
->entry_size
;
5658 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5659 elements
+= stack
->push
;
5661 switch (ctx
->bc
->chip_class
) {
5664 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5665 * the stack must be reserved to hold the current active/continue
5667 if (reason
== FC_PUSH_VPM
) {
5673 /* r9xx: any stack operation on empty stack consumes 2 additional
5678 /* FIXME: do the two elements added above cover the cases for the
5682 /* r8xx+: 2 extra elements are not always required, but one extra
5683 * element must be added for each of the following cases:
5684 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5686 * (Currently we don't use ALU_ELSE_AFTER.)
5687 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5688 * PUSH instruction executed.
5690 * NOTE: it seems we also need to reserve additional element in some
5691 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5692 * then STACK_SIZE should be 2 instead of 1 */
5693 if (reason
== FC_PUSH_VPM
) {
5703 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5704 * for all chips, so we use 4 in the final formula, not the real entry_size
5708 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5710 if (entries
> stack
->max_entries
)
5711 stack
->max_entries
= entries
;
5714 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5718 --ctx
->bc
->stack
.push
;
5719 assert(ctx
->bc
->stack
.push
>= 0);
5722 --ctx
->bc
->stack
.push_wqm
;
5723 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5726 --ctx
->bc
->stack
.loop
;
5727 assert(ctx
->bc
->stack
.loop
>= 0);
5735 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5739 ++ctx
->bc
->stack
.push
;
5742 ++ctx
->bc
->stack
.push_wqm
;
5744 ++ctx
->bc
->stack
.loop
;
5750 callstack_update_max_depth(ctx
, reason
);
5753 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5755 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5757 sp
->mid
= realloc((void *)sp
->mid
,
5758 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5759 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5763 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5766 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5767 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5770 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5772 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5782 static int emit_return(struct r600_shader_ctx
*ctx
)
5784 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5788 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5791 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5792 ctx
->bc
->cf_last
->pop_count
= pops
;
5793 /* XXX work out offset */
5797 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5802 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5807 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5810 emit_jump_to_offset(ctx
, 1, 4);
5811 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5812 pops(ctx
, ifidx
+ 1);
5816 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5820 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5821 ctx
->bc
->cf_last
->pop_count
= 1;
5823 fc_set_mid(ctx
, fc_sp
);
5829 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5831 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5833 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
5834 * LOOP_STARTxxx for nested loops may put the branch stack into a state
5835 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
5836 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
5837 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
5838 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
5839 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5840 alu_type
= CF_OP_ALU
;
5843 emit_logic_pred(ctx
, opcode
, alu_type
);
5845 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
5847 fc_pushlevel(ctx
, FC_IF
);
5849 callstack_push(ctx
, FC_PUSH_VPM
);
5853 static int tgsi_if(struct r600_shader_ctx
*ctx
)
5855 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
5858 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
5860 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
5863 static int tgsi_else(struct r600_shader_ctx
*ctx
)
5865 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
5866 ctx
->bc
->cf_last
->pop_count
= 1;
5868 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
5869 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
5873 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
5876 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
5877 R600_ERR("if/endif unbalanced in shader\n");
5881 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
5882 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5883 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
5885 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5889 callstack_pop(ctx
, FC_PUSH_VPM
);
5893 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
5895 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
5896 * limited to 4096 iterations, like the other LOOP_* instructions. */
5897 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
5899 fc_pushlevel(ctx
, FC_LOOP
);
5901 /* check stack depth */
5902 callstack_push(ctx
, FC_LOOP
);
5906 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
5910 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
5912 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
5913 R600_ERR("loop/endloop in shader code are not paired.\n");
5917 /* fixup loop pointers - from r600isa
5918 LOOP END points to CF after LOOP START,
5919 LOOP START point to CF after LOOP END
5920 BRK/CONT point to LOOP END CF
5922 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
5924 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5926 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
5927 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
5929 /* XXX add LOOPRET support */
5931 callstack_pop(ctx
, FC_LOOP
);
5935 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
5939 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
5941 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
5946 R600_ERR("Break not inside loop/endloop pair\n");
5950 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5952 fc_set_mid(ctx
, fscp
);
5957 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
5959 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
5960 emit_gs_ring_writes(ctx
);
5962 return r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5965 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
5967 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5968 struct r600_bytecode_alu alu
;
5970 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5973 for (i
= 0; i
< lasti
+ 1; i
++) {
5974 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5977 if (ctx
->bc
->chip_class
== CAYMAN
) {
5978 for (j
= 0 ; j
< 4; j
++) {
5979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5981 alu
.op
= ALU_OP2_MULLO_UINT
;
5982 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
5983 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
5985 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
5986 alu
.dst
.sel
= ctx
->temp_reg
;
5987 alu
.dst
.write
= (j
== i
);
5990 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5998 alu
.dst
.sel
= ctx
->temp_reg
;
6001 alu
.op
= ALU_OP2_MULLO_UINT
;
6002 for (j
= 0; j
< 2; j
++) {
6003 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6007 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6014 for (i
= 0; i
< lasti
+ 1; i
++) {
6015 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6019 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6021 alu
.op
= ALU_OP2_ADD_INT
;
6023 alu
.src
[0].sel
= ctx
->temp_reg
;
6024 alu
.src
[0].chan
= i
;
6026 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6030 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6037 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
6038 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6039 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6040 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6043 * For state trackers other than OpenGL, we'll want to use
6044 * _RECIP_IEEE instead.
6046 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
6048 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
6049 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6050 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6051 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6052 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6053 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6054 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6055 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6056 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6057 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6058 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6059 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6060 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6061 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6062 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6063 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6065 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6066 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6068 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6069 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6070 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6071 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6072 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6073 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6074 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6075 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6076 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6077 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6079 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6080 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6081 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6082 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6083 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6084 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6085 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6086 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6087 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6088 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6089 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6090 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6091 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6092 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6093 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6094 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6095 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6096 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6097 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6098 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6099 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6100 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6101 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6102 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6103 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6104 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6105 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6106 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6107 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6108 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6109 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6110 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6111 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6112 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6113 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6114 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6115 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6116 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6117 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6118 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6119 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6120 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6121 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6122 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6123 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6124 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6125 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6127 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6128 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6129 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6130 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6131 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6132 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6133 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6134 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6135 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6137 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6138 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6139 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6140 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6141 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6142 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6143 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6144 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6145 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6146 {TGSI_OPCODE_EMIT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6147 {TGSI_OPCODE_ENDPRIM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6148 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6149 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6150 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6151 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6152 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6154 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6155 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6156 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6157 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6158 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6159 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6160 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6161 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6162 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6163 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6165 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6166 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6167 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6168 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6170 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6171 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6172 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6173 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6174 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6175 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6176 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6177 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6178 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6179 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6180 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6181 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6182 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6183 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6184 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6185 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6186 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6187 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6188 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6189 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6190 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6191 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6192 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6193 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6194 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6195 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6196 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6197 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6198 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6199 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6200 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6201 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6202 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6203 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6204 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6205 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6206 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6207 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6208 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6209 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6210 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6211 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6212 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6213 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6214 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6215 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6216 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6217 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6218 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6219 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6220 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6221 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6222 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6223 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6224 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6225 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6226 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6227 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6228 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6229 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6230 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6231 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6232 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6235 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6236 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6237 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6238 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6239 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6240 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6241 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6242 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6243 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6244 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6245 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6246 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6247 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6248 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6249 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6250 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6251 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6252 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6253 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6254 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6255 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6257 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6258 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6260 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6261 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6262 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6263 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6264 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6265 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6266 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6267 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6268 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6269 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6271 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6272 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6273 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6274 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6275 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6276 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6277 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6278 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6279 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6280 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6281 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6282 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6283 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6284 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6285 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6286 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6287 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6288 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6289 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6290 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6291 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6292 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6293 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6294 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6295 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6296 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6297 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6298 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6299 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6300 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6301 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6302 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6303 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6304 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6305 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6306 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6307 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6308 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6309 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6310 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6311 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6312 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6313 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6314 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6315 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6316 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6317 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6319 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6320 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6321 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6322 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6323 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6324 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6325 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6326 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6327 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6329 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6330 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6331 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6332 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6333 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6334 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6335 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6336 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6337 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6338 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6339 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6340 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6341 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6342 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6343 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6344 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6346 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6347 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6348 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6349 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6350 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6351 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6352 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6353 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6354 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6355 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6357 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6358 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6359 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6360 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6362 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6363 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6364 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6365 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6366 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6367 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6368 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6369 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6370 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6371 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6372 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6373 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6374 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6375 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6376 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6377 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6378 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6379 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6380 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6381 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6382 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6383 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6384 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6385 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6386 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6387 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6388 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6389 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6390 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6391 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6392 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6393 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6394 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6395 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6396 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6397 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6398 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6399 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6400 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6401 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6402 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6403 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6404 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6405 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6406 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6407 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6408 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6409 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6410 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6411 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6412 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6413 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6414 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6415 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6416 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6417 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6418 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6419 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6420 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6421 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6422 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6423 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6424 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6427 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6428 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6429 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6430 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6431 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6432 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6433 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6434 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6435 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6436 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6437 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6438 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6439 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6440 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6441 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6442 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6443 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6444 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6445 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6446 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6447 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6449 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6450 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6452 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6453 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6454 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6455 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6456 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6457 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6458 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6459 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6460 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6461 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6463 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6464 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6465 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6467 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6468 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6469 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6470 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6471 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6472 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6473 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6474 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6475 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6476 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6477 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6478 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6479 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6480 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6481 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6482 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6483 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6484 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6485 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6486 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6487 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6488 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6489 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6490 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6491 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6492 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6493 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6494 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6495 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6496 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6497 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6498 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6499 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6500 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6501 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6502 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6503 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6504 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6505 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6506 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6507 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6508 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6509 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6511 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6512 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6513 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6514 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6515 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6516 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6517 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6518 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6519 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6521 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6522 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6523 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6524 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6525 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6526 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6527 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6528 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6529 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6530 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6531 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6532 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6533 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6534 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6535 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6536 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6538 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6539 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6540 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6541 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6543 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6544 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6545 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6546 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6547 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6548 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6550 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6551 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6552 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6553 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6555 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6556 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6557 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6558 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6559 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6560 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6561 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6562 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6563 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6564 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6565 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6566 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6567 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6568 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6569 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6570 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6571 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6572 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6573 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6574 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6575 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6576 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6577 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6578 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6579 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6580 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6581 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6582 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6583 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6584 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6585 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6586 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6587 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6588 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6589 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6590 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6591 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6592 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6593 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6594 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6595 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6596 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6597 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6598 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6599 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6600 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6601 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6602 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6603 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6604 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6605 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6606 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6607 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6608 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6609 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6610 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6611 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6612 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6613 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6614 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6615 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6616 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6617 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},