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_cpu_to_le32(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 r600_update_gs_state(ctx
, shader
);
214 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
217 case TGSI_PROCESSOR_VERTEX
:
218 if (rctx
->b
.chip_class
>= EVERGREEN
) {
220 evergreen_update_es_state(ctx
, shader
);
222 evergreen_update_vs_state(ctx
, shader
);
225 r600_update_es_state(ctx
, shader
);
227 r600_update_vs_state(ctx
, shader
);
230 case TGSI_PROCESSOR_FRAGMENT
:
231 if (rctx
->b
.chip_class
>= EVERGREEN
) {
232 evergreen_update_ps_state(ctx
, shader
);
234 r600_update_ps_state(ctx
, shader
);
244 r600_pipe_shader_destroy(ctx
, shader
);
248 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
250 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
251 r600_bytecode_clear(&shader
->shader
.bc
);
252 r600_release_command_buffer(&shader
->command_buffer
);
256 * tgsi -> r600 shader
258 struct r600_shader_tgsi_instruction
;
260 struct r600_shader_src
{
270 struct r600_shader_ctx
{
271 struct tgsi_shader_info info
;
272 struct tgsi_parse_context parse
;
273 const struct tgsi_token
*tokens
;
275 unsigned file_offset
[TGSI_FILE_COUNT
];
277 struct r600_shader_tgsi_instruction
*inst_info
;
278 struct r600_bytecode
*bc
;
279 struct r600_shader
*shader
;
280 struct r600_shader_src src
[4];
283 uint32_t max_driver_temp_used
;
285 /* needed for evergreen interpolation */
286 boolean input_centroid
;
287 boolean input_linear
;
288 boolean input_perspective
;
292 boolean clip_vertex_write
;
294 unsigned edgeflag_output
;
297 int next_ring_offset
;
298 int gs_out_ring_offset
;
300 struct r600_shader
*gs_for_vs
;
301 int gs_export_gpr_treg
;
304 struct r600_shader_tgsi_instruction
{
305 unsigned tgsi_opcode
;
308 int (*process
)(struct r600_shader_ctx
*ctx
);
311 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, bool ind
);
312 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
313 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
314 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
315 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
316 static int tgsi_else(struct r600_shader_ctx
*ctx
);
317 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
318 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
319 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
320 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
322 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
324 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
327 if (i
->Instruction
.NumDstRegs
> 1) {
328 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
331 if (i
->Instruction
.Predicate
) {
332 R600_ERR("predicate unsupported\n");
336 if (i
->Instruction
.Label
) {
337 R600_ERR("label unsupported\n");
341 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
342 if (i
->Src
[j
].Register
.Dimension
) {
343 switch (i
->Src
[j
].Register
.File
) {
344 case TGSI_FILE_CONSTANT
:
346 case TGSI_FILE_INPUT
:
347 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
)
350 R600_ERR("unsupported src %d (dimension %d)\n", j
,
351 i
->Src
[j
].Register
.Dimension
);
356 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
357 if (i
->Dst
[j
].Register
.Dimension
) {
358 R600_ERR("unsupported dst (dimension)\n");
365 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
370 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
371 if (ctx
->shader
->input
[input
].centroid
)
373 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
374 /* if we have perspective add one */
375 if (ctx
->input_perspective
) {
377 /* if we have perspective centroid */
378 if (ctx
->input_centroid
)
381 if (ctx
->shader
->input
[input
].centroid
)
385 ctx
->shader
->input
[input
].ij_index
= ij_index
;
388 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
391 struct r600_bytecode_alu alu
;
392 int gpr
= 0, base_chan
= 0;
393 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
395 /* work out gpr and base_chan from index */
397 base_chan
= (2 * (ij_index
% 2)) + 1;
399 for (i
= 0; i
< 8; i
++) {
400 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
403 alu
.op
= ALU_OP2_INTERP_ZW
;
405 alu
.op
= ALU_OP2_INTERP_XY
;
407 if ((i
> 1) && (i
< 6)) {
408 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
412 alu
.dst
.chan
= i
% 4;
414 alu
.src
[0].sel
= gpr
;
415 alu
.src
[0].chan
= (base_chan
- (i
% 2));
417 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
419 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
422 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
429 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
432 struct r600_bytecode_alu alu
;
434 for (i
= 0; i
< 4; i
++) {
435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
437 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
439 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
444 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
449 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
457 * Special export handling in shaders
459 * shader export ARRAY_BASE for EXPORT_POS:
462 * 62, 63 are clip distance vectors
464 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
465 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
466 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
467 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
468 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
469 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
470 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
471 * exclusive from render target index)
472 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
475 * shader export ARRAY_BASE for EXPORT_PIXEL:
477 * 61 computed Z vector
479 * The use of the values exported in the computed Z vector are controlled
480 * by DB_SHADER_CONTROL:
481 * Z_EXPORT_ENABLE - Z as a float in RED
482 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
483 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
484 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
485 * DB_SOURCE_FORMAT - export control restrictions
490 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
491 static int r600_spi_sid(struct r600_shader_io
* io
)
493 int index
, name
= io
->name
;
495 /* These params are handled differently, they don't need
496 * semantic indices, so we'll use 0 for them.
498 if (name
== TGSI_SEMANTIC_POSITION
||
499 name
== TGSI_SEMANTIC_PSIZE
||
500 name
== TGSI_SEMANTIC_EDGEFLAG
||
501 name
== TGSI_SEMANTIC_LAYER
||
502 name
== TGSI_SEMANTIC_VIEWPORT_INDEX
||
503 name
== TGSI_SEMANTIC_FACE
)
506 if (name
== TGSI_SEMANTIC_GENERIC
) {
507 /* For generic params simply use sid from tgsi */
510 /* For non-generic params - pack name and sid into 8 bits */
511 index
= 0x80 | (name
<<3) | (io
->sid
);
514 /* Make sure that all really used indices have nonzero value, so
515 * we can just compare it to 0 later instead of comparing the name
516 * with different values to detect special cases. */
523 /* turn input into interpolate on EG */
524 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
528 if (ctx
->shader
->input
[index
].spi_sid
) {
529 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
530 if (ctx
->shader
->input
[index
].interpolate
> 0) {
531 evergreen_interp_assign_ij_index(ctx
, index
);
533 r
= evergreen_interp_alu(ctx
, index
);
536 r
= evergreen_interp_flat(ctx
, index
);
542 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
544 struct r600_bytecode_alu alu
;
546 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
547 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
549 for (i
= 0; i
< 4; i
++) {
550 memset(&alu
, 0, sizeof(alu
));
551 alu
.op
= ALU_OP3_CNDGT
;
554 alu
.dst
.sel
= gpr_front
;
555 alu
.src
[0].sel
= ctx
->face_gpr
;
556 alu
.src
[1].sel
= gpr_front
;
557 alu
.src
[2].sel
= gpr_back
;
564 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
571 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
573 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
574 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
576 switch (d
->Declaration
.File
) {
577 case TGSI_FILE_INPUT
:
578 i
= ctx
->shader
->ninput
;
579 assert(i
< Elements(ctx
->shader
->input
));
580 ctx
->shader
->ninput
+= count
;
581 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
582 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
583 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
584 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
585 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
586 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
587 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
588 switch (ctx
->shader
->input
[i
].name
) {
589 case TGSI_SEMANTIC_FACE
:
590 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
592 case TGSI_SEMANTIC_COLOR
:
595 case TGSI_SEMANTIC_POSITION
:
596 ctx
->fragcoord_input
= i
;
599 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
600 if ((r
= evergreen_interp_input(ctx
, i
)))
603 } else if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
604 /* FIXME probably skip inputs if they aren't passed in the ring */
605 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
606 ctx
->next_ring_offset
+= 16;
607 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
608 ctx
->shader
->gs_prim_id_input
= true;
610 for (j
= 1; j
< count
; ++j
) {
611 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
612 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
615 case TGSI_FILE_OUTPUT
:
616 i
= ctx
->shader
->noutput
++;
617 assert(i
< Elements(ctx
->shader
->output
));
618 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
619 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
620 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
621 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
622 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
623 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
||
624 ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
625 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
626 switch (d
->Semantic
.Name
) {
627 case TGSI_SEMANTIC_CLIPDIST
:
628 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
630 case TGSI_SEMANTIC_PSIZE
:
631 ctx
->shader
->vs_out_misc_write
= 1;
632 ctx
->shader
->vs_out_point_size
= 1;
634 case TGSI_SEMANTIC_EDGEFLAG
:
635 ctx
->shader
->vs_out_misc_write
= 1;
636 ctx
->shader
->vs_out_edgeflag
= 1;
637 ctx
->edgeflag_output
= i
;
639 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
640 ctx
->shader
->vs_out_misc_write
= 1;
641 ctx
->shader
->vs_out_viewport
= 1;
643 case TGSI_SEMANTIC_LAYER
:
644 ctx
->shader
->vs_out_misc_write
= 1;
645 ctx
->shader
->vs_out_layer
= 1;
647 case TGSI_SEMANTIC_CLIPVERTEX
:
648 ctx
->clip_vertex_write
= TRUE
;
652 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
653 ctx
->gs_out_ring_offset
+= 16;
655 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
656 switch (d
->Semantic
.Name
) {
657 case TGSI_SEMANTIC_COLOR
:
658 ctx
->shader
->nr_ps_max_color_exports
++;
663 case TGSI_FILE_TEMPORARY
:
664 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
665 if (d
->Array
.ArrayID
) {
666 r600_add_gpr_array(ctx
->shader
,
667 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
669 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
674 case TGSI_FILE_CONSTANT
:
675 case TGSI_FILE_SAMPLER
:
676 case TGSI_FILE_ADDRESS
:
679 case TGSI_FILE_SYSTEM_VALUE
:
680 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
681 if (!ctx
->native_integers
) {
682 struct r600_bytecode_alu alu
;
683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
685 alu
.op
= ALU_OP1_INT_TO_FLT
;
694 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
698 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
701 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
707 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
709 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
713 * for evergreen we need to scan the shader to find the number of GPRs we need to
714 * reserve for interpolation.
716 * we need to know if we are going to emit
717 * any centroid inputs
718 * if perspective and linear are required
720 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
725 ctx
->input_linear
= FALSE
;
726 ctx
->input_perspective
= FALSE
;
727 ctx
->input_centroid
= FALSE
;
728 ctx
->num_interp_gpr
= 1;
730 /* any centroid inputs */
731 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
732 /* skip position/face */
733 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
734 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
736 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
737 ctx
->input_linear
= TRUE
;
738 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
739 ctx
->input_perspective
= TRUE
;
740 if (ctx
->info
.input_centroid
[i
])
741 ctx
->input_centroid
= TRUE
;
745 /* ignoring sample for now */
746 if (ctx
->input_perspective
)
748 if (ctx
->input_linear
)
750 if (ctx
->input_centroid
)
753 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
755 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
756 return ctx
->num_interp_gpr
;
759 static void tgsi_src(struct r600_shader_ctx
*ctx
,
760 const struct tgsi_full_src_register
*tgsi_src
,
761 struct r600_shader_src
*r600_src
)
763 memset(r600_src
, 0, sizeof(*r600_src
));
764 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
765 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
766 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
767 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
768 r600_src
->neg
= tgsi_src
->Register
.Negate
;
769 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
771 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
773 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
774 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
775 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
777 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
778 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
779 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
782 index
= tgsi_src
->Register
.Index
;
783 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
784 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
785 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
786 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
787 r600_src
->swizzle
[0] = 3;
788 r600_src
->swizzle
[1] = 3;
789 r600_src
->swizzle
[2] = 3;
790 r600_src
->swizzle
[3] = 3;
792 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
793 r600_src
->swizzle
[0] = 0;
794 r600_src
->swizzle
[1] = 0;
795 r600_src
->swizzle
[2] = 0;
796 r600_src
->swizzle
[3] = 0;
800 if (tgsi_src
->Register
.Indirect
)
801 r600_src
->rel
= V_SQ_REL_RELATIVE
;
802 r600_src
->sel
= tgsi_src
->Register
.Index
;
803 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
805 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
806 if (tgsi_src
->Register
.Dimension
) {
807 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
812 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
813 unsigned int cb_idx
, unsigned int offset
, unsigned ar_chan
,
814 unsigned int dst_reg
)
816 struct r600_bytecode_vtx vtx
;
821 struct r600_bytecode_alu alu
;
823 memset(&alu
, 0, sizeof(alu
));
825 alu
.op
= ALU_OP2_ADD_INT
;
826 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
827 alu
.src
[0].chan
= ar_chan
;
829 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
830 alu
.src
[1].value
= offset
;
832 alu
.dst
.sel
= dst_reg
;
833 alu
.dst
.chan
= ar_chan
;
837 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
842 ar_reg
= ctx
->bc
->ar_reg
;
845 memset(&vtx
, 0, sizeof(vtx
));
846 vtx
.buffer_id
= cb_idx
;
847 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
848 vtx
.src_gpr
= ar_reg
;
849 vtx
.src_sel_x
= ar_chan
;
850 vtx
.mega_fetch_count
= 16;
851 vtx
.dst_gpr
= dst_reg
;
852 vtx
.dst_sel_x
= 0; /* SEL_X */
853 vtx
.dst_sel_y
= 1; /* SEL_Y */
854 vtx
.dst_sel_z
= 2; /* SEL_Z */
855 vtx
.dst_sel_w
= 3; /* SEL_W */
856 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
857 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
858 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
859 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
860 vtx
.endian
= r600_endian_swap(32);
862 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
868 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
870 struct r600_bytecode_vtx vtx
;
872 unsigned index
= src
->Register
.Index
;
873 unsigned vtx_id
= src
->Dimension
.Index
;
874 int offset_reg
= vtx_id
/ 3;
875 int offset_chan
= vtx_id
% 3;
877 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
878 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
880 if (offset_reg
== 0 && offset_chan
== 2)
883 if (src
->Dimension
.Indirect
) {
886 struct r600_bytecode_alu alu
;
889 /* you have got to be shitting me -
890 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
891 at least this is what fglrx seems to do. */
892 for (i
= 0; i
< 3; i
++) {
893 treg
[i
] = r600_get_temp(ctx
);
895 t2
= r600_get_temp(ctx
);
896 for (i
= 0; i
< 3; i
++) {
897 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
898 alu
.op
= ALU_OP1_MOV
;
900 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
901 alu
.dst
.sel
= treg
[i
];
905 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
910 alu
.op
= ALU_OP1_MOV
;
911 alu
.src
[0].sel
= treg
[0];
916 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
923 memset(&vtx
, 0, sizeof(vtx
));
924 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
925 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
926 vtx
.src_gpr
= offset_reg
;
927 vtx
.src_sel_x
= offset_chan
;
928 vtx
.offset
= index
* 16; /*bytes*/
929 vtx
.mega_fetch_count
= 16;
930 vtx
.dst_gpr
= dst_reg
;
931 vtx
.dst_sel_x
= 0; /* SEL_X */
932 vtx
.dst_sel_y
= 1; /* SEL_Y */
933 vtx
.dst_sel_z
= 2; /* SEL_Z */
934 vtx
.dst_sel_w
= 3; /* SEL_W */
935 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
936 vtx
.use_const_fields
= 1;
938 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
941 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
947 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
949 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
952 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
953 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
955 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
956 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
957 /* primitive id is in R0.z */
959 ctx
->src
[i
].swizzle
[0] = 2;
962 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
963 int treg
= r600_get_temp(ctx
);
965 fetch_gs_input(ctx
, src
, treg
);
966 ctx
->src
[i
].sel
= treg
;
972 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
974 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
975 struct r600_bytecode_alu alu
;
976 int i
, j
, k
, nconst
, r
;
978 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
979 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
982 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
984 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
985 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
989 if (ctx
->src
[i
].rel
) {
990 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
991 int treg
= r600_get_temp(ctx
);
992 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
995 ctx
->src
[i
].kc_bank
= 0;
996 ctx
->src
[i
].sel
= treg
;
1000 int treg
= r600_get_temp(ctx
);
1001 for (k
= 0; k
< 4; k
++) {
1002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1003 alu
.op
= ALU_OP1_MOV
;
1004 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1005 alu
.src
[0].chan
= k
;
1006 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1012 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1016 ctx
->src
[i
].sel
= treg
;
1024 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1025 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1027 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1028 struct r600_bytecode_alu alu
;
1029 int i
, j
, k
, nliteral
, r
;
1031 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1032 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1036 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1037 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1038 int treg
= r600_get_temp(ctx
);
1039 for (k
= 0; k
< 4; k
++) {
1040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1041 alu
.op
= ALU_OP1_MOV
;
1042 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1043 alu
.src
[0].chan
= k
;
1044 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1054 ctx
->src
[i
].sel
= treg
;
1061 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1063 int i
, r
, count
= ctx
->shader
->ninput
;
1065 for (i
= 0; i
< count
; i
++) {
1066 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1067 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1075 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
)
1077 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1080 /* Sanity checking. */
1081 if (so
->num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1082 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
1086 for (i
= 0; i
< so
->num_outputs
; i
++) {
1087 if (so
->output
[i
].output_buffer
>= 4) {
1088 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1089 so
->output
[i
].output_buffer
);
1095 /* Initialize locations where the outputs are stored. */
1096 for (i
= 0; i
< so
->num_outputs
; i
++) {
1097 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
1099 /* Lower outputs with dst_offset < start_component.
1101 * We can only output 4D vectors with a write mask, e.g. we can
1102 * only output the W component at offset 3, etc. If we want
1103 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1104 * to move it to X and output X. */
1105 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
1106 unsigned tmp
= r600_get_temp(ctx
);
1108 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
1109 struct r600_bytecode_alu alu
;
1110 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1111 alu
.op
= ALU_OP1_MOV
;
1112 alu
.src
[0].sel
= so_gpr
[i
];
1113 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
1118 if (j
== so
->output
[i
].num_components
- 1)
1120 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1124 so
->output
[i
].start_component
= 0;
1129 /* Write outputs to buffers. */
1130 for (i
= 0; i
< so
->num_outputs
; i
++) {
1131 struct r600_bytecode_output output
;
1133 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1134 output
.gpr
= so_gpr
[i
];
1135 output
.elem_size
= so
->output
[i
].num_components
;
1136 output
.array_base
= so
->output
[i
].dst_offset
- so
->output
[i
].start_component
;
1137 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1138 output
.burst_count
= 1;
1139 /* array_size is an upper limit for the burst_count
1140 * with MEM_STREAM instructions */
1141 output
.array_size
= 0xFFF;
1142 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << so
->output
[i
].start_component
;
1143 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1144 switch (so
->output
[i
].output_buffer
) {
1146 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1149 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1152 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1155 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1159 switch (so
->output
[i
].output_buffer
) {
1161 output
.op
= CF_OP_MEM_STREAM0
;
1164 output
.op
= CF_OP_MEM_STREAM1
;
1167 output
.op
= CF_OP_MEM_STREAM2
;
1170 output
.op
= CF_OP_MEM_STREAM3
;
1174 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
1183 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
1185 struct r600_bytecode_alu alu
;
1188 if (!ctx
->shader
->vs_out_edgeflag
)
1191 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
1193 /* clamp(x, 0, 1) */
1194 memset(&alu
, 0, sizeof(alu
));
1195 alu
.op
= ALU_OP1_MOV
;
1196 alu
.src
[0].sel
= reg
;
1201 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1203 memset(&alu
, 0, sizeof(alu
));
1204 alu
.op
= ALU_OP1_FLT_TO_INT
;
1205 alu
.src
[0].sel
= reg
;
1209 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1212 static int generate_gs_copy_shader(struct r600_context
*rctx
,
1213 struct r600_pipe_shader
*gs
,
1214 struct pipe_stream_output_info
*so
)
1216 struct r600_shader_ctx ctx
= {};
1217 struct r600_shader
*gs_shader
= &gs
->shader
;
1218 struct r600_pipe_shader
*cshader
;
1219 int ocnt
= gs_shader
->noutput
;
1220 struct r600_bytecode_alu alu
;
1221 struct r600_bytecode_vtx vtx
;
1222 struct r600_bytecode_output output
;
1223 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
1224 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
1225 int i
, next_clip_pos
= 61, next_param
= 0;
1227 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
1231 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
1232 sizeof(struct r600_shader_io
));
1234 cshader
->shader
.noutput
= ocnt
;
1236 ctx
.shader
= &cshader
->shader
;
1237 ctx
.bc
= &ctx
.shader
->bc
;
1238 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
1240 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
1241 rctx
->screen
->has_compressed_msaa_texturing
);
1243 ctx
.bc
->isa
= rctx
->isa
;
1245 /* R0.x = R0.x & 0x3fffffff */
1246 memset(&alu
, 0, sizeof(alu
));
1247 alu
.op
= ALU_OP2_AND_INT
;
1248 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1249 alu
.src
[1].value
= 0x3fffffff;
1251 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1253 /* R0.y = R0.x >> 30 */
1254 memset(&alu
, 0, sizeof(alu
));
1255 alu
.op
= ALU_OP2_LSHR_INT
;
1256 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1257 alu
.src
[1].value
= 0x1e;
1261 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1263 /* PRED_SETE_INT __, R0.y, 0 */
1264 memset(&alu
, 0, sizeof(alu
));
1265 alu
.op
= ALU_OP2_PRED_SETE_INT
;
1266 alu
.src
[0].chan
= 1;
1267 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1268 alu
.execute_mask
= 1;
1269 alu
.update_pred
= 1;
1271 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
1273 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
1274 cf_jump
= ctx
.bc
->cf_last
;
1276 /* fetch vertex data from GSVS ring */
1277 for (i
= 0; i
< ocnt
; ++i
) {
1278 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1280 out
->ring_offset
= i
* 16;
1282 memset(&vtx
, 0, sizeof(vtx
));
1283 vtx
.op
= FETCH_OP_VFETCH
;
1284 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1286 vtx
.offset
= out
->ring_offset
;
1287 vtx
.dst_gpr
= out
->gpr
;
1292 if (rctx
->b
.chip_class
>= EVERGREEN
) {
1293 vtx
.use_const_fields
= 1;
1295 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1298 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
1301 /* XXX handle clipvertex, streamout? */
1302 emit_streamout(&ctx
, so
);
1304 /* export vertex data */
1305 /* XXX factor out common code with r600_shader_from_tgsi ? */
1306 for (i
= 0; i
< ocnt
; ++i
) {
1307 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1309 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
1312 memset(&output
, 0, sizeof(output
));
1313 output
.gpr
= out
->gpr
;
1314 output
.elem_size
= 3;
1315 output
.swizzle_x
= 0;
1316 output
.swizzle_y
= 1;
1317 output
.swizzle_z
= 2;
1318 output
.swizzle_w
= 3;
1319 output
.burst_count
= 1;
1320 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1321 output
.op
= CF_OP_EXPORT
;
1322 switch (out
->name
) {
1323 case TGSI_SEMANTIC_POSITION
:
1324 output
.array_base
= 60;
1325 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1328 case TGSI_SEMANTIC_PSIZE
:
1329 output
.array_base
= 61;
1330 if (next_clip_pos
== 61)
1332 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1333 output
.swizzle_y
= 7;
1334 output
.swizzle_z
= 7;
1335 output
.swizzle_w
= 7;
1336 ctx
.shader
->vs_out_misc_write
= 1;
1337 ctx
.shader
->vs_out_point_size
= 1;
1339 case TGSI_SEMANTIC_LAYER
:
1340 output
.array_base
= 61;
1341 if (next_clip_pos
== 61)
1343 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1344 output
.swizzle_x
= 7;
1345 output
.swizzle_y
= 7;
1346 output
.swizzle_z
= 0;
1347 output
.swizzle_w
= 7;
1348 ctx
.shader
->vs_out_misc_write
= 1;
1349 ctx
.shader
->vs_out_layer
= 1;
1351 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
1352 output
.array_base
= 61;
1353 if (next_clip_pos
== 61)
1355 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1356 ctx
.shader
->vs_out_misc_write
= 1;
1357 ctx
.shader
->vs_out_viewport
= 1;
1358 output
.swizzle_x
= 7;
1359 output
.swizzle_y
= 7;
1360 output
.swizzle_z
= 7;
1361 output
.swizzle_w
= 0;
1363 case TGSI_SEMANTIC_CLIPDIST
:
1364 /* spi_sid is 0 for clipdistance outputs that were generated
1365 * for clipvertex - we don't need to pass them to PS */
1366 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
1368 /* duplicate it as PARAM to pass to the pixel shader */
1369 output
.array_base
= next_param
++;
1370 r600_bytecode_add_output(ctx
.bc
, &output
);
1371 last_exp_param
= ctx
.bc
->cf_last
;
1373 output
.array_base
= next_clip_pos
++;
1374 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1376 case TGSI_SEMANTIC_FOG
:
1377 output
.swizzle_y
= 4; /* 0 */
1378 output
.swizzle_z
= 4; /* 0 */
1379 output
.swizzle_w
= 5; /* 1 */
1382 output
.array_base
= next_param
++;
1385 r600_bytecode_add_output(ctx
.bc
, &output
);
1386 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
1387 last_exp_param
= ctx
.bc
->cf_last
;
1389 last_exp_pos
= ctx
.bc
->cf_last
;
1392 if (!last_exp_pos
) {
1393 memset(&output
, 0, sizeof(output
));
1395 output
.elem_size
= 3;
1396 output
.swizzle_x
= 7;
1397 output
.swizzle_y
= 7;
1398 output
.swizzle_z
= 7;
1399 output
.swizzle_w
= 7;
1400 output
.burst_count
= 1;
1402 output
.op
= CF_OP_EXPORT
;
1403 output
.array_base
= 60;
1404 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1405 r600_bytecode_add_output(ctx
.bc
, &output
);
1406 last_exp_pos
= ctx
.bc
->cf_last
;
1409 if (!last_exp_param
) {
1410 memset(&output
, 0, sizeof(output
));
1412 output
.elem_size
= 3;
1413 output
.swizzle_x
= 7;
1414 output
.swizzle_y
= 7;
1415 output
.swizzle_z
= 7;
1416 output
.swizzle_w
= 7;
1417 output
.burst_count
= 1;
1419 output
.op
= CF_OP_EXPORT
;
1420 output
.array_base
= next_param
++;
1421 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1422 r600_bytecode_add_output(ctx
.bc
, &output
);
1423 last_exp_param
= ctx
.bc
->cf_last
;
1426 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
1427 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
1429 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1430 cf_pop
= ctx
.bc
->cf_last
;
1432 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1433 cf_jump
->pop_count
= 1;
1434 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1435 cf_pop
->pop_count
= 1;
1437 if (ctx
.bc
->chip_class
== CAYMAN
)
1438 cm_bytecode_add_cf_end(ctx
.bc
);
1440 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1441 ctx
.bc
->cf_last
->end_of_program
= 1;
1444 gs
->gs_copy_shader
= cshader
;
1447 cshader
->shader
.ring_item_size
= ocnt
* 16;
1449 return r600_bytecode_build(ctx
.bc
);
1452 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, bool ind
)
1454 struct r600_bytecode_output output
;
1455 int i
, k
, ring_offset
;
1457 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
1458 if (ctx
->gs_for_vs
) {
1459 /* for ES we need to lookup corresponding ring offset expected by GS
1460 * (map this output to GS input by name and sid) */
1461 /* FIXME precompute offsets */
1463 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
1464 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
1465 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
1466 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
1467 ring_offset
= in
->ring_offset
;
1470 if (ring_offset
== -1)
1473 ring_offset
= i
* 16;
1475 /* next_ring_offset after parsing input decls contains total size of
1476 * single vertex data, gs_next_vertex - current vertex index */
1478 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
1480 /* get a temp and add the ring offset to the next vertex base in the shader */
1481 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1482 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
1483 output
.elem_size
= 3;
1484 output
.comp_mask
= 0xF;
1485 output
.burst_count
= 1;
1488 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
1490 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1491 output
.op
= CF_OP_MEM_RING
;
1495 output
.array_base
= ring_offset
>> 2; /* in dwords */
1496 output
.array_size
= 0xfff;
1497 output
.index_gpr
= ctx
->gs_export_gpr_treg
;
1499 output
.array_base
= ring_offset
>> 2; /* in dwords */
1500 r600_bytecode_add_output(ctx
->bc
, &output
);
1504 struct r600_bytecode_alu alu
;
1507 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1508 alu
.op
= ALU_OP2_ADD_INT
;
1509 alu
.src
[0].sel
= ctx
->gs_export_gpr_treg
;
1510 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1511 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
1512 alu
.dst
.sel
= ctx
->gs_export_gpr_treg
;
1515 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1519 ++ctx
->gs_next_vertex
;
1523 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
1524 struct r600_pipe_shader
*pipeshader
,
1525 struct r600_shader_key key
)
1527 struct r600_screen
*rscreen
= rctx
->screen
;
1528 struct r600_shader
*shader
= &pipeshader
->shader
;
1529 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1530 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1531 struct tgsi_full_immediate
*immediate
;
1532 struct tgsi_full_property
*property
;
1533 struct r600_shader_ctx ctx
;
1534 struct r600_bytecode_output output
[32];
1535 unsigned output_done
, noutput
;
1538 int next_param_base
= 0, next_clip_base
;
1539 int max_color_exports
= MAX2(key
.nr_cbufs
, 1);
1540 /* Declarations used by llvm code */
1541 bool use_llvm
= false;
1543 bool ring_outputs
= false;
1544 bool pos_emitted
= false;
1546 #ifdef R600_USE_LLVM
1547 use_llvm
= rscreen
->b
.debug_flags
& DBG_LLVM
;
1549 ctx
.bc
= &shader
->bc
;
1550 ctx
.shader
= shader
;
1551 ctx
.native_integers
= true;
1553 shader
->vs_as_es
= key
.vs_as_es
;
1555 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
1556 rscreen
->has_compressed_msaa_texturing
);
1557 ctx
.tokens
= tokens
;
1558 tgsi_scan_shader(tokens
, &ctx
.info
);
1559 shader
->indirect_files
= ctx
.info
.indirect_files
;
1560 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
1561 tgsi_parse_init(&ctx
.parse
, tokens
);
1562 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1563 shader
->processor_type
= ctx
.type
;
1564 ctx
.bc
->type
= shader
->processor_type
;
1566 ring_outputs
= key
.vs_as_es
|| (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
);
1569 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
1571 ctx
.gs_for_vs
= NULL
;
1574 ctx
.next_ring_offset
= 0;
1575 ctx
.gs_out_ring_offset
= 0;
1576 ctx
.gs_next_vertex
= 0;
1579 ctx
.fragcoord_input
= -1;
1580 ctx
.colors_used
= 0;
1581 ctx
.clip_vertex_write
= 0;
1583 shader
->nr_ps_color_exports
= 0;
1584 shader
->nr_ps_max_color_exports
= 0;
1586 shader
->two_side
= key
.color_two_side
;
1588 /* register allocations */
1589 /* Values [0,127] correspond to GPR[0..127].
1590 * Values [128,159] correspond to constant buffer bank 0
1591 * Values [160,191] correspond to constant buffer bank 1
1592 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1593 * Values [256,287] correspond to constant buffer bank 2 (EG)
1594 * Values [288,319] correspond to constant buffer bank 3 (EG)
1595 * Other special values are shown in the list below.
1596 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1597 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1598 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1599 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1600 * 248 SQ_ALU_SRC_0: special constant 0.0.
1601 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1602 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1603 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1604 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1605 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1606 * 254 SQ_ALU_SRC_PV: previous vector result.
1607 * 255 SQ_ALU_SRC_PS: previous scalar result.
1609 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1610 ctx
.file_offset
[i
] = 0;
1613 #ifdef R600_USE_LLVM
1614 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1615 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1616 "indirect adressing. Falling back to TGSI "
1621 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1622 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1624 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1627 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1628 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1630 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1631 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
1632 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
1634 ctx
.use_llvm
= use_llvm
;
1637 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1638 ctx
.file_offset
[TGSI_FILE_INPUT
];
1640 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1641 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1642 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1644 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1645 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1647 /* Outside the GPR range. This will be translated to one of the
1648 * kcache banks later. */
1649 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1651 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1652 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1653 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1654 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1655 ctx
.gs_export_gpr_treg
= ctx
.bc
->ar_reg
+ 1;
1656 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 2;
1658 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1660 if (indirect_gprs
) {
1661 shader
->max_arrays
= 0;
1662 shader
->num_arrays
= 0;
1664 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1665 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1666 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1667 ctx
.file_offset
[TGSI_FILE_INPUT
],
1670 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1671 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1672 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1673 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1679 ctx
.literals
= NULL
;
1680 shader
->fs_write_all
= FALSE
;
1681 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1682 tgsi_parse_token(&ctx
.parse
);
1683 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1684 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1685 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1686 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1687 if(ctx
.literals
== NULL
) {
1691 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1692 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1693 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1694 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1697 case TGSI_TOKEN_TYPE_DECLARATION
:
1698 r
= tgsi_declaration(&ctx
);
1702 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1704 case TGSI_TOKEN_TYPE_PROPERTY
:
1705 property
= &ctx
.parse
.FullToken
.FullProperty
;
1706 switch (property
->Property
.PropertyName
) {
1707 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1708 if (property
->u
[0].Data
== 1)
1709 shader
->fs_write_all
= TRUE
;
1711 case TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
:
1712 if (property
->u
[0].Data
== 1)
1713 shader
->vs_position_window_space
= TRUE
;
1715 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1716 /* we don't need this one */
1718 case TGSI_PROPERTY_GS_INPUT_PRIM
:
1719 shader
->gs_input_prim
= property
->u
[0].Data
;
1721 case TGSI_PROPERTY_GS_OUTPUT_PRIM
:
1722 shader
->gs_output_prim
= property
->u
[0].Data
;
1724 case TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
:
1725 shader
->gs_max_out_vertices
= property
->u
[0].Data
;
1730 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1736 shader
->ring_item_size
= ctx
.next_ring_offset
;
1738 /* Process two side if needed */
1739 if (shader
->two_side
&& ctx
.colors_used
) {
1740 int i
, count
= ctx
.shader
->ninput
;
1741 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1743 /* additional inputs will be allocated right after the existing inputs,
1744 * we won't need them after the color selection, so we don't need to
1745 * reserve these gprs for the rest of the shader code and to adjust
1746 * output offsets etc. */
1747 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1748 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1750 if (ctx
.face_gpr
== -1) {
1751 i
= ctx
.shader
->ninput
++;
1752 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1753 ctx
.shader
->input
[i
].spi_sid
= 0;
1754 ctx
.shader
->input
[i
].gpr
= gpr
++;
1755 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1758 for (i
= 0; i
< count
; i
++) {
1759 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1760 int ni
= ctx
.shader
->ninput
++;
1761 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1762 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1763 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1764 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1765 // TGSI to LLVM needs to know the lds position of inputs.
1766 // Non LLVM path computes it later (in process_twoside_color)
1767 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1768 ctx
.shader
->input
[i
].back_color_input
= ni
;
1769 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1770 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1777 /* LLVM backend setup */
1778 #ifdef R600_USE_LLVM
1780 struct radeon_llvm_context radeon_llvm_ctx
;
1782 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
1783 boolean use_kill
= false;
1785 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1786 radeon_llvm_ctx
.type
= ctx
.type
;
1787 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1788 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1789 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
1790 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1791 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1792 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
1793 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1794 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
1795 radeon_llvm_ctx
.stream_outputs
= &so
;
1796 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1797 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1798 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
1799 ctx
.bc
->has_compressed_msaa_texturing
;
1800 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1801 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1802 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
1804 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
1805 radeon_llvm_dispose(&radeon_llvm_ctx
);
1807 fprintf(stderr
, "R600 LLVM backend failed to compile "
1808 "shader. Falling back to TGSI\n");
1810 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1811 ctx
.file_offset
[TGSI_FILE_INPUT
];
1814 ctx
.shader
->uses_kill
= use_kill
;
1815 radeon_llvm_dispose(&radeon_llvm_ctx
);
1818 /* End of LLVM backend setup */
1820 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
1821 shader
->nr_ps_max_color_exports
= 8;
1824 if (ctx
.fragcoord_input
>= 0) {
1825 if (ctx
.bc
->chip_class
== CAYMAN
) {
1826 for (j
= 0 ; j
< 4; j
++) {
1827 struct r600_bytecode_alu alu
;
1828 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1829 alu
.op
= ALU_OP1_RECIP_IEEE
;
1830 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1831 alu
.src
[0].chan
= 3;
1833 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1835 alu
.dst
.write
= (j
== 3);
1837 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1841 struct r600_bytecode_alu alu
;
1842 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1843 alu
.op
= ALU_OP1_RECIP_IEEE
;
1844 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1845 alu
.src
[0].chan
= 3;
1847 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1851 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1856 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1857 struct r600_bytecode_alu alu
;
1860 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1861 alu
.op
= ALU_OP1_MOV
;
1862 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1863 alu
.src
[0].value
= 0;
1864 alu
.dst
.sel
= ctx
.gs_export_gpr_treg
;
1867 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1871 if (shader
->two_side
&& ctx
.colors_used
) {
1872 if ((r
= process_twoside_color_inputs(&ctx
)))
1876 tgsi_parse_init(&ctx
.parse
, tokens
);
1877 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1878 tgsi_parse_token(&ctx
.parse
);
1879 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1880 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1881 r
= tgsi_is_supported(&ctx
);
1884 ctx
.max_driver_temp_used
= 0;
1885 /* reserve first tmp for everyone */
1886 r600_get_temp(&ctx
);
1888 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1889 if ((r
= tgsi_split_constant(&ctx
)))
1891 if ((r
= tgsi_split_literal_constant(&ctx
)))
1893 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
)
1894 if ((r
= tgsi_split_gs_inputs(&ctx
)))
1896 if (ctx
.bc
->chip_class
== CAYMAN
)
1897 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1898 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1899 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1901 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1902 r
= ctx
.inst_info
->process(&ctx
);
1912 /* Reset the temporary register counter. */
1913 ctx
.max_driver_temp_used
= 0;
1915 noutput
= shader
->noutput
;
1917 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
1918 unsigned clipdist_temp
[2];
1920 clipdist_temp
[0] = r600_get_temp(&ctx
);
1921 clipdist_temp
[1] = r600_get_temp(&ctx
);
1923 /* need to convert a clipvertex write into clipdistance writes and not export
1924 the clip vertex anymore */
1926 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1927 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1928 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1930 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1931 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1934 /* reset spi_sid for clipvertex output to avoid confusing spi */
1935 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1937 shader
->clip_dist_write
= 0xFF;
1939 for (i
= 0; i
< 8; i
++) {
1943 for (j
= 0; j
< 4; j
++) {
1944 struct r600_bytecode_alu alu
;
1945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1946 alu
.op
= ALU_OP2_DOT4
;
1947 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1948 alu
.src
[0].chan
= j
;
1950 alu
.src
[1].sel
= 512 + i
;
1951 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1952 alu
.src
[1].chan
= j
;
1954 alu
.dst
.sel
= clipdist_temp
[oreg
];
1956 alu
.dst
.write
= (j
== ochan
);
1960 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1967 /* Add stream outputs. */
1968 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
&&
1969 so
.num_outputs
&& !use_llvm
)
1970 emit_streamout(&ctx
, &so
);
1972 convert_edgeflag_to_int(&ctx
);
1976 emit_gs_ring_writes(&ctx
, FALSE
);
1979 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
1981 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1982 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1983 output
[j
].gpr
= shader
->output
[i
].gpr
;
1984 output
[j
].elem_size
= 3;
1985 output
[j
].swizzle_x
= 0;
1986 output
[j
].swizzle_y
= 1;
1987 output
[j
].swizzle_z
= 2;
1988 output
[j
].swizzle_w
= 3;
1989 output
[j
].burst_count
= 1;
1990 output
[j
].type
= -1;
1991 output
[j
].op
= CF_OP_EXPORT
;
1993 case TGSI_PROCESSOR_VERTEX
:
1994 switch (shader
->output
[i
].name
) {
1995 case TGSI_SEMANTIC_POSITION
:
1996 output
[j
].array_base
= 60;
1997 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2001 case TGSI_SEMANTIC_PSIZE
:
2002 output
[j
].array_base
= 61;
2003 output
[j
].swizzle_y
= 7;
2004 output
[j
].swizzle_z
= 7;
2005 output
[j
].swizzle_w
= 7;
2006 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2009 case TGSI_SEMANTIC_EDGEFLAG
:
2010 output
[j
].array_base
= 61;
2011 output
[j
].swizzle_x
= 7;
2012 output
[j
].swizzle_y
= 0;
2013 output
[j
].swizzle_z
= 7;
2014 output
[j
].swizzle_w
= 7;
2015 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2018 case TGSI_SEMANTIC_LAYER
:
2019 output
[j
].array_base
= 61;
2020 output
[j
].swizzle_x
= 7;
2021 output
[j
].swizzle_y
= 7;
2022 output
[j
].swizzle_z
= 0;
2023 output
[j
].swizzle_w
= 7;
2024 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2027 case TGSI_SEMANTIC_CLIPVERTEX
:
2030 case TGSI_SEMANTIC_CLIPDIST
:
2031 output
[j
].array_base
= next_clip_base
++;
2032 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2034 /* spi_sid is 0 for clipdistance outputs that were generated
2035 * for clipvertex - we don't need to pass them to PS */
2036 if (shader
->output
[i
].spi_sid
) {
2038 /* duplicate it as PARAM to pass to the pixel shader */
2039 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2040 output
[j
].array_base
= next_param_base
++;
2041 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2044 case TGSI_SEMANTIC_FOG
:
2045 output
[j
].swizzle_y
= 4; /* 0 */
2046 output
[j
].swizzle_z
= 4; /* 0 */
2047 output
[j
].swizzle_w
= 5; /* 1 */
2051 case TGSI_PROCESSOR_FRAGMENT
:
2052 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2053 /* never export more colors than the number of CBs */
2054 if (shader
->output
[i
].sid
>= max_color_exports
) {
2059 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
2060 output
[j
].array_base
= shader
->output
[i
].sid
;
2061 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2062 shader
->nr_ps_color_exports
++;
2063 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
2064 for (k
= 1; k
< max_color_exports
; k
++) {
2066 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2067 output
[j
].gpr
= shader
->output
[i
].gpr
;
2068 output
[j
].elem_size
= 3;
2069 output
[j
].swizzle_x
= 0;
2070 output
[j
].swizzle_y
= 1;
2071 output
[j
].swizzle_z
= 2;
2072 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
2073 output
[j
].burst_count
= 1;
2074 output
[j
].array_base
= k
;
2075 output
[j
].op
= CF_OP_EXPORT
;
2076 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2077 shader
->nr_ps_color_exports
++;
2080 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
2081 output
[j
].array_base
= 61;
2082 output
[j
].swizzle_x
= 2;
2083 output
[j
].swizzle_y
= 7;
2084 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2085 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2086 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
2087 output
[j
].array_base
= 61;
2088 output
[j
].swizzle_x
= 7;
2089 output
[j
].swizzle_y
= 1;
2090 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2091 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2093 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
2099 R600_ERR("unsupported processor type %d\n", ctx
.type
);
2104 if (output
[j
].type
==-1) {
2105 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2106 output
[j
].array_base
= next_param_base
++;
2110 /* add fake position export */
2111 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& pos_emitted
== false) {
2112 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2114 output
[j
].elem_size
= 3;
2115 output
[j
].swizzle_x
= 7;
2116 output
[j
].swizzle_y
= 7;
2117 output
[j
].swizzle_z
= 7;
2118 output
[j
].swizzle_w
= 7;
2119 output
[j
].burst_count
= 1;
2120 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2121 output
[j
].array_base
= 60;
2122 output
[j
].op
= CF_OP_EXPORT
;
2126 /* add fake param output for vertex shader if no param is exported */
2127 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
2128 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2130 output
[j
].elem_size
= 3;
2131 output
[j
].swizzle_x
= 7;
2132 output
[j
].swizzle_y
= 7;
2133 output
[j
].swizzle_z
= 7;
2134 output
[j
].swizzle_w
= 7;
2135 output
[j
].burst_count
= 1;
2136 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2137 output
[j
].array_base
= 0;
2138 output
[j
].op
= CF_OP_EXPORT
;
2142 /* add fake pixel export */
2143 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
2144 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2146 output
[j
].elem_size
= 3;
2147 output
[j
].swizzle_x
= 7;
2148 output
[j
].swizzle_y
= 7;
2149 output
[j
].swizzle_z
= 7;
2150 output
[j
].swizzle_w
= 7;
2151 output
[j
].burst_count
= 1;
2152 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2153 output
[j
].array_base
= 0;
2154 output
[j
].op
= CF_OP_EXPORT
;
2160 /* set export done on last export of each type */
2161 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
2162 if (!(output_done
& (1 << output
[i
].type
))) {
2163 output_done
|= (1 << output
[i
].type
);
2164 output
[i
].op
= CF_OP_EXPORT_DONE
;
2167 /* add output to bytecode */
2169 for (i
= 0; i
< noutput
; i
++) {
2170 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
2177 /* add program end */
2179 if (ctx
.bc
->chip_class
== CAYMAN
)
2180 cm_bytecode_add_cf_end(ctx
.bc
);
2182 const struct cf_op_info
*last
= NULL
;
2184 if (ctx
.bc
->cf_last
)
2185 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
2187 /* alu clause instructions don't have EOP bit, so add NOP */
2188 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
)
2189 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2191 ctx
.bc
->cf_last
->end_of_program
= 1;
2195 /* check GPR limit - we have 124 = 128 - 4
2196 * (4 are reserved as alu clause temporary registers) */
2197 if (ctx
.bc
->ngpr
> 124) {
2198 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
2203 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2204 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
2209 tgsi_parse_free(&ctx
.parse
);
2213 tgsi_parse_free(&ctx
.parse
);
2217 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
2219 R600_ERR("%s tgsi opcode unsupported\n",
2220 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
2224 static int tgsi_end(struct r600_shader_ctx
*ctx
)
2229 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
2230 const struct r600_shader_src
*shader_src
,
2233 bc_src
->sel
= shader_src
->sel
;
2234 bc_src
->chan
= shader_src
->swizzle
[chan
];
2235 bc_src
->neg
= shader_src
->neg
;
2236 bc_src
->abs
= shader_src
->abs
;
2237 bc_src
->rel
= shader_src
->rel
;
2238 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
2239 bc_src
->kc_bank
= shader_src
->kc_bank
;
2242 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2248 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2250 bc_src
->neg
= !bc_src
->neg
;
2253 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2254 const struct tgsi_full_dst_register
*tgsi_dst
,
2256 struct r600_bytecode_alu_dst
*r600_dst
)
2258 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2260 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2261 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2262 r600_dst
->chan
= swizzle
;
2263 r600_dst
->write
= 1;
2264 if (tgsi_dst
->Register
.Indirect
)
2265 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2266 if (inst
->Instruction
.Saturate
) {
2267 r600_dst
->clamp
= 1;
2271 static int tgsi_last_instruction(unsigned writemask
)
2275 for (i
= 0; i
< 4; i
++) {
2276 if (writemask
& (1 << i
)) {
2283 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
2285 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2286 struct r600_bytecode_alu alu
;
2287 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2288 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2289 /* use temp register if trans_only and more than one dst component */
2290 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
2292 for (i
= 0; i
<= lasti
; i
++) {
2293 if (!(write_mask
& (1 << i
)))
2296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2298 alu
.dst
.sel
= ctx
->temp_reg
;
2302 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2304 alu
.op
= ctx
->inst_info
->op
;
2306 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2307 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2310 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2311 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2313 /* handle some special cases */
2314 switch (ctx
->inst_info
->tgsi_opcode
) {
2315 case TGSI_OPCODE_SUB
:
2316 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2318 case TGSI_OPCODE_ABS
:
2319 r600_bytecode_src_set_abs(&alu
.src
[0]);
2324 if (i
== lasti
|| trans_only
) {
2327 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2333 /* move result from temp to dst */
2334 for (i
= 0; i
<= lasti
; i
++) {
2335 if (!(write_mask
& (1 << i
)))
2338 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2339 alu
.op
= ALU_OP1_MOV
;
2340 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2341 alu
.src
[0].sel
= ctx
->temp_reg
;
2342 alu
.src
[0].chan
= i
;
2343 alu
.last
= (i
== lasti
);
2345 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2353 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2355 return tgsi_op2_s(ctx
, 0, 0);
2358 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2360 return tgsi_op2_s(ctx
, 1, 0);
2363 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2365 return tgsi_op2_s(ctx
, 0, 1);
2368 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2370 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2371 struct r600_bytecode_alu alu
;
2373 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2375 for (i
= 0; i
< lasti
+ 1; i
++) {
2377 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2379 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2380 alu
.op
= ctx
->inst_info
->op
;
2382 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2384 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2386 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2391 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2399 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2401 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2403 struct r600_bytecode_alu alu
;
2404 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2406 for (i
= 0 ; i
< last_slot
; i
++) {
2407 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2408 alu
.op
= ctx
->inst_info
->op
;
2409 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2410 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2412 /* RSQ should take the absolute value of src */
2413 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2414 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2417 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2418 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2420 if (i
== last_slot
- 1)
2422 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2429 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2431 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2433 struct r600_bytecode_alu alu
;
2434 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2435 for (k
= 0; k
< last_slot
; k
++) {
2436 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2439 for (i
= 0 ; i
< 4; i
++) {
2440 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2441 alu
.op
= ctx
->inst_info
->op
;
2442 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2443 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2445 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2446 alu
.dst
.write
= (i
== k
);
2449 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2458 * r600 - trunc to -PI..PI range
2459 * r700 - normalize by dividing by 2PI
2462 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2464 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2465 static float double_pi
= 3.1415926535 * 2;
2466 static float neg_pi
= -3.1415926535;
2469 struct r600_bytecode_alu alu
;
2471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2472 alu
.op
= ALU_OP3_MULADD
;
2476 alu
.dst
.sel
= ctx
->temp_reg
;
2479 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2481 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2482 alu
.src
[1].chan
= 0;
2483 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2484 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2485 alu
.src
[2].chan
= 0;
2487 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2492 alu
.op
= ALU_OP1_FRACT
;
2495 alu
.dst
.sel
= ctx
->temp_reg
;
2498 alu
.src
[0].sel
= ctx
->temp_reg
;
2499 alu
.src
[0].chan
= 0;
2501 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2505 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2506 alu
.op
= ALU_OP3_MULADD
;
2510 alu
.dst
.sel
= ctx
->temp_reg
;
2513 alu
.src
[0].sel
= ctx
->temp_reg
;
2514 alu
.src
[0].chan
= 0;
2516 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2517 alu
.src
[1].chan
= 0;
2518 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2519 alu
.src
[2].chan
= 0;
2521 if (ctx
->bc
->chip_class
== R600
) {
2522 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2523 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2525 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2526 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2531 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2537 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2539 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2540 struct r600_bytecode_alu alu
;
2541 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2544 r
= tgsi_setup_trig(ctx
);
2549 for (i
= 0; i
< last_slot
; i
++) {
2550 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2551 alu
.op
= ctx
->inst_info
->op
;
2554 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2555 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2557 alu
.src
[0].sel
= ctx
->temp_reg
;
2558 alu
.src
[0].chan
= 0;
2559 if (i
== last_slot
- 1)
2561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2568 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2570 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2571 struct r600_bytecode_alu alu
;
2573 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2575 r
= tgsi_setup_trig(ctx
);
2579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2580 alu
.op
= ctx
->inst_info
->op
;
2582 alu
.dst
.sel
= ctx
->temp_reg
;
2585 alu
.src
[0].sel
= ctx
->temp_reg
;
2586 alu
.src
[0].chan
= 0;
2588 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2592 /* replicate result */
2593 for (i
= 0; i
< lasti
+ 1; i
++) {
2594 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2597 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2598 alu
.op
= ALU_OP1_MOV
;
2600 alu
.src
[0].sel
= ctx
->temp_reg
;
2601 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2604 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2611 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2613 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2614 struct r600_bytecode_alu alu
;
2617 /* We'll only need the trig stuff if we are going to write to the
2618 * X or Y components of the destination vector.
2620 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2621 r
= tgsi_setup_trig(ctx
);
2627 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2628 if (ctx
->bc
->chip_class
== CAYMAN
) {
2629 for (i
= 0 ; i
< 3; i
++) {
2630 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2631 alu
.op
= ALU_OP1_COS
;
2632 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2638 alu
.src
[0].sel
= ctx
->temp_reg
;
2639 alu
.src
[0].chan
= 0;
2642 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2648 alu
.op
= ALU_OP1_COS
;
2649 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2651 alu
.src
[0].sel
= ctx
->temp_reg
;
2652 alu
.src
[0].chan
= 0;
2654 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2661 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2662 if (ctx
->bc
->chip_class
== CAYMAN
) {
2663 for (i
= 0 ; i
< 3; i
++) {
2664 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2665 alu
.op
= ALU_OP1_SIN
;
2666 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2671 alu
.src
[0].sel
= ctx
->temp_reg
;
2672 alu
.src
[0].chan
= 0;
2675 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2680 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2681 alu
.op
= ALU_OP1_SIN
;
2682 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2684 alu
.src
[0].sel
= ctx
->temp_reg
;
2685 alu
.src
[0].chan
= 0;
2687 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2694 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2695 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2697 alu
.op
= ALU_OP1_MOV
;
2699 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2701 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2702 alu
.src
[0].chan
= 0;
2706 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2712 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2715 alu
.op
= ALU_OP1_MOV
;
2717 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2719 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2720 alu
.src
[0].chan
= 0;
2724 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2732 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2734 struct r600_bytecode_alu alu
;
2737 for (i
= 0; i
< 4; i
++) {
2738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2739 alu
.op
= ctx
->inst_info
->op
;
2743 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2745 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILL
) {
2746 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2749 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2754 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2759 /* kill must be last in ALU */
2760 ctx
->bc
->force_add_cf
= 1;
2761 ctx
->shader
->uses_kill
= TRUE
;
2765 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2767 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2768 struct r600_bytecode_alu alu
;
2771 /* tmp.x = max(src.y, 0.0) */
2772 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2773 alu
.op
= ALU_OP2_MAX
;
2774 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2775 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2776 alu
.src
[1].chan
= 1;
2778 alu
.dst
.sel
= ctx
->temp_reg
;
2783 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2787 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2793 if (ctx
->bc
->chip_class
== CAYMAN
) {
2794 for (i
= 0; i
< 3; i
++) {
2795 /* tmp.z = log(tmp.x) */
2796 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2797 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2798 alu
.src
[0].sel
= ctx
->temp_reg
;
2799 alu
.src
[0].chan
= 0;
2800 alu
.dst
.sel
= ctx
->temp_reg
;
2808 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2813 /* tmp.z = log(tmp.x) */
2814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2815 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2816 alu
.src
[0].sel
= ctx
->temp_reg
;
2817 alu
.src
[0].chan
= 0;
2818 alu
.dst
.sel
= ctx
->temp_reg
;
2822 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2827 chan
= alu
.dst
.chan
;
2830 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2832 alu
.op
= ALU_OP3_MUL_LIT
;
2833 alu
.src
[0].sel
= sel
;
2834 alu
.src
[0].chan
= chan
;
2835 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2836 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2837 alu
.dst
.sel
= ctx
->temp_reg
;
2842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2846 if (ctx
->bc
->chip_class
== CAYMAN
) {
2847 for (i
= 0; i
< 3; i
++) {
2848 /* dst.z = exp(tmp.x) */
2849 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2850 alu
.op
= ALU_OP1_EXP_IEEE
;
2851 alu
.src
[0].sel
= ctx
->temp_reg
;
2852 alu
.src
[0].chan
= 0;
2853 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2859 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2864 /* dst.z = exp(tmp.x) */
2865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2866 alu
.op
= ALU_OP1_EXP_IEEE
;
2867 alu
.src
[0].sel
= ctx
->temp_reg
;
2868 alu
.src
[0].chan
= 0;
2869 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2878 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2879 alu
.op
= ALU_OP1_MOV
;
2880 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2881 alu
.src
[0].chan
= 0;
2882 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2883 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2884 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2888 /* dst.y = max(src.x, 0.0) */
2889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2890 alu
.op
= ALU_OP2_MAX
;
2891 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2892 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2893 alu
.src
[1].chan
= 0;
2894 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2895 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2896 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2901 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2902 alu
.op
= ALU_OP1_MOV
;
2903 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2904 alu
.src
[0].chan
= 0;
2905 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2906 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2908 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2915 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2917 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2918 struct r600_bytecode_alu alu
;
2921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2924 * For state trackers other than OpenGL, we'll want to use
2925 * _RECIPSQRT_IEEE instead.
2927 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2929 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2930 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2931 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2933 alu
.dst
.sel
= ctx
->temp_reg
;
2936 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2939 /* replicate result */
2940 return tgsi_helper_tempx_replicate(ctx
);
2943 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2945 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2946 struct r600_bytecode_alu alu
;
2949 for (i
= 0; i
< 4; i
++) {
2950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2951 alu
.src
[0].sel
= ctx
->temp_reg
;
2952 alu
.op
= ALU_OP1_MOV
;
2954 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2955 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2965 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2967 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2968 struct r600_bytecode_alu alu
;
2971 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2972 alu
.op
= ctx
->inst_info
->op
;
2973 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2974 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2976 alu
.dst
.sel
= ctx
->temp_reg
;
2979 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2982 /* replicate result */
2983 return tgsi_helper_tempx_replicate(ctx
);
2986 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2988 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2990 struct r600_bytecode_alu alu
;
2991 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2993 for (i
= 0; i
< 3; i
++) {
2994 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2995 alu
.op
= ALU_OP1_LOG_IEEE
;
2996 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2997 alu
.dst
.sel
= ctx
->temp_reg
;
3002 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3008 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3009 alu
.op
= ALU_OP2_MUL
;
3010 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
3011 alu
.src
[1].sel
= ctx
->temp_reg
;
3012 alu
.dst
.sel
= ctx
->temp_reg
;
3015 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3019 for (i
= 0; i
< last_slot
; i
++) {
3020 /* POW(a,b) = EXP2(b * LOG2(a))*/
3021 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3022 alu
.op
= ALU_OP1_EXP_IEEE
;
3023 alu
.src
[0].sel
= ctx
->temp_reg
;
3025 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3026 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3027 if (i
== last_slot
- 1)
3029 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3036 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
3038 struct r600_bytecode_alu alu
;
3042 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3043 alu
.op
= ALU_OP1_LOG_IEEE
;
3044 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3045 alu
.dst
.sel
= ctx
->temp_reg
;
3048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3052 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3053 alu
.op
= ALU_OP2_MUL
;
3054 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
3055 alu
.src
[1].sel
= ctx
->temp_reg
;
3056 alu
.dst
.sel
= ctx
->temp_reg
;
3059 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3062 /* POW(a,b) = EXP2(b * LOG2(a))*/
3063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3064 alu
.op
= ALU_OP1_EXP_IEEE
;
3065 alu
.src
[0].sel
= ctx
->temp_reg
;
3066 alu
.dst
.sel
= ctx
->temp_reg
;
3069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3072 return tgsi_helper_tempx_replicate(ctx
);
3075 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
3077 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3078 struct r600_bytecode_alu alu
;
3080 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3081 int tmp0
= ctx
->temp_reg
;
3082 int tmp1
= r600_get_temp(ctx
);
3083 int tmp2
= r600_get_temp(ctx
);
3084 int tmp3
= r600_get_temp(ctx
);
3087 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
3089 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
3090 * 2. tmp0.z = lo (tmp0.x * src2)
3091 * 3. tmp0.w = -tmp0.z
3092 * 4. tmp0.y = hi (tmp0.x * src2)
3093 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
3094 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
3095 * 7. tmp1.x = tmp0.x - tmp0.w
3096 * 8. tmp1.y = tmp0.x + tmp0.w
3097 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
3098 * 10. tmp0.z = hi(tmp0.x * src1) = q
3099 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
3101 * 12. tmp0.w = src1 - tmp0.y = r
3102 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
3103 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
3107 * 15. tmp1.z = tmp0.z + 1 = q + 1
3108 * 16. tmp1.w = tmp0.z - 1 = q - 1
3112 * 15. tmp1.z = tmp0.w - src2 = r - src2
3113 * 16. tmp1.w = tmp0.w + src2 = r + src2
3117 * 17. tmp1.x = tmp1.x & tmp1.y
3119 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
3120 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
3122 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
3123 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
3127 * Same as unsigned, using abs values of the operands,
3128 * and fixing the sign of the result in the end.
3131 for (i
= 0; i
< 4; i
++) {
3132 if (!(write_mask
& (1<<i
)))
3137 /* tmp2.x = -src0 */
3138 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3139 alu
.op
= ALU_OP2_SUB_INT
;
3145 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3147 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3150 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3153 /* tmp2.y = -src1 */
3154 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3155 alu
.op
= ALU_OP2_SUB_INT
;
3161 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3163 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3166 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3169 /* tmp2.z sign bit is set if src0 and src2 signs are different */
3170 /* it will be a sign of the quotient */
3173 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3174 alu
.op
= ALU_OP2_XOR_INT
;
3180 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3181 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3184 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3188 /* tmp2.x = |src0| */
3189 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3190 alu
.op
= ALU_OP3_CNDGE_INT
;
3197 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3198 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3199 alu
.src
[2].sel
= tmp2
;
3200 alu
.src
[2].chan
= 0;
3203 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3206 /* tmp2.y = |src1| */
3207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3208 alu
.op
= ALU_OP3_CNDGE_INT
;
3215 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3216 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3217 alu
.src
[2].sel
= tmp2
;
3218 alu
.src
[2].chan
= 1;
3221 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3226 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
3227 if (ctx
->bc
->chip_class
== CAYMAN
) {
3228 /* tmp3.x = u2f(src2) */
3229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3230 alu
.op
= ALU_OP1_UINT_TO_FLT
;
3237 alu
.src
[0].sel
= tmp2
;
3238 alu
.src
[0].chan
= 1;
3240 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3244 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3247 /* tmp0.x = recip(tmp3.x) */
3248 for (j
= 0 ; j
< 3; j
++) {
3249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3250 alu
.op
= ALU_OP1_RECIP_IEEE
;
3254 alu
.dst
.write
= (j
== 0);
3256 alu
.src
[0].sel
= tmp3
;
3257 alu
.src
[0].chan
= 0;
3261 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3266 alu
.op
= ALU_OP2_MUL
;
3268 alu
.src
[0].sel
= tmp0
;
3269 alu
.src
[0].chan
= 0;
3271 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3272 alu
.src
[1].value
= 0x4f800000;
3277 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3281 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3282 alu
.op
= ALU_OP1_FLT_TO_UINT
;
3288 alu
.src
[0].sel
= tmp3
;
3289 alu
.src
[0].chan
= 0;
3292 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3297 alu
.op
= ALU_OP1_RECIP_UINT
;
3304 alu
.src
[0].sel
= tmp2
;
3305 alu
.src
[0].chan
= 1;
3307 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3311 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3315 /* 2. tmp0.z = lo (tmp0.x * src2) */
3316 if (ctx
->bc
->chip_class
== CAYMAN
) {
3317 for (j
= 0 ; j
< 4; j
++) {
3318 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3319 alu
.op
= ALU_OP2_MULLO_UINT
;
3323 alu
.dst
.write
= (j
== 2);
3325 alu
.src
[0].sel
= tmp0
;
3326 alu
.src
[0].chan
= 0;
3328 alu
.src
[1].sel
= tmp2
;
3329 alu
.src
[1].chan
= 1;
3331 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3334 alu
.last
= (j
== 3);
3335 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3339 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3340 alu
.op
= ALU_OP2_MULLO_UINT
;
3346 alu
.src
[0].sel
= tmp0
;
3347 alu
.src
[0].chan
= 0;
3349 alu
.src
[1].sel
= tmp2
;
3350 alu
.src
[1].chan
= 1;
3352 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3356 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3360 /* 3. tmp0.w = -tmp0.z */
3361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3362 alu
.op
= ALU_OP2_SUB_INT
;
3368 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3369 alu
.src
[1].sel
= tmp0
;
3370 alu
.src
[1].chan
= 2;
3373 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3376 /* 4. tmp0.y = hi (tmp0.x * src2) */
3377 if (ctx
->bc
->chip_class
== CAYMAN
) {
3378 for (j
= 0 ; j
< 4; j
++) {
3379 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3380 alu
.op
= ALU_OP2_MULHI_UINT
;
3384 alu
.dst
.write
= (j
== 1);
3386 alu
.src
[0].sel
= tmp0
;
3387 alu
.src
[0].chan
= 0;
3390 alu
.src
[1].sel
= tmp2
;
3391 alu
.src
[1].chan
= 1;
3393 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3395 alu
.last
= (j
== 3);
3396 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3400 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3401 alu
.op
= ALU_OP2_MULHI_UINT
;
3407 alu
.src
[0].sel
= tmp0
;
3408 alu
.src
[0].chan
= 0;
3411 alu
.src
[1].sel
= tmp2
;
3412 alu
.src
[1].chan
= 1;
3414 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3418 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3422 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3423 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3424 alu
.op
= ALU_OP3_CNDE_INT
;
3431 alu
.src
[0].sel
= tmp0
;
3432 alu
.src
[0].chan
= 1;
3433 alu
.src
[1].sel
= tmp0
;
3434 alu
.src
[1].chan
= 3;
3435 alu
.src
[2].sel
= tmp0
;
3436 alu
.src
[2].chan
= 2;
3439 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3442 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3443 if (ctx
->bc
->chip_class
== CAYMAN
) {
3444 for (j
= 0 ; j
< 4; j
++) {
3445 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3446 alu
.op
= ALU_OP2_MULHI_UINT
;
3450 alu
.dst
.write
= (j
== 3);
3452 alu
.src
[0].sel
= tmp0
;
3453 alu
.src
[0].chan
= 2;
3455 alu
.src
[1].sel
= tmp0
;
3456 alu
.src
[1].chan
= 0;
3458 alu
.last
= (j
== 3);
3459 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3463 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3464 alu
.op
= ALU_OP2_MULHI_UINT
;
3470 alu
.src
[0].sel
= tmp0
;
3471 alu
.src
[0].chan
= 2;
3473 alu
.src
[1].sel
= tmp0
;
3474 alu
.src
[1].chan
= 0;
3477 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3481 /* 7. tmp1.x = tmp0.x - tmp0.w */
3482 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3483 alu
.op
= ALU_OP2_SUB_INT
;
3489 alu
.src
[0].sel
= tmp0
;
3490 alu
.src
[0].chan
= 0;
3491 alu
.src
[1].sel
= tmp0
;
3492 alu
.src
[1].chan
= 3;
3495 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3498 /* 8. tmp1.y = tmp0.x + tmp0.w */
3499 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3500 alu
.op
= ALU_OP2_ADD_INT
;
3506 alu
.src
[0].sel
= tmp0
;
3507 alu
.src
[0].chan
= 0;
3508 alu
.src
[1].sel
= tmp0
;
3509 alu
.src
[1].chan
= 3;
3512 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3515 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3516 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3517 alu
.op
= ALU_OP3_CNDE_INT
;
3524 alu
.src
[0].sel
= tmp0
;
3525 alu
.src
[0].chan
= 1;
3526 alu
.src
[1].sel
= tmp1
;
3527 alu
.src
[1].chan
= 1;
3528 alu
.src
[2].sel
= tmp1
;
3529 alu
.src
[2].chan
= 0;
3532 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3535 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3536 if (ctx
->bc
->chip_class
== CAYMAN
) {
3537 for (j
= 0 ; j
< 4; j
++) {
3538 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3539 alu
.op
= ALU_OP2_MULHI_UINT
;
3543 alu
.dst
.write
= (j
== 2);
3545 alu
.src
[0].sel
= tmp0
;
3546 alu
.src
[0].chan
= 0;
3549 alu
.src
[1].sel
= tmp2
;
3550 alu
.src
[1].chan
= 0;
3552 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3555 alu
.last
= (j
== 3);
3556 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3560 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3561 alu
.op
= ALU_OP2_MULHI_UINT
;
3567 alu
.src
[0].sel
= tmp0
;
3568 alu
.src
[0].chan
= 0;
3571 alu
.src
[1].sel
= tmp2
;
3572 alu
.src
[1].chan
= 0;
3574 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3578 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3582 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3583 if (ctx
->bc
->chip_class
== CAYMAN
) {
3584 for (j
= 0 ; j
< 4; j
++) {
3585 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3586 alu
.op
= ALU_OP2_MULLO_UINT
;
3590 alu
.dst
.write
= (j
== 1);
3593 alu
.src
[0].sel
= tmp2
;
3594 alu
.src
[0].chan
= 1;
3596 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3599 alu
.src
[1].sel
= tmp0
;
3600 alu
.src
[1].chan
= 2;
3602 alu
.last
= (j
== 3);
3603 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3607 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3608 alu
.op
= ALU_OP2_MULLO_UINT
;
3615 alu
.src
[0].sel
= tmp2
;
3616 alu
.src
[0].chan
= 1;
3618 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3621 alu
.src
[1].sel
= tmp0
;
3622 alu
.src
[1].chan
= 2;
3625 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3629 /* 12. tmp0.w = src1 - tmp0.y = r */
3630 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3631 alu
.op
= ALU_OP2_SUB_INT
;
3638 alu
.src
[0].sel
= tmp2
;
3639 alu
.src
[0].chan
= 0;
3641 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3644 alu
.src
[1].sel
= tmp0
;
3645 alu
.src
[1].chan
= 1;
3648 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3651 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3652 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3653 alu
.op
= ALU_OP2_SETGE_UINT
;
3659 alu
.src
[0].sel
= tmp0
;
3660 alu
.src
[0].chan
= 3;
3662 alu
.src
[1].sel
= tmp2
;
3663 alu
.src
[1].chan
= 1;
3665 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3669 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3672 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3673 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3674 alu
.op
= ALU_OP2_SETGE_UINT
;
3681 alu
.src
[0].sel
= tmp2
;
3682 alu
.src
[0].chan
= 0;
3684 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3687 alu
.src
[1].sel
= tmp0
;
3688 alu
.src
[1].chan
= 1;
3691 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3694 if (mod
) { /* UMOD */
3696 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3697 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3698 alu
.op
= ALU_OP2_SUB_INT
;
3704 alu
.src
[0].sel
= tmp0
;
3705 alu
.src
[0].chan
= 3;
3708 alu
.src
[1].sel
= tmp2
;
3709 alu
.src
[1].chan
= 1;
3711 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3715 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3718 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3719 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3720 alu
.op
= ALU_OP2_ADD_INT
;
3726 alu
.src
[0].sel
= tmp0
;
3727 alu
.src
[0].chan
= 3;
3729 alu
.src
[1].sel
= tmp2
;
3730 alu
.src
[1].chan
= 1;
3732 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3736 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3741 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3742 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3743 alu
.op
= ALU_OP2_ADD_INT
;
3749 alu
.src
[0].sel
= tmp0
;
3750 alu
.src
[0].chan
= 2;
3751 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3754 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3757 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3758 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3759 alu
.op
= ALU_OP2_ADD_INT
;
3765 alu
.src
[0].sel
= tmp0
;
3766 alu
.src
[0].chan
= 2;
3767 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3770 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3775 /* 17. tmp1.x = tmp1.x & tmp1.y */
3776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3777 alu
.op
= ALU_OP2_AND_INT
;
3783 alu
.src
[0].sel
= tmp1
;
3784 alu
.src
[0].chan
= 0;
3785 alu
.src
[1].sel
= tmp1
;
3786 alu
.src
[1].chan
= 1;
3789 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3792 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3793 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3794 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3795 alu
.op
= ALU_OP3_CNDE_INT
;
3802 alu
.src
[0].sel
= tmp1
;
3803 alu
.src
[0].chan
= 0;
3804 alu
.src
[1].sel
= tmp0
;
3805 alu
.src
[1].chan
= mod
? 3 : 2;
3806 alu
.src
[2].sel
= tmp1
;
3807 alu
.src
[2].chan
= 2;
3810 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3813 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3815 alu
.op
= ALU_OP3_CNDE_INT
;
3823 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3826 alu
.src
[0].sel
= tmp1
;
3827 alu
.src
[0].chan
= 1;
3828 alu
.src
[1].sel
= tmp1
;
3829 alu
.src
[1].chan
= 3;
3830 alu
.src
[2].sel
= tmp0
;
3831 alu
.src
[2].chan
= 2;
3834 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3839 /* fix the sign of the result */
3843 /* tmp0.x = -tmp0.z */
3844 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3845 alu
.op
= ALU_OP2_SUB_INT
;
3851 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3852 alu
.src
[1].sel
= tmp0
;
3853 alu
.src
[1].chan
= 2;
3856 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3859 /* sign of the remainder is the same as the sign of src0 */
3860 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3861 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3862 alu
.op
= ALU_OP3_CNDGE_INT
;
3865 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3867 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3868 alu
.src
[1].sel
= tmp0
;
3869 alu
.src
[1].chan
= 2;
3870 alu
.src
[2].sel
= tmp0
;
3871 alu
.src
[2].chan
= 0;
3874 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3879 /* tmp0.x = -tmp0.z */
3880 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3881 alu
.op
= ALU_OP2_SUB_INT
;
3887 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3888 alu
.src
[1].sel
= tmp0
;
3889 alu
.src
[1].chan
= 2;
3892 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3895 /* fix the quotient sign (same as the sign of src0*src1) */
3896 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3897 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3898 alu
.op
= ALU_OP3_CNDGE_INT
;
3901 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3903 alu
.src
[0].sel
= tmp2
;
3904 alu
.src
[0].chan
= 2;
3905 alu
.src
[1].sel
= tmp0
;
3906 alu
.src
[1].chan
= 2;
3907 alu
.src
[2].sel
= tmp0
;
3908 alu
.src
[2].chan
= 0;
3911 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3919 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3921 return tgsi_divmod(ctx
, 0, 0);
3924 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3926 return tgsi_divmod(ctx
, 1, 0);
3929 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3931 return tgsi_divmod(ctx
, 0, 1);
3934 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3936 return tgsi_divmod(ctx
, 1, 1);
3940 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3942 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3943 struct r600_bytecode_alu alu
;
3945 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3946 int last_inst
= tgsi_last_instruction(write_mask
);
3948 for (i
= 0; i
< 4; i
++) {
3949 if (!(write_mask
& (1<<i
)))
3952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3953 alu
.op
= ALU_OP1_TRUNC
;
3955 alu
.dst
.sel
= ctx
->temp_reg
;
3959 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3967 for (i
= 0; i
< 4; i
++) {
3968 if (!(write_mask
& (1<<i
)))
3971 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3972 alu
.op
= ctx
->inst_info
->op
;
3974 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3976 alu
.src
[0].sel
= ctx
->temp_reg
;
3977 alu
.src
[0].chan
= i
;
3979 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3981 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3989 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3991 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3992 struct r600_bytecode_alu alu
;
3994 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3995 int last_inst
= tgsi_last_instruction(write_mask
);
3998 for (i
= 0; i
< 4; i
++) {
3999 if (!(write_mask
& (1<<i
)))
4002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4003 alu
.op
= ALU_OP2_SUB_INT
;
4005 alu
.dst
.sel
= ctx
->temp_reg
;
4009 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4010 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4019 /* dst = (src >= 0 ? src : tmp) */
4020 for (i
= 0; i
< 4; i
++) {
4021 if (!(write_mask
& (1<<i
)))
4024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4025 alu
.op
= ALU_OP3_CNDGE_INT
;
4029 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4031 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4032 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4033 alu
.src
[2].sel
= ctx
->temp_reg
;
4034 alu
.src
[2].chan
= i
;
4038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4045 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
4047 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4048 struct r600_bytecode_alu alu
;
4050 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4051 int last_inst
= tgsi_last_instruction(write_mask
);
4053 /* tmp = (src >= 0 ? src : -1) */
4054 for (i
= 0; i
< 4; i
++) {
4055 if (!(write_mask
& (1<<i
)))
4058 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4059 alu
.op
= ALU_OP3_CNDGE_INT
;
4062 alu
.dst
.sel
= ctx
->temp_reg
;
4066 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4067 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4068 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
4072 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4077 /* dst = (tmp > 0 ? 1 : tmp) */
4078 for (i
= 0; i
< 4; i
++) {
4079 if (!(write_mask
& (1<<i
)))
4082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4083 alu
.op
= ALU_OP3_CNDGT_INT
;
4087 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4089 alu
.src
[0].sel
= ctx
->temp_reg
;
4090 alu
.src
[0].chan
= i
;
4092 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
4094 alu
.src
[2].sel
= ctx
->temp_reg
;
4095 alu
.src
[2].chan
= i
;
4099 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4108 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
4110 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4111 struct r600_bytecode_alu alu
;
4114 /* tmp = (src > 0 ? 1 : src) */
4115 for (i
= 0; i
< 4; i
++) {
4116 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4117 alu
.op
= ALU_OP3_CNDGT
;
4120 alu
.dst
.sel
= ctx
->temp_reg
;
4123 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4124 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4125 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
4129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4134 /* dst = (-tmp > 0 ? -1 : tmp) */
4135 for (i
= 0; i
< 4; i
++) {
4136 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4137 alu
.op
= ALU_OP3_CNDGT
;
4139 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4141 alu
.src
[0].sel
= ctx
->temp_reg
;
4142 alu
.src
[0].chan
= i
;
4145 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4148 alu
.src
[2].sel
= ctx
->temp_reg
;
4149 alu
.src
[2].chan
= i
;
4153 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4160 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
4162 struct r600_bytecode_alu alu
;
4165 for (i
= 0; i
< 4; i
++) {
4166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4167 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
4168 alu
.op
= ALU_OP0_NOP
;
4171 alu
.op
= ALU_OP1_MOV
;
4172 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4173 alu
.src
[0].sel
= ctx
->temp_reg
;
4174 alu
.src
[0].chan
= i
;
4179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4186 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
4188 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4189 struct r600_bytecode_alu alu
;
4191 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4193 for (i
= 0; i
< lasti
+ 1; i
++) {
4194 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4198 alu
.op
= ctx
->inst_info
->op
;
4199 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4200 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4203 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4210 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4217 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
4219 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4220 struct r600_bytecode_alu alu
;
4223 for (i
= 0; i
< 4; i
++) {
4224 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4225 alu
.op
= ctx
->inst_info
->op
;
4226 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4227 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4230 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4232 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4233 /* handle some special cases */
4234 switch (ctx
->inst_info
->tgsi_opcode
) {
4235 case TGSI_OPCODE_DP2
:
4237 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4238 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4241 case TGSI_OPCODE_DP3
:
4243 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4244 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4247 case TGSI_OPCODE_DPH
:
4249 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4250 alu
.src
[0].chan
= 0;
4260 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4267 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
4270 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4271 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
4272 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
4273 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
4274 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
4277 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
4280 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4281 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
4284 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
4286 struct r600_bytecode_vtx vtx
;
4287 struct r600_bytecode_alu alu
;
4288 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4290 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4292 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4293 if (src_requires_loading
) {
4294 for (i
= 0; i
< 4; i
++) {
4295 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4296 alu
.op
= ALU_OP1_MOV
;
4297 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4298 alu
.dst
.sel
= ctx
->temp_reg
;
4303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4307 src_gpr
= ctx
->temp_reg
;
4310 memset(&vtx
, 0, sizeof(vtx
));
4311 vtx
.op
= FETCH_OP_VFETCH
;
4312 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
4313 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
4314 vtx
.src_gpr
= src_gpr
;
4315 vtx
.mega_fetch_count
= 16;
4316 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4317 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
4318 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
4319 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4320 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4321 vtx
.use_const_fields
= 1;
4322 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4324 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4327 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4330 for (i
= 0; i
< 4; i
++) {
4331 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4332 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4335 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4336 alu
.op
= ALU_OP2_AND_INT
;
4339 alu
.dst
.sel
= vtx
.dst_gpr
;
4342 alu
.src
[0].sel
= vtx
.dst_gpr
;
4343 alu
.src
[0].chan
= i
;
4345 alu
.src
[1].sel
= 512 + (id
* 2);
4346 alu
.src
[1].chan
= i
% 4;
4347 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4356 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4357 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4358 alu
.op
= ALU_OP2_OR_INT
;
4361 alu
.dst
.sel
= vtx
.dst_gpr
;
4364 alu
.src
[0].sel
= vtx
.dst_gpr
;
4365 alu
.src
[0].chan
= 3;
4367 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4368 alu
.src
[1].chan
= 0;
4369 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4372 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4379 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4381 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4382 struct r600_bytecode_alu alu
;
4384 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4386 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4387 alu
.op
= ALU_OP1_MOV
;
4389 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4390 alu
.src
[0].sel
= 512 + (id
/ 4);
4391 alu
.src
[0].chan
= id
% 4;
4393 /* r600 we have them at channel 2 of the second dword */
4394 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4395 alu
.src
[0].chan
= 1;
4397 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4398 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4400 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4406 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4408 static float one_point_five
= 1.5f
;
4409 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4410 struct r600_bytecode_tex tex
;
4411 struct r600_bytecode_alu alu
;
4415 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
4416 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4417 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4418 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4420 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
4421 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4422 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
4424 /* Texture fetch instructions can only use gprs as source.
4425 * Also they cannot negate the source or take the absolute value */
4426 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4427 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4428 read_compressed_msaa
|| txf_add_offsets
;
4430 boolean src_loaded
= FALSE
;
4431 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4432 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4433 boolean has_txq_cube_array_z
= false;
4435 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4436 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4437 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4438 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4439 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4440 has_txq_cube_array_z
= true;
4443 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4444 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4445 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4446 sampler_src_reg
= 2;
4448 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4450 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4451 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4452 ctx
->shader
->uses_tex_buffers
= true;
4453 return r600_do_buffer_txq(ctx
);
4455 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4456 if (ctx
->bc
->chip_class
< EVERGREEN
)
4457 ctx
->shader
->uses_tex_buffers
= true;
4458 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4462 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4463 /* TGSI moves the sampler to src reg 3 for TXD */
4464 sampler_src_reg
= 3;
4466 for (i
= 1; i
< 3; i
++) {
4467 /* set gradients h/v */
4468 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4469 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4470 FETCH_OP_SET_GRADIENTS_V
;
4471 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4472 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4474 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4475 tex
.src_gpr
= r600_get_temp(ctx
);
4481 for (j
= 0; j
< 4; j
++) {
4482 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4483 alu
.op
= ALU_OP1_MOV
;
4484 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4485 alu
.dst
.sel
= tex
.src_gpr
;
4490 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4496 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4497 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4498 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4499 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4500 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4501 tex
.src_rel
= ctx
->src
[i
].rel
;
4503 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4504 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4505 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4506 tex
.coord_type_x
= 1;
4507 tex
.coord_type_y
= 1;
4508 tex
.coord_type_z
= 1;
4509 tex
.coord_type_w
= 1;
4511 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4515 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4517 /* Add perspective divide */
4518 if (ctx
->bc
->chip_class
== CAYMAN
) {
4520 for (i
= 0; i
< 3; i
++) {
4521 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4522 alu
.op
= ALU_OP1_RECIP_IEEE
;
4523 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4525 alu
.dst
.sel
= ctx
->temp_reg
;
4531 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4538 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4539 alu
.op
= ALU_OP1_RECIP_IEEE
;
4540 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4542 alu
.dst
.sel
= ctx
->temp_reg
;
4543 alu
.dst
.chan
= out_chan
;
4546 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4551 for (i
= 0; i
< 3; i
++) {
4552 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4553 alu
.op
= ALU_OP2_MUL
;
4554 alu
.src
[0].sel
= ctx
->temp_reg
;
4555 alu
.src
[0].chan
= out_chan
;
4556 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4557 alu
.dst
.sel
= ctx
->temp_reg
;
4560 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4565 alu
.op
= ALU_OP1_MOV
;
4566 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4567 alu
.src
[0].chan
= 0;
4568 alu
.dst
.sel
= ctx
->temp_reg
;
4572 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4576 src_gpr
= ctx
->temp_reg
;
4579 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4580 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4581 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4582 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4583 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4584 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4586 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4587 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4589 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4590 for (i
= 0; i
< 4; i
++) {
4591 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4592 alu
.op
= ALU_OP2_CUBE
;
4593 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4594 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4595 alu
.dst
.sel
= ctx
->temp_reg
;
4600 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4605 /* tmp1.z = RCP_e(|tmp1.z|) */
4606 if (ctx
->bc
->chip_class
== CAYMAN
) {
4607 for (i
= 0; i
< 3; i
++) {
4608 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4609 alu
.op
= ALU_OP1_RECIP_IEEE
;
4610 alu
.src
[0].sel
= ctx
->temp_reg
;
4611 alu
.src
[0].chan
= 2;
4613 alu
.dst
.sel
= ctx
->temp_reg
;
4619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4624 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4625 alu
.op
= ALU_OP1_RECIP_IEEE
;
4626 alu
.src
[0].sel
= ctx
->temp_reg
;
4627 alu
.src
[0].chan
= 2;
4629 alu
.dst
.sel
= ctx
->temp_reg
;
4633 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4638 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4639 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4640 * muladd has no writemask, have to use another temp
4642 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4643 alu
.op
= ALU_OP3_MULADD
;
4646 alu
.src
[0].sel
= ctx
->temp_reg
;
4647 alu
.src
[0].chan
= 0;
4648 alu
.src
[1].sel
= ctx
->temp_reg
;
4649 alu
.src
[1].chan
= 2;
4651 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4652 alu
.src
[2].chan
= 0;
4653 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4655 alu
.dst
.sel
= ctx
->temp_reg
;
4659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4663 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4664 alu
.op
= ALU_OP3_MULADD
;
4667 alu
.src
[0].sel
= ctx
->temp_reg
;
4668 alu
.src
[0].chan
= 1;
4669 alu
.src
[1].sel
= ctx
->temp_reg
;
4670 alu
.src
[1].chan
= 2;
4672 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4673 alu
.src
[2].chan
= 0;
4674 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4676 alu
.dst
.sel
= ctx
->temp_reg
;
4681 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4684 /* write initial compare value into Z component
4685 - W src 0 for shadow cube
4686 - X src 1 for shadow cube array */
4687 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4688 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4689 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4690 alu
.op
= ALU_OP1_MOV
;
4691 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4692 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4694 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4695 alu
.dst
.sel
= ctx
->temp_reg
;
4699 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4704 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4705 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4706 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4707 int mytmp
= r600_get_temp(ctx
);
4708 static const float eight
= 8.0f
;
4709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4710 alu
.op
= ALU_OP1_MOV
;
4711 alu
.src
[0].sel
= ctx
->temp_reg
;
4712 alu
.src
[0].chan
= 3;
4713 alu
.dst
.sel
= mytmp
;
4717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4721 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4722 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4723 alu
.op
= ALU_OP3_MULADD
;
4725 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4726 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4727 alu
.src
[1].chan
= 0;
4728 alu
.src
[1].value
= *(uint32_t *)&eight
;
4729 alu
.src
[2].sel
= mytmp
;
4730 alu
.src
[2].chan
= 0;
4731 alu
.dst
.sel
= ctx
->temp_reg
;
4735 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4738 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4739 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4740 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4741 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4742 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4743 tex
.src_gpr
= r600_get_temp(ctx
);
4748 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4749 tex
.coord_type_x
= 1;
4750 tex
.coord_type_y
= 1;
4751 tex
.coord_type_z
= 1;
4752 tex
.coord_type_w
= 1;
4753 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4754 alu
.op
= ALU_OP1_MOV
;
4755 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4756 alu
.dst
.sel
= tex
.src_gpr
;
4760 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4764 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4771 /* for cube forms of lod and bias we need to route things */
4772 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4773 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4774 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4775 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4777 alu
.op
= ALU_OP1_MOV
;
4778 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4779 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4780 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4782 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4783 alu
.dst
.sel
= ctx
->temp_reg
;
4787 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4793 src_gpr
= ctx
->temp_reg
;
4796 if (src_requires_loading
&& !src_loaded
) {
4797 for (i
= 0; i
< 4; i
++) {
4798 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4799 alu
.op
= ALU_OP1_MOV
;
4800 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4801 alu
.dst
.sel
= ctx
->temp_reg
;
4806 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4811 src_gpr
= ctx
->temp_reg
;
4814 /* get offset values */
4815 if (inst
->Texture
.NumOffsets
) {
4816 assert(inst
->Texture
.NumOffsets
== 1);
4818 /* The texture offset feature doesn't work with the TXF instruction
4819 * and must be emulated by adding the offset to the texture coordinates. */
4820 if (txf_add_offsets
) {
4821 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
4823 switch (inst
->Texture
.Texture
) {
4824 case TGSI_TEXTURE_3D
:
4825 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4826 alu
.op
= ALU_OP2_ADD_INT
;
4827 alu
.src
[0].sel
= src_gpr
;
4828 alu
.src
[0].chan
= 2;
4829 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4830 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
4831 alu
.dst
.sel
= src_gpr
;
4835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4840 case TGSI_TEXTURE_2D
:
4841 case TGSI_TEXTURE_SHADOW2D
:
4842 case TGSI_TEXTURE_RECT
:
4843 case TGSI_TEXTURE_SHADOWRECT
:
4844 case TGSI_TEXTURE_2D_ARRAY
:
4845 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
4846 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4847 alu
.op
= ALU_OP2_ADD_INT
;
4848 alu
.src
[0].sel
= src_gpr
;
4849 alu
.src
[0].chan
= 1;
4850 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4851 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
4852 alu
.dst
.sel
= src_gpr
;
4856 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4861 case TGSI_TEXTURE_1D
:
4862 case TGSI_TEXTURE_SHADOW1D
:
4863 case TGSI_TEXTURE_1D_ARRAY
:
4864 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
4865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4866 alu
.op
= ALU_OP2_ADD_INT
;
4867 alu
.src
[0].sel
= src_gpr
;
4868 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4869 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
4870 alu
.dst
.sel
= src_gpr
;
4873 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4877 /* texture offsets do not apply to other texture targets */
4880 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4881 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4882 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4886 /* Obtain the sample index for reading a compressed MSAA color texture.
4887 * To read the FMASK, we use the ldfptr instruction, which tells us
4888 * where the samples are stored.
4889 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4890 * which is the identity mapping. Each nibble says which physical sample
4891 * should be fetched to get that sample.
4893 * Assume src.z contains the sample index. It should be modified like this:
4894 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4895 * Then fetch the texel with src.
4897 if (read_compressed_msaa
) {
4898 unsigned sample_chan
= 3;
4899 unsigned temp
= r600_get_temp(ctx
);
4902 /* temp.w = ldfptr() */
4903 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4904 tex
.op
= FETCH_OP_LD
;
4905 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4906 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4907 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4908 tex
.src_gpr
= src_gpr
;
4910 tex
.dst_sel_x
= 7; /* mask out these components */
4913 tex
.dst_sel_w
= 0; /* store X */
4918 tex
.offset_x
= offset_x
;
4919 tex
.offset_y
= offset_y
;
4920 tex
.offset_z
= offset_z
;
4921 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4925 /* temp.x = sample_index*4 */
4926 if (ctx
->bc
->chip_class
== CAYMAN
) {
4927 for (i
= 0 ; i
< 4; i
++) {
4928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4929 alu
.op
= ALU_OP2_MULLO_INT
;
4930 alu
.src
[0].sel
= src_gpr
;
4931 alu
.src
[0].chan
= sample_chan
;
4932 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4933 alu
.src
[1].value
= 4;
4936 alu
.dst
.write
= i
== 0;
4939 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4945 alu
.op
= ALU_OP2_MULLO_INT
;
4946 alu
.src
[0].sel
= src_gpr
;
4947 alu
.src
[0].chan
= sample_chan
;
4948 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4949 alu
.src
[1].value
= 4;
4954 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4959 /* sample_index = temp.w >> temp.x */
4960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4961 alu
.op
= ALU_OP2_LSHR_INT
;
4962 alu
.src
[0].sel
= temp
;
4963 alu
.src
[0].chan
= 3;
4964 alu
.src
[1].sel
= temp
;
4965 alu
.src
[1].chan
= 0;
4966 alu
.dst
.sel
= src_gpr
;
4967 alu
.dst
.chan
= sample_chan
;
4970 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4974 /* sample_index & 0xF */
4975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4976 alu
.op
= ALU_OP2_AND_INT
;
4977 alu
.src
[0].sel
= src_gpr
;
4978 alu
.src
[0].chan
= sample_chan
;
4979 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4980 alu
.src
[1].value
= 0xF;
4981 alu
.dst
.sel
= src_gpr
;
4982 alu
.dst
.chan
= sample_chan
;
4985 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4989 /* visualize the FMASK */
4990 for (i
= 0; i
< 4; i
++) {
4991 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4992 alu
.op
= ALU_OP1_INT_TO_FLT
;
4993 alu
.src
[0].sel
= src_gpr
;
4994 alu
.src
[0].chan
= sample_chan
;
4995 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4999 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5007 /* does this shader want a num layers from TXQ for a cube array? */
5008 if (has_txq_cube_array_z
) {
5009 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
5011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5012 alu
.op
= ALU_OP1_MOV
;
5014 alu
.src
[0].sel
= 512 + (id
/ 4);
5015 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
5016 alu
.src
[0].chan
= id
% 4;
5017 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5022 /* disable writemask from texture instruction */
5023 inst
->Dst
[0].Register
.WriteMask
&= ~4;
5026 opcode
= ctx
->inst_info
->op
;
5027 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
5028 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
5029 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
5030 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5031 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
5032 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
5033 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
5035 case FETCH_OP_SAMPLE
:
5036 opcode
= FETCH_OP_SAMPLE_C
;
5038 case FETCH_OP_SAMPLE_L
:
5039 opcode
= FETCH_OP_SAMPLE_C_L
;
5041 case FETCH_OP_SAMPLE_LB
:
5042 opcode
= FETCH_OP_SAMPLE_C_LB
;
5044 case FETCH_OP_SAMPLE_G
:
5045 opcode
= FETCH_OP_SAMPLE_C_G
;
5050 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
5053 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
5054 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
5055 tex
.src_gpr
= src_gpr
;
5056 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
5057 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
5058 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
5059 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
5060 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
5062 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
5067 } else if (src_loaded
) {
5073 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
5074 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
5075 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
5076 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
5077 tex
.src_rel
= ctx
->src
[0].rel
;
5080 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
5081 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5082 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5083 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
5087 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
5090 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
5091 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
5092 tex
.coord_type_x
= 1;
5093 tex
.coord_type_y
= 1;
5095 tex
.coord_type_z
= 1;
5096 tex
.coord_type_w
= 1;
5098 tex
.offset_x
= offset_x
;
5099 tex
.offset_y
= offset_y
;
5100 tex
.offset_z
= offset_z
;
5102 /* Put the depth for comparison in W.
5103 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
5104 * Some instructions expect the depth in Z. */
5105 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
5106 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
5107 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
5108 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
5109 opcode
!= FETCH_OP_SAMPLE_C_L
&&
5110 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
5111 tex
.src_sel_w
= tex
.src_sel_z
;
5114 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
5115 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
5116 if (opcode
== FETCH_OP_SAMPLE_C_L
||
5117 opcode
== FETCH_OP_SAMPLE_C_LB
) {
5118 /* the array index is read from Y */
5119 tex
.coord_type_y
= 0;
5121 /* the array index is read from Z */
5122 tex
.coord_type_z
= 0;
5123 tex
.src_sel_z
= tex
.src_sel_y
;
5125 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
5126 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
5127 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5128 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
5129 (ctx
->bc
->chip_class
>= EVERGREEN
)))
5130 /* the array index is read from Z */
5131 tex
.coord_type_z
= 0;
5133 /* mask unused source components */
5134 if (opcode
== FETCH_OP_SAMPLE
) {
5135 switch (inst
->Texture
.Texture
) {
5136 case TGSI_TEXTURE_2D
:
5137 case TGSI_TEXTURE_RECT
:
5141 case TGSI_TEXTURE_1D_ARRAY
:
5145 case TGSI_TEXTURE_1D
:
5153 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
5157 /* add shadow ambient support - gallium doesn't do it yet */
5161 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
5163 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5164 struct r600_bytecode_alu alu
;
5165 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5169 /* optimize if it's just an equal balance */
5170 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
5171 for (i
= 0; i
< lasti
+ 1; i
++) {
5172 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5175 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5176 alu
.op
= ALU_OP2_ADD
;
5177 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5178 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5180 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5185 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5193 for (i
= 0; i
< lasti
+ 1; i
++) {
5194 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5198 alu
.op
= ALU_OP2_ADD
;
5199 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5200 alu
.src
[0].chan
= 0;
5201 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5202 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
5203 alu
.dst
.sel
= ctx
->temp_reg
;
5209 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5214 /* (1 - src0) * src2 */
5215 for (i
= 0; i
< lasti
+ 1; i
++) {
5216 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5220 alu
.op
= ALU_OP2_MUL
;
5221 alu
.src
[0].sel
= ctx
->temp_reg
;
5222 alu
.src
[0].chan
= i
;
5223 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5224 alu
.dst
.sel
= ctx
->temp_reg
;
5230 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5235 /* src0 * src1 + (1 - src0) * src2 */
5236 for (i
= 0; i
< lasti
+ 1; i
++) {
5237 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5241 alu
.op
= ALU_OP3_MULADD
;
5243 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5244 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5245 alu
.src
[2].sel
= ctx
->temp_reg
;
5246 alu
.src
[2].chan
= i
;
5248 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5260 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
5262 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5263 struct r600_bytecode_alu alu
;
5265 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5267 for (i
= 0; i
< lasti
+ 1; i
++) {
5268 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5272 alu
.op
= ALU_OP3_CNDGE
;
5273 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5274 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5275 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
5276 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5282 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5289 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
5291 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5292 struct r600_bytecode_alu alu
;
5294 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5296 for (i
= 0; i
< lasti
+ 1; i
++) {
5297 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5301 alu
.op
= ALU_OP3_CNDGE_INT
;
5302 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5303 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5304 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
5305 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5311 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5318 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
5320 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5321 static const unsigned int src0_swizzle
[] = {2, 0, 1};
5322 static const unsigned int src1_swizzle
[] = {1, 2, 0};
5323 struct r600_bytecode_alu alu
;
5324 uint32_t use_temp
= 0;
5327 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
5330 for (i
= 0; i
< 4; i
++) {
5331 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5332 alu
.op
= ALU_OP2_MUL
;
5334 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5335 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
5337 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5338 alu
.src
[0].chan
= i
;
5339 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5340 alu
.src
[1].chan
= i
;
5343 alu
.dst
.sel
= ctx
->temp_reg
;
5349 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5354 for (i
= 0; i
< 4; i
++) {
5355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5356 alu
.op
= ALU_OP3_MULADD
;
5359 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
5360 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
5362 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5363 alu
.src
[0].chan
= i
;
5364 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5365 alu
.src
[1].chan
= i
;
5368 alu
.src
[2].sel
= ctx
->temp_reg
;
5370 alu
.src
[2].chan
= i
;
5373 alu
.dst
.sel
= ctx
->temp_reg
;
5375 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5381 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5386 return tgsi_helper_copy(ctx
, inst
);
5390 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
5392 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5393 struct r600_bytecode_alu alu
;
5397 /* result.x = 2^floor(src); */
5398 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5399 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5401 alu
.op
= ALU_OP1_FLOOR
;
5402 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5404 alu
.dst
.sel
= ctx
->temp_reg
;
5408 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5412 if (ctx
->bc
->chip_class
== CAYMAN
) {
5413 for (i
= 0; i
< 3; i
++) {
5414 alu
.op
= ALU_OP1_EXP_IEEE
;
5415 alu
.src
[0].sel
= ctx
->temp_reg
;
5416 alu
.src
[0].chan
= 0;
5418 alu
.dst
.sel
= ctx
->temp_reg
;
5420 alu
.dst
.write
= i
== 0;
5422 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5427 alu
.op
= ALU_OP1_EXP_IEEE
;
5428 alu
.src
[0].sel
= ctx
->temp_reg
;
5429 alu
.src
[0].chan
= 0;
5431 alu
.dst
.sel
= ctx
->temp_reg
;
5435 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5441 /* result.y = tmp - floor(tmp); */
5442 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5445 alu
.op
= ALU_OP1_FRACT
;
5446 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5448 alu
.dst
.sel
= ctx
->temp_reg
;
5450 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5459 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5464 /* result.z = RoughApprox2ToX(tmp);*/
5465 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5466 if (ctx
->bc
->chip_class
== CAYMAN
) {
5467 for (i
= 0; i
< 3; i
++) {
5468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5469 alu
.op
= ALU_OP1_EXP_IEEE
;
5470 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5472 alu
.dst
.sel
= ctx
->temp_reg
;
5479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5484 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5485 alu
.op
= ALU_OP1_EXP_IEEE
;
5486 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5488 alu
.dst
.sel
= ctx
->temp_reg
;
5494 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5500 /* result.w = 1.0;*/
5501 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5502 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5504 alu
.op
= ALU_OP1_MOV
;
5505 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5506 alu
.src
[0].chan
= 0;
5508 alu
.dst
.sel
= ctx
->temp_reg
;
5512 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5516 return tgsi_helper_copy(ctx
, inst
);
5519 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5521 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5522 struct r600_bytecode_alu alu
;
5526 /* result.x = floor(log2(|src|)); */
5527 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5528 if (ctx
->bc
->chip_class
== CAYMAN
) {
5529 for (i
= 0; i
< 3; i
++) {
5530 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5532 alu
.op
= ALU_OP1_LOG_IEEE
;
5533 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5534 r600_bytecode_src_set_abs(&alu
.src
[0]);
5536 alu
.dst
.sel
= ctx
->temp_reg
;
5542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5550 alu
.op
= ALU_OP1_LOG_IEEE
;
5551 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5552 r600_bytecode_src_set_abs(&alu
.src
[0]);
5554 alu
.dst
.sel
= ctx
->temp_reg
;
5558 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5563 alu
.op
= ALU_OP1_FLOOR
;
5564 alu
.src
[0].sel
= ctx
->temp_reg
;
5565 alu
.src
[0].chan
= 0;
5567 alu
.dst
.sel
= ctx
->temp_reg
;
5572 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5577 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5578 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5580 if (ctx
->bc
->chip_class
== CAYMAN
) {
5581 for (i
= 0; i
< 3; i
++) {
5582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5584 alu
.op
= ALU_OP1_LOG_IEEE
;
5585 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5586 r600_bytecode_src_set_abs(&alu
.src
[0]);
5588 alu
.dst
.sel
= ctx
->temp_reg
;
5595 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5602 alu
.op
= ALU_OP1_LOG_IEEE
;
5603 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5604 r600_bytecode_src_set_abs(&alu
.src
[0]);
5606 alu
.dst
.sel
= ctx
->temp_reg
;
5611 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5618 alu
.op
= ALU_OP1_FLOOR
;
5619 alu
.src
[0].sel
= ctx
->temp_reg
;
5620 alu
.src
[0].chan
= 1;
5622 alu
.dst
.sel
= ctx
->temp_reg
;
5627 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5631 if (ctx
->bc
->chip_class
== CAYMAN
) {
5632 for (i
= 0; i
< 3; i
++) {
5633 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5634 alu
.op
= ALU_OP1_EXP_IEEE
;
5635 alu
.src
[0].sel
= ctx
->temp_reg
;
5636 alu
.src
[0].chan
= 1;
5638 alu
.dst
.sel
= ctx
->temp_reg
;
5645 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5651 alu
.op
= ALU_OP1_EXP_IEEE
;
5652 alu
.src
[0].sel
= ctx
->temp_reg
;
5653 alu
.src
[0].chan
= 1;
5655 alu
.dst
.sel
= ctx
->temp_reg
;
5660 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5665 if (ctx
->bc
->chip_class
== CAYMAN
) {
5666 for (i
= 0; i
< 3; i
++) {
5667 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5668 alu
.op
= ALU_OP1_RECIP_IEEE
;
5669 alu
.src
[0].sel
= ctx
->temp_reg
;
5670 alu
.src
[0].chan
= 1;
5672 alu
.dst
.sel
= ctx
->temp_reg
;
5679 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5684 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5685 alu
.op
= ALU_OP1_RECIP_IEEE
;
5686 alu
.src
[0].sel
= ctx
->temp_reg
;
5687 alu
.src
[0].chan
= 1;
5689 alu
.dst
.sel
= ctx
->temp_reg
;
5694 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5699 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5701 alu
.op
= ALU_OP2_MUL
;
5703 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5704 r600_bytecode_src_set_abs(&alu
.src
[0]);
5706 alu
.src
[1].sel
= ctx
->temp_reg
;
5707 alu
.src
[1].chan
= 1;
5709 alu
.dst
.sel
= ctx
->temp_reg
;
5714 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5719 /* result.z = log2(|src|);*/
5720 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5721 if (ctx
->bc
->chip_class
== CAYMAN
) {
5722 for (i
= 0; i
< 3; i
++) {
5723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5725 alu
.op
= ALU_OP1_LOG_IEEE
;
5726 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5727 r600_bytecode_src_set_abs(&alu
.src
[0]);
5729 alu
.dst
.sel
= ctx
->temp_reg
;
5736 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5741 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5743 alu
.op
= ALU_OP1_LOG_IEEE
;
5744 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5745 r600_bytecode_src_set_abs(&alu
.src
[0]);
5747 alu
.dst
.sel
= ctx
->temp_reg
;
5752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5758 /* result.w = 1.0; */
5759 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5762 alu
.op
= ALU_OP1_MOV
;
5763 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5764 alu
.src
[0].chan
= 0;
5766 alu
.dst
.sel
= ctx
->temp_reg
;
5771 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5776 return tgsi_helper_copy(ctx
, inst
);
5779 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5781 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5782 struct r600_bytecode_alu alu
;
5784 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5788 switch (inst
->Instruction
.Opcode
) {
5789 case TGSI_OPCODE_ARL
:
5790 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5792 case TGSI_OPCODE_ARR
:
5793 alu
.op
= ALU_OP1_FLT_TO_INT
;
5795 case TGSI_OPCODE_UARL
:
5796 alu
.op
= ALU_OP1_MOV
;
5803 for (i
= 0; i
<= lasti
; ++i
) {
5804 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5806 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5807 alu
.last
= i
== lasti
;
5808 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5811 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5816 ctx
->bc
->ar_loaded
= 0;
5819 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5821 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5822 struct r600_bytecode_alu alu
;
5824 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5826 switch (inst
->Instruction
.Opcode
) {
5827 case TGSI_OPCODE_ARL
:
5828 memset(&alu
, 0, sizeof(alu
));
5829 alu
.op
= ALU_OP1_FLOOR
;
5830 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5832 for (i
= 0; i
<= lasti
; ++i
) {
5833 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
5835 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5836 alu
.last
= i
== lasti
;
5837 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5842 memset(&alu
, 0, sizeof(alu
));
5843 alu
.op
= ALU_OP1_FLT_TO_INT
;
5844 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5845 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5847 /* FLT_TO_INT is trans-only on r600/r700 */
5849 for (i
= 0; i
<= lasti
; ++i
) {
5851 alu
.src
[0].chan
= i
;
5852 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5856 case TGSI_OPCODE_ARR
:
5857 memset(&alu
, 0, sizeof(alu
));
5858 alu
.op
= ALU_OP1_FLT_TO_INT
;
5859 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5861 /* FLT_TO_INT is trans-only on r600/r700 */
5863 for (i
= 0; i
<= lasti
; ++i
) {
5864 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
5866 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5867 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5872 case TGSI_OPCODE_UARL
:
5873 memset(&alu
, 0, sizeof(alu
));
5874 alu
.op
= ALU_OP1_MOV
;
5875 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5877 for (i
= 0; i
<= lasti
; ++i
) {
5878 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
5880 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5881 alu
.last
= i
== lasti
;
5882 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5892 ctx
->bc
->ar_loaded
= 0;
5896 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5898 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5899 struct r600_bytecode_alu alu
;
5902 for (i
= 0; i
< 4; i
++) {
5903 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5905 alu
.op
= ALU_OP2_MUL
;
5906 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5908 if (i
== 0 || i
== 3) {
5909 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5911 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5914 if (i
== 0 || i
== 2) {
5915 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5917 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5921 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5928 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5930 struct r600_bytecode_alu alu
;
5933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5935 alu
.execute_mask
= 1;
5936 alu
.update_pred
= 1;
5938 alu
.dst
.sel
= ctx
->temp_reg
;
5942 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5943 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5944 alu
.src
[1].chan
= 0;
5948 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5954 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5956 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5960 if (ctx
->bc
->cf_last
) {
5961 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5963 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5968 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5969 ctx
->bc
->force_add_cf
= 1;
5970 } else if (alu_pop
== 2) {
5971 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5972 ctx
->bc
->force_add_cf
= 1;
5979 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5980 ctx
->bc
->cf_last
->pop_count
= pops
;
5981 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5987 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5990 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5991 unsigned elements
, entries
;
5993 unsigned entry_size
= stack
->entry_size
;
5995 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5996 elements
+= stack
->push
;
5998 switch (ctx
->bc
->chip_class
) {
6001 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
6002 * the stack must be reserved to hold the current active/continue
6004 if (reason
== FC_PUSH_VPM
) {
6010 /* r9xx: any stack operation on empty stack consumes 2 additional
6015 /* FIXME: do the two elements added above cover the cases for the
6019 /* r8xx+: 2 extra elements are not always required, but one extra
6020 * element must be added for each of the following cases:
6021 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
6023 * (Currently we don't use ALU_ELSE_AFTER.)
6024 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
6025 * PUSH instruction executed.
6027 * NOTE: it seems we also need to reserve additional element in some
6028 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
6029 * then STACK_SIZE should be 2 instead of 1 */
6030 if (reason
== FC_PUSH_VPM
) {
6040 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
6041 * for all chips, so we use 4 in the final formula, not the real entry_size
6045 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
6047 if (entries
> stack
->max_entries
)
6048 stack
->max_entries
= entries
;
6051 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
6055 --ctx
->bc
->stack
.push
;
6056 assert(ctx
->bc
->stack
.push
>= 0);
6059 --ctx
->bc
->stack
.push_wqm
;
6060 assert(ctx
->bc
->stack
.push_wqm
>= 0);
6063 --ctx
->bc
->stack
.loop
;
6064 assert(ctx
->bc
->stack
.loop
>= 0);
6072 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
6076 ++ctx
->bc
->stack
.push
;
6079 ++ctx
->bc
->stack
.push_wqm
;
6081 ++ctx
->bc
->stack
.loop
;
6087 callstack_update_max_depth(ctx
, reason
);
6090 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
6092 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
6094 sp
->mid
= realloc((void *)sp
->mid
,
6095 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
6096 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
6100 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
6103 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
6104 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
6107 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
6109 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
6119 static int emit_return(struct r600_shader_ctx
*ctx
)
6121 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
6125 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
6128 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
6129 ctx
->bc
->cf_last
->pop_count
= pops
;
6130 /* XXX work out offset */
6134 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
6139 static void emit_testflag(struct r600_shader_ctx
*ctx
)
6144 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
6147 emit_jump_to_offset(ctx
, 1, 4);
6148 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
6149 pops(ctx
, ifidx
+ 1);
6153 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
6157 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6158 ctx
->bc
->cf_last
->pop_count
= 1;
6160 fc_set_mid(ctx
, fc_sp
);
6166 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
6168 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
6170 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
6171 * LOOP_STARTxxx for nested loops may put the branch stack into a state
6172 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
6173 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
6174 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
6175 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
6176 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6177 alu_type
= CF_OP_ALU
;
6180 emit_logic_pred(ctx
, opcode
, alu_type
);
6182 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
6184 fc_pushlevel(ctx
, FC_IF
);
6186 callstack_push(ctx
, FC_PUSH_VPM
);
6190 static int tgsi_if(struct r600_shader_ctx
*ctx
)
6192 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
6195 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
6197 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
6200 static int tgsi_else(struct r600_shader_ctx
*ctx
)
6202 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
6203 ctx
->bc
->cf_last
->pop_count
= 1;
6205 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
6206 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
6210 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
6213 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
6214 R600_ERR("if/endif unbalanced in shader\n");
6218 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
6219 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6220 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
6222 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6226 callstack_pop(ctx
, FC_PUSH_VPM
);
6230 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
6232 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
6233 * limited to 4096 iterations, like the other LOOP_* instructions. */
6234 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
6236 fc_pushlevel(ctx
, FC_LOOP
);
6238 /* check stack depth */
6239 callstack_push(ctx
, FC_LOOP
);
6243 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
6247 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
6249 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
6250 R600_ERR("loop/endloop in shader code are not paired.\n");
6254 /* fixup loop pointers - from r600isa
6255 LOOP END points to CF after LOOP START,
6256 LOOP START point to CF after LOOP END
6257 BRK/CONT point to LOOP END CF
6259 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
6261 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6263 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
6264 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
6266 /* XXX add LOOPRET support */
6268 callstack_pop(ctx
, FC_LOOP
);
6272 static int tgsi_loop_breakc(struct r600_shader_ctx
*ctx
)
6277 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
6279 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
6283 R600_ERR("BREAKC not inside loop/endloop pair\n");
6287 if (ctx
->bc
->chip_class
== EVERGREEN
&&
6288 ctx
->bc
->family
!= CHIP_CYPRESS
&&
6289 ctx
->bc
->family
!= CHIP_JUNIPER
) {
6290 /* HW bug: ALU_BREAK does not save the active mask correctly */
6295 r
= r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_BREAK
);
6298 fc_set_mid(ctx
, fscp
);
6300 return tgsi_endif(ctx
);
6302 r
= emit_logic_pred(ctx
, ALU_OP2_PRED_SETE_INT
, CF_OP_ALU_BREAK
);
6305 fc_set_mid(ctx
, fscp
);
6311 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
6315 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
6317 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
6322 R600_ERR("Break not inside loop/endloop pair\n");
6326 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6328 fc_set_mid(ctx
, fscp
);
6333 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
6335 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
6336 emit_gs_ring_writes(ctx
, TRUE
);
6338 return r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6341 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
6343 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6344 struct r600_bytecode_alu alu
;
6346 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6349 for (i
= 0; i
< lasti
+ 1; i
++) {
6350 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6353 if (ctx
->bc
->chip_class
== CAYMAN
) {
6354 for (j
= 0 ; j
< 4; j
++) {
6355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6357 alu
.op
= ALU_OP2_MULLO_UINT
;
6358 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
6359 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
6361 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
6362 alu
.dst
.sel
= ctx
->temp_reg
;
6363 alu
.dst
.write
= (j
== i
);
6366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6371 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6374 alu
.dst
.sel
= ctx
->temp_reg
;
6377 alu
.op
= ALU_OP2_MULLO_UINT
;
6378 for (j
= 0; j
< 2; j
++) {
6379 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6383 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6390 for (i
= 0; i
< lasti
+ 1; i
++) {
6391 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6395 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6397 alu
.op
= ALU_OP2_ADD_INT
;
6399 alu
.src
[0].sel
= ctx
->temp_reg
;
6400 alu
.src
[0].chan
= i
;
6402 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6406 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6413 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
6414 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6415 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6416 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6419 * For state trackers other than OpenGL, we'll want to use
6420 * _RECIP_IEEE instead.
6422 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
6424 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
6425 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6426 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6427 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6428 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6429 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6430 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6431 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6432 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6433 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6434 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6435 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6436 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6437 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6438 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6439 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6441 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6442 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6444 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6445 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6446 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6447 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6448 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6449 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6450 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6451 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6452 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6453 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6455 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6456 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6457 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6458 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6459 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6460 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6461 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6462 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6463 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6464 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6465 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6467 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6468 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6469 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6470 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6471 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6472 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6473 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6474 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6475 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6476 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6477 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6478 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6479 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6480 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6481 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6482 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6483 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6484 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6485 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6486 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6487 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6488 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6489 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6490 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6491 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6492 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6493 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6494 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6495 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6496 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6497 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6498 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6499 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6500 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6501 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6503 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6504 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6505 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6506 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6507 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6508 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6509 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6510 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6511 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6513 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6514 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6515 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6516 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6517 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6518 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6519 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6520 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6521 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6522 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6523 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6524 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6525 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6526 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6527 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6528 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6530 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6531 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6532 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6533 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6534 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6535 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6536 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6537 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6538 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6539 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6541 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6542 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_loop_breakc
},
6543 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6544 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6546 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6547 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6548 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6549 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6550 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6551 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6552 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6553 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6554 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6555 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6556 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6557 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6558 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6559 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6560 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6561 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6562 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6563 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6564 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6565 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6566 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6567 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6568 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6569 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6570 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6571 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6572 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6573 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6574 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6575 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6576 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6577 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6578 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6579 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6580 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6581 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6582 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6583 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6584 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6585 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6586 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6587 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6588 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6589 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6590 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6591 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6592 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6593 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6594 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6595 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6596 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6597 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6598 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6599 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6600 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6601 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6602 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6603 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6604 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6605 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6606 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6607 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6608 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6611 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6612 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6613 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6614 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6615 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6616 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6617 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6618 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6619 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6620 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6621 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6622 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6623 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6624 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6625 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6626 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6627 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6628 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6629 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6630 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6631 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6633 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6634 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6636 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6637 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6638 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6639 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6640 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6641 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6642 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6643 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6644 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6645 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6647 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6648 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6649 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6650 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6651 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6652 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6653 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6654 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6655 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6656 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6657 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6658 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6659 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6660 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6661 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6662 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6663 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6664 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6665 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6666 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6667 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6668 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6669 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6670 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6671 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6672 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6673 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6674 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6675 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6676 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6677 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6678 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6679 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6680 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6681 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6682 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6683 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6684 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6685 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6686 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6687 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6688 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6689 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6690 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6691 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6692 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6693 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6695 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6696 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6697 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6698 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6699 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6700 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6701 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6702 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6703 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6705 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6706 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6707 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6708 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6709 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6710 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6711 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6712 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6713 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6714 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6715 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6716 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6717 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6718 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6719 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6720 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6722 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6723 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6724 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6725 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6726 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6727 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6728 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6729 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6730 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6731 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6733 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6734 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6735 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6736 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6738 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6739 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6740 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6741 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6742 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6743 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6744 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6745 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6746 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6747 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6748 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6749 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6750 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6751 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6752 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6753 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6754 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6755 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6756 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6757 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6758 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6759 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6760 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6761 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6762 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6763 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6764 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6765 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6766 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6767 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6768 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6769 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6770 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6771 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6772 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6773 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6774 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6775 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6776 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6777 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6778 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6779 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6780 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6781 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6782 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6783 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6784 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6785 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6786 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6787 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6788 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6789 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6790 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6791 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6792 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6793 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6794 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6795 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6796 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6797 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6798 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6799 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6800 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6803 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6804 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6805 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6806 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6807 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6808 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6809 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6810 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6811 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6812 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6813 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6814 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6815 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6816 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6817 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6818 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6819 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6820 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6821 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6822 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6823 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6825 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6826 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6828 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6829 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6830 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6831 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6832 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6833 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6834 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6835 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6836 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6837 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6839 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6840 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6841 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6842 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6843 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6844 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6845 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6846 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6847 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6848 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6849 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6850 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6851 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6852 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6853 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6854 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6855 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6856 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6857 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6858 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6859 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6860 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6861 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6862 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6863 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6864 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6865 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6866 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6867 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6868 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6869 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6870 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6871 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6872 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6873 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6874 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6875 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6876 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6877 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6878 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6879 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6880 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6881 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6882 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6883 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6884 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6885 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6887 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6888 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6889 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6890 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6891 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6892 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6893 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6894 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6895 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6897 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6898 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6899 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6900 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6901 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6902 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6903 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6904 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6905 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6906 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6907 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6908 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6909 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6910 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6911 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6912 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6914 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6915 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6916 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6917 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6919 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6920 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6921 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6922 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6923 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6924 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6926 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6927 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6928 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6929 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6931 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6932 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6933 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6934 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6935 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6936 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6937 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6938 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6939 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6940 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6941 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6942 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6943 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6944 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6945 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6946 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6947 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6948 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6949 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6950 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6951 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6952 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6953 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6954 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6955 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6956 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6957 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6958 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6959 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6960 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6961 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6962 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6963 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6964 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6965 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6966 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6967 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6968 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6969 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6970 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6971 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6972 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6973 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6974 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6975 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6976 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6977 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6978 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6979 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6980 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6981 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6982 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6983 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6984 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6985 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6986 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6987 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6988 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6989 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6990 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6991 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6992 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6993 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},