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, MUL_64
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 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
64 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
65 struct r600_pipe_shader
*pipeshader
,
66 union r600_shader_key key
);
69 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
70 int size
, unsigned comp_mask
) {
75 if (ps
->num_arrays
== ps
->max_arrays
) {
77 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
78 sizeof(struct r600_shader_array
));
81 int n
= ps
->num_arrays
;
84 ps
->arrays
[n
].comp_mask
= comp_mask
;
85 ps
->arrays
[n
].gpr_start
= start_gpr
;
86 ps
->arrays
[n
].gpr_count
= size
;
89 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
93 fprintf(stderr
, "STREAMOUT\n");
94 for (i
= 0; i
< so
->num_outputs
; i
++) {
95 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
96 so
->output
[i
].start_component
;
97 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
100 so
->output
[i
].output_buffer
,
101 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
102 so
->output
[i
].register_index
,
107 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
111 static int store_shader(struct pipe_context
*ctx
,
112 struct r600_pipe_shader
*shader
)
114 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
117 if (shader
->bo
== NULL
) {
118 shader
->bo
= (struct r600_resource
*)
119 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
120 if (shader
->bo
== NULL
) {
123 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
124 if (R600_BIG_ENDIAN
) {
125 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
126 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
129 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
131 rctx
->b
.ws
->buffer_unmap(shader
->bo
->cs_buf
);
137 int r600_pipe_shader_create(struct pipe_context
*ctx
,
138 struct r600_pipe_shader
*shader
,
139 union r600_shader_key key
)
141 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
142 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
144 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
, sel
->tokens
);
145 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
146 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
147 unsigned export_shader
;
149 shader
->shader
.bc
.isa
= rctx
->isa
;
152 fprintf(stderr
, "--------------------------------------------------------------\n");
153 tgsi_dump(sel
->tokens
, 0);
155 if (sel
->so
.num_outputs
) {
156 r600_dump_streamout(&sel
->so
);
159 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
161 R600_ERR("translation from TGSI failed !\n");
165 /* disable SB for shaders using doubles */
166 use_sb
&= !shader
->shader
.uses_doubles
;
168 /* Check if the bytecode has already been built. When using the llvm
169 * backend, r600_shader_from_tgsi() will take care of building the
172 if (!shader
->shader
.bc
.bytecode
) {
173 r
= r600_bytecode_build(&shader
->shader
.bc
);
175 R600_ERR("building bytecode failed !\n");
180 if (dump
&& !sb_disasm
) {
181 fprintf(stderr
, "--------------------------------------------------------------\n");
182 r600_bytecode_disasm(&shader
->shader
.bc
);
183 fprintf(stderr
, "______________________________________________________________\n");
184 } else if ((dump
&& sb_disasm
) || use_sb
) {
185 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
188 R600_ERR("r600_sb_bytecode_process failed !\n");
193 if (shader
->gs_copy_shader
) {
196 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
197 &shader
->gs_copy_shader
->shader
, dump
, 0);
202 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
206 /* Store the shader in a buffer. */
207 if ((r
= store_shader(ctx
, shader
)))
211 switch (shader
->shader
.processor_type
) {
212 case TGSI_PROCESSOR_GEOMETRY
:
213 if (rctx
->b
.chip_class
>= EVERGREEN
) {
214 evergreen_update_gs_state(ctx
, shader
);
215 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
217 r600_update_gs_state(ctx
, shader
);
218 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
221 case TGSI_PROCESSOR_VERTEX
:
222 export_shader
= key
.vs
.as_es
;
223 if (rctx
->b
.chip_class
>= EVERGREEN
) {
225 evergreen_update_es_state(ctx
, shader
);
227 evergreen_update_vs_state(ctx
, shader
);
230 r600_update_es_state(ctx
, shader
);
232 r600_update_vs_state(ctx
, shader
);
235 case TGSI_PROCESSOR_FRAGMENT
:
236 if (rctx
->b
.chip_class
>= EVERGREEN
) {
237 evergreen_update_ps_state(ctx
, shader
);
239 r600_update_ps_state(ctx
, shader
);
249 r600_pipe_shader_destroy(ctx
, shader
);
253 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
255 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
256 r600_bytecode_clear(&shader
->shader
.bc
);
257 r600_release_command_buffer(&shader
->command_buffer
);
261 * tgsi -> r600 shader
263 struct r600_shader_tgsi_instruction
;
265 struct r600_shader_src
{
272 boolean kc_rel
; /* true if cache bank is indexed */
281 struct r600_shader_ctx
{
282 struct tgsi_shader_info info
;
283 struct tgsi_parse_context parse
;
284 const struct tgsi_token
*tokens
;
286 unsigned file_offset
[TGSI_FILE_COUNT
];
288 const struct r600_shader_tgsi_instruction
*inst_info
;
289 struct r600_bytecode
*bc
;
290 struct r600_shader
*shader
;
291 struct r600_shader_src src
[4];
294 uint32_t max_driver_temp_used
;
296 /* needed for evergreen interpolation */
297 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
298 /* evergreen/cayman also store sample mask in face register */
300 /* sample id is .w component stored in fixed point position register */
301 int fixed_pt_position_gpr
;
303 boolean clip_vertex_write
;
305 unsigned edgeflag_output
;
308 int next_ring_offset
;
309 int gs_out_ring_offset
;
311 struct r600_shader
*gs_for_vs
;
312 int gs_export_gpr_tregs
[4];
313 const struct pipe_stream_output_info
*gs_stream_output_info
;
314 unsigned enabled_stream_buffers_mask
;
317 struct r600_shader_tgsi_instruction
{
319 int (*process
)(struct r600_shader_ctx
*ctx
);
322 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
323 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
324 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
325 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
326 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
327 static int tgsi_else(struct r600_shader_ctx
*ctx
);
328 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
329 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
330 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
331 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
332 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
333 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
334 unsigned int dst_reg
);
335 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
336 const struct r600_shader_src
*shader_src
,
339 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
341 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
344 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
345 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
348 if (i
->Instruction
.Predicate
) {
349 R600_ERR("predicate unsupported\n");
353 if (i
->Instruction
.Label
) {
354 R600_ERR("label unsupported\n");
358 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
359 if (i
->Src
[j
].Register
.Dimension
) {
360 switch (i
->Src
[j
].Register
.File
) {
361 case TGSI_FILE_CONSTANT
:
363 case TGSI_FILE_INPUT
:
364 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
)
367 R600_ERR("unsupported src %d (dimension %d)\n", j
,
368 i
->Src
[j
].Register
.Dimension
);
373 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
374 if (i
->Dst
[j
].Register
.Dimension
) {
375 R600_ERR("unsupported dst (dimension)\n");
382 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
384 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
385 interpolate
== TGSI_INTERPOLATE_LINEAR
||
386 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
388 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
392 case TGSI_INTERPOLATE_LOC_CENTER
:
395 case TGSI_INTERPOLATE_LOC_CENTROID
:
398 case TGSI_INTERPOLATE_LOC_SAMPLE
:
403 return is_linear
* 3 + loc
;
409 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
412 int i
= eg_get_interpolator_index(
413 ctx
->shader
->input
[input
].interpolate
,
414 ctx
->shader
->input
[input
].interpolate_location
);
416 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
419 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
422 struct r600_bytecode_alu alu
;
423 int gpr
= 0, base_chan
= 0;
424 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
426 /* work out gpr and base_chan from index */
428 base_chan
= (2 * (ij_index
% 2)) + 1;
430 for (i
= 0; i
< 8; i
++) {
431 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
434 alu
.op
= ALU_OP2_INTERP_ZW
;
436 alu
.op
= ALU_OP2_INTERP_XY
;
438 if ((i
> 1) && (i
< 6)) {
439 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
443 alu
.dst
.chan
= i
% 4;
445 alu
.src
[0].sel
= gpr
;
446 alu
.src
[0].chan
= (base_chan
- (i
% 2));
448 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
450 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
453 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
460 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
463 struct r600_bytecode_alu alu
;
465 for (i
= 0; i
< 4; i
++) {
466 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
468 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
470 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
475 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
480 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
488 * Special export handling in shaders
490 * shader export ARRAY_BASE for EXPORT_POS:
493 * 62, 63 are clip distance vectors
495 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
496 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
497 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
498 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
499 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
500 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
501 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
502 * exclusive from render target index)
503 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
506 * shader export ARRAY_BASE for EXPORT_PIXEL:
508 * 61 computed Z vector
510 * The use of the values exported in the computed Z vector are controlled
511 * by DB_SHADER_CONTROL:
512 * Z_EXPORT_ENABLE - Z as a float in RED
513 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
514 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
515 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
516 * DB_SOURCE_FORMAT - export control restrictions
521 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
522 static int r600_spi_sid(struct r600_shader_io
* io
)
524 int index
, name
= io
->name
;
526 /* These params are handled differently, they don't need
527 * semantic indices, so we'll use 0 for them.
529 if (name
== TGSI_SEMANTIC_POSITION
||
530 name
== TGSI_SEMANTIC_PSIZE
||
531 name
== TGSI_SEMANTIC_EDGEFLAG
||
532 name
== TGSI_SEMANTIC_FACE
||
533 name
== TGSI_SEMANTIC_SAMPLEMASK
)
536 if (name
== TGSI_SEMANTIC_GENERIC
) {
537 /* For generic params simply use sid from tgsi */
540 /* For non-generic params - pack name and sid into 8 bits */
541 index
= 0x80 | (name
<<3) | (io
->sid
);
544 /* Make sure that all really used indices have nonzero value, so
545 * we can just compare it to 0 later instead of comparing the name
546 * with different values to detect special cases. */
553 /* turn input into interpolate on EG */
554 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
558 if (ctx
->shader
->input
[index
].spi_sid
) {
559 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
560 if (ctx
->shader
->input
[index
].interpolate
> 0) {
561 evergreen_interp_assign_ij_index(ctx
, index
);
563 r
= evergreen_interp_alu(ctx
, index
);
566 r
= evergreen_interp_flat(ctx
, index
);
572 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
574 struct r600_bytecode_alu alu
;
576 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
577 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
579 for (i
= 0; i
< 4; i
++) {
580 memset(&alu
, 0, sizeof(alu
));
581 alu
.op
= ALU_OP3_CNDGT
;
584 alu
.dst
.sel
= gpr_front
;
585 alu
.src
[0].sel
= ctx
->face_gpr
;
586 alu
.src
[1].sel
= gpr_front
;
587 alu
.src
[2].sel
= gpr_back
;
594 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
601 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
603 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
606 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
609 i
= ctx
->shader
->noutput
++;
610 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
611 ctx
->shader
->output
[i
].sid
= 0;
612 ctx
->shader
->output
[i
].gpr
= 0;
613 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
614 ctx
->shader
->output
[i
].write_mask
= 0x4;
615 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
620 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
622 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
623 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
625 switch (d
->Declaration
.File
) {
626 case TGSI_FILE_INPUT
:
627 for (j
= 0; j
< count
; j
++) {
628 i
= ctx
->shader
->ninput
+ j
;
629 assert(i
< Elements(ctx
->shader
->input
));
630 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
631 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
632 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
633 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
634 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
635 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
636 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
637 switch (ctx
->shader
->input
[i
].name
) {
638 case TGSI_SEMANTIC_FACE
:
639 if (ctx
->face_gpr
!= -1)
640 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
642 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
644 case TGSI_SEMANTIC_COLOR
:
647 case TGSI_SEMANTIC_POSITION
:
648 ctx
->fragcoord_input
= i
;
650 case TGSI_SEMANTIC_PRIMID
:
651 /* set this for now */
652 ctx
->shader
->gs_prim_id_input
= true;
653 ctx
->shader
->ps_prim_id_input
= i
;
656 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
657 if ((r
= evergreen_interp_input(ctx
, i
)))
660 } else if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
661 /* FIXME probably skip inputs if they aren't passed in the ring */
662 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
663 ctx
->next_ring_offset
+= 16;
664 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
665 ctx
->shader
->gs_prim_id_input
= true;
668 ctx
->shader
->ninput
+= count
;
670 case TGSI_FILE_OUTPUT
:
671 for (j
= 0; j
< count
; j
++) {
672 i
= ctx
->shader
->noutput
+ j
;
673 assert(i
< Elements(ctx
->shader
->output
));
674 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
675 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
676 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
677 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
678 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
679 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
||
680 ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
681 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
682 switch (d
->Semantic
.Name
) {
683 case TGSI_SEMANTIC_CLIPDIST
:
684 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<<
685 ((d
->Semantic
.Index
+ j
) << 2);
687 case TGSI_SEMANTIC_PSIZE
:
688 ctx
->shader
->vs_out_misc_write
= 1;
689 ctx
->shader
->vs_out_point_size
= 1;
691 case TGSI_SEMANTIC_EDGEFLAG
:
692 ctx
->shader
->vs_out_misc_write
= 1;
693 ctx
->shader
->vs_out_edgeflag
= 1;
694 ctx
->edgeflag_output
= i
;
696 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
697 ctx
->shader
->vs_out_misc_write
= 1;
698 ctx
->shader
->vs_out_viewport
= 1;
700 case TGSI_SEMANTIC_LAYER
:
701 ctx
->shader
->vs_out_misc_write
= 1;
702 ctx
->shader
->vs_out_layer
= 1;
704 case TGSI_SEMANTIC_CLIPVERTEX
:
705 ctx
->clip_vertex_write
= TRUE
;
709 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
710 ctx
->gs_out_ring_offset
+= 16;
712 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
713 switch (d
->Semantic
.Name
) {
714 case TGSI_SEMANTIC_COLOR
:
715 ctx
->shader
->nr_ps_max_color_exports
++;
720 ctx
->shader
->noutput
+= count
;
722 case TGSI_FILE_TEMPORARY
:
723 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
724 if (d
->Array
.ArrayID
) {
725 r600_add_gpr_array(ctx
->shader
,
726 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
728 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
733 case TGSI_FILE_CONSTANT
:
734 case TGSI_FILE_SAMPLER
:
735 case TGSI_FILE_SAMPLER_VIEW
:
736 case TGSI_FILE_ADDRESS
:
739 case TGSI_FILE_SYSTEM_VALUE
:
740 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
741 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
742 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
743 break; /* Already handled from allocate_system_value_inputs */
744 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
745 if (!ctx
->native_integers
) {
746 struct r600_bytecode_alu alu
;
747 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
749 alu
.op
= ALU_OP1_INT_TO_FLT
;
758 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
762 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
764 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
767 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
773 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
775 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
778 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
780 struct tgsi_parse_context parse
;
784 unsigned name
, alternate_name
;
786 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
788 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
790 int i
, k
, num_regs
= 0;
792 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
796 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
797 while (!tgsi_parse_end_of_tokens(&parse
)) {
798 tgsi_parse_token(&parse
);
800 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
801 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
802 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
803 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
804 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
806 int interpolate
, location
, k
;
808 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
809 location
= TGSI_INTERPOLATE_LOC_CENTER
;
810 inputs
[1].enabled
= true; /* needs SAMPLEID */
811 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
812 location
= TGSI_INTERPOLATE_LOC_CENTER
;
813 /* Needs sample positions, currently those are always available */
815 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
818 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
819 k
= eg_get_interpolator_index(interpolate
, location
);
820 ctx
->eg_interpolators
[k
].enabled
= true;
822 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
823 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
824 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
825 for (k
= 0; k
< Elements(inputs
); k
++) {
826 if (d
->Semantic
.Name
== inputs
[k
].name
||
827 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
828 inputs
[k
].enabled
= true;
835 tgsi_parse_free(&parse
);
837 for (i
= 0; i
< Elements(inputs
); i
++) {
838 boolean enabled
= inputs
[i
].enabled
;
839 int *reg
= inputs
[i
].reg
;
840 unsigned name
= inputs
[i
].name
;
843 int gpr
= gpr_offset
+ num_regs
++;
845 // add to inputs, allocate a gpr
846 k
= ctx
->shader
->ninput
++;
847 ctx
->shader
->input
[k
].name
= name
;
848 ctx
->shader
->input
[k
].sid
= 0;
849 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
850 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
851 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
855 return gpr_offset
+ num_regs
;
859 * for evergreen we need to scan the shader to find the number of GPRs we need to
860 * reserve for interpolation and system values
862 * we need to know if we are going to emit
863 * any sample or centroid inputs
864 * if perspective and linear are required
866 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
870 struct tgsi_parse_context parse
;
872 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
874 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
876 /* skip position/face/mask/sampleid */
877 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
878 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
879 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
880 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
883 k
= eg_get_interpolator_index(
884 ctx
->info
.input_interpolate
[i
],
885 ctx
->info
.input_interpolate_loc
[i
]);
887 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
890 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
894 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
895 while (!tgsi_parse_end_of_tokens(&parse
)) {
896 tgsi_parse_token(&parse
);
898 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
899 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
900 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
901 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
902 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
904 int interpolate
, location
, k
;
906 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
907 location
= TGSI_INTERPOLATE_LOC_CENTER
;
908 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
909 location
= TGSI_INTERPOLATE_LOC_CENTER
;
911 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
914 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
915 k
= eg_get_interpolator_index(interpolate
, location
);
916 ctx
->eg_interpolators
[k
].enabled
= true;
921 tgsi_parse_free(&parse
);
923 /* assign gpr to each interpolator according to priority */
925 for (i
= 0; i
< Elements(ctx
->eg_interpolators
); i
++) {
926 if (ctx
->eg_interpolators
[i
].enabled
) {
927 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
932 /* XXX PULL MODEL and LINE STIPPLE */
934 num_baryc
= (num_baryc
+ 1) >> 1;
935 return allocate_system_value_inputs(ctx
, num_baryc
);
938 /* sample_id_sel == NULL means fetch for current sample */
939 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
941 struct r600_bytecode_vtx vtx
;
944 assert(ctx
->fixed_pt_position_gpr
!= -1);
946 t1
= r600_get_temp(ctx
);
948 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
949 vtx
.op
= FETCH_OP_VFETCH
;
950 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
951 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
952 if (sample_id
== NULL
) {
953 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
957 struct r600_bytecode_alu alu
;
959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
960 alu
.op
= ALU_OP1_MOV
;
961 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
965 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
972 vtx
.mega_fetch_count
= 16;
978 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
979 vtx
.num_format_all
= 2;
980 vtx
.format_comp_all
= 1;
981 vtx
.use_const_fields
= 0;
982 vtx
.offset
= 1; // first element is size of buffer
983 vtx
.endian
= r600_endian_swap(32);
984 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
986 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
993 static void tgsi_src(struct r600_shader_ctx
*ctx
,
994 const struct tgsi_full_src_register
*tgsi_src
,
995 struct r600_shader_src
*r600_src
)
997 memset(r600_src
, 0, sizeof(*r600_src
));
998 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
999 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1000 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1001 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1002 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1003 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1005 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1007 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1008 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1009 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1011 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1012 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1013 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1016 index
= tgsi_src
->Register
.Index
;
1017 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1018 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1019 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1020 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1021 r600_src
->swizzle
[0] = 2; // Z value
1022 r600_src
->swizzle
[1] = 2;
1023 r600_src
->swizzle
[2] = 2;
1024 r600_src
->swizzle
[3] = 2;
1025 r600_src
->sel
= ctx
->face_gpr
;
1026 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1027 r600_src
->swizzle
[0] = 3; // W value
1028 r600_src
->swizzle
[1] = 3;
1029 r600_src
->swizzle
[2] = 3;
1030 r600_src
->swizzle
[3] = 3;
1031 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1032 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1033 r600_src
->swizzle
[0] = 0;
1034 r600_src
->swizzle
[1] = 1;
1035 r600_src
->swizzle
[2] = 4;
1036 r600_src
->swizzle
[3] = 4;
1037 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1038 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1039 r600_src
->swizzle
[0] = 3;
1040 r600_src
->swizzle
[1] = 3;
1041 r600_src
->swizzle
[2] = 3;
1042 r600_src
->swizzle
[3] = 3;
1044 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1045 r600_src
->swizzle
[0] = 0;
1046 r600_src
->swizzle
[1] = 0;
1047 r600_src
->swizzle
[2] = 0;
1048 r600_src
->swizzle
[3] = 0;
1050 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1051 r600_src
->swizzle
[0] = 3;
1052 r600_src
->swizzle
[1] = 3;
1053 r600_src
->swizzle
[2] = 3;
1054 r600_src
->swizzle
[3] = 3;
1058 if (tgsi_src
->Register
.Indirect
)
1059 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1060 r600_src
->sel
= tgsi_src
->Register
.Index
;
1061 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1063 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1064 if (tgsi_src
->Register
.Dimension
) {
1065 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1066 if (tgsi_src
->Dimension
.Indirect
) {
1067 r600_src
->kc_rel
= 1;
1073 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1074 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1075 unsigned int dst_reg
)
1077 struct r600_bytecode_vtx vtx
;
1078 unsigned int ar_reg
;
1082 struct r600_bytecode_alu alu
;
1084 memset(&alu
, 0, sizeof(alu
));
1086 alu
.op
= ALU_OP2_ADD_INT
;
1087 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1088 alu
.src
[0].chan
= ar_chan
;
1090 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1091 alu
.src
[1].value
= offset
;
1093 alu
.dst
.sel
= dst_reg
;
1094 alu
.dst
.chan
= ar_chan
;
1098 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1103 ar_reg
= ctx
->bc
->ar_reg
;
1106 memset(&vtx
, 0, sizeof(vtx
));
1107 vtx
.buffer_id
= cb_idx
;
1108 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1109 vtx
.src_gpr
= ar_reg
;
1110 vtx
.src_sel_x
= ar_chan
;
1111 vtx
.mega_fetch_count
= 16;
1112 vtx
.dst_gpr
= dst_reg
;
1113 vtx
.dst_sel_x
= 0; /* SEL_X */
1114 vtx
.dst_sel_y
= 1; /* SEL_Y */
1115 vtx
.dst_sel_z
= 2; /* SEL_Z */
1116 vtx
.dst_sel_w
= 3; /* SEL_W */
1117 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1118 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1119 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1120 vtx
.endian
= r600_endian_swap(32);
1121 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1123 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1129 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1131 struct r600_bytecode_vtx vtx
;
1133 unsigned index
= src
->Register
.Index
;
1134 unsigned vtx_id
= src
->Dimension
.Index
;
1135 int offset_reg
= vtx_id
/ 3;
1136 int offset_chan
= vtx_id
% 3;
1138 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1139 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1141 if (offset_reg
== 0 && offset_chan
== 2)
1144 if (src
->Dimension
.Indirect
) {
1147 struct r600_bytecode_alu alu
;
1150 /* you have got to be shitting me -
1151 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1152 at least this is what fglrx seems to do. */
1153 for (i
= 0; i
< 3; i
++) {
1154 treg
[i
] = r600_get_temp(ctx
);
1156 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1158 t2
= r600_get_temp(ctx
);
1159 for (i
= 0; i
< 3; i
++) {
1160 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1161 alu
.op
= ALU_OP1_MOV
;
1163 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1164 alu
.dst
.sel
= treg
[i
];
1168 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1172 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1173 alu
.op
= ALU_OP1_MOV
;
1174 alu
.src
[0].sel
= treg
[0];
1179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1186 memset(&vtx
, 0, sizeof(vtx
));
1187 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1188 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1189 vtx
.src_gpr
= offset_reg
;
1190 vtx
.src_sel_x
= offset_chan
;
1191 vtx
.offset
= index
* 16; /*bytes*/
1192 vtx
.mega_fetch_count
= 16;
1193 vtx
.dst_gpr
= dst_reg
;
1194 vtx
.dst_sel_x
= 0; /* SEL_X */
1195 vtx
.dst_sel_y
= 1; /* SEL_Y */
1196 vtx
.dst_sel_z
= 2; /* SEL_Z */
1197 vtx
.dst_sel_w
= 3; /* SEL_W */
1198 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1199 vtx
.use_const_fields
= 1;
1201 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1204 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1210 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1212 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1215 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1216 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1218 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1219 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1220 /* primitive id is in R0.z */
1221 ctx
->src
[i
].sel
= 0;
1222 ctx
->src
[i
].swizzle
[0] = 2;
1225 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1226 int treg
= r600_get_temp(ctx
);
1228 fetch_gs_input(ctx
, src
, treg
);
1229 ctx
->src
[i
].sel
= treg
;
1235 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1237 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1238 struct r600_bytecode_alu alu
;
1239 int i
, j
, k
, nconst
, r
;
1241 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1242 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1245 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1247 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1248 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1252 if (ctx
->src
[i
].rel
) {
1253 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1254 int treg
= r600_get_temp(ctx
);
1255 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1258 ctx
->src
[i
].kc_bank
= 0;
1259 ctx
->src
[i
].kc_rel
= 0;
1260 ctx
->src
[i
].sel
= treg
;
1261 ctx
->src
[i
].rel
= 0;
1264 int treg
= r600_get_temp(ctx
);
1265 for (k
= 0; k
< 4; k
++) {
1266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1267 alu
.op
= ALU_OP1_MOV
;
1268 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1269 alu
.src
[0].chan
= k
;
1270 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1271 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1272 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1282 ctx
->src
[i
].sel
= treg
;
1290 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1291 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1293 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1294 struct r600_bytecode_alu alu
;
1295 int i
, j
, k
, nliteral
, r
;
1297 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1298 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1302 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1303 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1304 int treg
= r600_get_temp(ctx
);
1305 for (k
= 0; k
< 4; k
++) {
1306 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1307 alu
.op
= ALU_OP1_MOV
;
1308 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1309 alu
.src
[0].chan
= k
;
1310 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1320 ctx
->src
[i
].sel
= treg
;
1327 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1329 int i
, r
, count
= ctx
->shader
->ninput
;
1331 for (i
= 0; i
< count
; i
++) {
1332 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1333 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1341 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
1342 int stream
, unsigned *stream_item_size
)
1344 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1345 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
1348 /* Sanity checking. */
1349 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
1350 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
1354 for (i
= 0; i
< so
->num_outputs
; i
++) {
1355 if (so
->output
[i
].output_buffer
>= 4) {
1356 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
1357 so
->output
[i
].output_buffer
);
1363 /* Initialize locations where the outputs are stored. */
1364 for (i
= 0; i
< so
->num_outputs
; i
++) {
1366 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
1367 start_comp
[i
] = so
->output
[i
].start_component
;
1368 /* Lower outputs with dst_offset < start_component.
1370 * We can only output 4D vectors with a write mask, e.g. we can
1371 * only output the W component at offset 3, etc. If we want
1372 * to store Y, Z, or W at buffer offset 0, we need to use MOV
1373 * to move it to X and output X. */
1374 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
1375 unsigned tmp
= r600_get_temp(ctx
);
1377 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
1378 struct r600_bytecode_alu alu
;
1379 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1380 alu
.op
= ALU_OP1_MOV
;
1381 alu
.src
[0].sel
= so_gpr
[i
];
1382 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
1387 if (j
== so
->output
[i
].num_components
- 1)
1389 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1398 /* Write outputs to buffers. */
1399 for (i
= 0; i
< so
->num_outputs
; i
++) {
1400 struct r600_bytecode_output output
;
1402 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
1405 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1406 output
.gpr
= so_gpr
[i
];
1407 output
.elem_size
= so
->output
[i
].num_components
- 1;
1408 if (output
.elem_size
== 2)
1409 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
1410 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
1411 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1412 output
.burst_count
= 1;
1413 /* array_size is an upper limit for the burst_count
1414 * with MEM_STREAM instructions */
1415 output
.array_size
= 0xFFF;
1416 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
1418 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1419 switch (so
->output
[i
].output_buffer
) {
1421 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
1424 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
1427 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
1430 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
1433 output
.op
+= so
->output
[i
].stream
* 4;
1434 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
1435 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
1437 switch (so
->output
[i
].output_buffer
) {
1439 output
.op
= CF_OP_MEM_STREAM0
;
1442 output
.op
= CF_OP_MEM_STREAM1
;
1445 output
.op
= CF_OP_MEM_STREAM2
;
1448 output
.op
= CF_OP_MEM_STREAM3
;
1451 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
1453 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
1462 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
1464 struct r600_bytecode_alu alu
;
1467 if (!ctx
->shader
->vs_out_edgeflag
)
1470 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
1472 /* clamp(x, 0, 1) */
1473 memset(&alu
, 0, sizeof(alu
));
1474 alu
.op
= ALU_OP1_MOV
;
1475 alu
.src
[0].sel
= reg
;
1480 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1482 memset(&alu
, 0, sizeof(alu
));
1483 alu
.op
= ALU_OP1_FLT_TO_INT
;
1484 alu
.src
[0].sel
= reg
;
1488 r600_bytecode_add_alu(ctx
->bc
, &alu
);
1491 static int generate_gs_copy_shader(struct r600_context
*rctx
,
1492 struct r600_pipe_shader
*gs
,
1493 struct pipe_stream_output_info
*so
)
1495 struct r600_shader_ctx ctx
= {};
1496 struct r600_shader
*gs_shader
= &gs
->shader
;
1497 struct r600_pipe_shader
*cshader
;
1498 int ocnt
= gs_shader
->noutput
;
1499 struct r600_bytecode_alu alu
;
1500 struct r600_bytecode_vtx vtx
;
1501 struct r600_bytecode_output output
;
1502 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
1503 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
1504 int i
, j
, next_clip_pos
= 61, next_param
= 0;
1507 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
1511 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
1512 sizeof(struct r600_shader_io
));
1514 cshader
->shader
.noutput
= ocnt
;
1516 ctx
.shader
= &cshader
->shader
;
1517 ctx
.bc
= &ctx
.shader
->bc
;
1518 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
1520 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
1521 rctx
->screen
->has_compressed_msaa_texturing
);
1523 ctx
.bc
->isa
= rctx
->isa
;
1526 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
1528 /* R0.x = R0.x & 0x3fffffff */
1529 memset(&alu
, 0, sizeof(alu
));
1530 alu
.op
= ALU_OP2_AND_INT
;
1531 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1532 alu
.src
[1].value
= 0x3fffffff;
1534 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1536 /* R0.y = R0.x >> 30 */
1537 memset(&alu
, 0, sizeof(alu
));
1538 alu
.op
= ALU_OP2_LSHR_INT
;
1539 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1540 alu
.src
[1].value
= 0x1e;
1544 r600_bytecode_add_alu(ctx
.bc
, &alu
);
1546 /* fetch vertex data from GSVS ring */
1547 for (i
= 0; i
< ocnt
; ++i
) {
1548 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1551 out
->ring_offset
= i
* 16;
1553 memset(&vtx
, 0, sizeof(vtx
));
1554 vtx
.op
= FETCH_OP_VFETCH
;
1555 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1556 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1557 vtx
.offset
= out
->ring_offset
;
1558 vtx
.dst_gpr
= out
->gpr
;
1564 if (rctx
->b
.chip_class
>= EVERGREEN
) {
1565 vtx
.use_const_fields
= 1;
1567 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1570 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
1572 ctx
.temp_reg
= i
+ 1;
1573 for (ring
= 3; ring
>= 0; --ring
) {
1574 bool enabled
= false;
1575 for (i
= 0; i
< so
->num_outputs
; i
++) {
1576 if (so
->output
[i
].stream
== ring
) {
1581 if (ring
!= 0 && !enabled
) {
1582 cshader
->shader
.ring_item_sizes
[ring
] = 0;
1587 // Patch up jump label
1588 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1589 cf_pop
= ctx
.bc
->cf_last
;
1591 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1592 cf_jump
->pop_count
= 1;
1593 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1594 cf_pop
->pop_count
= 1;
1597 /* PRED_SETE_INT __, R0.y, ring */
1598 memset(&alu
, 0, sizeof(alu
));
1599 alu
.op
= ALU_OP2_PRED_SETE_INT
;
1600 alu
.src
[0].chan
= 1;
1601 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1602 alu
.src
[1].value
= ring
;
1603 alu
.execute_mask
= 1;
1604 alu
.update_pred
= 1;
1606 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
1608 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
1609 cf_jump
= ctx
.bc
->cf_last
;
1612 emit_streamout(&ctx
, so
, ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
1613 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
1616 /* export vertex data */
1617 /* XXX factor out common code with r600_shader_from_tgsi ? */
1618 for (i
= 0; i
< ocnt
; ++i
) {
1619 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
1620 bool instream0
= true;
1621 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
1624 for (j
= 0; j
< so
->num_outputs
; j
++) {
1625 if (so
->output
[j
].register_index
== i
) {
1626 if (so
->output
[j
].stream
== 0)
1628 if (so
->output
[j
].stream
> 0)
1634 memset(&output
, 0, sizeof(output
));
1635 output
.gpr
= out
->gpr
;
1636 output
.elem_size
= 3;
1637 output
.swizzle_x
= 0;
1638 output
.swizzle_y
= 1;
1639 output
.swizzle_z
= 2;
1640 output
.swizzle_w
= 3;
1641 output
.burst_count
= 1;
1642 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1643 output
.op
= CF_OP_EXPORT
;
1644 switch (out
->name
) {
1645 case TGSI_SEMANTIC_POSITION
:
1646 output
.array_base
= 60;
1647 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1650 case TGSI_SEMANTIC_PSIZE
:
1651 output
.array_base
= 61;
1652 if (next_clip_pos
== 61)
1654 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1655 output
.swizzle_y
= 7;
1656 output
.swizzle_z
= 7;
1657 output
.swizzle_w
= 7;
1658 ctx
.shader
->vs_out_misc_write
= 1;
1659 ctx
.shader
->vs_out_point_size
= 1;
1661 case TGSI_SEMANTIC_LAYER
:
1663 /* duplicate it as PARAM to pass to the pixel shader */
1664 output
.array_base
= next_param
++;
1665 r600_bytecode_add_output(ctx
.bc
, &output
);
1666 last_exp_param
= ctx
.bc
->cf_last
;
1668 output
.array_base
= 61;
1669 if (next_clip_pos
== 61)
1671 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1672 output
.swizzle_x
= 7;
1673 output
.swizzle_y
= 7;
1674 output
.swizzle_z
= 0;
1675 output
.swizzle_w
= 7;
1676 ctx
.shader
->vs_out_misc_write
= 1;
1677 ctx
.shader
->vs_out_layer
= 1;
1679 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
1681 /* duplicate it as PARAM to pass to the pixel shader */
1682 output
.array_base
= next_param
++;
1683 r600_bytecode_add_output(ctx
.bc
, &output
);
1684 last_exp_param
= ctx
.bc
->cf_last
;
1686 output
.array_base
= 61;
1687 if (next_clip_pos
== 61)
1689 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1690 ctx
.shader
->vs_out_misc_write
= 1;
1691 ctx
.shader
->vs_out_viewport
= 1;
1692 output
.swizzle_x
= 7;
1693 output
.swizzle_y
= 7;
1694 output
.swizzle_z
= 7;
1695 output
.swizzle_w
= 0;
1697 case TGSI_SEMANTIC_CLIPDIST
:
1698 /* spi_sid is 0 for clipdistance outputs that were generated
1699 * for clipvertex - we don't need to pass them to PS */
1700 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
1702 /* duplicate it as PARAM to pass to the pixel shader */
1703 output
.array_base
= next_param
++;
1704 r600_bytecode_add_output(ctx
.bc
, &output
);
1705 last_exp_param
= ctx
.bc
->cf_last
;
1707 output
.array_base
= next_clip_pos
++;
1708 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1710 case TGSI_SEMANTIC_FOG
:
1711 output
.swizzle_y
= 4; /* 0 */
1712 output
.swizzle_z
= 4; /* 0 */
1713 output
.swizzle_w
= 5; /* 1 */
1716 output
.array_base
= next_param
++;
1719 r600_bytecode_add_output(ctx
.bc
, &output
);
1720 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
1721 last_exp_param
= ctx
.bc
->cf_last
;
1723 last_exp_pos
= ctx
.bc
->cf_last
;
1726 if (!last_exp_pos
) {
1727 memset(&output
, 0, sizeof(output
));
1729 output
.elem_size
= 3;
1730 output
.swizzle_x
= 7;
1731 output
.swizzle_y
= 7;
1732 output
.swizzle_z
= 7;
1733 output
.swizzle_w
= 7;
1734 output
.burst_count
= 1;
1736 output
.op
= CF_OP_EXPORT
;
1737 output
.array_base
= 60;
1738 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
1739 r600_bytecode_add_output(ctx
.bc
, &output
);
1740 last_exp_pos
= ctx
.bc
->cf_last
;
1743 if (!last_exp_param
) {
1744 memset(&output
, 0, sizeof(output
));
1746 output
.elem_size
= 3;
1747 output
.swizzle_x
= 7;
1748 output
.swizzle_y
= 7;
1749 output
.swizzle_z
= 7;
1750 output
.swizzle_w
= 7;
1751 output
.burst_count
= 1;
1753 output
.op
= CF_OP_EXPORT
;
1754 output
.array_base
= next_param
++;
1755 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
1756 r600_bytecode_add_output(ctx
.bc
, &output
);
1757 last_exp_param
= ctx
.bc
->cf_last
;
1760 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
1761 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
1763 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
1764 cf_pop
= ctx
.bc
->cf_last
;
1766 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
1767 cf_jump
->pop_count
= 1;
1768 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
1769 cf_pop
->pop_count
= 1;
1771 if (ctx
.bc
->chip_class
== CAYMAN
)
1772 cm_bytecode_add_cf_end(ctx
.bc
);
1774 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
1775 ctx
.bc
->cf_last
->end_of_program
= 1;
1778 gs
->gs_copy_shader
= cshader
;
1779 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
1783 return r600_bytecode_build(ctx
.bc
);
1786 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
)
1788 struct r600_bytecode_output output
;
1789 int i
, k
, ring_offset
;
1790 int effective_stream
= stream
== -1 ? 0 : stream
;
1793 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
1794 if (ctx
->gs_for_vs
) {
1795 /* for ES we need to lookup corresponding ring offset expected by GS
1796 * (map this output to GS input by name and sid) */
1797 /* FIXME precompute offsets */
1799 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
1800 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
1801 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
1802 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
1803 ring_offset
= in
->ring_offset
;
1806 if (ring_offset
== -1)
1809 ring_offset
= idx
* 16;
1813 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
1815 /* next_ring_offset after parsing input decls contains total size of
1816 * single vertex data, gs_next_vertex - current vertex index */
1818 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
1820 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
1821 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
1822 output
.elem_size
= 3;
1823 output
.comp_mask
= 0xF;
1824 output
.burst_count
= 1;
1827 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
1829 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
1834 output
.op
= CF_OP_MEM_RING
; break;
1836 output
.op
= CF_OP_MEM_RING1
; break;
1838 output
.op
= CF_OP_MEM_RING2
; break;
1840 output
.op
= CF_OP_MEM_RING3
; break;
1844 output
.array_base
= ring_offset
>> 2; /* in dwords */
1845 output
.array_size
= 0xfff;
1846 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
1848 output
.array_base
= ring_offset
>> 2; /* in dwords */
1849 r600_bytecode_add_output(ctx
->bc
, &output
);
1853 /* get a temp and add the ring offset to the next vertex base in the shader */
1854 struct r600_bytecode_alu alu
;
1857 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1858 alu
.op
= ALU_OP2_ADD_INT
;
1859 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[effective_stream
];
1860 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1861 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
1862 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[effective_stream
];
1865 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1869 ++ctx
->gs_next_vertex
;
1873 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
1874 struct r600_pipe_shader
*pipeshader
,
1875 union r600_shader_key key
)
1877 struct r600_screen
*rscreen
= rctx
->screen
;
1878 struct r600_shader
*shader
= &pipeshader
->shader
;
1879 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
1880 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
1881 struct tgsi_full_immediate
*immediate
;
1882 struct r600_shader_ctx ctx
;
1883 struct r600_bytecode_output output
[32];
1884 unsigned output_done
, noutput
;
1887 int next_param_base
= 0, next_clip_base
;
1888 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
1889 /* Declarations used by llvm code */
1890 bool use_llvm
= false;
1892 bool ring_outputs
= false;
1893 bool pos_emitted
= false;
1895 #ifdef R600_USE_LLVM
1896 use_llvm
= rscreen
->b
.debug_flags
& DBG_LLVM
;
1898 ctx
.bc
= &shader
->bc
;
1899 ctx
.shader
= shader
;
1900 ctx
.native_integers
= true;
1903 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
1904 rscreen
->has_compressed_msaa_texturing
);
1905 ctx
.tokens
= tokens
;
1906 tgsi_scan_shader(tokens
, &ctx
.info
);
1907 shader
->indirect_files
= ctx
.info
.indirect_files
;
1909 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
1911 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
1912 tgsi_parse_init(&ctx
.parse
, tokens
);
1913 ctx
.type
= ctx
.info
.processor
;
1914 shader
->processor_type
= ctx
.type
;
1915 ctx
.bc
->type
= shader
->processor_type
;
1918 case TGSI_PROCESSOR_VERTEX
:
1919 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
1920 shader
->vs_as_es
= key
.vs
.as_es
;
1921 if (shader
->vs_as_es
)
1922 ring_outputs
= true;
1924 case TGSI_PROCESSOR_GEOMETRY
:
1925 ring_outputs
= true;
1927 case TGSI_PROCESSOR_FRAGMENT
:
1928 shader
->two_side
= key
.ps
.color_two_side
;
1934 if (shader
->vs_as_es
) {
1935 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
1937 ctx
.gs_for_vs
= NULL
;
1940 ctx
.next_ring_offset
= 0;
1941 ctx
.gs_out_ring_offset
= 0;
1942 ctx
.gs_next_vertex
= 0;
1943 ctx
.gs_stream_output_info
= &so
;
1946 ctx
.fixed_pt_position_gpr
= -1;
1947 ctx
.fragcoord_input
= -1;
1948 ctx
.colors_used
= 0;
1949 ctx
.clip_vertex_write
= 0;
1951 shader
->nr_ps_color_exports
= 0;
1952 shader
->nr_ps_max_color_exports
= 0;
1955 /* register allocations */
1956 /* Values [0,127] correspond to GPR[0..127].
1957 * Values [128,159] correspond to constant buffer bank 0
1958 * Values [160,191] correspond to constant buffer bank 1
1959 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
1960 * Values [256,287] correspond to constant buffer bank 2 (EG)
1961 * Values [288,319] correspond to constant buffer bank 3 (EG)
1962 * Other special values are shown in the list below.
1963 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
1964 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
1965 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
1966 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
1967 * 248 SQ_ALU_SRC_0: special constant 0.0.
1968 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
1969 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
1970 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
1971 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
1972 * 253 SQ_ALU_SRC_LITERAL: literal constant.
1973 * 254 SQ_ALU_SRC_PV: previous vector result.
1974 * 255 SQ_ALU_SRC_PS: previous scalar result.
1976 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
1977 ctx
.file_offset
[i
] = 0;
1980 #ifdef R600_USE_LLVM
1981 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
1982 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
1983 "indirect adressing. Falling back to TGSI "
1988 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
1989 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
1991 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
1994 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
) {
1995 if (ctx
.bc
->chip_class
>= EVERGREEN
)
1996 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
1998 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
2000 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2001 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
2002 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
2004 ctx
.use_llvm
= use_llvm
;
2007 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
2008 ctx
.file_offset
[TGSI_FILE_INPUT
];
2010 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
2011 ctx
.file_offset
[TGSI_FILE_INPUT
] +
2012 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
2014 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
2015 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
2017 /* Outside the GPR range. This will be translated to one of the
2018 * kcache banks later. */
2019 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
2021 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
2022 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
2023 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
2024 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
2025 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
2027 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2028 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
2029 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
2030 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
2031 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
2032 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
2034 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
2037 shader
->max_arrays
= 0;
2038 shader
->num_arrays
= 0;
2039 if (indirect_gprs
) {
2041 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
2042 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
2043 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
2044 ctx
.file_offset
[TGSI_FILE_INPUT
],
2047 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
2048 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
2049 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
2050 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
2056 ctx
.literals
= NULL
;
2058 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
];
2059 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
2060 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
2062 if (shader
->vs_as_gs_a
)
2063 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
2065 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
2066 tgsi_parse_token(&ctx
.parse
);
2067 switch (ctx
.parse
.FullToken
.Token
.Type
) {
2068 case TGSI_TOKEN_TYPE_IMMEDIATE
:
2069 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
2070 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
2071 if(ctx
.literals
== NULL
) {
2075 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
2076 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
2077 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
2078 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
2081 case TGSI_TOKEN_TYPE_DECLARATION
:
2082 r
= tgsi_declaration(&ctx
);
2086 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2087 case TGSI_TOKEN_TYPE_PROPERTY
:
2090 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
2096 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
2097 shader
->ring_item_sizes
[1] = 0;
2098 shader
->ring_item_sizes
[2] = 0;
2099 shader
->ring_item_sizes
[3] = 0;
2101 /* Process two side if needed */
2102 if (shader
->two_side
&& ctx
.colors_used
) {
2103 int i
, count
= ctx
.shader
->ninput
;
2104 unsigned next_lds_loc
= ctx
.shader
->nlds
;
2106 /* additional inputs will be allocated right after the existing inputs,
2107 * we won't need them after the color selection, so we don't need to
2108 * reserve these gprs for the rest of the shader code and to adjust
2109 * output offsets etc. */
2110 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
2111 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
2113 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
2114 if (ctx
.face_gpr
== -1) {
2115 i
= ctx
.shader
->ninput
++;
2116 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
2117 ctx
.shader
->input
[i
].spi_sid
= 0;
2118 ctx
.shader
->input
[i
].gpr
= gpr
++;
2119 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
2122 for (i
= 0; i
< count
; i
++) {
2123 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2124 int ni
= ctx
.shader
->ninput
++;
2125 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
2126 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
2127 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
2128 ctx
.shader
->input
[ni
].gpr
= gpr
++;
2129 // TGSI to LLVM needs to know the lds position of inputs.
2130 // Non LLVM path computes it later (in process_twoside_color)
2131 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
2132 ctx
.shader
->input
[i
].back_color_input
= ni
;
2133 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
2134 if ((r
= evergreen_interp_input(&ctx
, ni
)))
2141 /* LLVM backend setup */
2142 #ifdef R600_USE_LLVM
2144 struct radeon_llvm_context radeon_llvm_ctx
;
2146 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
2147 boolean use_kill
= false;
2149 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
2150 radeon_llvm_ctx
.type
= ctx
.type
;
2151 radeon_llvm_ctx
.two_side
= shader
->two_side
;
2152 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
2153 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
2154 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
2155 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
2156 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
2157 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
2158 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
2159 radeon_llvm_ctx
.stream_outputs
= &so
;
2160 radeon_llvm_ctx
.alpha_to_one
= key
.ps
.alpha_to_one
;
2161 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
2162 ctx
.bc
->has_compressed_msaa_texturing
;
2163 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
2164 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
2165 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
2167 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
, dump
)) {
2168 radeon_llvm_dispose(&radeon_llvm_ctx
);
2170 fprintf(stderr
, "R600 LLVM backend failed to compile "
2171 "shader. Falling back to TGSI\n");
2173 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
2174 ctx
.file_offset
[TGSI_FILE_INPUT
];
2177 ctx
.shader
->uses_kill
= use_kill
;
2178 radeon_llvm_dispose(&radeon_llvm_ctx
);
2181 /* End of LLVM backend setup */
2183 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
2184 shader
->nr_ps_max_color_exports
= 8;
2187 if (ctx
.fragcoord_input
>= 0) {
2188 if (ctx
.bc
->chip_class
== CAYMAN
) {
2189 for (j
= 0 ; j
< 4; j
++) {
2190 struct r600_bytecode_alu alu
;
2191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2192 alu
.op
= ALU_OP1_RECIP_IEEE
;
2193 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2194 alu
.src
[0].chan
= 3;
2196 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2198 alu
.dst
.write
= (j
== 3);
2200 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
2204 struct r600_bytecode_alu alu
;
2205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2206 alu
.op
= ALU_OP1_RECIP_IEEE
;
2207 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2208 alu
.src
[0].chan
= 3;
2210 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
2214 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
2219 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2220 struct r600_bytecode_alu alu
;
2223 /* GS thread with no output workaround - emit a cut at start of GS */
2224 if (ctx
.bc
->chip_class
== R600
)
2225 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
2227 for (j
= 0; j
< 4; j
++) {
2228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2229 alu
.op
= ALU_OP1_MOV
;
2230 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2231 alu
.src
[0].value
= 0;
2232 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
2235 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
2240 if (shader
->two_side
&& ctx
.colors_used
) {
2241 if ((r
= process_twoside_color_inputs(&ctx
)))
2245 tgsi_parse_init(&ctx
.parse
, tokens
);
2246 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
2247 tgsi_parse_token(&ctx
.parse
);
2248 switch (ctx
.parse
.FullToken
.Token
.Type
) {
2249 case TGSI_TOKEN_TYPE_INSTRUCTION
:
2250 r
= tgsi_is_supported(&ctx
);
2253 ctx
.max_driver_temp_used
= 0;
2254 /* reserve first tmp for everyone */
2255 r600_get_temp(&ctx
);
2257 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
2258 if ((r
= tgsi_split_constant(&ctx
)))
2260 if ((r
= tgsi_split_literal_constant(&ctx
)))
2262 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
)
2263 if ((r
= tgsi_split_gs_inputs(&ctx
)))
2265 if (ctx
.bc
->chip_class
== CAYMAN
)
2266 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
2267 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
2268 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
2270 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
2271 r
= ctx
.inst_info
->process(&ctx
);
2281 /* Reset the temporary register counter. */
2282 ctx
.max_driver_temp_used
= 0;
2284 noutput
= shader
->noutput
;
2286 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
2287 unsigned clipdist_temp
[2];
2289 clipdist_temp
[0] = r600_get_temp(&ctx
);
2290 clipdist_temp
[1] = r600_get_temp(&ctx
);
2292 /* need to convert a clipvertex write into clipdistance writes and not export
2293 the clip vertex anymore */
2295 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
2296 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
2297 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
2299 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
2300 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
2303 /* reset spi_sid for clipvertex output to avoid confusing spi */
2304 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
2306 shader
->clip_dist_write
= 0xFF;
2308 for (i
= 0; i
< 8; i
++) {
2312 for (j
= 0; j
< 4; j
++) {
2313 struct r600_bytecode_alu alu
;
2314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2315 alu
.op
= ALU_OP2_DOT4
;
2316 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
2317 alu
.src
[0].chan
= j
;
2319 alu
.src
[1].sel
= 512 + i
;
2320 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
2321 alu
.src
[1].chan
= j
;
2323 alu
.dst
.sel
= clipdist_temp
[oreg
];
2325 alu
.dst
.write
= (j
== ochan
);
2329 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
2336 /* Add stream outputs. */
2337 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
&&
2338 so
.num_outputs
&& !use_llvm
)
2339 emit_streamout(&ctx
, &so
, -1, NULL
);
2341 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2342 convert_edgeflag_to_int(&ctx
);
2345 if (shader
->vs_as_es
) {
2346 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
2347 ctx
.gs_export_gpr_tregs
[1] = -1;
2348 ctx
.gs_export_gpr_tregs
[2] = -1;
2349 ctx
.gs_export_gpr_tregs
[3] = -1;
2351 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
2355 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
2357 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
2358 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2359 output
[j
].gpr
= shader
->output
[i
].gpr
;
2360 output
[j
].elem_size
= 3;
2361 output
[j
].swizzle_x
= 0;
2362 output
[j
].swizzle_y
= 1;
2363 output
[j
].swizzle_z
= 2;
2364 output
[j
].swizzle_w
= 3;
2365 output
[j
].burst_count
= 1;
2366 output
[j
].type
= -1;
2367 output
[j
].op
= CF_OP_EXPORT
;
2369 case TGSI_PROCESSOR_VERTEX
:
2370 switch (shader
->output
[i
].name
) {
2371 case TGSI_SEMANTIC_POSITION
:
2372 output
[j
].array_base
= 60;
2373 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2377 case TGSI_SEMANTIC_PSIZE
:
2378 output
[j
].array_base
= 61;
2379 output
[j
].swizzle_y
= 7;
2380 output
[j
].swizzle_z
= 7;
2381 output
[j
].swizzle_w
= 7;
2382 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2385 case TGSI_SEMANTIC_EDGEFLAG
:
2386 output
[j
].array_base
= 61;
2387 output
[j
].swizzle_x
= 7;
2388 output
[j
].swizzle_y
= 0;
2389 output
[j
].swizzle_z
= 7;
2390 output
[j
].swizzle_w
= 7;
2391 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2394 case TGSI_SEMANTIC_LAYER
:
2395 /* spi_sid is 0 for outputs that are
2396 * not consumed by PS */
2397 if (shader
->output
[i
].spi_sid
) {
2398 output
[j
].array_base
= next_param_base
++;
2399 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2401 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2403 output
[j
].array_base
= 61;
2404 output
[j
].swizzle_x
= 7;
2405 output
[j
].swizzle_y
= 7;
2406 output
[j
].swizzle_z
= 0;
2407 output
[j
].swizzle_w
= 7;
2408 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2411 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2412 /* spi_sid is 0 for outputs that are
2413 * not consumed by PS */
2414 if (shader
->output
[i
].spi_sid
) {
2415 output
[j
].array_base
= next_param_base
++;
2416 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2418 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2420 output
[j
].array_base
= 61;
2421 output
[j
].swizzle_x
= 7;
2422 output
[j
].swizzle_y
= 7;
2423 output
[j
].swizzle_z
= 7;
2424 output
[j
].swizzle_w
= 0;
2425 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2428 case TGSI_SEMANTIC_CLIPVERTEX
:
2431 case TGSI_SEMANTIC_CLIPDIST
:
2432 output
[j
].array_base
= next_clip_base
++;
2433 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2435 /* spi_sid is 0 for clipdistance outputs that were generated
2436 * for clipvertex - we don't need to pass them to PS */
2437 if (shader
->output
[i
].spi_sid
) {
2439 /* duplicate it as PARAM to pass to the pixel shader */
2440 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
2441 output
[j
].array_base
= next_param_base
++;
2442 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2445 case TGSI_SEMANTIC_FOG
:
2446 output
[j
].swizzle_y
= 4; /* 0 */
2447 output
[j
].swizzle_z
= 4; /* 0 */
2448 output
[j
].swizzle_w
= 5; /* 1 */
2450 case TGSI_SEMANTIC_PRIMID
:
2451 output
[j
].swizzle_x
= 2;
2452 output
[j
].swizzle_y
= 4; /* 0 */
2453 output
[j
].swizzle_z
= 4; /* 0 */
2454 output
[j
].swizzle_w
= 4; /* 0 */
2459 case TGSI_PROCESSOR_FRAGMENT
:
2460 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2461 /* never export more colors than the number of CBs */
2462 if (shader
->output
[i
].sid
>= max_color_exports
) {
2467 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
2468 output
[j
].array_base
= shader
->output
[i
].sid
;
2469 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2470 shader
->nr_ps_color_exports
++;
2471 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
2472 for (k
= 1; k
< max_color_exports
; k
++) {
2474 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2475 output
[j
].gpr
= shader
->output
[i
].gpr
;
2476 output
[j
].elem_size
= 3;
2477 output
[j
].swizzle_x
= 0;
2478 output
[j
].swizzle_y
= 1;
2479 output
[j
].swizzle_z
= 2;
2480 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
2481 output
[j
].burst_count
= 1;
2482 output
[j
].array_base
= k
;
2483 output
[j
].op
= CF_OP_EXPORT
;
2484 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2485 shader
->nr_ps_color_exports
++;
2488 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
2489 output
[j
].array_base
= 61;
2490 output
[j
].swizzle_x
= 2;
2491 output
[j
].swizzle_y
= 7;
2492 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2493 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2494 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
2495 output
[j
].array_base
= 61;
2496 output
[j
].swizzle_x
= 7;
2497 output
[j
].swizzle_y
= 1;
2498 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
2499 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2500 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
2501 output
[j
].array_base
= 61;
2502 output
[j
].swizzle_x
= 7;
2503 output
[j
].swizzle_y
= 7;
2504 output
[j
].swizzle_z
= 0;
2505 output
[j
].swizzle_w
= 7;
2506 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2508 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
2514 R600_ERR("unsupported processor type %d\n", ctx
.type
);
2519 if (output
[j
].type
==-1) {
2520 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2521 output
[j
].array_base
= next_param_base
++;
2525 /* add fake position export */
2526 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& pos_emitted
== false) {
2527 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2529 output
[j
].elem_size
= 3;
2530 output
[j
].swizzle_x
= 7;
2531 output
[j
].swizzle_y
= 7;
2532 output
[j
].swizzle_z
= 7;
2533 output
[j
].swizzle_w
= 7;
2534 output
[j
].burst_count
= 1;
2535 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2536 output
[j
].array_base
= 60;
2537 output
[j
].op
= CF_OP_EXPORT
;
2541 /* add fake param output for vertex shader if no param is exported */
2542 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
&& next_param_base
== 0) {
2543 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2545 output
[j
].elem_size
= 3;
2546 output
[j
].swizzle_x
= 7;
2547 output
[j
].swizzle_y
= 7;
2548 output
[j
].swizzle_z
= 7;
2549 output
[j
].swizzle_w
= 7;
2550 output
[j
].burst_count
= 1;
2551 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2552 output
[j
].array_base
= 0;
2553 output
[j
].op
= CF_OP_EXPORT
;
2557 /* add fake pixel export */
2558 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
2559 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
2561 output
[j
].elem_size
= 3;
2562 output
[j
].swizzle_x
= 7;
2563 output
[j
].swizzle_y
= 7;
2564 output
[j
].swizzle_z
= 7;
2565 output
[j
].swizzle_w
= 7;
2566 output
[j
].burst_count
= 1;
2567 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
2568 output
[j
].array_base
= 0;
2569 output
[j
].op
= CF_OP_EXPORT
;
2571 shader
->nr_ps_color_exports
++;
2576 /* set export done on last export of each type */
2577 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
2578 if (!(output_done
& (1 << output
[i
].type
))) {
2579 output_done
|= (1 << output
[i
].type
);
2580 output
[i
].op
= CF_OP_EXPORT_DONE
;
2583 /* add output to bytecode */
2585 for (i
= 0; i
< noutput
; i
++) {
2586 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
2593 /* add program end */
2595 if (ctx
.bc
->chip_class
== CAYMAN
)
2596 cm_bytecode_add_cf_end(ctx
.bc
);
2598 const struct cf_op_info
*last
= NULL
;
2600 if (ctx
.bc
->cf_last
)
2601 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
2603 /* alu clause instructions don't have EOP bit, so add NOP */
2604 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
)
2605 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2607 ctx
.bc
->cf_last
->end_of_program
= 1;
2611 /* check GPR limit - we have 124 = 128 - 4
2612 * (4 are reserved as alu clause temporary registers) */
2613 if (ctx
.bc
->ngpr
> 124) {
2614 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
2619 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
2620 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
2625 tgsi_parse_free(&ctx
.parse
);
2629 tgsi_parse_free(&ctx
.parse
);
2633 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
2635 const unsigned tgsi_opcode
=
2636 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
2637 R600_ERR("%s tgsi opcode unsupported\n",
2638 tgsi_get_opcode_name(tgsi_opcode
));
2642 static int tgsi_end(struct r600_shader_ctx
*ctx
)
2647 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
2648 const struct r600_shader_src
*shader_src
,
2651 bc_src
->sel
= shader_src
->sel
;
2652 bc_src
->chan
= shader_src
->swizzle
[chan
];
2653 bc_src
->neg
= shader_src
->neg
;
2654 bc_src
->abs
= shader_src
->abs
;
2655 bc_src
->rel
= shader_src
->rel
;
2656 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
2657 bc_src
->kc_bank
= shader_src
->kc_bank
;
2658 bc_src
->kc_rel
= shader_src
->kc_rel
;
2661 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
2667 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
2669 bc_src
->neg
= !bc_src
->neg
;
2672 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
2673 const struct tgsi_full_dst_register
*tgsi_dst
,
2675 struct r600_bytecode_alu_dst
*r600_dst
)
2677 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2679 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
2680 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
2681 r600_dst
->chan
= swizzle
;
2682 r600_dst
->write
= 1;
2683 if (tgsi_dst
->Register
.Indirect
)
2684 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
2685 if (inst
->Instruction
.Saturate
) {
2686 r600_dst
->clamp
= 1;
2690 static int tgsi_last_instruction(unsigned writemask
)
2694 for (i
= 0; i
< 4; i
++) {
2695 if (writemask
& (1 << i
)) {
2704 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
)
2706 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2707 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2708 struct r600_bytecode_alu alu
;
2709 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2713 switch (write_mask
) {
2731 lasti
= tgsi_last_instruction(write_mask
);
2732 for (i
= 0; i
<= lasti
; i
++) {
2734 if (!(write_mask
& (1 << i
)))
2737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2740 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2742 alu
.dst
.sel
= ctx
->temp_reg
;
2746 if (i
== 1 || i
== 3)
2749 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2751 alu
.op
= ctx
->inst_info
->op
;
2752 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
2753 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2755 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2756 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
2759 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
2760 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
2763 /* handle some special cases */
2764 if (i
== 1 || i
== 3) {
2765 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
2766 case TGSI_OPCODE_SUB
:
2767 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2769 case TGSI_OPCODE_DABS
:
2770 r600_bytecode_src_set_abs(&alu
.src
[0]);
2779 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2785 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2787 /* move result from temp to dst */
2788 for (i
= 0; i
<= lasti
; i
++) {
2789 if (!(write_mask
& (1 << i
)))
2792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2793 alu
.op
= ALU_OP1_MOV
;
2794 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2795 alu
.src
[0].sel
= ctx
->temp_reg
;
2796 alu
.src
[0].chan
= use_tmp
- 1;
2797 alu
.last
= (i
== lasti
);
2799 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2807 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
2809 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2810 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2811 /* confirm writemasking */
2812 if ((write_mask
& 0x3) != 0x3 &&
2813 (write_mask
& 0xc) != 0xc) {
2814 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
2817 return tgsi_op2_64_params(ctx
, false, false);
2820 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
2822 return tgsi_op2_64_params(ctx
, true, false);
2825 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
2827 return tgsi_op2_64_params(ctx
, true, true);
2830 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
2832 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2833 struct r600_bytecode_alu alu
;
2836 int tmp
= r600_get_temp(ctx
);
2838 for (i
= 0; i
< lasti
+ 1; i
++) {
2840 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2841 alu
.op
= ctx
->inst_info
->op
;
2842 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2843 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
2846 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
2847 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2856 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2863 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
2865 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2866 struct r600_bytecode_alu alu
;
2867 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
2868 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
2869 /* use temp register if trans_only and more than one dst component */
2870 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
2872 for (i
= 0; i
<= lasti
; i
++) {
2873 if (!(write_mask
& (1 << i
)))
2876 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2878 alu
.dst
.sel
= ctx
->temp_reg
;
2882 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2884 alu
.op
= ctx
->inst_info
->op
;
2886 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
2887 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
2890 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
2891 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2893 /* handle some special cases */
2894 switch (inst
->Instruction
.Opcode
) {
2895 case TGSI_OPCODE_SUB
:
2896 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
2898 case TGSI_OPCODE_ABS
:
2899 r600_bytecode_src_set_abs(&alu
.src
[0]);
2904 if (i
== lasti
|| trans_only
) {
2907 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2913 /* move result from temp to dst */
2914 for (i
= 0; i
<= lasti
; i
++) {
2915 if (!(write_mask
& (1 << i
)))
2918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2919 alu
.op
= ALU_OP1_MOV
;
2920 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2921 alu
.src
[0].sel
= ctx
->temp_reg
;
2922 alu
.src
[0].chan
= i
;
2923 alu
.last
= (i
== lasti
);
2925 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2933 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
2935 return tgsi_op2_s(ctx
, 0, 0);
2938 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
2940 return tgsi_op2_s(ctx
, 1, 0);
2943 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
2945 return tgsi_op2_s(ctx
, 0, 1);
2948 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
2950 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2951 struct r600_bytecode_alu alu
;
2953 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2955 for (i
= 0; i
< lasti
+ 1; i
++) {
2957 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2959 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2960 alu
.op
= ctx
->inst_info
->op
;
2962 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
2964 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
2966 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
2971 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2979 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
2981 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2982 struct r600_bytecode_alu alu
;
2984 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
2986 for (i
= 0; i
< lasti
+ 1; i
++) {
2988 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
2990 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2991 alu
.op
= ALU_OP1_MOV
;
2993 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
2995 if (i
== 1 || i
== 3)
2996 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
2997 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3002 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3010 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
3012 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3013 struct r600_bytecode_alu alu
;
3014 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3016 int firsti
= write_mask
== 0xc ? 2 : 0;
3018 for (i
= 0; i
<= 3; i
++) {
3019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3020 alu
.op
= ctx
->inst_info
->op
;
3022 alu
.dst
.sel
= ctx
->temp_reg
;
3025 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3026 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
3032 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3037 /* MOV first two channels to writemask dst0 */
3038 for (i
= 0; i
<= 1; i
++) {
3039 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3040 alu
.op
= ALU_OP1_MOV
;
3041 alu
.src
[0].chan
= i
+ 2;
3042 alu
.src
[0].sel
= ctx
->temp_reg
;
3044 tgsi_dst(ctx
, &inst
->Dst
[0], firsti
+ i
, &alu
.dst
);
3045 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> (firsti
+ i
)) & 1;
3047 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3052 for (i
= 0; i
<= 3; i
++) {
3053 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
3054 /* MOV third channels to writemask dst1 */
3055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3056 alu
.op
= ALU_OP1_MOV
;
3057 alu
.src
[0].chan
= 1;
3058 alu
.src
[0].sel
= ctx
->temp_reg
;
3060 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
3062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3072 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
3074 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3075 struct r600_bytecode_alu alu
;
3077 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3079 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
3080 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
3082 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
3083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3084 alu
.op
= ctx
->inst_info
->op
;
3086 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3087 alu
.dst
.sel
= ctx
->temp_reg
;
3092 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3097 for (i
= 0; i
<= lasti
; i
++) {
3098 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3099 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
3101 alu
.src
[0].chan
= i
/2;
3103 alu
.src
[0].sel
= ctx
->temp_reg
;
3105 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3106 alu
.src
[0].value
= 0x0;
3108 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3109 alu
.last
= i
== lasti
;
3111 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3119 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
3121 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3122 struct r600_bytecode_alu alu
;
3124 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3126 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
3127 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
3129 for (i
= 0; i
<= lasti
; i
++) {
3130 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3131 alu
.op
= ALU_OP1_FLT64_TO_FLT32
;
3133 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], fp64_switch(i
));
3135 alu
.dst
.sel
= ctx
->temp_reg
;
3136 alu
.dst
.write
= i
%2 == 0;
3137 alu
.last
= i
== lasti
;
3139 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3144 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
3145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3146 alu
.op
= ctx
->inst_info
->op
;
3148 alu
.src
[0].chan
= i
*2;
3149 alu
.src
[0].sel
= ctx
->temp_reg
;
3150 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3153 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3161 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
3163 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3165 struct r600_bytecode_alu alu
;
3167 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3168 int t1
= ctx
->temp_reg
;
3170 /* these have to write the result to X/Y by the looks of it */
3171 for (i
= 0 ; i
< last_slot
; i
++) {
3172 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3173 alu
.op
= ctx
->inst_info
->op
;
3175 /* should only be one src regs */
3176 assert (inst
->Instruction
.NumSrcRegs
== 1);
3178 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
3179 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 0);
3181 /* RSQ should take the absolute value of src */
3182 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
3183 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
) {
3184 r600_bytecode_src_set_abs(&alu
.src
[1]);
3188 alu
.dst
.write
= (i
== 0 || i
== 1);
3190 if (ctx
->bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
3192 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3197 for (i
= 0 ; i
<= lasti
; i
++) {
3198 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3201 alu
.op
= ALU_OP1_MOV
;
3202 alu
.src
[0].sel
= t1
;
3203 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
3204 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3208 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3215 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
3217 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3219 struct r600_bytecode_alu alu
;
3220 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
3222 for (i
= 0 ; i
< last_slot
; i
++) {
3223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3224 alu
.op
= ctx
->inst_info
->op
;
3225 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3226 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
3228 /* RSQ should take the absolute value of src */
3229 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
3230 r600_bytecode_src_set_abs(&alu
.src
[j
]);
3233 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3234 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3236 if (i
== last_slot
- 1)
3238 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3245 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
3247 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3249 struct r600_bytecode_alu alu
;
3250 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3251 int t1
= ctx
->temp_reg
;
3253 for (k
= 0; k
<= lasti
; k
++) {
3254 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
3257 for (i
= 0 ; i
< 4; i
++) {
3258 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3259 alu
.op
= ctx
->inst_info
->op
;
3260 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3261 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
3265 alu
.dst
.write
= (i
== k
);
3268 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3274 for (i
= 0 ; i
<= lasti
; i
++) {
3275 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3278 alu
.op
= ALU_OP1_MOV
;
3279 alu
.src
[0].sel
= t1
;
3280 alu
.src
[0].chan
= i
;
3281 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3285 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3294 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
3296 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3298 struct r600_bytecode_alu alu
;
3299 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3300 int t1
= ctx
->temp_reg
;
3302 for (k
= 0; k
< 2; k
++) {
3303 if (!(inst
->Dst
[0].Register
.WriteMask
& (0x3 << (k
* 2))))
3306 for (i
= 0; i
< 4; i
++) {
3307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3308 alu
.op
= ctx
->inst_info
->op
;
3309 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3310 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));;
3317 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3323 for (i
= 0; i
<= lasti
; i
++) {
3324 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3326 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3327 alu
.op
= ALU_OP1_MOV
;
3328 alu
.src
[0].sel
= t1
;
3329 alu
.src
[0].chan
= i
;
3330 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3334 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3343 * r600 - trunc to -PI..PI range
3344 * r700 - normalize by dividing by 2PI
3347 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
3349 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
3350 static float double_pi
= 3.1415926535 * 2;
3351 static float neg_pi
= -3.1415926535;
3354 struct r600_bytecode_alu alu
;
3356 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3357 alu
.op
= ALU_OP3_MULADD
;
3361 alu
.dst
.sel
= ctx
->temp_reg
;
3364 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3366 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3367 alu
.src
[1].chan
= 0;
3368 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
3369 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
3370 alu
.src
[2].chan
= 0;
3372 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3377 alu
.op
= ALU_OP1_FRACT
;
3380 alu
.dst
.sel
= ctx
->temp_reg
;
3383 alu
.src
[0].sel
= ctx
->temp_reg
;
3384 alu
.src
[0].chan
= 0;
3386 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3391 alu
.op
= ALU_OP3_MULADD
;
3395 alu
.dst
.sel
= ctx
->temp_reg
;
3398 alu
.src
[0].sel
= ctx
->temp_reg
;
3399 alu
.src
[0].chan
= 0;
3401 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3402 alu
.src
[1].chan
= 0;
3403 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
3404 alu
.src
[2].chan
= 0;
3406 if (ctx
->bc
->chip_class
== R600
) {
3407 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
3408 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
3410 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3411 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
3416 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3422 static int cayman_trig(struct r600_shader_ctx
*ctx
)
3424 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3425 struct r600_bytecode_alu alu
;
3426 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
3429 r
= tgsi_setup_trig(ctx
);
3434 for (i
= 0; i
< last_slot
; i
++) {
3435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3436 alu
.op
= ctx
->inst_info
->op
;
3439 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3440 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3442 alu
.src
[0].sel
= ctx
->temp_reg
;
3443 alu
.src
[0].chan
= 0;
3444 if (i
== last_slot
- 1)
3446 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3453 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
3455 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3456 struct r600_bytecode_alu alu
;
3458 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
3460 r
= tgsi_setup_trig(ctx
);
3464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3465 alu
.op
= ctx
->inst_info
->op
;
3467 alu
.dst
.sel
= ctx
->temp_reg
;
3470 alu
.src
[0].sel
= ctx
->temp_reg
;
3471 alu
.src
[0].chan
= 0;
3473 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3477 /* replicate result */
3478 for (i
= 0; i
< lasti
+ 1; i
++) {
3479 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
3482 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3483 alu
.op
= ALU_OP1_MOV
;
3485 alu
.src
[0].sel
= ctx
->temp_reg
;
3486 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3489 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3496 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
3498 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3499 struct r600_bytecode_alu alu
;
3502 /* We'll only need the trig stuff if we are going to write to the
3503 * X or Y components of the destination vector.
3505 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
3506 r
= tgsi_setup_trig(ctx
);
3512 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
3513 if (ctx
->bc
->chip_class
== CAYMAN
) {
3514 for (i
= 0 ; i
< 3; i
++) {
3515 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3516 alu
.op
= ALU_OP1_COS
;
3517 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3523 alu
.src
[0].sel
= ctx
->temp_reg
;
3524 alu
.src
[0].chan
= 0;
3527 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3533 alu
.op
= ALU_OP1_COS
;
3534 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3536 alu
.src
[0].sel
= ctx
->temp_reg
;
3537 alu
.src
[0].chan
= 0;
3539 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3546 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
3547 if (ctx
->bc
->chip_class
== CAYMAN
) {
3548 for (i
= 0 ; i
< 3; i
++) {
3549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3550 alu
.op
= ALU_OP1_SIN
;
3551 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3556 alu
.src
[0].sel
= ctx
->temp_reg
;
3557 alu
.src
[0].chan
= 0;
3560 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3565 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3566 alu
.op
= ALU_OP1_SIN
;
3567 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
3569 alu
.src
[0].sel
= ctx
->temp_reg
;
3570 alu
.src
[0].chan
= 0;
3572 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3579 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
3580 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3582 alu
.op
= ALU_OP1_MOV
;
3584 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
3586 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3587 alu
.src
[0].chan
= 0;
3591 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3597 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
3598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3600 alu
.op
= ALU_OP1_MOV
;
3602 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
3604 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3605 alu
.src
[0].chan
= 0;
3609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3617 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
3619 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3620 struct r600_bytecode_alu alu
;
3623 for (i
= 0; i
< 4; i
++) {
3624 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3625 alu
.op
= ctx
->inst_info
->op
;
3629 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
3631 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
3632 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
3635 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
3640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3645 /* kill must be last in ALU */
3646 ctx
->bc
->force_add_cf
= 1;
3647 ctx
->shader
->uses_kill
= TRUE
;
3651 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
3653 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3654 struct r600_bytecode_alu alu
;
3657 /* tmp.x = max(src.y, 0.0) */
3658 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3659 alu
.op
= ALU_OP2_MAX
;
3660 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
3661 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
3662 alu
.src
[1].chan
= 1;
3664 alu
.dst
.sel
= ctx
->temp_reg
;
3669 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3673 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
3679 if (ctx
->bc
->chip_class
== CAYMAN
) {
3680 for (i
= 0; i
< 3; i
++) {
3681 /* tmp.z = log(tmp.x) */
3682 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3683 alu
.op
= ALU_OP1_LOG_CLAMPED
;
3684 alu
.src
[0].sel
= ctx
->temp_reg
;
3685 alu
.src
[0].chan
= 0;
3686 alu
.dst
.sel
= ctx
->temp_reg
;
3694 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3699 /* tmp.z = log(tmp.x) */
3700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3701 alu
.op
= ALU_OP1_LOG_CLAMPED
;
3702 alu
.src
[0].sel
= ctx
->temp_reg
;
3703 alu
.src
[0].chan
= 0;
3704 alu
.dst
.sel
= ctx
->temp_reg
;
3708 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3713 chan
= alu
.dst
.chan
;
3716 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
3717 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3718 alu
.op
= ALU_OP3_MUL_LIT
;
3719 alu
.src
[0].sel
= sel
;
3720 alu
.src
[0].chan
= chan
;
3721 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
3722 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
3723 alu
.dst
.sel
= ctx
->temp_reg
;
3728 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3732 if (ctx
->bc
->chip_class
== CAYMAN
) {
3733 for (i
= 0; i
< 3; i
++) {
3734 /* dst.z = exp(tmp.x) */
3735 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3736 alu
.op
= ALU_OP1_EXP_IEEE
;
3737 alu
.src
[0].sel
= ctx
->temp_reg
;
3738 alu
.src
[0].chan
= 0;
3739 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3745 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3750 /* dst.z = exp(tmp.x) */
3751 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3752 alu
.op
= ALU_OP1_EXP_IEEE
;
3753 alu
.src
[0].sel
= ctx
->temp_reg
;
3754 alu
.src
[0].chan
= 0;
3755 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
3757 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3764 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3765 alu
.op
= ALU_OP1_MOV
;
3766 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
3767 alu
.src
[0].chan
= 0;
3768 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
3769 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
3770 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3774 /* dst.y = max(src.x, 0.0) */
3775 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3776 alu
.op
= ALU_OP2_MAX
;
3777 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3778 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
3779 alu
.src
[1].chan
= 0;
3780 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
3781 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
3782 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3787 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3788 alu
.op
= ALU_OP1_MOV
;
3789 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
3790 alu
.src
[0].chan
= 0;
3791 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
3792 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
3794 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3801 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
3803 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3804 struct r600_bytecode_alu alu
;
3807 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3810 * For state trackers other than OpenGL, we'll want to use
3811 * _RECIPSQRT_IEEE instead.
3813 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
3815 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
3816 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
3817 r600_bytecode_src_set_abs(&alu
.src
[i
]);
3819 alu
.dst
.sel
= ctx
->temp_reg
;
3822 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3825 /* replicate result */
3826 return tgsi_helper_tempx_replicate(ctx
);
3829 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
3831 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3832 struct r600_bytecode_alu alu
;
3835 for (i
= 0; i
< 4; i
++) {
3836 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3837 alu
.src
[0].sel
= ctx
->temp_reg
;
3838 alu
.op
= ALU_OP1_MOV
;
3840 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3841 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3844 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3851 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
3853 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3854 struct r600_bytecode_alu alu
;
3857 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3858 alu
.op
= ctx
->inst_info
->op
;
3859 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
3860 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
3862 alu
.dst
.sel
= ctx
->temp_reg
;
3865 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3868 /* replicate result */
3869 return tgsi_helper_tempx_replicate(ctx
);
3872 static int cayman_pow(struct r600_shader_ctx
*ctx
)
3874 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3876 struct r600_bytecode_alu alu
;
3877 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
3879 for (i
= 0; i
< 3; i
++) {
3880 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3881 alu
.op
= ALU_OP1_LOG_IEEE
;
3882 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3883 alu
.dst
.sel
= ctx
->temp_reg
;
3888 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3894 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3895 alu
.op
= ALU_OP2_MUL
;
3896 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
3897 alu
.src
[1].sel
= ctx
->temp_reg
;
3898 alu
.dst
.sel
= ctx
->temp_reg
;
3901 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3905 for (i
= 0; i
< last_slot
; i
++) {
3906 /* POW(a,b) = EXP2(b * LOG2(a))*/
3907 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3908 alu
.op
= ALU_OP1_EXP_IEEE
;
3909 alu
.src
[0].sel
= ctx
->temp_reg
;
3911 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3912 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
3913 if (i
== last_slot
- 1)
3915 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3922 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
3924 struct r600_bytecode_alu alu
;
3928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3929 alu
.op
= ALU_OP1_LOG_IEEE
;
3930 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
3931 alu
.dst
.sel
= ctx
->temp_reg
;
3934 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3938 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3939 alu
.op
= ALU_OP2_MUL
;
3940 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
3941 alu
.src
[1].sel
= ctx
->temp_reg
;
3942 alu
.dst
.sel
= ctx
->temp_reg
;
3945 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3948 /* POW(a,b) = EXP2(b * LOG2(a))*/
3949 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3950 alu
.op
= ALU_OP1_EXP_IEEE
;
3951 alu
.src
[0].sel
= ctx
->temp_reg
;
3952 alu
.dst
.sel
= ctx
->temp_reg
;
3955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3958 return tgsi_helper_tempx_replicate(ctx
);
3961 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
3963 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3964 struct r600_bytecode_alu alu
;
3966 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3967 int tmp0
= ctx
->temp_reg
;
3968 int tmp1
= r600_get_temp(ctx
);
3969 int tmp2
= r600_get_temp(ctx
);
3970 int tmp3
= r600_get_temp(ctx
);
3973 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
3975 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
3976 * 2. tmp0.z = lo (tmp0.x * src2)
3977 * 3. tmp0.w = -tmp0.z
3978 * 4. tmp0.y = hi (tmp0.x * src2)
3979 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
3980 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
3981 * 7. tmp1.x = tmp0.x - tmp0.w
3982 * 8. tmp1.y = tmp0.x + tmp0.w
3983 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
3984 * 10. tmp0.z = hi(tmp0.x * src1) = q
3985 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
3987 * 12. tmp0.w = src1 - tmp0.y = r
3988 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
3989 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
3993 * 15. tmp1.z = tmp0.z + 1 = q + 1
3994 * 16. tmp1.w = tmp0.z - 1 = q - 1
3998 * 15. tmp1.z = tmp0.w - src2 = r - src2
3999 * 16. tmp1.w = tmp0.w + src2 = r + src2
4003 * 17. tmp1.x = tmp1.x & tmp1.y
4005 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
4006 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
4008 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
4009 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
4013 * Same as unsigned, using abs values of the operands,
4014 * and fixing the sign of the result in the end.
4017 for (i
= 0; i
< 4; i
++) {
4018 if (!(write_mask
& (1<<i
)))
4023 /* tmp2.x = -src0 */
4024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4025 alu
.op
= ALU_OP2_SUB_INT
;
4031 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4033 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4036 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4039 /* tmp2.y = -src1 */
4040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4041 alu
.op
= ALU_OP2_SUB_INT
;
4047 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4049 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4052 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4055 /* tmp2.z sign bit is set if src0 and src2 signs are different */
4056 /* it will be a sign of the quotient */
4059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4060 alu
.op
= ALU_OP2_XOR_INT
;
4066 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4067 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4070 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4074 /* tmp2.x = |src0| */
4075 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4076 alu
.op
= ALU_OP3_CNDGE_INT
;
4083 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4084 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4085 alu
.src
[2].sel
= tmp2
;
4086 alu
.src
[2].chan
= 0;
4089 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4092 /* tmp2.y = |src1| */
4093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4094 alu
.op
= ALU_OP3_CNDGE_INT
;
4101 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4102 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4103 alu
.src
[2].sel
= tmp2
;
4104 alu
.src
[2].chan
= 1;
4107 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4112 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
4113 if (ctx
->bc
->chip_class
== CAYMAN
) {
4114 /* tmp3.x = u2f(src2) */
4115 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4116 alu
.op
= ALU_OP1_UINT_TO_FLT
;
4123 alu
.src
[0].sel
= tmp2
;
4124 alu
.src
[0].chan
= 1;
4126 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4130 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4133 /* tmp0.x = recip(tmp3.x) */
4134 for (j
= 0 ; j
< 3; j
++) {
4135 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4136 alu
.op
= ALU_OP1_RECIP_IEEE
;
4140 alu
.dst
.write
= (j
== 0);
4142 alu
.src
[0].sel
= tmp3
;
4143 alu
.src
[0].chan
= 0;
4147 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4151 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4152 alu
.op
= ALU_OP2_MUL
;
4154 alu
.src
[0].sel
= tmp0
;
4155 alu
.src
[0].chan
= 0;
4157 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4158 alu
.src
[1].value
= 0x4f800000;
4163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4168 alu
.op
= ALU_OP1_FLT_TO_UINT
;
4174 alu
.src
[0].sel
= tmp3
;
4175 alu
.src
[0].chan
= 0;
4178 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4182 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4183 alu
.op
= ALU_OP1_RECIP_UINT
;
4190 alu
.src
[0].sel
= tmp2
;
4191 alu
.src
[0].chan
= 1;
4193 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4197 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4201 /* 2. tmp0.z = lo (tmp0.x * src2) */
4202 if (ctx
->bc
->chip_class
== CAYMAN
) {
4203 for (j
= 0 ; j
< 4; j
++) {
4204 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4205 alu
.op
= ALU_OP2_MULLO_UINT
;
4209 alu
.dst
.write
= (j
== 2);
4211 alu
.src
[0].sel
= tmp0
;
4212 alu
.src
[0].chan
= 0;
4214 alu
.src
[1].sel
= tmp2
;
4215 alu
.src
[1].chan
= 1;
4217 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4220 alu
.last
= (j
== 3);
4221 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4225 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4226 alu
.op
= ALU_OP2_MULLO_UINT
;
4232 alu
.src
[0].sel
= tmp0
;
4233 alu
.src
[0].chan
= 0;
4235 alu
.src
[1].sel
= tmp2
;
4236 alu
.src
[1].chan
= 1;
4238 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4242 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4246 /* 3. tmp0.w = -tmp0.z */
4247 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4248 alu
.op
= ALU_OP2_SUB_INT
;
4254 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4255 alu
.src
[1].sel
= tmp0
;
4256 alu
.src
[1].chan
= 2;
4259 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4262 /* 4. tmp0.y = hi (tmp0.x * src2) */
4263 if (ctx
->bc
->chip_class
== CAYMAN
) {
4264 for (j
= 0 ; j
< 4; j
++) {
4265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4266 alu
.op
= ALU_OP2_MULHI_UINT
;
4270 alu
.dst
.write
= (j
== 1);
4272 alu
.src
[0].sel
= tmp0
;
4273 alu
.src
[0].chan
= 0;
4276 alu
.src
[1].sel
= tmp2
;
4277 alu
.src
[1].chan
= 1;
4279 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4281 alu
.last
= (j
== 3);
4282 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4286 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4287 alu
.op
= ALU_OP2_MULHI_UINT
;
4293 alu
.src
[0].sel
= tmp0
;
4294 alu
.src
[0].chan
= 0;
4297 alu
.src
[1].sel
= tmp2
;
4298 alu
.src
[1].chan
= 1;
4300 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4304 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4308 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
4309 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4310 alu
.op
= ALU_OP3_CNDE_INT
;
4317 alu
.src
[0].sel
= tmp0
;
4318 alu
.src
[0].chan
= 1;
4319 alu
.src
[1].sel
= tmp0
;
4320 alu
.src
[1].chan
= 3;
4321 alu
.src
[2].sel
= tmp0
;
4322 alu
.src
[2].chan
= 2;
4325 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4328 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
4329 if (ctx
->bc
->chip_class
== CAYMAN
) {
4330 for (j
= 0 ; j
< 4; j
++) {
4331 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4332 alu
.op
= ALU_OP2_MULHI_UINT
;
4336 alu
.dst
.write
= (j
== 3);
4338 alu
.src
[0].sel
= tmp0
;
4339 alu
.src
[0].chan
= 2;
4341 alu
.src
[1].sel
= tmp0
;
4342 alu
.src
[1].chan
= 0;
4344 alu
.last
= (j
== 3);
4345 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4349 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4350 alu
.op
= ALU_OP2_MULHI_UINT
;
4356 alu
.src
[0].sel
= tmp0
;
4357 alu
.src
[0].chan
= 2;
4359 alu
.src
[1].sel
= tmp0
;
4360 alu
.src
[1].chan
= 0;
4363 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4367 /* 7. tmp1.x = tmp0.x - tmp0.w */
4368 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4369 alu
.op
= ALU_OP2_SUB_INT
;
4375 alu
.src
[0].sel
= tmp0
;
4376 alu
.src
[0].chan
= 0;
4377 alu
.src
[1].sel
= tmp0
;
4378 alu
.src
[1].chan
= 3;
4381 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4384 /* 8. tmp1.y = tmp0.x + tmp0.w */
4385 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4386 alu
.op
= ALU_OP2_ADD_INT
;
4392 alu
.src
[0].sel
= tmp0
;
4393 alu
.src
[0].chan
= 0;
4394 alu
.src
[1].sel
= tmp0
;
4395 alu
.src
[1].chan
= 3;
4398 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4401 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
4402 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4403 alu
.op
= ALU_OP3_CNDE_INT
;
4410 alu
.src
[0].sel
= tmp0
;
4411 alu
.src
[0].chan
= 1;
4412 alu
.src
[1].sel
= tmp1
;
4413 alu
.src
[1].chan
= 1;
4414 alu
.src
[2].sel
= tmp1
;
4415 alu
.src
[2].chan
= 0;
4418 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4421 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
4422 if (ctx
->bc
->chip_class
== CAYMAN
) {
4423 for (j
= 0 ; j
< 4; j
++) {
4424 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4425 alu
.op
= ALU_OP2_MULHI_UINT
;
4429 alu
.dst
.write
= (j
== 2);
4431 alu
.src
[0].sel
= tmp0
;
4432 alu
.src
[0].chan
= 0;
4435 alu
.src
[1].sel
= tmp2
;
4436 alu
.src
[1].chan
= 0;
4438 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4441 alu
.last
= (j
== 3);
4442 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4446 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4447 alu
.op
= ALU_OP2_MULHI_UINT
;
4453 alu
.src
[0].sel
= tmp0
;
4454 alu
.src
[0].chan
= 0;
4457 alu
.src
[1].sel
= tmp2
;
4458 alu
.src
[1].chan
= 0;
4460 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4464 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4468 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
4469 if (ctx
->bc
->chip_class
== CAYMAN
) {
4470 for (j
= 0 ; j
< 4; j
++) {
4471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4472 alu
.op
= ALU_OP2_MULLO_UINT
;
4476 alu
.dst
.write
= (j
== 1);
4479 alu
.src
[0].sel
= tmp2
;
4480 alu
.src
[0].chan
= 1;
4482 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4485 alu
.src
[1].sel
= tmp0
;
4486 alu
.src
[1].chan
= 2;
4488 alu
.last
= (j
== 3);
4489 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4494 alu
.op
= ALU_OP2_MULLO_UINT
;
4501 alu
.src
[0].sel
= tmp2
;
4502 alu
.src
[0].chan
= 1;
4504 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4507 alu
.src
[1].sel
= tmp0
;
4508 alu
.src
[1].chan
= 2;
4511 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4515 /* 12. tmp0.w = src1 - tmp0.y = r */
4516 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4517 alu
.op
= ALU_OP2_SUB_INT
;
4524 alu
.src
[0].sel
= tmp2
;
4525 alu
.src
[0].chan
= 0;
4527 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4530 alu
.src
[1].sel
= tmp0
;
4531 alu
.src
[1].chan
= 1;
4534 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4537 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
4538 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4539 alu
.op
= ALU_OP2_SETGE_UINT
;
4545 alu
.src
[0].sel
= tmp0
;
4546 alu
.src
[0].chan
= 3;
4548 alu
.src
[1].sel
= tmp2
;
4549 alu
.src
[1].chan
= 1;
4551 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4555 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4558 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
4559 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4560 alu
.op
= ALU_OP2_SETGE_UINT
;
4567 alu
.src
[0].sel
= tmp2
;
4568 alu
.src
[0].chan
= 0;
4570 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4573 alu
.src
[1].sel
= tmp0
;
4574 alu
.src
[1].chan
= 1;
4577 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4580 if (mod
) { /* UMOD */
4582 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
4583 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4584 alu
.op
= ALU_OP2_SUB_INT
;
4590 alu
.src
[0].sel
= tmp0
;
4591 alu
.src
[0].chan
= 3;
4594 alu
.src
[1].sel
= tmp2
;
4595 alu
.src
[1].chan
= 1;
4597 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4601 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4604 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
4605 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4606 alu
.op
= ALU_OP2_ADD_INT
;
4612 alu
.src
[0].sel
= tmp0
;
4613 alu
.src
[0].chan
= 3;
4615 alu
.src
[1].sel
= tmp2
;
4616 alu
.src
[1].chan
= 1;
4618 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
4622 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4627 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
4628 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4629 alu
.op
= ALU_OP2_ADD_INT
;
4635 alu
.src
[0].sel
= tmp0
;
4636 alu
.src
[0].chan
= 2;
4637 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
4640 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4643 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
4644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4645 alu
.op
= ALU_OP2_ADD_INT
;
4651 alu
.src
[0].sel
= tmp0
;
4652 alu
.src
[0].chan
= 2;
4653 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
4656 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4661 /* 17. tmp1.x = tmp1.x & tmp1.y */
4662 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4663 alu
.op
= ALU_OP2_AND_INT
;
4669 alu
.src
[0].sel
= tmp1
;
4670 alu
.src
[0].chan
= 0;
4671 alu
.src
[1].sel
= tmp1
;
4672 alu
.src
[1].chan
= 1;
4675 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4678 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
4679 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
4680 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4681 alu
.op
= ALU_OP3_CNDE_INT
;
4688 alu
.src
[0].sel
= tmp1
;
4689 alu
.src
[0].chan
= 0;
4690 alu
.src
[1].sel
= tmp0
;
4691 alu
.src
[1].chan
= mod
? 3 : 2;
4692 alu
.src
[2].sel
= tmp1
;
4693 alu
.src
[2].chan
= 2;
4696 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4699 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
4700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4701 alu
.op
= ALU_OP3_CNDE_INT
;
4709 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4712 alu
.src
[0].sel
= tmp1
;
4713 alu
.src
[0].chan
= 1;
4714 alu
.src
[1].sel
= tmp1
;
4715 alu
.src
[1].chan
= 3;
4716 alu
.src
[2].sel
= tmp0
;
4717 alu
.src
[2].chan
= 2;
4720 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4725 /* fix the sign of the result */
4729 /* tmp0.x = -tmp0.z */
4730 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4731 alu
.op
= ALU_OP2_SUB_INT
;
4737 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4738 alu
.src
[1].sel
= tmp0
;
4739 alu
.src
[1].chan
= 2;
4742 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4745 /* sign of the remainder is the same as the sign of src0 */
4746 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
4747 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4748 alu
.op
= ALU_OP3_CNDGE_INT
;
4751 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4753 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4754 alu
.src
[1].sel
= tmp0
;
4755 alu
.src
[1].chan
= 2;
4756 alu
.src
[2].sel
= tmp0
;
4757 alu
.src
[2].chan
= 0;
4760 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4765 /* tmp0.x = -tmp0.z */
4766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4767 alu
.op
= ALU_OP2_SUB_INT
;
4773 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4774 alu
.src
[1].sel
= tmp0
;
4775 alu
.src
[1].chan
= 2;
4778 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4781 /* fix the quotient sign (same as the sign of src0*src1) */
4782 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
4783 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4784 alu
.op
= ALU_OP3_CNDGE_INT
;
4787 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4789 alu
.src
[0].sel
= tmp2
;
4790 alu
.src
[0].chan
= 2;
4791 alu
.src
[1].sel
= tmp0
;
4792 alu
.src
[1].chan
= 2;
4793 alu
.src
[2].sel
= tmp0
;
4794 alu
.src
[2].chan
= 0;
4797 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
4805 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
4807 return tgsi_divmod(ctx
, 0, 0);
4810 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
4812 return tgsi_divmod(ctx
, 1, 0);
4815 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
4817 return tgsi_divmod(ctx
, 0, 1);
4820 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
4822 return tgsi_divmod(ctx
, 1, 1);
4826 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
4828 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4829 struct r600_bytecode_alu alu
;
4831 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4832 int last_inst
= tgsi_last_instruction(write_mask
);
4834 for (i
= 0; i
< 4; i
++) {
4835 if (!(write_mask
& (1<<i
)))
4838 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4839 alu
.op
= ALU_OP1_TRUNC
;
4841 alu
.dst
.sel
= ctx
->temp_reg
;
4845 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4848 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4853 for (i
= 0; i
< 4; i
++) {
4854 if (!(write_mask
& (1<<i
)))
4857 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4858 alu
.op
= ctx
->inst_info
->op
;
4860 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4862 alu
.src
[0].sel
= ctx
->temp_reg
;
4863 alu
.src
[0].chan
= i
;
4865 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
4867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4875 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
4877 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4878 struct r600_bytecode_alu alu
;
4880 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4881 int last_inst
= tgsi_last_instruction(write_mask
);
4884 for (i
= 0; i
< 4; i
++) {
4885 if (!(write_mask
& (1<<i
)))
4888 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4889 alu
.op
= ALU_OP2_SUB_INT
;
4891 alu
.dst
.sel
= ctx
->temp_reg
;
4895 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4896 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4905 /* dst = (src >= 0 ? src : tmp) */
4906 for (i
= 0; i
< 4; i
++) {
4907 if (!(write_mask
& (1<<i
)))
4910 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4911 alu
.op
= ALU_OP3_CNDGE_INT
;
4915 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4917 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4918 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4919 alu
.src
[2].sel
= ctx
->temp_reg
;
4920 alu
.src
[2].chan
= i
;
4924 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4931 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
4933 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4934 struct r600_bytecode_alu alu
;
4936 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4937 int last_inst
= tgsi_last_instruction(write_mask
);
4939 /* tmp = (src >= 0 ? src : -1) */
4940 for (i
= 0; i
< 4; i
++) {
4941 if (!(write_mask
& (1<<i
)))
4944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4945 alu
.op
= ALU_OP3_CNDGE_INT
;
4948 alu
.dst
.sel
= ctx
->temp_reg
;
4952 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4953 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4954 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
4958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4963 /* dst = (tmp > 0 ? 1 : tmp) */
4964 for (i
= 0; i
< 4; i
++) {
4965 if (!(write_mask
& (1<<i
)))
4968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4969 alu
.op
= ALU_OP3_CNDGT_INT
;
4973 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4975 alu
.src
[0].sel
= ctx
->temp_reg
;
4976 alu
.src
[0].chan
= i
;
4978 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
4980 alu
.src
[2].sel
= ctx
->temp_reg
;
4981 alu
.src
[2].chan
= i
;
4985 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4994 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
4996 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4997 struct r600_bytecode_alu alu
;
5000 /* tmp = (src > 0 ? 1 : src) */
5001 for (i
= 0; i
< 4; i
++) {
5002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5003 alu
.op
= ALU_OP3_CNDGT
;
5006 alu
.dst
.sel
= ctx
->temp_reg
;
5009 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5010 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5011 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
5015 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5020 /* dst = (-tmp > 0 ? -1 : tmp) */
5021 for (i
= 0; i
< 4; i
++) {
5022 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5023 alu
.op
= ALU_OP3_CNDGT
;
5025 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5027 alu
.src
[0].sel
= ctx
->temp_reg
;
5028 alu
.src
[0].chan
= i
;
5031 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5034 alu
.src
[2].sel
= ctx
->temp_reg
;
5035 alu
.src
[2].chan
= i
;
5039 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5046 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
5048 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5049 struct r600_bytecode_alu alu
;
5052 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5053 int last_inst
= tgsi_last_instruction(write_mask
);
5057 for (i
= 0; i
< 4; i
++) {
5058 if (!(write_mask
& (1<<i
)))
5061 /* create mask tmp */
5062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5063 alu
.op
= ALU_OP2_BFM_INT
;
5067 alu
.last
= i
== last_inst
;
5069 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
5070 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5072 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5077 t2
= r600_get_temp(ctx
);
5079 for (i
= 0; i
< 4; i
++) {
5080 if (!(write_mask
& (1<<i
)))
5083 /* shift insert left */
5084 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5085 alu
.op
= ALU_OP2_LSHL_INT
;
5089 alu
.last
= i
== last_inst
;
5091 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5092 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
5094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5099 for (i
= 0; i
< 4; i
++) {
5100 if (!(write_mask
& (1<<i
)))
5103 /* actual bitfield insert */
5104 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5105 alu
.op
= ALU_OP3_BFI_INT
;
5107 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5110 alu
.last
= i
== last_inst
;
5112 alu
.src
[0].sel
= t1
;
5113 alu
.src
[0].chan
= i
;
5114 alu
.src
[1].sel
= t2
;
5115 alu
.src
[1].chan
= i
;
5116 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
5118 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5126 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
5128 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5129 struct r600_bytecode_alu alu
;
5132 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5133 int last_inst
= tgsi_last_instruction(write_mask
);
5135 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
5136 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
5140 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
5141 for (i
= 0; i
< 4; i
++) {
5142 if (!(write_mask
& (1<<i
)))
5145 /* t1 = FFBH_INT / FFBH_UINT */
5146 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5147 alu
.op
= ctx
->inst_info
->op
;
5151 alu
.last
= i
== last_inst
;
5153 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5160 t2
= r600_get_temp(ctx
);
5162 for (i
= 0; i
< 4; i
++) {
5163 if (!(write_mask
& (1<<i
)))
5167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5168 alu
.op
= ALU_OP2_SUB_INT
;
5172 alu
.last
= i
== last_inst
;
5174 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
5175 alu
.src
[0].value
= 31;
5176 alu
.src
[1].sel
= t1
;
5177 alu
.src
[1].chan
= i
;
5179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5184 for (i
= 0; i
< 4; i
++) {
5185 if (!(write_mask
& (1<<i
)))
5188 /* result = t1 >= 0 ? t2 : t1 */
5189 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5190 alu
.op
= ALU_OP3_CNDGE_INT
;
5192 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5195 alu
.last
= i
== last_inst
;
5197 alu
.src
[0].sel
= t1
;
5198 alu
.src
[0].chan
= i
;
5199 alu
.src
[1].sel
= t2
;
5200 alu
.src
[1].chan
= i
;
5201 alu
.src
[2].sel
= t1
;
5202 alu
.src
[2].chan
= i
;
5204 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5212 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
5214 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5215 struct r600_bytecode_alu alu
;
5216 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
5220 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
5222 input
= inst
->Src
[0].Register
.Index
;
5224 /* Interpolators have been marked for use already by allocate_system_value_inputs */
5225 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
5226 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5227 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
5230 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
5233 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
5236 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
5237 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
5239 /* NOTE: currently offset is not perspective correct */
5240 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
5241 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5242 int sample_gpr
= -1;
5243 int gradientsH
, gradientsV
;
5244 struct r600_bytecode_tex tex
;
5246 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5247 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
5250 gradientsH
= r600_get_temp(ctx
);
5251 gradientsV
= r600_get_temp(ctx
);
5252 for (i
= 0; i
< 2; i
++) {
5253 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
5254 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
5255 tex
.src_gpr
= interp_gpr
;
5256 tex
.src_sel_x
= interp_base_chan
+ 0;
5257 tex
.src_sel_y
= interp_base_chan
+ 1;
5260 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
5265 tex
.inst_mod
= 1; // Use per pixel gradient calculation
5267 tex
.resource_id
= tex
.sampler_id
;
5268 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
5273 for (i
= 0; i
< 2; i
++) {
5274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5275 alu
.op
= ALU_OP3_MULADD
;
5277 alu
.src
[0].sel
= gradientsH
;
5278 alu
.src
[0].chan
= i
;
5279 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5280 alu
.src
[1].sel
= sample_gpr
;
5281 alu
.src
[1].chan
= 2;
5284 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
5286 alu
.src
[2].sel
= interp_gpr
;
5287 alu
.src
[2].chan
= interp_base_chan
+ i
;
5288 alu
.dst
.sel
= ctx
->temp_reg
;
5292 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5297 for (i
= 0; i
< 2; i
++) {
5298 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5299 alu
.op
= ALU_OP3_MULADD
;
5301 alu
.src
[0].sel
= gradientsV
;
5302 alu
.src
[0].chan
= i
;
5303 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5304 alu
.src
[1].sel
= sample_gpr
;
5305 alu
.src
[1].chan
= 3;
5308 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
5310 alu
.src
[2].sel
= ctx
->temp_reg
;
5311 alu
.src
[2].chan
= i
;
5312 alu
.dst
.sel
= ctx
->temp_reg
;
5316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5322 tmp
= r600_get_temp(ctx
);
5323 for (i
= 0; i
< 8; i
++) {
5324 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5325 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
5328 if ((i
> 1 && i
< 6)) {
5334 alu
.dst
.chan
= i
% 4;
5336 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
5337 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
5338 alu
.src
[0].sel
= ctx
->temp_reg
;
5339 alu
.src
[0].chan
= 1 - (i
% 2);
5341 alu
.src
[0].sel
= interp_gpr
;
5342 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
5344 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
5345 alu
.src
[1].chan
= 0;
5347 alu
.last
= i
% 4 == 3;
5348 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
5350 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5355 // INTERP can't swizzle dst
5356 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5357 for (i
= 0; i
<= lasti
; i
++) {
5358 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5362 alu
.op
= ALU_OP1_MOV
;
5363 alu
.src
[0].sel
= tmp
;
5364 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
5365 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5367 alu
.last
= i
== lasti
;
5368 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5377 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
5379 struct r600_bytecode_alu alu
;
5382 for (i
= 0; i
< 4; i
++) {
5383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5384 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
5385 alu
.op
= ALU_OP0_NOP
;
5388 alu
.op
= ALU_OP1_MOV
;
5389 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5390 alu
.src
[0].sel
= ctx
->temp_reg
;
5391 alu
.src
[0].chan
= i
;
5396 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5403 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
5404 unsigned temp
, int chan
,
5405 struct r600_bytecode_alu_src
*bc_src
,
5406 const struct r600_shader_src
*shader_src
)
5408 struct r600_bytecode_alu alu
;
5411 r600_bytecode_src(bc_src
, shader_src
, chan
);
5413 /* op3 operands don't support abs modifier */
5415 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
5416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5417 alu
.op
= ALU_OP1_MOV
;
5419 alu
.dst
.chan
= chan
;
5422 alu
.src
[0] = *bc_src
;
5423 alu
.last
= true; // sufficient?
5424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5428 memset(bc_src
, 0, sizeof(*bc_src
));
5430 bc_src
->chan
= chan
;
5435 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
5437 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5438 struct r600_bytecode_alu alu
;
5440 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5443 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5445 if (ctx
->src
[j
].abs
)
5446 temp_regs
[j
] = r600_get_temp(ctx
);
5448 for (i
= 0; i
< lasti
+ 1; i
++) {
5449 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5452 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5453 alu
.op
= ctx
->inst_info
->op
;
5454 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5455 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
5460 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5467 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5474 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
5476 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5477 struct r600_bytecode_alu alu
;
5480 for (i
= 0; i
< 4; i
++) {
5481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5482 alu
.op
= ctx
->inst_info
->op
;
5483 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5484 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
5487 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5489 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5490 /* handle some special cases */
5491 switch (inst
->Instruction
.Opcode
) {
5492 case TGSI_OPCODE_DP2
:
5494 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5495 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
5498 case TGSI_OPCODE_DP3
:
5500 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
5501 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
5504 case TGSI_OPCODE_DPH
:
5506 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5507 alu
.src
[0].chan
= 0;
5517 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5524 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
5527 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5528 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
5529 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
5530 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
5531 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
5532 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== TGSI_PROCESSOR_GEOMETRY
);
5535 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
5538 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5539 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
5542 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
5544 struct r600_bytecode_vtx vtx
;
5545 struct r600_bytecode_alu alu
;
5546 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5548 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
5550 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
5551 if (src_requires_loading
) {
5552 for (i
= 0; i
< 4; i
++) {
5553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5554 alu
.op
= ALU_OP1_MOV
;
5555 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5556 alu
.dst
.sel
= ctx
->temp_reg
;
5561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5565 src_gpr
= ctx
->temp_reg
;
5568 memset(&vtx
, 0, sizeof(vtx
));
5569 vtx
.op
= FETCH_OP_VFETCH
;
5570 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
5571 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
5572 vtx
.src_gpr
= src_gpr
;
5573 vtx
.mega_fetch_count
= 16;
5574 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
5575 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
5576 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
5577 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
5578 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
5579 vtx
.use_const_fields
= 1;
5581 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
5584 if (ctx
->bc
->chip_class
>= EVERGREEN
)
5587 for (i
= 0; i
< 4; i
++) {
5588 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5589 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5593 alu
.op
= ALU_OP2_AND_INT
;
5596 alu
.dst
.sel
= vtx
.dst_gpr
;
5599 alu
.src
[0].sel
= vtx
.dst_gpr
;
5600 alu
.src
[0].chan
= i
;
5602 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
5603 alu
.src
[1].sel
+= (id
* 2);
5604 alu
.src
[1].chan
= i
% 4;
5605 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
5609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5614 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
5615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5616 alu
.op
= ALU_OP2_OR_INT
;
5619 alu
.dst
.sel
= vtx
.dst_gpr
;
5622 alu
.src
[0].sel
= vtx
.dst_gpr
;
5623 alu
.src
[0].chan
= 3;
5625 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
5626 alu
.src
[1].chan
= 0;
5627 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
5630 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5637 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
5639 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5640 struct r600_bytecode_alu alu
;
5642 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
5644 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5645 alu
.op
= ALU_OP1_MOV
;
5646 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
5647 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
5648 /* channel 0 or 2 of each word */
5649 alu
.src
[0].sel
+= (id
/ 2);
5650 alu
.src
[0].chan
= (id
% 2) * 2;
5652 /* r600 we have them at channel 2 of the second dword */
5653 alu
.src
[0].sel
+= (id
* 2) + 1;
5654 alu
.src
[0].chan
= 1;
5656 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
5657 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5665 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
5667 static float one_point_five
= 1.5f
;
5668 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5669 struct r600_bytecode_tex tex
;
5670 struct r600_bytecode_alu alu
;
5674 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
5675 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
5676 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
5677 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
5679 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
5680 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
5681 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
5683 /* Texture fetch instructions can only use gprs as source.
5684 * Also they cannot negate the source or take the absolute value */
5685 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
5686 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
5687 tgsi_tex_src_requires_loading(ctx
, 0)) ||
5688 read_compressed_msaa
|| txf_add_offsets
;
5690 boolean src_loaded
= FALSE
;
5691 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
5692 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
5693 boolean has_txq_cube_array_z
= false;
5694 unsigned sampler_index_mode
;
5696 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
5697 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5698 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
5699 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
5700 ctx
->shader
->has_txq_cube_array_z_comp
= true;
5701 has_txq_cube_array_z
= true;
5704 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
5705 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
5706 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
5707 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
5708 sampler_src_reg
= 2;
5710 /* TGSI moves the sampler to src reg 3 for TXD */
5711 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
5712 sampler_src_reg
= 3;
5714 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
5716 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
5718 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
5719 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
5720 ctx
->shader
->uses_tex_buffers
= true;
5721 return r600_do_buffer_txq(ctx
);
5723 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
5724 if (ctx
->bc
->chip_class
< EVERGREEN
)
5725 ctx
->shader
->uses_tex_buffers
= true;
5726 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
5730 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
5732 /* Add perspective divide */
5733 if (ctx
->bc
->chip_class
== CAYMAN
) {
5735 for (i
= 0; i
< 3; i
++) {
5736 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5737 alu
.op
= ALU_OP1_RECIP_IEEE
;
5738 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5740 alu
.dst
.sel
= ctx
->temp_reg
;
5746 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5753 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5754 alu
.op
= ALU_OP1_RECIP_IEEE
;
5755 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5757 alu
.dst
.sel
= ctx
->temp_reg
;
5758 alu
.dst
.chan
= out_chan
;
5761 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5766 for (i
= 0; i
< 3; i
++) {
5767 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5768 alu
.op
= ALU_OP2_MUL
;
5769 alu
.src
[0].sel
= ctx
->temp_reg
;
5770 alu
.src
[0].chan
= out_chan
;
5771 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5772 alu
.dst
.sel
= ctx
->temp_reg
;
5775 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5779 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5780 alu
.op
= ALU_OP1_MOV
;
5781 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5782 alu
.src
[0].chan
= 0;
5783 alu
.dst
.sel
= ctx
->temp_reg
;
5787 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5791 src_gpr
= ctx
->temp_reg
;
5795 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
5796 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5797 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5798 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
5799 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
5800 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
5802 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
5803 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
5805 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
5806 for (i
= 0; i
< 4; i
++) {
5807 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5808 alu
.op
= ALU_OP2_CUBE
;
5809 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
5810 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
5811 alu
.dst
.sel
= ctx
->temp_reg
;
5816 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5821 /* tmp1.z = RCP_e(|tmp1.z|) */
5822 if (ctx
->bc
->chip_class
== CAYMAN
) {
5823 for (i
= 0; i
< 3; i
++) {
5824 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5825 alu
.op
= ALU_OP1_RECIP_IEEE
;
5826 alu
.src
[0].sel
= ctx
->temp_reg
;
5827 alu
.src
[0].chan
= 2;
5829 alu
.dst
.sel
= ctx
->temp_reg
;
5835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5840 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5841 alu
.op
= ALU_OP1_RECIP_IEEE
;
5842 alu
.src
[0].sel
= ctx
->temp_reg
;
5843 alu
.src
[0].chan
= 2;
5845 alu
.dst
.sel
= ctx
->temp_reg
;
5849 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5854 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
5855 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
5856 * muladd has no writemask, have to use another temp
5858 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5859 alu
.op
= ALU_OP3_MULADD
;
5862 alu
.src
[0].sel
= ctx
->temp_reg
;
5863 alu
.src
[0].chan
= 0;
5864 alu
.src
[1].sel
= ctx
->temp_reg
;
5865 alu
.src
[1].chan
= 2;
5867 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
5868 alu
.src
[2].chan
= 0;
5869 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
5871 alu
.dst
.sel
= ctx
->temp_reg
;
5875 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5880 alu
.op
= ALU_OP3_MULADD
;
5883 alu
.src
[0].sel
= ctx
->temp_reg
;
5884 alu
.src
[0].chan
= 1;
5885 alu
.src
[1].sel
= ctx
->temp_reg
;
5886 alu
.src
[1].chan
= 2;
5888 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
5889 alu
.src
[2].chan
= 0;
5890 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
5892 alu
.dst
.sel
= ctx
->temp_reg
;
5897 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5900 /* write initial compare value into Z component
5901 - W src 0 for shadow cube
5902 - X src 1 for shadow cube array */
5903 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
5904 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
5905 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5906 alu
.op
= ALU_OP1_MOV
;
5907 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
5908 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5910 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5911 alu
.dst
.sel
= ctx
->temp_reg
;
5915 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5920 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
5921 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
5922 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
5923 int mytmp
= r600_get_temp(ctx
);
5924 static const float eight
= 8.0f
;
5925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5926 alu
.op
= ALU_OP1_MOV
;
5927 alu
.src
[0].sel
= ctx
->temp_reg
;
5928 alu
.src
[0].chan
= 3;
5929 alu
.dst
.sel
= mytmp
;
5933 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5937 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
5938 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5939 alu
.op
= ALU_OP3_MULADD
;
5941 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5942 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5943 alu
.src
[1].chan
= 0;
5944 alu
.src
[1].value
= *(uint32_t *)&eight
;
5945 alu
.src
[2].sel
= mytmp
;
5946 alu
.src
[2].chan
= 0;
5947 alu
.dst
.sel
= ctx
->temp_reg
;
5951 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5954 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
5955 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
5956 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
5957 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
5958 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
5959 tex
.src_gpr
= r600_get_temp(ctx
);
5964 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
5965 tex
.coord_type_x
= 1;
5966 tex
.coord_type_y
= 1;
5967 tex
.coord_type_z
= 1;
5968 tex
.coord_type_w
= 1;
5969 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5970 alu
.op
= ALU_OP1_MOV
;
5971 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5972 alu
.dst
.sel
= tex
.src_gpr
;
5976 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5980 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
5987 /* for cube forms of lod and bias we need to route things */
5988 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
5989 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
5990 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
5991 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
5992 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5993 alu
.op
= ALU_OP1_MOV
;
5994 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
5995 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
5996 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5998 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
5999 alu
.dst
.sel
= ctx
->temp_reg
;
6003 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6009 src_gpr
= ctx
->temp_reg
;
6012 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
6013 int temp_h
= 0, temp_v
= 0;
6016 /* if we've already loaded the src (i.e. CUBE don't reload it). */
6017 if (src_loaded
== TRUE
)
6021 for (i
= start_val
; i
< 3; i
++) {
6022 int treg
= r600_get_temp(ctx
);
6031 for (j
= 0; j
< 4; j
++) {
6032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6033 alu
.op
= ALU_OP1_MOV
;
6034 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
6040 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6045 for (i
= 1; i
< 3; i
++) {
6046 /* set gradients h/v */
6047 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6048 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
6049 FETCH_OP_SET_GRADIENTS_V
;
6050 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6051 tex
.sampler_index_mode
= sampler_index_mode
;
6052 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6053 tex
.resource_index_mode
= sampler_index_mode
;
6055 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
6061 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
6062 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
6063 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
6064 tex
.coord_type_x
= 1;
6065 tex
.coord_type_y
= 1;
6066 tex
.coord_type_z
= 1;
6067 tex
.coord_type_w
= 1;
6069 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6075 if (src_requires_loading
&& !src_loaded
) {
6076 for (i
= 0; i
< 4; i
++) {
6077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6078 alu
.op
= ALU_OP1_MOV
;
6079 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6080 alu
.dst
.sel
= ctx
->temp_reg
;
6085 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6090 src_gpr
= ctx
->temp_reg
;
6093 /* get offset values */
6094 if (inst
->Texture
.NumOffsets
) {
6095 assert(inst
->Texture
.NumOffsets
== 1);
6097 /* The texture offset feature doesn't work with the TXF instruction
6098 * and must be emulated by adding the offset to the texture coordinates. */
6099 if (txf_add_offsets
) {
6100 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
6102 switch (inst
->Texture
.Texture
) {
6103 case TGSI_TEXTURE_3D
:
6104 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6105 alu
.op
= ALU_OP2_ADD_INT
;
6106 alu
.src
[0].sel
= src_gpr
;
6107 alu
.src
[0].chan
= 2;
6108 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6109 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
6110 alu
.dst
.sel
= src_gpr
;
6114 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6119 case TGSI_TEXTURE_2D
:
6120 case TGSI_TEXTURE_SHADOW2D
:
6121 case TGSI_TEXTURE_RECT
:
6122 case TGSI_TEXTURE_SHADOWRECT
:
6123 case TGSI_TEXTURE_2D_ARRAY
:
6124 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
6125 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6126 alu
.op
= ALU_OP2_ADD_INT
;
6127 alu
.src
[0].sel
= src_gpr
;
6128 alu
.src
[0].chan
= 1;
6129 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6130 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
6131 alu
.dst
.sel
= src_gpr
;
6135 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6140 case TGSI_TEXTURE_1D
:
6141 case TGSI_TEXTURE_SHADOW1D
:
6142 case TGSI_TEXTURE_1D_ARRAY
:
6143 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
6144 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6145 alu
.op
= ALU_OP2_ADD_INT
;
6146 alu
.src
[0].sel
= src_gpr
;
6147 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6148 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
6149 alu
.dst
.sel
= src_gpr
;
6152 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6156 /* texture offsets do not apply to other texture targets */
6159 switch (inst
->Texture
.Texture
) {
6160 case TGSI_TEXTURE_3D
:
6161 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
6163 case TGSI_TEXTURE_2D
:
6164 case TGSI_TEXTURE_SHADOW2D
:
6165 case TGSI_TEXTURE_RECT
:
6166 case TGSI_TEXTURE_SHADOWRECT
:
6167 case TGSI_TEXTURE_2D_ARRAY
:
6168 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
6169 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
6171 case TGSI_TEXTURE_1D
:
6172 case TGSI_TEXTURE_SHADOW1D
:
6173 case TGSI_TEXTURE_1D_ARRAY
:
6174 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
6175 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
6180 /* Obtain the sample index for reading a compressed MSAA color texture.
6181 * To read the FMASK, we use the ldfptr instruction, which tells us
6182 * where the samples are stored.
6183 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
6184 * which is the identity mapping. Each nibble says which physical sample
6185 * should be fetched to get that sample.
6187 * Assume src.z contains the sample index. It should be modified like this:
6188 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
6189 * Then fetch the texel with src.
6191 if (read_compressed_msaa
) {
6192 unsigned sample_chan
= 3;
6193 unsigned temp
= r600_get_temp(ctx
);
6196 /* temp.w = ldfptr() */
6197 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6198 tex
.op
= FETCH_OP_LD
;
6199 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
6200 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6201 tex
.sampler_index_mode
= sampler_index_mode
;
6202 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6203 tex
.resource_index_mode
= sampler_index_mode
;
6204 tex
.src_gpr
= src_gpr
;
6206 tex
.dst_sel_x
= 7; /* mask out these components */
6209 tex
.dst_sel_w
= 0; /* store X */
6214 tex
.offset_x
= offset_x
;
6215 tex
.offset_y
= offset_y
;
6216 tex
.offset_z
= offset_z
;
6217 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6221 /* temp.x = sample_index*4 */
6222 if (ctx
->bc
->chip_class
== CAYMAN
) {
6223 for (i
= 0 ; i
< 4; i
++) {
6224 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6225 alu
.op
= ALU_OP2_MULLO_INT
;
6226 alu
.src
[0].sel
= src_gpr
;
6227 alu
.src
[0].chan
= sample_chan
;
6228 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6229 alu
.src
[1].value
= 4;
6232 alu
.dst
.write
= i
== 0;
6235 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6241 alu
.op
= ALU_OP2_MULLO_INT
;
6242 alu
.src
[0].sel
= src_gpr
;
6243 alu
.src
[0].chan
= sample_chan
;
6244 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6245 alu
.src
[1].value
= 4;
6250 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6255 /* sample_index = temp.w >> temp.x */
6256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6257 alu
.op
= ALU_OP2_LSHR_INT
;
6258 alu
.src
[0].sel
= temp
;
6259 alu
.src
[0].chan
= 3;
6260 alu
.src
[1].sel
= temp
;
6261 alu
.src
[1].chan
= 0;
6262 alu
.dst
.sel
= src_gpr
;
6263 alu
.dst
.chan
= sample_chan
;
6266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6270 /* sample_index & 0xF */
6271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6272 alu
.op
= ALU_OP2_AND_INT
;
6273 alu
.src
[0].sel
= src_gpr
;
6274 alu
.src
[0].chan
= sample_chan
;
6275 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6276 alu
.src
[1].value
= 0xF;
6277 alu
.dst
.sel
= src_gpr
;
6278 alu
.dst
.chan
= sample_chan
;
6281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6285 /* visualize the FMASK */
6286 for (i
= 0; i
< 4; i
++) {
6287 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6288 alu
.op
= ALU_OP1_INT_TO_FLT
;
6289 alu
.src
[0].sel
= src_gpr
;
6290 alu
.src
[0].chan
= sample_chan
;
6291 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6295 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6303 /* does this shader want a num layers from TXQ for a cube array? */
6304 if (has_txq_cube_array_z
) {
6305 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6308 alu
.op
= ALU_OP1_MOV
;
6310 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6311 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6312 /* channel 1 or 3 of each word */
6313 alu
.src
[0].sel
+= (id
/ 2);
6314 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
6316 /* r600 we have them at channel 2 of the second dword */
6317 alu
.src
[0].sel
+= (id
* 2) + 1;
6318 alu
.src
[0].chan
= 2;
6320 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6321 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
6323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6326 /* disable writemask from texture instruction */
6327 inst
->Dst
[0].Register
.WriteMask
&= ~4;
6330 opcode
= ctx
->inst_info
->op
;
6331 if (opcode
== FETCH_OP_GATHER4
&&
6332 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
6333 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
6334 opcode
= FETCH_OP_GATHER4_O
;
6336 /* GATHER4_O/GATHER4_C_O use offset values loaded by
6337 SET_TEXTURE_OFFSETS instruction. The immediate offset values
6338 encoded in the instruction are ignored. */
6339 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6340 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
6341 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6342 tex
.sampler_index_mode
= sampler_index_mode
;
6343 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6344 tex
.resource_index_mode
= sampler_index_mode
;
6346 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
6347 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
6348 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
6349 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
6357 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6362 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
6363 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
6364 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
6365 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6366 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
6367 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
6368 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6370 case FETCH_OP_SAMPLE
:
6371 opcode
= FETCH_OP_SAMPLE_C
;
6373 case FETCH_OP_SAMPLE_L
:
6374 opcode
= FETCH_OP_SAMPLE_C_L
;
6376 case FETCH_OP_SAMPLE_LB
:
6377 opcode
= FETCH_OP_SAMPLE_C_LB
;
6379 case FETCH_OP_SAMPLE_G
:
6380 opcode
= FETCH_OP_SAMPLE_C_G
;
6382 /* Texture gather variants */
6383 case FETCH_OP_GATHER4
:
6384 opcode
= FETCH_OP_GATHER4_C
;
6386 case FETCH_OP_GATHER4_O
:
6387 opcode
= FETCH_OP_GATHER4_C_O
;
6392 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6395 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
6396 tex
.sampler_index_mode
= sampler_index_mode
;
6397 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
6398 tex
.resource_index_mode
= sampler_index_mode
;
6399 tex
.src_gpr
= src_gpr
;
6400 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6402 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
6403 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
6404 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
6407 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
6408 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
6409 tex
.inst_mod
= texture_component_select
;
6411 if (ctx
->bc
->chip_class
== CAYMAN
) {
6412 /* GATHER4 result order is different from TGSI TG4 */
6413 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
6414 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
6415 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
6416 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
6418 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
6419 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
6420 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
6421 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
6424 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
6425 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
6426 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
6430 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
6437 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
6438 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
6439 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
6440 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
6444 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
||
6445 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
6450 } else if (src_loaded
) {
6456 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
6457 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
6458 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
6459 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
6460 tex
.src_rel
= ctx
->src
[0].rel
;
6463 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
6464 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6465 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6466 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6470 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
6473 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
6474 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
6475 tex
.coord_type_x
= 1;
6476 tex
.coord_type_y
= 1;
6478 tex
.coord_type_z
= 1;
6479 tex
.coord_type_w
= 1;
6481 tex
.offset_x
= offset_x
;
6482 tex
.offset_y
= offset_y
;
6483 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
6484 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
6485 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
6489 tex
.offset_z
= offset_z
;
6492 /* Put the depth for comparison in W.
6493 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
6494 * Some instructions expect the depth in Z. */
6495 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
6496 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
6497 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
6498 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
6499 opcode
!= FETCH_OP_SAMPLE_C_L
&&
6500 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
6501 tex
.src_sel_w
= tex
.src_sel_z
;
6504 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
6505 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
6506 if (opcode
== FETCH_OP_SAMPLE_C_L
||
6507 opcode
== FETCH_OP_SAMPLE_C_LB
) {
6508 /* the array index is read from Y */
6509 tex
.coord_type_y
= 0;
6511 /* the array index is read from Z */
6512 tex
.coord_type_z
= 0;
6513 tex
.src_sel_z
= tex
.src_sel_y
;
6515 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
6516 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
6517 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6518 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
6519 (ctx
->bc
->chip_class
>= EVERGREEN
)))
6520 /* the array index is read from Z */
6521 tex
.coord_type_z
= 0;
6523 /* mask unused source components */
6524 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
6525 switch (inst
->Texture
.Texture
) {
6526 case TGSI_TEXTURE_2D
:
6527 case TGSI_TEXTURE_RECT
:
6531 case TGSI_TEXTURE_1D_ARRAY
:
6535 case TGSI_TEXTURE_1D
:
6543 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6547 /* add shadow ambient support - gallium doesn't do it yet */
6551 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
6553 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6554 struct r600_bytecode_alu alu
;
6555 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6556 unsigned i
, temp_regs
[2];
6559 /* optimize if it's just an equal balance */
6560 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
6561 for (i
= 0; i
< lasti
+ 1; i
++) {
6562 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6565 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6566 alu
.op
= ALU_OP2_ADD
;
6567 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6568 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6570 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6583 for (i
= 0; i
< lasti
+ 1; i
++) {
6584 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6587 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6588 alu
.op
= ALU_OP2_ADD
;
6589 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6590 alu
.src
[0].chan
= 0;
6591 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6592 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
6593 alu
.dst
.sel
= ctx
->temp_reg
;
6599 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6604 /* (1 - src0) * src2 */
6605 for (i
= 0; i
< lasti
+ 1; i
++) {
6606 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6609 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6610 alu
.op
= ALU_OP2_MUL
;
6611 alu
.src
[0].sel
= ctx
->temp_reg
;
6612 alu
.src
[0].chan
= i
;
6613 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6614 alu
.dst
.sel
= ctx
->temp_reg
;
6620 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6625 /* src0 * src1 + (1 - src0) * src2 */
6626 if (ctx
->src
[0].abs
)
6627 temp_regs
[0] = r600_get_temp(ctx
);
6630 if (ctx
->src
[1].abs
)
6631 temp_regs
[1] = r600_get_temp(ctx
);
6635 for (i
= 0; i
< lasti
+ 1; i
++) {
6636 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6639 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6640 alu
.op
= ALU_OP3_MULADD
;
6642 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
6645 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
6648 alu
.src
[2].sel
= ctx
->temp_reg
;
6649 alu
.src
[2].chan
= i
;
6651 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6656 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6663 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
6665 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6666 struct r600_bytecode_alu alu
;
6668 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6671 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6673 if (ctx
->src
[j
].abs
)
6674 temp_regs
[j
] = r600_get_temp(ctx
);
6677 for (i
= 0; i
< lasti
+ 1; i
++) {
6678 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6681 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6682 alu
.op
= ALU_OP3_CNDGE
;
6683 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
6686 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
6689 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
6692 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6698 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6705 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
6707 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6708 struct r600_bytecode_alu alu
;
6710 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6712 for (i
= 0; i
< lasti
+ 1; i
++) {
6713 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6716 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6717 alu
.op
= ALU_OP3_CNDE_INT
;
6718 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6719 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6720 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6721 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6727 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6734 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
6736 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6737 static const unsigned int src0_swizzle
[] = {2, 0, 1};
6738 static const unsigned int src1_swizzle
[] = {1, 2, 0};
6739 struct r600_bytecode_alu alu
;
6740 uint32_t use_temp
= 0;
6743 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
6746 for (i
= 0; i
< 4; i
++) {
6747 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6748 alu
.op
= ALU_OP2_MUL
;
6750 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
6751 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
6753 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6754 alu
.src
[0].chan
= i
;
6755 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6756 alu
.src
[1].chan
= i
;
6759 alu
.dst
.sel
= ctx
->temp_reg
;
6765 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6770 for (i
= 0; i
< 4; i
++) {
6771 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6772 alu
.op
= ALU_OP3_MULADD
;
6775 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
6776 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
6778 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6779 alu
.src
[0].chan
= i
;
6780 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6781 alu
.src
[1].chan
= i
;
6784 alu
.src
[2].sel
= ctx
->temp_reg
;
6786 alu
.src
[2].chan
= i
;
6789 alu
.dst
.sel
= ctx
->temp_reg
;
6791 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6797 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6802 return tgsi_helper_copy(ctx
, inst
);
6806 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
6808 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6809 struct r600_bytecode_alu alu
;
6813 /* result.x = 2^floor(src); */
6814 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
6815 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6817 alu
.op
= ALU_OP1_FLOOR
;
6818 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6820 alu
.dst
.sel
= ctx
->temp_reg
;
6824 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6828 if (ctx
->bc
->chip_class
== CAYMAN
) {
6829 for (i
= 0; i
< 3; i
++) {
6830 alu
.op
= ALU_OP1_EXP_IEEE
;
6831 alu
.src
[0].sel
= ctx
->temp_reg
;
6832 alu
.src
[0].chan
= 0;
6834 alu
.dst
.sel
= ctx
->temp_reg
;
6836 alu
.dst
.write
= i
== 0;
6838 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6843 alu
.op
= ALU_OP1_EXP_IEEE
;
6844 alu
.src
[0].sel
= ctx
->temp_reg
;
6845 alu
.src
[0].chan
= 0;
6847 alu
.dst
.sel
= ctx
->temp_reg
;
6851 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6857 /* result.y = tmp - floor(tmp); */
6858 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
6859 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6861 alu
.op
= ALU_OP1_FRACT
;
6862 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6864 alu
.dst
.sel
= ctx
->temp_reg
;
6866 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6875 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6880 /* result.z = RoughApprox2ToX(tmp);*/
6881 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
6882 if (ctx
->bc
->chip_class
== CAYMAN
) {
6883 for (i
= 0; i
< 3; i
++) {
6884 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6885 alu
.op
= ALU_OP1_EXP_IEEE
;
6886 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6888 alu
.dst
.sel
= ctx
->temp_reg
;
6895 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6901 alu
.op
= ALU_OP1_EXP_IEEE
;
6902 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6904 alu
.dst
.sel
= ctx
->temp_reg
;
6910 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6916 /* result.w = 1.0;*/
6917 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
6918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6920 alu
.op
= ALU_OP1_MOV
;
6921 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6922 alu
.src
[0].chan
= 0;
6924 alu
.dst
.sel
= ctx
->temp_reg
;
6928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6932 return tgsi_helper_copy(ctx
, inst
);
6935 static int tgsi_log(struct r600_shader_ctx
*ctx
)
6937 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6938 struct r600_bytecode_alu alu
;
6942 /* result.x = floor(log2(|src|)); */
6943 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
6944 if (ctx
->bc
->chip_class
== CAYMAN
) {
6945 for (i
= 0; i
< 3; i
++) {
6946 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6948 alu
.op
= ALU_OP1_LOG_IEEE
;
6949 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6950 r600_bytecode_src_set_abs(&alu
.src
[0]);
6952 alu
.dst
.sel
= ctx
->temp_reg
;
6958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6964 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6966 alu
.op
= ALU_OP1_LOG_IEEE
;
6967 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
6968 r600_bytecode_src_set_abs(&alu
.src
[0]);
6970 alu
.dst
.sel
= ctx
->temp_reg
;
6974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6979 alu
.op
= ALU_OP1_FLOOR
;
6980 alu
.src
[0].sel
= ctx
->temp_reg
;
6981 alu
.src
[0].chan
= 0;
6983 alu
.dst
.sel
= ctx
->temp_reg
;
6988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6993 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
6994 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
6996 if (ctx
->bc
->chip_class
== CAYMAN
) {
6997 for (i
= 0; i
< 3; i
++) {
6998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7000 alu
.op
= ALU_OP1_LOG_IEEE
;
7001 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7002 r600_bytecode_src_set_abs(&alu
.src
[0]);
7004 alu
.dst
.sel
= ctx
->temp_reg
;
7011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7016 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7018 alu
.op
= ALU_OP1_LOG_IEEE
;
7019 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7020 r600_bytecode_src_set_abs(&alu
.src
[0]);
7022 alu
.dst
.sel
= ctx
->temp_reg
;
7027 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7034 alu
.op
= ALU_OP1_FLOOR
;
7035 alu
.src
[0].sel
= ctx
->temp_reg
;
7036 alu
.src
[0].chan
= 1;
7038 alu
.dst
.sel
= ctx
->temp_reg
;
7043 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7047 if (ctx
->bc
->chip_class
== CAYMAN
) {
7048 for (i
= 0; i
< 3; i
++) {
7049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7050 alu
.op
= ALU_OP1_EXP_IEEE
;
7051 alu
.src
[0].sel
= ctx
->temp_reg
;
7052 alu
.src
[0].chan
= 1;
7054 alu
.dst
.sel
= ctx
->temp_reg
;
7061 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7066 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7067 alu
.op
= ALU_OP1_EXP_IEEE
;
7068 alu
.src
[0].sel
= ctx
->temp_reg
;
7069 alu
.src
[0].chan
= 1;
7071 alu
.dst
.sel
= ctx
->temp_reg
;
7076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7081 if (ctx
->bc
->chip_class
== CAYMAN
) {
7082 for (i
= 0; i
< 3; i
++) {
7083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7084 alu
.op
= ALU_OP1_RECIP_IEEE
;
7085 alu
.src
[0].sel
= ctx
->temp_reg
;
7086 alu
.src
[0].chan
= 1;
7088 alu
.dst
.sel
= ctx
->temp_reg
;
7095 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7100 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7101 alu
.op
= ALU_OP1_RECIP_IEEE
;
7102 alu
.src
[0].sel
= ctx
->temp_reg
;
7103 alu
.src
[0].chan
= 1;
7105 alu
.dst
.sel
= ctx
->temp_reg
;
7110 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7115 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7117 alu
.op
= ALU_OP2_MUL
;
7119 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7120 r600_bytecode_src_set_abs(&alu
.src
[0]);
7122 alu
.src
[1].sel
= ctx
->temp_reg
;
7123 alu
.src
[1].chan
= 1;
7125 alu
.dst
.sel
= ctx
->temp_reg
;
7130 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7135 /* result.z = log2(|src|);*/
7136 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
7137 if (ctx
->bc
->chip_class
== CAYMAN
) {
7138 for (i
= 0; i
< 3; i
++) {
7139 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7141 alu
.op
= ALU_OP1_LOG_IEEE
;
7142 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7143 r600_bytecode_src_set_abs(&alu
.src
[0]);
7145 alu
.dst
.sel
= ctx
->temp_reg
;
7152 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7157 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7159 alu
.op
= ALU_OP1_LOG_IEEE
;
7160 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7161 r600_bytecode_src_set_abs(&alu
.src
[0]);
7163 alu
.dst
.sel
= ctx
->temp_reg
;
7168 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7174 /* result.w = 1.0; */
7175 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
7176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7178 alu
.op
= ALU_OP1_MOV
;
7179 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7180 alu
.src
[0].chan
= 0;
7182 alu
.dst
.sel
= ctx
->temp_reg
;
7187 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7192 return tgsi_helper_copy(ctx
, inst
);
7195 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
7197 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7198 struct r600_bytecode_alu alu
;
7200 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7201 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
7203 assert(inst
->Dst
[0].Register
.Index
< 3);
7204 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7206 switch (inst
->Instruction
.Opcode
) {
7207 case TGSI_OPCODE_ARL
:
7208 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
7210 case TGSI_OPCODE_ARR
:
7211 alu
.op
= ALU_OP1_FLT_TO_INT
;
7213 case TGSI_OPCODE_UARL
:
7214 alu
.op
= ALU_OP1_MOV
;
7221 for (i
= 0; i
<= lasti
; ++i
) {
7222 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7224 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7225 alu
.last
= i
== lasti
;
7229 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7234 if (inst
->Dst
[0].Register
.Index
> 0)
7235 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
7237 ctx
->bc
->ar_loaded
= 0;
7241 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
7243 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7244 struct r600_bytecode_alu alu
;
7246 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7248 switch (inst
->Instruction
.Opcode
) {
7249 case TGSI_OPCODE_ARL
:
7250 memset(&alu
, 0, sizeof(alu
));
7251 alu
.op
= ALU_OP1_FLOOR
;
7252 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7254 for (i
= 0; i
<= lasti
; ++i
) {
7255 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
7257 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7258 alu
.last
= i
== lasti
;
7259 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7264 memset(&alu
, 0, sizeof(alu
));
7265 alu
.op
= ALU_OP1_FLT_TO_INT
;
7266 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
7267 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7269 /* FLT_TO_INT is trans-only on r600/r700 */
7271 for (i
= 0; i
<= lasti
; ++i
) {
7273 alu
.src
[0].chan
= i
;
7274 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7278 case TGSI_OPCODE_ARR
:
7279 memset(&alu
, 0, sizeof(alu
));
7280 alu
.op
= ALU_OP1_FLT_TO_INT
;
7281 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7283 /* FLT_TO_INT is trans-only on r600/r700 */
7285 for (i
= 0; i
<= lasti
; ++i
) {
7286 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
7288 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7289 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7294 case TGSI_OPCODE_UARL
:
7295 memset(&alu
, 0, sizeof(alu
));
7296 alu
.op
= ALU_OP1_MOV
;
7297 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
7299 for (i
= 0; i
<= lasti
; ++i
) {
7300 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
7302 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7303 alu
.last
= i
== lasti
;
7304 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
7314 ctx
->bc
->ar_loaded
= 0;
7318 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
7320 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7321 struct r600_bytecode_alu alu
;
7324 for (i
= 0; i
< 4; i
++) {
7325 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7327 alu
.op
= ALU_OP2_MUL
;
7328 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7330 if (i
== 0 || i
== 3) {
7331 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7333 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7336 if (i
== 0 || i
== 2) {
7337 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
7339 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
7343 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7350 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
7352 struct r600_bytecode_alu alu
;
7355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7357 alu
.execute_mask
= 1;
7358 alu
.update_pred
= 1;
7360 alu
.dst
.sel
= ctx
->temp_reg
;
7364 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7365 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7366 alu
.src
[1].chan
= 0;
7370 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
7376 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
7378 unsigned force_pop
= ctx
->bc
->force_add_cf
;
7382 if (ctx
->bc
->cf_last
) {
7383 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
7385 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
7390 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
7391 ctx
->bc
->force_add_cf
= 1;
7392 } else if (alu_pop
== 2) {
7393 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
7394 ctx
->bc
->force_add_cf
= 1;
7401 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
7402 ctx
->bc
->cf_last
->pop_count
= pops
;
7403 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7409 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
7412 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
7413 unsigned elements
, entries
;
7415 unsigned entry_size
= stack
->entry_size
;
7417 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
7418 elements
+= stack
->push
;
7420 switch (ctx
->bc
->chip_class
) {
7423 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
7424 * the stack must be reserved to hold the current active/continue
7426 if (reason
== FC_PUSH_VPM
) {
7432 /* r9xx: any stack operation on empty stack consumes 2 additional
7437 /* FIXME: do the two elements added above cover the cases for the
7441 /* r8xx+: 2 extra elements are not always required, but one extra
7442 * element must be added for each of the following cases:
7443 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
7445 * (Currently we don't use ALU_ELSE_AFTER.)
7446 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
7447 * PUSH instruction executed.
7449 * NOTE: it seems we also need to reserve additional element in some
7450 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
7451 * then STACK_SIZE should be 2 instead of 1 */
7452 if (reason
== FC_PUSH_VPM
) {
7462 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
7463 * for all chips, so we use 4 in the final formula, not the real entry_size
7467 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
7469 if (entries
> stack
->max_entries
)
7470 stack
->max_entries
= entries
;
7473 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
7477 --ctx
->bc
->stack
.push
;
7478 assert(ctx
->bc
->stack
.push
>= 0);
7481 --ctx
->bc
->stack
.push_wqm
;
7482 assert(ctx
->bc
->stack
.push_wqm
>= 0);
7485 --ctx
->bc
->stack
.loop
;
7486 assert(ctx
->bc
->stack
.loop
>= 0);
7494 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
7498 ++ctx
->bc
->stack
.push
;
7501 ++ctx
->bc
->stack
.push_wqm
;
7503 ++ctx
->bc
->stack
.loop
;
7509 callstack_update_max_depth(ctx
, reason
);
7512 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
7514 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
7516 sp
->mid
= realloc((void *)sp
->mid
,
7517 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
7518 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
7522 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
7525 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
7526 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
7529 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
7531 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
7541 static int emit_return(struct r600_shader_ctx
*ctx
)
7543 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
7547 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
7550 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
7551 ctx
->bc
->cf_last
->pop_count
= pops
;
7552 /* XXX work out offset */
7556 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
7561 static void emit_testflag(struct r600_shader_ctx
*ctx
)
7566 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
7569 emit_jump_to_offset(ctx
, 1, 4);
7570 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
7571 pops(ctx
, ifidx
+ 1);
7575 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
7579 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
7580 ctx
->bc
->cf_last
->pop_count
= 1;
7582 fc_set_mid(ctx
, fc_sp
);
7588 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
7590 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
7592 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
7593 * LOOP_STARTxxx for nested loops may put the branch stack into a state
7594 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
7595 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
7596 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
7597 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
7598 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7599 alu_type
= CF_OP_ALU
;
7602 emit_logic_pred(ctx
, opcode
, alu_type
);
7604 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
7606 fc_pushlevel(ctx
, FC_IF
);
7608 callstack_push(ctx
, FC_PUSH_VPM
);
7612 static int tgsi_if(struct r600_shader_ctx
*ctx
)
7614 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
7617 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
7619 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
7622 static int tgsi_else(struct r600_shader_ctx
*ctx
)
7624 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
7625 ctx
->bc
->cf_last
->pop_count
= 1;
7627 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
7628 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
7632 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
7635 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
7636 R600_ERR("if/endif unbalanced in shader\n");
7640 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
7641 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7642 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
7644 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7648 callstack_pop(ctx
, FC_PUSH_VPM
);
7652 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
7654 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
7655 * limited to 4096 iterations, like the other LOOP_* instructions. */
7656 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
7658 fc_pushlevel(ctx
, FC_LOOP
);
7660 /* check stack depth */
7661 callstack_push(ctx
, FC_LOOP
);
7665 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
7669 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
7671 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
7672 R600_ERR("loop/endloop in shader code are not paired.\n");
7676 /* fixup loop pointers - from r600isa
7677 LOOP END points to CF after LOOP START,
7678 LOOP START point to CF after LOOP END
7679 BRK/CONT point to LOOP END CF
7681 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
7683 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
7685 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
7686 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
7688 /* XXX add LOOPRET support */
7690 callstack_pop(ctx
, FC_LOOP
);
7694 static int tgsi_loop_breakc(struct r600_shader_ctx
*ctx
)
7699 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
7701 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
7705 R600_ERR("BREAKC not inside loop/endloop pair\n");
7709 if (ctx
->bc
->chip_class
== EVERGREEN
&&
7710 ctx
->bc
->family
!= CHIP_CYPRESS
&&
7711 ctx
->bc
->family
!= CHIP_JUNIPER
) {
7712 /* HW bug: ALU_BREAK does not save the active mask correctly */
7717 r
= r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_BREAK
);
7720 fc_set_mid(ctx
, fscp
);
7722 return tgsi_endif(ctx
);
7724 r
= emit_logic_pred(ctx
, ALU_OP2_PRED_SETE_INT
, CF_OP_ALU_BREAK
);
7727 fc_set_mid(ctx
, fscp
);
7733 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
7737 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
7739 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
7744 R600_ERR("Break not inside loop/endloop pair\n");
7748 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
7750 fc_set_mid(ctx
, fscp
);
7755 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
7757 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7758 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
7761 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
7762 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
7764 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
7766 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
7770 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
7772 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7773 struct r600_bytecode_alu alu
;
7775 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7778 for (i
= 0; i
< lasti
+ 1; i
++) {
7779 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7782 if (ctx
->bc
->chip_class
== CAYMAN
) {
7783 for (j
= 0 ; j
< 4; j
++) {
7784 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7786 alu
.op
= ALU_OP2_MULLO_UINT
;
7787 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
7788 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
7791 alu
.dst
.sel
= ctx
->temp_reg
;
7792 alu
.dst
.write
= (j
== i
);
7795 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7800 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7803 alu
.dst
.sel
= ctx
->temp_reg
;
7806 alu
.op
= ALU_OP2_MULLO_UINT
;
7807 for (j
= 0; j
< 2; j
++) {
7808 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
7812 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7819 for (i
= 0; i
< lasti
+ 1; i
++) {
7820 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7823 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7824 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7826 alu
.op
= ALU_OP2_ADD_INT
;
7828 alu
.src
[0].sel
= ctx
->temp_reg
;
7829 alu
.src
[0].chan
= i
;
7831 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7842 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
7843 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
7844 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
7845 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
7848 * For state trackers other than OpenGL, we'll want to use
7849 * _RECIP_IEEE instead.
7851 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
7853 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
7854 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
7855 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
7856 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
7857 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
7858 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
7859 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
7860 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
7861 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
7862 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
7863 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
7864 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
7865 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
7866 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
7867 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
7868 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7869 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
7870 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7871 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
7872 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
7873 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
7874 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7875 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
7876 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
7877 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
7878 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
7879 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
7880 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
7881 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
7882 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
7883 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
7884 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
7885 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
7886 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
7887 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
7888 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
7889 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7890 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7891 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7892 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7893 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
7894 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
7895 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
7896 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
7897 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
7898 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
7899 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
7900 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
7901 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
7902 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
7903 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
7904 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7905 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7906 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7907 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7908 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
7909 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
7910 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
7911 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
7912 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7913 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7914 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
7915 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
7916 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
7917 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
7918 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
7919 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7920 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
7921 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
7922 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
7923 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
7924 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
7925 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
7926 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
7927 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
7928 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7929 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7930 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7931 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7932 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
7933 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
7934 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
7935 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
7936 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
7937 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
7938 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
7939 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
7940 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
7941 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
7942 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7943 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
7944 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
7945 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
7946 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
7947 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
7948 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
7949 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7950 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
7951 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7952 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
7953 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
7954 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
7955 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
7956 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7957 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
7958 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
7959 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
7960 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
7961 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
7962 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7963 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
7964 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_loop_breakc
},
7965 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
7966 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
7967 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
7968 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
7969 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
7970 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
7971 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
7972 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
7973 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
7974 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
7975 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
7976 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
7977 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
7978 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
7979 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
7980 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
7981 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
7982 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
7983 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
7984 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
7985 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
7986 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
7987 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
7988 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
7989 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
7990 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7991 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7992 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7993 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
7994 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
7995 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
7996 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
7997 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
7998 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
7999 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
8000 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
8001 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
8002 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
8003 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
8004 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
8005 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
8006 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
8007 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
8008 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
8009 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
8010 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8011 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8012 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8013 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8014 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8015 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8016 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8017 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8018 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8019 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8020 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8021 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8022 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8023 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8024 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8025 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8026 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8027 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8028 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8029 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
8030 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
8031 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
8032 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
8033 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
8034 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
8035 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8036 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
8037 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
8038 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
8039 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
8040 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
8041 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8042 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8043 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8044 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8047 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
8048 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8049 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
8050 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
8051 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
8052 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
8053 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
8054 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
8055 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
8056 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
8057 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
8058 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
8059 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
8060 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
8061 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
8062 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
8063 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
8064 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
8065 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
8066 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
8067 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8068 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
8069 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8070 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
8071 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
8072 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
8073 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8074 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
8075 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
8076 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
8077 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
8078 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
8079 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
8080 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
8081 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
8082 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
8083 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
8084 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
8085 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8086 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8087 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
8088 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8089 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8090 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8091 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8092 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
8093 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
8094 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
8095 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
8096 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
8097 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
8098 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
8099 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
8100 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8101 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
8102 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8103 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8104 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8105 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8106 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8107 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
8108 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
8109 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8110 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
8111 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8112 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8113 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
8114 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
8115 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
8116 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8117 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
8118 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8119 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
8120 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8121 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
8122 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
8123 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
8124 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
8125 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
8126 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
8127 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8128 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8129 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8130 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8131 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
8132 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
8133 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
8134 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
8135 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
8136 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
8137 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
8138 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
8139 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
8140 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
8141 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8142 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
8143 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8144 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
8145 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
8146 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
8147 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
8148 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8149 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
8150 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8151 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8152 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
8153 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
8154 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
8155 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8156 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
8157 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
8158 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
8159 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
8160 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
8161 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8162 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
8163 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8164 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
8165 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
8166 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
8167 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
8168 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
8169 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
8170 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
8171 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
8172 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
8173 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
8174 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
8175 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
8176 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
8177 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
8178 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
8179 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
8180 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
8181 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
8182 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
8183 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
8184 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
8185 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
8186 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
8187 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
8188 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
8189 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8190 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8191 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8192 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8193 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
8194 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
8195 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
8196 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
8197 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
8198 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
8199 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
8200 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
8201 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
8202 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
8203 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
8204 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
8205 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
8206 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
8207 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
8208 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
8209 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8210 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8211 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8212 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8213 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8214 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8215 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8216 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8217 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8218 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8219 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8220 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8221 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8222 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8223 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8224 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8225 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8226 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8227 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8228 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
8229 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
8230 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
8231 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
8232 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_op3
},
8233 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_op3
},
8234 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
8235 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
8236 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
8237 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
8238 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
8239 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
8240 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8241 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8242 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8243 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
8244 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
8245 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
8246 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
8247 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
8248 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
8249 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
8250 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
8251 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
8252 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
8253 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
8254 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
8255 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
8256 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
8257 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
8258 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
8259 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
8260 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
8261 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
8262 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
8263 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
8264 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
8265 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
8266 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8269 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
8270 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8271 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
8272 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
8273 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
8274 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
8275 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
8276 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
8277 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
8278 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
8279 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
8280 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
8281 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
8282 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
8283 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
8284 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
8285 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
8286 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
8287 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
8288 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
8289 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8290 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
8291 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8292 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
8293 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
8294 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
8295 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8296 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
8297 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
8298 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
8299 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
8300 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
8301 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
8302 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
8303 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
8304 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
8305 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
8306 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
8307 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8308 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8309 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
8310 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8311 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8312 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8313 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8314 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
8315 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
8316 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
8317 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
8318 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
8319 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
8320 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
8321 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
8322 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8323 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
8324 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8325 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8326 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8327 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8328 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8329 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
8330 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
8331 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
8332 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
8333 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8334 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8335 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
8336 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
8337 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
8338 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8339 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
8340 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8341 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
8342 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8343 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
8344 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
8345 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
8346 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
8347 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
8348 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
8349 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
8350 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
8351 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8352 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8353 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
8354 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
8355 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
8356 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
8357 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
8358 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
8359 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
8360 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
8361 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
8362 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
8363 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8364 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
8365 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8366 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
8367 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
8368 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
8369 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
8370 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8371 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
8372 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8373 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
8374 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
8375 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
8376 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
8377 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8378 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
8379 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
8380 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
8381 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
8382 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
8383 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8384 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
8385 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8386 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
8387 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
8388 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
8389 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
8390 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
8391 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
8392 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
8393 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
8394 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
8395 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
8396 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
8397 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
8398 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
8399 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
8400 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
8401 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
8402 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
8403 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
8404 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
8405 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
8406 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
8407 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
8408 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
8409 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
8410 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
8411 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8412 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8413 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8414 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8415 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
8416 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
8417 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
8418 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
8419 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
8420 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
8421 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
8422 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
8423 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
8424 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
8425 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
8426 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
8427 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
8428 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
8429 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
8430 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
8431 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8432 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8433 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8434 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8435 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8436 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8437 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8438 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8439 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8440 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8441 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8442 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8443 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8444 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8445 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8446 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8447 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
8448 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
8449 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
8450 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
8451 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
8452 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
8453 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
8454 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_op3
},
8455 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_op3
},
8456 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
8457 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
8458 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
8459 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
8460 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
8461 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
8462 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8463 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8464 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
8465 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
8466 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
8467 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
8468 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
8469 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
8470 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
8471 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
8472 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
8473 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
8474 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
8475 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
8476 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
8477 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
8478 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
8479 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
8480 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
8481 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
8482 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
8483 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
8484 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
8485 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
8486 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
8487 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
8488 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},