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
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
814 struct r600_bytecode_vtx vtx
;
819 struct r600_bytecode_alu alu
;
821 memset(&alu
, 0, sizeof(alu
));
823 alu
.op
= ALU_OP2_ADD_INT
;
824 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
826 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
827 alu
.src
[1].value
= offset
;
829 alu
.dst
.sel
= dst_reg
;
833 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
838 ar_reg
= ctx
->bc
->ar_reg
;
841 memset(&vtx
, 0, sizeof(vtx
));
842 vtx
.buffer_id
= cb_idx
;
843 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
844 vtx
.src_gpr
= ar_reg
;
845 vtx
.mega_fetch_count
= 16;
846 vtx
.dst_gpr
= dst_reg
;
847 vtx
.dst_sel_x
= 0; /* SEL_X */
848 vtx
.dst_sel_y
= 1; /* SEL_Y */
849 vtx
.dst_sel_z
= 2; /* SEL_Z */
850 vtx
.dst_sel_w
= 3; /* SEL_W */
851 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
852 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
853 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
854 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
855 vtx
.endian
= r600_endian_swap(32);
857 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
863 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
865 struct r600_bytecode_vtx vtx
;
867 unsigned index
= src
->Register
.Index
;
868 unsigned vtx_id
= src
->Dimension
.Index
;
869 int offset_reg
= vtx_id
/ 3;
870 int offset_chan
= vtx_id
% 3;
872 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
873 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
875 if (offset_reg
== 0 && offset_chan
== 2)
878 if (src
->Dimension
.Indirect
) {
881 struct r600_bytecode_alu alu
;
884 /* you have got to be shitting me -
885 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
886 at least this is what fglrx seems to do. */
887 for (i
= 0; i
< 3; i
++) {
888 treg
[i
] = r600_get_temp(ctx
);
890 t2
= r600_get_temp(ctx
);
891 for (i
= 0; i
< 3; i
++) {
892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
893 alu
.op
= ALU_OP1_MOV
;
895 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
896 alu
.dst
.sel
= treg
[i
];
900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
904 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
905 alu
.op
= ALU_OP1_MOV
;
906 alu
.src
[0].sel
= treg
[0];
911 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
918 memset(&vtx
, 0, sizeof(vtx
));
919 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
920 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
921 vtx
.src_gpr
= offset_reg
;
922 vtx
.src_sel_x
= offset_chan
;
923 vtx
.offset
= index
* 16; /*bytes*/
924 vtx
.mega_fetch_count
= 16;
925 vtx
.dst_gpr
= dst_reg
;
926 vtx
.dst_sel_x
= 0; /* SEL_X */
927 vtx
.dst_sel_y
= 1; /* SEL_Y */
928 vtx
.dst_sel_z
= 2; /* SEL_Z */
929 vtx
.dst_sel_w
= 3; /* SEL_W */
930 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
931 vtx
.use_const_fields
= 1;
933 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
936 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
942 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
944 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
947 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
948 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
950 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
951 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
952 /* primitive id is in R0.z */
954 ctx
->src
[i
].swizzle
[0] = 2;
957 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
958 int treg
= r600_get_temp(ctx
);
960 fetch_gs_input(ctx
, src
, treg
);
961 ctx
->src
[i
].sel
= treg
;
967 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
969 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
970 struct r600_bytecode_alu alu
;
971 int i
, j
, k
, nconst
, r
;
973 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
974 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
977 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
979 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
980 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
984 if (ctx
->src
[i
].rel
) {
985 int treg
= r600_get_temp(ctx
);
986 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
989 ctx
->src
[i
].kc_bank
= 0;
990 ctx
->src
[i
].sel
= treg
;
994 int treg
= r600_get_temp(ctx
);
995 for (k
= 0; k
< 4; k
++) {
996 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
997 alu
.op
= ALU_OP1_MOV
;
998 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1000 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1006 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1010 ctx
->src
[i
].sel
= treg
;
1018 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1019 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1021 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1022 struct r600_bytecode_alu alu
;
1023 int i
, j
, k
, nliteral
, r
;
1025 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1026 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1030 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1031 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1032 int treg
= r600_get_temp(ctx
);
1033 for (k
= 0; k
< 4; k
++) {
1034 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1035 alu
.op
= ALU_OP1_MOV
;
1036 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1037 alu
.src
[0].chan
= k
;
1038 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1044 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1048 ctx
->src
[i
].sel
= treg
;
1055 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1057 int i
, r
, count
= ctx
->shader
->ninput
;
1059 for (i
= 0; i
< count
; i
++) {
1060 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1061 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1069 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
)
1071 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1074 /* Sanity checking. */
1075 if (so
->num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1076 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
1080 for (i
= 0; i
< so
->num_outputs
; i
++) {
1081 if (so
->output
[i
].output_buffer
>= 4) {
1082 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1083 so
->output
[i
].output_buffer
);
1089 /* Initialize locations where the outputs are stored. */
1090 for (i
= 0; i
< so
->num_outputs
; i
++) {
1091 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
1093 /* Lower outputs with dst_offset < start_component.
1095 * We can only output 4D vectors with a write mask, e.g. we can
1096 * only output the W component at offset 3, etc. If we want
1097 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1098 * to move it to X and output X. */
1099 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
1100 unsigned tmp
= r600_get_temp(ctx
);
1102 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
1103 struct r600_bytecode_alu alu
;
1104 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1105 alu
.op
= ALU_OP1_MOV
;
1106 alu
.src
[0].sel
= so_gpr
[i
];
1107 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
1112 if (j
== so
->output
[i
].num_components
- 1)
1114 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1118 so
->output
[i
].start_component
= 0;
1123 /* Write outputs to buffers. */
1124 for (i
= 0; i
< so
->num_outputs
; i
++) {
1125 struct r600_bytecode_output output
;
1127 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1128 output
.gpr
= so_gpr
[i
];
1129 output
.elem_size
= so
->output
[i
].num_components
;
1130 output
.array_base
= so
->output
[i
].dst_offset
- so
->output
[i
].start_component
;
1131 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1132 output
.burst_count
= 1;
1133 /* array_size is an upper limit for the burst_count
1134 * with MEM_STREAM instructions */
1135 output
.array_size
= 0xFFF;
1136 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << so
->output
[i
].start_component
;
1137 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1138 switch (so
->output
[i
].output_buffer
) {
1140 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1143 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1146 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1149 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1153 switch (so
->output
[i
].output_buffer
) {
1155 output
.op
= CF_OP_MEM_STREAM0
;
1158 output
.op
= CF_OP_MEM_STREAM1
;
1161 output
.op
= CF_OP_MEM_STREAM2
;
1164 output
.op
= CF_OP_MEM_STREAM3
;
1168 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
1177 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
1179 struct r600_bytecode_alu alu
;
1182 if (!ctx
->shader
->vs_out_edgeflag
)
1185 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
1187 /* clamp(x, 0, 1) */
1188 memset(&alu
, 0, sizeof(alu
));
1189 alu
.op
= ALU_OP1_MOV
;
1190 alu
.src
[0].sel
= reg
;
1195 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1197 memset(&alu
, 0, sizeof(alu
));
1198 alu
.op
= ALU_OP1_FLT_TO_INT
;
1199 alu
.src
[0].sel
= reg
;
1203 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1206 static int generate_gs_copy_shader(struct r600_context
*rctx
,
1207 struct r600_pipe_shader
*gs
,
1208 struct pipe_stream_output_info
*so
)
1210 struct r600_shader_ctx ctx
= {};
1211 struct r600_shader
*gs_shader
= &gs
->shader
;
1212 struct r600_pipe_shader
*cshader
;
1213 int ocnt
= gs_shader
->noutput
;
1214 struct r600_bytecode_alu alu
;
1215 struct r600_bytecode_vtx vtx
;
1216 struct r600_bytecode_output output
;
1217 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
1218 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
1219 int i
, next_clip_pos
= 61, next_param
= 0;
1221 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
1225 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
1226 sizeof(struct r600_shader_io
));
1228 cshader
->shader
.noutput
= ocnt
;
1230 ctx
.shader
= &cshader
->shader
;
1231 ctx
.bc
= &ctx
.shader
->bc
;
1232 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
1234 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
1235 rctx
->screen
->has_compressed_msaa_texturing
);
1237 ctx
.bc
->isa
= rctx
->isa
;
1239 /* R0.x = R0.x & 0x3fffffff */
1240 memset(&alu
, 0, sizeof(alu
));
1241 alu
.op
= ALU_OP2_AND_INT
;
1242 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1243 alu
.src
[1].value
= 0x3fffffff;
1245 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1247 /* R0.y = R0.x >> 30 */
1248 memset(&alu
, 0, sizeof(alu
));
1249 alu
.op
= ALU_OP2_LSHR_INT
;
1250 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1251 alu
.src
[1].value
= 0x1e;
1255 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1257 /* PRED_SETE_INT __, R0.y, 0 */
1258 memset(&alu
, 0, sizeof(alu
));
1259 alu
.op
= ALU_OP2_PRED_SETE_INT
;
1260 alu
.src
[0].chan
= 1;
1261 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1262 alu
.execute_mask
= 1;
1263 alu
.update_pred
= 1;
1265 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
1267 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
1268 cf_jump
= ctx
.bc
->cf_last
;
1270 /* fetch vertex data from GSVS ring */
1271 for (i
= 0; i
< ocnt
; ++i
) {
1272 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1274 out
->ring_offset
= i
* 16;
1276 memset(&vtx
, 0, sizeof(vtx
));
1277 vtx
.op
= FETCH_OP_VFETCH
;
1278 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1280 vtx
.offset
= out
->ring_offset
;
1281 vtx
.dst_gpr
= out
->gpr
;
1286 if (rctx
->b
.chip_class
>= EVERGREEN
) {
1287 vtx
.use_const_fields
= 1;
1289 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1292 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
1295 /* XXX handle clipvertex, streamout? */
1296 emit_streamout(&ctx
, so
);
1298 /* export vertex data */
1299 /* XXX factor out common code with r600_shader_from_tgsi ? */
1300 for (i
= 0; i
< ocnt
; ++i
) {
1301 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1303 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
1306 memset(&output
, 0, sizeof(output
));
1307 output
.gpr
= out
->gpr
;
1308 output
.elem_size
= 3;
1309 output
.swizzle_x
= 0;
1310 output
.swizzle_y
= 1;
1311 output
.swizzle_z
= 2;
1312 output
.swizzle_w
= 3;
1313 output
.burst_count
= 1;
1314 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1315 output
.op
= CF_OP_EXPORT
;
1316 switch (out
->name
) {
1317 case TGSI_SEMANTIC_POSITION
:
1318 output
.array_base
= 60;
1319 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1322 case TGSI_SEMANTIC_PSIZE
:
1323 output
.array_base
= 61;
1324 if (next_clip_pos
== 61)
1326 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1327 output
.swizzle_y
= 7;
1328 output
.swizzle_z
= 7;
1329 output
.swizzle_w
= 7;
1330 ctx
.shader
->vs_out_misc_write
= 1;
1331 ctx
.shader
->vs_out_point_size
= 1;
1333 case TGSI_SEMANTIC_LAYER
:
1334 output
.array_base
= 61;
1335 if (next_clip_pos
== 61)
1337 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1338 output
.swizzle_x
= 7;
1339 output
.swizzle_y
= 7;
1340 output
.swizzle_z
= 0;
1341 output
.swizzle_w
= 7;
1342 ctx
.shader
->vs_out_misc_write
= 1;
1343 ctx
.shader
->vs_out_layer
= 1;
1345 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
1346 output
.array_base
= 61;
1347 if (next_clip_pos
== 61)
1349 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1350 ctx
.shader
->vs_out_misc_write
= 1;
1351 ctx
.shader
->vs_out_viewport
= 1;
1352 output
.swizzle_x
= 7;
1353 output
.swizzle_y
= 7;
1354 output
.swizzle_z
= 7;
1355 output
.swizzle_w
= 0;
1357 case TGSI_SEMANTIC_CLIPDIST
:
1358 /* spi_sid is 0 for clipdistance outputs that were generated
1359 * for clipvertex - we don't need to pass them to PS */
1360 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
1362 /* duplicate it as PARAM to pass to the pixel shader */
1363 output
.array_base
= next_param
++;
1364 r600_bytecode_add_output(ctx
.bc
, &output
);
1365 last_exp_param
= ctx
.bc
->cf_last
;
1367 output
.array_base
= next_clip_pos
++;
1368 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1370 case TGSI_SEMANTIC_FOG
:
1371 output
.swizzle_y
= 4; /* 0 */
1372 output
.swizzle_z
= 4; /* 0 */
1373 output
.swizzle_w
= 5; /* 1 */
1376 output
.array_base
= next_param
++;
1379 r600_bytecode_add_output(ctx
.bc
, &output
);
1380 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
1381 last_exp_param
= ctx
.bc
->cf_last
;
1383 last_exp_pos
= ctx
.bc
->cf_last
;
1386 if (!last_exp_pos
) {
1387 memset(&output
, 0, sizeof(output
));
1389 output
.elem_size
= 3;
1390 output
.swizzle_x
= 7;
1391 output
.swizzle_y
= 7;
1392 output
.swizzle_z
= 7;
1393 output
.swizzle_w
= 7;
1394 output
.burst_count
= 1;
1396 output
.op
= CF_OP_EXPORT
;
1397 output
.array_base
= 60;
1398 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1399 r600_bytecode_add_output(ctx
.bc
, &output
);
1400 last_exp_pos
= ctx
.bc
->cf_last
;
1403 if (!last_exp_param
) {
1404 memset(&output
, 0, sizeof(output
));
1406 output
.elem_size
= 3;
1407 output
.swizzle_x
= 7;
1408 output
.swizzle_y
= 7;
1409 output
.swizzle_z
= 7;
1410 output
.swizzle_w
= 7;
1411 output
.burst_count
= 1;
1413 output
.op
= CF_OP_EXPORT
;
1414 output
.array_base
= next_param
++;
1415 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1416 r600_bytecode_add_output(ctx
.bc
, &output
);
1417 last_exp_param
= ctx
.bc
->cf_last
;
1420 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
1421 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
1423 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1424 cf_pop
= ctx
.bc
->cf_last
;
1426 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1427 cf_jump
->pop_count
= 1;
1428 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1429 cf_pop
->pop_count
= 1;
1431 if (ctx
.bc
->chip_class
== CAYMAN
)
1432 cm_bytecode_add_cf_end(ctx
.bc
);
1434 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1435 ctx
.bc
->cf_last
->end_of_program
= 1;
1438 gs
->gs_copy_shader
= cshader
;
1441 cshader
->shader
.ring_item_size
= ocnt
* 16;
1443 return r600_bytecode_build(ctx
.bc
);
1446 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, bool ind
)
1448 struct r600_bytecode_output output
;
1449 int i
, k
, ring_offset
;
1451 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
1452 if (ctx
->gs_for_vs
) {
1453 /* for ES we need to lookup corresponding ring offset expected by GS
1454 * (map this output to GS input by name and sid) */
1455 /* FIXME precompute offsets */
1457 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
1458 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
1459 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
1460 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
1461 ring_offset
= in
->ring_offset
;
1464 if (ring_offset
== -1)
1467 ring_offset
= i
* 16;
1469 /* next_ring_offset after parsing input decls contains total size of
1470 * single vertex data, gs_next_vertex - current vertex index */
1472 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
1474 /* get a temp and add the ring offset to the next vertex base in the shader */
1475 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1476 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
1477 output
.elem_size
= 3;
1478 output
.comp_mask
= 0xF;
1479 output
.burst_count
= 1;
1482 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
1484 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1485 output
.op
= CF_OP_MEM_RING
;
1489 output
.array_base
= ring_offset
>> 2; /* in dwords */
1490 output
.array_size
= 0xfff;
1491 output
.index_gpr
= ctx
->gs_export_gpr_treg
;
1493 output
.array_base
= ring_offset
>> 2; /* in dwords */
1494 r600_bytecode_add_output(ctx
->bc
, &output
);
1498 struct r600_bytecode_alu alu
;
1501 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1502 alu
.op
= ALU_OP2_ADD_INT
;
1503 alu
.src
[0].sel
= ctx
->gs_export_gpr_treg
;
1504 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1505 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
1506 alu
.dst
.sel
= ctx
->gs_export_gpr_treg
;
1509 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1513 ++ctx
->gs_next_vertex
;
1517 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
1518 struct r600_pipe_shader
*pipeshader
,
1519 struct r600_shader_key key
)
1521 struct r600_screen
*rscreen
= rctx
->screen
;
1522 struct r600_shader
*shader
= &pipeshader
->shader
;
1523 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1524 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1525 struct tgsi_full_immediate
*immediate
;
1526 struct tgsi_full_property
*property
;
1527 struct r600_shader_ctx ctx
;
1528 struct r600_bytecode_output output
[32];
1529 unsigned output_done
, noutput
;
1532 int next_param_base
= 0, next_clip_base
;
1533 int max_color_exports
= MAX2(key
.nr_cbufs
, 1);
1534 /* Declarations used by llvm code */
1535 bool use_llvm
= false;
1537 bool ring_outputs
= false;
1538 bool pos_emitted
= false;
1540 #ifdef R600_USE_LLVM
1541 use_llvm
= rscreen
->b
.debug_flags
& DBG_LLVM
;
1543 ctx
.bc
= &shader
->bc
;
1544 ctx
.shader
= shader
;
1545 ctx
.native_integers
= true;
1547 shader
->vs_as_es
= key
.vs_as_es
;
1549 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
1550 rscreen
->has_compressed_msaa_texturing
);
1551 ctx
.tokens
= tokens
;
1552 tgsi_scan_shader(tokens
, &ctx
.info
);
1553 shader
->indirect_files
= ctx
.info
.indirect_files
;
1554 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
1555 tgsi_parse_init(&ctx
.parse
, tokens
);
1556 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1557 shader
->processor_type
= ctx
.type
;
1558 ctx
.bc
->type
= shader
->processor_type
;
1560 ring_outputs
= key
.vs_as_es
|| (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
);
1563 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
1565 ctx
.gs_for_vs
= NULL
;
1568 ctx
.next_ring_offset
= 0;
1569 ctx
.gs_out_ring_offset
= 0;
1570 ctx
.gs_next_vertex
= 0;
1573 ctx
.fragcoord_input
= -1;
1574 ctx
.colors_used
= 0;
1575 ctx
.clip_vertex_write
= 0;
1577 shader
->nr_ps_color_exports
= 0;
1578 shader
->nr_ps_max_color_exports
= 0;
1580 shader
->two_side
= key
.color_two_side
;
1582 /* register allocations */
1583 /* Values [0,127] correspond to GPR[0..127].
1584 * Values [128,159] correspond to constant buffer bank 0
1585 * Values [160,191] correspond to constant buffer bank 1
1586 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1587 * Values [256,287] correspond to constant buffer bank 2 (EG)
1588 * Values [288,319] correspond to constant buffer bank 3 (EG)
1589 * Other special values are shown in the list below.
1590 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1591 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1592 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1593 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1594 * 248 SQ_ALU_SRC_0: special constant 0.0.
1595 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1596 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1597 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1598 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1599 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1600 * 254 SQ_ALU_SRC_PV: previous vector result.
1601 * 255 SQ_ALU_SRC_PS: previous scalar result.
1603 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1604 ctx
.file_offset
[i
] = 0;
1607 #ifdef R600_USE_LLVM
1608 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1609 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1610 "indirect adressing. Falling back to TGSI "
1615 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1616 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1618 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1621 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1622 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1624 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1625 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
1626 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
1628 ctx
.use_llvm
= use_llvm
;
1631 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1632 ctx
.file_offset
[TGSI_FILE_INPUT
];
1634 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1635 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1636 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1638 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1639 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1641 /* Outside the GPR range. This will be translated to one of the
1642 * kcache banks later. */
1643 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1645 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1646 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1647 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1648 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1649 ctx
.gs_export_gpr_treg
= ctx
.bc
->ar_reg
+ 1;
1650 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 2;
1652 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1654 if (indirect_gprs
) {
1655 shader
->max_arrays
= 0;
1656 shader
->num_arrays
= 0;
1658 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1659 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1660 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1661 ctx
.file_offset
[TGSI_FILE_INPUT
],
1664 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1665 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1666 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1667 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1673 ctx
.literals
= NULL
;
1674 shader
->fs_write_all
= FALSE
;
1675 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1676 tgsi_parse_token(&ctx
.parse
);
1677 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1678 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1679 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1680 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1681 if(ctx
.literals
== NULL
) {
1685 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1686 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1687 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1688 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1691 case TGSI_TOKEN_TYPE_DECLARATION
:
1692 r
= tgsi_declaration(&ctx
);
1696 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1698 case TGSI_TOKEN_TYPE_PROPERTY
:
1699 property
= &ctx
.parse
.FullToken
.FullProperty
;
1700 switch (property
->Property
.PropertyName
) {
1701 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1702 if (property
->u
[0].Data
== 1)
1703 shader
->fs_write_all
= TRUE
;
1705 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1706 /* we don't need this one */
1708 case TGSI_PROPERTY_GS_INPUT_PRIM
:
1709 shader
->gs_input_prim
= property
->u
[0].Data
;
1711 case TGSI_PROPERTY_GS_OUTPUT_PRIM
:
1712 shader
->gs_output_prim
= property
->u
[0].Data
;
1714 case TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
:
1715 shader
->gs_max_out_vertices
= property
->u
[0].Data
;
1720 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1726 shader
->ring_item_size
= ctx
.next_ring_offset
;
1728 /* Process two side if needed */
1729 if (shader
->two_side
&& ctx
.colors_used
) {
1730 int i
, count
= ctx
.shader
->ninput
;
1731 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1733 /* additional inputs will be allocated right after the existing inputs,
1734 * we won't need them after the color selection, so we don't need to
1735 * reserve these gprs for the rest of the shader code and to adjust
1736 * output offsets etc. */
1737 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1738 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1740 if (ctx
.face_gpr
== -1) {
1741 i
= ctx
.shader
->ninput
++;
1742 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1743 ctx
.shader
->input
[i
].spi_sid
= 0;
1744 ctx
.shader
->input
[i
].gpr
= gpr
++;
1745 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1748 for (i
= 0; i
< count
; i
++) {
1749 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1750 int ni
= ctx
.shader
->ninput
++;
1751 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1752 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1753 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1754 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1755 // TGSI to LLVM needs to know the lds position of inputs.
1756 // Non LLVM path computes it later (in process_twoside_color)
1757 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1758 ctx
.shader
->input
[i
].back_color_input
= ni
;
1759 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1760 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1767 /* LLVM backend setup */
1768 #ifdef R600_USE_LLVM
1770 struct radeon_llvm_context radeon_llvm_ctx
;
1772 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
1773 boolean use_kill
= false;
1775 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1776 radeon_llvm_ctx
.type
= ctx
.type
;
1777 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1778 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1779 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
1780 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1781 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1782 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
1783 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1784 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
1785 radeon_llvm_ctx
.stream_outputs
= &so
;
1786 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1787 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1788 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
1789 ctx
.bc
->has_compressed_msaa_texturing
;
1790 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1791 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1792 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
1794 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
1795 radeon_llvm_dispose(&radeon_llvm_ctx
);
1797 fprintf(stderr
, "R600 LLVM backend failed to compile "
1798 "shader. Falling back to TGSI\n");
1800 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1801 ctx
.file_offset
[TGSI_FILE_INPUT
];
1804 ctx
.shader
->uses_kill
= use_kill
;
1805 radeon_llvm_dispose(&radeon_llvm_ctx
);
1808 /* End of LLVM backend setup */
1810 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
1811 shader
->nr_ps_max_color_exports
= 8;
1814 if (ctx
.fragcoord_input
>= 0) {
1815 if (ctx
.bc
->chip_class
== CAYMAN
) {
1816 for (j
= 0 ; j
< 4; j
++) {
1817 struct r600_bytecode_alu alu
;
1818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1819 alu
.op
= ALU_OP1_RECIP_IEEE
;
1820 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1821 alu
.src
[0].chan
= 3;
1823 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1825 alu
.dst
.write
= (j
== 3);
1827 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1831 struct r600_bytecode_alu alu
;
1832 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1833 alu
.op
= ALU_OP1_RECIP_IEEE
;
1834 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1835 alu
.src
[0].chan
= 3;
1837 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1841 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1846 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1847 struct r600_bytecode_alu alu
;
1850 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1851 alu
.op
= ALU_OP1_MOV
;
1852 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1853 alu
.src
[0].value
= 0;
1854 alu
.dst
.sel
= ctx
.gs_export_gpr_treg
;
1857 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1861 if (shader
->two_side
&& ctx
.colors_used
) {
1862 if ((r
= process_twoside_color_inputs(&ctx
)))
1866 tgsi_parse_init(&ctx
.parse
, tokens
);
1867 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1868 tgsi_parse_token(&ctx
.parse
);
1869 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1870 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1871 r
= tgsi_is_supported(&ctx
);
1874 ctx
.max_driver_temp_used
= 0;
1875 /* reserve first tmp for everyone */
1876 r600_get_temp(&ctx
);
1878 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1879 if ((r
= tgsi_split_constant(&ctx
)))
1881 if ((r
= tgsi_split_literal_constant(&ctx
)))
1883 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
)
1884 if ((r
= tgsi_split_gs_inputs(&ctx
)))
1886 if (ctx
.bc
->chip_class
== CAYMAN
)
1887 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1888 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1889 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1891 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1892 r
= ctx
.inst_info
->process(&ctx
);
1902 /* Reset the temporary register counter. */
1903 ctx
.max_driver_temp_used
= 0;
1905 noutput
= shader
->noutput
;
1907 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
1908 unsigned clipdist_temp
[2];
1910 clipdist_temp
[0] = r600_get_temp(&ctx
);
1911 clipdist_temp
[1] = r600_get_temp(&ctx
);
1913 /* need to convert a clipvertex write into clipdistance writes and not export
1914 the clip vertex anymore */
1916 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1917 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1918 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1920 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1921 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1924 /* reset spi_sid for clipvertex output to avoid confusing spi */
1925 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1927 shader
->clip_dist_write
= 0xFF;
1929 for (i
= 0; i
< 8; i
++) {
1933 for (j
= 0; j
< 4; j
++) {
1934 struct r600_bytecode_alu alu
;
1935 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1936 alu
.op
= ALU_OP2_DOT4
;
1937 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1938 alu
.src
[0].chan
= j
;
1940 alu
.src
[1].sel
= 512 + i
;
1941 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1942 alu
.src
[1].chan
= j
;
1944 alu
.dst
.sel
= clipdist_temp
[oreg
];
1946 alu
.dst
.write
= (j
== ochan
);
1950 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1957 /* Add stream outputs. */
1958 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
&&
1959 so
.num_outputs
&& !use_llvm
)
1960 emit_streamout(&ctx
, &so
);
1962 convert_edgeflag_to_int(&ctx
);
1966 emit_gs_ring_writes(&ctx
, FALSE
);
1969 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
1971 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1972 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1973 output
[j
].gpr
= shader
->output
[i
].gpr
;
1974 output
[j
].elem_size
= 3;
1975 output
[j
].swizzle_x
= 0;
1976 output
[j
].swizzle_y
= 1;
1977 output
[j
].swizzle_z
= 2;
1978 output
[j
].swizzle_w
= 3;
1979 output
[j
].burst_count
= 1;
1980 output
[j
].type
= -1;
1981 output
[j
].op
= CF_OP_EXPORT
;
1983 case TGSI_PROCESSOR_VERTEX
:
1984 switch (shader
->output
[i
].name
) {
1985 case TGSI_SEMANTIC_POSITION
:
1986 output
[j
].array_base
= 60;
1987 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1991 case TGSI_SEMANTIC_PSIZE
:
1992 output
[j
].array_base
= 61;
1993 output
[j
].swizzle_y
= 7;
1994 output
[j
].swizzle_z
= 7;
1995 output
[j
].swizzle_w
= 7;
1996 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1999 case TGSI_SEMANTIC_EDGEFLAG
:
2000 output
[j
].array_base
= 61;
2001 output
[j
].swizzle_x
= 7;
2002 output
[j
].swizzle_y
= 0;
2003 output
[j
].swizzle_z
= 7;
2004 output
[j
].swizzle_w
= 7;
2005 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2008 case TGSI_SEMANTIC_LAYER
:
2009 output
[j
].array_base
= 61;
2010 output
[j
].swizzle_x
= 7;
2011 output
[j
].swizzle_y
= 7;
2012 output
[j
].swizzle_z
= 0;
2013 output
[j
].swizzle_w
= 7;
2014 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2017 case TGSI_SEMANTIC_CLIPVERTEX
:
2020 case TGSI_SEMANTIC_CLIPDIST
:
2021 output
[j
].array_base
= next_clip_base
++;
2022 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2024 /* spi_sid is 0 for clipdistance outputs that were generated
2025 * for clipvertex - we don't need to pass them to PS */
2026 if (shader
->output
[i
].spi_sid
) {
2028 /* duplicate it as PARAM to pass to the pixel shader */
2029 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2030 output
[j
].array_base
= next_param_base
++;
2031 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2034 case TGSI_SEMANTIC_FOG
:
2035 output
[j
].swizzle_y
= 4; /* 0 */
2036 output
[j
].swizzle_z
= 4; /* 0 */
2037 output
[j
].swizzle_w
= 5; /* 1 */
2041 case TGSI_PROCESSOR_FRAGMENT
:
2042 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2043 /* never export more colors than the number of CBs */
2044 if (shader
->output
[i
].sid
>= max_color_exports
) {
2049 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
2050 output
[j
].array_base
= shader
->output
[i
].sid
;
2051 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2052 shader
->nr_ps_color_exports
++;
2053 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
2054 for (k
= 1; k
< max_color_exports
; k
++) {
2056 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2057 output
[j
].gpr
= shader
->output
[i
].gpr
;
2058 output
[j
].elem_size
= 3;
2059 output
[j
].swizzle_x
= 0;
2060 output
[j
].swizzle_y
= 1;
2061 output
[j
].swizzle_z
= 2;
2062 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
2063 output
[j
].burst_count
= 1;
2064 output
[j
].array_base
= k
;
2065 output
[j
].op
= CF_OP_EXPORT
;
2066 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2067 shader
->nr_ps_color_exports
++;
2070 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
2071 output
[j
].array_base
= 61;
2072 output
[j
].swizzle_x
= 2;
2073 output
[j
].swizzle_y
= 7;
2074 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2075 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2076 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
2077 output
[j
].array_base
= 61;
2078 output
[j
].swizzle_x
= 7;
2079 output
[j
].swizzle_y
= 1;
2080 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2081 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2083 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
2089 R600_ERR("unsupported processor type %d\n", ctx
.type
);
2094 if (output
[j
].type
==-1) {
2095 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2096 output
[j
].array_base
= next_param_base
++;
2100 /* add fake position export */
2101 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& pos_emitted
== false) {
2102 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2104 output
[j
].elem_size
= 3;
2105 output
[j
].swizzle_x
= 7;
2106 output
[j
].swizzle_y
= 7;
2107 output
[j
].swizzle_z
= 7;
2108 output
[j
].swizzle_w
= 7;
2109 output
[j
].burst_count
= 1;
2110 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2111 output
[j
].array_base
= 60;
2112 output
[j
].op
= CF_OP_EXPORT
;
2116 /* add fake param output for vertex shader if no param is exported */
2117 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
2118 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2120 output
[j
].elem_size
= 3;
2121 output
[j
].swizzle_x
= 7;
2122 output
[j
].swizzle_y
= 7;
2123 output
[j
].swizzle_z
= 7;
2124 output
[j
].swizzle_w
= 7;
2125 output
[j
].burst_count
= 1;
2126 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2127 output
[j
].array_base
= 0;
2128 output
[j
].op
= CF_OP_EXPORT
;
2132 /* add fake pixel export */
2133 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
2134 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2136 output
[j
].elem_size
= 3;
2137 output
[j
].swizzle_x
= 7;
2138 output
[j
].swizzle_y
= 7;
2139 output
[j
].swizzle_z
= 7;
2140 output
[j
].swizzle_w
= 7;
2141 output
[j
].burst_count
= 1;
2142 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2143 output
[j
].array_base
= 0;
2144 output
[j
].op
= CF_OP_EXPORT
;
2150 /* set export done on last export of each type */
2151 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
2152 if (!(output_done
& (1 << output
[i
].type
))) {
2153 output_done
|= (1 << output
[i
].type
);
2154 output
[i
].op
= CF_OP_EXPORT_DONE
;
2157 /* add output to bytecode */
2159 for (i
= 0; i
< noutput
; i
++) {
2160 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
2167 /* add program end */
2169 if (ctx
.bc
->chip_class
== CAYMAN
)
2170 cm_bytecode_add_cf_end(ctx
.bc
);
2172 const struct cf_op_info
*last
= NULL
;
2174 if (ctx
.bc
->cf_last
)
2175 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
2177 /* alu clause instructions don't have EOP bit, so add NOP */
2178 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
)
2179 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2181 ctx
.bc
->cf_last
->end_of_program
= 1;
2185 /* check GPR limit - we have 124 = 128 - 4
2186 * (4 are reserved as alu clause temporary registers) */
2187 if (ctx
.bc
->ngpr
> 124) {
2188 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
2193 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2194 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
2199 tgsi_parse_free(&ctx
.parse
);
2203 tgsi_parse_free(&ctx
.parse
);
2207 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
2209 R600_ERR("%s tgsi opcode unsupported\n",
2210 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
2214 static int tgsi_end(struct r600_shader_ctx
*ctx
)
2219 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
2220 const struct r600_shader_src
*shader_src
,
2223 bc_src
->sel
= shader_src
->sel
;
2224 bc_src
->chan
= shader_src
->swizzle
[chan
];
2225 bc_src
->neg
= shader_src
->neg
;
2226 bc_src
->abs
= shader_src
->abs
;
2227 bc_src
->rel
= shader_src
->rel
;
2228 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
2229 bc_src
->kc_bank
= shader_src
->kc_bank
;
2232 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2238 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2240 bc_src
->neg
= !bc_src
->neg
;
2243 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2244 const struct tgsi_full_dst_register
*tgsi_dst
,
2246 struct r600_bytecode_alu_dst
*r600_dst
)
2248 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2250 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2251 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2252 r600_dst
->chan
= swizzle
;
2253 r600_dst
->write
= 1;
2254 if (tgsi_dst
->Register
.Indirect
)
2255 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2256 if (inst
->Instruction
.Saturate
) {
2257 r600_dst
->clamp
= 1;
2261 static int tgsi_last_instruction(unsigned writemask
)
2265 for (i
= 0; i
< 4; i
++) {
2266 if (writemask
& (1 << i
)) {
2273 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
2275 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2276 struct r600_bytecode_alu alu
;
2277 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2278 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2279 /* use temp register if trans_only and more than one dst component */
2280 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
2282 for (i
= 0; i
<= lasti
; i
++) {
2283 if (!(write_mask
& (1 << i
)))
2286 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2288 alu
.dst
.sel
= ctx
->temp_reg
;
2292 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2294 alu
.op
= ctx
->inst_info
->op
;
2296 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2297 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2300 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2301 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2303 /* handle some special cases */
2304 switch (ctx
->inst_info
->tgsi_opcode
) {
2305 case TGSI_OPCODE_SUB
:
2306 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2308 case TGSI_OPCODE_ABS
:
2309 r600_bytecode_src_set_abs(&alu
.src
[0]);
2314 if (i
== lasti
|| trans_only
) {
2317 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2323 /* move result from temp to dst */
2324 for (i
= 0; i
<= lasti
; i
++) {
2325 if (!(write_mask
& (1 << i
)))
2328 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2329 alu
.op
= ALU_OP1_MOV
;
2330 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2331 alu
.src
[0].sel
= ctx
->temp_reg
;
2332 alu
.src
[0].chan
= i
;
2333 alu
.last
= (i
== lasti
);
2335 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2343 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2345 return tgsi_op2_s(ctx
, 0, 0);
2348 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2350 return tgsi_op2_s(ctx
, 1, 0);
2353 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2355 return tgsi_op2_s(ctx
, 0, 1);
2358 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2360 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2361 struct r600_bytecode_alu alu
;
2363 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2365 for (i
= 0; i
< lasti
+ 1; i
++) {
2367 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2369 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2370 alu
.op
= ctx
->inst_info
->op
;
2372 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2374 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2376 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2381 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2389 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2391 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2393 struct r600_bytecode_alu alu
;
2394 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2396 for (i
= 0 ; i
< last_slot
; i
++) {
2397 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2398 alu
.op
= ctx
->inst_info
->op
;
2399 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2400 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2402 /* RSQ should take the absolute value of src */
2403 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2404 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2407 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2408 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2410 if (i
== last_slot
- 1)
2412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2419 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2421 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2423 struct r600_bytecode_alu alu
;
2424 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2425 for (k
= 0; k
< last_slot
; k
++) {
2426 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2429 for (i
= 0 ; i
< 4; i
++) {
2430 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2431 alu
.op
= ctx
->inst_info
->op
;
2432 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2433 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2435 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2436 alu
.dst
.write
= (i
== k
);
2439 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2448 * r600 - trunc to -PI..PI range
2449 * r700 - normalize by dividing by 2PI
2452 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2454 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2455 static float double_pi
= 3.1415926535 * 2;
2456 static float neg_pi
= -3.1415926535;
2459 struct r600_bytecode_alu alu
;
2461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2462 alu
.op
= ALU_OP3_MULADD
;
2466 alu
.dst
.sel
= ctx
->temp_reg
;
2469 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2471 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2472 alu
.src
[1].chan
= 0;
2473 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2474 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2475 alu
.src
[2].chan
= 0;
2477 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2482 alu
.op
= ALU_OP1_FRACT
;
2485 alu
.dst
.sel
= ctx
->temp_reg
;
2488 alu
.src
[0].sel
= ctx
->temp_reg
;
2489 alu
.src
[0].chan
= 0;
2491 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2495 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2496 alu
.op
= ALU_OP3_MULADD
;
2500 alu
.dst
.sel
= ctx
->temp_reg
;
2503 alu
.src
[0].sel
= ctx
->temp_reg
;
2504 alu
.src
[0].chan
= 0;
2506 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2507 alu
.src
[1].chan
= 0;
2508 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2509 alu
.src
[2].chan
= 0;
2511 if (ctx
->bc
->chip_class
== R600
) {
2512 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2513 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2515 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2516 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2521 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2527 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2529 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2530 struct r600_bytecode_alu alu
;
2531 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2534 r
= tgsi_setup_trig(ctx
);
2539 for (i
= 0; i
< last_slot
; i
++) {
2540 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2541 alu
.op
= ctx
->inst_info
->op
;
2544 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2545 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2547 alu
.src
[0].sel
= ctx
->temp_reg
;
2548 alu
.src
[0].chan
= 0;
2549 if (i
== last_slot
- 1)
2551 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2558 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2560 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2561 struct r600_bytecode_alu alu
;
2563 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2565 r
= tgsi_setup_trig(ctx
);
2569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2570 alu
.op
= ctx
->inst_info
->op
;
2572 alu
.dst
.sel
= ctx
->temp_reg
;
2575 alu
.src
[0].sel
= ctx
->temp_reg
;
2576 alu
.src
[0].chan
= 0;
2578 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2582 /* replicate result */
2583 for (i
= 0; i
< lasti
+ 1; i
++) {
2584 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2587 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2588 alu
.op
= ALU_OP1_MOV
;
2590 alu
.src
[0].sel
= ctx
->temp_reg
;
2591 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2594 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2601 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2603 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2604 struct r600_bytecode_alu alu
;
2607 /* We'll only need the trig stuff if we are going to write to the
2608 * X or Y components of the destination vector.
2610 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2611 r
= tgsi_setup_trig(ctx
);
2617 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2618 if (ctx
->bc
->chip_class
== CAYMAN
) {
2619 for (i
= 0 ; i
< 3; i
++) {
2620 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2621 alu
.op
= ALU_OP1_COS
;
2622 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2628 alu
.src
[0].sel
= ctx
->temp_reg
;
2629 alu
.src
[0].chan
= 0;
2632 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2637 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2638 alu
.op
= ALU_OP1_COS
;
2639 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2641 alu
.src
[0].sel
= ctx
->temp_reg
;
2642 alu
.src
[0].chan
= 0;
2644 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2651 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2652 if (ctx
->bc
->chip_class
== CAYMAN
) {
2653 for (i
= 0 ; i
< 3; i
++) {
2654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2655 alu
.op
= ALU_OP1_SIN
;
2656 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2661 alu
.src
[0].sel
= ctx
->temp_reg
;
2662 alu
.src
[0].chan
= 0;
2665 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2670 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2671 alu
.op
= ALU_OP1_SIN
;
2672 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2674 alu
.src
[0].sel
= ctx
->temp_reg
;
2675 alu
.src
[0].chan
= 0;
2677 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2684 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2685 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2687 alu
.op
= ALU_OP1_MOV
;
2689 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2691 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2692 alu
.src
[0].chan
= 0;
2696 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2702 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2703 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2705 alu
.op
= ALU_OP1_MOV
;
2707 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2709 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2710 alu
.src
[0].chan
= 0;
2714 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2722 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2724 struct r600_bytecode_alu alu
;
2727 for (i
= 0; i
< 4; i
++) {
2728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2729 alu
.op
= ctx
->inst_info
->op
;
2733 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2735 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILL
) {
2736 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2739 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2744 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2749 /* kill must be last in ALU */
2750 ctx
->bc
->force_add_cf
= 1;
2751 ctx
->shader
->uses_kill
= TRUE
;
2755 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2757 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2758 struct r600_bytecode_alu alu
;
2761 /* tmp.x = max(src.y, 0.0) */
2762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2763 alu
.op
= ALU_OP2_MAX
;
2764 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2765 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2766 alu
.src
[1].chan
= 1;
2768 alu
.dst
.sel
= ctx
->temp_reg
;
2773 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2777 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2783 if (ctx
->bc
->chip_class
== CAYMAN
) {
2784 for (i
= 0; i
< 3; i
++) {
2785 /* tmp.z = log(tmp.x) */
2786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2787 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2788 alu
.src
[0].sel
= ctx
->temp_reg
;
2789 alu
.src
[0].chan
= 0;
2790 alu
.dst
.sel
= ctx
->temp_reg
;
2798 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2803 /* tmp.z = log(tmp.x) */
2804 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2805 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2806 alu
.src
[0].sel
= ctx
->temp_reg
;
2807 alu
.src
[0].chan
= 0;
2808 alu
.dst
.sel
= ctx
->temp_reg
;
2812 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2817 chan
= alu
.dst
.chan
;
2820 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2821 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2822 alu
.op
= ALU_OP3_MUL_LIT
;
2823 alu
.src
[0].sel
= sel
;
2824 alu
.src
[0].chan
= chan
;
2825 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2826 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2827 alu
.dst
.sel
= ctx
->temp_reg
;
2832 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2836 if (ctx
->bc
->chip_class
== CAYMAN
) {
2837 for (i
= 0; i
< 3; i
++) {
2838 /* dst.z = exp(tmp.x) */
2839 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2840 alu
.op
= ALU_OP1_EXP_IEEE
;
2841 alu
.src
[0].sel
= ctx
->temp_reg
;
2842 alu
.src
[0].chan
= 0;
2843 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2849 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2854 /* dst.z = exp(tmp.x) */
2855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2856 alu
.op
= ALU_OP1_EXP_IEEE
;
2857 alu
.src
[0].sel
= ctx
->temp_reg
;
2858 alu
.src
[0].chan
= 0;
2859 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2861 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2868 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2869 alu
.op
= ALU_OP1_MOV
;
2870 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2871 alu
.src
[0].chan
= 0;
2872 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2873 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2874 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2878 /* dst.y = max(src.x, 0.0) */
2879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2880 alu
.op
= ALU_OP2_MAX
;
2881 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2882 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2883 alu
.src
[1].chan
= 0;
2884 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2885 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2886 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2891 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2892 alu
.op
= ALU_OP1_MOV
;
2893 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2894 alu
.src
[0].chan
= 0;
2895 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2896 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2898 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2905 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2907 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2908 struct r600_bytecode_alu alu
;
2911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2914 * For state trackers other than OpenGL, we'll want to use
2915 * _RECIPSQRT_IEEE instead.
2917 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2919 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2920 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2921 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2923 alu
.dst
.sel
= ctx
->temp_reg
;
2926 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2929 /* replicate result */
2930 return tgsi_helper_tempx_replicate(ctx
);
2933 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2935 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2936 struct r600_bytecode_alu alu
;
2939 for (i
= 0; i
< 4; i
++) {
2940 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2941 alu
.src
[0].sel
= ctx
->temp_reg
;
2942 alu
.op
= ALU_OP1_MOV
;
2944 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2945 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2948 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2955 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2957 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2958 struct r600_bytecode_alu alu
;
2961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2962 alu
.op
= ctx
->inst_info
->op
;
2963 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2964 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2966 alu
.dst
.sel
= ctx
->temp_reg
;
2969 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2972 /* replicate result */
2973 return tgsi_helper_tempx_replicate(ctx
);
2976 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2978 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2980 struct r600_bytecode_alu alu
;
2981 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2983 for (i
= 0; i
< 3; i
++) {
2984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2985 alu
.op
= ALU_OP1_LOG_IEEE
;
2986 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2987 alu
.dst
.sel
= ctx
->temp_reg
;
2992 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2999 alu
.op
= ALU_OP2_MUL
;
3000 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
3001 alu
.src
[1].sel
= ctx
->temp_reg
;
3002 alu
.dst
.sel
= ctx
->temp_reg
;
3005 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3009 for (i
= 0; i
< last_slot
; i
++) {
3010 /* POW(a,b) = EXP2(b * LOG2(a))*/
3011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3012 alu
.op
= ALU_OP1_EXP_IEEE
;
3013 alu
.src
[0].sel
= ctx
->temp_reg
;
3015 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3016 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3017 if (i
== last_slot
- 1)
3019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3026 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
3028 struct r600_bytecode_alu alu
;
3032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3033 alu
.op
= ALU_OP1_LOG_IEEE
;
3034 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3035 alu
.dst
.sel
= ctx
->temp_reg
;
3038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3042 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3043 alu
.op
= ALU_OP2_MUL
;
3044 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
3045 alu
.src
[1].sel
= ctx
->temp_reg
;
3046 alu
.dst
.sel
= ctx
->temp_reg
;
3049 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3052 /* POW(a,b) = EXP2(b * LOG2(a))*/
3053 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3054 alu
.op
= ALU_OP1_EXP_IEEE
;
3055 alu
.src
[0].sel
= ctx
->temp_reg
;
3056 alu
.dst
.sel
= ctx
->temp_reg
;
3059 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3062 return tgsi_helper_tempx_replicate(ctx
);
3065 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
3067 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3068 struct r600_bytecode_alu alu
;
3070 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3071 int tmp0
= ctx
->temp_reg
;
3072 int tmp1
= r600_get_temp(ctx
);
3073 int tmp2
= r600_get_temp(ctx
);
3074 int tmp3
= r600_get_temp(ctx
);
3077 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
3079 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
3080 * 2. tmp0.z = lo (tmp0.x * src2)
3081 * 3. tmp0.w = -tmp0.z
3082 * 4. tmp0.y = hi (tmp0.x * src2)
3083 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
3084 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
3085 * 7. tmp1.x = tmp0.x - tmp0.w
3086 * 8. tmp1.y = tmp0.x + tmp0.w
3087 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
3088 * 10. tmp0.z = hi(tmp0.x * src1) = q
3089 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
3091 * 12. tmp0.w = src1 - tmp0.y = r
3092 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
3093 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
3097 * 15. tmp1.z = tmp0.z + 1 = q + 1
3098 * 16. tmp1.w = tmp0.z - 1 = q - 1
3102 * 15. tmp1.z = tmp0.w - src2 = r - src2
3103 * 16. tmp1.w = tmp0.w + src2 = r + src2
3107 * 17. tmp1.x = tmp1.x & tmp1.y
3109 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
3110 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
3112 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
3113 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
3117 * Same as unsigned, using abs values of the operands,
3118 * and fixing the sign of the result in the end.
3121 for (i
= 0; i
< 4; i
++) {
3122 if (!(write_mask
& (1<<i
)))
3127 /* tmp2.x = -src0 */
3128 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3129 alu
.op
= ALU_OP2_SUB_INT
;
3135 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3137 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3140 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3143 /* tmp2.y = -src1 */
3144 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3145 alu
.op
= ALU_OP2_SUB_INT
;
3151 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3153 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3156 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3159 /* tmp2.z sign bit is set if src0 and src2 signs are different */
3160 /* it will be a sign of the quotient */
3163 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3164 alu
.op
= ALU_OP2_XOR_INT
;
3170 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3171 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3174 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3178 /* tmp2.x = |src0| */
3179 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3180 alu
.op
= ALU_OP3_CNDGE_INT
;
3187 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3188 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3189 alu
.src
[2].sel
= tmp2
;
3190 alu
.src
[2].chan
= 0;
3193 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3196 /* tmp2.y = |src1| */
3197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3198 alu
.op
= ALU_OP3_CNDGE_INT
;
3205 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3206 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3207 alu
.src
[2].sel
= tmp2
;
3208 alu
.src
[2].chan
= 1;
3211 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3216 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
3217 if (ctx
->bc
->chip_class
== CAYMAN
) {
3218 /* tmp3.x = u2f(src2) */
3219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3220 alu
.op
= ALU_OP1_UINT_TO_FLT
;
3227 alu
.src
[0].sel
= tmp2
;
3228 alu
.src
[0].chan
= 1;
3230 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3234 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3237 /* tmp0.x = recip(tmp3.x) */
3238 for (j
= 0 ; j
< 3; j
++) {
3239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3240 alu
.op
= ALU_OP1_RECIP_IEEE
;
3244 alu
.dst
.write
= (j
== 0);
3246 alu
.src
[0].sel
= tmp3
;
3247 alu
.src
[0].chan
= 0;
3251 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3255 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3256 alu
.op
= ALU_OP2_MUL
;
3258 alu
.src
[0].sel
= tmp0
;
3259 alu
.src
[0].chan
= 0;
3261 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3262 alu
.src
[1].value
= 0x4f800000;
3267 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3272 alu
.op
= ALU_OP1_FLT_TO_UINT
;
3278 alu
.src
[0].sel
= tmp3
;
3279 alu
.src
[0].chan
= 0;
3282 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3286 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3287 alu
.op
= ALU_OP1_RECIP_UINT
;
3294 alu
.src
[0].sel
= tmp2
;
3295 alu
.src
[0].chan
= 1;
3297 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3301 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3305 /* 2. tmp0.z = lo (tmp0.x * src2) */
3306 if (ctx
->bc
->chip_class
== CAYMAN
) {
3307 for (j
= 0 ; j
< 4; j
++) {
3308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3309 alu
.op
= ALU_OP2_MULLO_UINT
;
3313 alu
.dst
.write
= (j
== 2);
3315 alu
.src
[0].sel
= tmp0
;
3316 alu
.src
[0].chan
= 0;
3318 alu
.src
[1].sel
= tmp2
;
3319 alu
.src
[1].chan
= 1;
3321 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3324 alu
.last
= (j
== 3);
3325 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3329 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3330 alu
.op
= ALU_OP2_MULLO_UINT
;
3336 alu
.src
[0].sel
= tmp0
;
3337 alu
.src
[0].chan
= 0;
3339 alu
.src
[1].sel
= tmp2
;
3340 alu
.src
[1].chan
= 1;
3342 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3346 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3350 /* 3. tmp0.w = -tmp0.z */
3351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3352 alu
.op
= ALU_OP2_SUB_INT
;
3358 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3359 alu
.src
[1].sel
= tmp0
;
3360 alu
.src
[1].chan
= 2;
3363 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3366 /* 4. tmp0.y = hi (tmp0.x * src2) */
3367 if (ctx
->bc
->chip_class
== CAYMAN
) {
3368 for (j
= 0 ; j
< 4; j
++) {
3369 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3370 alu
.op
= ALU_OP2_MULHI_UINT
;
3374 alu
.dst
.write
= (j
== 1);
3376 alu
.src
[0].sel
= tmp0
;
3377 alu
.src
[0].chan
= 0;
3380 alu
.src
[1].sel
= tmp2
;
3381 alu
.src
[1].chan
= 1;
3383 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3385 alu
.last
= (j
== 3);
3386 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3391 alu
.op
= ALU_OP2_MULHI_UINT
;
3397 alu
.src
[0].sel
= tmp0
;
3398 alu
.src
[0].chan
= 0;
3401 alu
.src
[1].sel
= tmp2
;
3402 alu
.src
[1].chan
= 1;
3404 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3408 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3412 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3413 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3414 alu
.op
= ALU_OP3_CNDE_INT
;
3421 alu
.src
[0].sel
= tmp0
;
3422 alu
.src
[0].chan
= 1;
3423 alu
.src
[1].sel
= tmp0
;
3424 alu
.src
[1].chan
= 3;
3425 alu
.src
[2].sel
= tmp0
;
3426 alu
.src
[2].chan
= 2;
3429 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3432 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3433 if (ctx
->bc
->chip_class
== CAYMAN
) {
3434 for (j
= 0 ; j
< 4; j
++) {
3435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3436 alu
.op
= ALU_OP2_MULHI_UINT
;
3440 alu
.dst
.write
= (j
== 3);
3442 alu
.src
[0].sel
= tmp0
;
3443 alu
.src
[0].chan
= 2;
3445 alu
.src
[1].sel
= tmp0
;
3446 alu
.src
[1].chan
= 0;
3448 alu
.last
= (j
== 3);
3449 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3453 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3454 alu
.op
= ALU_OP2_MULHI_UINT
;
3460 alu
.src
[0].sel
= tmp0
;
3461 alu
.src
[0].chan
= 2;
3463 alu
.src
[1].sel
= tmp0
;
3464 alu
.src
[1].chan
= 0;
3467 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3471 /* 7. tmp1.x = tmp0.x - tmp0.w */
3472 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3473 alu
.op
= ALU_OP2_SUB_INT
;
3479 alu
.src
[0].sel
= tmp0
;
3480 alu
.src
[0].chan
= 0;
3481 alu
.src
[1].sel
= tmp0
;
3482 alu
.src
[1].chan
= 3;
3485 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3488 /* 8. tmp1.y = tmp0.x + tmp0.w */
3489 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3490 alu
.op
= ALU_OP2_ADD_INT
;
3496 alu
.src
[0].sel
= tmp0
;
3497 alu
.src
[0].chan
= 0;
3498 alu
.src
[1].sel
= tmp0
;
3499 alu
.src
[1].chan
= 3;
3502 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3505 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3507 alu
.op
= ALU_OP3_CNDE_INT
;
3514 alu
.src
[0].sel
= tmp0
;
3515 alu
.src
[0].chan
= 1;
3516 alu
.src
[1].sel
= tmp1
;
3517 alu
.src
[1].chan
= 1;
3518 alu
.src
[2].sel
= tmp1
;
3519 alu
.src
[2].chan
= 0;
3522 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3525 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3526 if (ctx
->bc
->chip_class
== CAYMAN
) {
3527 for (j
= 0 ; j
< 4; j
++) {
3528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3529 alu
.op
= ALU_OP2_MULHI_UINT
;
3533 alu
.dst
.write
= (j
== 2);
3535 alu
.src
[0].sel
= tmp0
;
3536 alu
.src
[0].chan
= 0;
3539 alu
.src
[1].sel
= tmp2
;
3540 alu
.src
[1].chan
= 0;
3542 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3545 alu
.last
= (j
== 3);
3546 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3550 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3551 alu
.op
= ALU_OP2_MULHI_UINT
;
3557 alu
.src
[0].sel
= tmp0
;
3558 alu
.src
[0].chan
= 0;
3561 alu
.src
[1].sel
= tmp2
;
3562 alu
.src
[1].chan
= 0;
3564 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3568 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3572 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3573 if (ctx
->bc
->chip_class
== CAYMAN
) {
3574 for (j
= 0 ; j
< 4; j
++) {
3575 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3576 alu
.op
= ALU_OP2_MULLO_UINT
;
3580 alu
.dst
.write
= (j
== 1);
3583 alu
.src
[0].sel
= tmp2
;
3584 alu
.src
[0].chan
= 1;
3586 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3589 alu
.src
[1].sel
= tmp0
;
3590 alu
.src
[1].chan
= 2;
3592 alu
.last
= (j
== 3);
3593 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3597 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3598 alu
.op
= ALU_OP2_MULLO_UINT
;
3605 alu
.src
[0].sel
= tmp2
;
3606 alu
.src
[0].chan
= 1;
3608 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3611 alu
.src
[1].sel
= tmp0
;
3612 alu
.src
[1].chan
= 2;
3615 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3619 /* 12. tmp0.w = src1 - tmp0.y = r */
3620 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3621 alu
.op
= ALU_OP2_SUB_INT
;
3628 alu
.src
[0].sel
= tmp2
;
3629 alu
.src
[0].chan
= 0;
3631 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3634 alu
.src
[1].sel
= tmp0
;
3635 alu
.src
[1].chan
= 1;
3638 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3641 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3642 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3643 alu
.op
= ALU_OP2_SETGE_UINT
;
3649 alu
.src
[0].sel
= tmp0
;
3650 alu
.src
[0].chan
= 3;
3652 alu
.src
[1].sel
= tmp2
;
3653 alu
.src
[1].chan
= 1;
3655 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3659 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3662 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3663 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3664 alu
.op
= ALU_OP2_SETGE_UINT
;
3671 alu
.src
[0].sel
= tmp2
;
3672 alu
.src
[0].chan
= 0;
3674 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3677 alu
.src
[1].sel
= tmp0
;
3678 alu
.src
[1].chan
= 1;
3681 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3684 if (mod
) { /* UMOD */
3686 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3688 alu
.op
= ALU_OP2_SUB_INT
;
3694 alu
.src
[0].sel
= tmp0
;
3695 alu
.src
[0].chan
= 3;
3698 alu
.src
[1].sel
= tmp2
;
3699 alu
.src
[1].chan
= 1;
3701 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3705 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3708 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3710 alu
.op
= ALU_OP2_ADD_INT
;
3716 alu
.src
[0].sel
= tmp0
;
3717 alu
.src
[0].chan
= 3;
3719 alu
.src
[1].sel
= tmp2
;
3720 alu
.src
[1].chan
= 1;
3722 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3726 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3731 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3733 alu
.op
= ALU_OP2_ADD_INT
;
3739 alu
.src
[0].sel
= tmp0
;
3740 alu
.src
[0].chan
= 2;
3741 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3744 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3747 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3748 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3749 alu
.op
= ALU_OP2_ADD_INT
;
3755 alu
.src
[0].sel
= tmp0
;
3756 alu
.src
[0].chan
= 2;
3757 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3760 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3765 /* 17. tmp1.x = tmp1.x & tmp1.y */
3766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3767 alu
.op
= ALU_OP2_AND_INT
;
3773 alu
.src
[0].sel
= tmp1
;
3774 alu
.src
[0].chan
= 0;
3775 alu
.src
[1].sel
= tmp1
;
3776 alu
.src
[1].chan
= 1;
3779 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3782 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3783 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3784 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3785 alu
.op
= ALU_OP3_CNDE_INT
;
3792 alu
.src
[0].sel
= tmp1
;
3793 alu
.src
[0].chan
= 0;
3794 alu
.src
[1].sel
= tmp0
;
3795 alu
.src
[1].chan
= mod
? 3 : 2;
3796 alu
.src
[2].sel
= tmp1
;
3797 alu
.src
[2].chan
= 2;
3800 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3803 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3804 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3805 alu
.op
= ALU_OP3_CNDE_INT
;
3813 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3816 alu
.src
[0].sel
= tmp1
;
3817 alu
.src
[0].chan
= 1;
3818 alu
.src
[1].sel
= tmp1
;
3819 alu
.src
[1].chan
= 3;
3820 alu
.src
[2].sel
= tmp0
;
3821 alu
.src
[2].chan
= 2;
3824 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3829 /* fix the sign of the result */
3833 /* tmp0.x = -tmp0.z */
3834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3835 alu
.op
= ALU_OP2_SUB_INT
;
3841 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3842 alu
.src
[1].sel
= tmp0
;
3843 alu
.src
[1].chan
= 2;
3846 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3849 /* sign of the remainder is the same as the sign of src0 */
3850 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3852 alu
.op
= ALU_OP3_CNDGE_INT
;
3855 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3857 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3858 alu
.src
[1].sel
= tmp0
;
3859 alu
.src
[1].chan
= 2;
3860 alu
.src
[2].sel
= tmp0
;
3861 alu
.src
[2].chan
= 0;
3864 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3869 /* tmp0.x = -tmp0.z */
3870 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3871 alu
.op
= ALU_OP2_SUB_INT
;
3877 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3878 alu
.src
[1].sel
= tmp0
;
3879 alu
.src
[1].chan
= 2;
3882 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3885 /* fix the quotient sign (same as the sign of src0*src1) */
3886 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3887 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3888 alu
.op
= ALU_OP3_CNDGE_INT
;
3891 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3893 alu
.src
[0].sel
= tmp2
;
3894 alu
.src
[0].chan
= 2;
3895 alu
.src
[1].sel
= tmp0
;
3896 alu
.src
[1].chan
= 2;
3897 alu
.src
[2].sel
= tmp0
;
3898 alu
.src
[2].chan
= 0;
3901 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3909 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3911 return tgsi_divmod(ctx
, 0, 0);
3914 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3916 return tgsi_divmod(ctx
, 1, 0);
3919 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3921 return tgsi_divmod(ctx
, 0, 1);
3924 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3926 return tgsi_divmod(ctx
, 1, 1);
3930 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3932 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3933 struct r600_bytecode_alu alu
;
3935 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3936 int last_inst
= tgsi_last_instruction(write_mask
);
3938 for (i
= 0; i
< 4; i
++) {
3939 if (!(write_mask
& (1<<i
)))
3942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3943 alu
.op
= ALU_OP1_TRUNC
;
3945 alu
.dst
.sel
= ctx
->temp_reg
;
3949 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3952 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3957 for (i
= 0; i
< 4; i
++) {
3958 if (!(write_mask
& (1<<i
)))
3961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3962 alu
.op
= ctx
->inst_info
->op
;
3964 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3966 alu
.src
[0].sel
= ctx
->temp_reg
;
3967 alu
.src
[0].chan
= i
;
3969 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3971 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3979 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3981 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3982 struct r600_bytecode_alu alu
;
3984 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3985 int last_inst
= tgsi_last_instruction(write_mask
);
3988 for (i
= 0; i
< 4; i
++) {
3989 if (!(write_mask
& (1<<i
)))
3992 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3993 alu
.op
= ALU_OP2_SUB_INT
;
3995 alu
.dst
.sel
= ctx
->temp_reg
;
3999 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4000 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4004 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4009 /* dst = (src >= 0 ? src : tmp) */
4010 for (i
= 0; i
< 4; i
++) {
4011 if (!(write_mask
& (1<<i
)))
4014 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4015 alu
.op
= ALU_OP3_CNDGE_INT
;
4019 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4021 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4022 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4023 alu
.src
[2].sel
= ctx
->temp_reg
;
4024 alu
.src
[2].chan
= i
;
4028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4035 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
4037 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4038 struct r600_bytecode_alu alu
;
4040 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4041 int last_inst
= tgsi_last_instruction(write_mask
);
4043 /* tmp = (src >= 0 ? src : -1) */
4044 for (i
= 0; i
< 4; i
++) {
4045 if (!(write_mask
& (1<<i
)))
4048 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4049 alu
.op
= ALU_OP3_CNDGE_INT
;
4052 alu
.dst
.sel
= ctx
->temp_reg
;
4056 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4057 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4058 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
4062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4067 /* dst = (tmp > 0 ? 1 : tmp) */
4068 for (i
= 0; i
< 4; i
++) {
4069 if (!(write_mask
& (1<<i
)))
4072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4073 alu
.op
= ALU_OP3_CNDGT_INT
;
4077 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4079 alu
.src
[0].sel
= ctx
->temp_reg
;
4080 alu
.src
[0].chan
= i
;
4082 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
4084 alu
.src
[2].sel
= ctx
->temp_reg
;
4085 alu
.src
[2].chan
= i
;
4089 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4098 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
4100 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4101 struct r600_bytecode_alu alu
;
4104 /* tmp = (src > 0 ? 1 : src) */
4105 for (i
= 0; i
< 4; i
++) {
4106 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4107 alu
.op
= ALU_OP3_CNDGT
;
4110 alu
.dst
.sel
= ctx
->temp_reg
;
4113 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4114 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4115 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
4119 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4124 /* dst = (-tmp > 0 ? -1 : tmp) */
4125 for (i
= 0; i
< 4; i
++) {
4126 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4127 alu
.op
= ALU_OP3_CNDGT
;
4129 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4131 alu
.src
[0].sel
= ctx
->temp_reg
;
4132 alu
.src
[0].chan
= i
;
4135 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4138 alu
.src
[2].sel
= ctx
->temp_reg
;
4139 alu
.src
[2].chan
= i
;
4143 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4150 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
4152 struct r600_bytecode_alu alu
;
4155 for (i
= 0; i
< 4; i
++) {
4156 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4157 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
4158 alu
.op
= ALU_OP0_NOP
;
4161 alu
.op
= ALU_OP1_MOV
;
4162 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4163 alu
.src
[0].sel
= ctx
->temp_reg
;
4164 alu
.src
[0].chan
= i
;
4169 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4176 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
4178 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4179 struct r600_bytecode_alu alu
;
4181 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4183 for (i
= 0; i
< lasti
+ 1; i
++) {
4184 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4188 alu
.op
= ctx
->inst_info
->op
;
4189 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4190 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4193 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4207 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
4209 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4210 struct r600_bytecode_alu alu
;
4213 for (i
= 0; i
< 4; i
++) {
4214 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4215 alu
.op
= ctx
->inst_info
->op
;
4216 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4217 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4220 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4222 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4223 /* handle some special cases */
4224 switch (ctx
->inst_info
->tgsi_opcode
) {
4225 case TGSI_OPCODE_DP2
:
4227 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4228 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4231 case TGSI_OPCODE_DP3
:
4233 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4234 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4237 case TGSI_OPCODE_DPH
:
4239 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4240 alu
.src
[0].chan
= 0;
4250 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4257 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
4260 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4261 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
4262 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
4263 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
4264 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
4267 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
4270 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4271 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
4274 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
4276 struct r600_bytecode_vtx vtx
;
4277 struct r600_bytecode_alu alu
;
4278 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4280 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4282 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4283 if (src_requires_loading
) {
4284 for (i
= 0; i
< 4; i
++) {
4285 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4286 alu
.op
= ALU_OP1_MOV
;
4287 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4288 alu
.dst
.sel
= ctx
->temp_reg
;
4293 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4297 src_gpr
= ctx
->temp_reg
;
4300 memset(&vtx
, 0, sizeof(vtx
));
4301 vtx
.op
= FETCH_OP_VFETCH
;
4302 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
4303 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
4304 vtx
.src_gpr
= src_gpr
;
4305 vtx
.mega_fetch_count
= 16;
4306 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4307 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
4308 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
4309 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4310 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4311 vtx
.use_const_fields
= 1;
4312 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4314 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4317 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4320 for (i
= 0; i
< 4; i
++) {
4321 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4322 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4326 alu
.op
= ALU_OP2_AND_INT
;
4329 alu
.dst
.sel
= vtx
.dst_gpr
;
4332 alu
.src
[0].sel
= vtx
.dst_gpr
;
4333 alu
.src
[0].chan
= i
;
4335 alu
.src
[1].sel
= 512 + (id
* 2);
4336 alu
.src
[1].chan
= i
% 4;
4337 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4341 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4346 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4348 alu
.op
= ALU_OP2_OR_INT
;
4351 alu
.dst
.sel
= vtx
.dst_gpr
;
4354 alu
.src
[0].sel
= vtx
.dst_gpr
;
4355 alu
.src
[0].chan
= 3;
4357 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4358 alu
.src
[1].chan
= 0;
4359 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4362 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4369 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4371 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4372 struct r600_bytecode_alu alu
;
4374 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4377 alu
.op
= ALU_OP1_MOV
;
4379 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4380 alu
.src
[0].sel
= 512 + (id
/ 4);
4381 alu
.src
[0].chan
= id
% 4;
4383 /* r600 we have them at channel 2 of the second dword */
4384 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4385 alu
.src
[0].chan
= 1;
4387 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4388 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4390 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4396 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4398 static float one_point_five
= 1.5f
;
4399 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4400 struct r600_bytecode_tex tex
;
4401 struct r600_bytecode_alu alu
;
4405 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
4406 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4407 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4408 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4410 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
4411 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4412 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
4414 /* Texture fetch instructions can only use gprs as source.
4415 * Also they cannot negate the source or take the absolute value */
4416 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4417 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4418 read_compressed_msaa
|| txf_add_offsets
;
4420 boolean src_loaded
= FALSE
;
4421 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4422 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4423 boolean has_txq_cube_array_z
= false;
4425 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4426 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4427 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4428 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4429 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4430 has_txq_cube_array_z
= true;
4433 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4434 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4435 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4436 sampler_src_reg
= 2;
4438 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4440 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4441 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4442 ctx
->shader
->uses_tex_buffers
= true;
4443 return r600_do_buffer_txq(ctx
);
4445 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4446 if (ctx
->bc
->chip_class
< EVERGREEN
)
4447 ctx
->shader
->uses_tex_buffers
= true;
4448 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4452 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4453 /* TGSI moves the sampler to src reg 3 for TXD */
4454 sampler_src_reg
= 3;
4456 for (i
= 1; i
< 3; i
++) {
4457 /* set gradients h/v */
4458 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4459 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4460 FETCH_OP_SET_GRADIENTS_V
;
4461 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4462 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4464 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4465 tex
.src_gpr
= r600_get_temp(ctx
);
4471 for (j
= 0; j
< 4; j
++) {
4472 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4473 alu
.op
= ALU_OP1_MOV
;
4474 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4475 alu
.dst
.sel
= tex
.src_gpr
;
4480 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4486 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4487 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4488 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4489 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4490 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4491 tex
.src_rel
= ctx
->src
[i
].rel
;
4493 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4494 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4495 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4496 tex
.coord_type_x
= 1;
4497 tex
.coord_type_y
= 1;
4498 tex
.coord_type_z
= 1;
4499 tex
.coord_type_w
= 1;
4501 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4505 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4507 /* Add perspective divide */
4508 if (ctx
->bc
->chip_class
== CAYMAN
) {
4510 for (i
= 0; i
< 3; i
++) {
4511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4512 alu
.op
= ALU_OP1_RECIP_IEEE
;
4513 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4515 alu
.dst
.sel
= ctx
->temp_reg
;
4521 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4529 alu
.op
= ALU_OP1_RECIP_IEEE
;
4530 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4532 alu
.dst
.sel
= ctx
->temp_reg
;
4533 alu
.dst
.chan
= out_chan
;
4536 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4541 for (i
= 0; i
< 3; i
++) {
4542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4543 alu
.op
= ALU_OP2_MUL
;
4544 alu
.src
[0].sel
= ctx
->temp_reg
;
4545 alu
.src
[0].chan
= out_chan
;
4546 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4547 alu
.dst
.sel
= ctx
->temp_reg
;
4550 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4555 alu
.op
= ALU_OP1_MOV
;
4556 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4557 alu
.src
[0].chan
= 0;
4558 alu
.dst
.sel
= ctx
->temp_reg
;
4562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4566 src_gpr
= ctx
->temp_reg
;
4569 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4570 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4571 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4572 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4573 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4574 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4576 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4577 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4579 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4580 for (i
= 0; i
< 4; i
++) {
4581 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4582 alu
.op
= ALU_OP2_CUBE
;
4583 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4584 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4585 alu
.dst
.sel
= ctx
->temp_reg
;
4590 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4595 /* tmp1.z = RCP_e(|tmp1.z|) */
4596 if (ctx
->bc
->chip_class
== CAYMAN
) {
4597 for (i
= 0; i
< 3; i
++) {
4598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4599 alu
.op
= ALU_OP1_RECIP_IEEE
;
4600 alu
.src
[0].sel
= ctx
->temp_reg
;
4601 alu
.src
[0].chan
= 2;
4603 alu
.dst
.sel
= ctx
->temp_reg
;
4609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4615 alu
.op
= ALU_OP1_RECIP_IEEE
;
4616 alu
.src
[0].sel
= ctx
->temp_reg
;
4617 alu
.src
[0].chan
= 2;
4619 alu
.dst
.sel
= ctx
->temp_reg
;
4623 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4628 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4629 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4630 * muladd has no writemask, have to use another temp
4632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4633 alu
.op
= ALU_OP3_MULADD
;
4636 alu
.src
[0].sel
= ctx
->temp_reg
;
4637 alu
.src
[0].chan
= 0;
4638 alu
.src
[1].sel
= ctx
->temp_reg
;
4639 alu
.src
[1].chan
= 2;
4641 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4642 alu
.src
[2].chan
= 0;
4643 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4645 alu
.dst
.sel
= ctx
->temp_reg
;
4649 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4654 alu
.op
= ALU_OP3_MULADD
;
4657 alu
.src
[0].sel
= ctx
->temp_reg
;
4658 alu
.src
[0].chan
= 1;
4659 alu
.src
[1].sel
= ctx
->temp_reg
;
4660 alu
.src
[1].chan
= 2;
4662 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4663 alu
.src
[2].chan
= 0;
4664 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4666 alu
.dst
.sel
= ctx
->temp_reg
;
4671 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4674 /* write initial compare value into Z component
4675 - W src 0 for shadow cube
4676 - X src 1 for shadow cube array */
4677 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4678 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4679 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4680 alu
.op
= ALU_OP1_MOV
;
4681 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4682 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4684 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4685 alu
.dst
.sel
= ctx
->temp_reg
;
4689 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4694 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4695 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4696 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4697 int mytmp
= r600_get_temp(ctx
);
4698 static const float eight
= 8.0f
;
4699 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4700 alu
.op
= ALU_OP1_MOV
;
4701 alu
.src
[0].sel
= ctx
->temp_reg
;
4702 alu
.src
[0].chan
= 3;
4703 alu
.dst
.sel
= mytmp
;
4707 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4711 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4712 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4713 alu
.op
= ALU_OP3_MULADD
;
4715 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4716 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4717 alu
.src
[1].chan
= 0;
4718 alu
.src
[1].value
= *(uint32_t *)&eight
;
4719 alu
.src
[2].sel
= mytmp
;
4720 alu
.src
[2].chan
= 0;
4721 alu
.dst
.sel
= ctx
->temp_reg
;
4725 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4728 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4729 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4730 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4731 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4732 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4733 tex
.src_gpr
= r600_get_temp(ctx
);
4738 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4739 tex
.coord_type_x
= 1;
4740 tex
.coord_type_y
= 1;
4741 tex
.coord_type_z
= 1;
4742 tex
.coord_type_w
= 1;
4743 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4744 alu
.op
= ALU_OP1_MOV
;
4745 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4746 alu
.dst
.sel
= tex
.src_gpr
;
4750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4754 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4761 /* for cube forms of lod and bias we need to route things */
4762 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4763 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4764 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4765 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4767 alu
.op
= ALU_OP1_MOV
;
4768 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4769 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4770 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4772 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4773 alu
.dst
.sel
= ctx
->temp_reg
;
4777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4783 src_gpr
= ctx
->temp_reg
;
4786 if (src_requires_loading
&& !src_loaded
) {
4787 for (i
= 0; i
< 4; i
++) {
4788 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4789 alu
.op
= ALU_OP1_MOV
;
4790 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4791 alu
.dst
.sel
= ctx
->temp_reg
;
4796 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4801 src_gpr
= ctx
->temp_reg
;
4804 /* get offset values */
4805 if (inst
->Texture
.NumOffsets
) {
4806 assert(inst
->Texture
.NumOffsets
== 1);
4808 /* The texture offset feature doesn't work with the TXF instruction
4809 * and must be emulated by adding the offset to the texture coordinates. */
4810 if (txf_add_offsets
) {
4811 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
4813 switch (inst
->Texture
.Texture
) {
4814 case TGSI_TEXTURE_3D
:
4815 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4816 alu
.op
= ALU_OP2_ADD_INT
;
4817 alu
.src
[0].sel
= src_gpr
;
4818 alu
.src
[0].chan
= 2;
4819 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4820 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
4821 alu
.dst
.sel
= src_gpr
;
4825 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4830 case TGSI_TEXTURE_2D
:
4831 case TGSI_TEXTURE_SHADOW2D
:
4832 case TGSI_TEXTURE_RECT
:
4833 case TGSI_TEXTURE_SHADOWRECT
:
4834 case TGSI_TEXTURE_2D_ARRAY
:
4835 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
4836 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4837 alu
.op
= ALU_OP2_ADD_INT
;
4838 alu
.src
[0].sel
= src_gpr
;
4839 alu
.src
[0].chan
= 1;
4840 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4841 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
4842 alu
.dst
.sel
= src_gpr
;
4846 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4851 case TGSI_TEXTURE_1D
:
4852 case TGSI_TEXTURE_SHADOW1D
:
4853 case TGSI_TEXTURE_1D_ARRAY
:
4854 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
4855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4856 alu
.op
= ALU_OP2_ADD_INT
;
4857 alu
.src
[0].sel
= src_gpr
;
4858 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4859 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
4860 alu
.dst
.sel
= src_gpr
;
4863 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4867 /* texture offsets do not apply to other texture targets */
4870 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4871 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4872 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4876 /* Obtain the sample index for reading a compressed MSAA color texture.
4877 * To read the FMASK, we use the ldfptr instruction, which tells us
4878 * where the samples are stored.
4879 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4880 * which is the identity mapping. Each nibble says which physical sample
4881 * should be fetched to get that sample.
4883 * Assume src.z contains the sample index. It should be modified like this:
4884 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4885 * Then fetch the texel with src.
4887 if (read_compressed_msaa
) {
4888 unsigned sample_chan
= 3;
4889 unsigned temp
= r600_get_temp(ctx
);
4892 /* temp.w = ldfptr() */
4893 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4894 tex
.op
= FETCH_OP_LD
;
4895 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4896 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4897 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4898 tex
.src_gpr
= src_gpr
;
4900 tex
.dst_sel_x
= 7; /* mask out these components */
4903 tex
.dst_sel_w
= 0; /* store X */
4908 tex
.offset_x
= offset_x
;
4909 tex
.offset_y
= offset_y
;
4910 tex
.offset_z
= offset_z
;
4911 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4915 /* temp.x = sample_index*4 */
4916 if (ctx
->bc
->chip_class
== CAYMAN
) {
4917 for (i
= 0 ; i
< 4; i
++) {
4918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4919 alu
.op
= ALU_OP2_MULLO_INT
;
4920 alu
.src
[0].sel
= src_gpr
;
4921 alu
.src
[0].chan
= sample_chan
;
4922 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4923 alu
.src
[1].value
= 4;
4926 alu
.dst
.write
= i
== 0;
4929 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4934 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4935 alu
.op
= ALU_OP2_MULLO_INT
;
4936 alu
.src
[0].sel
= src_gpr
;
4937 alu
.src
[0].chan
= sample_chan
;
4938 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4939 alu
.src
[1].value
= 4;
4944 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4949 /* sample_index = temp.w >> temp.x */
4950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4951 alu
.op
= ALU_OP2_LSHR_INT
;
4952 alu
.src
[0].sel
= temp
;
4953 alu
.src
[0].chan
= 3;
4954 alu
.src
[1].sel
= temp
;
4955 alu
.src
[1].chan
= 0;
4956 alu
.dst
.sel
= src_gpr
;
4957 alu
.dst
.chan
= sample_chan
;
4960 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4964 /* sample_index & 0xF */
4965 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4966 alu
.op
= ALU_OP2_AND_INT
;
4967 alu
.src
[0].sel
= src_gpr
;
4968 alu
.src
[0].chan
= sample_chan
;
4969 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4970 alu
.src
[1].value
= 0xF;
4971 alu
.dst
.sel
= src_gpr
;
4972 alu
.dst
.chan
= sample_chan
;
4975 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4979 /* visualize the FMASK */
4980 for (i
= 0; i
< 4; i
++) {
4981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4982 alu
.op
= ALU_OP1_INT_TO_FLT
;
4983 alu
.src
[0].sel
= src_gpr
;
4984 alu
.src
[0].chan
= sample_chan
;
4985 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4997 /* does this shader want a num layers from TXQ for a cube array? */
4998 if (has_txq_cube_array_z
) {
4999 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
5001 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5002 alu
.op
= ALU_OP1_MOV
;
5004 alu
.src
[0].sel
= 512 + (id
/ 4);
5005 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
5006 alu
.src
[0].chan
= id
% 4;
5007 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5009 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5012 /* disable writemask from texture instruction */
5013 inst
->Dst
[0].Register
.WriteMask
&= ~4;
5016 opcode
= ctx
->inst_info
->op
;
5017 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
5018 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
5019 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
5020 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5021 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
5022 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
5023 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
5025 case FETCH_OP_SAMPLE
:
5026 opcode
= FETCH_OP_SAMPLE_C
;
5028 case FETCH_OP_SAMPLE_L
:
5029 opcode
= FETCH_OP_SAMPLE_C_L
;
5031 case FETCH_OP_SAMPLE_LB
:
5032 opcode
= FETCH_OP_SAMPLE_C_LB
;
5034 case FETCH_OP_SAMPLE_G
:
5035 opcode
= FETCH_OP_SAMPLE_C_G
;
5040 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
5043 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
5044 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
5045 tex
.src_gpr
= src_gpr
;
5046 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
5047 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
5048 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
5049 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
5050 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
5052 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
5057 } else if (src_loaded
) {
5063 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
5064 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
5065 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
5066 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
5067 tex
.src_rel
= ctx
->src
[0].rel
;
5070 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
5071 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5072 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5073 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
5077 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
5080 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
5081 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
5082 tex
.coord_type_x
= 1;
5083 tex
.coord_type_y
= 1;
5085 tex
.coord_type_z
= 1;
5086 tex
.coord_type_w
= 1;
5088 tex
.offset_x
= offset_x
;
5089 tex
.offset_y
= offset_y
;
5090 tex
.offset_z
= offset_z
;
5092 /* Put the depth for comparison in W.
5093 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
5094 * Some instructions expect the depth in Z. */
5095 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
5096 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
5097 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
5098 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
5099 opcode
!= FETCH_OP_SAMPLE_C_L
&&
5100 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
5101 tex
.src_sel_w
= tex
.src_sel_z
;
5104 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
5105 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
5106 if (opcode
== FETCH_OP_SAMPLE_C_L
||
5107 opcode
== FETCH_OP_SAMPLE_C_LB
) {
5108 /* the array index is read from Y */
5109 tex
.coord_type_y
= 0;
5111 /* the array index is read from Z */
5112 tex
.coord_type_z
= 0;
5113 tex
.src_sel_z
= tex
.src_sel_y
;
5115 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
5116 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
5117 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5118 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
5119 (ctx
->bc
->chip_class
>= EVERGREEN
)))
5120 /* the array index is read from Z */
5121 tex
.coord_type_z
= 0;
5123 /* mask unused source components */
5124 if (opcode
== FETCH_OP_SAMPLE
) {
5125 switch (inst
->Texture
.Texture
) {
5126 case TGSI_TEXTURE_2D
:
5127 case TGSI_TEXTURE_RECT
:
5131 case TGSI_TEXTURE_1D_ARRAY
:
5135 case TGSI_TEXTURE_1D
:
5143 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
5147 /* add shadow ambient support - gallium doesn't do it yet */
5151 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
5153 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5154 struct r600_bytecode_alu alu
;
5155 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5159 /* optimize if it's just an equal balance */
5160 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
5161 for (i
= 0; i
< lasti
+ 1; i
++) {
5162 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5166 alu
.op
= ALU_OP2_ADD
;
5167 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5168 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5170 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5183 for (i
= 0; i
< lasti
+ 1; i
++) {
5184 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5188 alu
.op
= ALU_OP2_ADD
;
5189 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5190 alu
.src
[0].chan
= 0;
5191 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5192 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
5193 alu
.dst
.sel
= ctx
->temp_reg
;
5199 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5204 /* (1 - src0) * src2 */
5205 for (i
= 0; i
< lasti
+ 1; i
++) {
5206 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5210 alu
.op
= ALU_OP2_MUL
;
5211 alu
.src
[0].sel
= ctx
->temp_reg
;
5212 alu
.src
[0].chan
= i
;
5213 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5214 alu
.dst
.sel
= ctx
->temp_reg
;
5220 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5225 /* src0 * src1 + (1 - src0) * src2 */
5226 for (i
= 0; i
< lasti
+ 1; i
++) {
5227 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5231 alu
.op
= ALU_OP3_MULADD
;
5233 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5234 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5235 alu
.src
[2].sel
= ctx
->temp_reg
;
5236 alu
.src
[2].chan
= i
;
5238 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5250 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
5252 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5253 struct r600_bytecode_alu alu
;
5255 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5257 for (i
= 0; i
< lasti
+ 1; i
++) {
5258 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5261 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5262 alu
.op
= ALU_OP3_CNDGE
;
5263 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5264 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5265 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
5266 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5272 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5279 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
5281 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5282 struct r600_bytecode_alu alu
;
5284 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5286 for (i
= 0; i
< lasti
+ 1; i
++) {
5287 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5290 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5291 alu
.op
= ALU_OP3_CNDGE_INT
;
5292 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5293 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5294 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
5295 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5301 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5308 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
5310 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5311 static const unsigned int src0_swizzle
[] = {2, 0, 1};
5312 static const unsigned int src1_swizzle
[] = {1, 2, 0};
5313 struct r600_bytecode_alu alu
;
5314 uint32_t use_temp
= 0;
5317 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
5320 for (i
= 0; i
< 4; i
++) {
5321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5322 alu
.op
= ALU_OP2_MUL
;
5324 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5325 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
5327 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5328 alu
.src
[0].chan
= i
;
5329 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5330 alu
.src
[1].chan
= i
;
5333 alu
.dst
.sel
= ctx
->temp_reg
;
5339 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5344 for (i
= 0; i
< 4; i
++) {
5345 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5346 alu
.op
= ALU_OP3_MULADD
;
5349 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
5350 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
5352 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5353 alu
.src
[0].chan
= i
;
5354 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5355 alu
.src
[1].chan
= i
;
5358 alu
.src
[2].sel
= ctx
->temp_reg
;
5360 alu
.src
[2].chan
= i
;
5363 alu
.dst
.sel
= ctx
->temp_reg
;
5365 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5371 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5376 return tgsi_helper_copy(ctx
, inst
);
5380 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
5382 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5383 struct r600_bytecode_alu alu
;
5387 /* result.x = 2^floor(src); */
5388 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5389 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5391 alu
.op
= ALU_OP1_FLOOR
;
5392 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5394 alu
.dst
.sel
= ctx
->temp_reg
;
5398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5402 if (ctx
->bc
->chip_class
== CAYMAN
) {
5403 for (i
= 0; i
< 3; i
++) {
5404 alu
.op
= ALU_OP1_EXP_IEEE
;
5405 alu
.src
[0].sel
= ctx
->temp_reg
;
5406 alu
.src
[0].chan
= 0;
5408 alu
.dst
.sel
= ctx
->temp_reg
;
5410 alu
.dst
.write
= i
== 0;
5412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5417 alu
.op
= ALU_OP1_EXP_IEEE
;
5418 alu
.src
[0].sel
= ctx
->temp_reg
;
5419 alu
.src
[0].chan
= 0;
5421 alu
.dst
.sel
= ctx
->temp_reg
;
5425 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5431 /* result.y = tmp - floor(tmp); */
5432 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5433 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5435 alu
.op
= ALU_OP1_FRACT
;
5436 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5438 alu
.dst
.sel
= ctx
->temp_reg
;
5440 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5449 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5454 /* result.z = RoughApprox2ToX(tmp);*/
5455 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5456 if (ctx
->bc
->chip_class
== CAYMAN
) {
5457 for (i
= 0; i
< 3; i
++) {
5458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5459 alu
.op
= ALU_OP1_EXP_IEEE
;
5460 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5462 alu
.dst
.sel
= ctx
->temp_reg
;
5469 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5475 alu
.op
= ALU_OP1_EXP_IEEE
;
5476 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5478 alu
.dst
.sel
= ctx
->temp_reg
;
5484 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5490 /* result.w = 1.0;*/
5491 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5494 alu
.op
= ALU_OP1_MOV
;
5495 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5496 alu
.src
[0].chan
= 0;
5498 alu
.dst
.sel
= ctx
->temp_reg
;
5502 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5506 return tgsi_helper_copy(ctx
, inst
);
5509 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5511 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5512 struct r600_bytecode_alu alu
;
5516 /* result.x = floor(log2(|src|)); */
5517 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5518 if (ctx
->bc
->chip_class
== CAYMAN
) {
5519 for (i
= 0; i
< 3; i
++) {
5520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5522 alu
.op
= ALU_OP1_LOG_IEEE
;
5523 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5524 r600_bytecode_src_set_abs(&alu
.src
[0]);
5526 alu
.dst
.sel
= ctx
->temp_reg
;
5532 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5538 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5540 alu
.op
= ALU_OP1_LOG_IEEE
;
5541 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5542 r600_bytecode_src_set_abs(&alu
.src
[0]);
5544 alu
.dst
.sel
= ctx
->temp_reg
;
5548 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5553 alu
.op
= ALU_OP1_FLOOR
;
5554 alu
.src
[0].sel
= ctx
->temp_reg
;
5555 alu
.src
[0].chan
= 0;
5557 alu
.dst
.sel
= ctx
->temp_reg
;
5562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5567 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5568 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5570 if (ctx
->bc
->chip_class
== CAYMAN
) {
5571 for (i
= 0; i
< 3; i
++) {
5572 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5574 alu
.op
= ALU_OP1_LOG_IEEE
;
5575 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5576 r600_bytecode_src_set_abs(&alu
.src
[0]);
5578 alu
.dst
.sel
= ctx
->temp_reg
;
5585 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5590 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5592 alu
.op
= ALU_OP1_LOG_IEEE
;
5593 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5594 r600_bytecode_src_set_abs(&alu
.src
[0]);
5596 alu
.dst
.sel
= ctx
->temp_reg
;
5601 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5606 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5608 alu
.op
= ALU_OP1_FLOOR
;
5609 alu
.src
[0].sel
= ctx
->temp_reg
;
5610 alu
.src
[0].chan
= 1;
5612 alu
.dst
.sel
= ctx
->temp_reg
;
5617 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5621 if (ctx
->bc
->chip_class
== CAYMAN
) {
5622 for (i
= 0; i
< 3; i
++) {
5623 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5624 alu
.op
= ALU_OP1_EXP_IEEE
;
5625 alu
.src
[0].sel
= ctx
->temp_reg
;
5626 alu
.src
[0].chan
= 1;
5628 alu
.dst
.sel
= ctx
->temp_reg
;
5635 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5641 alu
.op
= ALU_OP1_EXP_IEEE
;
5642 alu
.src
[0].sel
= ctx
->temp_reg
;
5643 alu
.src
[0].chan
= 1;
5645 alu
.dst
.sel
= ctx
->temp_reg
;
5650 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5655 if (ctx
->bc
->chip_class
== CAYMAN
) {
5656 for (i
= 0; i
< 3; i
++) {
5657 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5658 alu
.op
= ALU_OP1_RECIP_IEEE
;
5659 alu
.src
[0].sel
= ctx
->temp_reg
;
5660 alu
.src
[0].chan
= 1;
5662 alu
.dst
.sel
= ctx
->temp_reg
;
5669 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5674 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5675 alu
.op
= ALU_OP1_RECIP_IEEE
;
5676 alu
.src
[0].sel
= ctx
->temp_reg
;
5677 alu
.src
[0].chan
= 1;
5679 alu
.dst
.sel
= ctx
->temp_reg
;
5684 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5689 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5691 alu
.op
= ALU_OP2_MUL
;
5693 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5694 r600_bytecode_src_set_abs(&alu
.src
[0]);
5696 alu
.src
[1].sel
= ctx
->temp_reg
;
5697 alu
.src
[1].chan
= 1;
5699 alu
.dst
.sel
= ctx
->temp_reg
;
5704 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5709 /* result.z = log2(|src|);*/
5710 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5711 if (ctx
->bc
->chip_class
== CAYMAN
) {
5712 for (i
= 0; i
< 3; i
++) {
5713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5715 alu
.op
= ALU_OP1_LOG_IEEE
;
5716 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5717 r600_bytecode_src_set_abs(&alu
.src
[0]);
5719 alu
.dst
.sel
= ctx
->temp_reg
;
5726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5733 alu
.op
= ALU_OP1_LOG_IEEE
;
5734 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5735 r600_bytecode_src_set_abs(&alu
.src
[0]);
5737 alu
.dst
.sel
= ctx
->temp_reg
;
5742 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5748 /* result.w = 1.0; */
5749 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5750 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5752 alu
.op
= ALU_OP1_MOV
;
5753 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5754 alu
.src
[0].chan
= 0;
5756 alu
.dst
.sel
= ctx
->temp_reg
;
5761 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5766 return tgsi_helper_copy(ctx
, inst
);
5769 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5771 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5772 struct r600_bytecode_alu alu
;
5775 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5777 switch (inst
->Instruction
.Opcode
) {
5778 case TGSI_OPCODE_ARL
:
5779 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5781 case TGSI_OPCODE_ARR
:
5782 alu
.op
= ALU_OP1_FLT_TO_INT
;
5784 case TGSI_OPCODE_UARL
:
5785 alu
.op
= ALU_OP1_MOV
;
5792 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5794 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5796 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5800 ctx
->bc
->ar_loaded
= 0;
5803 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5805 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5806 struct r600_bytecode_alu alu
;
5809 switch (inst
->Instruction
.Opcode
) {
5810 case TGSI_OPCODE_ARL
:
5811 memset(&alu
, 0, sizeof(alu
));
5812 alu
.op
= ALU_OP1_FLOOR
;
5813 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5814 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5818 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5821 memset(&alu
, 0, sizeof(alu
));
5822 alu
.op
= ALU_OP1_FLT_TO_INT
;
5823 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5824 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5828 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5831 case TGSI_OPCODE_ARR
:
5832 memset(&alu
, 0, sizeof(alu
));
5833 alu
.op
= ALU_OP1_FLT_TO_INT
;
5834 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5835 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5839 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5842 case TGSI_OPCODE_UARL
:
5843 memset(&alu
, 0, sizeof(alu
));
5844 alu
.op
= ALU_OP1_MOV
;
5845 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5846 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5850 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5858 ctx
->bc
->ar_loaded
= 0;
5862 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5864 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5865 struct r600_bytecode_alu alu
;
5868 for (i
= 0; i
< 4; i
++) {
5869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5871 alu
.op
= ALU_OP2_MUL
;
5872 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5874 if (i
== 0 || i
== 3) {
5875 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5877 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5880 if (i
== 0 || i
== 2) {
5881 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5883 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5887 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5894 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5896 struct r600_bytecode_alu alu
;
5899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5901 alu
.execute_mask
= 1;
5902 alu
.update_pred
= 1;
5904 alu
.dst
.sel
= ctx
->temp_reg
;
5908 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5909 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5910 alu
.src
[1].chan
= 0;
5914 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5920 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5922 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5926 if (ctx
->bc
->cf_last
) {
5927 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5929 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5934 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5935 ctx
->bc
->force_add_cf
= 1;
5936 } else if (alu_pop
== 2) {
5937 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5938 ctx
->bc
->force_add_cf
= 1;
5945 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5946 ctx
->bc
->cf_last
->pop_count
= pops
;
5947 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5953 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5956 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5957 unsigned elements
, entries
;
5959 unsigned entry_size
= stack
->entry_size
;
5961 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5962 elements
+= stack
->push
;
5964 switch (ctx
->bc
->chip_class
) {
5967 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5968 * the stack must be reserved to hold the current active/continue
5970 if (reason
== FC_PUSH_VPM
) {
5976 /* r9xx: any stack operation on empty stack consumes 2 additional
5981 /* FIXME: do the two elements added above cover the cases for the
5985 /* r8xx+: 2 extra elements are not always required, but one extra
5986 * element must be added for each of the following cases:
5987 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5989 * (Currently we don't use ALU_ELSE_AFTER.)
5990 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5991 * PUSH instruction executed.
5993 * NOTE: it seems we also need to reserve additional element in some
5994 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5995 * then STACK_SIZE should be 2 instead of 1 */
5996 if (reason
== FC_PUSH_VPM
) {
6006 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
6007 * for all chips, so we use 4 in the final formula, not the real entry_size
6011 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
6013 if (entries
> stack
->max_entries
)
6014 stack
->max_entries
= entries
;
6017 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
6021 --ctx
->bc
->stack
.push
;
6022 assert(ctx
->bc
->stack
.push
>= 0);
6025 --ctx
->bc
->stack
.push_wqm
;
6026 assert(ctx
->bc
->stack
.push_wqm
>= 0);
6029 --ctx
->bc
->stack
.loop
;
6030 assert(ctx
->bc
->stack
.loop
>= 0);
6038 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
6042 ++ctx
->bc
->stack
.push
;
6045 ++ctx
->bc
->stack
.push_wqm
;
6047 ++ctx
->bc
->stack
.loop
;
6053 callstack_update_max_depth(ctx
, reason
);
6056 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
6058 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
6060 sp
->mid
= realloc((void *)sp
->mid
,
6061 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
6062 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
6066 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
6069 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
6070 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
6073 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
6075 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
6085 static int emit_return(struct r600_shader_ctx
*ctx
)
6087 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
6091 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
6094 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
6095 ctx
->bc
->cf_last
->pop_count
= pops
;
6096 /* XXX work out offset */
6100 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
6105 static void emit_testflag(struct r600_shader_ctx
*ctx
)
6110 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
6113 emit_jump_to_offset(ctx
, 1, 4);
6114 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
6115 pops(ctx
, ifidx
+ 1);
6119 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
6123 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6124 ctx
->bc
->cf_last
->pop_count
= 1;
6126 fc_set_mid(ctx
, fc_sp
);
6132 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
6134 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
6136 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
6137 * LOOP_STARTxxx for nested loops may put the branch stack into a state
6138 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
6139 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
6140 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
6141 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
6142 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6143 alu_type
= CF_OP_ALU
;
6146 emit_logic_pred(ctx
, opcode
, alu_type
);
6148 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
6150 fc_pushlevel(ctx
, FC_IF
);
6152 callstack_push(ctx
, FC_PUSH_VPM
);
6156 static int tgsi_if(struct r600_shader_ctx
*ctx
)
6158 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
6161 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
6163 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
6166 static int tgsi_else(struct r600_shader_ctx
*ctx
)
6168 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
6169 ctx
->bc
->cf_last
->pop_count
= 1;
6171 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
6172 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
6176 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
6179 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
6180 R600_ERR("if/endif unbalanced in shader\n");
6184 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
6185 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6186 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
6188 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6192 callstack_pop(ctx
, FC_PUSH_VPM
);
6196 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
6198 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
6199 * limited to 4096 iterations, like the other LOOP_* instructions. */
6200 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
6202 fc_pushlevel(ctx
, FC_LOOP
);
6204 /* check stack depth */
6205 callstack_push(ctx
, FC_LOOP
);
6209 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
6213 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
6215 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
6216 R600_ERR("loop/endloop in shader code are not paired.\n");
6220 /* fixup loop pointers - from r600isa
6221 LOOP END points to CF after LOOP START,
6222 LOOP START point to CF after LOOP END
6223 BRK/CONT point to LOOP END CF
6225 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
6227 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6229 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
6230 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
6232 /* XXX add LOOPRET support */
6234 callstack_pop(ctx
, FC_LOOP
);
6238 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
6242 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
6244 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
6249 R600_ERR("Break not inside loop/endloop pair\n");
6253 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6255 fc_set_mid(ctx
, fscp
);
6260 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
6262 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
6263 emit_gs_ring_writes(ctx
, TRUE
);
6265 return r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6268 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
6270 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6271 struct r600_bytecode_alu alu
;
6273 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6276 for (i
= 0; i
< lasti
+ 1; i
++) {
6277 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6280 if (ctx
->bc
->chip_class
== CAYMAN
) {
6281 for (j
= 0 ; j
< 4; j
++) {
6282 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6284 alu
.op
= ALU_OP2_MULLO_UINT
;
6285 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
6286 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
6288 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
6289 alu
.dst
.sel
= ctx
->temp_reg
;
6290 alu
.dst
.write
= (j
== i
);
6293 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6298 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6301 alu
.dst
.sel
= ctx
->temp_reg
;
6304 alu
.op
= ALU_OP2_MULLO_UINT
;
6305 for (j
= 0; j
< 2; j
++) {
6306 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6310 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6317 for (i
= 0; i
< lasti
+ 1; i
++) {
6318 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6322 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6324 alu
.op
= ALU_OP2_ADD_INT
;
6326 alu
.src
[0].sel
= ctx
->temp_reg
;
6327 alu
.src
[0].chan
= i
;
6329 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6333 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6340 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
6341 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6342 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6343 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6346 * For state trackers other than OpenGL, we'll want to use
6347 * _RECIP_IEEE instead.
6349 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
6351 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
6352 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6353 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6354 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6355 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6356 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6357 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6358 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6359 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6360 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6361 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6362 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6363 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6364 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6365 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6366 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6368 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6369 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6371 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6372 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6373 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6374 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6375 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6376 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6377 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6378 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6379 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6380 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6382 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6383 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6384 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6385 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6386 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6387 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6388 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6389 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6390 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6391 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6392 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6393 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6394 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6395 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6396 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6397 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6398 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6399 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6400 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6401 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6402 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6403 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6404 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6405 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6406 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6407 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6408 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6409 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6410 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6411 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6412 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6413 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6414 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6415 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6416 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6417 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6418 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6419 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6420 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6421 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6422 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6423 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6424 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6425 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6426 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6427 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6428 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6430 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6431 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6432 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6433 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6434 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6435 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6436 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6437 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6438 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6440 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6441 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6442 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6443 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6444 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6445 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6446 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6447 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6448 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6449 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6450 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6451 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6452 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6453 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6454 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6455 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6457 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6458 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6459 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6460 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6461 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6462 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6463 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6464 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6465 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6468 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6469 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6470 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6471 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6473 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6474 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6475 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6476 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6477 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6478 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6479 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6480 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6481 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6482 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6483 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6484 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6485 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6486 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6487 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6488 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6489 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6490 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6491 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6492 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6493 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6494 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6495 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6496 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6497 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6498 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6499 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6500 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6501 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6502 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6503 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6504 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6505 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6506 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6507 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6508 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6509 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6510 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6511 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6512 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6513 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6514 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6515 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6516 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6517 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6518 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6519 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6520 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6521 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6522 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6523 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6524 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6525 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6526 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6527 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6528 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6529 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6530 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6531 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6532 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6533 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6534 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6535 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6538 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6539 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6540 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6541 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6542 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6543 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6544 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6545 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6546 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6547 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6548 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6549 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6550 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6551 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6552 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6553 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6554 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6555 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6556 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6557 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6558 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6560 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6561 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6563 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6564 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6565 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6566 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6567 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6568 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6569 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6570 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6571 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6572 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6574 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6575 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6576 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6577 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6578 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6579 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6580 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6581 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6582 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6583 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6584 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6585 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6586 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6587 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6588 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6589 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6590 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6591 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6592 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6593 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6594 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6595 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6596 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6597 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6598 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6599 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6600 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6601 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6602 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6603 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6604 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6605 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6606 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6607 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6608 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6609 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6610 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6611 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6612 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6613 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6614 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6615 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6616 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6617 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6618 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6619 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6620 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6622 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6623 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6624 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6625 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6626 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6627 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6628 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6629 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6630 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6632 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6633 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6634 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6635 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6636 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6637 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6638 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6639 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6640 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6641 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6642 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6643 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6644 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6645 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6646 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6647 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6649 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6650 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6651 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6652 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6653 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6654 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6655 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6656 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6657 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6658 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6660 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6661 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6662 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6663 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6665 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6666 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6667 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6668 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6669 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6670 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6671 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6672 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6673 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6674 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6675 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6676 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6677 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6678 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6679 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6680 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6681 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6682 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6683 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6684 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6685 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6686 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6687 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6688 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6689 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6690 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6691 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6692 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6693 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6694 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6695 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6696 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6697 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6698 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6699 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6700 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6701 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6702 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6703 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6704 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6705 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6706 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6707 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6708 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6709 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6710 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6711 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6712 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6713 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6714 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6715 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6716 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6717 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6718 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6719 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6720 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6721 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6722 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6723 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6724 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6725 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6726 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6727 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6730 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6731 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6732 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6733 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6734 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6735 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6736 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6737 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6738 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6739 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6740 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6741 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6742 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6743 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6744 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6745 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6746 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6747 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6748 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6749 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6750 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6752 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6753 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6755 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6756 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6757 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6758 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6759 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6760 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6761 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6762 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6763 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6764 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6766 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6767 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6768 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6769 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6770 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6771 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6772 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6773 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6774 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6775 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6776 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6777 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6778 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6779 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6780 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6781 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6782 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6783 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6784 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6785 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6786 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6787 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6788 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6789 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6790 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6791 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6792 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6793 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6794 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6795 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6796 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6797 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6798 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6799 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6800 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6801 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6802 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6803 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6804 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6805 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6806 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6807 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6808 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6809 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6810 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6811 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6812 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6814 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6815 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6816 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6817 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6818 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6819 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6820 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6821 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6822 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6824 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6825 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6826 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6827 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6828 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6829 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6830 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6831 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6832 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6833 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6834 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6835 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6836 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6837 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6838 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6839 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6841 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6842 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6843 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6844 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6846 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6847 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6848 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6849 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6850 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6851 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6853 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6854 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6855 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6856 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6858 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6859 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6860 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6861 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6862 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6863 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6864 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6865 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6866 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6867 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6868 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6869 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6870 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6871 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6872 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6873 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6874 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6875 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6876 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6877 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6878 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6879 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6880 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6881 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6882 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6883 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6884 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6885 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6886 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6887 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6888 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6889 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6890 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6891 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6892 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6893 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6894 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6895 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6896 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6897 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6898 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6899 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6900 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6901 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6902 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6903 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6904 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6905 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6906 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6907 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6908 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6909 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6910 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6911 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6912 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6913 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6914 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6915 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6916 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6917 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6918 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6919 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6920 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},