2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_llvm.h"
25 #include "r600_formats.h"
26 #include "r600_opcodes.h"
27 #include "r600_shader.h"
30 #include "sb/sb_public.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "tgsi/tgsi_info.h"
34 #include "tgsi/tgsi_parse.h"
35 #include "tgsi/tgsi_scan.h"
36 #include "tgsi/tgsi_dump.h"
37 #include "util/u_memory.h"
38 #include "util/u_math.h"
43 Why CAYMAN got loops for lots of instructions is explained here.
45 -These 8xx t-slot only ops are implemented in all vector slots.
46 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
47 These 8xx t-slot only opcodes become vector ops, with all four
48 slots expecting the arguments on sources a and b. Result is
49 broadcast to all channels.
50 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT
51 These 8xx t-slot only opcodes become vector ops in the z, y, and
53 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
54 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
57 The w slot may have an independent co-issued operation, or if the
58 result is required to be in the w slot, the opcode above may be
59 issued in the w slot as well.
60 The compiler must issue the source argument to slots z, y, and x
63 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
64 struct r600_pipe_shader
*pipeshader
,
65 struct r600_shader_key key
);
67 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
68 int size
, unsigned comp_mask
) {
73 if (ps
->num_arrays
== ps
->max_arrays
) {
75 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
76 sizeof(struct r600_shader_array
));
79 int n
= ps
->num_arrays
;
82 ps
->arrays
[n
].comp_mask
= comp_mask
;
83 ps
->arrays
[n
].gpr_start
= start_gpr
;
84 ps
->arrays
[n
].gpr_count
= size
;
87 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
91 fprintf(stderr
, "STREAMOUT\n");
92 for (i
= 0; i
< so
->num_outputs
; i
++) {
93 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
94 so
->output
[i
].start_component
;
95 fprintf(stderr
, " %i: MEM_STREAM0_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
96 i
, so
->output
[i
].output_buffer
,
97 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
98 so
->output
[i
].register_index
,
103 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
107 static int store_shader(struct pipe_context
*ctx
,
108 struct r600_pipe_shader
*shader
)
110 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
113 if (shader
->bo
== NULL
) {
114 shader
->bo
= (struct r600_resource
*)
115 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
116 if (shader
->bo
== NULL
) {
119 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
120 if (R600_BIG_ENDIAN
) {
121 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
122 ptr
[i
] = util_bswap32(shader
->shader
.bc
.bytecode
[i
]);
125 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
127 rctx
->b
.ws
->buffer_unmap(shader
->bo
->cs_buf
);
133 int r600_pipe_shader_create(struct pipe_context
*ctx
,
134 struct r600_pipe_shader
*shader
,
135 struct r600_shader_key key
)
137 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
140 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
, sel
->tokens
);
141 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
142 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
143 unsigned export_shader
= key
.vs_as_es
;
145 shader
->shader
.bc
.isa
= rctx
->isa
;
148 fprintf(stderr
, "--------------------------------------------------------------\n");
149 tgsi_dump(sel
->tokens
, 0);
151 if (sel
->so
.num_outputs
) {
152 r600_dump_streamout(&sel
->so
);
155 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
157 R600_ERR("translation from TGSI failed !\n");
161 /* disable SB for geom shaders - it can't handle the CF_EMIT instructions */
162 use_sb
&= (shader
->shader
.processor_type
!= TGSI_PROCESSOR_GEOMETRY
);
164 /* Check if the bytecode has already been built. When using the llvm
165 * backend, r600_shader_from_tgsi() will take care of building the
168 if (!shader
->shader
.bc
.bytecode
) {
169 r
= r600_bytecode_build(&shader
->shader
.bc
);
171 R600_ERR("building bytecode failed !\n");
176 if (dump
&& !sb_disasm
) {
177 fprintf(stderr
, "--------------------------------------------------------------\n");
178 r600_bytecode_disasm(&shader
->shader
.bc
);
179 fprintf(stderr
, "______________________________________________________________\n");
180 } else if ((dump
&& sb_disasm
) || use_sb
) {
181 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
184 R600_ERR("r600_sb_bytecode_process failed !\n");
189 if (shader
->gs_copy_shader
) {
192 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
193 &shader
->gs_copy_shader
->shader
, dump
, 0);
198 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
202 /* Store the shader in a buffer. */
203 if ((r
= store_shader(ctx
, shader
)))
207 switch (shader
->shader
.processor_type
) {
208 case TGSI_PROCESSOR_GEOMETRY
:
209 if (rctx
->b
.chip_class
>= EVERGREEN
) {
210 evergreen_update_gs_state(ctx
, shader
);
211 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
213 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
);
243 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
245 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
246 r600_bytecode_clear(&shader
->shader
.bc
);
247 r600_release_command_buffer(&shader
->command_buffer
);
251 * tgsi -> r600 shader
253 struct r600_shader_tgsi_instruction
;
255 struct r600_shader_src
{
265 struct r600_shader_ctx
{
266 struct tgsi_shader_info info
;
267 struct tgsi_parse_context parse
;
268 const struct tgsi_token
*tokens
;
270 unsigned file_offset
[TGSI_FILE_COUNT
];
272 struct r600_shader_tgsi_instruction
*inst_info
;
273 struct r600_bytecode
*bc
;
274 struct r600_shader
*shader
;
275 struct r600_shader_src src
[4];
278 uint32_t max_driver_temp_used
;
280 /* needed for evergreen interpolation */
281 boolean input_centroid
;
282 boolean input_linear
;
283 boolean input_perspective
;
287 boolean clip_vertex_write
;
291 int next_ring_offset
;
292 int gs_out_ring_offset
;
294 struct r600_shader
*gs_for_vs
;
295 int gs_export_gpr_treg
;
298 struct r600_shader_tgsi_instruction
{
299 unsigned tgsi_opcode
;
302 int (*process
)(struct r600_shader_ctx
*ctx
);
305 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, bool ind
);
306 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
307 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
308 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
309 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
310 static int tgsi_else(struct r600_shader_ctx
*ctx
);
311 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
312 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
313 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
314 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
316 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
318 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
321 if (i
->Instruction
.NumDstRegs
> 1) {
322 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
325 if (i
->Instruction
.Predicate
) {
326 R600_ERR("predicate unsupported\n");
330 if (i
->Instruction
.Label
) {
331 R600_ERR("label unsupported\n");
335 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
336 if (i
->Src
[j
].Register
.Dimension
) {
337 switch (i
->Src
[j
].Register
.File
) {
338 case TGSI_FILE_CONSTANT
:
340 case TGSI_FILE_INPUT
:
341 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
)
344 R600_ERR("unsupported src %d (dimension %d)\n", j
,
345 i
->Src
[j
].Register
.Dimension
);
350 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
351 if (i
->Dst
[j
].Register
.Dimension
) {
352 R600_ERR("unsupported dst (dimension)\n");
359 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
364 if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
) {
365 if (ctx
->shader
->input
[input
].centroid
)
367 } else if (ctx
->shader
->input
[input
].interpolate
== TGSI_INTERPOLATE_LINEAR
) {
368 /* if we have perspective add one */
369 if (ctx
->input_perspective
) {
371 /* if we have perspective centroid */
372 if (ctx
->input_centroid
)
375 if (ctx
->shader
->input
[input
].centroid
)
379 ctx
->shader
->input
[input
].ij_index
= ij_index
;
382 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
385 struct r600_bytecode_alu alu
;
386 int gpr
= 0, base_chan
= 0;
387 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
389 /* work out gpr and base_chan from index */
391 base_chan
= (2 * (ij_index
% 2)) + 1;
393 for (i
= 0; i
< 8; i
++) {
394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
397 alu
.op
= ALU_OP2_INTERP_ZW
;
399 alu
.op
= ALU_OP2_INTERP_XY
;
401 if ((i
> 1) && (i
< 6)) {
402 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
406 alu
.dst
.chan
= i
% 4;
408 alu
.src
[0].sel
= gpr
;
409 alu
.src
[0].chan
= (base_chan
- (i
% 2));
411 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
413 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
416 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
423 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
426 struct r600_bytecode_alu alu
;
428 for (i
= 0; i
< 4; i
++) {
429 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
431 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
433 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
438 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
443 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
451 * Special export handling in shaders
453 * shader export ARRAY_BASE for EXPORT_POS:
456 * 62, 63 are clip distance vectors
458 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
459 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
460 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
461 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
462 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
463 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
464 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
465 * exclusive from render target index)
466 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
469 * shader export ARRAY_BASE for EXPORT_PIXEL:
471 * 61 computed Z vector
473 * The use of the values exported in the computed Z vector are controlled
474 * by DB_SHADER_CONTROL:
475 * Z_EXPORT_ENABLE - Z as a float in RED
476 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
477 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
478 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
479 * DB_SOURCE_FORMAT - export control restrictions
484 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
485 static int r600_spi_sid(struct r600_shader_io
* io
)
487 int index
, name
= io
->name
;
489 /* These params are handled differently, they don't need
490 * semantic indices, so we'll use 0 for them.
492 if (name
== TGSI_SEMANTIC_POSITION
||
493 name
== TGSI_SEMANTIC_PSIZE
||
494 name
== TGSI_SEMANTIC_LAYER
||
495 name
== TGSI_SEMANTIC_FACE
)
498 if (name
== TGSI_SEMANTIC_GENERIC
) {
499 /* For generic params simply use sid from tgsi */
502 /* For non-generic params - pack name and sid into 8 bits */
503 index
= 0x80 | (name
<<3) | (io
->sid
);
506 /* Make sure that all really used indices have nonzero value, so
507 * we can just compare it to 0 later instead of comparing the name
508 * with different values to detect special cases. */
515 /* turn input into interpolate on EG */
516 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
520 if (ctx
->shader
->input
[index
].spi_sid
) {
521 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
522 if (ctx
->shader
->input
[index
].interpolate
> 0) {
523 evergreen_interp_assign_ij_index(ctx
, index
);
525 r
= evergreen_interp_alu(ctx
, index
);
528 r
= evergreen_interp_flat(ctx
, index
);
534 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
536 struct r600_bytecode_alu alu
;
538 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
539 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
541 for (i
= 0; i
< 4; i
++) {
542 memset(&alu
, 0, sizeof(alu
));
543 alu
.op
= ALU_OP3_CNDGT
;
546 alu
.dst
.sel
= gpr_front
;
547 alu
.src
[0].sel
= ctx
->face_gpr
;
548 alu
.src
[1].sel
= gpr_front
;
549 alu
.src
[2].sel
= gpr_back
;
556 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
563 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
565 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
566 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
568 switch (d
->Declaration
.File
) {
569 case TGSI_FILE_INPUT
:
570 i
= ctx
->shader
->ninput
;
571 assert(i
< Elements(ctx
->shader
->input
));
572 ctx
->shader
->ninput
+= count
;
573 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
574 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
;
575 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
576 ctx
->shader
->input
[i
].centroid
= d
->Interp
.Centroid
;
577 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
;
578 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
579 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
580 switch (ctx
->shader
->input
[i
].name
) {
581 case TGSI_SEMANTIC_FACE
:
582 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
584 case TGSI_SEMANTIC_COLOR
:
587 case TGSI_SEMANTIC_POSITION
:
588 ctx
->fragcoord_input
= i
;
591 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
592 if ((r
= evergreen_interp_input(ctx
, i
)))
595 } else if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
596 /* FIXME probably skip inputs if they aren't passed in the ring */
597 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
598 ctx
->next_ring_offset
+= 16;
599 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
600 ctx
->shader
->gs_prim_id_input
= true;
602 for (j
= 1; j
< count
; ++j
) {
603 ctx
->shader
->input
[i
+ j
] = ctx
->shader
->input
[i
];
604 ctx
->shader
->input
[i
+ j
].gpr
+= j
;
607 case TGSI_FILE_OUTPUT
:
608 i
= ctx
->shader
->noutput
++;
609 assert(i
< Elements(ctx
->shader
->output
));
610 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
611 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
;
612 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
;
613 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
614 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
615 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
||
616 ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
617 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
618 switch (d
->Semantic
.Name
) {
619 case TGSI_SEMANTIC_CLIPDIST
:
620 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<< (d
->Semantic
.Index
<< 2);
622 case TGSI_SEMANTIC_PSIZE
:
623 ctx
->shader
->vs_out_misc_write
= 1;
624 ctx
->shader
->vs_out_point_size
= 1;
626 case TGSI_SEMANTIC_LAYER
:
627 ctx
->shader
->vs_out_misc_write
= 1;
628 ctx
->shader
->vs_out_layer
= 1;
630 case TGSI_SEMANTIC_CLIPVERTEX
:
631 ctx
->clip_vertex_write
= TRUE
;
635 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
636 ctx
->gs_out_ring_offset
+= 16;
638 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
639 switch (d
->Semantic
.Name
) {
640 case TGSI_SEMANTIC_COLOR
:
641 ctx
->shader
->nr_ps_max_color_exports
++;
646 case TGSI_FILE_TEMPORARY
:
647 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
648 if (d
->Array
.ArrayID
) {
649 r600_add_gpr_array(ctx
->shader
,
650 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
652 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
657 case TGSI_FILE_CONSTANT
:
658 case TGSI_FILE_SAMPLER
:
659 case TGSI_FILE_ADDRESS
:
662 case TGSI_FILE_SYSTEM_VALUE
:
663 if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
664 if (!ctx
->native_integers
) {
665 struct r600_bytecode_alu alu
;
666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
668 alu
.op
= ALU_OP1_INT_TO_FLT
;
677 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
681 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
684 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
690 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
692 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
696 * for evergreen we need to scan the shader to find the number of GPRs we need to
697 * reserve for interpolation.
699 * we need to know if we are going to emit
700 * any centroid inputs
701 * if perspective and linear are required
703 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
708 ctx
->input_linear
= FALSE
;
709 ctx
->input_perspective
= FALSE
;
710 ctx
->input_centroid
= FALSE
;
711 ctx
->num_interp_gpr
= 1;
713 /* any centroid inputs */
714 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
715 /* skip position/face */
716 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
717 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
)
719 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_LINEAR
)
720 ctx
->input_linear
= TRUE
;
721 if (ctx
->info
.input_interpolate
[i
] == TGSI_INTERPOLATE_PERSPECTIVE
)
722 ctx
->input_perspective
= TRUE
;
723 if (ctx
->info
.input_centroid
[i
])
724 ctx
->input_centroid
= TRUE
;
728 /* ignoring sample for now */
729 if (ctx
->input_perspective
)
731 if (ctx
->input_linear
)
733 if (ctx
->input_centroid
)
736 ctx
->num_interp_gpr
+= (num_baryc
+ 1) >> 1;
738 /* XXX PULL MODEL and LINE STIPPLE, FIXED PT POS */
739 return ctx
->num_interp_gpr
;
742 static void tgsi_src(struct r600_shader_ctx
*ctx
,
743 const struct tgsi_full_src_register
*tgsi_src
,
744 struct r600_shader_src
*r600_src
)
746 memset(r600_src
, 0, sizeof(*r600_src
));
747 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
748 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
749 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
750 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
751 r600_src
->neg
= tgsi_src
->Register
.Negate
;
752 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
754 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
756 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
757 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
758 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
760 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
761 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
);
762 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
765 index
= tgsi_src
->Register
.Index
;
766 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
767 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
768 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
769 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
770 r600_src
->swizzle
[0] = 3;
771 r600_src
->swizzle
[1] = 3;
772 r600_src
->swizzle
[2] = 3;
773 r600_src
->swizzle
[3] = 3;
775 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
776 r600_src
->swizzle
[0] = 0;
777 r600_src
->swizzle
[1] = 0;
778 r600_src
->swizzle
[2] = 0;
779 r600_src
->swizzle
[3] = 0;
783 if (tgsi_src
->Register
.Indirect
)
784 r600_src
->rel
= V_SQ_REL_RELATIVE
;
785 r600_src
->sel
= tgsi_src
->Register
.Index
;
786 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
788 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
789 if (tgsi_src
->Register
.Dimension
) {
790 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
795 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
, unsigned int cb_idx
, unsigned int offset
, unsigned int dst_reg
)
797 struct r600_bytecode_vtx vtx
;
802 struct r600_bytecode_alu alu
;
804 memset(&alu
, 0, sizeof(alu
));
806 alu
.op
= ALU_OP2_ADD_INT
;
807 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
809 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
810 alu
.src
[1].value
= offset
;
812 alu
.dst
.sel
= dst_reg
;
816 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
821 ar_reg
= ctx
->bc
->ar_reg
;
824 memset(&vtx
, 0, sizeof(vtx
));
825 vtx
.buffer_id
= cb_idx
;
826 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
827 vtx
.src_gpr
= ar_reg
;
828 vtx
.mega_fetch_count
= 16;
829 vtx
.dst_gpr
= dst_reg
;
830 vtx
.dst_sel_x
= 0; /* SEL_X */
831 vtx
.dst_sel_y
= 1; /* SEL_Y */
832 vtx
.dst_sel_z
= 2; /* SEL_Z */
833 vtx
.dst_sel_w
= 3; /* SEL_W */
834 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
835 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
836 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
837 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
838 vtx
.endian
= r600_endian_swap(32);
840 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
846 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
848 struct r600_bytecode_vtx vtx
;
850 unsigned index
= src
->Register
.Index
;
851 unsigned vtx_id
= src
->Dimension
.Index
;
852 int offset_reg
= vtx_id
/ 3;
853 int offset_chan
= vtx_id
% 3;
855 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
856 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
858 if (offset_reg
== 0 && offset_chan
== 2)
861 if (src
->Dimension
.Indirect
) {
864 struct r600_bytecode_alu alu
;
867 /* you have got to be shitting me -
868 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
869 at least this is what fglrx seems to do. */
870 for (i
= 0; i
< 3; i
++) {
871 treg
[i
] = r600_get_temp(ctx
);
873 t2
= r600_get_temp(ctx
);
874 for (i
= 0; i
< 3; i
++) {
875 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
876 alu
.op
= ALU_OP1_MOV
;
878 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
879 alu
.dst
.sel
= treg
[i
];
883 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
887 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
888 alu
.op
= ALU_OP1_MOV
;
889 alu
.src
[0].sel
= treg
[0];
894 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
901 memset(&vtx
, 0, sizeof(vtx
));
902 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
903 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
904 vtx
.src_gpr
= offset_reg
;
905 vtx
.src_sel_x
= offset_chan
;
906 vtx
.offset
= index
* 16; /*bytes*/
907 vtx
.mega_fetch_count
= 16;
908 vtx
.dst_gpr
= dst_reg
;
909 vtx
.dst_sel_x
= 0; /* SEL_X */
910 vtx
.dst_sel_y
= 1; /* SEL_Y */
911 vtx
.dst_sel_z
= 2; /* SEL_Z */
912 vtx
.dst_sel_w
= 3; /* SEL_W */
913 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
914 vtx
.use_const_fields
= 1;
916 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
919 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
925 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
927 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
930 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
931 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
933 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
934 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
935 /* primitive id is in R0.z */
937 ctx
->src
[i
].swizzle
[0] = 2;
940 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
941 int treg
= r600_get_temp(ctx
);
943 fetch_gs_input(ctx
, src
, treg
);
944 ctx
->src
[i
].sel
= treg
;
950 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
952 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
953 struct r600_bytecode_alu alu
;
954 int i
, j
, k
, nconst
, r
;
956 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
957 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
960 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
962 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
963 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
967 if (ctx
->src
[i
].rel
) {
968 int treg
= r600_get_temp(ctx
);
969 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].sel
- 512, treg
)))
972 ctx
->src
[i
].kc_bank
= 0;
973 ctx
->src
[i
].sel
= treg
;
977 int treg
= r600_get_temp(ctx
);
978 for (k
= 0; k
< 4; k
++) {
979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
980 alu
.op
= ALU_OP1_MOV
;
981 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
983 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
989 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
993 ctx
->src
[i
].sel
= treg
;
1001 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1002 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1004 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1005 struct r600_bytecode_alu alu
;
1006 int i
, j
, k
, nliteral
, r
;
1008 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1009 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1013 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1014 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1015 int treg
= r600_get_temp(ctx
);
1016 for (k
= 0; k
< 4; k
++) {
1017 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1018 alu
.op
= ALU_OP1_MOV
;
1019 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1020 alu
.src
[0].chan
= k
;
1021 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1027 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1031 ctx
->src
[i
].sel
= treg
;
1038 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1040 int i
, r
, count
= ctx
->shader
->ninput
;
1042 for (i
= 0; i
< count
; i
++) {
1043 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1044 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1052 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
)
1054 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1057 /* Sanity checking. */
1058 if (so
->num_outputs
> PIPE_MAX_SHADER_OUTPUTS
) {
1059 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
1063 for (i
= 0; i
< so
->num_outputs
; i
++) {
1064 if (so
->output
[i
].output_buffer
>= 4) {
1065 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1066 so
->output
[i
].output_buffer
);
1072 /* Initialize locations where the outputs are stored. */
1073 for (i
= 0; i
< so
->num_outputs
; i
++) {
1074 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
1076 /* Lower outputs with dst_offset < start_component.
1078 * We can only output 4D vectors with a write mask, e.g. we can
1079 * only output the W component at offset 3, etc. If we want
1080 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1081 * to move it to X and output X. */
1082 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
1083 unsigned tmp
= r600_get_temp(ctx
);
1085 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
1086 struct r600_bytecode_alu alu
;
1087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1088 alu
.op
= ALU_OP1_MOV
;
1089 alu
.src
[0].sel
= so_gpr
[i
];
1090 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
1095 if (j
== so
->output
[i
].num_components
- 1)
1097 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1101 so
->output
[i
].start_component
= 0;
1106 /* Write outputs to buffers. */
1107 for (i
= 0; i
< so
->num_outputs
; i
++) {
1108 struct r600_bytecode_output output
;
1110 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1111 output
.gpr
= so_gpr
[i
];
1112 output
.elem_size
= so
->output
[i
].num_components
;
1113 output
.array_base
= so
->output
[i
].dst_offset
- so
->output
[i
].start_component
;
1114 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1115 output
.burst_count
= 1;
1116 /* array_size is an upper limit for the burst_count
1117 * with MEM_STREAM instructions */
1118 output
.array_size
= 0xFFF;
1119 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << so
->output
[i
].start_component
;
1120 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1121 switch (so
->output
[i
].output_buffer
) {
1123 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1126 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1129 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1132 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1136 switch (so
->output
[i
].output_buffer
) {
1138 output
.op
= CF_OP_MEM_STREAM0
;
1141 output
.op
= CF_OP_MEM_STREAM1
;
1144 output
.op
= CF_OP_MEM_STREAM2
;
1147 output
.op
= CF_OP_MEM_STREAM3
;
1151 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
1160 static int generate_gs_copy_shader(struct r600_context
*rctx
,
1161 struct r600_pipe_shader
*gs
,
1162 struct pipe_stream_output_info
*so
)
1164 struct r600_shader_ctx ctx
= {};
1165 struct r600_shader
*gs_shader
= &gs
->shader
;
1166 struct r600_pipe_shader
*cshader
;
1167 int ocnt
= gs_shader
->noutput
;
1168 struct r600_bytecode_alu alu
;
1169 struct r600_bytecode_vtx vtx
;
1170 struct r600_bytecode_output output
;
1171 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
1172 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
1173 int i
, next_clip_pos
= 61, next_param
= 0;
1175 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
1179 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
1180 sizeof(struct r600_shader_io
));
1182 cshader
->shader
.noutput
= ocnt
;
1184 ctx
.shader
= &cshader
->shader
;
1185 ctx
.bc
= &ctx
.shader
->bc
;
1186 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
1188 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
1189 rctx
->screen
->has_compressed_msaa_texturing
);
1191 ctx
.bc
->isa
= rctx
->isa
;
1193 /* R0.x = R0.x & 0x3fffffff */
1194 memset(&alu
, 0, sizeof(alu
));
1195 alu
.op
= ALU_OP2_AND_INT
;
1196 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1197 alu
.src
[1].value
= 0x3fffffff;
1199 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1201 /* R0.y = R0.x >> 30 */
1202 memset(&alu
, 0, sizeof(alu
));
1203 alu
.op
= ALU_OP2_LSHR_INT
;
1204 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1205 alu
.src
[1].value
= 0x1e;
1209 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1211 /* PRED_SETE_INT __, R0.y, 0 */
1212 memset(&alu
, 0, sizeof(alu
));
1213 alu
.op
= ALU_OP2_PRED_SETE_INT
;
1214 alu
.src
[0].chan
= 1;
1215 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1216 alu
.execute_mask
= 1;
1217 alu
.update_pred
= 1;
1219 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
1221 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
1222 cf_jump
= ctx
.bc
->cf_last
;
1224 /* fetch vertex data from GSVS ring */
1225 for (i
= 0; i
< ocnt
; ++i
) {
1226 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1228 out
->ring_offset
= i
* 16;
1230 memset(&vtx
, 0, sizeof(vtx
));
1231 vtx
.op
= FETCH_OP_VFETCH
;
1232 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1234 vtx
.offset
= out
->ring_offset
;
1235 vtx
.dst_gpr
= out
->gpr
;
1240 if (rctx
->b
.chip_class
>= EVERGREEN
) {
1241 vtx
.use_const_fields
= 1;
1243 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1246 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
1249 /* XXX handle clipvertex, streamout? */
1250 emit_streamout(&ctx
, so
);
1252 /* export vertex data */
1253 /* XXX factor out common code with r600_shader_from_tgsi ? */
1254 for (i
= 0; i
< ocnt
; ++i
) {
1255 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1257 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
1260 memset(&output
, 0, sizeof(output
));
1261 output
.gpr
= out
->gpr
;
1262 output
.elem_size
= 3;
1263 output
.swizzle_x
= 0;
1264 output
.swizzle_y
= 1;
1265 output
.swizzle_z
= 2;
1266 output
.swizzle_w
= 3;
1267 output
.burst_count
= 1;
1268 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1269 output
.op
= CF_OP_EXPORT
;
1270 switch (out
->name
) {
1271 case TGSI_SEMANTIC_POSITION
:
1272 output
.array_base
= 60;
1273 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1276 case TGSI_SEMANTIC_PSIZE
:
1277 output
.array_base
= 61;
1278 if (next_clip_pos
== 61)
1280 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1281 output
.swizzle_y
= 7;
1282 output
.swizzle_z
= 7;
1283 output
.swizzle_w
= 7;
1284 ctx
.shader
->vs_out_misc_write
= 1;
1285 ctx
.shader
->vs_out_point_size
= 1;
1287 case TGSI_SEMANTIC_LAYER
:
1288 output
.array_base
= 61;
1289 if (next_clip_pos
== 61)
1291 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1292 output
.swizzle_x
= 7;
1293 output
.swizzle_y
= 7;
1294 output
.swizzle_z
= 0;
1295 output
.swizzle_w
= 7;
1296 ctx
.shader
->vs_out_misc_write
= 1;
1297 ctx
.shader
->vs_out_layer
= 1;
1299 case TGSI_SEMANTIC_CLIPDIST
:
1300 /* spi_sid is 0 for clipdistance outputs that were generated
1301 * for clipvertex - we don't need to pass them to PS */
1302 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
1304 /* duplicate it as PARAM to pass to the pixel shader */
1305 output
.array_base
= next_param
++;
1306 r600_bytecode_add_output(ctx
.bc
, &output
);
1307 last_exp_param
= ctx
.bc
->cf_last
;
1309 output
.array_base
= next_clip_pos
++;
1310 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1312 case TGSI_SEMANTIC_FOG
:
1313 output
.swizzle_y
= 4; /* 0 */
1314 output
.swizzle_z
= 4; /* 0 */
1315 output
.swizzle_w
= 5; /* 1 */
1318 output
.array_base
= next_param
++;
1321 r600_bytecode_add_output(ctx
.bc
, &output
);
1322 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
1323 last_exp_param
= ctx
.bc
->cf_last
;
1325 last_exp_pos
= ctx
.bc
->cf_last
;
1328 if (!last_exp_pos
) {
1329 memset(&output
, 0, sizeof(output
));
1331 output
.elem_size
= 3;
1332 output
.swizzle_x
= 7;
1333 output
.swizzle_y
= 7;
1334 output
.swizzle_z
= 7;
1335 output
.swizzle_w
= 7;
1336 output
.burst_count
= 1;
1338 output
.op
= CF_OP_EXPORT
;
1339 output
.array_base
= 60;
1340 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1341 r600_bytecode_add_output(ctx
.bc
, &output
);
1342 last_exp_pos
= ctx
.bc
->cf_last
;
1345 if (!last_exp_param
) {
1346 memset(&output
, 0, sizeof(output
));
1348 output
.elem_size
= 3;
1349 output
.swizzle_x
= 7;
1350 output
.swizzle_y
= 7;
1351 output
.swizzle_z
= 7;
1352 output
.swizzle_w
= 7;
1353 output
.burst_count
= 1;
1355 output
.op
= CF_OP_EXPORT
;
1356 output
.array_base
= next_param
++;
1357 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1358 r600_bytecode_add_output(ctx
.bc
, &output
);
1359 last_exp_param
= ctx
.bc
->cf_last
;
1362 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
1363 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
1365 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1366 cf_pop
= ctx
.bc
->cf_last
;
1368 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1369 cf_jump
->pop_count
= 1;
1370 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1371 cf_pop
->pop_count
= 1;
1373 if (ctx
.bc
->chip_class
== CAYMAN
)
1374 cm_bytecode_add_cf_end(ctx
.bc
);
1376 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1377 ctx
.bc
->cf_last
->end_of_program
= 1;
1380 gs
->gs_copy_shader
= cshader
;
1383 cshader
->shader
.ring_item_size
= ocnt
* 16;
1385 return r600_bytecode_build(ctx
.bc
);
1388 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, bool ind
)
1390 struct r600_bytecode_output output
;
1391 int i
, k
, ring_offset
;
1393 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
1394 if (ctx
->gs_for_vs
) {
1395 /* for ES we need to lookup corresponding ring offset expected by GS
1396 * (map this output to GS input by name and sid) */
1397 /* FIXME precompute offsets */
1399 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
1400 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
1401 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
1402 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
1403 ring_offset
= in
->ring_offset
;
1406 if (ring_offset
== -1)
1409 ring_offset
= i
* 16;
1411 /* next_ring_offset after parsing input decls contains total size of
1412 * single vertex data, gs_next_vertex - current vertex index */
1414 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
1416 /* get a temp and add the ring offset to the next vertex base in the shader */
1417 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1418 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
1419 output
.elem_size
= 3;
1420 output
.comp_mask
= 0xF;
1421 output
.burst_count
= 1;
1424 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
1426 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1427 output
.op
= CF_OP_MEM_RING
;
1431 output
.array_base
= ring_offset
>> 2; /* in dwords */
1432 output
.array_size
= 0xfff;
1433 output
.index_gpr
= ctx
->gs_export_gpr_treg
;
1435 output
.array_base
= ring_offset
>> 2; /* in dwords */
1436 r600_bytecode_add_output(ctx
->bc
, &output
);
1440 struct r600_bytecode_alu alu
;
1443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1444 alu
.op
= ALU_OP2_ADD_INT
;
1445 alu
.src
[0].sel
= ctx
->gs_export_gpr_treg
;
1446 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1447 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
1448 alu
.dst
.sel
= ctx
->gs_export_gpr_treg
;
1451 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1455 ++ctx
->gs_next_vertex
;
1459 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
1460 struct r600_pipe_shader
*pipeshader
,
1461 struct r600_shader_key key
)
1463 struct r600_screen
*rscreen
= rctx
->screen
;
1464 struct r600_shader
*shader
= &pipeshader
->shader
;
1465 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1466 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1467 struct tgsi_full_immediate
*immediate
;
1468 struct tgsi_full_property
*property
;
1469 struct r600_shader_ctx ctx
;
1470 struct r600_bytecode_output output
[32];
1471 unsigned output_done
, noutput
;
1474 int next_param_base
= 0, next_clip_base
;
1475 int max_color_exports
= MAX2(key
.nr_cbufs
, 1);
1476 /* Declarations used by llvm code */
1477 bool use_llvm
= false;
1479 bool ring_outputs
= false;
1480 bool pos_emitted
= false;
1482 #ifdef R600_USE_LLVM
1483 use_llvm
= !(rscreen
->b
.debug_flags
& DBG_NO_LLVM
);
1485 ctx
.bc
= &shader
->bc
;
1486 ctx
.shader
= shader
;
1487 ctx
.native_integers
= true;
1489 shader
->vs_as_es
= key
.vs_as_es
;
1491 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
1492 rscreen
->has_compressed_msaa_texturing
);
1493 ctx
.tokens
= tokens
;
1494 tgsi_scan_shader(tokens
, &ctx
.info
);
1495 shader
->indirect_files
= ctx
.info
.indirect_files
;
1496 indirect_gprs
= ctx
.info
.indirect_files
& ~(1 << TGSI_FILE_CONSTANT
);
1497 tgsi_parse_init(&ctx
.parse
, tokens
);
1498 ctx
.type
= ctx
.parse
.FullHeader
.Processor
.Processor
;
1499 shader
->processor_type
= ctx
.type
;
1500 ctx
.bc
->type
= shader
->processor_type
;
1502 ring_outputs
= key
.vs_as_es
|| (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
);
1505 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
1507 ctx
.gs_for_vs
= NULL
;
1510 ctx
.next_ring_offset
= 0;
1511 ctx
.gs_out_ring_offset
= 0;
1512 ctx
.gs_next_vertex
= 0;
1515 ctx
.fragcoord_input
= -1;
1516 ctx
.colors_used
= 0;
1517 ctx
.clip_vertex_write
= 0;
1519 shader
->nr_ps_color_exports
= 0;
1520 shader
->nr_ps_max_color_exports
= 0;
1522 shader
->two_side
= key
.color_two_side
;
1524 /* register allocations */
1525 /* Values [0,127] correspond to GPR[0..127].
1526 * Values [128,159] correspond to constant buffer bank 0
1527 * Values [160,191] correspond to constant buffer bank 1
1528 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1529 * Values [256,287] correspond to constant buffer bank 2 (EG)
1530 * Values [288,319] correspond to constant buffer bank 3 (EG)
1531 * Other special values are shown in the list below.
1532 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1533 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1534 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1535 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1536 * 248 SQ_ALU_SRC_0: special constant 0.0.
1537 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1538 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1539 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1540 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1541 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1542 * 254 SQ_ALU_SRC_PV: previous vector result.
1543 * 255 SQ_ALU_SRC_PS: previous scalar result.
1545 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1546 ctx
.file_offset
[i
] = 0;
1549 #ifdef R600_USE_LLVM
1550 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1551 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1552 "indirect adressing. Falling back to TGSI "
1557 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1558 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1560 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1563 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& ctx
.bc
->chip_class
>= EVERGREEN
) {
1564 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1566 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1567 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
1568 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
1570 ctx
.use_llvm
= use_llvm
;
1573 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1574 ctx
.file_offset
[TGSI_FILE_INPUT
];
1576 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1577 ctx
.file_offset
[TGSI_FILE_INPUT
] +
1578 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1580 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
1581 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
1583 /* Outside the GPR range. This will be translated to one of the
1584 * kcache banks later. */
1585 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
1587 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
1588 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
1589 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
1590 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1591 ctx
.gs_export_gpr_treg
= ctx
.bc
->ar_reg
+ 1;
1592 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 2;
1594 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 1;
1596 if (indirect_gprs
) {
1597 shader
->max_arrays
= 0;
1598 shader
->num_arrays
= 0;
1600 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
1601 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
1602 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
1603 ctx
.file_offset
[TGSI_FILE_INPUT
],
1606 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
1607 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1608 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
1609 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
1615 ctx
.literals
= NULL
;
1616 shader
->fs_write_all
= FALSE
;
1617 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1618 tgsi_parse_token(&ctx
.parse
);
1619 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1620 case TGSI_TOKEN_TYPE_IMMEDIATE
:
1621 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
1622 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
1623 if(ctx
.literals
== NULL
) {
1627 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
1628 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
1629 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
1630 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
1633 case TGSI_TOKEN_TYPE_DECLARATION
:
1634 r
= tgsi_declaration(&ctx
);
1638 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1640 case TGSI_TOKEN_TYPE_PROPERTY
:
1641 property
= &ctx
.parse
.FullToken
.FullProperty
;
1642 switch (property
->Property
.PropertyName
) {
1643 case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
:
1644 if (property
->u
[0].Data
== 1)
1645 shader
->fs_write_all
= TRUE
;
1647 case TGSI_PROPERTY_VS_PROHIBIT_UCPS
:
1648 /* we don't need this one */
1650 case TGSI_PROPERTY_GS_INPUT_PRIM
:
1651 shader
->gs_input_prim
= property
->u
[0].Data
;
1653 case TGSI_PROPERTY_GS_OUTPUT_PRIM
:
1654 shader
->gs_output_prim
= property
->u
[0].Data
;
1656 case TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
:
1657 shader
->gs_max_out_vertices
= property
->u
[0].Data
;
1662 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
1668 shader
->ring_item_size
= ctx
.next_ring_offset
;
1670 /* Process two side if needed */
1671 if (shader
->two_side
&& ctx
.colors_used
) {
1672 int i
, count
= ctx
.shader
->ninput
;
1673 unsigned next_lds_loc
= ctx
.shader
->nlds
;
1675 /* additional inputs will be allocated right after the existing inputs,
1676 * we won't need them after the color selection, so we don't need to
1677 * reserve these gprs for the rest of the shader code and to adjust
1678 * output offsets etc. */
1679 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
1680 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
1682 if (ctx
.face_gpr
== -1) {
1683 i
= ctx
.shader
->ninput
++;
1684 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
1685 ctx
.shader
->input
[i
].spi_sid
= 0;
1686 ctx
.shader
->input
[i
].gpr
= gpr
++;
1687 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
1690 for (i
= 0; i
< count
; i
++) {
1691 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1692 int ni
= ctx
.shader
->ninput
++;
1693 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
1694 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
1695 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
1696 ctx
.shader
->input
[ni
].gpr
= gpr
++;
1697 // TGSI to LLVM needs to know the lds position of inputs.
1698 // Non LLVM path computes it later (in process_twoside_color)
1699 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
1700 ctx
.shader
->input
[i
].back_color_input
= ni
;
1701 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
1702 if ((r
= evergreen_interp_input(&ctx
, ni
)))
1709 /* LLVM backend setup */
1710 #ifdef R600_USE_LLVM
1712 struct radeon_llvm_context radeon_llvm_ctx
;
1714 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
1715 boolean use_kill
= false;
1717 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
1718 radeon_llvm_ctx
.type
= ctx
.type
;
1719 radeon_llvm_ctx
.two_side
= shader
->two_side
;
1720 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
1721 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
1722 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
1723 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
1724 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
1725 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
1726 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
1727 radeon_llvm_ctx
.stream_outputs
= &so
;
1728 radeon_llvm_ctx
.clip_vertex
= ctx
.cv_output
;
1729 radeon_llvm_ctx
.alpha_to_one
= key
.alpha_to_one
;
1730 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
1731 ctx
.bc
->has_compressed_msaa_texturing
;
1732 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
1733 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
1734 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
1736 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
1737 radeon_llvm_dispose(&radeon_llvm_ctx
);
1739 fprintf(stderr
, "R600 LLVM backend failed to compile "
1740 "shader. Falling back to TGSI\n");
1742 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
1743 ctx
.file_offset
[TGSI_FILE_INPUT
];
1746 ctx
.shader
->uses_kill
= use_kill
;
1747 radeon_llvm_dispose(&radeon_llvm_ctx
);
1750 /* End of LLVM backend setup */
1752 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
1753 shader
->nr_ps_max_color_exports
= 8;
1756 if (ctx
.fragcoord_input
>= 0) {
1757 if (ctx
.bc
->chip_class
== CAYMAN
) {
1758 for (j
= 0 ; j
< 4; j
++) {
1759 struct r600_bytecode_alu alu
;
1760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1761 alu
.op
= ALU_OP1_RECIP_IEEE
;
1762 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1763 alu
.src
[0].chan
= 3;
1765 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1767 alu
.dst
.write
= (j
== 3);
1769 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1773 struct r600_bytecode_alu alu
;
1774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1775 alu
.op
= ALU_OP1_RECIP_IEEE
;
1776 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1777 alu
.src
[0].chan
= 3;
1779 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
1783 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
1788 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
1789 struct r600_bytecode_alu alu
;
1792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1793 alu
.op
= ALU_OP1_MOV
;
1794 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1795 alu
.src
[0].value
= 0;
1796 alu
.dst
.sel
= ctx
.gs_export_gpr_treg
;
1799 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1803 if (shader
->two_side
&& ctx
.colors_used
) {
1804 if ((r
= process_twoside_color_inputs(&ctx
)))
1808 tgsi_parse_init(&ctx
.parse
, tokens
);
1809 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
1810 tgsi_parse_token(&ctx
.parse
);
1811 switch (ctx
.parse
.FullToken
.Token
.Type
) {
1812 case TGSI_TOKEN_TYPE_INSTRUCTION
:
1813 r
= tgsi_is_supported(&ctx
);
1816 ctx
.max_driver_temp_used
= 0;
1817 /* reserve first tmp for everyone */
1818 r600_get_temp(&ctx
);
1820 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
1821 if ((r
= tgsi_split_constant(&ctx
)))
1823 if ((r
= tgsi_split_literal_constant(&ctx
)))
1825 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
)
1826 if ((r
= tgsi_split_gs_inputs(&ctx
)))
1828 if (ctx
.bc
->chip_class
== CAYMAN
)
1829 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
1830 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
1831 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
1833 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
1834 r
= ctx
.inst_info
->process(&ctx
);
1844 /* Reset the temporary register counter. */
1845 ctx
.max_driver_temp_used
= 0;
1847 noutput
= shader
->noutput
;
1849 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
1850 unsigned clipdist_temp
[2];
1852 clipdist_temp
[0] = r600_get_temp(&ctx
);
1853 clipdist_temp
[1] = r600_get_temp(&ctx
);
1855 /* need to convert a clipvertex write into clipdistance writes and not export
1856 the clip vertex anymore */
1858 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
1859 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1860 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
1862 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
1863 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
1866 /* reset spi_sid for clipvertex output to avoid confusing spi */
1867 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
1869 shader
->clip_dist_write
= 0xFF;
1871 for (i
= 0; i
< 8; i
++) {
1875 for (j
= 0; j
< 4; j
++) {
1876 struct r600_bytecode_alu alu
;
1877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1878 alu
.op
= ALU_OP2_DOT4
;
1879 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
1880 alu
.src
[0].chan
= j
;
1882 alu
.src
[1].sel
= 512 + i
;
1883 alu
.src
[1].kc_bank
= R600_UCP_CONST_BUFFER
;
1884 alu
.src
[1].chan
= j
;
1886 alu
.dst
.sel
= clipdist_temp
[oreg
];
1888 alu
.dst
.write
= (j
== ochan
);
1892 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
1899 /* Add stream outputs. */
1900 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
&&
1901 so
.num_outputs
&& !use_llvm
)
1902 emit_streamout(&ctx
, &so
);
1906 emit_gs_ring_writes(&ctx
, FALSE
);
1909 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
1911 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
1912 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1913 output
[j
].gpr
= shader
->output
[i
].gpr
;
1914 output
[j
].elem_size
= 3;
1915 output
[j
].swizzle_x
= 0;
1916 output
[j
].swizzle_y
= 1;
1917 output
[j
].swizzle_z
= 2;
1918 output
[j
].swizzle_w
= 3;
1919 output
[j
].burst_count
= 1;
1920 output
[j
].type
= -1;
1921 output
[j
].op
= CF_OP_EXPORT
;
1923 case TGSI_PROCESSOR_VERTEX
:
1924 switch (shader
->output
[i
].name
) {
1925 case TGSI_SEMANTIC_POSITION
:
1926 output
[j
].array_base
= 60;
1927 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1931 case TGSI_SEMANTIC_PSIZE
:
1932 output
[j
].array_base
= 61;
1933 output
[j
].swizzle_y
= 7;
1934 output
[j
].swizzle_z
= 7;
1935 output
[j
].swizzle_w
= 7;
1936 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1939 case TGSI_SEMANTIC_LAYER
:
1940 output
[j
].array_base
= 61;
1941 output
[j
].swizzle_x
= 7;
1942 output
[j
].swizzle_y
= 7;
1943 output
[j
].swizzle_z
= 0;
1944 output
[j
].swizzle_w
= 7;
1945 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1948 case TGSI_SEMANTIC_CLIPVERTEX
:
1951 case TGSI_SEMANTIC_CLIPDIST
:
1952 output
[j
].array_base
= next_clip_base
++;
1953 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1955 /* spi_sid is 0 for clipdistance outputs that were generated
1956 * for clipvertex - we don't need to pass them to PS */
1957 if (shader
->output
[i
].spi_sid
) {
1959 /* duplicate it as PARAM to pass to the pixel shader */
1960 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
1961 output
[j
].array_base
= next_param_base
++;
1962 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1965 case TGSI_SEMANTIC_FOG
:
1966 output
[j
].swizzle_y
= 4; /* 0 */
1967 output
[j
].swizzle_z
= 4; /* 0 */
1968 output
[j
].swizzle_w
= 5; /* 1 */
1972 case TGSI_PROCESSOR_FRAGMENT
:
1973 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1974 /* never export more colors than the number of CBs */
1975 if (shader
->output
[i
].sid
>= max_color_exports
) {
1980 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1981 output
[j
].array_base
= shader
->output
[i
].sid
;
1982 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1983 shader
->nr_ps_color_exports
++;
1984 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
1985 for (k
= 1; k
< max_color_exports
; k
++) {
1987 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
1988 output
[j
].gpr
= shader
->output
[i
].gpr
;
1989 output
[j
].elem_size
= 3;
1990 output
[j
].swizzle_x
= 0;
1991 output
[j
].swizzle_y
= 1;
1992 output
[j
].swizzle_z
= 2;
1993 output
[j
].swizzle_w
= key
.alpha_to_one
? 5 : 3;
1994 output
[j
].burst_count
= 1;
1995 output
[j
].array_base
= k
;
1996 output
[j
].op
= CF_OP_EXPORT
;
1997 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
1998 shader
->nr_ps_color_exports
++;
2001 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
2002 output
[j
].array_base
= 61;
2003 output
[j
].swizzle_x
= 2;
2004 output
[j
].swizzle_y
= 7;
2005 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2006 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2007 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
2008 output
[j
].array_base
= 61;
2009 output
[j
].swizzle_x
= 7;
2010 output
[j
].swizzle_y
= 1;
2011 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2012 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2014 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
2020 R600_ERR("unsupported processor type %d\n", ctx
.type
);
2025 if (output
[j
].type
==-1) {
2026 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2027 output
[j
].array_base
= next_param_base
++;
2031 /* add fake position export */
2032 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& pos_emitted
== false) {
2033 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2035 output
[j
].elem_size
= 3;
2036 output
[j
].swizzle_x
= 7;
2037 output
[j
].swizzle_y
= 7;
2038 output
[j
].swizzle_z
= 7;
2039 output
[j
].swizzle_w
= 7;
2040 output
[j
].burst_count
= 1;
2041 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2042 output
[j
].array_base
= 60;
2043 output
[j
].op
= CF_OP_EXPORT
;
2047 /* add fake param output for vertex shader if no param is exported */
2048 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
2049 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2051 output
[j
].elem_size
= 3;
2052 output
[j
].swizzle_x
= 7;
2053 output
[j
].swizzle_y
= 7;
2054 output
[j
].swizzle_z
= 7;
2055 output
[j
].swizzle_w
= 7;
2056 output
[j
].burst_count
= 1;
2057 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2058 output
[j
].array_base
= 0;
2059 output
[j
].op
= CF_OP_EXPORT
;
2063 /* add fake pixel export */
2064 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
2065 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2067 output
[j
].elem_size
= 3;
2068 output
[j
].swizzle_x
= 7;
2069 output
[j
].swizzle_y
= 7;
2070 output
[j
].swizzle_z
= 7;
2071 output
[j
].swizzle_w
= 7;
2072 output
[j
].burst_count
= 1;
2073 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2074 output
[j
].array_base
= 0;
2075 output
[j
].op
= CF_OP_EXPORT
;
2081 /* set export done on last export of each type */
2082 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
2083 if (!(output_done
& (1 << output
[i
].type
))) {
2084 output_done
|= (1 << output
[i
].type
);
2085 output
[i
].op
= CF_OP_EXPORT_DONE
;
2088 /* add output to bytecode */
2090 for (i
= 0; i
< noutput
; i
++) {
2091 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
2098 /* add program end */
2100 if (ctx
.bc
->chip_class
== CAYMAN
)
2101 cm_bytecode_add_cf_end(ctx
.bc
);
2103 const struct cf_op_info
*last
= NULL
;
2105 if (ctx
.bc
->cf_last
)
2106 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
2108 /* alu clause instructions don't have EOP bit, so add NOP */
2109 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
)
2110 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2112 ctx
.bc
->cf_last
->end_of_program
= 1;
2116 /* check GPR limit - we have 124 = 128 - 4
2117 * (4 are reserved as alu clause temporary registers) */
2118 if (ctx
.bc
->ngpr
> 124) {
2119 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
2124 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2125 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
2130 tgsi_parse_free(&ctx
.parse
);
2134 tgsi_parse_free(&ctx
.parse
);
2138 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
2140 R600_ERR("%s tgsi opcode unsupported\n",
2141 tgsi_get_opcode_name(ctx
->inst_info
->tgsi_opcode
));
2145 static int tgsi_end(struct r600_shader_ctx
*ctx
)
2150 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
2151 const struct r600_shader_src
*shader_src
,
2154 bc_src
->sel
= shader_src
->sel
;
2155 bc_src
->chan
= shader_src
->swizzle
[chan
];
2156 bc_src
->neg
= shader_src
->neg
;
2157 bc_src
->abs
= shader_src
->abs
;
2158 bc_src
->rel
= shader_src
->rel
;
2159 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
2160 bc_src
->kc_bank
= shader_src
->kc_bank
;
2163 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2169 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2171 bc_src
->neg
= !bc_src
->neg
;
2174 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2175 const struct tgsi_full_dst_register
*tgsi_dst
,
2177 struct r600_bytecode_alu_dst
*r600_dst
)
2179 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2181 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2182 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2183 r600_dst
->chan
= swizzle
;
2184 r600_dst
->write
= 1;
2185 if (tgsi_dst
->Register
.Indirect
)
2186 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2187 if (inst
->Instruction
.Saturate
) {
2188 r600_dst
->clamp
= 1;
2192 static int tgsi_last_instruction(unsigned writemask
)
2196 for (i
= 0; i
< 4; i
++) {
2197 if (writemask
& (1 << i
)) {
2204 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
2206 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2207 struct r600_bytecode_alu alu
;
2208 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2209 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2210 /* use temp register if trans_only and more than one dst component */
2211 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
2213 for (i
= 0; i
<= lasti
; i
++) {
2214 if (!(write_mask
& (1 << i
)))
2217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2219 alu
.dst
.sel
= ctx
->temp_reg
;
2223 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2225 alu
.op
= ctx
->inst_info
->op
;
2227 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2228 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2231 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2232 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2234 /* handle some special cases */
2235 switch (ctx
->inst_info
->tgsi_opcode
) {
2236 case TGSI_OPCODE_SUB
:
2237 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2239 case TGSI_OPCODE_ABS
:
2240 r600_bytecode_src_set_abs(&alu
.src
[0]);
2245 if (i
== lasti
|| trans_only
) {
2248 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2254 /* move result from temp to dst */
2255 for (i
= 0; i
<= lasti
; i
++) {
2256 if (!(write_mask
& (1 << i
)))
2259 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2260 alu
.op
= ALU_OP1_MOV
;
2261 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2262 alu
.src
[0].sel
= ctx
->temp_reg
;
2263 alu
.src
[0].chan
= i
;
2264 alu
.last
= (i
== lasti
);
2266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2274 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2276 return tgsi_op2_s(ctx
, 0, 0);
2279 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2281 return tgsi_op2_s(ctx
, 1, 0);
2284 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2286 return tgsi_op2_s(ctx
, 0, 1);
2289 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2291 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2292 struct r600_bytecode_alu alu
;
2294 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2296 for (i
= 0; i
< lasti
+ 1; i
++) {
2298 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2301 alu
.op
= ctx
->inst_info
->op
;
2303 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2305 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2307 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2312 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2320 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
2322 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2324 struct r600_bytecode_alu alu
;
2325 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2327 for (i
= 0 ; i
< last_slot
; i
++) {
2328 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2329 alu
.op
= ctx
->inst_info
->op
;
2330 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2331 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
2333 /* RSQ should take the absolute value of src */
2334 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_RSQ
) {
2335 r600_bytecode_src_set_abs(&alu
.src
[j
]);
2338 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2339 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2341 if (i
== last_slot
- 1)
2343 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2350 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
2352 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2354 struct r600_bytecode_alu alu
;
2355 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2356 for (k
= 0; k
< last_slot
; k
++) {
2357 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
2360 for (i
= 0 ; i
< 4; i
++) {
2361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2362 alu
.op
= ctx
->inst_info
->op
;
2363 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2364 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
2366 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2367 alu
.dst
.write
= (i
== k
);
2370 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2379 * r600 - trunc to -PI..PI range
2380 * r700 - normalize by dividing by 2PI
2383 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
2385 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
2386 static float double_pi
= 3.1415926535 * 2;
2387 static float neg_pi
= -3.1415926535;
2390 struct r600_bytecode_alu alu
;
2392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2393 alu
.op
= ALU_OP3_MULADD
;
2397 alu
.dst
.sel
= ctx
->temp_reg
;
2400 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2402 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2403 alu
.src
[1].chan
= 0;
2404 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
2405 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2406 alu
.src
[2].chan
= 0;
2408 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2412 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2413 alu
.op
= ALU_OP1_FRACT
;
2416 alu
.dst
.sel
= ctx
->temp_reg
;
2419 alu
.src
[0].sel
= ctx
->temp_reg
;
2420 alu
.src
[0].chan
= 0;
2422 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2426 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2427 alu
.op
= ALU_OP3_MULADD
;
2431 alu
.dst
.sel
= ctx
->temp_reg
;
2434 alu
.src
[0].sel
= ctx
->temp_reg
;
2435 alu
.src
[0].chan
= 0;
2437 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2438 alu
.src
[1].chan
= 0;
2439 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
2440 alu
.src
[2].chan
= 0;
2442 if (ctx
->bc
->chip_class
== R600
) {
2443 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
2444 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
2446 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2447 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
2452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2458 static int cayman_trig(struct r600_shader_ctx
*ctx
)
2460 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2461 struct r600_bytecode_alu alu
;
2462 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2465 r
= tgsi_setup_trig(ctx
);
2470 for (i
= 0; i
< last_slot
; i
++) {
2471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2472 alu
.op
= ctx
->inst_info
->op
;
2475 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2476 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2478 alu
.src
[0].sel
= ctx
->temp_reg
;
2479 alu
.src
[0].chan
= 0;
2480 if (i
== last_slot
- 1)
2482 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2489 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
2491 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2492 struct r600_bytecode_alu alu
;
2494 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2496 r
= tgsi_setup_trig(ctx
);
2500 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2501 alu
.op
= ctx
->inst_info
->op
;
2503 alu
.dst
.sel
= ctx
->temp_reg
;
2506 alu
.src
[0].sel
= ctx
->temp_reg
;
2507 alu
.src
[0].chan
= 0;
2509 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2513 /* replicate result */
2514 for (i
= 0; i
< lasti
+ 1; i
++) {
2515 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2519 alu
.op
= ALU_OP1_MOV
;
2521 alu
.src
[0].sel
= ctx
->temp_reg
;
2522 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2525 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2532 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
2534 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2535 struct r600_bytecode_alu alu
;
2538 /* We'll only need the trig stuff if we are going to write to the
2539 * X or Y components of the destination vector.
2541 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
2542 r
= tgsi_setup_trig(ctx
);
2548 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
2549 if (ctx
->bc
->chip_class
== CAYMAN
) {
2550 for (i
= 0 ; i
< 3; i
++) {
2551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2552 alu
.op
= ALU_OP1_COS
;
2553 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2559 alu
.src
[0].sel
= ctx
->temp_reg
;
2560 alu
.src
[0].chan
= 0;
2563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2568 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2569 alu
.op
= ALU_OP1_COS
;
2570 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2572 alu
.src
[0].sel
= ctx
->temp_reg
;
2573 alu
.src
[0].chan
= 0;
2575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2582 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
2583 if (ctx
->bc
->chip_class
== CAYMAN
) {
2584 for (i
= 0 ; i
< 3; i
++) {
2585 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2586 alu
.op
= ALU_OP1_SIN
;
2587 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2592 alu
.src
[0].sel
= ctx
->temp_reg
;
2593 alu
.src
[0].chan
= 0;
2596 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2602 alu
.op
= ALU_OP1_SIN
;
2603 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2605 alu
.src
[0].sel
= ctx
->temp_reg
;
2606 alu
.src
[0].chan
= 0;
2608 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2615 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
2616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2618 alu
.op
= ALU_OP1_MOV
;
2620 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2622 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2623 alu
.src
[0].chan
= 0;
2627 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2633 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
2634 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2636 alu
.op
= ALU_OP1_MOV
;
2638 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2640 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2641 alu
.src
[0].chan
= 0;
2645 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2653 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
2655 struct r600_bytecode_alu alu
;
2658 for (i
= 0; i
< 4; i
++) {
2659 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2660 alu
.op
= ctx
->inst_info
->op
;
2664 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2666 if (ctx
->inst_info
->tgsi_opcode
== TGSI_OPCODE_KILL
) {
2667 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
2670 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2675 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2680 /* kill must be last in ALU */
2681 ctx
->bc
->force_add_cf
= 1;
2682 ctx
->shader
->uses_kill
= TRUE
;
2686 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
2688 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2689 struct r600_bytecode_alu alu
;
2692 /* tmp.x = max(src.y, 0.0) */
2693 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2694 alu
.op
= ALU_OP2_MAX
;
2695 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
2696 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2697 alu
.src
[1].chan
= 1;
2699 alu
.dst
.sel
= ctx
->temp_reg
;
2704 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2708 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
2714 if (ctx
->bc
->chip_class
== CAYMAN
) {
2715 for (i
= 0; i
< 3; i
++) {
2716 /* tmp.z = log(tmp.x) */
2717 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2718 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2719 alu
.src
[0].sel
= ctx
->temp_reg
;
2720 alu
.src
[0].chan
= 0;
2721 alu
.dst
.sel
= ctx
->temp_reg
;
2729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2734 /* tmp.z = log(tmp.x) */
2735 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2736 alu
.op
= ALU_OP1_LOG_CLAMPED
;
2737 alu
.src
[0].sel
= ctx
->temp_reg
;
2738 alu
.src
[0].chan
= 0;
2739 alu
.dst
.sel
= ctx
->temp_reg
;
2743 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2748 chan
= alu
.dst
.chan
;
2751 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
2752 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2753 alu
.op
= ALU_OP3_MUL_LIT
;
2754 alu
.src
[0].sel
= sel
;
2755 alu
.src
[0].chan
= chan
;
2756 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
2757 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
2758 alu
.dst
.sel
= ctx
->temp_reg
;
2763 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2767 if (ctx
->bc
->chip_class
== CAYMAN
) {
2768 for (i
= 0; i
< 3; i
++) {
2769 /* dst.z = exp(tmp.x) */
2770 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2771 alu
.op
= ALU_OP1_EXP_IEEE
;
2772 alu
.src
[0].sel
= ctx
->temp_reg
;
2773 alu
.src
[0].chan
= 0;
2774 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2780 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2785 /* dst.z = exp(tmp.x) */
2786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2787 alu
.op
= ALU_OP1_EXP_IEEE
;
2788 alu
.src
[0].sel
= ctx
->temp_reg
;
2789 alu
.src
[0].chan
= 0;
2790 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
2792 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2800 alu
.op
= ALU_OP1_MOV
;
2801 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
2802 alu
.src
[0].chan
= 0;
2803 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
2804 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
2805 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2809 /* dst.y = max(src.x, 0.0) */
2810 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2811 alu
.op
= ALU_OP2_MAX
;
2812 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2813 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
2814 alu
.src
[1].chan
= 0;
2815 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
2816 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
2817 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2823 alu
.op
= ALU_OP1_MOV
;
2824 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
2825 alu
.src
[0].chan
= 0;
2826 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
2827 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
2829 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2836 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
2838 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2839 struct r600_bytecode_alu alu
;
2842 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2845 * For state trackers other than OpenGL, we'll want to use
2846 * _RECIPSQRT_IEEE instead.
2848 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
2850 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2851 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2852 r600_bytecode_src_set_abs(&alu
.src
[i
]);
2854 alu
.dst
.sel
= ctx
->temp_reg
;
2857 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2860 /* replicate result */
2861 return tgsi_helper_tempx_replicate(ctx
);
2864 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
2866 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2867 struct r600_bytecode_alu alu
;
2870 for (i
= 0; i
< 4; i
++) {
2871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2872 alu
.src
[0].sel
= ctx
->temp_reg
;
2873 alu
.op
= ALU_OP1_MOV
;
2875 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2876 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2879 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2886 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
2888 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2889 struct r600_bytecode_alu alu
;
2892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2893 alu
.op
= ctx
->inst_info
->op
;
2894 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2895 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
2897 alu
.dst
.sel
= ctx
->temp_reg
;
2900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2903 /* replicate result */
2904 return tgsi_helper_tempx_replicate(ctx
);
2907 static int cayman_pow(struct r600_shader_ctx
*ctx
)
2909 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2911 struct r600_bytecode_alu alu
;
2912 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
2914 for (i
= 0; i
< 3; i
++) {
2915 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2916 alu
.op
= ALU_OP1_LOG_IEEE
;
2917 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2918 alu
.dst
.sel
= ctx
->temp_reg
;
2923 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2929 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2930 alu
.op
= ALU_OP2_MUL
;
2931 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2932 alu
.src
[1].sel
= ctx
->temp_reg
;
2933 alu
.dst
.sel
= ctx
->temp_reg
;
2936 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2940 for (i
= 0; i
< last_slot
; i
++) {
2941 /* POW(a,b) = EXP2(b * LOG2(a))*/
2942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2943 alu
.op
= ALU_OP1_EXP_IEEE
;
2944 alu
.src
[0].sel
= ctx
->temp_reg
;
2946 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2947 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
2948 if (i
== last_slot
- 1)
2950 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2957 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
2959 struct r600_bytecode_alu alu
;
2963 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2964 alu
.op
= ALU_OP1_LOG_IEEE
;
2965 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
2966 alu
.dst
.sel
= ctx
->temp_reg
;
2969 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2974 alu
.op
= ALU_OP2_MUL
;
2975 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
2976 alu
.src
[1].sel
= ctx
->temp_reg
;
2977 alu
.dst
.sel
= ctx
->temp_reg
;
2980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2983 /* POW(a,b) = EXP2(b * LOG2(a))*/
2984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2985 alu
.op
= ALU_OP1_EXP_IEEE
;
2986 alu
.src
[0].sel
= ctx
->temp_reg
;
2987 alu
.dst
.sel
= ctx
->temp_reg
;
2990 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2993 return tgsi_helper_tempx_replicate(ctx
);
2996 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
2998 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2999 struct r600_bytecode_alu alu
;
3001 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3002 int tmp0
= ctx
->temp_reg
;
3003 int tmp1
= r600_get_temp(ctx
);
3004 int tmp2
= r600_get_temp(ctx
);
3005 int tmp3
= r600_get_temp(ctx
);
3008 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
3010 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
3011 * 2. tmp0.z = lo (tmp0.x * src2)
3012 * 3. tmp0.w = -tmp0.z
3013 * 4. tmp0.y = hi (tmp0.x * src2)
3014 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
3015 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
3016 * 7. tmp1.x = tmp0.x - tmp0.w
3017 * 8. tmp1.y = tmp0.x + tmp0.w
3018 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
3019 * 10. tmp0.z = hi(tmp0.x * src1) = q
3020 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
3022 * 12. tmp0.w = src1 - tmp0.y = r
3023 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
3024 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
3028 * 15. tmp1.z = tmp0.z + 1 = q + 1
3029 * 16. tmp1.w = tmp0.z - 1 = q - 1
3033 * 15. tmp1.z = tmp0.w - src2 = r - src2
3034 * 16. tmp1.w = tmp0.w + src2 = r + src2
3038 * 17. tmp1.x = tmp1.x & tmp1.y
3040 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
3041 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
3043 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
3044 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
3048 * Same as unsigned, using abs values of the operands,
3049 * and fixing the sign of the result in the end.
3052 for (i
= 0; i
< 4; i
++) {
3053 if (!(write_mask
& (1<<i
)))
3058 /* tmp2.x = -src0 */
3059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3060 alu
.op
= ALU_OP2_SUB_INT
;
3066 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3068 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3071 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3074 /* tmp2.y = -src1 */
3075 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3076 alu
.op
= ALU_OP2_SUB_INT
;
3082 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3084 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3087 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3090 /* tmp2.z sign bit is set if src0 and src2 signs are different */
3091 /* it will be a sign of the quotient */
3094 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3095 alu
.op
= ALU_OP2_XOR_INT
;
3101 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3102 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3105 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3109 /* tmp2.x = |src0| */
3110 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3111 alu
.op
= ALU_OP3_CNDGE_INT
;
3118 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3119 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3120 alu
.src
[2].sel
= tmp2
;
3121 alu
.src
[2].chan
= 0;
3124 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3127 /* tmp2.y = |src1| */
3128 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3129 alu
.op
= ALU_OP3_CNDGE_INT
;
3136 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3137 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3138 alu
.src
[2].sel
= tmp2
;
3139 alu
.src
[2].chan
= 1;
3142 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3147 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
3148 if (ctx
->bc
->chip_class
== CAYMAN
) {
3149 /* tmp3.x = u2f(src2) */
3150 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3151 alu
.op
= ALU_OP1_UINT_TO_FLT
;
3158 alu
.src
[0].sel
= tmp2
;
3159 alu
.src
[0].chan
= 1;
3161 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3165 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3168 /* tmp0.x = recip(tmp3.x) */
3169 for (j
= 0 ; j
< 3; j
++) {
3170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3171 alu
.op
= ALU_OP1_RECIP_IEEE
;
3175 alu
.dst
.write
= (j
== 0);
3177 alu
.src
[0].sel
= tmp3
;
3178 alu
.src
[0].chan
= 0;
3182 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3186 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3187 alu
.op
= ALU_OP2_MUL
;
3189 alu
.src
[0].sel
= tmp0
;
3190 alu
.src
[0].chan
= 0;
3192 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3193 alu
.src
[1].value
= 0x4f800000;
3198 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3203 alu
.op
= ALU_OP1_FLT_TO_UINT
;
3209 alu
.src
[0].sel
= tmp3
;
3210 alu
.src
[0].chan
= 0;
3213 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3218 alu
.op
= ALU_OP1_RECIP_UINT
;
3225 alu
.src
[0].sel
= tmp2
;
3226 alu
.src
[0].chan
= 1;
3228 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3232 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3236 /* 2. tmp0.z = lo (tmp0.x * src2) */
3237 if (ctx
->bc
->chip_class
== CAYMAN
) {
3238 for (j
= 0 ; j
< 4; j
++) {
3239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3240 alu
.op
= ALU_OP2_MULLO_UINT
;
3244 alu
.dst
.write
= (j
== 2);
3246 alu
.src
[0].sel
= tmp0
;
3247 alu
.src
[0].chan
= 0;
3249 alu
.src
[1].sel
= tmp2
;
3250 alu
.src
[1].chan
= 1;
3252 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3255 alu
.last
= (j
== 3);
3256 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3261 alu
.op
= ALU_OP2_MULLO_UINT
;
3267 alu
.src
[0].sel
= tmp0
;
3268 alu
.src
[0].chan
= 0;
3270 alu
.src
[1].sel
= tmp2
;
3271 alu
.src
[1].chan
= 1;
3273 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3277 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3281 /* 3. tmp0.w = -tmp0.z */
3282 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3283 alu
.op
= ALU_OP2_SUB_INT
;
3289 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3290 alu
.src
[1].sel
= tmp0
;
3291 alu
.src
[1].chan
= 2;
3294 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3297 /* 4. tmp0.y = hi (tmp0.x * src2) */
3298 if (ctx
->bc
->chip_class
== CAYMAN
) {
3299 for (j
= 0 ; j
< 4; j
++) {
3300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3301 alu
.op
= ALU_OP2_MULHI_UINT
;
3305 alu
.dst
.write
= (j
== 1);
3307 alu
.src
[0].sel
= tmp0
;
3308 alu
.src
[0].chan
= 0;
3311 alu
.src
[1].sel
= tmp2
;
3312 alu
.src
[1].chan
= 1;
3314 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3316 alu
.last
= (j
== 3);
3317 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3322 alu
.op
= ALU_OP2_MULHI_UINT
;
3328 alu
.src
[0].sel
= tmp0
;
3329 alu
.src
[0].chan
= 0;
3332 alu
.src
[1].sel
= tmp2
;
3333 alu
.src
[1].chan
= 1;
3335 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3339 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3343 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
3344 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3345 alu
.op
= ALU_OP3_CNDE_INT
;
3352 alu
.src
[0].sel
= tmp0
;
3353 alu
.src
[0].chan
= 1;
3354 alu
.src
[1].sel
= tmp0
;
3355 alu
.src
[1].chan
= 3;
3356 alu
.src
[2].sel
= tmp0
;
3357 alu
.src
[2].chan
= 2;
3360 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3363 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
3364 if (ctx
->bc
->chip_class
== CAYMAN
) {
3365 for (j
= 0 ; j
< 4; j
++) {
3366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3367 alu
.op
= ALU_OP2_MULHI_UINT
;
3371 alu
.dst
.write
= (j
== 3);
3373 alu
.src
[0].sel
= tmp0
;
3374 alu
.src
[0].chan
= 2;
3376 alu
.src
[1].sel
= tmp0
;
3377 alu
.src
[1].chan
= 0;
3379 alu
.last
= (j
== 3);
3380 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3385 alu
.op
= ALU_OP2_MULHI_UINT
;
3391 alu
.src
[0].sel
= tmp0
;
3392 alu
.src
[0].chan
= 2;
3394 alu
.src
[1].sel
= tmp0
;
3395 alu
.src
[1].chan
= 0;
3398 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3402 /* 7. tmp1.x = tmp0.x - tmp0.w */
3403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3404 alu
.op
= ALU_OP2_SUB_INT
;
3410 alu
.src
[0].sel
= tmp0
;
3411 alu
.src
[0].chan
= 0;
3412 alu
.src
[1].sel
= tmp0
;
3413 alu
.src
[1].chan
= 3;
3416 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3419 /* 8. tmp1.y = tmp0.x + tmp0.w */
3420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3421 alu
.op
= ALU_OP2_ADD_INT
;
3427 alu
.src
[0].sel
= tmp0
;
3428 alu
.src
[0].chan
= 0;
3429 alu
.src
[1].sel
= tmp0
;
3430 alu
.src
[1].chan
= 3;
3433 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3436 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
3437 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3438 alu
.op
= ALU_OP3_CNDE_INT
;
3445 alu
.src
[0].sel
= tmp0
;
3446 alu
.src
[0].chan
= 1;
3447 alu
.src
[1].sel
= tmp1
;
3448 alu
.src
[1].chan
= 1;
3449 alu
.src
[2].sel
= tmp1
;
3450 alu
.src
[2].chan
= 0;
3453 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3456 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
3457 if (ctx
->bc
->chip_class
== CAYMAN
) {
3458 for (j
= 0 ; j
< 4; j
++) {
3459 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3460 alu
.op
= ALU_OP2_MULHI_UINT
;
3464 alu
.dst
.write
= (j
== 2);
3466 alu
.src
[0].sel
= tmp0
;
3467 alu
.src
[0].chan
= 0;
3470 alu
.src
[1].sel
= tmp2
;
3471 alu
.src
[1].chan
= 0;
3473 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3476 alu
.last
= (j
== 3);
3477 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3482 alu
.op
= ALU_OP2_MULHI_UINT
;
3488 alu
.src
[0].sel
= tmp0
;
3489 alu
.src
[0].chan
= 0;
3492 alu
.src
[1].sel
= tmp2
;
3493 alu
.src
[1].chan
= 0;
3495 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3499 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3503 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
3504 if (ctx
->bc
->chip_class
== CAYMAN
) {
3505 for (j
= 0 ; j
< 4; j
++) {
3506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3507 alu
.op
= ALU_OP2_MULLO_UINT
;
3511 alu
.dst
.write
= (j
== 1);
3514 alu
.src
[0].sel
= tmp2
;
3515 alu
.src
[0].chan
= 1;
3517 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3520 alu
.src
[1].sel
= tmp0
;
3521 alu
.src
[1].chan
= 2;
3523 alu
.last
= (j
== 3);
3524 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3529 alu
.op
= ALU_OP2_MULLO_UINT
;
3536 alu
.src
[0].sel
= tmp2
;
3537 alu
.src
[0].chan
= 1;
3539 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
3542 alu
.src
[1].sel
= tmp0
;
3543 alu
.src
[1].chan
= 2;
3546 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3550 /* 12. tmp0.w = src1 - tmp0.y = r */
3551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3552 alu
.op
= ALU_OP2_SUB_INT
;
3559 alu
.src
[0].sel
= tmp2
;
3560 alu
.src
[0].chan
= 0;
3562 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3565 alu
.src
[1].sel
= tmp0
;
3566 alu
.src
[1].chan
= 1;
3569 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3572 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
3573 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3574 alu
.op
= ALU_OP2_SETGE_UINT
;
3580 alu
.src
[0].sel
= tmp0
;
3581 alu
.src
[0].chan
= 3;
3583 alu
.src
[1].sel
= tmp2
;
3584 alu
.src
[1].chan
= 1;
3586 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3590 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3593 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
3594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3595 alu
.op
= ALU_OP2_SETGE_UINT
;
3602 alu
.src
[0].sel
= tmp2
;
3603 alu
.src
[0].chan
= 0;
3605 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3608 alu
.src
[1].sel
= tmp0
;
3609 alu
.src
[1].chan
= 1;
3612 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3615 if (mod
) { /* UMOD */
3617 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
3618 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3619 alu
.op
= ALU_OP2_SUB_INT
;
3625 alu
.src
[0].sel
= tmp0
;
3626 alu
.src
[0].chan
= 3;
3629 alu
.src
[1].sel
= tmp2
;
3630 alu
.src
[1].chan
= 1;
3632 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3636 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3639 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
3640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3641 alu
.op
= ALU_OP2_ADD_INT
;
3647 alu
.src
[0].sel
= tmp0
;
3648 alu
.src
[0].chan
= 3;
3650 alu
.src
[1].sel
= tmp2
;
3651 alu
.src
[1].chan
= 1;
3653 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
3657 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3662 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
3663 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3664 alu
.op
= ALU_OP2_ADD_INT
;
3670 alu
.src
[0].sel
= tmp0
;
3671 alu
.src
[0].chan
= 2;
3672 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
3675 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3678 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
3679 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3680 alu
.op
= ALU_OP2_ADD_INT
;
3686 alu
.src
[0].sel
= tmp0
;
3687 alu
.src
[0].chan
= 2;
3688 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
3691 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3696 /* 17. tmp1.x = tmp1.x & tmp1.y */
3697 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3698 alu
.op
= ALU_OP2_AND_INT
;
3704 alu
.src
[0].sel
= tmp1
;
3705 alu
.src
[0].chan
= 0;
3706 alu
.src
[1].sel
= tmp1
;
3707 alu
.src
[1].chan
= 1;
3710 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3713 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
3714 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
3715 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3716 alu
.op
= ALU_OP3_CNDE_INT
;
3723 alu
.src
[0].sel
= tmp1
;
3724 alu
.src
[0].chan
= 0;
3725 alu
.src
[1].sel
= tmp0
;
3726 alu
.src
[1].chan
= mod
? 3 : 2;
3727 alu
.src
[2].sel
= tmp1
;
3728 alu
.src
[2].chan
= 2;
3731 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3734 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
3735 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3736 alu
.op
= ALU_OP3_CNDE_INT
;
3744 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3747 alu
.src
[0].sel
= tmp1
;
3748 alu
.src
[0].chan
= 1;
3749 alu
.src
[1].sel
= tmp1
;
3750 alu
.src
[1].chan
= 3;
3751 alu
.src
[2].sel
= tmp0
;
3752 alu
.src
[2].chan
= 2;
3755 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3760 /* fix the sign of the result */
3764 /* tmp0.x = -tmp0.z */
3765 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3766 alu
.op
= ALU_OP2_SUB_INT
;
3772 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3773 alu
.src
[1].sel
= tmp0
;
3774 alu
.src
[1].chan
= 2;
3777 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3780 /* sign of the remainder is the same as the sign of src0 */
3781 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
3782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3783 alu
.op
= ALU_OP3_CNDGE_INT
;
3786 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3788 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3789 alu
.src
[1].sel
= tmp0
;
3790 alu
.src
[1].chan
= 2;
3791 alu
.src
[2].sel
= tmp0
;
3792 alu
.src
[2].chan
= 0;
3795 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3800 /* tmp0.x = -tmp0.z */
3801 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3802 alu
.op
= ALU_OP2_SUB_INT
;
3808 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3809 alu
.src
[1].sel
= tmp0
;
3810 alu
.src
[1].chan
= 2;
3813 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3816 /* fix the quotient sign (same as the sign of src0*src1) */
3817 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
3818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3819 alu
.op
= ALU_OP3_CNDGE_INT
;
3822 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3824 alu
.src
[0].sel
= tmp2
;
3825 alu
.src
[0].chan
= 2;
3826 alu
.src
[1].sel
= tmp0
;
3827 alu
.src
[1].chan
= 2;
3828 alu
.src
[2].sel
= tmp0
;
3829 alu
.src
[2].chan
= 0;
3832 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
3840 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
3842 return tgsi_divmod(ctx
, 0, 0);
3845 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
3847 return tgsi_divmod(ctx
, 1, 0);
3850 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
3852 return tgsi_divmod(ctx
, 0, 1);
3855 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
3857 return tgsi_divmod(ctx
, 1, 1);
3861 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
3863 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3864 struct r600_bytecode_alu alu
;
3866 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3867 int last_inst
= tgsi_last_instruction(write_mask
);
3869 for (i
= 0; i
< 4; i
++) {
3870 if (!(write_mask
& (1<<i
)))
3873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3874 alu
.op
= ALU_OP1_TRUNC
;
3876 alu
.dst
.sel
= ctx
->temp_reg
;
3880 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3883 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3888 for (i
= 0; i
< 4; i
++) {
3889 if (!(write_mask
& (1<<i
)))
3892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3893 alu
.op
= ctx
->inst_info
->op
;
3895 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3897 alu
.src
[0].sel
= ctx
->temp_reg
;
3898 alu
.src
[0].chan
= i
;
3900 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
3902 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3910 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
3912 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3913 struct r600_bytecode_alu alu
;
3915 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3916 int last_inst
= tgsi_last_instruction(write_mask
);
3919 for (i
= 0; i
< 4; i
++) {
3920 if (!(write_mask
& (1<<i
)))
3923 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3924 alu
.op
= ALU_OP2_SUB_INT
;
3926 alu
.dst
.sel
= ctx
->temp_reg
;
3930 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3931 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3935 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3940 /* dst = (src >= 0 ? src : tmp) */
3941 for (i
= 0; i
< 4; i
++) {
3942 if (!(write_mask
& (1<<i
)))
3945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3946 alu
.op
= ALU_OP3_CNDGE_INT
;
3950 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3952 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3953 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3954 alu
.src
[2].sel
= ctx
->temp_reg
;
3955 alu
.src
[2].chan
= i
;
3959 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3966 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
3968 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3969 struct r600_bytecode_alu alu
;
3971 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3972 int last_inst
= tgsi_last_instruction(write_mask
);
3974 /* tmp = (src >= 0 ? src : -1) */
3975 for (i
= 0; i
< 4; i
++) {
3976 if (!(write_mask
& (1<<i
)))
3979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3980 alu
.op
= ALU_OP3_CNDGE_INT
;
3983 alu
.dst
.sel
= ctx
->temp_reg
;
3987 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3988 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3989 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
3993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3998 /* dst = (tmp > 0 ? 1 : tmp) */
3999 for (i
= 0; i
< 4; i
++) {
4000 if (!(write_mask
& (1<<i
)))
4003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4004 alu
.op
= ALU_OP3_CNDGT_INT
;
4008 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4010 alu
.src
[0].sel
= ctx
->temp_reg
;
4011 alu
.src
[0].chan
= i
;
4013 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
4015 alu
.src
[2].sel
= ctx
->temp_reg
;
4016 alu
.src
[2].chan
= i
;
4020 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4029 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
4031 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4032 struct r600_bytecode_alu alu
;
4035 /* tmp = (src > 0 ? 1 : src) */
4036 for (i
= 0; i
< 4; i
++) {
4037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4038 alu
.op
= ALU_OP3_CNDGT
;
4041 alu
.dst
.sel
= ctx
->temp_reg
;
4044 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4045 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4046 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
4050 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4055 /* dst = (-tmp > 0 ? -1 : tmp) */
4056 for (i
= 0; i
< 4; i
++) {
4057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4058 alu
.op
= ALU_OP3_CNDGT
;
4060 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4062 alu
.src
[0].sel
= ctx
->temp_reg
;
4063 alu
.src
[0].chan
= i
;
4066 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4069 alu
.src
[2].sel
= ctx
->temp_reg
;
4070 alu
.src
[2].chan
= i
;
4074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4081 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
4083 struct r600_bytecode_alu alu
;
4086 for (i
= 0; i
< 4; i
++) {
4087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4088 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
4089 alu
.op
= ALU_OP0_NOP
;
4092 alu
.op
= ALU_OP1_MOV
;
4093 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4094 alu
.src
[0].sel
= ctx
->temp_reg
;
4095 alu
.src
[0].chan
= i
;
4100 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4107 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
4109 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4110 struct r600_bytecode_alu alu
;
4112 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4114 for (i
= 0; i
< lasti
+ 1; i
++) {
4115 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4118 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4119 alu
.op
= ctx
->inst_info
->op
;
4120 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4121 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4124 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4138 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
4140 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4141 struct r600_bytecode_alu alu
;
4144 for (i
= 0; i
< 4; i
++) {
4145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4146 alu
.op
= ctx
->inst_info
->op
;
4147 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4148 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4151 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4153 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4154 /* handle some special cases */
4155 switch (ctx
->inst_info
->tgsi_opcode
) {
4156 case TGSI_OPCODE_DP2
:
4158 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4159 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4162 case TGSI_OPCODE_DP3
:
4164 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
4165 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
4168 case TGSI_OPCODE_DPH
:
4170 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4171 alu
.src
[0].chan
= 0;
4181 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4188 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
4191 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4192 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
4193 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
4194 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
4195 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
;
4198 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
4201 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4202 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
4205 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
4207 struct r600_bytecode_vtx vtx
;
4208 struct r600_bytecode_alu alu
;
4209 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4211 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4213 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4214 if (src_requires_loading
) {
4215 for (i
= 0; i
< 4; i
++) {
4216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4217 alu
.op
= ALU_OP1_MOV
;
4218 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4219 alu
.dst
.sel
= ctx
->temp_reg
;
4224 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4228 src_gpr
= ctx
->temp_reg
;
4231 memset(&vtx
, 0, sizeof(vtx
));
4232 vtx
.op
= FETCH_OP_VFETCH
;
4233 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
4234 vtx
.fetch_type
= 2; /* VTX_FETCH_NO_INDEX_OFFSET */
4235 vtx
.src_gpr
= src_gpr
;
4236 vtx
.mega_fetch_count
= 16;
4237 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4238 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
4239 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
4240 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
4241 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
4242 vtx
.use_const_fields
= 1;
4243 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
4245 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
4248 if (ctx
->bc
->chip_class
>= EVERGREEN
)
4251 for (i
= 0; i
< 4; i
++) {
4252 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4253 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4257 alu
.op
= ALU_OP2_AND_INT
;
4260 alu
.dst
.sel
= vtx
.dst_gpr
;
4263 alu
.src
[0].sel
= vtx
.dst_gpr
;
4264 alu
.src
[0].chan
= i
;
4266 alu
.src
[1].sel
= 512 + (id
* 2);
4267 alu
.src
[1].chan
= i
% 4;
4268 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4272 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4277 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
4278 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4279 alu
.op
= ALU_OP2_OR_INT
;
4282 alu
.dst
.sel
= vtx
.dst_gpr
;
4285 alu
.src
[0].sel
= vtx
.dst_gpr
;
4286 alu
.src
[0].chan
= 3;
4288 alu
.src
[1].sel
= 512 + (id
* 2) + 1;
4289 alu
.src
[1].chan
= 0;
4290 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4293 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4300 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
4302 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4303 struct r600_bytecode_alu alu
;
4305 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
4307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4308 alu
.op
= ALU_OP1_MOV
;
4310 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4311 alu
.src
[0].sel
= 512 + (id
/ 4);
4312 alu
.src
[0].chan
= id
% 4;
4314 /* r600 we have them at channel 2 of the second dword */
4315 alu
.src
[0].sel
= 512 + (id
* 2) + 1;
4316 alu
.src
[0].chan
= 1;
4318 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
4319 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4321 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4327 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
4329 static float one_point_five
= 1.5f
;
4330 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4331 struct r600_bytecode_tex tex
;
4332 struct r600_bytecode_alu alu
;
4336 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
4337 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
4338 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
4339 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
4341 /* Texture fetch instructions can only use gprs as source.
4342 * Also they cannot negate the source or take the absolute value */
4343 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
4344 tgsi_tex_src_requires_loading(ctx
, 0)) ||
4345 read_compressed_msaa
;
4346 boolean src_loaded
= FALSE
;
4347 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
4348 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
4349 boolean has_txq_cube_array_z
= false;
4351 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
4352 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4353 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
4354 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
4355 ctx
->shader
->has_txq_cube_array_z_comp
= true;
4356 has_txq_cube_array_z
= true;
4359 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
4360 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4361 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4362 sampler_src_reg
= 2;
4364 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
4366 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
4367 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
4368 ctx
->shader
->uses_tex_buffers
= true;
4369 return r600_do_buffer_txq(ctx
);
4371 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
4372 if (ctx
->bc
->chip_class
< EVERGREEN
)
4373 ctx
->shader
->uses_tex_buffers
= true;
4374 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
4378 /* get offset values */
4379 if (inst
->Texture
.NumOffsets
) {
4380 assert(inst
->Texture
.NumOffsets
== 1);
4382 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
4383 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
4384 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
4387 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
4388 /* TGSI moves the sampler to src reg 3 for TXD */
4389 sampler_src_reg
= 3;
4391 for (i
= 1; i
< 3; i
++) {
4392 /* set gradients h/v */
4393 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4394 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
4395 FETCH_OP_SET_GRADIENTS_V
;
4396 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4397 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4399 if (tgsi_tex_src_requires_loading(ctx
, i
)) {
4400 tex
.src_gpr
= r600_get_temp(ctx
);
4406 for (j
= 0; j
< 4; j
++) {
4407 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4408 alu
.op
= ALU_OP1_MOV
;
4409 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
4410 alu
.dst
.sel
= tex
.src_gpr
;
4415 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4421 tex
.src_gpr
= tgsi_tex_get_src_gpr(ctx
, i
);
4422 tex
.src_sel_x
= ctx
->src
[i
].swizzle
[0];
4423 tex
.src_sel_y
= ctx
->src
[i
].swizzle
[1];
4424 tex
.src_sel_z
= ctx
->src
[i
].swizzle
[2];
4425 tex
.src_sel_w
= ctx
->src
[i
].swizzle
[3];
4426 tex
.src_rel
= ctx
->src
[i
].rel
;
4428 tex
.dst_gpr
= ctx
->temp_reg
; /* just to avoid confusing the asm scheduler */
4429 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4430 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
4431 tex
.coord_type_x
= 1;
4432 tex
.coord_type_y
= 1;
4433 tex
.coord_type_z
= 1;
4434 tex
.coord_type_w
= 1;
4436 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4440 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
4442 /* Add perspective divide */
4443 if (ctx
->bc
->chip_class
== CAYMAN
) {
4445 for (i
= 0; i
< 3; i
++) {
4446 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4447 alu
.op
= ALU_OP1_RECIP_IEEE
;
4448 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4450 alu
.dst
.sel
= ctx
->temp_reg
;
4456 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4463 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4464 alu
.op
= ALU_OP1_RECIP_IEEE
;
4465 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4467 alu
.dst
.sel
= ctx
->temp_reg
;
4468 alu
.dst
.chan
= out_chan
;
4471 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4476 for (i
= 0; i
< 3; i
++) {
4477 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4478 alu
.op
= ALU_OP2_MUL
;
4479 alu
.src
[0].sel
= ctx
->temp_reg
;
4480 alu
.src
[0].chan
= out_chan
;
4481 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4482 alu
.dst
.sel
= ctx
->temp_reg
;
4485 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4489 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4490 alu
.op
= ALU_OP1_MOV
;
4491 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4492 alu
.src
[0].chan
= 0;
4493 alu
.dst
.sel
= ctx
->temp_reg
;
4497 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4501 src_gpr
= ctx
->temp_reg
;
4504 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4505 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4506 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4507 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4508 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
4509 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
4511 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
4512 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
4514 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
4515 for (i
= 0; i
< 4; i
++) {
4516 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4517 alu
.op
= ALU_OP2_CUBE
;
4518 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
4519 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
4520 alu
.dst
.sel
= ctx
->temp_reg
;
4525 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4530 /* tmp1.z = RCP_e(|tmp1.z|) */
4531 if (ctx
->bc
->chip_class
== CAYMAN
) {
4532 for (i
= 0; i
< 3; i
++) {
4533 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4534 alu
.op
= ALU_OP1_RECIP_IEEE
;
4535 alu
.src
[0].sel
= ctx
->temp_reg
;
4536 alu
.src
[0].chan
= 2;
4538 alu
.dst
.sel
= ctx
->temp_reg
;
4544 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4550 alu
.op
= ALU_OP1_RECIP_IEEE
;
4551 alu
.src
[0].sel
= ctx
->temp_reg
;
4552 alu
.src
[0].chan
= 2;
4554 alu
.dst
.sel
= ctx
->temp_reg
;
4558 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4563 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
4564 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
4565 * muladd has no writemask, have to use another temp
4567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4568 alu
.op
= ALU_OP3_MULADD
;
4571 alu
.src
[0].sel
= ctx
->temp_reg
;
4572 alu
.src
[0].chan
= 0;
4573 alu
.src
[1].sel
= ctx
->temp_reg
;
4574 alu
.src
[1].chan
= 2;
4576 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4577 alu
.src
[2].chan
= 0;
4578 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4580 alu
.dst
.sel
= ctx
->temp_reg
;
4584 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4588 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4589 alu
.op
= ALU_OP3_MULADD
;
4592 alu
.src
[0].sel
= ctx
->temp_reg
;
4593 alu
.src
[0].chan
= 1;
4594 alu
.src
[1].sel
= ctx
->temp_reg
;
4595 alu
.src
[1].chan
= 2;
4597 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4598 alu
.src
[2].chan
= 0;
4599 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
4601 alu
.dst
.sel
= ctx
->temp_reg
;
4606 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4609 /* write initial compare value into Z component
4610 - W src 0 for shadow cube
4611 - X src 1 for shadow cube array */
4612 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4613 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4615 alu
.op
= ALU_OP1_MOV
;
4616 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
4617 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4619 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4620 alu
.dst
.sel
= ctx
->temp_reg
;
4624 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4629 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4630 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4631 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
4632 int mytmp
= r600_get_temp(ctx
);
4633 static const float eight
= 8.0f
;
4634 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4635 alu
.op
= ALU_OP1_MOV
;
4636 alu
.src
[0].sel
= ctx
->temp_reg
;
4637 alu
.src
[0].chan
= 3;
4638 alu
.dst
.sel
= mytmp
;
4642 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4646 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
4647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4648 alu
.op
= ALU_OP3_MULADD
;
4650 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4651 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4652 alu
.src
[1].chan
= 0;
4653 alu
.src
[1].value
= *(uint32_t *)&eight
;
4654 alu
.src
[2].sel
= mytmp
;
4655 alu
.src
[2].chan
= 0;
4656 alu
.dst
.sel
= ctx
->temp_reg
;
4660 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4663 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
4664 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4665 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
4666 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4667 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4668 tex
.src_gpr
= r600_get_temp(ctx
);
4673 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
4674 tex
.coord_type_x
= 1;
4675 tex
.coord_type_y
= 1;
4676 tex
.coord_type_z
= 1;
4677 tex
.coord_type_w
= 1;
4678 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4679 alu
.op
= ALU_OP1_MOV
;
4680 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4681 alu
.dst
.sel
= tex
.src_gpr
;
4685 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4689 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4696 /* for cube forms of lod and bias we need to route things */
4697 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
4698 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
4699 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4700 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
4701 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4702 alu
.op
= ALU_OP1_MOV
;
4703 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
4704 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
4705 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4707 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
4708 alu
.dst
.sel
= ctx
->temp_reg
;
4712 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4718 src_gpr
= ctx
->temp_reg
;
4721 if (src_requires_loading
&& !src_loaded
) {
4722 for (i
= 0; i
< 4; i
++) {
4723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4724 alu
.op
= ALU_OP1_MOV
;
4725 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4726 alu
.dst
.sel
= ctx
->temp_reg
;
4731 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4736 src_gpr
= ctx
->temp_reg
;
4739 /* Obtain the sample index for reading a compressed MSAA color texture.
4740 * To read the FMASK, we use the ldfptr instruction, which tells us
4741 * where the samples are stored.
4742 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
4743 * which is the identity mapping. Each nibble says which physical sample
4744 * should be fetched to get that sample.
4746 * Assume src.z contains the sample index. It should be modified like this:
4747 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
4748 * Then fetch the texel with src.
4750 if (read_compressed_msaa
) {
4751 unsigned sample_chan
= 3;
4752 unsigned temp
= r600_get_temp(ctx
);
4755 /* temp.w = ldfptr() */
4756 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4757 tex
.op
= FETCH_OP_LD
;
4758 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
4759 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4760 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4761 tex
.src_gpr
= src_gpr
;
4763 tex
.dst_sel_x
= 7; /* mask out these components */
4766 tex
.dst_sel_w
= 0; /* store X */
4771 tex
.offset_x
= offset_x
;
4772 tex
.offset_y
= offset_y
;
4773 tex
.offset_z
= offset_z
;
4774 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
4778 /* temp.x = sample_index*4 */
4779 if (ctx
->bc
->chip_class
== CAYMAN
) {
4780 for (i
= 0 ; i
< 4; i
++) {
4781 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4782 alu
.op
= ALU_OP2_MULLO_INT
;
4783 alu
.src
[0].sel
= src_gpr
;
4784 alu
.src
[0].chan
= sample_chan
;
4785 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4786 alu
.src
[1].value
= 4;
4789 alu
.dst
.write
= i
== 0;
4792 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4798 alu
.op
= ALU_OP2_MULLO_INT
;
4799 alu
.src
[0].sel
= src_gpr
;
4800 alu
.src
[0].chan
= sample_chan
;
4801 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4802 alu
.src
[1].value
= 4;
4807 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4812 /* sample_index = temp.w >> temp.x */
4813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4814 alu
.op
= ALU_OP2_LSHR_INT
;
4815 alu
.src
[0].sel
= temp
;
4816 alu
.src
[0].chan
= 3;
4817 alu
.src
[1].sel
= temp
;
4818 alu
.src
[1].chan
= 0;
4819 alu
.dst
.sel
= src_gpr
;
4820 alu
.dst
.chan
= sample_chan
;
4823 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4827 /* sample_index & 0xF */
4828 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4829 alu
.op
= ALU_OP2_AND_INT
;
4830 alu
.src
[0].sel
= src_gpr
;
4831 alu
.src
[0].chan
= sample_chan
;
4832 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4833 alu
.src
[1].value
= 0xF;
4834 alu
.dst
.sel
= src_gpr
;
4835 alu
.dst
.chan
= sample_chan
;
4838 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4842 /* visualize the FMASK */
4843 for (i
= 0; i
< 4; i
++) {
4844 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4845 alu
.op
= ALU_OP1_INT_TO_FLT
;
4846 alu
.src
[0].sel
= src_gpr
;
4847 alu
.src
[0].chan
= sample_chan
;
4848 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4852 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4860 /* does this shader want a num layers from TXQ for a cube array? */
4861 if (has_txq_cube_array_z
) {
4862 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4865 alu
.op
= ALU_OP1_MOV
;
4867 alu
.src
[0].sel
= 512 + (id
/ 4);
4868 alu
.src
[0].kc_bank
= R600_TXQ_CONST_BUFFER
;
4869 alu
.src
[0].chan
= id
% 4;
4870 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4872 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4875 /* disable writemask from texture instruction */
4876 inst
->Dst
[0].Register
.WriteMask
&= ~4;
4879 opcode
= ctx
->inst_info
->op
;
4880 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4881 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4882 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4883 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4884 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
4885 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4886 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4888 case FETCH_OP_SAMPLE
:
4889 opcode
= FETCH_OP_SAMPLE_C
;
4891 case FETCH_OP_SAMPLE_L
:
4892 opcode
= FETCH_OP_SAMPLE_C_L
;
4894 case FETCH_OP_SAMPLE_LB
:
4895 opcode
= FETCH_OP_SAMPLE_C_LB
;
4897 case FETCH_OP_SAMPLE_G
:
4898 opcode
= FETCH_OP_SAMPLE_C_G
;
4903 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
4906 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
4907 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
4908 tex
.src_gpr
= src_gpr
;
4909 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
4910 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
4911 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
4912 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
4913 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
4915 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
) {
4920 } else if (src_loaded
) {
4926 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
4927 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
4928 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
4929 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
4930 tex
.src_rel
= ctx
->src
[0].rel
;
4933 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
4934 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
4935 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4936 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
4940 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
4943 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
4944 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
4945 tex
.coord_type_x
= 1;
4946 tex
.coord_type_y
= 1;
4948 tex
.coord_type_z
= 1;
4949 tex
.coord_type_w
= 1;
4951 tex
.offset_x
= offset_x
;
4952 tex
.offset_y
= offset_y
;
4953 tex
.offset_z
= offset_z
;
4955 /* Put the depth for comparison in W.
4956 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
4957 * Some instructions expect the depth in Z. */
4958 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
4959 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
4960 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
4961 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
4962 opcode
!= FETCH_OP_SAMPLE_C_L
&&
4963 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
4964 tex
.src_sel_w
= tex
.src_sel_z
;
4967 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
4968 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
4969 if (opcode
== FETCH_OP_SAMPLE_C_L
||
4970 opcode
== FETCH_OP_SAMPLE_C_LB
) {
4971 /* the array index is read from Y */
4972 tex
.coord_type_y
= 0;
4974 /* the array index is read from Z */
4975 tex
.coord_type_z
= 0;
4976 tex
.src_sel_z
= tex
.src_sel_y
;
4978 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
4979 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
4980 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
4981 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
4982 (ctx
->bc
->chip_class
>= EVERGREEN
)))
4983 /* the array index is read from Z */
4984 tex
.coord_type_z
= 0;
4986 /* mask unused source components */
4987 if (opcode
== FETCH_OP_SAMPLE
) {
4988 switch (inst
->Texture
.Texture
) {
4989 case TGSI_TEXTURE_2D
:
4990 case TGSI_TEXTURE_RECT
:
4994 case TGSI_TEXTURE_1D_ARRAY
:
4998 case TGSI_TEXTURE_1D
:
5006 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
5010 /* add shadow ambient support - gallium doesn't do it yet */
5014 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
5016 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5017 struct r600_bytecode_alu alu
;
5018 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5022 /* optimize if it's just an equal balance */
5023 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
5024 for (i
= 0; i
< lasti
+ 1; i
++) {
5025 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5029 alu
.op
= ALU_OP2_ADD
;
5030 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5031 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5033 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5046 for (i
= 0; i
< lasti
+ 1; i
++) {
5047 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5050 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5051 alu
.op
= ALU_OP2_ADD
;
5052 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5053 alu
.src
[0].chan
= 0;
5054 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5055 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
5056 alu
.dst
.sel
= ctx
->temp_reg
;
5062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5067 /* (1 - src0) * src2 */
5068 for (i
= 0; i
< lasti
+ 1; i
++) {
5069 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5073 alu
.op
= ALU_OP2_MUL
;
5074 alu
.src
[0].sel
= ctx
->temp_reg
;
5075 alu
.src
[0].chan
= i
;
5076 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5077 alu
.dst
.sel
= ctx
->temp_reg
;
5083 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5088 /* src0 * src1 + (1 - src0) * src2 */
5089 for (i
= 0; i
< lasti
+ 1; i
++) {
5090 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5094 alu
.op
= ALU_OP3_MULADD
;
5096 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5097 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5098 alu
.src
[2].sel
= ctx
->temp_reg
;
5099 alu
.src
[2].chan
= i
;
5101 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5113 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
5115 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5116 struct r600_bytecode_alu alu
;
5118 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5120 for (i
= 0; i
< lasti
+ 1; i
++) {
5121 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5124 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5125 alu
.op
= ALU_OP3_CNDGE
;
5126 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5127 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5128 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
5129 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5135 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5142 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
5144 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5145 struct r600_bytecode_alu alu
;
5147 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5149 for (i
= 0; i
< lasti
+ 1; i
++) {
5150 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5153 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5154 alu
.op
= ALU_OP3_CNDGE_INT
;
5155 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5156 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5157 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
5158 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5164 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5171 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
5173 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5174 static const unsigned int src0_swizzle
[] = {2, 0, 1};
5175 static const unsigned int src1_swizzle
[] = {1, 2, 0};
5176 struct r600_bytecode_alu alu
;
5177 uint32_t use_temp
= 0;
5180 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
5183 for (i
= 0; i
< 4; i
++) {
5184 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5185 alu
.op
= ALU_OP2_MUL
;
5187 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5188 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
5190 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5191 alu
.src
[0].chan
= i
;
5192 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5193 alu
.src
[1].chan
= i
;
5196 alu
.dst
.sel
= ctx
->temp_reg
;
5202 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5207 for (i
= 0; i
< 4; i
++) {
5208 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5209 alu
.op
= ALU_OP3_MULADD
;
5212 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
5213 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
5215 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5216 alu
.src
[0].chan
= i
;
5217 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5218 alu
.src
[1].chan
= i
;
5221 alu
.src
[2].sel
= ctx
->temp_reg
;
5223 alu
.src
[2].chan
= i
;
5226 alu
.dst
.sel
= ctx
->temp_reg
;
5228 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5234 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5239 return tgsi_helper_copy(ctx
, inst
);
5243 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
5245 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5246 struct r600_bytecode_alu alu
;
5250 /* result.x = 2^floor(src); */
5251 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5254 alu
.op
= ALU_OP1_FLOOR
;
5255 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5257 alu
.dst
.sel
= ctx
->temp_reg
;
5261 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5265 if (ctx
->bc
->chip_class
== CAYMAN
) {
5266 for (i
= 0; i
< 3; i
++) {
5267 alu
.op
= ALU_OP1_EXP_IEEE
;
5268 alu
.src
[0].sel
= ctx
->temp_reg
;
5269 alu
.src
[0].chan
= 0;
5271 alu
.dst
.sel
= ctx
->temp_reg
;
5273 alu
.dst
.write
= i
== 0;
5275 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5280 alu
.op
= ALU_OP1_EXP_IEEE
;
5281 alu
.src
[0].sel
= ctx
->temp_reg
;
5282 alu
.src
[0].chan
= 0;
5284 alu
.dst
.sel
= ctx
->temp_reg
;
5288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5294 /* result.y = tmp - floor(tmp); */
5295 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5298 alu
.op
= ALU_OP1_FRACT
;
5299 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5301 alu
.dst
.sel
= ctx
->temp_reg
;
5303 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5312 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5317 /* result.z = RoughApprox2ToX(tmp);*/
5318 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
5319 if (ctx
->bc
->chip_class
== CAYMAN
) {
5320 for (i
= 0; i
< 3; i
++) {
5321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5322 alu
.op
= ALU_OP1_EXP_IEEE
;
5323 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5325 alu
.dst
.sel
= ctx
->temp_reg
;
5332 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5337 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5338 alu
.op
= ALU_OP1_EXP_IEEE
;
5339 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5341 alu
.dst
.sel
= ctx
->temp_reg
;
5347 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5353 /* result.w = 1.0;*/
5354 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
5355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5357 alu
.op
= ALU_OP1_MOV
;
5358 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5359 alu
.src
[0].chan
= 0;
5361 alu
.dst
.sel
= ctx
->temp_reg
;
5365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5369 return tgsi_helper_copy(ctx
, inst
);
5372 static int tgsi_log(struct r600_shader_ctx
*ctx
)
5374 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5375 struct r600_bytecode_alu alu
;
5379 /* result.x = floor(log2(|src|)); */
5380 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
5381 if (ctx
->bc
->chip_class
== CAYMAN
) {
5382 for (i
= 0; i
< 3; i
++) {
5383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5385 alu
.op
= ALU_OP1_LOG_IEEE
;
5386 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5387 r600_bytecode_src_set_abs(&alu
.src
[0]);
5389 alu
.dst
.sel
= ctx
->temp_reg
;
5395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5403 alu
.op
= ALU_OP1_LOG_IEEE
;
5404 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5405 r600_bytecode_src_set_abs(&alu
.src
[0]);
5407 alu
.dst
.sel
= ctx
->temp_reg
;
5411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5416 alu
.op
= ALU_OP1_FLOOR
;
5417 alu
.src
[0].sel
= ctx
->temp_reg
;
5418 alu
.src
[0].chan
= 0;
5420 alu
.dst
.sel
= ctx
->temp_reg
;
5425 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5430 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
5431 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
5433 if (ctx
->bc
->chip_class
== CAYMAN
) {
5434 for (i
= 0; i
< 3; i
++) {
5435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5437 alu
.op
= ALU_OP1_LOG_IEEE
;
5438 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5439 r600_bytecode_src_set_abs(&alu
.src
[0]);
5441 alu
.dst
.sel
= ctx
->temp_reg
;
5448 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5453 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5455 alu
.op
= ALU_OP1_LOG_IEEE
;
5456 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5457 r600_bytecode_src_set_abs(&alu
.src
[0]);
5459 alu
.dst
.sel
= ctx
->temp_reg
;
5464 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5469 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5471 alu
.op
= ALU_OP1_FLOOR
;
5472 alu
.src
[0].sel
= ctx
->temp_reg
;
5473 alu
.src
[0].chan
= 1;
5475 alu
.dst
.sel
= ctx
->temp_reg
;
5480 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5484 if (ctx
->bc
->chip_class
== CAYMAN
) {
5485 for (i
= 0; i
< 3; i
++) {
5486 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5487 alu
.op
= ALU_OP1_EXP_IEEE
;
5488 alu
.src
[0].sel
= ctx
->temp_reg
;
5489 alu
.src
[0].chan
= 1;
5491 alu
.dst
.sel
= ctx
->temp_reg
;
5498 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5503 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5504 alu
.op
= ALU_OP1_EXP_IEEE
;
5505 alu
.src
[0].sel
= ctx
->temp_reg
;
5506 alu
.src
[0].chan
= 1;
5508 alu
.dst
.sel
= ctx
->temp_reg
;
5513 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5518 if (ctx
->bc
->chip_class
== CAYMAN
) {
5519 for (i
= 0; i
< 3; i
++) {
5520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5521 alu
.op
= ALU_OP1_RECIP_IEEE
;
5522 alu
.src
[0].sel
= ctx
->temp_reg
;
5523 alu
.src
[0].chan
= 1;
5525 alu
.dst
.sel
= ctx
->temp_reg
;
5532 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5537 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5538 alu
.op
= ALU_OP1_RECIP_IEEE
;
5539 alu
.src
[0].sel
= ctx
->temp_reg
;
5540 alu
.src
[0].chan
= 1;
5542 alu
.dst
.sel
= ctx
->temp_reg
;
5547 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5552 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5554 alu
.op
= ALU_OP2_MUL
;
5556 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5557 r600_bytecode_src_set_abs(&alu
.src
[0]);
5559 alu
.src
[1].sel
= ctx
->temp_reg
;
5560 alu
.src
[1].chan
= 1;
5562 alu
.dst
.sel
= ctx
->temp_reg
;
5567 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5572 /* result.z = log2(|src|);*/
5573 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
5574 if (ctx
->bc
->chip_class
== CAYMAN
) {
5575 for (i
= 0; i
< 3; i
++) {
5576 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5578 alu
.op
= ALU_OP1_LOG_IEEE
;
5579 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5580 r600_bytecode_src_set_abs(&alu
.src
[0]);
5582 alu
.dst
.sel
= ctx
->temp_reg
;
5589 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5596 alu
.op
= ALU_OP1_LOG_IEEE
;
5597 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5598 r600_bytecode_src_set_abs(&alu
.src
[0]);
5600 alu
.dst
.sel
= ctx
->temp_reg
;
5605 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5611 /* result.w = 1.0; */
5612 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
5613 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5615 alu
.op
= ALU_OP1_MOV
;
5616 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5617 alu
.src
[0].chan
= 0;
5619 alu
.dst
.sel
= ctx
->temp_reg
;
5624 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5629 return tgsi_helper_copy(ctx
, inst
);
5632 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
5634 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5635 struct r600_bytecode_alu alu
;
5638 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5640 switch (inst
->Instruction
.Opcode
) {
5641 case TGSI_OPCODE_ARL
:
5642 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
5644 case TGSI_OPCODE_ARR
:
5645 alu
.op
= ALU_OP1_FLT_TO_INT
;
5647 case TGSI_OPCODE_UARL
:
5648 alu
.op
= ALU_OP1_MOV
;
5655 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5657 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5663 ctx
->bc
->ar_loaded
= 0;
5666 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
5668 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5669 struct r600_bytecode_alu alu
;
5672 switch (inst
->Instruction
.Opcode
) {
5673 case TGSI_OPCODE_ARL
:
5674 memset(&alu
, 0, sizeof(alu
));
5675 alu
.op
= ALU_OP1_FLOOR
;
5676 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5677 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5681 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5684 memset(&alu
, 0, sizeof(alu
));
5685 alu
.op
= ALU_OP1_FLT_TO_INT
;
5686 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
5687 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5691 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5694 case TGSI_OPCODE_ARR
:
5695 memset(&alu
, 0, sizeof(alu
));
5696 alu
.op
= ALU_OP1_FLT_TO_INT
;
5697 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5698 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5702 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5705 case TGSI_OPCODE_UARL
:
5706 memset(&alu
, 0, sizeof(alu
));
5707 alu
.op
= ALU_OP1_MOV
;
5708 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5709 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
5713 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5721 ctx
->bc
->ar_loaded
= 0;
5725 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
5727 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5728 struct r600_bytecode_alu alu
;
5731 for (i
= 0; i
< 4; i
++) {
5732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5734 alu
.op
= ALU_OP2_MUL
;
5735 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5737 if (i
== 0 || i
== 3) {
5738 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5740 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5743 if (i
== 0 || i
== 2) {
5744 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5746 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5757 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
5759 struct r600_bytecode_alu alu
;
5762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5764 alu
.execute_mask
= 1;
5765 alu
.update_pred
= 1;
5767 alu
.dst
.sel
= ctx
->temp_reg
;
5771 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5772 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5773 alu
.src
[1].chan
= 0;
5777 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
5783 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
5785 unsigned force_pop
= ctx
->bc
->force_add_cf
;
5789 if (ctx
->bc
->cf_last
) {
5790 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
5792 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
5797 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
5798 ctx
->bc
->force_add_cf
= 1;
5799 } else if (alu_pop
== 2) {
5800 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
5801 ctx
->bc
->force_add_cf
= 1;
5808 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
5809 ctx
->bc
->cf_last
->pop_count
= pops
;
5810 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
5816 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
5819 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
5820 unsigned elements
, entries
;
5822 unsigned entry_size
= stack
->entry_size
;
5824 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
5825 elements
+= stack
->push
;
5827 switch (ctx
->bc
->chip_class
) {
5830 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
5831 * the stack must be reserved to hold the current active/continue
5833 if (reason
== FC_PUSH_VPM
) {
5839 /* r9xx: any stack operation on empty stack consumes 2 additional
5844 /* FIXME: do the two elements added above cover the cases for the
5848 /* r8xx+: 2 extra elements are not always required, but one extra
5849 * element must be added for each of the following cases:
5850 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
5852 * (Currently we don't use ALU_ELSE_AFTER.)
5853 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
5854 * PUSH instruction executed.
5856 * NOTE: it seems we also need to reserve additional element in some
5857 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
5858 * then STACK_SIZE should be 2 instead of 1 */
5859 if (reason
== FC_PUSH_VPM
) {
5869 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
5870 * for all chips, so we use 4 in the final formula, not the real entry_size
5874 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
5876 if (entries
> stack
->max_entries
)
5877 stack
->max_entries
= entries
;
5880 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
5884 --ctx
->bc
->stack
.push
;
5885 assert(ctx
->bc
->stack
.push
>= 0);
5888 --ctx
->bc
->stack
.push_wqm
;
5889 assert(ctx
->bc
->stack
.push_wqm
>= 0);
5892 --ctx
->bc
->stack
.loop
;
5893 assert(ctx
->bc
->stack
.loop
>= 0);
5901 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
5905 ++ctx
->bc
->stack
.push
;
5908 ++ctx
->bc
->stack
.push_wqm
;
5910 ++ctx
->bc
->stack
.loop
;
5916 callstack_update_max_depth(ctx
, reason
);
5919 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
5921 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
5923 sp
->mid
= realloc((void *)sp
->mid
,
5924 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
5925 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
5929 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
5932 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
5933 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
5936 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
5938 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
5948 static int emit_return(struct r600_shader_ctx
*ctx
)
5950 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
5954 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
5957 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
5958 ctx
->bc
->cf_last
->pop_count
= pops
;
5959 /* XXX work out offset */
5963 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
5968 static void emit_testflag(struct r600_shader_ctx
*ctx
)
5973 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
5976 emit_jump_to_offset(ctx
, 1, 4);
5977 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
5978 pops(ctx
, ifidx
+ 1);
5982 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
5986 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
5987 ctx
->bc
->cf_last
->pop_count
= 1;
5989 fc_set_mid(ctx
, fc_sp
);
5995 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
5997 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
5999 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
6000 * LOOP_STARTxxx for nested loops may put the branch stack into a state
6001 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
6002 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
6003 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
6004 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
6005 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6006 alu_type
= CF_OP_ALU
;
6009 emit_logic_pred(ctx
, opcode
, alu_type
);
6011 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
6013 fc_pushlevel(ctx
, FC_IF
);
6015 callstack_push(ctx
, FC_PUSH_VPM
);
6019 static int tgsi_if(struct r600_shader_ctx
*ctx
)
6021 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
6024 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
6026 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
6029 static int tgsi_else(struct r600_shader_ctx
*ctx
)
6031 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
6032 ctx
->bc
->cf_last
->pop_count
= 1;
6034 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
6035 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
6039 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
6042 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
6043 R600_ERR("if/endif unbalanced in shader\n");
6047 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
6048 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6049 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
6051 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6055 callstack_pop(ctx
, FC_PUSH_VPM
);
6059 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
6061 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
6062 * limited to 4096 iterations, like the other LOOP_* instructions. */
6063 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
6065 fc_pushlevel(ctx
, FC_LOOP
);
6067 /* check stack depth */
6068 callstack_push(ctx
, FC_LOOP
);
6072 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
6076 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
6078 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
6079 R600_ERR("loop/endloop in shader code are not paired.\n");
6083 /* fixup loop pointers - from r600isa
6084 LOOP END points to CF after LOOP START,
6085 LOOP START point to CF after LOOP END
6086 BRK/CONT point to LOOP END CF
6088 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
6090 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
6092 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
6093 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
6095 /* XXX add LOOPRET support */
6097 callstack_pop(ctx
, FC_LOOP
);
6101 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
6105 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
6107 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
6112 R600_ERR("Break not inside loop/endloop pair\n");
6116 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6118 fc_set_mid(ctx
, fscp
);
6123 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
6125 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
6126 emit_gs_ring_writes(ctx
, TRUE
);
6128 return r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
6131 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
6133 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6134 struct r600_bytecode_alu alu
;
6136 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6139 for (i
= 0; i
< lasti
+ 1; i
++) {
6140 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6143 if (ctx
->bc
->chip_class
== CAYMAN
) {
6144 for (j
= 0 ; j
< 4; j
++) {
6145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6147 alu
.op
= ALU_OP2_MULLO_UINT
;
6148 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
6149 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
6151 tgsi_dst(ctx
, &inst
->Dst
[0], j
, &alu
.dst
);
6152 alu
.dst
.sel
= ctx
->temp_reg
;
6153 alu
.dst
.write
= (j
== i
);
6156 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6161 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6164 alu
.dst
.sel
= ctx
->temp_reg
;
6167 alu
.op
= ALU_OP2_MULLO_UINT
;
6168 for (j
= 0; j
< 2; j
++) {
6169 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6180 for (i
= 0; i
< lasti
+ 1; i
++) {
6181 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6184 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6185 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6187 alu
.op
= ALU_OP2_ADD_INT
;
6189 alu
.src
[0].sel
= ctx
->temp_reg
;
6190 alu
.src
[0].chan
= i
;
6192 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6196 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6203 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
6204 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6205 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6206 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6209 * For state trackers other than OpenGL, we'll want to use
6210 * _RECIP_IEEE instead.
6212 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
6214 {TGSI_OPCODE_RSQ
, 0, ALU_OP0_NOP
, tgsi_rsq
},
6215 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6216 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6217 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6218 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6219 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6220 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6221 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6222 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6223 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6224 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6225 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6226 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6227 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6228 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6229 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6231 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6232 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6234 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6235 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6236 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6237 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6238 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6239 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6240 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6241 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6242 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6243 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6245 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6246 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6247 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6248 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6249 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6250 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6251 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6252 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6253 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6254 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6255 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6256 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6257 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6258 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6259 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6260 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6261 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6262 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6263 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6264 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6265 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6266 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6267 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6268 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6269 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6270 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6271 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6272 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6273 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6274 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_r600_arl
},
6275 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6276 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6277 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6278 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6279 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6280 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6281 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6282 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6283 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6284 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6285 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6286 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6287 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6288 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6289 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6290 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6291 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6293 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6294 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6295 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6296 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6297 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6298 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6299 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6300 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6301 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
6303 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6304 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6305 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6306 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6307 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6308 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6309 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6310 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6311 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6312 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6313 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6314 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6315 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6316 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6317 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6318 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6320 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6321 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6322 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6323 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6324 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6325 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6326 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6327 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6328 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6329 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6331 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6332 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6333 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6334 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6336 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6337 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
6338 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6339 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6340 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6341 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6342 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6343 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
6344 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6345 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
6346 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6347 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6348 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6349 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6350 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6351 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6352 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6353 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6354 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6355 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6356 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
6357 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6358 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
6359 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6360 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6361 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6362 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6363 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6364 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6365 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6366 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6367 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6368 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6369 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6370 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6371 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6372 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6373 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6374 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6375 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
6376 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6377 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6378 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6379 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6380 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6381 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6382 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6383 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6384 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6385 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6386 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6387 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6388 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6389 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6390 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6391 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6392 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6393 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6394 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6395 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6396 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6397 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6398 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6401 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
6402 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6403 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6404 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6405 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
6406 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
6407 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6408 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6409 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6410 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6411 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6412 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6413 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6414 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6415 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6416 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6417 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6418 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6419 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6420 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6421 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6423 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6424 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6426 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6427 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6428 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6429 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6430 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6431 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6432 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
6433 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
6434 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, tgsi_pow
},
6435 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6437 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6438 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6439 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6440 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6441 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, tgsi_trig
},
6442 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6443 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6444 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6445 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6446 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6447 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6448 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6449 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6450 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6451 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6452 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6453 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, tgsi_trig
},
6454 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6455 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6456 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6457 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6458 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6459 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6460 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6461 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6462 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6463 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6464 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6465 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6466 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6467 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6468 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6469 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6470 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6471 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6472 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6473 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6474 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6475 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6476 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6477 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6478 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6479 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6480 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6481 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6482 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6483 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6485 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6486 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6487 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6488 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6489 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6490 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
6491 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6492 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6493 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6495 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6496 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6497 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6498 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6499 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6500 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6501 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6502 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6503 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6504 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6505 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6506 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6507 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6508 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6509 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6510 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6512 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6513 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6514 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6515 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6516 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6517 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6518 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6519 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6520 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6521 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6523 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6524 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6525 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6526 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6528 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6529 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
6530 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6531 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6532 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6533 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6534 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6535 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6536 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6537 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
6538 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
6539 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6540 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6541 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6542 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6543 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6544 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6545 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
6546 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6547 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6548 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6549 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6550 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6551 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6552 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6553 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6554 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6555 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6556 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6557 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6558 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6559 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6560 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6561 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6562 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6563 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6564 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6565 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6566 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6567 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6568 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6569 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6570 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6571 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6572 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6573 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6574 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6575 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6576 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6577 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6578 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6579 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6580 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6581 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6582 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6583 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6584 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6585 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6586 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6587 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6588 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6589 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6590 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6593 static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
6594 {TGSI_OPCODE_ARL
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6595 {TGSI_OPCODE_MOV
, 0, ALU_OP1_MOV
, tgsi_op2
},
6596 {TGSI_OPCODE_LIT
, 0, ALU_OP0_NOP
, tgsi_lit
},
6597 {TGSI_OPCODE_RCP
, 0, ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
6598 {TGSI_OPCODE_RSQ
, 0, ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
6599 {TGSI_OPCODE_EXP
, 0, ALU_OP0_NOP
, tgsi_exp
},
6600 {TGSI_OPCODE_LOG
, 0, ALU_OP0_NOP
, tgsi_log
},
6601 {TGSI_OPCODE_MUL
, 0, ALU_OP2_MUL
, tgsi_op2
},
6602 {TGSI_OPCODE_ADD
, 0, ALU_OP2_ADD
, tgsi_op2
},
6603 {TGSI_OPCODE_DP3
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6604 {TGSI_OPCODE_DP4
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6605 {TGSI_OPCODE_DST
, 0, ALU_OP0_NOP
, tgsi_opdst
},
6606 {TGSI_OPCODE_MIN
, 0, ALU_OP2_MIN
, tgsi_op2
},
6607 {TGSI_OPCODE_MAX
, 0, ALU_OP2_MAX
, tgsi_op2
},
6608 {TGSI_OPCODE_SLT
, 0, ALU_OP2_SETGT
, tgsi_op2_swap
},
6609 {TGSI_OPCODE_SGE
, 0, ALU_OP2_SETGE
, tgsi_op2
},
6610 {TGSI_OPCODE_MAD
, 1, ALU_OP3_MULADD
, tgsi_op3
},
6611 {TGSI_OPCODE_SUB
, 0, ALU_OP2_ADD
, tgsi_op2
},
6612 {TGSI_OPCODE_LRP
, 0, ALU_OP0_NOP
, tgsi_lrp
},
6613 {TGSI_OPCODE_CND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6615 {20, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6616 {TGSI_OPCODE_DP2A
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6618 {22, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6619 {23, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6620 {TGSI_OPCODE_FRC
, 0, ALU_OP1_FRACT
, tgsi_op2
},
6621 {TGSI_OPCODE_CLAMP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6622 {TGSI_OPCODE_FLR
, 0, ALU_OP1_FLOOR
, tgsi_op2
},
6623 {TGSI_OPCODE_ROUND
, 0, ALU_OP1_RNDNE
, tgsi_op2
},
6624 {TGSI_OPCODE_EX2
, 0, ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
6625 {TGSI_OPCODE_LG2
, 0, ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
6626 {TGSI_OPCODE_POW
, 0, ALU_OP0_NOP
, cayman_pow
},
6627 {TGSI_OPCODE_XPD
, 0, ALU_OP0_NOP
, tgsi_xpd
},
6629 {32, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6630 {TGSI_OPCODE_ABS
, 0, ALU_OP1_MOV
, tgsi_op2
},
6631 {TGSI_OPCODE_RCC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6632 {TGSI_OPCODE_DPH
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6633 {TGSI_OPCODE_COS
, 0, ALU_OP1_COS
, cayman_trig
},
6634 {TGSI_OPCODE_DDX
, 0, FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
6635 {TGSI_OPCODE_DDY
, 0, FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
6636 {TGSI_OPCODE_KILL
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
6637 {TGSI_OPCODE_PK2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6638 {TGSI_OPCODE_PK2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6639 {TGSI_OPCODE_PK4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6640 {TGSI_OPCODE_PK4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6641 {TGSI_OPCODE_RFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6642 {TGSI_OPCODE_SEQ
, 0, ALU_OP2_SETE
, tgsi_op2
},
6643 {TGSI_OPCODE_SFL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6644 {TGSI_OPCODE_SGT
, 0, ALU_OP2_SETGT
, tgsi_op2
},
6645 {TGSI_OPCODE_SIN
, 0, ALU_OP1_SIN
, cayman_trig
},
6646 {TGSI_OPCODE_SLE
, 0, ALU_OP2_SETGE
, tgsi_op2_swap
},
6647 {TGSI_OPCODE_SNE
, 0, ALU_OP2_SETNE
, tgsi_op2
},
6648 {TGSI_OPCODE_STR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6649 {TGSI_OPCODE_TEX
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6650 {TGSI_OPCODE_TXD
, 0, FETCH_OP_SAMPLE_G
, tgsi_tex
},
6651 {TGSI_OPCODE_TXP
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6652 {TGSI_OPCODE_UP2H
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6653 {TGSI_OPCODE_UP2US
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6654 {TGSI_OPCODE_UP4B
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6655 {TGSI_OPCODE_UP4UB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6656 {TGSI_OPCODE_X2D
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6657 {TGSI_OPCODE_ARA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6658 {TGSI_OPCODE_ARR
, 0, ALU_OP0_NOP
, tgsi_eg_arl
},
6659 {TGSI_OPCODE_BRA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6660 {TGSI_OPCODE_CAL
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6661 {TGSI_OPCODE_RET
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6662 {TGSI_OPCODE_SSG
, 0, ALU_OP0_NOP
, tgsi_ssg
},
6663 {TGSI_OPCODE_CMP
, 0, ALU_OP0_NOP
, tgsi_cmp
},
6664 {TGSI_OPCODE_SCS
, 0, ALU_OP0_NOP
, tgsi_scs
},
6665 {TGSI_OPCODE_TXB
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6666 {TGSI_OPCODE_NRM
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6667 {TGSI_OPCODE_DIV
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6668 {TGSI_OPCODE_DP2
, 0, ALU_OP2_DOT4
, tgsi_dp
},
6669 {TGSI_OPCODE_TXL
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6670 {TGSI_OPCODE_BRK
, 0, CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
6671 {TGSI_OPCODE_IF
, 0, ALU_OP0_NOP
, tgsi_if
},
6672 {TGSI_OPCODE_UIF
, 0, ALU_OP0_NOP
, tgsi_uif
},
6673 {76, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6674 {TGSI_OPCODE_ELSE
, 0, ALU_OP0_NOP
, tgsi_else
},
6675 {TGSI_OPCODE_ENDIF
, 0, ALU_OP0_NOP
, tgsi_endif
},
6677 {79, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6678 {80, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6679 {TGSI_OPCODE_PUSHA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6680 {TGSI_OPCODE_POPA
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6681 {TGSI_OPCODE_CEIL
, 0, ALU_OP1_CEIL
, tgsi_op2
},
6682 {TGSI_OPCODE_I2F
, 0, ALU_OP1_INT_TO_FLT
, tgsi_op2
},
6683 {TGSI_OPCODE_NOT
, 0, ALU_OP1_NOT_INT
, tgsi_op2
},
6684 {TGSI_OPCODE_TRUNC
, 0, ALU_OP1_TRUNC
, tgsi_op2
},
6685 {TGSI_OPCODE_SHL
, 0, ALU_OP2_LSHL_INT
, tgsi_op2
},
6687 {88, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6688 {TGSI_OPCODE_AND
, 0, ALU_OP2_AND_INT
, tgsi_op2
},
6689 {TGSI_OPCODE_OR
, 0, ALU_OP2_OR_INT
, tgsi_op2
},
6690 {TGSI_OPCODE_MOD
, 0, ALU_OP0_NOP
, tgsi_imod
},
6691 {TGSI_OPCODE_XOR
, 0, ALU_OP2_XOR_INT
, tgsi_op2
},
6692 {TGSI_OPCODE_SAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6693 {TGSI_OPCODE_TXF
, 0, FETCH_OP_LD
, tgsi_tex
},
6694 {TGSI_OPCODE_TXQ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6695 {TGSI_OPCODE_CONT
, 0, CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
6696 {TGSI_OPCODE_EMIT
, 0, CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
6697 {TGSI_OPCODE_ENDPRIM
, 0, CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
6698 {TGSI_OPCODE_BGNLOOP
, 0, ALU_OP0_NOP
, tgsi_bgnloop
},
6699 {TGSI_OPCODE_BGNSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6700 {TGSI_OPCODE_ENDLOOP
, 0, ALU_OP0_NOP
, tgsi_endloop
},
6701 {TGSI_OPCODE_ENDSUB
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6702 {TGSI_OPCODE_TXQ_LZ
, 0, FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
6704 {104, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6705 {105, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6706 {106, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6707 {TGSI_OPCODE_NOP
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6709 {TGSI_OPCODE_FSEQ
, 0, ALU_OP2_SETE_DX10
, tgsi_op2
},
6710 {TGSI_OPCODE_FSGE
, 0, ALU_OP2_SETGE_DX10
, tgsi_op2
},
6711 {TGSI_OPCODE_FSLT
, 0, ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
6712 {TGSI_OPCODE_FSNE
, 0, ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
6713 {TGSI_OPCODE_NRM4
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6714 {TGSI_OPCODE_CALLNZ
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6716 {114, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6717 {TGSI_OPCODE_BREAKC
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6718 {TGSI_OPCODE_KILL_IF
, 0, ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
6719 {TGSI_OPCODE_END
, 0, ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
6721 {118, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6722 {TGSI_OPCODE_F2I
, 0, ALU_OP1_FLT_TO_INT
, tgsi_op2
},
6723 {TGSI_OPCODE_IDIV
, 0, ALU_OP0_NOP
, tgsi_idiv
},
6724 {TGSI_OPCODE_IMAX
, 0, ALU_OP2_MAX_INT
, tgsi_op2
},
6725 {TGSI_OPCODE_IMIN
, 0, ALU_OP2_MIN_INT
, tgsi_op2
},
6726 {TGSI_OPCODE_INEG
, 0, ALU_OP2_SUB_INT
, tgsi_ineg
},
6727 {TGSI_OPCODE_ISGE
, 0, ALU_OP2_SETGE_INT
, tgsi_op2
},
6728 {TGSI_OPCODE_ISHR
, 0, ALU_OP2_ASHR_INT
, tgsi_op2
},
6729 {TGSI_OPCODE_ISLT
, 0, ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
6730 {TGSI_OPCODE_F2U
, 0, ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
6731 {TGSI_OPCODE_U2F
, 0, ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
6732 {TGSI_OPCODE_UADD
, 0, ALU_OP2_ADD_INT
, tgsi_op2
},
6733 {TGSI_OPCODE_UDIV
, 0, ALU_OP0_NOP
, tgsi_udiv
},
6734 {TGSI_OPCODE_UMAD
, 0, ALU_OP0_NOP
, tgsi_umad
},
6735 {TGSI_OPCODE_UMAX
, 0, ALU_OP2_MAX_UINT
, tgsi_op2
},
6736 {TGSI_OPCODE_UMIN
, 0, ALU_OP2_MIN_UINT
, tgsi_op2
},
6737 {TGSI_OPCODE_UMOD
, 0, ALU_OP0_NOP
, tgsi_umod
},
6738 {TGSI_OPCODE_UMUL
, 0, ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
6739 {TGSI_OPCODE_USEQ
, 0, ALU_OP2_SETE_INT
, tgsi_op2
},
6740 {TGSI_OPCODE_USGE
, 0, ALU_OP2_SETGE_UINT
, tgsi_op2
},
6741 {TGSI_OPCODE_USHR
, 0, ALU_OP2_LSHR_INT
, tgsi_op2
},
6742 {TGSI_OPCODE_USLT
, 0, ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
6743 {TGSI_OPCODE_USNE
, 0, ALU_OP2_SETNE_INT
, tgsi_op2
},
6744 {TGSI_OPCODE_SWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6745 {TGSI_OPCODE_CASE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6746 {TGSI_OPCODE_DEFAULT
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6747 {TGSI_OPCODE_ENDSWITCH
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6748 {TGSI_OPCODE_SAMPLE
, 0, 0, tgsi_unsupported
},
6749 {TGSI_OPCODE_SAMPLE_I
, 0, 0, tgsi_unsupported
},
6750 {TGSI_OPCODE_SAMPLE_I_MS
, 0, 0, tgsi_unsupported
},
6751 {TGSI_OPCODE_SAMPLE_B
, 0, 0, tgsi_unsupported
},
6752 {TGSI_OPCODE_SAMPLE_C
, 0, 0, tgsi_unsupported
},
6753 {TGSI_OPCODE_SAMPLE_C_LZ
, 0, 0, tgsi_unsupported
},
6754 {TGSI_OPCODE_SAMPLE_D
, 0, 0, tgsi_unsupported
},
6755 {TGSI_OPCODE_SAMPLE_L
, 0, 0, tgsi_unsupported
},
6756 {TGSI_OPCODE_GATHER4
, 0, 0, tgsi_unsupported
},
6757 {TGSI_OPCODE_SVIEWINFO
, 0, 0, tgsi_unsupported
},
6758 {TGSI_OPCODE_SAMPLE_POS
, 0, 0, tgsi_unsupported
},
6759 {TGSI_OPCODE_SAMPLE_INFO
, 0, 0, tgsi_unsupported
},
6760 {TGSI_OPCODE_UARL
, 0, ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
6761 {TGSI_OPCODE_UCMP
, 0, ALU_OP0_NOP
, tgsi_ucmp
},
6762 {TGSI_OPCODE_IABS
, 0, 0, tgsi_iabs
},
6763 {TGSI_OPCODE_ISSG
, 0, 0, tgsi_issg
},
6764 {TGSI_OPCODE_LOAD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6765 {TGSI_OPCODE_STORE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6766 {TGSI_OPCODE_MFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6767 {TGSI_OPCODE_LFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6768 {TGSI_OPCODE_SFENCE
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6769 {TGSI_OPCODE_BARRIER
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6770 {TGSI_OPCODE_ATOMUADD
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6771 {TGSI_OPCODE_ATOMXCHG
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6772 {TGSI_OPCODE_ATOMCAS
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6773 {TGSI_OPCODE_ATOMAND
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6774 {TGSI_OPCODE_ATOMOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6775 {TGSI_OPCODE_ATOMXOR
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6776 {TGSI_OPCODE_ATOMUMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6777 {TGSI_OPCODE_ATOMUMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6778 {TGSI_OPCODE_ATOMIMIN
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6779 {TGSI_OPCODE_ATOMIMAX
, 0, ALU_OP0_NOP
, tgsi_unsupported
},
6780 {TGSI_OPCODE_TEX2
, 0, FETCH_OP_SAMPLE
, tgsi_tex
},
6781 {TGSI_OPCODE_TXB2
, 0, FETCH_OP_SAMPLE_LB
, tgsi_tex
},
6782 {TGSI_OPCODE_TXL2
, 0, FETCH_OP_SAMPLE_L
, tgsi_tex
},
6783 {TGSI_OPCODE_LAST
, 0, ALU_OP0_NOP
, tgsi_unsupported
},