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_formats.h"
25 #include "r600_opcodes.h"
26 #include "r600_shader.h"
29 #include "sb/sb_public.h"
31 #include "pipe/p_shader_tokens.h"
32 #include "tgsi/tgsi_info.h"
33 #include "tgsi/tgsi_parse.h"
34 #include "tgsi/tgsi_scan.h"
35 #include "tgsi/tgsi_dump.h"
36 #include "util/u_bitcast.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 /* Contents of r0 on entry to various shaders
69 GS - r0.xyw, r1.xyz = per-vertex offsets
75 .w = tess factor base.
77 TES - .x = TessCoord.x
79 - .z = RelPatchID (??)
82 PS - face_gpr.z = SampleMask
85 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
86 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
87 struct r600_pipe_shader
*pipeshader
,
88 union r600_shader_key key
);
90 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
91 int size
, unsigned comp_mask
) {
96 if (ps
->num_arrays
== ps
->max_arrays
) {
98 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
99 sizeof(struct r600_shader_array
));
102 int n
= ps
->num_arrays
;
105 ps
->arrays
[n
].comp_mask
= comp_mask
;
106 ps
->arrays
[n
].gpr_start
= start_gpr
;
107 ps
->arrays
[n
].gpr_count
= size
;
110 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
114 fprintf(stderr
, "STREAMOUT\n");
115 for (i
= 0; i
< so
->num_outputs
; i
++) {
116 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
117 so
->output
[i
].start_component
;
118 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
120 so
->output
[i
].stream
,
121 so
->output
[i
].output_buffer
,
122 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
123 so
->output
[i
].register_index
,
128 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
132 static int store_shader(struct pipe_context
*ctx
,
133 struct r600_pipe_shader
*shader
)
135 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 if (shader
->bo
== NULL
) {
139 shader
->bo
= (struct r600_resource
*)
140 pipe_buffer_create(ctx
->screen
, 0, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
141 if (shader
->bo
== NULL
) {
144 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
145 if (R600_BIG_ENDIAN
) {
146 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
147 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
150 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
152 rctx
->b
.ws
->buffer_unmap(shader
->bo
->buf
);
158 int r600_pipe_shader_create(struct pipe_context
*ctx
,
159 struct r600_pipe_shader
*shader
,
160 union r600_shader_key key
)
162 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
163 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
165 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
,
166 tgsi_get_processor_type(sel
->tokens
));
167 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
168 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
169 unsigned export_shader
;
171 shader
->shader
.bc
.isa
= rctx
->isa
;
174 fprintf(stderr
, "--------------------------------------------------------------\n");
175 tgsi_dump(sel
->tokens
, 0);
177 if (sel
->so
.num_outputs
) {
178 r600_dump_streamout(&sel
->so
);
181 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
183 R600_ERR("translation from TGSI failed !\n");
186 if (shader
->shader
.processor_type
== PIPE_SHADER_VERTEX
) {
187 /* only disable for vertex shaders in tess paths */
191 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_CTRL
);
192 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_EVAL
);
194 /* disable SB for shaders using doubles */
195 use_sb
&= !shader
->shader
.uses_doubles
;
197 use_sb
&= !shader
->shader
.uses_atomics
;
199 /* Check if the bytecode has already been built. */
200 if (!shader
->shader
.bc
.bytecode
) {
201 r
= r600_bytecode_build(&shader
->shader
.bc
);
203 R600_ERR("building bytecode failed !\n");
208 if (dump
&& !sb_disasm
) {
209 fprintf(stderr
, "--------------------------------------------------------------\n");
210 r600_bytecode_disasm(&shader
->shader
.bc
);
211 fprintf(stderr
, "______________________________________________________________\n");
212 } else if ((dump
&& sb_disasm
) || use_sb
) {
213 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
216 R600_ERR("r600_sb_bytecode_process failed !\n");
221 if (shader
->gs_copy_shader
) {
224 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
225 &shader
->gs_copy_shader
->shader
, dump
, 0);
230 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
234 /* Store the shader in a buffer. */
235 if ((r
= store_shader(ctx
, shader
)))
239 switch (shader
->shader
.processor_type
) {
240 case PIPE_SHADER_TESS_CTRL
:
241 evergreen_update_hs_state(ctx
, shader
);
243 case PIPE_SHADER_TESS_EVAL
:
245 evergreen_update_es_state(ctx
, shader
);
247 evergreen_update_vs_state(ctx
, shader
);
249 case PIPE_SHADER_GEOMETRY
:
250 if (rctx
->b
.chip_class
>= EVERGREEN
) {
251 evergreen_update_gs_state(ctx
, shader
);
252 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
254 r600_update_gs_state(ctx
, shader
);
255 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
258 case PIPE_SHADER_VERTEX
:
259 export_shader
= key
.vs
.as_es
;
260 if (rctx
->b
.chip_class
>= EVERGREEN
) {
262 evergreen_update_ls_state(ctx
, shader
);
263 else if (key
.vs
.as_es
)
264 evergreen_update_es_state(ctx
, shader
);
266 evergreen_update_vs_state(ctx
, shader
);
269 r600_update_es_state(ctx
, shader
);
271 r600_update_vs_state(ctx
, shader
);
274 case PIPE_SHADER_FRAGMENT
:
275 if (rctx
->b
.chip_class
>= EVERGREEN
) {
276 evergreen_update_ps_state(ctx
, shader
);
278 r600_update_ps_state(ctx
, shader
);
288 r600_pipe_shader_destroy(ctx
, shader
);
292 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
294 r600_resource_reference(&shader
->bo
, NULL
);
295 r600_bytecode_clear(&shader
->shader
.bc
);
296 r600_release_command_buffer(&shader
->command_buffer
);
300 * tgsi -> r600 shader
302 struct r600_shader_tgsi_instruction
;
304 struct r600_shader_src
{
311 boolean kc_rel
; /* true if cache bank is indexed */
320 struct r600_shader_ctx
{
321 struct tgsi_shader_info info
;
322 struct tgsi_parse_context parse
;
323 const struct tgsi_token
*tokens
;
325 unsigned file_offset
[TGSI_FILE_COUNT
];
327 const struct r600_shader_tgsi_instruction
*inst_info
;
328 struct r600_bytecode
*bc
;
329 struct r600_shader
*shader
;
330 struct r600_shader_src src
[4];
333 uint32_t max_driver_temp_used
;
334 /* needed for evergreen interpolation */
335 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
336 /* evergreen/cayman also store sample mask in face register */
338 /* sample id is .w component stored in fixed point position register */
339 int fixed_pt_position_gpr
;
341 boolean clip_vertex_write
;
343 unsigned edgeflag_output
;
346 int next_ring_offset
;
347 int gs_out_ring_offset
;
349 struct r600_shader
*gs_for_vs
;
350 int gs_export_gpr_tregs
[4];
351 int gs_rotated_input
[2];
352 const struct pipe_stream_output_info
*gs_stream_output_info
;
353 unsigned enabled_stream_buffers_mask
;
354 unsigned tess_input_info
; /* temp with tess input offsets */
355 unsigned tess_output_info
; /* temp with tess input offsets */
358 struct r600_shader_tgsi_instruction
{
360 int (*process
)(struct r600_shader_ctx
*ctx
);
363 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
364 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
365 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
366 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
367 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
368 static int tgsi_else(struct r600_shader_ctx
*ctx
);
369 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
370 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
371 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
372 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
373 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
374 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
375 unsigned int dst_reg
);
376 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
377 const struct r600_shader_src
*shader_src
,
379 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
382 static int tgsi_last_instruction(unsigned writemask
)
386 for (i
= 0; i
< 4; i
++) {
387 if (writemask
& (1 << i
)) {
394 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
396 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
399 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
400 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
404 if (i
->Instruction
.Label
) {
405 R600_ERR("label unsupported\n");
409 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
410 if (i
->Src
[j
].Register
.Dimension
) {
411 switch (i
->Src
[j
].Register
.File
) {
412 case TGSI_FILE_CONSTANT
:
413 case TGSI_FILE_HW_ATOMIC
:
415 case TGSI_FILE_INPUT
:
416 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
417 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
418 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
420 case TGSI_FILE_OUTPUT
:
421 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
424 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
425 i
->Src
[j
].Register
.File
,
426 i
->Src
[j
].Register
.Dimension
);
431 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
432 if (i
->Dst
[j
].Register
.Dimension
) {
433 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
435 R600_ERR("unsupported dst (dimension)\n");
442 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
444 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
445 interpolate
== TGSI_INTERPOLATE_LINEAR
||
446 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
448 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
452 case TGSI_INTERPOLATE_LOC_CENTER
:
455 case TGSI_INTERPOLATE_LOC_CENTROID
:
458 case TGSI_INTERPOLATE_LOC_SAMPLE
:
463 return is_linear
* 3 + loc
;
469 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
472 int i
= eg_get_interpolator_index(
473 ctx
->shader
->input
[input
].interpolate
,
474 ctx
->shader
->input
[input
].interpolate_location
);
476 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
479 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
482 struct r600_bytecode_alu alu
;
483 int gpr
= 0, base_chan
= 0;
484 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
486 /* work out gpr and base_chan from index */
488 base_chan
= (2 * (ij_index
% 2)) + 1;
490 for (i
= 0; i
< 8; i
++) {
491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
494 alu
.op
= ALU_OP2_INTERP_ZW
;
496 alu
.op
= ALU_OP2_INTERP_XY
;
498 if ((i
> 1) && (i
< 6)) {
499 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
503 alu
.dst
.chan
= i
% 4;
505 alu
.src
[0].sel
= gpr
;
506 alu
.src
[0].chan
= (base_chan
- (i
% 2));
508 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
510 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
513 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
520 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
523 struct r600_bytecode_alu alu
;
525 for (i
= 0; i
< 4; i
++) {
526 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
528 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
530 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
535 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
540 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
548 * Special export handling in shaders
550 * shader export ARRAY_BASE for EXPORT_POS:
553 * 62, 63 are clip distance vectors
555 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
556 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
557 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
558 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
559 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
560 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
561 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
562 * exclusive from render target index)
563 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
566 * shader export ARRAY_BASE for EXPORT_PIXEL:
568 * 61 computed Z vector
570 * The use of the values exported in the computed Z vector are controlled
571 * by DB_SHADER_CONTROL:
572 * Z_EXPORT_ENABLE - Z as a float in RED
573 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
574 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
575 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
576 * DB_SOURCE_FORMAT - export control restrictions
581 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
582 static int r600_spi_sid(struct r600_shader_io
* io
)
584 int index
, name
= io
->name
;
586 /* These params are handled differently, they don't need
587 * semantic indices, so we'll use 0 for them.
589 if (name
== TGSI_SEMANTIC_POSITION
||
590 name
== TGSI_SEMANTIC_PSIZE
||
591 name
== TGSI_SEMANTIC_EDGEFLAG
||
592 name
== TGSI_SEMANTIC_FACE
||
593 name
== TGSI_SEMANTIC_SAMPLEMASK
)
596 if (name
== TGSI_SEMANTIC_GENERIC
) {
597 /* For generic params simply use sid from tgsi */
600 /* For non-generic params - pack name and sid into 8 bits */
601 index
= 0x80 | (name
<<3) | (io
->sid
);
604 /* Make sure that all really used indices have nonzero value, so
605 * we can just compare it to 0 later instead of comparing the name
606 * with different values to detect special cases. */
613 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
614 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
616 switch (semantic_name
) {
617 case TGSI_SEMANTIC_POSITION
:
619 case TGSI_SEMANTIC_PSIZE
:
621 case TGSI_SEMANTIC_CLIPDIST
:
624 case TGSI_SEMANTIC_GENERIC
:
626 return 4 + index
- 9;
628 /* same explanation as in the default statement,
629 * the only user hitting this is st/nine.
633 /* patch indices are completely separate and thus start from 0 */
634 case TGSI_SEMANTIC_TESSOUTER
:
636 case TGSI_SEMANTIC_TESSINNER
:
638 case TGSI_SEMANTIC_PATCH
:
642 /* Don't fail here. The result of this function is only used
643 * for LS, TCS, TES, and GS, where legacy GL semantics can't
644 * occur, but this function is called for all vertex shaders
645 * before it's known whether LS will be compiled or not.
651 /* turn input into interpolate on EG */
652 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
656 if (ctx
->shader
->input
[index
].spi_sid
) {
657 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
658 if (ctx
->shader
->input
[index
].interpolate
> 0) {
659 evergreen_interp_assign_ij_index(ctx
, index
);
660 r
= evergreen_interp_alu(ctx
, index
);
662 r
= evergreen_interp_flat(ctx
, index
);
668 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
670 struct r600_bytecode_alu alu
;
672 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
673 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
675 for (i
= 0; i
< 4; i
++) {
676 memset(&alu
, 0, sizeof(alu
));
677 alu
.op
= ALU_OP3_CNDGT
;
680 alu
.dst
.sel
= gpr_front
;
681 alu
.src
[0].sel
= ctx
->face_gpr
;
682 alu
.src
[1].sel
= gpr_front
;
683 alu
.src
[2].sel
= gpr_back
;
690 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
697 /* execute a single slot ALU calculation */
698 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
699 int dst_sel
, int dst_chan
,
700 int src0_sel
, unsigned src0_chan_val
,
701 int src1_sel
, unsigned src1_chan_val
)
703 struct r600_bytecode_alu alu
;
706 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
707 for (i
= 0; i
< 4; i
++) {
708 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
710 alu
.src
[0].sel
= src0_sel
;
711 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
712 alu
.src
[0].value
= src0_chan_val
;
714 alu
.src
[0].chan
= src0_chan_val
;
715 alu
.src
[1].sel
= src1_sel
;
716 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
717 alu
.src
[1].value
= src1_chan_val
;
719 alu
.src
[1].chan
= src1_chan_val
;
720 alu
.dst
.sel
= dst_sel
;
722 alu
.dst
.write
= i
== dst_chan
;
724 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
733 alu
.src
[0].sel
= src0_sel
;
734 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
735 alu
.src
[0].value
= src0_chan_val
;
737 alu
.src
[0].chan
= src0_chan_val
;
738 alu
.src
[1].sel
= src1_sel
;
739 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
740 alu
.src
[1].value
= src1_chan_val
;
742 alu
.src
[1].chan
= src1_chan_val
;
743 alu
.dst
.sel
= dst_sel
;
744 alu
.dst
.chan
= dst_chan
;
747 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
753 /* execute a single slot ALU calculation */
754 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
755 int dst_sel
, int dst_chan
,
756 int src0_sel
, unsigned src0_chan_val
,
757 int src1_sel
, unsigned src1_chan_val
,
758 int src2_sel
, unsigned src2_chan_val
)
760 struct r600_bytecode_alu alu
;
763 /* validate this for other ops */
764 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
);
765 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
767 alu
.src
[0].sel
= src0_sel
;
768 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
769 alu
.src
[0].value
= src0_chan_val
;
771 alu
.src
[0].chan
= src0_chan_val
;
772 alu
.src
[1].sel
= src1_sel
;
773 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
774 alu
.src
[1].value
= src1_chan_val
;
776 alu
.src
[1].chan
= src1_chan_val
;
777 alu
.src
[2].sel
= src2_sel
;
778 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
779 alu
.src
[2].value
= src2_chan_val
;
781 alu
.src
[2].chan
= src2_chan_val
;
782 alu
.dst
.sel
= dst_sel
;
783 alu
.dst
.chan
= dst_chan
;
786 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
792 /* put it in temp_reg.x */
793 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
795 int temp_reg
, bool is_patch_var
)
799 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
801 Dimension - patch0_offset (input_vals.z),
802 Non-dim - patch0_data_offset (input_vals.w)
804 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
806 ctx
->tess_output_info
, 0,
808 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
814 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
816 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
819 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
821 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
824 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
827 i
= ctx
->shader
->noutput
++;
828 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
829 ctx
->shader
->output
[i
].sid
= 0;
830 ctx
->shader
->output
[i
].gpr
= 0;
831 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
832 ctx
->shader
->output
[i
].write_mask
= 0x4;
833 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
838 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
840 struct r600_bytecode_alu alu
;
843 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
844 alu
.op
= ctx
->inst_info
->op
;
847 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
853 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
855 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
856 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
858 switch (d
->Declaration
.File
) {
859 case TGSI_FILE_INPUT
:
860 for (j
= 0; j
< count
; j
++) {
861 i
= ctx
->shader
->ninput
+ j
;
862 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
863 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
864 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
865 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
866 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
867 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
868 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
869 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
870 switch (ctx
->shader
->input
[i
].name
) {
871 case TGSI_SEMANTIC_FACE
:
872 if (ctx
->face_gpr
!= -1)
873 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
875 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
877 case TGSI_SEMANTIC_COLOR
:
880 case TGSI_SEMANTIC_POSITION
:
881 ctx
->fragcoord_input
= i
;
883 case TGSI_SEMANTIC_PRIMID
:
884 /* set this for now */
885 ctx
->shader
->gs_prim_id_input
= true;
886 ctx
->shader
->ps_prim_id_input
= i
;
889 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
890 if ((r
= evergreen_interp_input(ctx
, i
)))
893 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
894 /* FIXME probably skip inputs if they aren't passed in the ring */
895 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
896 ctx
->next_ring_offset
+= 16;
897 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
898 ctx
->shader
->gs_prim_id_input
= true;
901 ctx
->shader
->ninput
+= count
;
903 case TGSI_FILE_OUTPUT
:
904 for (j
= 0; j
< count
; j
++) {
905 i
= ctx
->shader
->noutput
+ j
;
906 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
907 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
908 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
909 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
910 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
911 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
912 if (ctx
->type
== PIPE_SHADER_VERTEX
||
913 ctx
->type
== PIPE_SHADER_GEOMETRY
||
914 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
915 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
916 switch (d
->Semantic
.Name
) {
917 case TGSI_SEMANTIC_CLIPDIST
:
918 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<<
919 ((d
->Semantic
.Index
+ j
) << 2);
921 case TGSI_SEMANTIC_PSIZE
:
922 ctx
->shader
->vs_out_misc_write
= 1;
923 ctx
->shader
->vs_out_point_size
= 1;
925 case TGSI_SEMANTIC_EDGEFLAG
:
926 ctx
->shader
->vs_out_misc_write
= 1;
927 ctx
->shader
->vs_out_edgeflag
= 1;
928 ctx
->edgeflag_output
= i
;
930 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
931 ctx
->shader
->vs_out_misc_write
= 1;
932 ctx
->shader
->vs_out_viewport
= 1;
934 case TGSI_SEMANTIC_LAYER
:
935 ctx
->shader
->vs_out_misc_write
= 1;
936 ctx
->shader
->vs_out_layer
= 1;
938 case TGSI_SEMANTIC_CLIPVERTEX
:
939 ctx
->clip_vertex_write
= TRUE
;
943 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
944 ctx
->gs_out_ring_offset
+= 16;
946 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
947 switch (d
->Semantic
.Name
) {
948 case TGSI_SEMANTIC_COLOR
:
949 ctx
->shader
->nr_ps_max_color_exports
++;
954 ctx
->shader
->noutput
+= count
;
956 case TGSI_FILE_TEMPORARY
:
957 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
958 if (d
->Array
.ArrayID
) {
959 r600_add_gpr_array(ctx
->shader
,
960 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
962 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
967 case TGSI_FILE_CONSTANT
:
968 case TGSI_FILE_SAMPLER
:
969 case TGSI_FILE_SAMPLER_VIEW
:
970 case TGSI_FILE_ADDRESS
:
973 case TGSI_FILE_HW_ATOMIC
:
974 i
= ctx
->shader
->nhwatomic_ranges
;
975 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
976 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
977 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
978 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
979 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
980 ctx
->shader
->nhwatomic_ranges
++;
981 ctx
->shader
->nhwatomic
+= count
;
984 case TGSI_FILE_SYSTEM_VALUE
:
985 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
986 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
987 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
988 break; /* Already handled from allocate_system_value_inputs */
989 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
990 if (!ctx
->native_integers
) {
991 struct r600_bytecode_alu alu
;
992 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
994 alu
.op
= ALU_OP1_INT_TO_FLT
;
1003 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1007 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1009 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1011 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1012 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1013 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1014 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1015 unsigned temp_reg
= r600_get_temp(ctx
);
1017 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1021 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1024 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1028 do_lds_fetch_values(ctx
, temp_reg
, dreg
);
1030 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1034 for (i
= 0; i
< 2; i
++) {
1035 struct r600_bytecode_alu alu
;
1036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1037 alu
.op
= ALU_OP1_MOV
;
1039 alu
.src
[0].chan
= 0 + i
;
1041 alu
.dst
.chan
= 0 + i
;
1043 alu
.last
= (i
== 1) ? 1 : 0;
1044 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1047 /* ADD r1.z, 1.0f, -r0.x */
1048 struct r600_bytecode_alu alu
;
1049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1050 alu
.op
= ALU_OP2_ADD
;
1051 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1053 alu
.src
[1].chan
= 0;
1059 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1062 /* ADD r1.z, r1.z, -r1.y */
1063 alu
.op
= ALU_OP2_ADD
;
1065 alu
.src
[0].chan
= 2;
1067 alu
.src
[1].chan
= 1;
1073 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1079 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1085 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1087 struct tgsi_parse_context parse
;
1091 unsigned name
, alternate_name
;
1093 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1095 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1097 int i
, k
, num_regs
= 0;
1099 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1103 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1104 while (!tgsi_parse_end_of_tokens(&parse
)) {
1105 tgsi_parse_token(&parse
);
1107 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1108 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1109 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1110 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1111 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1113 int interpolate
, location
, k
;
1115 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1116 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1117 inputs
[1].enabled
= true; /* needs SAMPLEID */
1118 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1119 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1120 /* Needs sample positions, currently those are always available */
1122 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1125 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1126 k
= eg_get_interpolator_index(interpolate
, location
);
1128 ctx
->eg_interpolators
[k
].enabled
= true;
1130 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1131 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1132 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1133 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1134 if (d
->Semantic
.Name
== inputs
[k
].name
||
1135 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1136 inputs
[k
].enabled
= true;
1143 tgsi_parse_free(&parse
);
1145 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1146 boolean enabled
= inputs
[i
].enabled
;
1147 int *reg
= inputs
[i
].reg
;
1148 unsigned name
= inputs
[i
].name
;
1151 int gpr
= gpr_offset
+ num_regs
++;
1152 ctx
->shader
->nsys_inputs
++;
1154 // add to inputs, allocate a gpr
1155 k
= ctx
->shader
->ninput
++;
1156 ctx
->shader
->input
[k
].name
= name
;
1157 ctx
->shader
->input
[k
].sid
= 0;
1158 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1159 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1160 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1164 return gpr_offset
+ num_regs
;
1168 * for evergreen we need to scan the shader to find the number of GPRs we need to
1169 * reserve for interpolation and system values
1171 * we need to know if we are going to emit
1172 * any sample or centroid inputs
1173 * if perspective and linear are required
1175 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1179 struct tgsi_parse_context parse
;
1181 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1183 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1185 /* skip position/face/mask/sampleid */
1186 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1187 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1188 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1189 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1192 k
= eg_get_interpolator_index(
1193 ctx
->info
.input_interpolate
[i
],
1194 ctx
->info
.input_interpolate_loc
[i
]);
1196 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1199 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1203 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1204 while (!tgsi_parse_end_of_tokens(&parse
)) {
1205 tgsi_parse_token(&parse
);
1207 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1208 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1209 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1210 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1211 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1213 int interpolate
, location
, k
;
1215 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1216 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1217 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1218 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1220 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1223 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1224 k
= eg_get_interpolator_index(interpolate
, location
);
1226 ctx
->eg_interpolators
[k
].enabled
= true;
1231 tgsi_parse_free(&parse
);
1233 /* assign gpr to each interpolator according to priority */
1235 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1236 if (ctx
->eg_interpolators
[i
].enabled
) {
1237 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1242 /* XXX PULL MODEL and LINE STIPPLE */
1244 num_baryc
= (num_baryc
+ 1) >> 1;
1245 return allocate_system_value_inputs(ctx
, num_baryc
);
1248 /* sample_id_sel == NULL means fetch for current sample */
1249 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1251 struct r600_bytecode_vtx vtx
;
1254 assert(ctx
->fixed_pt_position_gpr
!= -1);
1256 t1
= r600_get_temp(ctx
);
1258 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1259 vtx
.op
= FETCH_OP_VFETCH
;
1260 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1261 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1262 if (sample_id
== NULL
) {
1263 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1267 struct r600_bytecode_alu alu
;
1269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1270 alu
.op
= ALU_OP1_MOV
;
1271 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1275 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1282 vtx
.mega_fetch_count
= 16;
1288 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1289 vtx
.num_format_all
= 2;
1290 vtx
.format_comp_all
= 1;
1291 vtx
.use_const_fields
= 0;
1292 vtx
.offset
= 1; // first element is size of buffer
1293 vtx
.endian
= r600_endian_swap(32);
1294 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1296 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1303 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1304 const struct tgsi_full_src_register
*tgsi_src
,
1305 struct r600_shader_src
*r600_src
)
1307 memset(r600_src
, 0, sizeof(*r600_src
));
1308 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1309 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1310 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1311 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1312 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1313 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1315 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1317 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1318 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1319 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1321 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1322 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1323 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1326 index
= tgsi_src
->Register
.Index
;
1327 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1328 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1329 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1330 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1331 r600_src
->swizzle
[0] = 2; // Z value
1332 r600_src
->swizzle
[1] = 2;
1333 r600_src
->swizzle
[2] = 2;
1334 r600_src
->swizzle
[3] = 2;
1335 r600_src
->sel
= ctx
->face_gpr
;
1336 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1337 r600_src
->swizzle
[0] = 3; // W value
1338 r600_src
->swizzle
[1] = 3;
1339 r600_src
->swizzle
[2] = 3;
1340 r600_src
->swizzle
[3] = 3;
1341 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1342 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1343 r600_src
->swizzle
[0] = 0;
1344 r600_src
->swizzle
[1] = 1;
1345 r600_src
->swizzle
[2] = 4;
1346 r600_src
->swizzle
[3] = 4;
1347 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1348 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1349 r600_src
->swizzle
[0] = 3;
1350 r600_src
->swizzle
[1] = 3;
1351 r600_src
->swizzle
[2] = 3;
1352 r600_src
->swizzle
[3] = 3;
1354 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1355 r600_src
->swizzle
[0] = 0;
1356 r600_src
->swizzle
[1] = 0;
1357 r600_src
->swizzle
[2] = 0;
1358 r600_src
->swizzle
[3] = 0;
1360 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1361 r600_src
->swizzle
[0] = 3;
1362 r600_src
->swizzle
[1] = 3;
1363 r600_src
->swizzle
[2] = 3;
1364 r600_src
->swizzle
[3] = 3;
1366 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1367 r600_src
->swizzle
[0] = 2;
1368 r600_src
->swizzle
[1] = 2;
1369 r600_src
->swizzle
[2] = 2;
1370 r600_src
->swizzle
[3] = 2;
1372 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1374 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1376 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1378 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1379 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1380 r600_src
->sel
= ctx
->tess_input_info
;
1381 r600_src
->swizzle
[0] = 2;
1382 r600_src
->swizzle
[1] = 2;
1383 r600_src
->swizzle
[2] = 2;
1384 r600_src
->swizzle
[3] = 2;
1386 r600_src
->sel
= ctx
->tess_input_info
;
1387 r600_src
->swizzle
[0] = 3;
1388 r600_src
->swizzle
[1] = 3;
1389 r600_src
->swizzle
[2] = 3;
1390 r600_src
->swizzle
[3] = 3;
1392 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1394 r600_src
->swizzle
[0] = 0;
1395 r600_src
->swizzle
[1] = 0;
1396 r600_src
->swizzle
[2] = 0;
1397 r600_src
->swizzle
[3] = 0;
1398 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1400 r600_src
->swizzle
[0] = 3;
1401 r600_src
->swizzle
[1] = 3;
1402 r600_src
->swizzle
[2] = 3;
1403 r600_src
->swizzle
[3] = 3;
1406 if (tgsi_src
->Register
.Indirect
)
1407 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1408 r600_src
->sel
= tgsi_src
->Register
.Index
;
1409 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1411 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1412 if (tgsi_src
->Register
.Dimension
) {
1413 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1414 if (tgsi_src
->Dimension
.Indirect
) {
1415 r600_src
->kc_rel
= 1;
1421 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1422 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1423 unsigned int dst_reg
)
1425 struct r600_bytecode_vtx vtx
;
1426 unsigned int ar_reg
;
1430 struct r600_bytecode_alu alu
;
1432 memset(&alu
, 0, sizeof(alu
));
1434 alu
.op
= ALU_OP2_ADD_INT
;
1435 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1436 alu
.src
[0].chan
= ar_chan
;
1438 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1439 alu
.src
[1].value
= offset
;
1441 alu
.dst
.sel
= dst_reg
;
1442 alu
.dst
.chan
= ar_chan
;
1446 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1451 ar_reg
= ctx
->bc
->ar_reg
;
1454 memset(&vtx
, 0, sizeof(vtx
));
1455 vtx
.buffer_id
= cb_idx
;
1456 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1457 vtx
.src_gpr
= ar_reg
;
1458 vtx
.src_sel_x
= ar_chan
;
1459 vtx
.mega_fetch_count
= 16;
1460 vtx
.dst_gpr
= dst_reg
;
1461 vtx
.dst_sel_x
= 0; /* SEL_X */
1462 vtx
.dst_sel_y
= 1; /* SEL_Y */
1463 vtx
.dst_sel_z
= 2; /* SEL_Z */
1464 vtx
.dst_sel_w
= 3; /* SEL_W */
1465 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1466 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1467 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1468 vtx
.endian
= r600_endian_swap(32);
1469 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1471 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1477 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1479 struct r600_bytecode_vtx vtx
;
1481 unsigned index
= src
->Register
.Index
;
1482 unsigned vtx_id
= src
->Dimension
.Index
;
1483 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1484 int offset_chan
= vtx_id
% 3;
1487 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1488 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1490 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1493 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1494 t2
= r600_get_temp(ctx
);
1496 if (src
->Dimension
.Indirect
) {
1498 struct r600_bytecode_alu alu
;
1501 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1502 if (src
->DimIndirect
.Index
> 0) {
1503 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1511 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1512 at least this is what fglrx seems to do. */
1513 for (i
= 0; i
< 3; i
++) {
1514 treg
[i
] = r600_get_temp(ctx
);
1516 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1518 for (i
= 0; i
< 3; i
++) {
1519 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1520 alu
.op
= ALU_OP1_MOV
;
1521 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1522 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1523 alu
.dst
.sel
= treg
[i
];
1527 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1531 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1532 alu
.op
= ALU_OP1_MOV
;
1533 alu
.src
[0].sel
= treg
[0];
1538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1545 if (src
->Register
.Indirect
) {
1547 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1549 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1551 /* pull the value from index_reg */
1552 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1555 V_SQ_ALU_SRC_LITERAL
, first
);
1558 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1561 V_SQ_ALU_SRC_LITERAL
, 4,
1562 offset_reg
, offset_chan
);
1567 index
= src
->Register
.Index
- first
;
1570 memset(&vtx
, 0, sizeof(vtx
));
1571 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1572 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1573 vtx
.src_gpr
= offset_reg
;
1574 vtx
.src_sel_x
= offset_chan
;
1575 vtx
.offset
= index
* 16; /*bytes*/
1576 vtx
.mega_fetch_count
= 16;
1577 vtx
.dst_gpr
= dst_reg
;
1578 vtx
.dst_sel_x
= 0; /* SEL_X */
1579 vtx
.dst_sel_y
= 1; /* SEL_Y */
1580 vtx
.dst_sel_z
= 2; /* SEL_Z */
1581 vtx
.dst_sel_w
= 3; /* SEL_W */
1582 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1583 vtx
.use_const_fields
= 1;
1585 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1588 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1594 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1596 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1599 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1600 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1602 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1603 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1604 /* primitive id is in R0.z */
1605 ctx
->src
[i
].sel
= 0;
1606 ctx
->src
[i
].swizzle
[0] = 2;
1609 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1610 int treg
= r600_get_temp(ctx
);
1612 fetch_gs_input(ctx
, src
, treg
);
1613 ctx
->src
[i
].sel
= treg
;
1614 ctx
->src
[i
].rel
= 0;
1621 /* Tessellation shaders pass outputs to the next shader using LDS.
1623 * LS outputs = TCS(HS) inputs
1624 * TCS(HS) outputs = TES(DS) inputs
1626 * The LDS layout is:
1627 * - TCS inputs for patch 0
1628 * - TCS inputs for patch 1
1629 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1631 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1632 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1633 * - TCS outputs for patch 1
1634 * - Per-patch TCS outputs for patch 1
1635 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1636 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1639 * All three shaders VS(LS), TCS, TES share the same LDS space.
1641 /* this will return with the dw address in temp_reg.x */
1642 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1643 const struct tgsi_full_dst_register
*dst
,
1644 const struct tgsi_full_src_register
*src
,
1645 int stride_bytes_reg
, int stride_bytes_chan
)
1647 struct tgsi_full_dst_register reg
;
1648 ubyte
*name
, *index
, *array_first
;
1651 struct tgsi_shader_info
*info
= &ctx
->info
;
1652 /* Set the register description. The address computation is the same
1653 * for sources and destinations. */
1655 reg
.Register
.File
= src
->Register
.File
;
1656 reg
.Register
.Index
= src
->Register
.Index
;
1657 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1658 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1659 reg
.Indirect
= src
->Indirect
;
1660 reg
.Dimension
= src
->Dimension
;
1661 reg
.DimIndirect
= src
->DimIndirect
;
1665 /* If the register is 2-dimensional (e.g. an array of vertices
1666 * in a primitive), calculate the base address of the vertex. */
1667 if (reg
.Register
.Dimension
) {
1669 if (reg
.Dimension
.Indirect
) {
1671 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1673 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1674 /* pull the value from index_reg */
1678 sel
= V_SQ_ALU_SRC_LITERAL
;
1679 chan
= reg
.Dimension
.Index
;
1682 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1684 stride_bytes_reg
, stride_bytes_chan
,
1691 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1692 name
= info
->input_semantic_name
;
1693 index
= info
->input_semantic_index
;
1694 array_first
= info
->input_array_first
;
1695 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1696 name
= info
->output_semantic_name
;
1697 index
= info
->output_semantic_index
;
1698 array_first
= info
->output_array_first
;
1703 if (reg
.Register
.Indirect
) {
1706 /* Add the relative address of the element. */
1707 if (reg
.Indirect
.ArrayID
)
1708 first
= array_first
[reg
.Indirect
.ArrayID
];
1710 first
= reg
.Register
.Index
;
1712 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1714 /* pull the value from index_reg */
1715 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1717 V_SQ_ALU_SRC_LITERAL
, 16,
1723 param
= r600_get_lds_unique_index(name
[first
],
1727 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1728 index
[reg
.Register
.Index
]);
1731 /* add to base_addr - passed in temp_reg.x */
1733 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1736 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1744 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1747 struct r600_bytecode_alu alu
;
1750 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1751 ctx
->bc
->force_add_cf
= 1;
1752 for (i
= 1; i
< 4; i
++) {
1753 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1756 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1760 for (i
= 0; i
< 4; i
++) {
1761 /* emit an LDS_READ_RET */
1762 memset(&alu
, 0, sizeof(alu
));
1763 alu
.op
= LDS_OP1_LDS_READ_RET
;
1764 alu
.src
[0].sel
= temp_reg
;
1765 alu
.src
[0].chan
= i
;
1766 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1767 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1769 alu
.is_lds_idx_op
= true;
1771 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1775 for (i
= 0; i
< 4; i
++) {
1776 /* then read from LDS_OQ_A_POP */
1777 memset(&alu
, 0, sizeof(alu
));
1779 alu
.op
= ALU_OP1_MOV
;
1780 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1781 alu
.src
[0].chan
= 0;
1782 alu
.dst
.sel
= dst_reg
;
1786 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1793 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1796 unsigned temp_reg
= r600_get_temp(ctx
);
1798 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1799 src
->Register
.Dimension
? false : true);
1803 /* the base address is now in temp.x */
1804 r
= r600_get_byte_address(ctx
, temp_reg
,
1805 NULL
, src
, ctx
->tess_output_info
, 1);
1809 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1815 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1818 unsigned temp_reg
= r600_get_temp(ctx
);
1820 /* t.x = ips * r0.y */
1821 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1823 ctx
->tess_input_info
, 0,
1829 /* the base address is now in temp.x */
1830 r
= r600_get_byte_address(ctx
, temp_reg
,
1831 NULL
, src
, ctx
->tess_input_info
, 1);
1835 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1841 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1844 unsigned temp_reg
= r600_get_temp(ctx
);
1846 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1847 src
->Register
.Dimension
? false : true);
1850 /* the base address is now in temp.x */
1851 r
= r600_get_byte_address(ctx
, temp_reg
,
1853 ctx
->tess_output_info
, 1);
1857 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1863 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1865 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1868 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1869 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1871 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1872 int treg
= r600_get_temp(ctx
);
1873 fetch_tes_input(ctx
, src
, treg
);
1874 ctx
->src
[i
].sel
= treg
;
1875 ctx
->src
[i
].rel
= 0;
1877 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1878 int treg
= r600_get_temp(ctx
);
1879 fetch_tcs_input(ctx
, src
, treg
);
1880 ctx
->src
[i
].sel
= treg
;
1881 ctx
->src
[i
].rel
= 0;
1883 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1884 int treg
= r600_get_temp(ctx
);
1885 fetch_tcs_output(ctx
, src
, treg
);
1886 ctx
->src
[i
].sel
= treg
;
1887 ctx
->src
[i
].rel
= 0;
1893 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1895 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1896 struct r600_bytecode_alu alu
;
1897 int i
, j
, k
, nconst
, r
;
1899 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1900 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1903 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1905 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1906 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1910 if (ctx
->src
[i
].rel
) {
1911 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1912 int treg
= r600_get_temp(ctx
);
1913 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1916 ctx
->src
[i
].kc_bank
= 0;
1917 ctx
->src
[i
].kc_rel
= 0;
1918 ctx
->src
[i
].sel
= treg
;
1919 ctx
->src
[i
].rel
= 0;
1922 int treg
= r600_get_temp(ctx
);
1923 for (k
= 0; k
< 4; k
++) {
1924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1925 alu
.op
= ALU_OP1_MOV
;
1926 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1927 alu
.src
[0].chan
= k
;
1928 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1929 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1930 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1936 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1940 ctx
->src
[i
].sel
= treg
;
1948 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1949 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1951 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1952 struct r600_bytecode_alu alu
;
1953 int i
, j
, k
, nliteral
, r
;
1955 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1956 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1960 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1961 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1962 int treg
= r600_get_temp(ctx
);
1963 for (k
= 0; k
< 4; k
++) {
1964 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1965 alu
.op
= ALU_OP1_MOV
;
1966 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1967 alu
.src
[0].chan
= k
;
1968 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1978 ctx
->src
[i
].sel
= treg
;
1985 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1987 int i
, r
, count
= ctx
->shader
->ninput
;
1989 for (i
= 0; i
< count
; i
++) {
1990 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1991 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1999 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2000 int stream
, unsigned *stream_item_size
)
2002 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2003 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2006 /* Sanity checking. */
2007 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2008 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2012 for (i
= 0; i
< so
->num_outputs
; i
++) {
2013 if (so
->output
[i
].output_buffer
>= 4) {
2014 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2015 so
->output
[i
].output_buffer
);
2021 /* Initialize locations where the outputs are stored. */
2022 for (i
= 0; i
< so
->num_outputs
; i
++) {
2024 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2025 start_comp
[i
] = so
->output
[i
].start_component
;
2026 /* Lower outputs with dst_offset < start_component.
2028 * We can only output 4D vectors with a write mask, e.g. we can
2029 * only output the W component at offset 3, etc. If we want
2030 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2031 * to move it to X and output X. */
2032 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2033 unsigned tmp
= r600_get_temp(ctx
);
2035 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2036 struct r600_bytecode_alu alu
;
2037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2038 alu
.op
= ALU_OP1_MOV
;
2039 alu
.src
[0].sel
= so_gpr
[i
];
2040 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2045 if (j
== so
->output
[i
].num_components
- 1)
2047 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2056 /* Write outputs to buffers. */
2057 for (i
= 0; i
< so
->num_outputs
; i
++) {
2058 struct r600_bytecode_output output
;
2060 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2063 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2064 output
.gpr
= so_gpr
[i
];
2065 output
.elem_size
= so
->output
[i
].num_components
- 1;
2066 if (output
.elem_size
== 2)
2067 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2068 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2069 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2070 output
.burst_count
= 1;
2071 /* array_size is an upper limit for the burst_count
2072 * with MEM_STREAM instructions */
2073 output
.array_size
= 0xFFF;
2074 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2076 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2077 switch (so
->output
[i
].output_buffer
) {
2079 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2082 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2085 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2088 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2091 output
.op
+= so
->output
[i
].stream
* 4;
2092 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2093 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2095 switch (so
->output
[i
].output_buffer
) {
2097 output
.op
= CF_OP_MEM_STREAM0
;
2100 output
.op
= CF_OP_MEM_STREAM1
;
2103 output
.op
= CF_OP_MEM_STREAM2
;
2106 output
.op
= CF_OP_MEM_STREAM3
;
2109 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2111 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2120 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2122 struct r600_bytecode_alu alu
;
2125 if (!ctx
->shader
->vs_out_edgeflag
)
2128 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2130 /* clamp(x, 0, 1) */
2131 memset(&alu
, 0, sizeof(alu
));
2132 alu
.op
= ALU_OP1_MOV
;
2133 alu
.src
[0].sel
= reg
;
2138 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2140 memset(&alu
, 0, sizeof(alu
));
2141 alu
.op
= ALU_OP1_FLT_TO_INT
;
2142 alu
.src
[0].sel
= reg
;
2146 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2149 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2150 struct r600_pipe_shader
*gs
,
2151 struct pipe_stream_output_info
*so
)
2153 struct r600_shader_ctx ctx
= {};
2154 struct r600_shader
*gs_shader
= &gs
->shader
;
2155 struct r600_pipe_shader
*cshader
;
2156 int ocnt
= gs_shader
->noutput
;
2157 struct r600_bytecode_alu alu
;
2158 struct r600_bytecode_vtx vtx
;
2159 struct r600_bytecode_output output
;
2160 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2161 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2162 int i
, j
, next_clip_pos
= 61, next_param
= 0;
2164 bool only_ring_0
= true;
2165 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2169 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2170 sizeof(struct r600_shader_io
));
2172 cshader
->shader
.noutput
= ocnt
;
2174 ctx
.shader
= &cshader
->shader
;
2175 ctx
.bc
= &ctx
.shader
->bc
;
2176 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2178 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2179 rctx
->screen
->has_compressed_msaa_texturing
);
2181 ctx
.bc
->isa
= rctx
->isa
;
2184 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2186 /* R0.x = R0.x & 0x3fffffff */
2187 memset(&alu
, 0, sizeof(alu
));
2188 alu
.op
= ALU_OP2_AND_INT
;
2189 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2190 alu
.src
[1].value
= 0x3fffffff;
2192 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2194 /* R0.y = R0.x >> 30 */
2195 memset(&alu
, 0, sizeof(alu
));
2196 alu
.op
= ALU_OP2_LSHR_INT
;
2197 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2198 alu
.src
[1].value
= 0x1e;
2202 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2204 /* fetch vertex data from GSVS ring */
2205 for (i
= 0; i
< ocnt
; ++i
) {
2206 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2209 out
->ring_offset
= i
* 16;
2211 memset(&vtx
, 0, sizeof(vtx
));
2212 vtx
.op
= FETCH_OP_VFETCH
;
2213 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2214 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2215 vtx
.mega_fetch_count
= 16;
2216 vtx
.offset
= out
->ring_offset
;
2217 vtx
.dst_gpr
= out
->gpr
;
2223 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2224 vtx
.use_const_fields
= 1;
2226 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2229 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2231 ctx
.temp_reg
= i
+ 1;
2232 for (ring
= 3; ring
>= 0; --ring
) {
2233 bool enabled
= false;
2234 for (i
= 0; i
< so
->num_outputs
; i
++) {
2235 if (so
->output
[i
].stream
== ring
) {
2238 only_ring_0
= false;
2242 if (ring
!= 0 && !enabled
) {
2243 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2248 // Patch up jump label
2249 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2250 cf_pop
= ctx
.bc
->cf_last
;
2252 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2253 cf_jump
->pop_count
= 1;
2254 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2255 cf_pop
->pop_count
= 1;
2258 /* PRED_SETE_INT __, R0.y, ring */
2259 memset(&alu
, 0, sizeof(alu
));
2260 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2261 alu
.src
[0].chan
= 1;
2262 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2263 alu
.src
[1].value
= ring
;
2264 alu
.execute_mask
= 1;
2265 alu
.update_pred
= 1;
2267 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2269 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2270 cf_jump
= ctx
.bc
->cf_last
;
2273 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2274 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2277 /* bc adds nops - copy it */
2278 if (ctx
.bc
->chip_class
== R600
) {
2279 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2280 alu
.op
= ALU_OP0_NOP
;
2282 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2284 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2287 /* export vertex data */
2288 /* XXX factor out common code with r600_shader_from_tgsi ? */
2289 for (i
= 0; i
< ocnt
; ++i
) {
2290 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2291 bool instream0
= true;
2292 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2295 for (j
= 0; j
< so
->num_outputs
; j
++) {
2296 if (so
->output
[j
].register_index
== i
) {
2297 if (so
->output
[j
].stream
== 0)
2299 if (so
->output
[j
].stream
> 0)
2305 memset(&output
, 0, sizeof(output
));
2306 output
.gpr
= out
->gpr
;
2307 output
.elem_size
= 3;
2308 output
.swizzle_x
= 0;
2309 output
.swizzle_y
= 1;
2310 output
.swizzle_z
= 2;
2311 output
.swizzle_w
= 3;
2312 output
.burst_count
= 1;
2313 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2314 output
.op
= CF_OP_EXPORT
;
2315 switch (out
->name
) {
2316 case TGSI_SEMANTIC_POSITION
:
2317 output
.array_base
= 60;
2318 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2321 case TGSI_SEMANTIC_PSIZE
:
2322 output
.array_base
= 61;
2323 if (next_clip_pos
== 61)
2325 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2326 output
.swizzle_y
= 7;
2327 output
.swizzle_z
= 7;
2328 output
.swizzle_w
= 7;
2329 ctx
.shader
->vs_out_misc_write
= 1;
2330 ctx
.shader
->vs_out_point_size
= 1;
2332 case TGSI_SEMANTIC_LAYER
:
2334 /* duplicate it as PARAM to pass to the pixel shader */
2335 output
.array_base
= next_param
++;
2336 r600_bytecode_add_output(ctx
.bc
, &output
);
2337 last_exp_param
= ctx
.bc
->cf_last
;
2339 output
.array_base
= 61;
2340 if (next_clip_pos
== 61)
2342 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2343 output
.swizzle_x
= 7;
2344 output
.swizzle_y
= 7;
2345 output
.swizzle_z
= 0;
2346 output
.swizzle_w
= 7;
2347 ctx
.shader
->vs_out_misc_write
= 1;
2348 ctx
.shader
->vs_out_layer
= 1;
2350 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2352 /* duplicate it as PARAM to pass to the pixel shader */
2353 output
.array_base
= next_param
++;
2354 r600_bytecode_add_output(ctx
.bc
, &output
);
2355 last_exp_param
= ctx
.bc
->cf_last
;
2357 output
.array_base
= 61;
2358 if (next_clip_pos
== 61)
2360 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2361 ctx
.shader
->vs_out_misc_write
= 1;
2362 ctx
.shader
->vs_out_viewport
= 1;
2363 output
.swizzle_x
= 7;
2364 output
.swizzle_y
= 7;
2365 output
.swizzle_z
= 7;
2366 output
.swizzle_w
= 0;
2368 case TGSI_SEMANTIC_CLIPDIST
:
2369 /* spi_sid is 0 for clipdistance outputs that were generated
2370 * for clipvertex - we don't need to pass them to PS */
2371 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2373 /* duplicate it as PARAM to pass to the pixel shader */
2374 output
.array_base
= next_param
++;
2375 r600_bytecode_add_output(ctx
.bc
, &output
);
2376 last_exp_param
= ctx
.bc
->cf_last
;
2378 output
.array_base
= next_clip_pos
++;
2379 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2381 case TGSI_SEMANTIC_FOG
:
2382 output
.swizzle_y
= 4; /* 0 */
2383 output
.swizzle_z
= 4; /* 0 */
2384 output
.swizzle_w
= 5; /* 1 */
2387 output
.array_base
= next_param
++;
2390 r600_bytecode_add_output(ctx
.bc
, &output
);
2391 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2392 last_exp_param
= ctx
.bc
->cf_last
;
2394 last_exp_pos
= ctx
.bc
->cf_last
;
2397 if (!last_exp_pos
) {
2398 memset(&output
, 0, sizeof(output
));
2400 output
.elem_size
= 3;
2401 output
.swizzle_x
= 7;
2402 output
.swizzle_y
= 7;
2403 output
.swizzle_z
= 7;
2404 output
.swizzle_w
= 7;
2405 output
.burst_count
= 1;
2407 output
.op
= CF_OP_EXPORT
;
2408 output
.array_base
= 60;
2409 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2410 r600_bytecode_add_output(ctx
.bc
, &output
);
2411 last_exp_pos
= ctx
.bc
->cf_last
;
2414 if (!last_exp_param
) {
2415 memset(&output
, 0, sizeof(output
));
2417 output
.elem_size
= 3;
2418 output
.swizzle_x
= 7;
2419 output
.swizzle_y
= 7;
2420 output
.swizzle_z
= 7;
2421 output
.swizzle_w
= 7;
2422 output
.burst_count
= 1;
2424 output
.op
= CF_OP_EXPORT
;
2425 output
.array_base
= next_param
++;
2426 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2427 r600_bytecode_add_output(ctx
.bc
, &output
);
2428 last_exp_param
= ctx
.bc
->cf_last
;
2431 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2432 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2434 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2435 cf_pop
= ctx
.bc
->cf_last
;
2437 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2438 cf_jump
->pop_count
= 1;
2439 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2440 cf_pop
->pop_count
= 1;
2442 if (ctx
.bc
->chip_class
== CAYMAN
)
2443 cm_bytecode_add_cf_end(ctx
.bc
);
2445 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2446 ctx
.bc
->cf_last
->end_of_program
= 1;
2449 gs
->gs_copy_shader
= cshader
;
2450 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2454 return r600_bytecode_build(ctx
.bc
);
2457 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2460 struct r600_bytecode_alu alu
;
2463 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2464 alu
.op
= ALU_OP2_ADD_INT
;
2465 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2466 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2467 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2468 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2471 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2478 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
)
2480 struct r600_bytecode_output output
;
2481 int i
, k
, ring_offset
;
2482 int effective_stream
= stream
== -1 ? 0 : stream
;
2485 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2486 if (ctx
->gs_for_vs
) {
2487 /* for ES we need to lookup corresponding ring offset expected by GS
2488 * (map this output to GS input by name and sid) */
2489 /* FIXME precompute offsets */
2491 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2492 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2493 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2494 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2495 ring_offset
= in
->ring_offset
;
2498 if (ring_offset
== -1)
2501 ring_offset
= idx
* 16;
2505 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2507 /* next_ring_offset after parsing input decls contains total size of
2508 * single vertex data, gs_next_vertex - current vertex index */
2510 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2512 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2513 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2514 output
.elem_size
= 3;
2515 output
.comp_mask
= 0xF;
2516 output
.burst_count
= 1;
2519 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2521 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2526 output
.op
= CF_OP_MEM_RING
; break;
2528 output
.op
= CF_OP_MEM_RING1
; break;
2530 output
.op
= CF_OP_MEM_RING2
; break;
2532 output
.op
= CF_OP_MEM_RING3
; break;
2536 output
.array_base
= ring_offset
>> 2; /* in dwords */
2537 output
.array_size
= 0xfff;
2538 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2540 output
.array_base
= ring_offset
>> 2; /* in dwords */
2541 r600_bytecode_add_output(ctx
->bc
, &output
);
2544 ++ctx
->gs_next_vertex
;
2549 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2552 struct r600_bytecode_vtx vtx
;
2553 int temp_val
= ctx
->temp_reg
;
2554 /* need to store the TCS output somewhere */
2555 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2557 V_SQ_ALU_SRC_LITERAL
, 0,
2562 /* used by VS/TCS */
2563 if (ctx
->tess_input_info
) {
2564 /* fetch tcs input values into resv space */
2565 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2566 vtx
.op
= FETCH_OP_VFETCH
;
2567 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2568 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2569 vtx
.mega_fetch_count
= 16;
2570 vtx
.data_format
= FMT_32_32_32_32
;
2571 vtx
.num_format_all
= 2;
2572 vtx
.format_comp_all
= 1;
2573 vtx
.use_const_fields
= 0;
2574 vtx
.endian
= r600_endian_swap(32);
2575 vtx
.srf_mode_all
= 1;
2577 vtx
.dst_gpr
= ctx
->tess_input_info
;
2582 vtx
.src_gpr
= temp_val
;
2585 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2590 /* used by TCS/TES */
2591 if (ctx
->tess_output_info
) {
2592 /* fetch tcs output values into resv space */
2593 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2594 vtx
.op
= FETCH_OP_VFETCH
;
2595 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2596 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2597 vtx
.mega_fetch_count
= 16;
2598 vtx
.data_format
= FMT_32_32_32_32
;
2599 vtx
.num_format_all
= 2;
2600 vtx
.format_comp_all
= 1;
2601 vtx
.use_const_fields
= 0;
2602 vtx
.endian
= r600_endian_swap(32);
2603 vtx
.srf_mode_all
= 1;
2605 vtx
.dst_gpr
= ctx
->tess_output_info
;
2610 vtx
.src_gpr
= temp_val
;
2613 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2620 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2625 /* fetch tcs input values into input_vals */
2626 ctx
->tess_input_info
= r600_get_temp(ctx
);
2627 ctx
->tess_output_info
= 0;
2628 r
= r600_fetch_tess_io_info(ctx
);
2632 temp_reg
= r600_get_temp(ctx
);
2633 /* dst reg contains LDS address stride * idx */
2634 /* MUL vertexID, vertex_dw_stride */
2635 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2637 ctx
->tess_input_info
, 1,
2638 0, 1); /* rel id in r0.y? */
2642 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2643 struct r600_bytecode_alu alu
;
2644 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2647 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2650 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2655 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2657 temp_reg
, param
? 1 : 0,
2658 V_SQ_ALU_SRC_LITERAL
, 8);
2663 for (j
= 0; j
< 2; j
++) {
2664 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2665 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2666 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2667 alu
.src
[0].sel
= temp_reg
;
2668 alu
.src
[0].chan
= chan
;
2669 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2670 alu
.src
[1].chan
= j
* 2;
2671 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2672 alu
.src
[2].chan
= (j
* 2) + 1;
2676 alu
.is_lds_idx_op
= true;
2677 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2685 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2687 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2688 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2690 int temp_reg
= r600_get_temp(ctx
);
2691 struct r600_bytecode_alu alu
;
2692 unsigned write_mask
= dst
->Register
.WriteMask
;
2694 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2697 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2701 /* the base address is now in temp.x */
2702 r
= r600_get_byte_address(ctx
, temp_reg
,
2703 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2708 lasti
= tgsi_last_instruction(write_mask
);
2709 for (i
= 1; i
<= lasti
; i
++) {
2711 if (!(write_mask
& (1 << i
)))
2713 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2716 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2721 for (i
= 0; i
<= lasti
; i
++) {
2722 if (!(write_mask
& (1 << i
)))
2725 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2726 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2727 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2728 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2729 alu
.src
[0].sel
= temp_reg
;
2730 alu
.src
[0].chan
= i
;
2732 alu
.src
[1].sel
= dst
->Register
.Index
;
2733 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2734 alu
.src
[1].chan
= i
;
2736 alu
.src
[2].sel
= dst
->Register
.Index
;
2737 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2738 alu
.src
[2].chan
= i
+ 1;
2742 alu
.is_lds_idx_op
= true;
2743 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2749 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2750 alu
.op
= LDS_OP2_LDS_WRITE
;
2751 alu
.src
[0].sel
= temp_reg
;
2752 alu
.src
[0].chan
= i
;
2754 alu
.src
[1].sel
= dst
->Register
.Index
;
2755 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2756 alu
.src
[1].chan
= i
;
2758 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2761 alu
.is_lds_idx_op
= true;
2762 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2769 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2773 unsigned temp_reg
= r600_get_temp(ctx
);
2774 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2775 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2778 param
= r600_get_lds_unique_index(name
, 0);
2779 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2783 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2786 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2790 do_lds_fetch_values(ctx
, temp_reg
, dreg
);
2794 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2797 int stride
, outer_comps
, inner_comps
;
2798 int tessinner_idx
= -1, tessouter_idx
= -1;
2800 int temp_reg
= r600_get_temp(ctx
);
2801 int treg
[3] = {-1, -1, -1};
2802 struct r600_bytecode_alu alu
;
2803 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2805 /* only execute factor emission for invocation 0 */
2806 /* PRED_SETE_INT __, R0.x, 0 */
2807 memset(&alu
, 0, sizeof(alu
));
2808 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2809 alu
.src
[0].chan
= 2;
2810 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2811 alu
.execute_mask
= 1;
2812 alu
.update_pred
= 1;
2814 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2816 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2817 cf_jump
= ctx
->bc
->cf_last
;
2819 treg
[0] = r600_get_temp(ctx
);
2820 switch (ctx
->shader
->tcs_prim_mode
) {
2821 case PIPE_PRIM_LINES
:
2822 stride
= 8; /* 2 dwords, 1 vec2 store */
2826 case PIPE_PRIM_TRIANGLES
:
2827 stride
= 16; /* 4 dwords, 1 vec4 store */
2830 treg
[1] = r600_get_temp(ctx
);
2832 case PIPE_PRIM_QUADS
:
2833 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2836 treg
[1] = r600_get_temp(ctx
);
2837 treg
[2] = r600_get_temp(ctx
);
2844 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2845 /* TF_WRITE takes index in R.x, value in R.y */
2846 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2847 if (ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_TESSINNER
)
2849 if (ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_TESSOUTER
)
2853 if (tessouter_idx
== -1)
2856 if (tessinner_idx
== -1 && inner_comps
)
2859 if (tessouter_idx
!= -1) {
2860 r
= r600_tess_factor_read(ctx
, tessouter_idx
);
2865 if (tessinner_idx
!= -1) {
2866 r
= r600_tess_factor_read(ctx
, tessinner_idx
);
2871 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2872 /* r.x = relpatchid(r0.y) * tf_stride */
2874 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2875 /* add incoming r0.w to it: t.x = t.x + r0.w */
2876 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2879 V_SQ_ALU_SRC_LITERAL
, stride
,
2884 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2885 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2886 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2888 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
2891 else if (out_comp
== 0)
2895 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2896 treg
[i
/ 2], (2 * (i
% 2)),
2898 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2901 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2902 treg
[i
/ 2], 1 + (2 * (i
%2)),
2903 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
2908 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2909 struct r600_bytecode_gds gds
;
2911 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
2912 gds
.src_gpr
= treg
[i
/ 2];
2913 gds
.src_sel_x
= 2 * (i
% 2);
2914 gds
.src_sel_y
= 1 + (2 * (i
% 2));
2920 gds
.op
= FETCH_OP_TF_WRITE
;
2921 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
2926 // Patch up jump label
2927 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
2928 cf_pop
= ctx
->bc
->cf_last
;
2930 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2931 cf_jump
->pop_count
= 1;
2932 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2933 cf_pop
->pop_count
= 1;
2938 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
2939 struct r600_pipe_shader
*pipeshader
,
2940 union r600_shader_key key
)
2942 struct r600_screen
*rscreen
= rctx
->screen
;
2943 struct r600_shader
*shader
= &pipeshader
->shader
;
2944 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
2945 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
2946 struct tgsi_full_immediate
*immediate
;
2947 struct r600_shader_ctx ctx
;
2948 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
2949 unsigned output_done
, noutput
;
2952 int next_param_base
= 0, next_clip_base
;
2953 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
2955 bool ring_outputs
= false;
2956 bool lds_outputs
= false;
2957 bool lds_inputs
= false;
2958 bool pos_emitted
= false;
2960 ctx
.bc
= &shader
->bc
;
2961 ctx
.shader
= shader
;
2962 ctx
.native_integers
= true;
2964 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
2965 rscreen
->has_compressed_msaa_texturing
);
2966 ctx
.tokens
= tokens
;
2967 tgsi_scan_shader(tokens
, &ctx
.info
);
2968 shader
->indirect_files
= ctx
.info
.indirect_files
;
2970 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
2971 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
2972 shader
->nsys_inputs
= 0;
2974 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0;
2975 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
2976 tgsi_parse_init(&ctx
.parse
, tokens
);
2977 ctx
.type
= ctx
.info
.processor
;
2978 shader
->processor_type
= ctx
.type
;
2979 ctx
.bc
->type
= shader
->processor_type
;
2982 case PIPE_SHADER_VERTEX
:
2983 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
2984 shader
->vs_as_es
= key
.vs
.as_es
;
2985 shader
->vs_as_ls
= key
.vs
.as_ls
;
2986 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
2987 if (shader
->vs_as_es
)
2988 ring_outputs
= true;
2989 if (shader
->vs_as_ls
)
2992 case PIPE_SHADER_GEOMETRY
:
2993 ring_outputs
= true;
2994 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
2995 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
2997 case PIPE_SHADER_TESS_CTRL
:
2998 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
2999 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3003 case PIPE_SHADER_TESS_EVAL
:
3004 shader
->tes_as_es
= key
.tes
.as_es
;
3005 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3007 if (shader
->tes_as_es
)
3008 ring_outputs
= true;
3010 case PIPE_SHADER_FRAGMENT
:
3011 shader
->two_side
= key
.ps
.color_two_side
;
3012 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3018 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3019 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3021 ctx
.gs_for_vs
= NULL
;
3024 ctx
.next_ring_offset
= 0;
3025 ctx
.gs_out_ring_offset
= 0;
3026 ctx
.gs_next_vertex
= 0;
3027 ctx
.gs_stream_output_info
= &so
;
3030 ctx
.fixed_pt_position_gpr
= -1;
3031 ctx
.fragcoord_input
= -1;
3032 ctx
.colors_used
= 0;
3033 ctx
.clip_vertex_write
= 0;
3035 shader
->nr_ps_color_exports
= 0;
3036 shader
->nr_ps_max_color_exports
= 0;
3039 /* register allocations */
3040 /* Values [0,127] correspond to GPR[0..127].
3041 * Values [128,159] correspond to constant buffer bank 0
3042 * Values [160,191] correspond to constant buffer bank 1
3043 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3044 * Values [256,287] correspond to constant buffer bank 2 (EG)
3045 * Values [288,319] correspond to constant buffer bank 3 (EG)
3046 * Other special values are shown in the list below.
3047 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3048 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3049 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3050 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3051 * 248 SQ_ALU_SRC_0: special constant 0.0.
3052 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3053 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3054 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3055 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3056 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3057 * 254 SQ_ALU_SRC_PV: previous vector result.
3058 * 255 SQ_ALU_SRC_PS: previous scalar result.
3060 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3061 ctx
.file_offset
[i
] = 0;
3064 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3066 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3067 if (ctx
.info
.num_inputs
)
3068 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3070 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3071 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3072 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3074 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3076 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3077 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3078 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3080 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3081 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3082 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3083 bool add_tesscoord
= false, add_tess_inout
= false;
3084 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3085 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3086 /* if we have tesscoord save one reg */
3087 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3088 add_tesscoord
= true;
3089 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3090 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3091 add_tess_inout
= true;
3093 if (add_tesscoord
|| add_tess_inout
)
3094 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3096 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3099 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3100 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3101 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3102 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3103 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3105 /* Outside the GPR range. This will be translated to one of the
3106 * kcache banks later. */
3107 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3109 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3110 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3111 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3112 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3113 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3115 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3116 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3117 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3118 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3119 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3120 ctx
.tess_input_info
= 0;
3121 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3122 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3123 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3124 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3125 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3126 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3127 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3128 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3129 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3130 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3131 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3134 ctx
.gs_rotated_input
[0] = 0;
3135 ctx
.gs_rotated_input
[1] = 1;
3138 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3141 shader
->max_arrays
= 0;
3142 shader
->num_arrays
= 0;
3143 if (indirect_gprs
) {
3145 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3146 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3147 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3148 ctx
.file_offset
[TGSI_FILE_INPUT
],
3151 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3152 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3153 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3154 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3160 ctx
.literals
= NULL
;
3162 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3163 ctx
.info
.colors_written
== 1;
3164 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3165 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3167 if (shader
->vs_as_gs_a
)
3168 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3170 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3171 r600_fetch_tess_io_info(&ctx
);
3173 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3174 tgsi_parse_token(&ctx
.parse
);
3175 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3176 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3177 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3178 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3179 if(ctx
.literals
== NULL
) {
3183 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3184 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3185 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3186 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3189 case TGSI_TOKEN_TYPE_DECLARATION
:
3190 r
= tgsi_declaration(&ctx
);
3194 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3195 case TGSI_TOKEN_TYPE_PROPERTY
:
3198 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3204 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3205 shader
->ring_item_sizes
[1] = 0;
3206 shader
->ring_item_sizes
[2] = 0;
3207 shader
->ring_item_sizes
[3] = 0;
3209 /* Process two side if needed */
3210 if (shader
->two_side
&& ctx
.colors_used
) {
3211 int i
, count
= ctx
.shader
->ninput
;
3212 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3214 /* additional inputs will be allocated right after the existing inputs,
3215 * we won't need them after the color selection, so we don't need to
3216 * reserve these gprs for the rest of the shader code and to adjust
3217 * output offsets etc. */
3218 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3219 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3221 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3222 if (ctx
.face_gpr
== -1) {
3223 i
= ctx
.shader
->ninput
++;
3224 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3225 ctx
.shader
->input
[i
].spi_sid
= 0;
3226 ctx
.shader
->input
[i
].gpr
= gpr
++;
3227 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3230 for (i
= 0; i
< count
; i
++) {
3231 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3232 int ni
= ctx
.shader
->ninput
++;
3233 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3234 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3235 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3236 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3237 // TGSI to LLVM needs to know the lds position of inputs.
3238 // Non LLVM path computes it later (in process_twoside_color)
3239 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3240 ctx
.shader
->input
[i
].back_color_input
= ni
;
3241 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3242 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3249 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3250 shader
->nr_ps_max_color_exports
= 8;
3252 if (ctx
.fragcoord_input
>= 0) {
3253 if (ctx
.bc
->chip_class
== CAYMAN
) {
3254 for (j
= 0 ; j
< 4; j
++) {
3255 struct r600_bytecode_alu alu
;
3256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3257 alu
.op
= ALU_OP1_RECIP_IEEE
;
3258 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3259 alu
.src
[0].chan
= 3;
3261 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3263 alu
.dst
.write
= (j
== 3);
3265 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3269 struct r600_bytecode_alu alu
;
3270 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3271 alu
.op
= ALU_OP1_RECIP_IEEE
;
3272 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3273 alu
.src
[0].chan
= 3;
3275 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3279 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3284 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3285 struct r600_bytecode_alu alu
;
3288 /* GS thread with no output workaround - emit a cut at start of GS */
3289 if (ctx
.bc
->chip_class
== R600
)
3290 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3292 for (j
= 0; j
< 4; j
++) {
3293 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3294 alu
.op
= ALU_OP1_MOV
;
3295 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3296 alu
.src
[0].value
= 0;
3297 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3300 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3305 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3306 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3307 ctx
.gs_rotated_input
[0], 2,
3309 V_SQ_ALU_SRC_LITERAL
, 1);
3313 for (i
= 0; i
< 6; i
++) {
3314 int rotated
= (i
+ 4) % 6;
3315 int offset_reg
= i
/ 3;
3316 int offset_chan
= i
% 3;
3317 int rotated_offset_reg
= rotated
/ 3;
3318 int rotated_offset_chan
= rotated
% 3;
3320 if (offset_reg
== 0 && offset_chan
== 2)
3322 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3323 rotated_offset_chan
= 3;
3325 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3326 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3327 ctx
.gs_rotated_input
[0], 2,
3328 offset_reg
, offset_chan
,
3329 rotated_offset_reg
, rotated_offset_chan
);
3336 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3337 r600_fetch_tess_io_info(&ctx
);
3339 if (shader
->two_side
&& ctx
.colors_used
) {
3340 if ((r
= process_twoside_color_inputs(&ctx
)))
3344 tgsi_parse_init(&ctx
.parse
, tokens
);
3345 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3346 tgsi_parse_token(&ctx
.parse
);
3347 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3348 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3349 r
= tgsi_is_supported(&ctx
);
3352 ctx
.max_driver_temp_used
= 0;
3353 /* reserve first tmp for everyone */
3354 r600_get_temp(&ctx
);
3356 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3357 if ((r
= tgsi_split_constant(&ctx
)))
3359 if ((r
= tgsi_split_literal_constant(&ctx
)))
3361 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3362 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3364 } else if (lds_inputs
) {
3365 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3368 if (ctx
.bc
->chip_class
== CAYMAN
)
3369 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3370 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3371 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3373 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3374 r
= ctx
.inst_info
->process(&ctx
);
3378 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3379 r
= r600_store_tcs_output(&ctx
);
3389 /* Reset the temporary register counter. */
3390 ctx
.max_driver_temp_used
= 0;
3392 noutput
= shader
->noutput
;
3394 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3395 unsigned clipdist_temp
[2];
3397 clipdist_temp
[0] = r600_get_temp(&ctx
);
3398 clipdist_temp
[1] = r600_get_temp(&ctx
);
3400 /* need to convert a clipvertex write into clipdistance writes and not export
3401 the clip vertex anymore */
3403 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3404 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3405 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3407 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3408 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3411 /* reset spi_sid for clipvertex output to avoid confusing spi */
3412 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3414 shader
->clip_dist_write
= 0xFF;
3416 for (i
= 0; i
< 8; i
++) {
3420 for (j
= 0; j
< 4; j
++) {
3421 struct r600_bytecode_alu alu
;
3422 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3423 alu
.op
= ALU_OP2_DOT4
;
3424 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3425 alu
.src
[0].chan
= j
;
3427 alu
.src
[1].sel
= 512 + i
;
3428 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3429 alu
.src
[1].chan
= j
;
3431 alu
.dst
.sel
= clipdist_temp
[oreg
];
3433 alu
.dst
.write
= (j
== ochan
);
3436 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3443 /* Add stream outputs. */
3444 if (so
.num_outputs
) {
3446 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3448 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3451 emit_streamout(&ctx
, &so
, -1, NULL
);
3453 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3454 convert_edgeflag_to_int(&ctx
);
3456 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3457 r600_emit_tess_factor(&ctx
);
3460 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3461 if (ctx
.shader
->noutput
)
3462 emit_lds_vs_writes(&ctx
);
3464 } else if (ring_outputs
) {
3465 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3466 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3467 ctx
.gs_export_gpr_tregs
[1] = -1;
3468 ctx
.gs_export_gpr_tregs
[2] = -1;
3469 ctx
.gs_export_gpr_tregs
[3] = -1;
3471 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3475 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3477 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3478 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3479 output
[j
].gpr
= shader
->output
[i
].gpr
;
3480 output
[j
].elem_size
= 3;
3481 output
[j
].swizzle_x
= 0;
3482 output
[j
].swizzle_y
= 1;
3483 output
[j
].swizzle_z
= 2;
3484 output
[j
].swizzle_w
= 3;
3485 output
[j
].burst_count
= 1;
3486 output
[j
].type
= -1;
3487 output
[j
].op
= CF_OP_EXPORT
;
3489 case PIPE_SHADER_VERTEX
:
3490 case PIPE_SHADER_TESS_EVAL
:
3491 switch (shader
->output
[i
].name
) {
3492 case TGSI_SEMANTIC_POSITION
:
3493 output
[j
].array_base
= 60;
3494 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3498 case TGSI_SEMANTIC_PSIZE
:
3499 output
[j
].array_base
= 61;
3500 output
[j
].swizzle_y
= 7;
3501 output
[j
].swizzle_z
= 7;
3502 output
[j
].swizzle_w
= 7;
3503 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3506 case TGSI_SEMANTIC_EDGEFLAG
:
3507 output
[j
].array_base
= 61;
3508 output
[j
].swizzle_x
= 7;
3509 output
[j
].swizzle_y
= 0;
3510 output
[j
].swizzle_z
= 7;
3511 output
[j
].swizzle_w
= 7;
3512 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3515 case TGSI_SEMANTIC_LAYER
:
3516 /* spi_sid is 0 for outputs that are
3517 * not consumed by PS */
3518 if (shader
->output
[i
].spi_sid
) {
3519 output
[j
].array_base
= next_param_base
++;
3520 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3522 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3524 output
[j
].array_base
= 61;
3525 output
[j
].swizzle_x
= 7;
3526 output
[j
].swizzle_y
= 7;
3527 output
[j
].swizzle_z
= 0;
3528 output
[j
].swizzle_w
= 7;
3529 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3532 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3533 /* spi_sid is 0 for outputs that are
3534 * not consumed by PS */
3535 if (shader
->output
[i
].spi_sid
) {
3536 output
[j
].array_base
= next_param_base
++;
3537 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3539 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3541 output
[j
].array_base
= 61;
3542 output
[j
].swizzle_x
= 7;
3543 output
[j
].swizzle_y
= 7;
3544 output
[j
].swizzle_z
= 7;
3545 output
[j
].swizzle_w
= 0;
3546 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3549 case TGSI_SEMANTIC_CLIPVERTEX
:
3552 case TGSI_SEMANTIC_CLIPDIST
:
3553 output
[j
].array_base
= next_clip_base
++;
3554 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3556 /* spi_sid is 0 for clipdistance outputs that were generated
3557 * for clipvertex - we don't need to pass them to PS */
3558 if (shader
->output
[i
].spi_sid
) {
3560 /* duplicate it as PARAM to pass to the pixel shader */
3561 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3562 output
[j
].array_base
= next_param_base
++;
3563 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3566 case TGSI_SEMANTIC_FOG
:
3567 output
[j
].swizzle_y
= 4; /* 0 */
3568 output
[j
].swizzle_z
= 4; /* 0 */
3569 output
[j
].swizzle_w
= 5; /* 1 */
3571 case TGSI_SEMANTIC_PRIMID
:
3572 output
[j
].swizzle_x
= 2;
3573 output
[j
].swizzle_y
= 4; /* 0 */
3574 output
[j
].swizzle_z
= 4; /* 0 */
3575 output
[j
].swizzle_w
= 4; /* 0 */
3580 case PIPE_SHADER_FRAGMENT
:
3581 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3582 /* never export more colors than the number of CBs */
3583 if (shader
->output
[i
].sid
>= max_color_exports
) {
3588 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3589 output
[j
].array_base
= shader
->output
[i
].sid
;
3590 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3591 shader
->nr_ps_color_exports
++;
3592 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3593 for (k
= 1; k
< max_color_exports
; k
++) {
3595 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3596 output
[j
].gpr
= shader
->output
[i
].gpr
;
3597 output
[j
].elem_size
= 3;
3598 output
[j
].swizzle_x
= 0;
3599 output
[j
].swizzle_y
= 1;
3600 output
[j
].swizzle_z
= 2;
3601 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3602 output
[j
].burst_count
= 1;
3603 output
[j
].array_base
= k
;
3604 output
[j
].op
= CF_OP_EXPORT
;
3605 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3606 shader
->nr_ps_color_exports
++;
3609 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3610 output
[j
].array_base
= 61;
3611 output
[j
].swizzle_x
= 2;
3612 output
[j
].swizzle_y
= 7;
3613 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3614 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3615 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3616 output
[j
].array_base
= 61;
3617 output
[j
].swizzle_x
= 7;
3618 output
[j
].swizzle_y
= 1;
3619 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3620 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3621 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3622 output
[j
].array_base
= 61;
3623 output
[j
].swizzle_x
= 7;
3624 output
[j
].swizzle_y
= 7;
3625 output
[j
].swizzle_z
= 0;
3626 output
[j
].swizzle_w
= 7;
3627 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3629 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3634 case PIPE_SHADER_TESS_CTRL
:
3637 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3642 if (output
[j
].type
==-1) {
3643 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3644 output
[j
].array_base
= next_param_base
++;
3648 /* add fake position export */
3649 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3650 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3652 output
[j
].elem_size
= 3;
3653 output
[j
].swizzle_x
= 7;
3654 output
[j
].swizzle_y
= 7;
3655 output
[j
].swizzle_z
= 7;
3656 output
[j
].swizzle_w
= 7;
3657 output
[j
].burst_count
= 1;
3658 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3659 output
[j
].array_base
= 60;
3660 output
[j
].op
= CF_OP_EXPORT
;
3664 /* add fake param output for vertex shader if no param is exported */
3665 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3666 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3668 output
[j
].elem_size
= 3;
3669 output
[j
].swizzle_x
= 7;
3670 output
[j
].swizzle_y
= 7;
3671 output
[j
].swizzle_z
= 7;
3672 output
[j
].swizzle_w
= 7;
3673 output
[j
].burst_count
= 1;
3674 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3675 output
[j
].array_base
= 0;
3676 output
[j
].op
= CF_OP_EXPORT
;
3680 /* add fake pixel export */
3681 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3682 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3684 output
[j
].elem_size
= 3;
3685 output
[j
].swizzle_x
= 7;
3686 output
[j
].swizzle_y
= 7;
3687 output
[j
].swizzle_z
= 7;
3688 output
[j
].swizzle_w
= 7;
3689 output
[j
].burst_count
= 1;
3690 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3691 output
[j
].array_base
= 0;
3692 output
[j
].op
= CF_OP_EXPORT
;
3694 shader
->nr_ps_color_exports
++;
3699 /* set export done on last export of each type */
3700 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
3701 if (!(output_done
& (1 << output
[i
].type
))) {
3702 output_done
|= (1 << output
[i
].type
);
3703 output
[i
].op
= CF_OP_EXPORT_DONE
;
3706 /* add output to bytecode */
3707 for (i
= 0; i
< noutput
; i
++) {
3708 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3714 /* add program end */
3715 if (ctx
.bc
->chip_class
== CAYMAN
)
3716 cm_bytecode_add_cf_end(ctx
.bc
);
3718 const struct cf_op_info
*last
= NULL
;
3720 if (ctx
.bc
->cf_last
)
3721 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3723 /* alu clause instructions don't have EOP bit, so add NOP */
3724 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
|| ctx
.bc
->cf_last
->op
== CF_OP_GDS
)
3725 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3727 ctx
.bc
->cf_last
->end_of_program
= 1;
3730 /* check GPR limit - we have 124 = 128 - 4
3731 * (4 are reserved as alu clause temporary registers) */
3732 if (ctx
.bc
->ngpr
> 124) {
3733 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3738 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3739 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3744 tgsi_parse_free(&ctx
.parse
);
3748 tgsi_parse_free(&ctx
.parse
);
3752 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3754 const unsigned tgsi_opcode
=
3755 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3756 R600_ERR("%s tgsi opcode unsupported\n",
3757 tgsi_get_opcode_name(tgsi_opcode
));
3761 static int tgsi_end(struct r600_shader_ctx
*ctx
)
3766 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3767 const struct r600_shader_src
*shader_src
,
3770 bc_src
->sel
= shader_src
->sel
;
3771 bc_src
->chan
= shader_src
->swizzle
[chan
];
3772 bc_src
->neg
= shader_src
->neg
;
3773 bc_src
->abs
= shader_src
->abs
;
3774 bc_src
->rel
= shader_src
->rel
;
3775 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3776 bc_src
->kc_bank
= shader_src
->kc_bank
;
3777 bc_src
->kc_rel
= shader_src
->kc_rel
;
3780 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3786 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3788 bc_src
->neg
= !bc_src
->neg
;
3791 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3792 const struct tgsi_full_dst_register
*tgsi_dst
,
3794 struct r600_bytecode_alu_dst
*r600_dst
)
3796 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3798 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
3799 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
3800 r600_dst
->chan
= swizzle
;
3801 r600_dst
->write
= 1;
3802 if (inst
->Instruction
.Saturate
) {
3803 r600_dst
->clamp
= 1;
3805 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
3806 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
3810 if (tgsi_dst
->Register
.Indirect
)
3811 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
3815 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
)
3817 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3818 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3819 struct r600_bytecode_alu alu
;
3820 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3824 switch (write_mask
) {
3842 lasti
= tgsi_last_instruction(write_mask
);
3843 for (i
= 0; i
<= lasti
; i
++) {
3845 if (!(write_mask
& (1 << i
)))
3848 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3851 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3853 alu
.dst
.sel
= ctx
->temp_reg
;
3857 if (i
== 1 || i
== 3)
3860 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3862 alu
.op
= ctx
->inst_info
->op
;
3863 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
3864 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3866 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3867 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
3870 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
3871 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
3874 /* handle some special cases */
3875 if (i
== 1 || i
== 3) {
3876 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
3877 case TGSI_OPCODE_DABS
:
3878 r600_bytecode_src_set_abs(&alu
.src
[0]);
3887 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3893 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3895 /* move result from temp to dst */
3896 for (i
= 0; i
<= lasti
; i
++) {
3897 if (!(write_mask
& (1 << i
)))
3900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3901 alu
.op
= ALU_OP1_MOV
;
3902 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3903 alu
.src
[0].sel
= ctx
->temp_reg
;
3904 alu
.src
[0].chan
= use_tmp
- 1;
3905 alu
.last
= (i
== lasti
);
3907 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3915 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
3917 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3918 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3919 /* confirm writemasking */
3920 if ((write_mask
& 0x3) != 0x3 &&
3921 (write_mask
& 0xc) != 0xc) {
3922 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
3925 return tgsi_op2_64_params(ctx
, false, false);
3928 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
3930 return tgsi_op2_64_params(ctx
, true, false);
3933 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
3935 return tgsi_op2_64_params(ctx
, true, true);
3938 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
3940 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3941 struct r600_bytecode_alu alu
;
3944 int tmp
= r600_get_temp(ctx
);
3946 for (i
= 0; i
< lasti
+ 1; i
++) {
3948 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3949 alu
.op
= ctx
->inst_info
->op
;
3950 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3951 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
3954 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
3955 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3964 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3971 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
3973 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3974 struct r600_bytecode_alu alu
;
3975 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3976 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3977 /* use temp register if trans_only and more than one dst component */
3978 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
3979 unsigned op
= ctx
->inst_info
->op
;
3981 if (op
== ALU_OP2_MUL_IEEE
&&
3982 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
3985 for (i
= 0; i
<= lasti
; i
++) {
3986 if (!(write_mask
& (1 << i
)))
3989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3991 alu
.dst
.sel
= ctx
->temp_reg
;
3995 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3999 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4000 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4003 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4004 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4006 if (i
== lasti
|| trans_only
) {
4009 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4015 /* move result from temp to dst */
4016 for (i
= 0; i
<= lasti
; i
++) {
4017 if (!(write_mask
& (1 << i
)))
4020 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4021 alu
.op
= ALU_OP1_MOV
;
4022 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4023 alu
.src
[0].sel
= ctx
->temp_reg
;
4024 alu
.src
[0].chan
= i
;
4025 alu
.last
= (i
== lasti
);
4027 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4035 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4037 return tgsi_op2_s(ctx
, 0, 0);
4040 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4042 return tgsi_op2_s(ctx
, 1, 0);
4045 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4047 return tgsi_op2_s(ctx
, 0, 1);
4050 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4052 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4053 struct r600_bytecode_alu alu
;
4055 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4057 for (i
= 0; i
< lasti
+ 1; i
++) {
4059 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4062 alu
.op
= ctx
->inst_info
->op
;
4064 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4066 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4068 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4081 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4083 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4084 struct r600_bytecode_alu alu
;
4086 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4088 for (i
= 0; i
< lasti
+ 1; i
++) {
4090 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4093 alu
.op
= ALU_OP1_MOV
;
4095 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4097 if (i
== 1 || i
== 3)
4098 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4099 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4104 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4112 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4114 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4115 struct r600_bytecode_alu alu
;
4116 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4119 for (i
= 0; i
<= 3; i
++) {
4120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4121 alu
.op
= ctx
->inst_info
->op
;
4123 alu
.dst
.sel
= ctx
->temp_reg
;
4126 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4127 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4133 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4138 /* Replicate significand result across channels. */
4139 for (i
= 0; i
<= 3; i
++) {
4140 if (!(write_mask
& (1 << i
)))
4143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4144 alu
.op
= ALU_OP1_MOV
;
4145 alu
.src
[0].chan
= (i
& 1) + 2;
4146 alu
.src
[0].sel
= ctx
->temp_reg
;
4148 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4151 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4156 for (i
= 0; i
<= 3; i
++) {
4157 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4158 /* MOV third channels to writemask dst1 */
4159 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4160 alu
.op
= ALU_OP1_MOV
;
4161 alu
.src
[0].chan
= 1;
4162 alu
.src
[0].sel
= ctx
->temp_reg
;
4164 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4166 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4176 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4178 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4179 struct r600_bytecode_alu alu
;
4181 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4183 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4184 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4186 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4187 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4188 alu
.op
= ctx
->inst_info
->op
;
4190 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4191 alu
.dst
.sel
= ctx
->temp_reg
;
4196 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4201 for (i
= 0; i
<= lasti
; i
++) {
4202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4203 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4205 alu
.src
[0].chan
= i
/2;
4207 alu
.src
[0].sel
= ctx
->temp_reg
;
4209 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4210 alu
.src
[0].value
= 0x0;
4212 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4213 alu
.last
= i
== lasti
;
4215 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4223 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4225 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4226 struct r600_bytecode_alu alu
;
4228 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4230 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4231 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4233 for (i
= 0; i
<= lasti
; i
++) {
4234 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4235 alu
.op
= ALU_OP1_FLT64_TO_FLT32
;
4237 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], fp64_switch(i
));
4239 alu
.dst
.sel
= ctx
->temp_reg
;
4240 alu
.dst
.write
= i
%2 == 0;
4241 alu
.last
= i
== lasti
;
4243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4248 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4250 alu
.op
= ctx
->inst_info
->op
;
4252 alu
.src
[0].chan
= i
*2;
4253 alu
.src
[0].sel
= ctx
->temp_reg
;
4254 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4257 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4265 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4268 struct r600_shader_src
*src
,
4271 struct r600_bytecode_alu alu
;
4272 const int last_slot
= 3;
4275 /* these have to write the result to X/Y by the looks of it */
4276 for (int i
= 0 ; i
< last_slot
; i
++) {
4277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4280 r600_bytecode_src(&alu
.src
[0], src
, 1);
4281 r600_bytecode_src(&alu
.src
[1], src
, 0);
4284 r600_bytecode_src_set_abs(&alu
.src
[1]);
4286 alu
.dst
.sel
= dst_reg
;
4288 alu
.dst
.write
= (i
== 0 || i
== 1);
4290 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4292 r
= r600_bytecode_add_alu(bc
, &alu
);
4300 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4302 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4304 struct r600_bytecode_alu alu
;
4305 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4306 int t1
= ctx
->temp_reg
;
4308 /* should only be one src regs */
4309 assert(inst
->Instruction
.NumSrcRegs
== 1);
4311 /* only support one double at a time */
4312 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4313 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4315 r
= cayman_emit_unary_double_raw(
4316 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4318 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4319 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4323 for (i
= 0 ; i
<= lasti
; i
++) {
4324 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4326 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4327 alu
.op
= ALU_OP1_MOV
;
4328 alu
.src
[0].sel
= t1
;
4329 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4330 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4334 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4341 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4343 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4345 struct r600_bytecode_alu alu
;
4346 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4348 for (i
= 0 ; i
< last_slot
; i
++) {
4349 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4350 alu
.op
= ctx
->inst_info
->op
;
4351 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4352 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4354 /* RSQ should take the absolute value of src */
4355 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4356 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4359 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4360 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4362 if (i
== last_slot
- 1)
4364 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4371 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4373 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4375 struct r600_bytecode_alu alu
;
4376 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4377 int t1
= ctx
->temp_reg
;
4379 for (k
= 0; k
<= lasti
; k
++) {
4380 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4383 for (i
= 0 ; i
< 4; i
++) {
4384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4385 alu
.op
= ctx
->inst_info
->op
;
4386 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4387 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4391 alu
.dst
.write
= (i
== k
);
4394 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4400 for (i
= 0 ; i
<= lasti
; i
++) {
4401 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4404 alu
.op
= ALU_OP1_MOV
;
4405 alu
.src
[0].sel
= t1
;
4406 alu
.src
[0].chan
= i
;
4407 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4420 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4422 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4424 struct r600_bytecode_alu alu
;
4425 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4426 int t1
= ctx
->temp_reg
;
4428 /* t1 would get overwritten below if we actually tried to
4429 * multiply two pairs of doubles at a time. */
4430 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4431 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4433 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4435 for (i
= 0; i
< 4; i
++) {
4436 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4437 alu
.op
= ctx
->inst_info
->op
;
4438 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4439 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4446 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4451 for (i
= 0; i
<= lasti
; i
++) {
4452 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4454 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4455 alu
.op
= ALU_OP1_MOV
;
4456 alu
.src
[0].sel
= t1
;
4457 alu
.src
[0].chan
= i
;
4458 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4462 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4471 * Emit RECIP_64 + MUL_64 to implement division.
4473 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4475 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4477 struct r600_bytecode_alu alu
;
4478 int t1
= ctx
->temp_reg
;
4481 /* Only support one double at a time. This is the same constraint as
4482 * in DMUL lowering. */
4483 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4484 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4486 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4488 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4492 for (int i
= 0; i
< 4; i
++) {
4493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4494 alu
.op
= ALU_OP2_MUL_64
;
4496 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4498 alu
.src
[1].sel
= t1
;
4499 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4506 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4511 for (int i
= 0; i
< 2; i
++) {
4512 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4513 alu
.op
= ALU_OP1_MOV
;
4514 alu
.src
[0].sel
= t1
;
4515 alu
.src
[0].chan
= i
;
4516 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4520 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4528 * r600 - trunc to -PI..PI range
4529 * r700 - normalize by dividing by 2PI
4532 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4535 struct r600_bytecode_alu alu
;
4537 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4538 alu
.op
= ALU_OP3_MULADD
;
4542 alu
.dst
.sel
= ctx
->temp_reg
;
4545 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4547 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4548 alu
.src
[1].chan
= 0;
4549 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4550 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4551 alu
.src
[2].chan
= 0;
4553 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4557 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4558 alu
.op
= ALU_OP1_FRACT
;
4561 alu
.dst
.sel
= ctx
->temp_reg
;
4564 alu
.src
[0].sel
= ctx
->temp_reg
;
4565 alu
.src
[0].chan
= 0;
4567 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4571 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4572 alu
.op
= ALU_OP3_MULADD
;
4576 alu
.dst
.sel
= ctx
->temp_reg
;
4579 alu
.src
[0].sel
= ctx
->temp_reg
;
4580 alu
.src
[0].chan
= 0;
4582 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4583 alu
.src
[1].chan
= 0;
4584 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4585 alu
.src
[2].chan
= 0;
4587 if (ctx
->bc
->chip_class
== R600
) {
4588 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4589 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4591 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4592 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4597 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4603 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4605 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4606 struct r600_bytecode_alu alu
;
4607 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4610 r
= tgsi_setup_trig(ctx
);
4615 for (i
= 0; i
< last_slot
; i
++) {
4616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4617 alu
.op
= ctx
->inst_info
->op
;
4620 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4621 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4623 alu
.src
[0].sel
= ctx
->temp_reg
;
4624 alu
.src
[0].chan
= 0;
4625 if (i
== last_slot
- 1)
4627 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4634 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4636 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4637 struct r600_bytecode_alu alu
;
4639 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4641 r
= tgsi_setup_trig(ctx
);
4645 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4646 alu
.op
= ctx
->inst_info
->op
;
4648 alu
.dst
.sel
= ctx
->temp_reg
;
4651 alu
.src
[0].sel
= ctx
->temp_reg
;
4652 alu
.src
[0].chan
= 0;
4654 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4658 /* replicate result */
4659 for (i
= 0; i
< lasti
+ 1; i
++) {
4660 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4663 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4664 alu
.op
= ALU_OP1_MOV
;
4666 alu
.src
[0].sel
= ctx
->temp_reg
;
4667 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4670 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4677 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4679 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4680 struct r600_bytecode_alu alu
;
4683 for (i
= 0; i
< 4; i
++) {
4684 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4685 alu
.op
= ctx
->inst_info
->op
;
4689 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4691 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4692 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4695 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4700 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4705 /* kill must be last in ALU */
4706 ctx
->bc
->force_add_cf
= 1;
4707 ctx
->shader
->uses_kill
= TRUE
;
4711 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4713 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4714 struct r600_bytecode_alu alu
;
4717 /* tmp.x = max(src.y, 0.0) */
4718 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4719 alu
.op
= ALU_OP2_MAX
;
4720 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4721 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4722 alu
.src
[1].chan
= 1;
4724 alu
.dst
.sel
= ctx
->temp_reg
;
4729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4733 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4739 if (ctx
->bc
->chip_class
== CAYMAN
) {
4740 for (i
= 0; i
< 3; i
++) {
4741 /* tmp.z = log(tmp.x) */
4742 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4743 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4744 alu
.src
[0].sel
= ctx
->temp_reg
;
4745 alu
.src
[0].chan
= 0;
4746 alu
.dst
.sel
= ctx
->temp_reg
;
4754 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4759 /* tmp.z = log(tmp.x) */
4760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4761 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4762 alu
.src
[0].sel
= ctx
->temp_reg
;
4763 alu
.src
[0].chan
= 0;
4764 alu
.dst
.sel
= ctx
->temp_reg
;
4768 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4773 chan
= alu
.dst
.chan
;
4776 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
4777 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4778 alu
.op
= ALU_OP3_MUL_LIT
;
4779 alu
.src
[0].sel
= sel
;
4780 alu
.src
[0].chan
= chan
;
4781 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
4782 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
4783 alu
.dst
.sel
= ctx
->temp_reg
;
4788 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4792 if (ctx
->bc
->chip_class
== CAYMAN
) {
4793 for (i
= 0; i
< 3; i
++) {
4794 /* dst.z = exp(tmp.x) */
4795 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4796 alu
.op
= ALU_OP1_EXP_IEEE
;
4797 alu
.src
[0].sel
= ctx
->temp_reg
;
4798 alu
.src
[0].chan
= 0;
4799 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4805 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4810 /* dst.z = exp(tmp.x) */
4811 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4812 alu
.op
= ALU_OP1_EXP_IEEE
;
4813 alu
.src
[0].sel
= ctx
->temp_reg
;
4814 alu
.src
[0].chan
= 0;
4815 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4817 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4824 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4825 alu
.op
= ALU_OP1_MOV
;
4826 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
4827 alu
.src
[0].chan
= 0;
4828 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4829 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
4830 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4834 /* dst.y = max(src.x, 0.0) */
4835 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4836 alu
.op
= ALU_OP2_MAX
;
4837 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4838 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4839 alu
.src
[1].chan
= 0;
4840 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
4841 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
4842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4847 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4848 alu
.op
= ALU_OP1_MOV
;
4849 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4850 alu
.src
[0].chan
= 0;
4851 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
4852 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
4854 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4861 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
4863 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4864 struct r600_bytecode_alu alu
;
4867 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4869 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
4871 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4872 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4873 r600_bytecode_src_set_abs(&alu
.src
[i
]);
4875 alu
.dst
.sel
= ctx
->temp_reg
;
4878 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4881 /* replicate result */
4882 return tgsi_helper_tempx_replicate(ctx
);
4885 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
4887 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4888 struct r600_bytecode_alu alu
;
4891 for (i
= 0; i
< 4; i
++) {
4892 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4893 alu
.src
[0].sel
= ctx
->temp_reg
;
4894 alu
.op
= ALU_OP1_MOV
;
4896 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4897 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4907 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
4909 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4910 struct r600_bytecode_alu alu
;
4913 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4914 alu
.op
= ctx
->inst_info
->op
;
4915 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4916 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4918 alu
.dst
.sel
= ctx
->temp_reg
;
4921 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4924 /* replicate result */
4925 return tgsi_helper_tempx_replicate(ctx
);
4928 static int cayman_pow(struct r600_shader_ctx
*ctx
)
4930 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4932 struct r600_bytecode_alu alu
;
4933 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4935 for (i
= 0; i
< 3; i
++) {
4936 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4937 alu
.op
= ALU_OP1_LOG_IEEE
;
4938 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4939 alu
.dst
.sel
= ctx
->temp_reg
;
4944 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4951 alu
.op
= ALU_OP2_MUL
;
4952 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4953 alu
.src
[1].sel
= ctx
->temp_reg
;
4954 alu
.dst
.sel
= ctx
->temp_reg
;
4957 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4961 for (i
= 0; i
< last_slot
; i
++) {
4962 /* POW(a,b) = EXP2(b * LOG2(a))*/
4963 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4964 alu
.op
= ALU_OP1_EXP_IEEE
;
4965 alu
.src
[0].sel
= ctx
->temp_reg
;
4967 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4968 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4969 if (i
== last_slot
- 1)
4971 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4978 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
4980 struct r600_bytecode_alu alu
;
4984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4985 alu
.op
= ALU_OP1_LOG_IEEE
;
4986 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4987 alu
.dst
.sel
= ctx
->temp_reg
;
4990 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4994 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4995 alu
.op
= ALU_OP2_MUL
;
4996 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
4997 alu
.src
[1].sel
= ctx
->temp_reg
;
4998 alu
.dst
.sel
= ctx
->temp_reg
;
5001 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5004 /* POW(a,b) = EXP2(b * LOG2(a))*/
5005 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5006 alu
.op
= ALU_OP1_EXP_IEEE
;
5007 alu
.src
[0].sel
= ctx
->temp_reg
;
5008 alu
.dst
.sel
= ctx
->temp_reg
;
5011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5014 return tgsi_helper_tempx_replicate(ctx
);
5017 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5019 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5020 struct r600_bytecode_alu alu
;
5022 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5023 int tmp0
= ctx
->temp_reg
;
5024 int tmp1
= r600_get_temp(ctx
);
5025 int tmp2
= r600_get_temp(ctx
);
5026 int tmp3
= r600_get_temp(ctx
);
5029 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5031 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5032 * 2. tmp0.z = lo (tmp0.x * src2)
5033 * 3. tmp0.w = -tmp0.z
5034 * 4. tmp0.y = hi (tmp0.x * src2)
5035 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5036 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5037 * 7. tmp1.x = tmp0.x - tmp0.w
5038 * 8. tmp1.y = tmp0.x + tmp0.w
5039 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5040 * 10. tmp0.z = hi(tmp0.x * src1) = q
5041 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5043 * 12. tmp0.w = src1 - tmp0.y = r
5044 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5045 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5049 * 15. tmp1.z = tmp0.z + 1 = q + 1
5050 * 16. tmp1.w = tmp0.z - 1 = q - 1
5054 * 15. tmp1.z = tmp0.w - src2 = r - src2
5055 * 16. tmp1.w = tmp0.w + src2 = r + src2
5059 * 17. tmp1.x = tmp1.x & tmp1.y
5061 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5062 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5064 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5065 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5069 * Same as unsigned, using abs values of the operands,
5070 * and fixing the sign of the result in the end.
5073 for (i
= 0; i
< 4; i
++) {
5074 if (!(write_mask
& (1<<i
)))
5079 /* tmp2.x = -src0 */
5080 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5081 alu
.op
= ALU_OP2_SUB_INT
;
5087 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5089 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5092 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5095 /* tmp2.y = -src1 */
5096 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5097 alu
.op
= ALU_OP2_SUB_INT
;
5103 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5105 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5108 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5111 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5112 /* it will be a sign of the quotient */
5115 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5116 alu
.op
= ALU_OP2_XOR_INT
;
5122 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5123 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5126 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5130 /* tmp2.x = |src0| */
5131 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5132 alu
.op
= ALU_OP3_CNDGE_INT
;
5139 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5140 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5141 alu
.src
[2].sel
= tmp2
;
5142 alu
.src
[2].chan
= 0;
5145 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5148 /* tmp2.y = |src1| */
5149 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5150 alu
.op
= ALU_OP3_CNDGE_INT
;
5157 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5158 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5159 alu
.src
[2].sel
= tmp2
;
5160 alu
.src
[2].chan
= 1;
5163 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5168 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5169 if (ctx
->bc
->chip_class
== CAYMAN
) {
5170 /* tmp3.x = u2f(src2) */
5171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5172 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5179 alu
.src
[0].sel
= tmp2
;
5180 alu
.src
[0].chan
= 1;
5182 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5186 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5189 /* tmp0.x = recip(tmp3.x) */
5190 for (j
= 0 ; j
< 3; j
++) {
5191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5192 alu
.op
= ALU_OP1_RECIP_IEEE
;
5196 alu
.dst
.write
= (j
== 0);
5198 alu
.src
[0].sel
= tmp3
;
5199 alu
.src
[0].chan
= 0;
5203 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5208 alu
.op
= ALU_OP2_MUL
;
5210 alu
.src
[0].sel
= tmp0
;
5211 alu
.src
[0].chan
= 0;
5213 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5214 alu
.src
[1].value
= 0x4f800000;
5219 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5224 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5230 alu
.src
[0].sel
= tmp3
;
5231 alu
.src
[0].chan
= 0;
5234 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5238 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5239 alu
.op
= ALU_OP1_RECIP_UINT
;
5246 alu
.src
[0].sel
= tmp2
;
5247 alu
.src
[0].chan
= 1;
5249 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5253 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5257 /* 2. tmp0.z = lo (tmp0.x * src2) */
5258 if (ctx
->bc
->chip_class
== CAYMAN
) {
5259 for (j
= 0 ; j
< 4; j
++) {
5260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5261 alu
.op
= ALU_OP2_MULLO_UINT
;
5265 alu
.dst
.write
= (j
== 2);
5267 alu
.src
[0].sel
= tmp0
;
5268 alu
.src
[0].chan
= 0;
5270 alu
.src
[1].sel
= tmp2
;
5271 alu
.src
[1].chan
= 1;
5273 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5276 alu
.last
= (j
== 3);
5277 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5281 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5282 alu
.op
= ALU_OP2_MULLO_UINT
;
5288 alu
.src
[0].sel
= tmp0
;
5289 alu
.src
[0].chan
= 0;
5291 alu
.src
[1].sel
= tmp2
;
5292 alu
.src
[1].chan
= 1;
5294 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5298 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5302 /* 3. tmp0.w = -tmp0.z */
5303 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5304 alu
.op
= ALU_OP2_SUB_INT
;
5310 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5311 alu
.src
[1].sel
= tmp0
;
5312 alu
.src
[1].chan
= 2;
5315 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5318 /* 4. tmp0.y = hi (tmp0.x * src2) */
5319 if (ctx
->bc
->chip_class
== CAYMAN
) {
5320 for (j
= 0 ; j
< 4; j
++) {
5321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5322 alu
.op
= ALU_OP2_MULHI_UINT
;
5326 alu
.dst
.write
= (j
== 1);
5328 alu
.src
[0].sel
= tmp0
;
5329 alu
.src
[0].chan
= 0;
5332 alu
.src
[1].sel
= tmp2
;
5333 alu
.src
[1].chan
= 1;
5335 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5337 alu
.last
= (j
== 3);
5338 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5343 alu
.op
= ALU_OP2_MULHI_UINT
;
5349 alu
.src
[0].sel
= tmp0
;
5350 alu
.src
[0].chan
= 0;
5353 alu
.src
[1].sel
= tmp2
;
5354 alu
.src
[1].chan
= 1;
5356 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5360 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5364 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5365 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5366 alu
.op
= ALU_OP3_CNDE_INT
;
5373 alu
.src
[0].sel
= tmp0
;
5374 alu
.src
[0].chan
= 1;
5375 alu
.src
[1].sel
= tmp0
;
5376 alu
.src
[1].chan
= 3;
5377 alu
.src
[2].sel
= tmp0
;
5378 alu
.src
[2].chan
= 2;
5381 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5384 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5385 if (ctx
->bc
->chip_class
== CAYMAN
) {
5386 for (j
= 0 ; j
< 4; j
++) {
5387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5388 alu
.op
= ALU_OP2_MULHI_UINT
;
5392 alu
.dst
.write
= (j
== 3);
5394 alu
.src
[0].sel
= tmp0
;
5395 alu
.src
[0].chan
= 2;
5397 alu
.src
[1].sel
= tmp0
;
5398 alu
.src
[1].chan
= 0;
5400 alu
.last
= (j
== 3);
5401 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5406 alu
.op
= ALU_OP2_MULHI_UINT
;
5412 alu
.src
[0].sel
= tmp0
;
5413 alu
.src
[0].chan
= 2;
5415 alu
.src
[1].sel
= tmp0
;
5416 alu
.src
[1].chan
= 0;
5419 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5423 /* 7. tmp1.x = tmp0.x - tmp0.w */
5424 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5425 alu
.op
= ALU_OP2_SUB_INT
;
5431 alu
.src
[0].sel
= tmp0
;
5432 alu
.src
[0].chan
= 0;
5433 alu
.src
[1].sel
= tmp0
;
5434 alu
.src
[1].chan
= 3;
5437 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5440 /* 8. tmp1.y = tmp0.x + tmp0.w */
5441 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5442 alu
.op
= ALU_OP2_ADD_INT
;
5448 alu
.src
[0].sel
= tmp0
;
5449 alu
.src
[0].chan
= 0;
5450 alu
.src
[1].sel
= tmp0
;
5451 alu
.src
[1].chan
= 3;
5454 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5457 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5459 alu
.op
= ALU_OP3_CNDE_INT
;
5466 alu
.src
[0].sel
= tmp0
;
5467 alu
.src
[0].chan
= 1;
5468 alu
.src
[1].sel
= tmp1
;
5469 alu
.src
[1].chan
= 1;
5470 alu
.src
[2].sel
= tmp1
;
5471 alu
.src
[2].chan
= 0;
5474 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5477 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5478 if (ctx
->bc
->chip_class
== CAYMAN
) {
5479 for (j
= 0 ; j
< 4; j
++) {
5480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5481 alu
.op
= ALU_OP2_MULHI_UINT
;
5485 alu
.dst
.write
= (j
== 2);
5487 alu
.src
[0].sel
= tmp0
;
5488 alu
.src
[0].chan
= 0;
5491 alu
.src
[1].sel
= tmp2
;
5492 alu
.src
[1].chan
= 0;
5494 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5497 alu
.last
= (j
== 3);
5498 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5502 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5503 alu
.op
= ALU_OP2_MULHI_UINT
;
5509 alu
.src
[0].sel
= tmp0
;
5510 alu
.src
[0].chan
= 0;
5513 alu
.src
[1].sel
= tmp2
;
5514 alu
.src
[1].chan
= 0;
5516 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5520 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5524 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5525 if (ctx
->bc
->chip_class
== CAYMAN
) {
5526 for (j
= 0 ; j
< 4; j
++) {
5527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5528 alu
.op
= ALU_OP2_MULLO_UINT
;
5532 alu
.dst
.write
= (j
== 1);
5535 alu
.src
[0].sel
= tmp2
;
5536 alu
.src
[0].chan
= 1;
5538 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5541 alu
.src
[1].sel
= tmp0
;
5542 alu
.src
[1].chan
= 2;
5544 alu
.last
= (j
== 3);
5545 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5550 alu
.op
= ALU_OP2_MULLO_UINT
;
5557 alu
.src
[0].sel
= tmp2
;
5558 alu
.src
[0].chan
= 1;
5560 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5563 alu
.src
[1].sel
= tmp0
;
5564 alu
.src
[1].chan
= 2;
5567 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5571 /* 12. tmp0.w = src1 - tmp0.y = r */
5572 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5573 alu
.op
= ALU_OP2_SUB_INT
;
5580 alu
.src
[0].sel
= tmp2
;
5581 alu
.src
[0].chan
= 0;
5583 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5586 alu
.src
[1].sel
= tmp0
;
5587 alu
.src
[1].chan
= 1;
5590 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5593 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5595 alu
.op
= ALU_OP2_SETGE_UINT
;
5601 alu
.src
[0].sel
= tmp0
;
5602 alu
.src
[0].chan
= 3;
5604 alu
.src
[1].sel
= tmp2
;
5605 alu
.src
[1].chan
= 1;
5607 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5611 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5614 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5616 alu
.op
= ALU_OP2_SETGE_UINT
;
5623 alu
.src
[0].sel
= tmp2
;
5624 alu
.src
[0].chan
= 0;
5626 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5629 alu
.src
[1].sel
= tmp0
;
5630 alu
.src
[1].chan
= 1;
5633 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5636 if (mod
) { /* UMOD */
5638 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5639 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5640 alu
.op
= ALU_OP2_SUB_INT
;
5646 alu
.src
[0].sel
= tmp0
;
5647 alu
.src
[0].chan
= 3;
5650 alu
.src
[1].sel
= tmp2
;
5651 alu
.src
[1].chan
= 1;
5653 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5657 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5660 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5661 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5662 alu
.op
= ALU_OP2_ADD_INT
;
5668 alu
.src
[0].sel
= tmp0
;
5669 alu
.src
[0].chan
= 3;
5671 alu
.src
[1].sel
= tmp2
;
5672 alu
.src
[1].chan
= 1;
5674 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5678 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5683 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5684 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5685 alu
.op
= ALU_OP2_ADD_INT
;
5691 alu
.src
[0].sel
= tmp0
;
5692 alu
.src
[0].chan
= 2;
5693 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5696 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5699 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5701 alu
.op
= ALU_OP2_ADD_INT
;
5707 alu
.src
[0].sel
= tmp0
;
5708 alu
.src
[0].chan
= 2;
5709 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5712 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5717 /* 17. tmp1.x = tmp1.x & tmp1.y */
5718 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5719 alu
.op
= ALU_OP2_AND_INT
;
5725 alu
.src
[0].sel
= tmp1
;
5726 alu
.src
[0].chan
= 0;
5727 alu
.src
[1].sel
= tmp1
;
5728 alu
.src
[1].chan
= 1;
5731 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5734 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5735 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5736 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5737 alu
.op
= ALU_OP3_CNDE_INT
;
5744 alu
.src
[0].sel
= tmp1
;
5745 alu
.src
[0].chan
= 0;
5746 alu
.src
[1].sel
= tmp0
;
5747 alu
.src
[1].chan
= mod
? 3 : 2;
5748 alu
.src
[2].sel
= tmp1
;
5749 alu
.src
[2].chan
= 2;
5752 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5755 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5756 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5757 alu
.op
= ALU_OP3_CNDE_INT
;
5765 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5768 alu
.src
[0].sel
= tmp1
;
5769 alu
.src
[0].chan
= 1;
5770 alu
.src
[1].sel
= tmp1
;
5771 alu
.src
[1].chan
= 3;
5772 alu
.src
[2].sel
= tmp0
;
5773 alu
.src
[2].chan
= 2;
5776 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5781 /* fix the sign of the result */
5785 /* tmp0.x = -tmp0.z */
5786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5787 alu
.op
= ALU_OP2_SUB_INT
;
5793 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5794 alu
.src
[1].sel
= tmp0
;
5795 alu
.src
[1].chan
= 2;
5798 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5801 /* sign of the remainder is the same as the sign of src0 */
5802 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
5803 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5804 alu
.op
= ALU_OP3_CNDGE_INT
;
5807 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5809 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5810 alu
.src
[1].sel
= tmp0
;
5811 alu
.src
[1].chan
= 2;
5812 alu
.src
[2].sel
= tmp0
;
5813 alu
.src
[2].chan
= 0;
5816 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5821 /* tmp0.x = -tmp0.z */
5822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5823 alu
.op
= ALU_OP2_SUB_INT
;
5829 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5830 alu
.src
[1].sel
= tmp0
;
5831 alu
.src
[1].chan
= 2;
5834 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5837 /* fix the quotient sign (same as the sign of src0*src1) */
5838 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
5839 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5840 alu
.op
= ALU_OP3_CNDGE_INT
;
5843 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5845 alu
.src
[0].sel
= tmp2
;
5846 alu
.src
[0].chan
= 2;
5847 alu
.src
[1].sel
= tmp0
;
5848 alu
.src
[1].chan
= 2;
5849 alu
.src
[2].sel
= tmp0
;
5850 alu
.src
[2].chan
= 0;
5853 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5861 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
5863 return tgsi_divmod(ctx
, 0, 0);
5866 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
5868 return tgsi_divmod(ctx
, 1, 0);
5871 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
5873 return tgsi_divmod(ctx
, 0, 1);
5876 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
5878 return tgsi_divmod(ctx
, 1, 1);
5882 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
5884 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5885 struct r600_bytecode_alu alu
;
5887 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5888 int last_inst
= tgsi_last_instruction(write_mask
);
5890 for (i
= 0; i
< 4; i
++) {
5891 if (!(write_mask
& (1<<i
)))
5894 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5895 alu
.op
= ALU_OP1_TRUNC
;
5897 alu
.dst
.sel
= ctx
->temp_reg
;
5901 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5904 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5909 for (i
= 0; i
< 4; i
++) {
5910 if (!(write_mask
& (1<<i
)))
5913 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5914 alu
.op
= ctx
->inst_info
->op
;
5916 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5918 alu
.src
[0].sel
= ctx
->temp_reg
;
5919 alu
.src
[0].chan
= i
;
5921 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
5923 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5931 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
5933 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5934 struct r600_bytecode_alu alu
;
5936 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5937 int last_inst
= tgsi_last_instruction(write_mask
);
5940 for (i
= 0; i
< 4; i
++) {
5941 if (!(write_mask
& (1<<i
)))
5944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5945 alu
.op
= ALU_OP2_SUB_INT
;
5947 alu
.dst
.sel
= ctx
->temp_reg
;
5951 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5952 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5961 /* dst = (src >= 0 ? src : tmp) */
5962 for (i
= 0; i
< 4; i
++) {
5963 if (!(write_mask
& (1<<i
)))
5966 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5967 alu
.op
= ALU_OP3_CNDGE_INT
;
5971 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5973 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5974 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5975 alu
.src
[2].sel
= ctx
->temp_reg
;
5976 alu
.src
[2].chan
= i
;
5980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5987 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
5989 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5990 struct r600_bytecode_alu alu
;
5992 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5993 int last_inst
= tgsi_last_instruction(write_mask
);
5995 /* tmp = (src >= 0 ? src : -1) */
5996 for (i
= 0; i
< 4; i
++) {
5997 if (!(write_mask
& (1<<i
)))
6000 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6001 alu
.op
= ALU_OP3_CNDGE_INT
;
6004 alu
.dst
.sel
= ctx
->temp_reg
;
6008 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6009 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6010 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6019 /* dst = (tmp > 0 ? 1 : tmp) */
6020 for (i
= 0; i
< 4; i
++) {
6021 if (!(write_mask
& (1<<i
)))
6024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6025 alu
.op
= ALU_OP3_CNDGT_INT
;
6029 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6031 alu
.src
[0].sel
= ctx
->temp_reg
;
6032 alu
.src
[0].chan
= i
;
6034 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6036 alu
.src
[2].sel
= ctx
->temp_reg
;
6037 alu
.src
[2].chan
= i
;
6041 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6050 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6052 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6053 struct r600_bytecode_alu alu
;
6056 /* tmp = (src > 0 ? 1 : src) */
6057 for (i
= 0; i
< 4; i
++) {
6058 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6059 alu
.op
= ALU_OP3_CNDGT
;
6062 alu
.dst
.sel
= ctx
->temp_reg
;
6065 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6066 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6067 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6071 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6076 /* dst = (-tmp > 0 ? -1 : tmp) */
6077 for (i
= 0; i
< 4; i
++) {
6078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6079 alu
.op
= ALU_OP3_CNDGT
;
6081 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6083 alu
.src
[0].sel
= ctx
->temp_reg
;
6084 alu
.src
[0].chan
= i
;
6087 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6090 alu
.src
[2].sel
= ctx
->temp_reg
;
6091 alu
.src
[2].chan
= i
;
6095 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6102 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6104 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6105 struct r600_bytecode_alu alu
;
6108 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6109 int last_inst
= tgsi_last_instruction(write_mask
);
6111 t1
= r600_get_temp(ctx
);
6113 for (i
= 0; i
< 4; i
++) {
6114 if (!(write_mask
& (1<<i
)))
6117 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6118 alu
.op
= ALU_OP2_SETGE_INT
;
6119 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6120 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6121 alu
.src
[1].value
= 32;
6122 alu
.dst
.sel
= ctx
->temp_reg
;
6125 alu
.last
= i
== last_inst
;
6126 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6131 for (i
= 0; i
< 4; i
++) {
6132 if (!(write_mask
& (1<<i
)))
6135 /* create mask tmp */
6136 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6137 alu
.op
= ALU_OP2_BFM_INT
;
6141 alu
.last
= i
== last_inst
;
6143 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6144 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6146 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6151 t2
= r600_get_temp(ctx
);
6153 for (i
= 0; i
< 4; i
++) {
6154 if (!(write_mask
& (1<<i
)))
6157 /* shift insert left */
6158 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6159 alu
.op
= ALU_OP2_LSHL_INT
;
6163 alu
.last
= i
== last_inst
;
6165 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6166 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6168 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6173 for (i
= 0; i
< 4; i
++) {
6174 if (!(write_mask
& (1<<i
)))
6177 /* actual bitfield insert */
6178 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6179 alu
.op
= ALU_OP3_BFI_INT
;
6181 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6184 alu
.last
= i
== last_inst
;
6186 alu
.src
[0].sel
= t1
;
6187 alu
.src
[0].chan
= i
;
6188 alu
.src
[1].sel
= t2
;
6189 alu
.src
[1].chan
= i
;
6190 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6192 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6197 for (i
= 0; i
< 4; i
++) {
6198 if (!(write_mask
& (1<<i
)))
6200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6201 alu
.op
= ALU_OP3_CNDE_INT
;
6203 alu
.src
[0].sel
= ctx
->temp_reg
;
6204 alu
.src
[0].chan
= i
;
6205 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6207 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6209 alu
.src
[1].sel
= alu
.dst
.sel
;
6210 alu
.src
[1].chan
= i
;
6212 alu
.last
= i
== last_inst
;
6213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6220 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6222 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6223 struct r600_bytecode_alu alu
;
6226 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6227 int last_inst
= tgsi_last_instruction(write_mask
);
6229 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6230 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6234 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6235 for (i
= 0; i
< 4; i
++) {
6236 if (!(write_mask
& (1<<i
)))
6239 /* t1 = FFBH_INT / FFBH_UINT */
6240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6241 alu
.op
= ctx
->inst_info
->op
;
6245 alu
.last
= i
== last_inst
;
6247 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6254 t2
= r600_get_temp(ctx
);
6256 for (i
= 0; i
< 4; i
++) {
6257 if (!(write_mask
& (1<<i
)))
6261 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6262 alu
.op
= ALU_OP2_SUB_INT
;
6266 alu
.last
= i
== last_inst
;
6268 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6269 alu
.src
[0].value
= 31;
6270 alu
.src
[1].sel
= t1
;
6271 alu
.src
[1].chan
= i
;
6273 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6278 for (i
= 0; i
< 4; i
++) {
6279 if (!(write_mask
& (1<<i
)))
6282 /* result = t1 >= 0 ? t2 : t1 */
6283 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6284 alu
.op
= ALU_OP3_CNDGE_INT
;
6286 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6289 alu
.last
= i
== last_inst
;
6291 alu
.src
[0].sel
= t1
;
6292 alu
.src
[0].chan
= i
;
6293 alu
.src
[1].sel
= t2
;
6294 alu
.src
[1].chan
= i
;
6295 alu
.src
[2].sel
= t1
;
6296 alu
.src
[2].chan
= i
;
6298 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6306 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6308 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6309 struct r600_bytecode_alu alu
;
6310 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6312 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6314 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6316 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6317 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6318 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6319 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6322 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6325 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6328 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6329 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6331 /* NOTE: currently offset is not perspective correct */
6332 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6333 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6334 int sample_gpr
= -1;
6335 int gradientsH
, gradientsV
;
6336 struct r600_bytecode_tex tex
;
6338 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6339 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6342 gradientsH
= r600_get_temp(ctx
);
6343 gradientsV
= r600_get_temp(ctx
);
6344 for (i
= 0; i
< 2; i
++) {
6345 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6346 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6347 tex
.src_gpr
= interp_gpr
;
6348 tex
.src_sel_x
= interp_base_chan
+ 0;
6349 tex
.src_sel_y
= interp_base_chan
+ 1;
6352 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6357 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6359 tex
.resource_id
= tex
.sampler_id
;
6360 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6365 for (i
= 0; i
< 2; i
++) {
6366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6367 alu
.op
= ALU_OP3_MULADD
;
6369 alu
.src
[0].sel
= gradientsH
;
6370 alu
.src
[0].chan
= i
;
6371 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6372 alu
.src
[1].sel
= sample_gpr
;
6373 alu
.src
[1].chan
= 2;
6376 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6378 alu
.src
[2].sel
= interp_gpr
;
6379 alu
.src
[2].chan
= interp_base_chan
+ i
;
6380 alu
.dst
.sel
= ctx
->temp_reg
;
6384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6389 for (i
= 0; i
< 2; i
++) {
6390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6391 alu
.op
= ALU_OP3_MULADD
;
6393 alu
.src
[0].sel
= gradientsV
;
6394 alu
.src
[0].chan
= i
;
6395 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6396 alu
.src
[1].sel
= sample_gpr
;
6397 alu
.src
[1].chan
= 3;
6400 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6402 alu
.src
[2].sel
= ctx
->temp_reg
;
6403 alu
.src
[2].chan
= i
;
6404 alu
.dst
.sel
= ctx
->temp_reg
;
6408 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6414 tmp
= r600_get_temp(ctx
);
6415 for (i
= 0; i
< 8; i
++) {
6416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6417 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6420 if ((i
> 1 && i
< 6)) {
6426 alu
.dst
.chan
= i
% 4;
6428 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6429 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6430 alu
.src
[0].sel
= ctx
->temp_reg
;
6431 alu
.src
[0].chan
= 1 - (i
% 2);
6433 alu
.src
[0].sel
= interp_gpr
;
6434 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6436 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6437 alu
.src
[1].chan
= 0;
6439 alu
.last
= i
% 4 == 3;
6440 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6442 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6447 // INTERP can't swizzle dst
6448 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6449 for (i
= 0; i
<= lasti
; i
++) {
6450 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6453 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6454 alu
.op
= ALU_OP1_MOV
;
6455 alu
.src
[0].sel
= tmp
;
6456 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6457 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6459 alu
.last
= i
== lasti
;
6460 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6469 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6471 struct r600_bytecode_alu alu
;
6474 for (i
= 0; i
< 4; i
++) {
6475 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6476 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6477 alu
.op
= ALU_OP0_NOP
;
6480 alu
.op
= ALU_OP1_MOV
;
6481 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6482 alu
.src
[0].sel
= ctx
->temp_reg
;
6483 alu
.src
[0].chan
= i
;
6488 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6495 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6496 unsigned temp
, int chan
,
6497 struct r600_bytecode_alu_src
*bc_src
,
6498 const struct r600_shader_src
*shader_src
)
6500 struct r600_bytecode_alu alu
;
6503 r600_bytecode_src(bc_src
, shader_src
, chan
);
6505 /* op3 operands don't support abs modifier */
6507 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6508 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6509 alu
.op
= ALU_OP1_MOV
;
6511 alu
.dst
.chan
= chan
;
6514 alu
.src
[0] = *bc_src
;
6515 alu
.last
= true; // sufficient?
6516 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6520 memset(bc_src
, 0, sizeof(*bc_src
));
6522 bc_src
->chan
= chan
;
6527 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6529 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6530 struct r600_bytecode_alu alu
;
6532 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6534 unsigned op
= ctx
->inst_info
->op
;
6536 if (op
== ALU_OP3_MULADD_IEEE
&&
6537 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6538 op
= ALU_OP3_MULADD
;
6540 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6542 if (ctx
->src
[j
].abs
)
6543 temp_regs
[j
] = r600_get_temp(ctx
);
6545 for (i
= 0; i
< lasti
+ 1; i
++) {
6546 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6551 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6552 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6557 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6564 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6571 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6573 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6574 struct r600_bytecode_alu alu
;
6576 unsigned op
= ctx
->inst_info
->op
;
6577 if (op
== ALU_OP2_DOT4_IEEE
&&
6578 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6581 for (i
= 0; i
< 4; i
++) {
6582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6584 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6585 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6588 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6590 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6591 /* handle some special cases */
6592 switch (inst
->Instruction
.Opcode
) {
6593 case TGSI_OPCODE_DP2
:
6595 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6596 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6599 case TGSI_OPCODE_DP3
:
6601 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6602 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6611 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6618 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6621 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6622 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6623 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6624 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6625 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6626 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6629 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6632 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6633 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6636 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6638 struct r600_bytecode_vtx vtx
;
6639 struct r600_bytecode_alu alu
;
6640 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6642 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6644 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6645 if (src_requires_loading
) {
6646 for (i
= 0; i
< 4; i
++) {
6647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6648 alu
.op
= ALU_OP1_MOV
;
6649 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6650 alu
.dst
.sel
= ctx
->temp_reg
;
6655 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6659 src_gpr
= ctx
->temp_reg
;
6662 memset(&vtx
, 0, sizeof(vtx
));
6663 vtx
.op
= FETCH_OP_VFETCH
;
6664 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6665 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6666 vtx
.src_gpr
= src_gpr
;
6667 vtx
.mega_fetch_count
= 16;
6668 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6669 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6670 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6671 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6672 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6673 vtx
.use_const_fields
= 1;
6675 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6678 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6681 for (i
= 0; i
< 4; i
++) {
6682 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6683 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6686 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6687 alu
.op
= ALU_OP2_AND_INT
;
6690 alu
.dst
.sel
= vtx
.dst_gpr
;
6693 alu
.src
[0].sel
= vtx
.dst_gpr
;
6694 alu
.src
[0].chan
= i
;
6696 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6697 alu
.src
[1].sel
+= (id
* 2);
6698 alu
.src
[1].chan
= i
% 4;
6699 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6703 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6708 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6710 alu
.op
= ALU_OP2_OR_INT
;
6713 alu
.dst
.sel
= vtx
.dst_gpr
;
6716 alu
.src
[0].sel
= vtx
.dst_gpr
;
6717 alu
.src
[0].chan
= 3;
6719 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6720 alu
.src
[1].chan
= 0;
6721 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6724 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6731 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
6733 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6734 struct r600_bytecode_alu alu
;
6736 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6738 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6739 alu
.op
= ALU_OP1_MOV
;
6740 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6741 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6742 /* channel 0 or 2 of each word */
6743 alu
.src
[0].sel
+= (id
/ 2);
6744 alu
.src
[0].chan
= (id
% 2) * 2;
6746 /* r600 we have them at channel 2 of the second dword */
6747 alu
.src
[0].sel
+= (id
* 2) + 1;
6748 alu
.src
[0].chan
= 1;
6750 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6751 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6753 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6759 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6761 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6762 struct r600_bytecode_tex tex
;
6763 struct r600_bytecode_alu alu
;
6767 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
6768 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6769 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
6770 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
6772 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
6773 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6774 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
6776 /* Texture fetch instructions can only use gprs as source.
6777 * Also they cannot negate the source or take the absolute value */
6778 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
6779 tgsi_tex_src_requires_loading(ctx
, 0)) ||
6780 read_compressed_msaa
|| txf_add_offsets
;
6782 boolean src_loaded
= FALSE
;
6783 unsigned sampler_src_reg
= 1;
6784 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
6785 boolean has_txq_cube_array_z
= false;
6786 unsigned sampler_index_mode
;
6788 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
6789 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6790 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
6791 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
6792 ctx
->shader
->has_txq_cube_array_z_comp
= true;
6793 has_txq_cube_array_z
= true;
6796 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
6797 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6798 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
6799 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
6800 sampler_src_reg
= 2;
6802 /* TGSI moves the sampler to src reg 3 for TXD */
6803 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
6804 sampler_src_reg
= 3;
6806 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6808 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6810 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
6811 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
6812 ctx
->shader
->uses_tex_buffers
= true;
6813 return r600_do_buffer_txq(ctx
);
6815 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
6816 if (ctx
->bc
->chip_class
< EVERGREEN
)
6817 ctx
->shader
->uses_tex_buffers
= true;
6818 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
6822 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
6824 /* Add perspective divide */
6825 if (ctx
->bc
->chip_class
== CAYMAN
) {
6827 for (i
= 0; i
< 3; i
++) {
6828 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6829 alu
.op
= ALU_OP1_RECIP_IEEE
;
6830 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6832 alu
.dst
.sel
= ctx
->temp_reg
;
6838 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6845 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6846 alu
.op
= ALU_OP1_RECIP_IEEE
;
6847 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6849 alu
.dst
.sel
= ctx
->temp_reg
;
6850 alu
.dst
.chan
= out_chan
;
6853 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6858 for (i
= 0; i
< 3; i
++) {
6859 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6860 alu
.op
= ALU_OP2_MUL
;
6861 alu
.src
[0].sel
= ctx
->temp_reg
;
6862 alu
.src
[0].chan
= out_chan
;
6863 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6864 alu
.dst
.sel
= ctx
->temp_reg
;
6867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6872 alu
.op
= ALU_OP1_MOV
;
6873 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6874 alu
.src
[0].chan
= 0;
6875 alu
.dst
.sel
= ctx
->temp_reg
;
6879 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6883 src_gpr
= ctx
->temp_reg
;
6887 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
6888 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6889 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6890 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
6891 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
6893 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
6894 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
6896 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
6897 for (i
= 0; i
< 4; i
++) {
6898 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6899 alu
.op
= ALU_OP2_CUBE
;
6900 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
6901 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
6902 alu
.dst
.sel
= ctx
->temp_reg
;
6907 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6912 /* tmp1.z = RCP_e(|tmp1.z|) */
6913 if (ctx
->bc
->chip_class
== CAYMAN
) {
6914 for (i
= 0; i
< 3; i
++) {
6915 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6916 alu
.op
= ALU_OP1_RECIP_IEEE
;
6917 alu
.src
[0].sel
= ctx
->temp_reg
;
6918 alu
.src
[0].chan
= 2;
6920 alu
.dst
.sel
= ctx
->temp_reg
;
6926 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6931 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6932 alu
.op
= ALU_OP1_RECIP_IEEE
;
6933 alu
.src
[0].sel
= ctx
->temp_reg
;
6934 alu
.src
[0].chan
= 2;
6936 alu
.dst
.sel
= ctx
->temp_reg
;
6940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6945 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
6946 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
6947 * muladd has no writemask, have to use another temp
6949 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6950 alu
.op
= ALU_OP3_MULADD
;
6953 alu
.src
[0].sel
= ctx
->temp_reg
;
6954 alu
.src
[0].chan
= 0;
6955 alu
.src
[1].sel
= ctx
->temp_reg
;
6956 alu
.src
[1].chan
= 2;
6958 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
6959 alu
.src
[2].chan
= 0;
6960 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
6962 alu
.dst
.sel
= ctx
->temp_reg
;
6966 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6970 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6971 alu
.op
= ALU_OP3_MULADD
;
6974 alu
.src
[0].sel
= ctx
->temp_reg
;
6975 alu
.src
[0].chan
= 1;
6976 alu
.src
[1].sel
= ctx
->temp_reg
;
6977 alu
.src
[1].chan
= 2;
6979 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
6980 alu
.src
[2].chan
= 0;
6981 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
6983 alu
.dst
.sel
= ctx
->temp_reg
;
6988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6991 /* write initial compare value into Z component
6992 - W src 0 for shadow cube
6993 - X src 1 for shadow cube array */
6994 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6995 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
6996 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6997 alu
.op
= ALU_OP1_MOV
;
6998 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
6999 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7001 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7002 alu
.dst
.sel
= ctx
->temp_reg
;
7006 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7011 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7012 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7013 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7014 int mytmp
= r600_get_temp(ctx
);
7015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7016 alu
.op
= ALU_OP1_MOV
;
7017 alu
.src
[0].sel
= ctx
->temp_reg
;
7018 alu
.src
[0].chan
= 3;
7019 alu
.dst
.sel
= mytmp
;
7023 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7027 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7029 alu
.op
= ALU_OP3_MULADD
;
7031 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7032 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7033 alu
.src
[1].chan
= 0;
7034 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7035 alu
.src
[2].sel
= mytmp
;
7036 alu
.src
[2].chan
= 0;
7037 alu
.dst
.sel
= ctx
->temp_reg
;
7041 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7044 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7045 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7046 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7047 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7048 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7049 tex
.src_gpr
= r600_get_temp(ctx
);
7054 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7055 tex
.coord_type_x
= 1;
7056 tex
.coord_type_y
= 1;
7057 tex
.coord_type_z
= 1;
7058 tex
.coord_type_w
= 1;
7059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7060 alu
.op
= ALU_OP1_MOV
;
7061 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7062 alu
.dst
.sel
= tex
.src_gpr
;
7066 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7070 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7077 /* for cube forms of lod and bias we need to route things */
7078 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7079 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7080 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7081 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7083 alu
.op
= ALU_OP1_MOV
;
7084 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7085 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7086 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7088 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7089 alu
.dst
.sel
= ctx
->temp_reg
;
7093 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7099 src_gpr
= ctx
->temp_reg
;
7102 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7103 int temp_h
= 0, temp_v
= 0;
7106 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7107 if (src_loaded
== TRUE
)
7111 for (i
= start_val
; i
< 3; i
++) {
7112 int treg
= r600_get_temp(ctx
);
7121 for (j
= 0; j
< 4; j
++) {
7122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7123 alu
.op
= ALU_OP1_MOV
;
7124 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7130 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7135 for (i
= 1; i
< 3; i
++) {
7136 /* set gradients h/v */
7137 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7138 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7139 FETCH_OP_SET_GRADIENTS_V
;
7140 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7141 tex
.sampler_index_mode
= sampler_index_mode
;
7142 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7143 tex
.resource_index_mode
= sampler_index_mode
;
7145 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7151 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7152 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7153 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7154 tex
.coord_type_x
= 1;
7155 tex
.coord_type_y
= 1;
7156 tex
.coord_type_z
= 1;
7157 tex
.coord_type_w
= 1;
7159 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7165 if (src_requires_loading
&& !src_loaded
) {
7166 for (i
= 0; i
< 4; i
++) {
7167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7168 alu
.op
= ALU_OP1_MOV
;
7169 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7170 alu
.dst
.sel
= ctx
->temp_reg
;
7175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7180 src_gpr
= ctx
->temp_reg
;
7183 /* get offset values */
7184 if (inst
->Texture
.NumOffsets
) {
7185 assert(inst
->Texture
.NumOffsets
== 1);
7187 /* The texture offset feature doesn't work with the TXF instruction
7188 * and must be emulated by adding the offset to the texture coordinates. */
7189 if (txf_add_offsets
) {
7190 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7192 switch (inst
->Texture
.Texture
) {
7193 case TGSI_TEXTURE_3D
:
7194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7195 alu
.op
= ALU_OP2_ADD_INT
;
7196 alu
.src
[0].sel
= src_gpr
;
7197 alu
.src
[0].chan
= 2;
7198 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7199 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7200 alu
.dst
.sel
= src_gpr
;
7204 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7209 case TGSI_TEXTURE_2D
:
7210 case TGSI_TEXTURE_SHADOW2D
:
7211 case TGSI_TEXTURE_RECT
:
7212 case TGSI_TEXTURE_SHADOWRECT
:
7213 case TGSI_TEXTURE_2D_ARRAY
:
7214 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7215 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7216 alu
.op
= ALU_OP2_ADD_INT
;
7217 alu
.src
[0].sel
= src_gpr
;
7218 alu
.src
[0].chan
= 1;
7219 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7220 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7221 alu
.dst
.sel
= src_gpr
;
7225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7230 case TGSI_TEXTURE_1D
:
7231 case TGSI_TEXTURE_SHADOW1D
:
7232 case TGSI_TEXTURE_1D_ARRAY
:
7233 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7234 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7235 alu
.op
= ALU_OP2_ADD_INT
;
7236 alu
.src
[0].sel
= src_gpr
;
7237 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7238 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7239 alu
.dst
.sel
= src_gpr
;
7242 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7246 /* texture offsets do not apply to other texture targets */
7249 switch (inst
->Texture
.Texture
) {
7250 case TGSI_TEXTURE_3D
:
7251 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7253 case TGSI_TEXTURE_2D
:
7254 case TGSI_TEXTURE_SHADOW2D
:
7255 case TGSI_TEXTURE_RECT
:
7256 case TGSI_TEXTURE_SHADOWRECT
:
7257 case TGSI_TEXTURE_2D_ARRAY
:
7258 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7259 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7261 case TGSI_TEXTURE_1D
:
7262 case TGSI_TEXTURE_SHADOW1D
:
7263 case TGSI_TEXTURE_1D_ARRAY
:
7264 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7265 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7270 /* Obtain the sample index for reading a compressed MSAA color texture.
7271 * To read the FMASK, we use the ldfptr instruction, which tells us
7272 * where the samples are stored.
7273 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7274 * which is the identity mapping. Each nibble says which physical sample
7275 * should be fetched to get that sample.
7277 * Assume src.z contains the sample index. It should be modified like this:
7278 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7279 * Then fetch the texel with src.
7281 if (read_compressed_msaa
) {
7282 unsigned sample_chan
= 3;
7283 unsigned temp
= r600_get_temp(ctx
);
7286 /* temp.w = ldfptr() */
7287 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7288 tex
.op
= FETCH_OP_LD
;
7289 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7290 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7291 tex
.sampler_index_mode
= sampler_index_mode
;
7292 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7293 tex
.resource_index_mode
= sampler_index_mode
;
7294 tex
.src_gpr
= src_gpr
;
7296 tex
.dst_sel_x
= 7; /* mask out these components */
7299 tex
.dst_sel_w
= 0; /* store X */
7304 tex
.offset_x
= offset_x
;
7305 tex
.offset_y
= offset_y
;
7306 tex
.offset_z
= offset_z
;
7307 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7311 /* temp.x = sample_index*4 */
7312 if (ctx
->bc
->chip_class
== CAYMAN
) {
7313 for (i
= 0 ; i
< 4; i
++) {
7314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7315 alu
.op
= ALU_OP2_MULLO_INT
;
7316 alu
.src
[0].sel
= src_gpr
;
7317 alu
.src
[0].chan
= sample_chan
;
7318 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7319 alu
.src
[1].value
= 4;
7322 alu
.dst
.write
= i
== 0;
7325 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7330 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7331 alu
.op
= ALU_OP2_MULLO_INT
;
7332 alu
.src
[0].sel
= src_gpr
;
7333 alu
.src
[0].chan
= sample_chan
;
7334 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7335 alu
.src
[1].value
= 4;
7340 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7345 /* sample_index = temp.w >> temp.x */
7346 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7347 alu
.op
= ALU_OP2_LSHR_INT
;
7348 alu
.src
[0].sel
= temp
;
7349 alu
.src
[0].chan
= 3;
7350 alu
.src
[1].sel
= temp
;
7351 alu
.src
[1].chan
= 0;
7352 alu
.dst
.sel
= src_gpr
;
7353 alu
.dst
.chan
= sample_chan
;
7356 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7360 /* sample_index & 0xF */
7361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7362 alu
.op
= ALU_OP2_AND_INT
;
7363 alu
.src
[0].sel
= src_gpr
;
7364 alu
.src
[0].chan
= sample_chan
;
7365 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7366 alu
.src
[1].value
= 0xF;
7367 alu
.dst
.sel
= src_gpr
;
7368 alu
.dst
.chan
= sample_chan
;
7371 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7375 /* visualize the FMASK */
7376 for (i
= 0; i
< 4; i
++) {
7377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7378 alu
.op
= ALU_OP1_INT_TO_FLT
;
7379 alu
.src
[0].sel
= src_gpr
;
7380 alu
.src
[0].chan
= sample_chan
;
7381 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7385 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7393 /* does this shader want a num layers from TXQ for a cube array? */
7394 if (has_txq_cube_array_z
) {
7395 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7397 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7398 alu
.op
= ALU_OP1_MOV
;
7400 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7401 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7402 /* channel 1 or 3 of each word */
7403 alu
.src
[0].sel
+= (id
/ 2);
7404 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
7406 /* r600 we have them at channel 2 of the second dword */
7407 alu
.src
[0].sel
+= (id
* 2) + 1;
7408 alu
.src
[0].chan
= 2;
7410 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7411 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7413 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7416 /* disable writemask from texture instruction */
7417 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7420 opcode
= ctx
->inst_info
->op
;
7421 if (opcode
== FETCH_OP_GATHER4
&&
7422 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7423 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7424 opcode
= FETCH_OP_GATHER4_O
;
7426 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7427 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7428 encoded in the instruction are ignored. */
7429 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7430 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7431 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7432 tex
.sampler_index_mode
= sampler_index_mode
;
7433 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7434 tex
.resource_index_mode
= sampler_index_mode
;
7436 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7437 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7438 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7439 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7447 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7452 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7453 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7454 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7455 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7456 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7457 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7458 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7460 case FETCH_OP_SAMPLE
:
7461 opcode
= FETCH_OP_SAMPLE_C
;
7463 case FETCH_OP_SAMPLE_L
:
7464 opcode
= FETCH_OP_SAMPLE_C_L
;
7466 case FETCH_OP_SAMPLE_LB
:
7467 opcode
= FETCH_OP_SAMPLE_C_LB
;
7469 case FETCH_OP_SAMPLE_G
:
7470 opcode
= FETCH_OP_SAMPLE_C_G
;
7472 /* Texture gather variants */
7473 case FETCH_OP_GATHER4
:
7474 opcode
= FETCH_OP_GATHER4_C
;
7476 case FETCH_OP_GATHER4_O
:
7477 opcode
= FETCH_OP_GATHER4_C_O
;
7482 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7485 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7486 tex
.sampler_index_mode
= sampler_index_mode
;
7487 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7488 tex
.resource_index_mode
= sampler_index_mode
;
7489 tex
.src_gpr
= src_gpr
;
7490 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7492 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7493 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7494 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7497 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7498 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7499 tex
.inst_mod
= texture_component_select
;
7501 if (ctx
->bc
->chip_class
== CAYMAN
) {
7502 /* GATHER4 result order is different from TGSI TG4 */
7503 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7504 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7505 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7506 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7508 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7509 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7510 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7511 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7514 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7515 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7516 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7520 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7527 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7528 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7529 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7530 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7534 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7539 } else if (src_loaded
) {
7545 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7546 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7547 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7548 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7549 tex
.src_rel
= ctx
->src
[0].rel
;
7552 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7553 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7554 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7555 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7559 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7562 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7563 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7564 tex
.coord_type_x
= 1;
7565 tex
.coord_type_y
= 1;
7567 tex
.coord_type_z
= 1;
7568 tex
.coord_type_w
= 1;
7570 tex
.offset_x
= offset_x
;
7571 tex
.offset_y
= offset_y
;
7572 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7573 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7574 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7578 tex
.offset_z
= offset_z
;
7581 /* Put the depth for comparison in W.
7582 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7583 * Some instructions expect the depth in Z. */
7584 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7585 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7586 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7587 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7588 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7589 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7590 tex
.src_sel_w
= tex
.src_sel_z
;
7593 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7594 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7595 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7596 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7597 /* the array index is read from Y */
7598 tex
.coord_type_y
= 0;
7600 /* the array index is read from Z */
7601 tex
.coord_type_z
= 0;
7602 tex
.src_sel_z
= tex
.src_sel_y
;
7604 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7605 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7606 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7607 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7608 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7609 /* the array index is read from Z */
7610 tex
.coord_type_z
= 0;
7612 /* mask unused source components */
7613 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7614 switch (inst
->Texture
.Texture
) {
7615 case TGSI_TEXTURE_2D
:
7616 case TGSI_TEXTURE_RECT
:
7620 case TGSI_TEXTURE_1D_ARRAY
:
7624 case TGSI_TEXTURE_1D
:
7632 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7636 /* add shadow ambient support - gallium doesn't do it yet */
7640 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7641 struct tgsi_full_src_register
*src
)
7645 if (src
->Register
.Indirect
) {
7646 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7647 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7648 return ctx
->shader
->atomics
[i
].hw_idx
;
7651 uint32_t index
= src
->Register
.Index
;
7652 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7653 if (ctx
->shader
->atomics
[i
].buffer_id
!= src
->Dimension
.Index
)
7655 if (index
> ctx
->shader
->atomics
[i
].end
)
7657 if (index
< ctx
->shader
->atomics
[i
].start
)
7659 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7660 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7668 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
7670 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7672 struct r600_bytecode_gds gds
;
7674 int uav_index_mode
= 0;
7676 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7678 if (inst
->Src
[0].Register
.Indirect
)
7681 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7682 gds
.op
= FETCH_OP_GDS_READ_RET
;
7683 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7684 gds
.uav_id
= uav_id
;
7685 gds
.uav_index_mode
= uav_index_mode
;
7686 gds
.src_gpr
= ctx
->temp_reg
;
7694 gds
.src_gpr2
= ctx
->temp_reg
;
7695 gds
.alloc_consume
= 1;
7696 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7700 ctx
->bc
->cf_last
->vpm
= 1;
7704 static int tgsi_load(struct r600_shader_ctx
*ctx
)
7706 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7707 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
7708 return tgsi_load_gds(ctx
);
7712 static int get_gds_op(int opcode
)
7715 case TGSI_OPCODE_ATOMUADD
:
7716 return FETCH_OP_GDS_ADD_RET
;
7717 case TGSI_OPCODE_ATOMAND
:
7718 return FETCH_OP_GDS_AND_RET
;
7719 case TGSI_OPCODE_ATOMOR
:
7720 return FETCH_OP_GDS_OR_RET
;
7721 case TGSI_OPCODE_ATOMXOR
:
7722 return FETCH_OP_GDS_XOR_RET
;
7723 case TGSI_OPCODE_ATOMUMIN
:
7724 return FETCH_OP_GDS_MIN_UINT_RET
;
7725 case TGSI_OPCODE_ATOMUMAX
:
7726 return FETCH_OP_GDS_MAX_UINT_RET
;
7727 case TGSI_OPCODE_ATOMXCHG
:
7728 return FETCH_OP_GDS_XCHG_RET
;
7729 case TGSI_OPCODE_ATOMCAS
:
7730 return FETCH_OP_GDS_CMP_XCHG_RET
;
7736 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
7738 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7739 struct r600_bytecode_gds gds
;
7740 struct r600_bytecode_alu alu
;
7741 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
7744 int uav_index_mode
= 0;
7747 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
7751 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7753 if (inst
->Src
[0].Register
.Indirect
)
7756 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
7757 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
7758 int abs_value
= abs(value
);
7759 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
7760 gds_op
= FETCH_OP_GDS_SUB_RET
;
7761 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7762 alu
.op
= ALU_OP1_MOV
;
7763 alu
.dst
.sel
= ctx
->temp_reg
;
7765 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
7766 alu
.src
[0].value
= abs_value
;
7769 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7773 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7774 alu
.op
= ALU_OP1_MOV
;
7775 alu
.dst
.sel
= ctx
->temp_reg
;
7777 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
7780 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7785 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7787 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7788 gds
.uav_id
= uav_id
;
7789 gds
.uav_index_mode
= uav_index_mode
;
7790 gds
.src_gpr
= ctx
->temp_reg
;
7791 gds
.src_gpr2
= ctx
->temp_reg
;
7799 gds
.alloc_consume
= 1;
7800 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7803 ctx
->bc
->cf_last
->vpm
= 1;
7807 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
7809 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7810 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
7811 return tgsi_atomic_op_gds(ctx
);
7815 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
7817 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7818 struct r600_bytecode_alu alu
;
7819 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7820 unsigned i
, temp_regs
[2];
7823 /* optimize if it's just an equal balance */
7824 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
7825 for (i
= 0; i
< lasti
+ 1; i
++) {
7826 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7829 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7830 alu
.op
= ALU_OP2_ADD
;
7831 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
7832 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7834 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7839 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7847 for (i
= 0; i
< lasti
+ 1; i
++) {
7848 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7852 alu
.op
= ALU_OP2_ADD
;
7853 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7854 alu
.src
[0].chan
= 0;
7855 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7856 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
7857 alu
.dst
.sel
= ctx
->temp_reg
;
7863 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7868 /* (1 - src0) * src2 */
7869 for (i
= 0; i
< lasti
+ 1; i
++) {
7870 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7874 alu
.op
= ALU_OP2_MUL
;
7875 alu
.src
[0].sel
= ctx
->temp_reg
;
7876 alu
.src
[0].chan
= i
;
7877 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7878 alu
.dst
.sel
= ctx
->temp_reg
;
7884 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7889 /* src0 * src1 + (1 - src0) * src2 */
7890 if (ctx
->src
[0].abs
)
7891 temp_regs
[0] = r600_get_temp(ctx
);
7894 if (ctx
->src
[1].abs
)
7895 temp_regs
[1] = r600_get_temp(ctx
);
7899 for (i
= 0; i
< lasti
+ 1; i
++) {
7900 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7903 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7904 alu
.op
= ALU_OP3_MULADD
;
7906 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
7909 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
7912 alu
.src
[2].sel
= ctx
->temp_reg
;
7913 alu
.src
[2].chan
= i
;
7915 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7920 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7927 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
7929 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7930 struct r600_bytecode_alu alu
;
7932 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7936 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
7938 ctx
->src
[0].abs
= 0;
7939 ctx
->src
[0].neg
= 0;
7944 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7946 if (ctx
->src
[j
].abs
)
7947 temp_regs
[j
] = r600_get_temp(ctx
);
7950 for (i
= 0; i
< lasti
+ 1; i
++) {
7951 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7954 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7956 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
7959 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
7962 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
7965 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7971 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7978 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
7980 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7981 struct r600_bytecode_alu alu
;
7983 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7985 for (i
= 0; i
< lasti
+ 1; i
++) {
7986 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7990 alu
.op
= ALU_OP3_CNDE_INT
;
7991 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7992 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7993 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
7994 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8000 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8007 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
8009 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8010 struct r600_bytecode_alu alu
;
8014 /* result.x = 2^floor(src); */
8015 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8016 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8018 alu
.op
= ALU_OP1_FLOOR
;
8019 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8021 alu
.dst
.sel
= ctx
->temp_reg
;
8025 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8029 if (ctx
->bc
->chip_class
== CAYMAN
) {
8030 for (i
= 0; i
< 3; i
++) {
8031 alu
.op
= ALU_OP1_EXP_IEEE
;
8032 alu
.src
[0].sel
= ctx
->temp_reg
;
8033 alu
.src
[0].chan
= 0;
8035 alu
.dst
.sel
= ctx
->temp_reg
;
8037 alu
.dst
.write
= i
== 0;
8039 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8044 alu
.op
= ALU_OP1_EXP_IEEE
;
8045 alu
.src
[0].sel
= ctx
->temp_reg
;
8046 alu
.src
[0].chan
= 0;
8048 alu
.dst
.sel
= ctx
->temp_reg
;
8052 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8058 /* result.y = tmp - floor(tmp); */
8059 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8060 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8062 alu
.op
= ALU_OP1_FRACT
;
8063 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8065 alu
.dst
.sel
= ctx
->temp_reg
;
8067 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8081 /* result.z = RoughApprox2ToX(tmp);*/
8082 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
8083 if (ctx
->bc
->chip_class
== CAYMAN
) {
8084 for (i
= 0; i
< 3; i
++) {
8085 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8086 alu
.op
= ALU_OP1_EXP_IEEE
;
8087 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8089 alu
.dst
.sel
= ctx
->temp_reg
;
8096 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8101 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8102 alu
.op
= ALU_OP1_EXP_IEEE
;
8103 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8105 alu
.dst
.sel
= ctx
->temp_reg
;
8111 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8117 /* result.w = 1.0;*/
8118 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
8119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8121 alu
.op
= ALU_OP1_MOV
;
8122 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8123 alu
.src
[0].chan
= 0;
8125 alu
.dst
.sel
= ctx
->temp_reg
;
8129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8133 return tgsi_helper_copy(ctx
, inst
);
8136 static int tgsi_log(struct r600_shader_ctx
*ctx
)
8138 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8139 struct r600_bytecode_alu alu
;
8143 /* result.x = floor(log2(|src|)); */
8144 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8145 if (ctx
->bc
->chip_class
== CAYMAN
) {
8146 for (i
= 0; i
< 3; i
++) {
8147 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8149 alu
.op
= ALU_OP1_LOG_IEEE
;
8150 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8151 r600_bytecode_src_set_abs(&alu
.src
[0]);
8153 alu
.dst
.sel
= ctx
->temp_reg
;
8159 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8167 alu
.op
= ALU_OP1_LOG_IEEE
;
8168 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8169 r600_bytecode_src_set_abs(&alu
.src
[0]);
8171 alu
.dst
.sel
= ctx
->temp_reg
;
8175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8180 alu
.op
= ALU_OP1_FLOOR
;
8181 alu
.src
[0].sel
= ctx
->temp_reg
;
8182 alu
.src
[0].chan
= 0;
8184 alu
.dst
.sel
= ctx
->temp_reg
;
8189 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8194 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
8195 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8197 if (ctx
->bc
->chip_class
== CAYMAN
) {
8198 for (i
= 0; i
< 3; i
++) {
8199 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8201 alu
.op
= ALU_OP1_LOG_IEEE
;
8202 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8203 r600_bytecode_src_set_abs(&alu
.src
[0]);
8205 alu
.dst
.sel
= ctx
->temp_reg
;
8212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8219 alu
.op
= ALU_OP1_LOG_IEEE
;
8220 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8221 r600_bytecode_src_set_abs(&alu
.src
[0]);
8223 alu
.dst
.sel
= ctx
->temp_reg
;
8228 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8235 alu
.op
= ALU_OP1_FLOOR
;
8236 alu
.src
[0].sel
= ctx
->temp_reg
;
8237 alu
.src
[0].chan
= 1;
8239 alu
.dst
.sel
= ctx
->temp_reg
;
8244 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8248 if (ctx
->bc
->chip_class
== CAYMAN
) {
8249 for (i
= 0; i
< 3; i
++) {
8250 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8251 alu
.op
= ALU_OP1_EXP_IEEE
;
8252 alu
.src
[0].sel
= ctx
->temp_reg
;
8253 alu
.src
[0].chan
= 1;
8255 alu
.dst
.sel
= ctx
->temp_reg
;
8262 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8267 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8268 alu
.op
= ALU_OP1_EXP_IEEE
;
8269 alu
.src
[0].sel
= ctx
->temp_reg
;
8270 alu
.src
[0].chan
= 1;
8272 alu
.dst
.sel
= ctx
->temp_reg
;
8277 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8282 if (ctx
->bc
->chip_class
== CAYMAN
) {
8283 for (i
= 0; i
< 3; i
++) {
8284 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8285 alu
.op
= ALU_OP1_RECIP_IEEE
;
8286 alu
.src
[0].sel
= ctx
->temp_reg
;
8287 alu
.src
[0].chan
= 1;
8289 alu
.dst
.sel
= ctx
->temp_reg
;
8296 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8301 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8302 alu
.op
= ALU_OP1_RECIP_IEEE
;
8303 alu
.src
[0].sel
= ctx
->temp_reg
;
8304 alu
.src
[0].chan
= 1;
8306 alu
.dst
.sel
= ctx
->temp_reg
;
8311 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8316 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8318 alu
.op
= ALU_OP2_MUL
;
8320 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8321 r600_bytecode_src_set_abs(&alu
.src
[0]);
8323 alu
.src
[1].sel
= ctx
->temp_reg
;
8324 alu
.src
[1].chan
= 1;
8326 alu
.dst
.sel
= ctx
->temp_reg
;
8331 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8336 /* result.z = log2(|src|);*/
8337 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
8338 if (ctx
->bc
->chip_class
== CAYMAN
) {
8339 for (i
= 0; i
< 3; i
++) {
8340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8342 alu
.op
= ALU_OP1_LOG_IEEE
;
8343 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8344 r600_bytecode_src_set_abs(&alu
.src
[0]);
8346 alu
.dst
.sel
= ctx
->temp_reg
;
8353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8358 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8360 alu
.op
= ALU_OP1_LOG_IEEE
;
8361 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8362 r600_bytecode_src_set_abs(&alu
.src
[0]);
8364 alu
.dst
.sel
= ctx
->temp_reg
;
8369 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8375 /* result.w = 1.0; */
8376 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
8377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8379 alu
.op
= ALU_OP1_MOV
;
8380 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8381 alu
.src
[0].chan
= 0;
8383 alu
.dst
.sel
= ctx
->temp_reg
;
8388 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8393 return tgsi_helper_copy(ctx
, inst
);
8396 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
8398 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8399 struct r600_bytecode_alu alu
;
8401 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8402 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
8404 assert(inst
->Dst
[0].Register
.Index
< 3);
8405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8407 switch (inst
->Instruction
.Opcode
) {
8408 case TGSI_OPCODE_ARL
:
8409 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
8411 case TGSI_OPCODE_ARR
:
8412 alu
.op
= ALU_OP1_FLT_TO_INT
;
8414 case TGSI_OPCODE_UARL
:
8415 alu
.op
= ALU_OP1_MOV
;
8422 for (i
= 0; i
<= lasti
; ++i
) {
8423 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8425 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8426 alu
.last
= i
== lasti
;
8430 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8435 if (inst
->Dst
[0].Register
.Index
> 0)
8436 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
8438 ctx
->bc
->ar_loaded
= 0;
8442 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
8444 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8445 struct r600_bytecode_alu alu
;
8447 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8449 switch (inst
->Instruction
.Opcode
) {
8450 case TGSI_OPCODE_ARL
:
8451 memset(&alu
, 0, sizeof(alu
));
8452 alu
.op
= ALU_OP1_FLOOR
;
8453 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8455 for (i
= 0; i
<= lasti
; ++i
) {
8456 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8458 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8459 alu
.last
= i
== lasti
;
8460 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8465 memset(&alu
, 0, sizeof(alu
));
8466 alu
.op
= ALU_OP1_FLT_TO_INT
;
8467 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
8468 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8470 /* FLT_TO_INT is trans-only on r600/r700 */
8472 for (i
= 0; i
<= lasti
; ++i
) {
8474 alu
.src
[0].chan
= i
;
8475 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8479 case TGSI_OPCODE_ARR
:
8480 memset(&alu
, 0, sizeof(alu
));
8481 alu
.op
= ALU_OP1_FLT_TO_INT
;
8482 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8484 /* FLT_TO_INT is trans-only on r600/r700 */
8486 for (i
= 0; i
<= lasti
; ++i
) {
8487 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8489 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8490 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8495 case TGSI_OPCODE_UARL
:
8496 memset(&alu
, 0, sizeof(alu
));
8497 alu
.op
= ALU_OP1_MOV
;
8498 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8500 for (i
= 0; i
<= lasti
; ++i
) {
8501 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8503 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8504 alu
.last
= i
== lasti
;
8505 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8515 ctx
->bc
->ar_loaded
= 0;
8519 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
8521 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8522 struct r600_bytecode_alu alu
;
8525 for (i
= 0; i
< 4; i
++) {
8526 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8528 alu
.op
= ALU_OP2_MUL
;
8529 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8531 if (i
== 0 || i
== 3) {
8532 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8534 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8537 if (i
== 0 || i
== 2) {
8538 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
8540 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8544 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8551 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
8553 struct r600_bytecode_alu alu
;
8556 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8558 alu
.execute_mask
= 1;
8559 alu
.update_pred
= 1;
8561 alu
.dst
.sel
= ctx
->temp_reg
;
8565 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8566 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
8567 alu
.src
[1].chan
= 0;
8571 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
8577 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
8579 unsigned force_pop
= ctx
->bc
->force_add_cf
;
8583 if (ctx
->bc
->cf_last
) {
8584 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
8586 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
8591 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
8592 ctx
->bc
->force_add_cf
= 1;
8593 } else if (alu_pop
== 2) {
8594 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
8595 ctx
->bc
->force_add_cf
= 1;
8602 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
8603 ctx
->bc
->cf_last
->pop_count
= pops
;
8604 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8610 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
8613 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
8614 unsigned elements
, entries
;
8616 unsigned entry_size
= stack
->entry_size
;
8618 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
8619 elements
+= stack
->push
;
8621 switch (ctx
->bc
->chip_class
) {
8624 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
8625 * the stack must be reserved to hold the current active/continue
8627 if (reason
== FC_PUSH_VPM
) {
8633 /* r9xx: any stack operation on empty stack consumes 2 additional
8638 /* FIXME: do the two elements added above cover the cases for the
8642 /* r8xx+: 2 extra elements are not always required, but one extra
8643 * element must be added for each of the following cases:
8644 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
8646 * (Currently we don't use ALU_ELSE_AFTER.)
8647 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
8648 * PUSH instruction executed.
8650 * NOTE: it seems we also need to reserve additional element in some
8651 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
8652 * then STACK_SIZE should be 2 instead of 1 */
8653 if (reason
== FC_PUSH_VPM
) {
8663 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
8664 * for all chips, so we use 4 in the final formula, not the real entry_size
8668 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
8670 if (entries
> stack
->max_entries
)
8671 stack
->max_entries
= entries
;
8674 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
8678 --ctx
->bc
->stack
.push
;
8679 assert(ctx
->bc
->stack
.push
>= 0);
8682 --ctx
->bc
->stack
.push_wqm
;
8683 assert(ctx
->bc
->stack
.push_wqm
>= 0);
8686 --ctx
->bc
->stack
.loop
;
8687 assert(ctx
->bc
->stack
.loop
>= 0);
8695 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
8699 ++ctx
->bc
->stack
.push
;
8702 ++ctx
->bc
->stack
.push_wqm
;
8704 ++ctx
->bc
->stack
.loop
;
8710 callstack_update_max_depth(ctx
, reason
);
8713 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
8715 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
8717 sp
->mid
= realloc((void *)sp
->mid
,
8718 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
8719 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
8723 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
8725 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
8726 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
8727 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
8731 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
8733 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
8743 static int emit_return(struct r600_shader_ctx
*ctx
)
8745 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
8749 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
8752 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
8753 ctx
->bc
->cf_last
->pop_count
= pops
;
8754 /* XXX work out offset */
8758 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
8763 static void emit_testflag(struct r600_shader_ctx
*ctx
)
8768 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
8771 emit_jump_to_offset(ctx
, 1, 4);
8772 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
8773 pops(ctx
, ifidx
+ 1);
8777 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
8781 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8782 ctx
->bc
->cf_last
->pop_count
= 1;
8784 fc_set_mid(ctx
, fc_sp
);
8790 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
8792 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
8794 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
8795 * LOOP_STARTxxx for nested loops may put the branch stack into a state
8796 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
8797 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
8798 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
8799 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
8800 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8801 alu_type
= CF_OP_ALU
;
8804 emit_logic_pred(ctx
, opcode
, alu_type
);
8806 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
8808 fc_pushlevel(ctx
, FC_IF
);
8810 callstack_push(ctx
, FC_PUSH_VPM
);
8814 static int tgsi_if(struct r600_shader_ctx
*ctx
)
8816 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
8819 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
8821 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
8824 static int tgsi_else(struct r600_shader_ctx
*ctx
)
8826 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
8827 ctx
->bc
->cf_last
->pop_count
= 1;
8829 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
8830 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
8834 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
8837 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
8838 R600_ERR("if/endif unbalanced in shader\n");
8842 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
8843 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8844 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
8846 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8850 callstack_pop(ctx
, FC_PUSH_VPM
);
8854 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
8856 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
8857 * limited to 4096 iterations, like the other LOOP_* instructions. */
8858 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
8860 fc_pushlevel(ctx
, FC_LOOP
);
8862 /* check stack depth */
8863 callstack_push(ctx
, FC_LOOP
);
8867 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
8871 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
8873 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
8874 R600_ERR("loop/endloop in shader code are not paired.\n");
8878 /* fixup loop pointers - from r600isa
8879 LOOP END points to CF after LOOP START,
8880 LOOP START point to CF after LOOP END
8881 BRK/CONT point to LOOP END CF
8883 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
8885 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8887 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
8888 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
8890 /* XXX add LOOPRET support */
8892 callstack_pop(ctx
, FC_LOOP
);
8896 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
8900 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
8902 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
8907 R600_ERR("Break not inside loop/endloop pair\n");
8911 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8913 fc_set_mid(ctx
, fscp
- 1);
8918 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
8920 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8921 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
8924 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
8925 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
8927 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8929 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
8930 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
8931 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
8936 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
8938 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8939 struct r600_bytecode_alu alu
;
8941 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8944 for (i
= 0; i
< lasti
+ 1; i
++) {
8945 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8948 if (ctx
->bc
->chip_class
== CAYMAN
) {
8949 for (j
= 0 ; j
< 4; j
++) {
8950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8952 alu
.op
= ALU_OP2_MULLO_UINT
;
8953 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
8954 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
8957 alu
.dst
.sel
= ctx
->temp_reg
;
8958 alu
.dst
.write
= (j
== i
);
8961 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8966 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8969 alu
.dst
.sel
= ctx
->temp_reg
;
8972 alu
.op
= ALU_OP2_MULLO_UINT
;
8973 for (j
= 0; j
< 2; j
++) {
8974 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
8978 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8985 for (i
= 0; i
< lasti
+ 1; i
++) {
8986 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8990 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8992 alu
.op
= ALU_OP2_ADD_INT
;
8994 alu
.src
[0].sel
= ctx
->temp_reg
;
8995 alu
.src
[0].chan
= i
;
8997 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9001 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9008 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
9010 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9011 struct r600_bytecode_alu alu
;
9013 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9015 /* temp.xy = f32_to_f16(src) */
9016 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9017 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
9019 alu
.dst
.sel
= ctx
->temp_reg
;
9021 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9022 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9026 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
9028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9032 /* dst.x = temp.y * 0x10000 + temp.x */
9033 for (i
= 0; i
< lasti
+ 1; i
++) {
9034 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9038 alu
.op
= ALU_OP3_MULADD_UINT24
;
9040 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9041 alu
.last
= i
== lasti
;
9042 alu
.src
[0].sel
= ctx
->temp_reg
;
9043 alu
.src
[0].chan
= 1;
9044 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9045 alu
.src
[1].value
= 0x10000;
9046 alu
.src
[2].sel
= ctx
->temp_reg
;
9047 alu
.src
[2].chan
= 0;
9048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9056 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
9058 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9059 struct r600_bytecode_alu alu
;
9061 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9063 /* temp.x = src.x */
9064 /* note: no need to mask out the high bits */
9065 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9066 alu
.op
= ALU_OP1_MOV
;
9068 alu
.dst
.sel
= ctx
->temp_reg
;
9070 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9071 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9075 /* temp.y = src.x >> 16 */
9076 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9077 alu
.op
= ALU_OP2_LSHR_INT
;
9079 alu
.dst
.sel
= ctx
->temp_reg
;
9081 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9082 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9083 alu
.src
[1].value
= 16;
9085 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9089 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
9090 for (i
= 0; i
< lasti
+ 1; i
++) {
9091 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9093 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9094 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9095 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
9096 alu
.src
[0].sel
= ctx
->temp_reg
;
9097 alu
.src
[0].chan
= i
% 2;
9098 alu
.last
= i
== lasti
;
9099 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9107 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
9109 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9110 struct r600_bytecode_alu alu
;
9111 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9118 for (i
= 0; i
< lasti
+ 1; i
++) {
9119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9120 alu
.op
= ALU_OP2_SETGE_INT
;
9121 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
9122 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9123 alu
.src
[1].value
= 32;
9124 alu
.dst
.sel
= ctx
->temp_reg
;
9129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9134 for (i
= 0; i
< lasti
+ 1; i
++) {
9135 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9136 alu
.op
= ALU_OP3_CNDE_INT
;
9138 alu
.src
[0].sel
= ctx
->temp_reg
;
9139 alu
.src
[1].chan
= i
;
9141 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9142 alu
.src
[1].sel
= alu
.dst
.sel
;
9143 alu
.src
[1].chan
= i
;
9144 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
9148 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9156 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
9157 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9158 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9159 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9161 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9163 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
9164 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9165 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9166 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9167 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9168 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9169 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9170 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9171 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
9172 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9173 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9174 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9175 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9176 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9177 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9178 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9179 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9180 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9181 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9182 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9183 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9184 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9185 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9186 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9187 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9188 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9189 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9190 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9191 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9192 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9193 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9194 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9195 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9196 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9197 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9198 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9199 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9200 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9201 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9202 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9203 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9204 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9205 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9206 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9207 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9208 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9209 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9210 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9211 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9212 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9213 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9214 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9215 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9216 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9217 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9218 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9219 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9220 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9221 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9222 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9223 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9224 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9225 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9226 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9227 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9228 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9229 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9230 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9231 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9232 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9233 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9234 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9235 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9236 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9237 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9238 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9239 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9240 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
9241 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9242 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9243 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9244 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9245 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9246 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
9247 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9248 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9249 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9250 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9251 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9252 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9253 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9254 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9255 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9256 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9257 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9258 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9259 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9260 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9261 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9262 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9263 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9264 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9265 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9266 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9267 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9268 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9269 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9270 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9271 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9272 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9273 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9274 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9275 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9276 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9277 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9278 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
9279 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9280 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9281 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9282 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9283 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9284 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
9285 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9286 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
9287 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9288 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9289 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9290 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9291 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9292 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9293 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9294 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9295 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9296 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9297 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
9298 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9299 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
9300 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9301 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9302 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9303 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9304 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9305 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9306 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9307 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9308 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9309 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9310 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9311 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9312 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9313 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9314 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9315 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9316 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
9317 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9318 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9319 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9320 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9321 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9322 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9323 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9324 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9325 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9326 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9327 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9328 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9329 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9330 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9331 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9332 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9333 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9334 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9335 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9336 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9337 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9338 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9339 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9340 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9341 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
9342 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
9343 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
9344 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
9345 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9346 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
9347 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
9348 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
9349 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
9350 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
9351 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9352 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9353 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9354 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9357 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
9358 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9359 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9360 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9361 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9362 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
9363 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9364 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9365 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9366 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9367 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9368 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9369 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9370 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9371 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9372 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9373 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9374 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9375 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9376 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
9377 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9378 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9379 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9380 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9381 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9382 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9383 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9384 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9385 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9386 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9387 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9388 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9389 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9390 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9391 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9392 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9393 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9394 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9395 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9396 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9397 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
9398 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9399 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9400 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9401 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9402 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9403 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9404 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9405 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9406 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9407 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9408 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9409 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9410 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9411 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9412 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
9413 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9414 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9415 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9416 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9417 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9418 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9419 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9420 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9421 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9422 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9423 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9424 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9425 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9426 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9427 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9428 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9429 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9430 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9431 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9432 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9433 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9434 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9435 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9436 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9437 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9438 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9439 [83] = { ALU_OP0_NOP
, tgsi_unsupported
},
9440 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9441 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9442 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9443 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9444 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9445 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9446 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9447 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9448 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9449 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9450 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9451 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9452 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9453 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9454 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9455 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9456 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9457 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9458 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9459 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9460 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9461 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9462 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9463 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9464 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9465 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9466 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9467 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9468 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9469 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9470 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9471 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9472 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9473 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9474 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9475 /* Refer below for TGSI_OPCODE_DFMA */
9476 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
9477 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9478 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9479 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9480 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9481 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9482 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9483 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9484 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
9485 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9486 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9487 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9488 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9489 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9490 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9491 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9492 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9493 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9494 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9495 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9496 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9497 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9498 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9499 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9500 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9501 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9502 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9503 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9504 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9505 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9506 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9507 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9508 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9509 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9510 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9511 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9512 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9513 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9514 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
9515 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9516 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9517 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9518 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
9519 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9520 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9521 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9522 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9523 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9524 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
9525 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
9526 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
9527 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
9528 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
9529 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
9530 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
9531 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
9532 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
9533 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
9534 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9535 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9536 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9537 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9538 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9539 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
9540 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
9541 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
9542 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
9543 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
9544 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
9545 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
9546 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
9547 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
9548 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
9549 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9550 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9551 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9552 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
9553 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
9554 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
9555 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
9556 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
9557 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
9558 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
9559 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
9560 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
9561 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
9562 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
9563 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
9564 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
9565 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
9566 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
9567 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9568 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9569 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
9570 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
9571 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
9572 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
9573 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
9574 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
9575 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
9576 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
9577 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9580 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
9581 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9582 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9583 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9584 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
9585 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
9586 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9587 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9588 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9589 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9590 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9591 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9592 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9593 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9594 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9595 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9596 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9597 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9598 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9599 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
9600 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
9601 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9602 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9603 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9604 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9605 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9606 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9607 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9608 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
9609 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
9610 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
9611 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9612 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9613 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9614 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9615 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9616 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
9617 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9618 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9619 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9620 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
9621 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9622 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9623 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9624 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9625 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9626 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9627 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9628 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
9629 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9630 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9631 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9632 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9633 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9634 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9635 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
9636 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9637 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9638 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9639 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9640 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9641 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9642 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9643 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9644 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9645 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9646 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9647 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9648 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9649 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9650 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9651 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9652 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9653 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9654 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9655 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9656 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9657 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9658 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9659 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9660 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9661 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9662 [83] = { ALU_OP0_NOP
, tgsi_unsupported
},
9663 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9664 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
9665 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9666 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9667 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9668 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9669 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9670 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9671 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9672 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9673 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9674 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9675 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9676 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9677 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9678 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9679 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9680 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9681 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9682 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9683 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9684 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9685 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9686 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9687 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9688 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9689 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9690 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9691 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9692 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9693 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9694 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9695 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9696 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9697 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9698 /* Refer below for TGSI_OPCODE_DFMA */
9699 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
9700 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9701 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9702 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9703 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9704 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9705 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9706 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9707 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
9708 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
9709 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9710 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9711 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9712 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9713 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9714 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9715 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
9716 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9717 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9718 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9719 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9720 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9721 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9722 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9723 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9724 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9725 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9726 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9727 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9728 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9729 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9730 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9731 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9732 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9733 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9734 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9735 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9736 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9737 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
9738 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9739 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9740 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9741 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
9742 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9743 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9744 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9745 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9746 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9747 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
9748 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
9749 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
9750 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
9751 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
9752 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
9753 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
9754 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
9755 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
9756 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
9757 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9758 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9759 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9760 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
9761 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
9762 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
9763 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
9764 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
9765 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
9766 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
9767 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
9768 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
9769 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
9770 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
9771 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
9772 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9773 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9774 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9775 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
9776 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
9777 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
9778 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
9779 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
9780 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
9781 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
9782 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
9783 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
9784 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
9785 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
9786 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
9787 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
9788 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
9789 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
9790 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9791 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9792 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
9793 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
9794 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
9795 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
9796 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
9797 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
9798 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
9799 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
9800 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},