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 */
356 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
359 struct r600_shader_tgsi_instruction
{
361 int (*process
)(struct r600_shader_ctx
*ctx
);
364 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
365 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
366 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
367 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
368 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
369 static int tgsi_else(struct r600_shader_ctx
*ctx
);
370 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
371 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
372 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
373 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
374 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
375 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
376 unsigned int dst_reg
);
377 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
378 const struct r600_shader_src
*shader_src
,
380 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
383 static int tgsi_last_instruction(unsigned writemask
)
387 for (i
= 0; i
< 4; i
++) {
388 if (writemask
& (1 << i
)) {
395 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
397 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
400 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
401 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
405 if (i
->Instruction
.Label
) {
406 R600_ERR("label unsupported\n");
410 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
411 if (i
->Src
[j
].Register
.Dimension
) {
412 switch (i
->Src
[j
].Register
.File
) {
413 case TGSI_FILE_CONSTANT
:
414 case TGSI_FILE_HW_ATOMIC
:
416 case TGSI_FILE_INPUT
:
417 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
418 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
419 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
421 case TGSI_FILE_OUTPUT
:
422 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
425 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
426 i
->Src
[j
].Register
.File
,
427 i
->Src
[j
].Register
.Dimension
);
432 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
433 if (i
->Dst
[j
].Register
.Dimension
) {
434 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
436 R600_ERR("unsupported dst (dimension)\n");
443 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
445 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
446 interpolate
== TGSI_INTERPOLATE_LINEAR
||
447 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
449 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
453 case TGSI_INTERPOLATE_LOC_CENTER
:
456 case TGSI_INTERPOLATE_LOC_CENTROID
:
459 case TGSI_INTERPOLATE_LOC_SAMPLE
:
464 return is_linear
* 3 + loc
;
470 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
473 int i
= eg_get_interpolator_index(
474 ctx
->shader
->input
[input
].interpolate
,
475 ctx
->shader
->input
[input
].interpolate_location
);
477 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
480 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
483 struct r600_bytecode_alu alu
;
484 int gpr
= 0, base_chan
= 0;
485 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
487 /* work out gpr and base_chan from index */
489 base_chan
= (2 * (ij_index
% 2)) + 1;
491 for (i
= 0; i
< 8; i
++) {
492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
495 alu
.op
= ALU_OP2_INTERP_ZW
;
497 alu
.op
= ALU_OP2_INTERP_XY
;
499 if ((i
> 1) && (i
< 6)) {
500 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
504 alu
.dst
.chan
= i
% 4;
506 alu
.src
[0].sel
= gpr
;
507 alu
.src
[0].chan
= (base_chan
- (i
% 2));
509 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
511 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
514 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
521 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
524 struct r600_bytecode_alu alu
;
526 for (i
= 0; i
< 4; i
++) {
527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
529 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
531 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
536 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
541 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
549 * Special export handling in shaders
551 * shader export ARRAY_BASE for EXPORT_POS:
554 * 62, 63 are clip distance vectors
556 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
557 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
558 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
559 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
560 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
561 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
562 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
563 * exclusive from render target index)
564 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
567 * shader export ARRAY_BASE for EXPORT_PIXEL:
569 * 61 computed Z vector
571 * The use of the values exported in the computed Z vector are controlled
572 * by DB_SHADER_CONTROL:
573 * Z_EXPORT_ENABLE - Z as a float in RED
574 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
575 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
576 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
577 * DB_SOURCE_FORMAT - export control restrictions
582 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
583 static int r600_spi_sid(struct r600_shader_io
* io
)
585 int index
, name
= io
->name
;
587 /* These params are handled differently, they don't need
588 * semantic indices, so we'll use 0 for them.
590 if (name
== TGSI_SEMANTIC_POSITION
||
591 name
== TGSI_SEMANTIC_PSIZE
||
592 name
== TGSI_SEMANTIC_EDGEFLAG
||
593 name
== TGSI_SEMANTIC_FACE
||
594 name
== TGSI_SEMANTIC_SAMPLEMASK
)
597 if (name
== TGSI_SEMANTIC_GENERIC
) {
598 /* For generic params simply use sid from tgsi */
601 /* For non-generic params - pack name and sid into 8 bits */
602 index
= 0x80 | (name
<<3) | (io
->sid
);
605 /* Make sure that all really used indices have nonzero value, so
606 * we can just compare it to 0 later instead of comparing the name
607 * with different values to detect special cases. */
614 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
615 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
617 switch (semantic_name
) {
618 case TGSI_SEMANTIC_POSITION
:
620 case TGSI_SEMANTIC_PSIZE
:
622 case TGSI_SEMANTIC_CLIPDIST
:
625 case TGSI_SEMANTIC_GENERIC
:
627 return 4 + index
- 9;
629 /* same explanation as in the default statement,
630 * the only user hitting this is st/nine.
634 /* patch indices are completely separate and thus start from 0 */
635 case TGSI_SEMANTIC_TESSOUTER
:
637 case TGSI_SEMANTIC_TESSINNER
:
639 case TGSI_SEMANTIC_PATCH
:
643 /* Don't fail here. The result of this function is only used
644 * for LS, TCS, TES, and GS, where legacy GL semantics can't
645 * occur, but this function is called for all vertex shaders
646 * before it's known whether LS will be compiled or not.
652 /* turn input into interpolate on EG */
653 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
657 if (ctx
->shader
->input
[index
].spi_sid
) {
658 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
659 if (ctx
->shader
->input
[index
].interpolate
> 0) {
660 evergreen_interp_assign_ij_index(ctx
, index
);
661 r
= evergreen_interp_alu(ctx
, index
);
663 r
= evergreen_interp_flat(ctx
, index
);
669 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
671 struct r600_bytecode_alu alu
;
673 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
674 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
676 for (i
= 0; i
< 4; i
++) {
677 memset(&alu
, 0, sizeof(alu
));
678 alu
.op
= ALU_OP3_CNDGT
;
681 alu
.dst
.sel
= gpr_front
;
682 alu
.src
[0].sel
= ctx
->face_gpr
;
683 alu
.src
[1].sel
= gpr_front
;
684 alu
.src
[2].sel
= gpr_back
;
691 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
698 /* execute a single slot ALU calculation */
699 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
700 int dst_sel
, int dst_chan
,
701 int src0_sel
, unsigned src0_chan_val
,
702 int src1_sel
, unsigned src1_chan_val
)
704 struct r600_bytecode_alu alu
;
707 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
708 for (i
= 0; i
< 4; i
++) {
709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
711 alu
.src
[0].sel
= src0_sel
;
712 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
713 alu
.src
[0].value
= src0_chan_val
;
715 alu
.src
[0].chan
= src0_chan_val
;
716 alu
.src
[1].sel
= src1_sel
;
717 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
718 alu
.src
[1].value
= src1_chan_val
;
720 alu
.src
[1].chan
= src1_chan_val
;
721 alu
.dst
.sel
= dst_sel
;
723 alu
.dst
.write
= i
== dst_chan
;
725 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
734 alu
.src
[0].sel
= src0_sel
;
735 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
736 alu
.src
[0].value
= src0_chan_val
;
738 alu
.src
[0].chan
= src0_chan_val
;
739 alu
.src
[1].sel
= src1_sel
;
740 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
741 alu
.src
[1].value
= src1_chan_val
;
743 alu
.src
[1].chan
= src1_chan_val
;
744 alu
.dst
.sel
= dst_sel
;
745 alu
.dst
.chan
= dst_chan
;
748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
754 /* execute a single slot ALU calculation */
755 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
756 int dst_sel
, int dst_chan
,
757 int src0_sel
, unsigned src0_chan_val
,
758 int src1_sel
, unsigned src1_chan_val
,
759 int src2_sel
, unsigned src2_chan_val
)
761 struct r600_bytecode_alu alu
;
764 /* validate this for other ops */
765 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
);
766 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
768 alu
.src
[0].sel
= src0_sel
;
769 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
770 alu
.src
[0].value
= src0_chan_val
;
772 alu
.src
[0].chan
= src0_chan_val
;
773 alu
.src
[1].sel
= src1_sel
;
774 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
775 alu
.src
[1].value
= src1_chan_val
;
777 alu
.src
[1].chan
= src1_chan_val
;
778 alu
.src
[2].sel
= src2_sel
;
779 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
780 alu
.src
[2].value
= src2_chan_val
;
782 alu
.src
[2].chan
= src2_chan_val
;
783 alu
.dst
.sel
= dst_sel
;
784 alu
.dst
.chan
= dst_chan
;
787 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
793 /* put it in temp_reg.x */
794 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
796 int temp_reg
, bool is_patch_var
)
800 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
802 Dimension - patch0_offset (input_vals.z),
803 Non-dim - patch0_data_offset (input_vals.w)
805 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
807 ctx
->tess_output_info
, 0,
809 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
815 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
817 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
820 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
822 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
825 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
828 i
= ctx
->shader
->noutput
++;
829 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
830 ctx
->shader
->output
[i
].sid
= 0;
831 ctx
->shader
->output
[i
].gpr
= 0;
832 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
833 ctx
->shader
->output
[i
].write_mask
= 0x4;
834 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
839 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
841 struct r600_bytecode_alu alu
;
844 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
845 alu
.op
= ctx
->inst_info
->op
;
848 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
854 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
856 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
857 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
859 switch (d
->Declaration
.File
) {
860 case TGSI_FILE_INPUT
:
861 for (j
= 0; j
< count
; j
++) {
862 i
= ctx
->shader
->ninput
+ j
;
863 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
864 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
865 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
866 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
867 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
868 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
869 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
870 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
871 switch (ctx
->shader
->input
[i
].name
) {
872 case TGSI_SEMANTIC_FACE
:
873 if (ctx
->face_gpr
!= -1)
874 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
876 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
878 case TGSI_SEMANTIC_COLOR
:
881 case TGSI_SEMANTIC_POSITION
:
882 ctx
->fragcoord_input
= i
;
884 case TGSI_SEMANTIC_PRIMID
:
885 /* set this for now */
886 ctx
->shader
->gs_prim_id_input
= true;
887 ctx
->shader
->ps_prim_id_input
= i
;
890 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
891 if ((r
= evergreen_interp_input(ctx
, i
)))
894 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
895 /* FIXME probably skip inputs if they aren't passed in the ring */
896 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
897 ctx
->next_ring_offset
+= 16;
898 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
899 ctx
->shader
->gs_prim_id_input
= true;
902 ctx
->shader
->ninput
+= count
;
904 case TGSI_FILE_OUTPUT
:
905 for (j
= 0; j
< count
; j
++) {
906 i
= ctx
->shader
->noutput
+ j
;
907 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
908 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
909 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
910 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
911 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
912 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
913 if (ctx
->type
== PIPE_SHADER_VERTEX
||
914 ctx
->type
== PIPE_SHADER_GEOMETRY
||
915 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
916 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
917 switch (d
->Semantic
.Name
) {
918 case TGSI_SEMANTIC_CLIPDIST
:
919 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<<
920 ((d
->Semantic
.Index
+ j
) << 2);
922 case TGSI_SEMANTIC_PSIZE
:
923 ctx
->shader
->vs_out_misc_write
= 1;
924 ctx
->shader
->vs_out_point_size
= 1;
926 case TGSI_SEMANTIC_EDGEFLAG
:
927 ctx
->shader
->vs_out_misc_write
= 1;
928 ctx
->shader
->vs_out_edgeflag
= 1;
929 ctx
->edgeflag_output
= i
;
931 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
932 ctx
->shader
->vs_out_misc_write
= 1;
933 ctx
->shader
->vs_out_viewport
= 1;
935 case TGSI_SEMANTIC_LAYER
:
936 ctx
->shader
->vs_out_misc_write
= 1;
937 ctx
->shader
->vs_out_layer
= 1;
939 case TGSI_SEMANTIC_CLIPVERTEX
:
940 ctx
->clip_vertex_write
= TRUE
;
944 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
945 ctx
->gs_out_ring_offset
+= 16;
947 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
948 switch (d
->Semantic
.Name
) {
949 case TGSI_SEMANTIC_COLOR
:
950 ctx
->shader
->nr_ps_max_color_exports
++;
955 ctx
->shader
->noutput
+= count
;
957 case TGSI_FILE_TEMPORARY
:
958 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
959 if (d
->Array
.ArrayID
) {
960 r600_add_gpr_array(ctx
->shader
,
961 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
963 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
968 case TGSI_FILE_CONSTANT
:
969 case TGSI_FILE_SAMPLER
:
970 case TGSI_FILE_SAMPLER_VIEW
:
971 case TGSI_FILE_ADDRESS
:
974 case TGSI_FILE_HW_ATOMIC
:
975 i
= ctx
->shader
->nhwatomic_ranges
;
976 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
977 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
978 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
979 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
980 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
981 ctx
->shader
->nhwatomic_ranges
++;
982 ctx
->shader
->nhwatomic
+= count
;
985 case TGSI_FILE_SYSTEM_VALUE
:
986 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
987 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
988 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
989 break; /* Already handled from allocate_system_value_inputs */
990 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
991 if (!ctx
->native_integers
) {
992 struct r600_bytecode_alu alu
;
993 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
995 alu
.op
= ALU_OP1_INT_TO_FLT
;
1004 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1008 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1010 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1012 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1013 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1014 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1015 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1016 unsigned temp_reg
= r600_get_temp(ctx
);
1018 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1022 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1025 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1029 do_lds_fetch_values(ctx
, temp_reg
, dreg
);
1031 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1035 for (i
= 0; i
< 2; i
++) {
1036 struct r600_bytecode_alu alu
;
1037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1038 alu
.op
= ALU_OP1_MOV
;
1040 alu
.src
[0].chan
= 0 + i
;
1042 alu
.dst
.chan
= 0 + i
;
1044 alu
.last
= (i
== 1) ? 1 : 0;
1045 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1048 /* ADD r1.z, 1.0f, -r0.x */
1049 struct r600_bytecode_alu alu
;
1050 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1051 alu
.op
= ALU_OP2_ADD
;
1052 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1054 alu
.src
[1].chan
= 0;
1060 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1063 /* ADD r1.z, r1.z, -r1.y */
1064 alu
.op
= ALU_OP2_ADD
;
1066 alu
.src
[0].chan
= 2;
1068 alu
.src
[1].chan
= 1;
1074 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1080 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1086 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1088 struct tgsi_parse_context parse
;
1092 unsigned name
, alternate_name
;
1094 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1096 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1098 int i
, k
, num_regs
= 0;
1100 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1104 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1105 while (!tgsi_parse_end_of_tokens(&parse
)) {
1106 tgsi_parse_token(&parse
);
1108 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1109 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1110 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1111 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1112 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1114 int interpolate
, location
, k
;
1116 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1117 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1118 inputs
[1].enabled
= true; /* needs SAMPLEID */
1119 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1120 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1121 /* Needs sample positions, currently those are always available */
1123 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1126 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1127 k
= eg_get_interpolator_index(interpolate
, location
);
1129 ctx
->eg_interpolators
[k
].enabled
= true;
1131 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1132 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1133 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1134 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1135 if (d
->Semantic
.Name
== inputs
[k
].name
||
1136 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1137 inputs
[k
].enabled
= true;
1144 tgsi_parse_free(&parse
);
1146 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1147 boolean enabled
= inputs
[i
].enabled
;
1148 int *reg
= inputs
[i
].reg
;
1149 unsigned name
= inputs
[i
].name
;
1152 int gpr
= gpr_offset
+ num_regs
++;
1153 ctx
->shader
->nsys_inputs
++;
1155 // add to inputs, allocate a gpr
1156 k
= ctx
->shader
->ninput
++;
1157 ctx
->shader
->input
[k
].name
= name
;
1158 ctx
->shader
->input
[k
].sid
= 0;
1159 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1160 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1161 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1165 return gpr_offset
+ num_regs
;
1169 * for evergreen we need to scan the shader to find the number of GPRs we need to
1170 * reserve for interpolation and system values
1172 * we need to know if we are going to emit
1173 * any sample or centroid inputs
1174 * if perspective and linear are required
1176 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1180 struct tgsi_parse_context parse
;
1182 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1184 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1186 /* skip position/face/mask/sampleid */
1187 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1188 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1189 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1190 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1193 k
= eg_get_interpolator_index(
1194 ctx
->info
.input_interpolate
[i
],
1195 ctx
->info
.input_interpolate_loc
[i
]);
1197 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1200 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1204 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1205 while (!tgsi_parse_end_of_tokens(&parse
)) {
1206 tgsi_parse_token(&parse
);
1208 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1209 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1210 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1211 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1212 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1214 int interpolate
, location
, k
;
1216 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1217 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1218 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1219 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1221 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1224 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1225 k
= eg_get_interpolator_index(interpolate
, location
);
1227 ctx
->eg_interpolators
[k
].enabled
= true;
1232 tgsi_parse_free(&parse
);
1234 /* assign gpr to each interpolator according to priority */
1236 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1237 if (ctx
->eg_interpolators
[i
].enabled
) {
1238 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1243 /* XXX PULL MODEL and LINE STIPPLE */
1245 num_baryc
= (num_baryc
+ 1) >> 1;
1246 return allocate_system_value_inputs(ctx
, num_baryc
);
1249 /* sample_id_sel == NULL means fetch for current sample */
1250 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1252 struct r600_bytecode_vtx vtx
;
1255 assert(ctx
->fixed_pt_position_gpr
!= -1);
1257 t1
= r600_get_temp(ctx
);
1259 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1260 vtx
.op
= FETCH_OP_VFETCH
;
1261 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1262 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1263 if (sample_id
== NULL
) {
1264 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1268 struct r600_bytecode_alu alu
;
1270 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1271 alu
.op
= ALU_OP1_MOV
;
1272 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1276 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1283 vtx
.mega_fetch_count
= 16;
1289 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1290 vtx
.num_format_all
= 2;
1291 vtx
.format_comp_all
= 1;
1292 vtx
.use_const_fields
= 0;
1293 vtx
.offset
= 1; // first element is size of buffer
1294 vtx
.endian
= r600_endian_swap(32);
1295 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1297 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1304 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1305 const struct tgsi_full_src_register
*tgsi_src
,
1306 struct r600_shader_src
*r600_src
)
1308 memset(r600_src
, 0, sizeof(*r600_src
));
1309 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1310 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1311 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1312 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1313 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1314 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1316 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1318 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1319 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1320 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1322 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1323 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1324 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1327 index
= tgsi_src
->Register
.Index
;
1328 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1329 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1330 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1331 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1332 r600_src
->swizzle
[0] = 2; // Z value
1333 r600_src
->swizzle
[1] = 2;
1334 r600_src
->swizzle
[2] = 2;
1335 r600_src
->swizzle
[3] = 2;
1336 r600_src
->sel
= ctx
->face_gpr
;
1337 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1338 r600_src
->swizzle
[0] = 3; // W value
1339 r600_src
->swizzle
[1] = 3;
1340 r600_src
->swizzle
[2] = 3;
1341 r600_src
->swizzle
[3] = 3;
1342 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1343 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1344 r600_src
->swizzle
[0] = 0;
1345 r600_src
->swizzle
[1] = 1;
1346 r600_src
->swizzle
[2] = 4;
1347 r600_src
->swizzle
[3] = 4;
1348 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1349 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1350 r600_src
->swizzle
[0] = 3;
1351 r600_src
->swizzle
[1] = 3;
1352 r600_src
->swizzle
[2] = 3;
1353 r600_src
->swizzle
[3] = 3;
1355 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1356 r600_src
->swizzle
[0] = 0;
1357 r600_src
->swizzle
[1] = 0;
1358 r600_src
->swizzle
[2] = 0;
1359 r600_src
->swizzle
[3] = 0;
1361 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1362 r600_src
->swizzle
[0] = 3;
1363 r600_src
->swizzle
[1] = 3;
1364 r600_src
->swizzle
[2] = 3;
1365 r600_src
->swizzle
[3] = 3;
1367 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1368 r600_src
->swizzle
[0] = 2;
1369 r600_src
->swizzle
[1] = 2;
1370 r600_src
->swizzle
[2] = 2;
1371 r600_src
->swizzle
[3] = 2;
1373 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1375 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1377 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1379 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1380 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1381 r600_src
->sel
= ctx
->tess_input_info
;
1382 r600_src
->swizzle
[0] = 2;
1383 r600_src
->swizzle
[1] = 2;
1384 r600_src
->swizzle
[2] = 2;
1385 r600_src
->swizzle
[3] = 2;
1387 r600_src
->sel
= ctx
->tess_input_info
;
1388 r600_src
->swizzle
[0] = 3;
1389 r600_src
->swizzle
[1] = 3;
1390 r600_src
->swizzle
[2] = 3;
1391 r600_src
->swizzle
[3] = 3;
1393 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1395 r600_src
->swizzle
[0] = 0;
1396 r600_src
->swizzle
[1] = 0;
1397 r600_src
->swizzle
[2] = 0;
1398 r600_src
->swizzle
[3] = 0;
1399 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1401 r600_src
->swizzle
[0] = 3;
1402 r600_src
->swizzle
[1] = 3;
1403 r600_src
->swizzle
[2] = 3;
1404 r600_src
->swizzle
[3] = 3;
1407 if (tgsi_src
->Register
.Indirect
)
1408 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1409 r600_src
->sel
= tgsi_src
->Register
.Index
;
1410 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1412 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1413 if (tgsi_src
->Register
.Dimension
) {
1414 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1415 if (tgsi_src
->Dimension
.Indirect
) {
1416 r600_src
->kc_rel
= 1;
1422 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1423 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1424 unsigned int dst_reg
)
1426 struct r600_bytecode_vtx vtx
;
1427 unsigned int ar_reg
;
1431 struct r600_bytecode_alu alu
;
1433 memset(&alu
, 0, sizeof(alu
));
1435 alu
.op
= ALU_OP2_ADD_INT
;
1436 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1437 alu
.src
[0].chan
= ar_chan
;
1439 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1440 alu
.src
[1].value
= offset
;
1442 alu
.dst
.sel
= dst_reg
;
1443 alu
.dst
.chan
= ar_chan
;
1447 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1452 ar_reg
= ctx
->bc
->ar_reg
;
1455 memset(&vtx
, 0, sizeof(vtx
));
1456 vtx
.buffer_id
= cb_idx
;
1457 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1458 vtx
.src_gpr
= ar_reg
;
1459 vtx
.src_sel_x
= ar_chan
;
1460 vtx
.mega_fetch_count
= 16;
1461 vtx
.dst_gpr
= dst_reg
;
1462 vtx
.dst_sel_x
= 0; /* SEL_X */
1463 vtx
.dst_sel_y
= 1; /* SEL_Y */
1464 vtx
.dst_sel_z
= 2; /* SEL_Z */
1465 vtx
.dst_sel_w
= 3; /* SEL_W */
1466 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1467 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1468 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1469 vtx
.endian
= r600_endian_swap(32);
1470 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1472 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1478 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1480 struct r600_bytecode_vtx vtx
;
1482 unsigned index
= src
->Register
.Index
;
1483 unsigned vtx_id
= src
->Dimension
.Index
;
1484 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1485 int offset_chan
= vtx_id
% 3;
1488 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1489 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1491 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1494 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1495 t2
= r600_get_temp(ctx
);
1497 if (src
->Dimension
.Indirect
) {
1499 struct r600_bytecode_alu alu
;
1502 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1503 if (src
->DimIndirect
.Index
> 0) {
1504 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1512 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1513 at least this is what fglrx seems to do. */
1514 for (i
= 0; i
< 3; i
++) {
1515 treg
[i
] = r600_get_temp(ctx
);
1517 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1519 for (i
= 0; i
< 3; i
++) {
1520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1521 alu
.op
= ALU_OP1_MOV
;
1522 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1523 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1524 alu
.dst
.sel
= treg
[i
];
1528 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1533 alu
.op
= ALU_OP1_MOV
;
1534 alu
.src
[0].sel
= treg
[0];
1539 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1546 if (src
->Register
.Indirect
) {
1548 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1550 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1552 /* pull the value from index_reg */
1553 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1556 V_SQ_ALU_SRC_LITERAL
, first
);
1559 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1562 V_SQ_ALU_SRC_LITERAL
, 4,
1563 offset_reg
, offset_chan
);
1568 index
= src
->Register
.Index
- first
;
1571 memset(&vtx
, 0, sizeof(vtx
));
1572 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1573 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1574 vtx
.src_gpr
= offset_reg
;
1575 vtx
.src_sel_x
= offset_chan
;
1576 vtx
.offset
= index
* 16; /*bytes*/
1577 vtx
.mega_fetch_count
= 16;
1578 vtx
.dst_gpr
= dst_reg
;
1579 vtx
.dst_sel_x
= 0; /* SEL_X */
1580 vtx
.dst_sel_y
= 1; /* SEL_Y */
1581 vtx
.dst_sel_z
= 2; /* SEL_Z */
1582 vtx
.dst_sel_w
= 3; /* SEL_W */
1583 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1584 vtx
.use_const_fields
= 1;
1586 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1589 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1595 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1597 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1600 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1601 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1603 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1604 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1605 /* primitive id is in R0.z */
1606 ctx
->src
[i
].sel
= 0;
1607 ctx
->src
[i
].swizzle
[0] = 2;
1610 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1611 int treg
= r600_get_temp(ctx
);
1613 fetch_gs_input(ctx
, src
, treg
);
1614 ctx
->src
[i
].sel
= treg
;
1615 ctx
->src
[i
].rel
= 0;
1622 /* Tessellation shaders pass outputs to the next shader using LDS.
1624 * LS outputs = TCS(HS) inputs
1625 * TCS(HS) outputs = TES(DS) inputs
1627 * The LDS layout is:
1628 * - TCS inputs for patch 0
1629 * - TCS inputs for patch 1
1630 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1632 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1633 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1634 * - TCS outputs for patch 1
1635 * - Per-patch TCS outputs for patch 1
1636 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1637 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1640 * All three shaders VS(LS), TCS, TES share the same LDS space.
1642 /* this will return with the dw address in temp_reg.x */
1643 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1644 const struct tgsi_full_dst_register
*dst
,
1645 const struct tgsi_full_src_register
*src
,
1646 int stride_bytes_reg
, int stride_bytes_chan
)
1648 struct tgsi_full_dst_register reg
;
1649 ubyte
*name
, *index
, *array_first
;
1652 struct tgsi_shader_info
*info
= &ctx
->info
;
1653 /* Set the register description. The address computation is the same
1654 * for sources and destinations. */
1656 reg
.Register
.File
= src
->Register
.File
;
1657 reg
.Register
.Index
= src
->Register
.Index
;
1658 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1659 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1660 reg
.Indirect
= src
->Indirect
;
1661 reg
.Dimension
= src
->Dimension
;
1662 reg
.DimIndirect
= src
->DimIndirect
;
1666 /* If the register is 2-dimensional (e.g. an array of vertices
1667 * in a primitive), calculate the base address of the vertex. */
1668 if (reg
.Register
.Dimension
) {
1670 if (reg
.Dimension
.Indirect
) {
1672 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1674 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1675 /* pull the value from index_reg */
1679 sel
= V_SQ_ALU_SRC_LITERAL
;
1680 chan
= reg
.Dimension
.Index
;
1683 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1685 stride_bytes_reg
, stride_bytes_chan
,
1692 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1693 name
= info
->input_semantic_name
;
1694 index
= info
->input_semantic_index
;
1695 array_first
= info
->input_array_first
;
1696 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1697 name
= info
->output_semantic_name
;
1698 index
= info
->output_semantic_index
;
1699 array_first
= info
->output_array_first
;
1704 if (reg
.Register
.Indirect
) {
1707 /* Add the relative address of the element. */
1708 if (reg
.Indirect
.ArrayID
)
1709 first
= array_first
[reg
.Indirect
.ArrayID
];
1711 first
= reg
.Register
.Index
;
1713 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1715 /* pull the value from index_reg */
1716 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1718 V_SQ_ALU_SRC_LITERAL
, 16,
1724 param
= r600_get_lds_unique_index(name
[first
],
1728 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1729 index
[reg
.Register
.Index
]);
1732 /* add to base_addr - passed in temp_reg.x */
1734 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1737 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1745 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1748 struct r600_bytecode_alu alu
;
1751 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1752 ctx
->bc
->force_add_cf
= 1;
1753 for (i
= 1; i
< 4; i
++) {
1754 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1757 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1761 for (i
= 0; i
< 4; i
++) {
1762 /* emit an LDS_READ_RET */
1763 memset(&alu
, 0, sizeof(alu
));
1764 alu
.op
= LDS_OP1_LDS_READ_RET
;
1765 alu
.src
[0].sel
= temp_reg
;
1766 alu
.src
[0].chan
= i
;
1767 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1768 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1770 alu
.is_lds_idx_op
= true;
1772 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1776 for (i
= 0; i
< 4; i
++) {
1777 /* then read from LDS_OQ_A_POP */
1778 memset(&alu
, 0, sizeof(alu
));
1780 alu
.op
= ALU_OP1_MOV
;
1781 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1782 alu
.src
[0].chan
= 0;
1783 alu
.dst
.sel
= dst_reg
;
1787 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1794 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1797 unsigned temp_reg
= r600_get_temp(ctx
);
1799 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1800 src
->Register
.Dimension
? false : true);
1804 /* the base address is now in temp.x */
1805 r
= r600_get_byte_address(ctx
, temp_reg
,
1806 NULL
, src
, ctx
->tess_output_info
, 1);
1810 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1816 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1819 unsigned temp_reg
= r600_get_temp(ctx
);
1821 /* t.x = ips * r0.y */
1822 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1824 ctx
->tess_input_info
, 0,
1830 /* the base address is now in temp.x */
1831 r
= r600_get_byte_address(ctx
, temp_reg
,
1832 NULL
, src
, ctx
->tess_input_info
, 1);
1836 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1842 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1845 unsigned temp_reg
= r600_get_temp(ctx
);
1847 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1848 src
->Register
.Dimension
? false : true);
1851 /* the base address is now in temp.x */
1852 r
= r600_get_byte_address(ctx
, temp_reg
,
1854 ctx
->tess_output_info
, 1);
1858 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1864 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1866 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1869 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1870 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1872 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1873 int treg
= r600_get_temp(ctx
);
1874 fetch_tes_input(ctx
, src
, treg
);
1875 ctx
->src
[i
].sel
= treg
;
1876 ctx
->src
[i
].rel
= 0;
1878 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1879 int treg
= r600_get_temp(ctx
);
1880 fetch_tcs_input(ctx
, src
, treg
);
1881 ctx
->src
[i
].sel
= treg
;
1882 ctx
->src
[i
].rel
= 0;
1884 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1885 int treg
= r600_get_temp(ctx
);
1886 fetch_tcs_output(ctx
, src
, treg
);
1887 ctx
->src
[i
].sel
= treg
;
1888 ctx
->src
[i
].rel
= 0;
1894 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1896 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1897 struct r600_bytecode_alu alu
;
1898 int i
, j
, k
, nconst
, r
;
1900 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1901 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1904 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1906 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1907 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1911 if (ctx
->src
[i
].rel
) {
1912 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1913 int treg
= r600_get_temp(ctx
);
1914 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1917 ctx
->src
[i
].kc_bank
= 0;
1918 ctx
->src
[i
].kc_rel
= 0;
1919 ctx
->src
[i
].sel
= treg
;
1920 ctx
->src
[i
].rel
= 0;
1923 int treg
= r600_get_temp(ctx
);
1924 for (k
= 0; k
< 4; k
++) {
1925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1926 alu
.op
= ALU_OP1_MOV
;
1927 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1928 alu
.src
[0].chan
= k
;
1929 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1930 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1931 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1941 ctx
->src
[i
].sel
= treg
;
1949 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1950 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1952 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1953 struct r600_bytecode_alu alu
;
1954 int i
, j
, k
, nliteral
, r
;
1956 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1957 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1961 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1962 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1963 int treg
= r600_get_temp(ctx
);
1964 for (k
= 0; k
< 4; k
++) {
1965 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1966 alu
.op
= ALU_OP1_MOV
;
1967 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1968 alu
.src
[0].chan
= k
;
1969 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1975 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1979 ctx
->src
[i
].sel
= treg
;
1986 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1988 int i
, r
, count
= ctx
->shader
->ninput
;
1990 for (i
= 0; i
< count
; i
++) {
1991 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1992 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2000 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2001 int stream
, unsigned *stream_item_size
)
2003 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2004 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2007 /* Sanity checking. */
2008 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2009 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2013 for (i
= 0; i
< so
->num_outputs
; i
++) {
2014 if (so
->output
[i
].output_buffer
>= 4) {
2015 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2016 so
->output
[i
].output_buffer
);
2022 /* Initialize locations where the outputs are stored. */
2023 for (i
= 0; i
< so
->num_outputs
; i
++) {
2025 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2026 start_comp
[i
] = so
->output
[i
].start_component
;
2027 /* Lower outputs with dst_offset < start_component.
2029 * We can only output 4D vectors with a write mask, e.g. we can
2030 * only output the W component at offset 3, etc. If we want
2031 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2032 * to move it to X and output X. */
2033 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2034 unsigned tmp
= r600_get_temp(ctx
);
2036 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2037 struct r600_bytecode_alu alu
;
2038 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2039 alu
.op
= ALU_OP1_MOV
;
2040 alu
.src
[0].sel
= so_gpr
[i
];
2041 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2046 if (j
== so
->output
[i
].num_components
- 1)
2048 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2057 /* Write outputs to buffers. */
2058 for (i
= 0; i
< so
->num_outputs
; i
++) {
2059 struct r600_bytecode_output output
;
2061 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2064 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2065 output
.gpr
= so_gpr
[i
];
2066 output
.elem_size
= so
->output
[i
].num_components
- 1;
2067 if (output
.elem_size
== 2)
2068 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2069 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2070 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2071 output
.burst_count
= 1;
2072 /* array_size is an upper limit for the burst_count
2073 * with MEM_STREAM instructions */
2074 output
.array_size
= 0xFFF;
2075 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2077 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2078 switch (so
->output
[i
].output_buffer
) {
2080 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2083 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2086 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2089 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2092 output
.op
+= so
->output
[i
].stream
* 4;
2093 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2094 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2096 switch (so
->output
[i
].output_buffer
) {
2098 output
.op
= CF_OP_MEM_STREAM0
;
2101 output
.op
= CF_OP_MEM_STREAM1
;
2104 output
.op
= CF_OP_MEM_STREAM2
;
2107 output
.op
= CF_OP_MEM_STREAM3
;
2110 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2112 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2121 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2123 struct r600_bytecode_alu alu
;
2126 if (!ctx
->shader
->vs_out_edgeflag
)
2129 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2131 /* clamp(x, 0, 1) */
2132 memset(&alu
, 0, sizeof(alu
));
2133 alu
.op
= ALU_OP1_MOV
;
2134 alu
.src
[0].sel
= reg
;
2139 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2141 memset(&alu
, 0, sizeof(alu
));
2142 alu
.op
= ALU_OP1_FLT_TO_INT
;
2143 alu
.src
[0].sel
= reg
;
2147 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2150 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2151 struct r600_pipe_shader
*gs
,
2152 struct pipe_stream_output_info
*so
)
2154 struct r600_shader_ctx ctx
= {};
2155 struct r600_shader
*gs_shader
= &gs
->shader
;
2156 struct r600_pipe_shader
*cshader
;
2157 int ocnt
= gs_shader
->noutput
;
2158 struct r600_bytecode_alu alu
;
2159 struct r600_bytecode_vtx vtx
;
2160 struct r600_bytecode_output output
;
2161 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2162 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2163 int i
, j
, next_clip_pos
= 61, next_param
= 0;
2165 bool only_ring_0
= true;
2166 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2170 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2171 sizeof(struct r600_shader_io
));
2173 cshader
->shader
.noutput
= ocnt
;
2175 ctx
.shader
= &cshader
->shader
;
2176 ctx
.bc
= &ctx
.shader
->bc
;
2177 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2179 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2180 rctx
->screen
->has_compressed_msaa_texturing
);
2182 ctx
.bc
->isa
= rctx
->isa
;
2185 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2187 /* R0.x = R0.x & 0x3fffffff */
2188 memset(&alu
, 0, sizeof(alu
));
2189 alu
.op
= ALU_OP2_AND_INT
;
2190 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2191 alu
.src
[1].value
= 0x3fffffff;
2193 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2195 /* R0.y = R0.x >> 30 */
2196 memset(&alu
, 0, sizeof(alu
));
2197 alu
.op
= ALU_OP2_LSHR_INT
;
2198 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2199 alu
.src
[1].value
= 0x1e;
2203 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2205 /* fetch vertex data from GSVS ring */
2206 for (i
= 0; i
< ocnt
; ++i
) {
2207 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2210 out
->ring_offset
= i
* 16;
2212 memset(&vtx
, 0, sizeof(vtx
));
2213 vtx
.op
= FETCH_OP_VFETCH
;
2214 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2215 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2216 vtx
.mega_fetch_count
= 16;
2217 vtx
.offset
= out
->ring_offset
;
2218 vtx
.dst_gpr
= out
->gpr
;
2224 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2225 vtx
.use_const_fields
= 1;
2227 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2230 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2232 ctx
.temp_reg
= i
+ 1;
2233 for (ring
= 3; ring
>= 0; --ring
) {
2234 bool enabled
= false;
2235 for (i
= 0; i
< so
->num_outputs
; i
++) {
2236 if (so
->output
[i
].stream
== ring
) {
2239 only_ring_0
= false;
2243 if (ring
!= 0 && !enabled
) {
2244 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2249 // Patch up jump label
2250 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2251 cf_pop
= ctx
.bc
->cf_last
;
2253 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2254 cf_jump
->pop_count
= 1;
2255 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2256 cf_pop
->pop_count
= 1;
2259 /* PRED_SETE_INT __, R0.y, ring */
2260 memset(&alu
, 0, sizeof(alu
));
2261 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2262 alu
.src
[0].chan
= 1;
2263 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2264 alu
.src
[1].value
= ring
;
2265 alu
.execute_mask
= 1;
2266 alu
.update_pred
= 1;
2268 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2270 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2271 cf_jump
= ctx
.bc
->cf_last
;
2274 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2275 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2278 /* bc adds nops - copy it */
2279 if (ctx
.bc
->chip_class
== R600
) {
2280 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2281 alu
.op
= ALU_OP0_NOP
;
2283 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2285 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2288 /* export vertex data */
2289 /* XXX factor out common code with r600_shader_from_tgsi ? */
2290 for (i
= 0; i
< ocnt
; ++i
) {
2291 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2292 bool instream0
= true;
2293 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2296 for (j
= 0; j
< so
->num_outputs
; j
++) {
2297 if (so
->output
[j
].register_index
== i
) {
2298 if (so
->output
[j
].stream
== 0)
2300 if (so
->output
[j
].stream
> 0)
2306 memset(&output
, 0, sizeof(output
));
2307 output
.gpr
= out
->gpr
;
2308 output
.elem_size
= 3;
2309 output
.swizzle_x
= 0;
2310 output
.swizzle_y
= 1;
2311 output
.swizzle_z
= 2;
2312 output
.swizzle_w
= 3;
2313 output
.burst_count
= 1;
2314 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2315 output
.op
= CF_OP_EXPORT
;
2316 switch (out
->name
) {
2317 case TGSI_SEMANTIC_POSITION
:
2318 output
.array_base
= 60;
2319 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2322 case TGSI_SEMANTIC_PSIZE
:
2323 output
.array_base
= 61;
2324 if (next_clip_pos
== 61)
2326 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2327 output
.swizzle_y
= 7;
2328 output
.swizzle_z
= 7;
2329 output
.swizzle_w
= 7;
2330 ctx
.shader
->vs_out_misc_write
= 1;
2331 ctx
.shader
->vs_out_point_size
= 1;
2333 case TGSI_SEMANTIC_LAYER
:
2335 /* duplicate it as PARAM to pass to the pixel shader */
2336 output
.array_base
= next_param
++;
2337 r600_bytecode_add_output(ctx
.bc
, &output
);
2338 last_exp_param
= ctx
.bc
->cf_last
;
2340 output
.array_base
= 61;
2341 if (next_clip_pos
== 61)
2343 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2344 output
.swizzle_x
= 7;
2345 output
.swizzle_y
= 7;
2346 output
.swizzle_z
= 0;
2347 output
.swizzle_w
= 7;
2348 ctx
.shader
->vs_out_misc_write
= 1;
2349 ctx
.shader
->vs_out_layer
= 1;
2351 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2353 /* duplicate it as PARAM to pass to the pixel shader */
2354 output
.array_base
= next_param
++;
2355 r600_bytecode_add_output(ctx
.bc
, &output
);
2356 last_exp_param
= ctx
.bc
->cf_last
;
2358 output
.array_base
= 61;
2359 if (next_clip_pos
== 61)
2361 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2362 ctx
.shader
->vs_out_misc_write
= 1;
2363 ctx
.shader
->vs_out_viewport
= 1;
2364 output
.swizzle_x
= 7;
2365 output
.swizzle_y
= 7;
2366 output
.swizzle_z
= 7;
2367 output
.swizzle_w
= 0;
2369 case TGSI_SEMANTIC_CLIPDIST
:
2370 /* spi_sid is 0 for clipdistance outputs that were generated
2371 * for clipvertex - we don't need to pass them to PS */
2372 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2374 /* duplicate it as PARAM to pass to the pixel shader */
2375 output
.array_base
= next_param
++;
2376 r600_bytecode_add_output(ctx
.bc
, &output
);
2377 last_exp_param
= ctx
.bc
->cf_last
;
2379 output
.array_base
= next_clip_pos
++;
2380 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2382 case TGSI_SEMANTIC_FOG
:
2383 output
.swizzle_y
= 4; /* 0 */
2384 output
.swizzle_z
= 4; /* 0 */
2385 output
.swizzle_w
= 5; /* 1 */
2388 output
.array_base
= next_param
++;
2391 r600_bytecode_add_output(ctx
.bc
, &output
);
2392 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2393 last_exp_param
= ctx
.bc
->cf_last
;
2395 last_exp_pos
= ctx
.bc
->cf_last
;
2398 if (!last_exp_pos
) {
2399 memset(&output
, 0, sizeof(output
));
2401 output
.elem_size
= 3;
2402 output
.swizzle_x
= 7;
2403 output
.swizzle_y
= 7;
2404 output
.swizzle_z
= 7;
2405 output
.swizzle_w
= 7;
2406 output
.burst_count
= 1;
2408 output
.op
= CF_OP_EXPORT
;
2409 output
.array_base
= 60;
2410 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2411 r600_bytecode_add_output(ctx
.bc
, &output
);
2412 last_exp_pos
= ctx
.bc
->cf_last
;
2415 if (!last_exp_param
) {
2416 memset(&output
, 0, sizeof(output
));
2418 output
.elem_size
= 3;
2419 output
.swizzle_x
= 7;
2420 output
.swizzle_y
= 7;
2421 output
.swizzle_z
= 7;
2422 output
.swizzle_w
= 7;
2423 output
.burst_count
= 1;
2425 output
.op
= CF_OP_EXPORT
;
2426 output
.array_base
= next_param
++;
2427 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2428 r600_bytecode_add_output(ctx
.bc
, &output
);
2429 last_exp_param
= ctx
.bc
->cf_last
;
2432 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2433 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2435 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2436 cf_pop
= ctx
.bc
->cf_last
;
2438 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2439 cf_jump
->pop_count
= 1;
2440 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2441 cf_pop
->pop_count
= 1;
2443 if (ctx
.bc
->chip_class
== CAYMAN
)
2444 cm_bytecode_add_cf_end(ctx
.bc
);
2446 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2447 ctx
.bc
->cf_last
->end_of_program
= 1;
2450 gs
->gs_copy_shader
= cshader
;
2451 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2455 return r600_bytecode_build(ctx
.bc
);
2458 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2461 struct r600_bytecode_alu alu
;
2464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2465 alu
.op
= ALU_OP2_ADD_INT
;
2466 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2467 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2468 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2469 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2472 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2479 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
)
2481 struct r600_bytecode_output output
;
2482 int i
, k
, ring_offset
;
2483 int effective_stream
= stream
== -1 ? 0 : stream
;
2486 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2487 if (ctx
->gs_for_vs
) {
2488 /* for ES we need to lookup corresponding ring offset expected by GS
2489 * (map this output to GS input by name and sid) */
2490 /* FIXME precompute offsets */
2492 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2493 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2494 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2495 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2496 ring_offset
= in
->ring_offset
;
2499 if (ring_offset
== -1)
2502 ring_offset
= idx
* 16;
2506 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2508 /* next_ring_offset after parsing input decls contains total size of
2509 * single vertex data, gs_next_vertex - current vertex index */
2511 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2513 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2514 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2515 output
.elem_size
= 3;
2516 output
.comp_mask
= 0xF;
2517 output
.burst_count
= 1;
2520 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2522 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2527 output
.op
= CF_OP_MEM_RING
; break;
2529 output
.op
= CF_OP_MEM_RING1
; break;
2531 output
.op
= CF_OP_MEM_RING2
; break;
2533 output
.op
= CF_OP_MEM_RING3
; break;
2537 output
.array_base
= ring_offset
>> 2; /* in dwords */
2538 output
.array_size
= 0xfff;
2539 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2541 output
.array_base
= ring_offset
>> 2; /* in dwords */
2542 r600_bytecode_add_output(ctx
->bc
, &output
);
2545 ++ctx
->gs_next_vertex
;
2550 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2553 struct r600_bytecode_vtx vtx
;
2554 int temp_val
= ctx
->temp_reg
;
2555 /* need to store the TCS output somewhere */
2556 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2558 V_SQ_ALU_SRC_LITERAL
, 0,
2563 /* used by VS/TCS */
2564 if (ctx
->tess_input_info
) {
2565 /* fetch tcs input values into resv space */
2566 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2567 vtx
.op
= FETCH_OP_VFETCH
;
2568 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2569 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2570 vtx
.mega_fetch_count
= 16;
2571 vtx
.data_format
= FMT_32_32_32_32
;
2572 vtx
.num_format_all
= 2;
2573 vtx
.format_comp_all
= 1;
2574 vtx
.use_const_fields
= 0;
2575 vtx
.endian
= r600_endian_swap(32);
2576 vtx
.srf_mode_all
= 1;
2578 vtx
.dst_gpr
= ctx
->tess_input_info
;
2583 vtx
.src_gpr
= temp_val
;
2586 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2591 /* used by TCS/TES */
2592 if (ctx
->tess_output_info
) {
2593 /* fetch tcs output values into resv space */
2594 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2595 vtx
.op
= FETCH_OP_VFETCH
;
2596 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2597 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2598 vtx
.mega_fetch_count
= 16;
2599 vtx
.data_format
= FMT_32_32_32_32
;
2600 vtx
.num_format_all
= 2;
2601 vtx
.format_comp_all
= 1;
2602 vtx
.use_const_fields
= 0;
2603 vtx
.endian
= r600_endian_swap(32);
2604 vtx
.srf_mode_all
= 1;
2606 vtx
.dst_gpr
= ctx
->tess_output_info
;
2611 vtx
.src_gpr
= temp_val
;
2614 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2621 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2626 /* fetch tcs input values into input_vals */
2627 ctx
->tess_input_info
= r600_get_temp(ctx
);
2628 ctx
->tess_output_info
= 0;
2629 r
= r600_fetch_tess_io_info(ctx
);
2633 temp_reg
= r600_get_temp(ctx
);
2634 /* dst reg contains LDS address stride * idx */
2635 /* MUL vertexID, vertex_dw_stride */
2636 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2638 ctx
->tess_input_info
, 1,
2639 0, 1); /* rel id in r0.y? */
2643 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2644 struct r600_bytecode_alu alu
;
2645 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2648 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2651 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2656 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2658 temp_reg
, param
? 1 : 0,
2659 V_SQ_ALU_SRC_LITERAL
, 8);
2664 for (j
= 0; j
< 2; j
++) {
2665 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2667 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2668 alu
.src
[0].sel
= temp_reg
;
2669 alu
.src
[0].chan
= chan
;
2670 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2671 alu
.src
[1].chan
= j
* 2;
2672 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2673 alu
.src
[2].chan
= (j
* 2) + 1;
2677 alu
.is_lds_idx_op
= true;
2678 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2686 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2688 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2689 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2691 int temp_reg
= r600_get_temp(ctx
);
2692 struct r600_bytecode_alu alu
;
2693 unsigned write_mask
= dst
->Register
.WriteMask
;
2695 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2698 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2702 /* the base address is now in temp.x */
2703 r
= r600_get_byte_address(ctx
, temp_reg
,
2704 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2709 lasti
= tgsi_last_instruction(write_mask
);
2710 for (i
= 1; i
<= lasti
; i
++) {
2712 if (!(write_mask
& (1 << i
)))
2714 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2717 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2722 for (i
= 0; i
<= lasti
; i
++) {
2723 if (!(write_mask
& (1 << i
)))
2726 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2727 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2729 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2730 alu
.src
[0].sel
= temp_reg
;
2731 alu
.src
[0].chan
= i
;
2733 alu
.src
[1].sel
= dst
->Register
.Index
;
2734 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2735 alu
.src
[1].chan
= i
;
2737 alu
.src
[2].sel
= dst
->Register
.Index
;
2738 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2739 alu
.src
[2].chan
= i
+ 1;
2743 alu
.is_lds_idx_op
= true;
2744 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2750 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2751 alu
.op
= LDS_OP2_LDS_WRITE
;
2752 alu
.src
[0].sel
= temp_reg
;
2753 alu
.src
[0].chan
= i
;
2755 alu
.src
[1].sel
= dst
->Register
.Index
;
2756 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2757 alu
.src
[1].chan
= i
;
2759 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2762 alu
.is_lds_idx_op
= true;
2763 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2770 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2774 unsigned temp_reg
= r600_get_temp(ctx
);
2775 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2776 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2779 param
= r600_get_lds_unique_index(name
, 0);
2780 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2784 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2787 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2791 do_lds_fetch_values(ctx
, temp_reg
, dreg
);
2795 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2798 int stride
, outer_comps
, inner_comps
;
2799 int tessinner_idx
= -1, tessouter_idx
= -1;
2801 int temp_reg
= r600_get_temp(ctx
);
2802 int treg
[3] = {-1, -1, -1};
2803 struct r600_bytecode_alu alu
;
2804 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2806 /* only execute factor emission for invocation 0 */
2807 /* PRED_SETE_INT __, R0.x, 0 */
2808 memset(&alu
, 0, sizeof(alu
));
2809 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2810 alu
.src
[0].chan
= 2;
2811 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2812 alu
.execute_mask
= 1;
2813 alu
.update_pred
= 1;
2815 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2817 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2818 cf_jump
= ctx
->bc
->cf_last
;
2820 treg
[0] = r600_get_temp(ctx
);
2821 switch (ctx
->shader
->tcs_prim_mode
) {
2822 case PIPE_PRIM_LINES
:
2823 stride
= 8; /* 2 dwords, 1 vec2 store */
2827 case PIPE_PRIM_TRIANGLES
:
2828 stride
= 16; /* 4 dwords, 1 vec4 store */
2831 treg
[1] = r600_get_temp(ctx
);
2833 case PIPE_PRIM_QUADS
:
2834 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2837 treg
[1] = r600_get_temp(ctx
);
2838 treg
[2] = r600_get_temp(ctx
);
2845 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2846 /* TF_WRITE takes index in R.x, value in R.y */
2847 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2848 if (ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_TESSINNER
)
2850 if (ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_TESSOUTER
)
2854 if (tessouter_idx
== -1)
2857 if (tessinner_idx
== -1 && inner_comps
)
2860 if (tessouter_idx
!= -1) {
2861 r
= r600_tess_factor_read(ctx
, tessouter_idx
);
2866 if (tessinner_idx
!= -1) {
2867 r
= r600_tess_factor_read(ctx
, tessinner_idx
);
2872 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2873 /* r.x = relpatchid(r0.y) * tf_stride */
2875 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2876 /* add incoming r0.w to it: t.x = t.x + r0.w */
2877 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2880 V_SQ_ALU_SRC_LITERAL
, stride
,
2885 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2886 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2887 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2889 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
2892 else if (out_comp
== 0)
2896 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2897 treg
[i
/ 2], (2 * (i
% 2)),
2899 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2902 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2903 treg
[i
/ 2], 1 + (2 * (i
%2)),
2904 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
2909 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2910 struct r600_bytecode_gds gds
;
2912 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
2913 gds
.src_gpr
= treg
[i
/ 2];
2914 gds
.src_sel_x
= 2 * (i
% 2);
2915 gds
.src_sel_y
= 1 + (2 * (i
% 2));
2921 gds
.op
= FETCH_OP_TF_WRITE
;
2922 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
2927 // Patch up jump label
2928 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
2929 cf_pop
= ctx
->bc
->cf_last
;
2931 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2932 cf_jump
->pop_count
= 1;
2933 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2934 cf_pop
->pop_count
= 1;
2940 * We have to work out the thread ID for load and atomic
2941 * operations, which store the returned value to an index
2942 * in an intermediate buffer.
2943 * The index is calculated by taking the thread id,
2944 * calculated from the MBCNT instructions.
2945 * Then the shader engine ID is multiplied by 256,
2946 * and the wave id is added.
2947 * Then the result is multipled by 64 and thread id is
2950 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
2952 struct r600_bytecode_alu alu
;
2955 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2956 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
2957 alu
.dst
.sel
= ctx
->temp_reg
;
2959 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2960 alu
.src
[0].value
= 0xffffffff;
2962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2966 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2967 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
2968 alu
.dst
.sel
= ctx
->temp_reg
;
2970 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2971 alu
.src
[0].value
= 0xffffffff;
2973 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2978 alu
.op
= ALU_OP3_MULADD_UINT24
;
2979 alu
.dst
.sel
= ctx
->temp_reg
;
2981 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
2982 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2983 alu
.src
[1].value
= 256;
2984 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
2988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2992 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2993 ctx
->thread_id_gpr
, 1,
2995 V_SQ_ALU_SRC_LITERAL
, 0x40,
3002 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3003 struct r600_pipe_shader
*pipeshader
,
3004 union r600_shader_key key
)
3006 struct r600_screen
*rscreen
= rctx
->screen
;
3007 struct r600_shader
*shader
= &pipeshader
->shader
;
3008 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3009 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3010 struct tgsi_full_immediate
*immediate
;
3011 struct r600_shader_ctx ctx
;
3012 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3013 unsigned output_done
, noutput
;
3016 int next_param_base
= 0, next_clip_base
;
3017 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3019 bool ring_outputs
= false;
3020 bool lds_outputs
= false;
3021 bool lds_inputs
= false;
3022 bool pos_emitted
= false;
3024 ctx
.bc
= &shader
->bc
;
3025 ctx
.shader
= shader
;
3026 ctx
.native_integers
= true;
3028 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3029 rscreen
->has_compressed_msaa_texturing
);
3030 ctx
.tokens
= tokens
;
3031 tgsi_scan_shader(tokens
, &ctx
.info
);
3032 shader
->indirect_files
= ctx
.info
.indirect_files
;
3034 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3035 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3036 shader
->nsys_inputs
= 0;
3038 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0;
3039 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3040 tgsi_parse_init(&ctx
.parse
, tokens
);
3041 ctx
.type
= ctx
.info
.processor
;
3042 shader
->processor_type
= ctx
.type
;
3043 ctx
.bc
->type
= shader
->processor_type
;
3046 case PIPE_SHADER_VERTEX
:
3047 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3048 shader
->vs_as_es
= key
.vs
.as_es
;
3049 shader
->vs_as_ls
= key
.vs
.as_ls
;
3050 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3051 if (shader
->vs_as_es
)
3052 ring_outputs
= true;
3053 if (shader
->vs_as_ls
)
3056 case PIPE_SHADER_GEOMETRY
:
3057 ring_outputs
= true;
3058 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3059 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3061 case PIPE_SHADER_TESS_CTRL
:
3062 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3063 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3067 case PIPE_SHADER_TESS_EVAL
:
3068 shader
->tes_as_es
= key
.tes
.as_es
;
3069 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3071 if (shader
->tes_as_es
)
3072 ring_outputs
= true;
3074 case PIPE_SHADER_FRAGMENT
:
3075 shader
->two_side
= key
.ps
.color_two_side
;
3076 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3082 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3083 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3085 ctx
.gs_for_vs
= NULL
;
3088 ctx
.next_ring_offset
= 0;
3089 ctx
.gs_out_ring_offset
= 0;
3090 ctx
.gs_next_vertex
= 0;
3091 ctx
.gs_stream_output_info
= &so
;
3094 ctx
.fixed_pt_position_gpr
= -1;
3095 ctx
.fragcoord_input
= -1;
3096 ctx
.colors_used
= 0;
3097 ctx
.clip_vertex_write
= 0;
3099 shader
->nr_ps_color_exports
= 0;
3100 shader
->nr_ps_max_color_exports
= 0;
3103 /* register allocations */
3104 /* Values [0,127] correspond to GPR[0..127].
3105 * Values [128,159] correspond to constant buffer bank 0
3106 * Values [160,191] correspond to constant buffer bank 1
3107 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3108 * Values [256,287] correspond to constant buffer bank 2 (EG)
3109 * Values [288,319] correspond to constant buffer bank 3 (EG)
3110 * Other special values are shown in the list below.
3111 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3112 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3113 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3114 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3115 * 248 SQ_ALU_SRC_0: special constant 0.0.
3116 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3117 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3118 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3119 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3120 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3121 * 254 SQ_ALU_SRC_PV: previous vector result.
3122 * 255 SQ_ALU_SRC_PS: previous scalar result.
3124 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3125 ctx
.file_offset
[i
] = 0;
3128 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3130 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3131 if (ctx
.info
.num_inputs
)
3132 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3134 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3135 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3136 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3138 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3140 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3141 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3142 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3144 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3145 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3146 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3147 bool add_tesscoord
= false, add_tess_inout
= false;
3148 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3149 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3150 /* if we have tesscoord save one reg */
3151 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3152 add_tesscoord
= true;
3153 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3154 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3155 add_tess_inout
= true;
3157 if (add_tesscoord
|| add_tess_inout
)
3158 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3160 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3163 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3164 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3165 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3166 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3167 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3169 /* Outside the GPR range. This will be translated to one of the
3170 * kcache banks later. */
3171 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3173 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3174 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3175 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3176 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3177 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3179 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3180 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3181 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3182 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3183 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3184 ctx
.tess_input_info
= 0;
3185 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3186 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3187 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3188 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3189 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3190 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3191 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3192 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3193 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3194 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3195 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3198 ctx
.gs_rotated_input
[0] = 0;
3199 ctx
.gs_rotated_input
[1] = 1;
3202 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3205 if (shader
->uses_images
&& ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3206 ctx
.thread_id_gpr
= ctx
.temp_reg
;
3209 ctx
.thread_id_gpr
= 0;
3211 shader
->max_arrays
= 0;
3212 shader
->num_arrays
= 0;
3213 if (indirect_gprs
) {
3215 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3216 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3217 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3218 ctx
.file_offset
[TGSI_FILE_INPUT
],
3221 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3222 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3223 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3224 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3230 ctx
.literals
= NULL
;
3232 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3233 ctx
.info
.colors_written
== 1;
3234 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3235 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3237 if (shader
->vs_as_gs_a
)
3238 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3240 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3241 r600_fetch_tess_io_info(&ctx
);
3243 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3244 tgsi_parse_token(&ctx
.parse
);
3245 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3246 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3247 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3248 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3249 if(ctx
.literals
== NULL
) {
3253 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3254 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3255 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3256 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3259 case TGSI_TOKEN_TYPE_DECLARATION
:
3260 r
= tgsi_declaration(&ctx
);
3264 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3265 case TGSI_TOKEN_TYPE_PROPERTY
:
3268 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3274 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3275 shader
->ring_item_sizes
[1] = 0;
3276 shader
->ring_item_sizes
[2] = 0;
3277 shader
->ring_item_sizes
[3] = 0;
3279 /* Process two side if needed */
3280 if (shader
->two_side
&& ctx
.colors_used
) {
3281 int i
, count
= ctx
.shader
->ninput
;
3282 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3284 /* additional inputs will be allocated right after the existing inputs,
3285 * we won't need them after the color selection, so we don't need to
3286 * reserve these gprs for the rest of the shader code and to adjust
3287 * output offsets etc. */
3288 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3289 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3291 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3292 if (ctx
.face_gpr
== -1) {
3293 i
= ctx
.shader
->ninput
++;
3294 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3295 ctx
.shader
->input
[i
].spi_sid
= 0;
3296 ctx
.shader
->input
[i
].gpr
= gpr
++;
3297 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3300 for (i
= 0; i
< count
; i
++) {
3301 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3302 int ni
= ctx
.shader
->ninput
++;
3303 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3304 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3305 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3306 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3307 // TGSI to LLVM needs to know the lds position of inputs.
3308 // Non LLVM path computes it later (in process_twoside_color)
3309 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3310 ctx
.shader
->input
[i
].back_color_input
= ni
;
3311 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3312 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3319 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3320 shader
->nr_ps_max_color_exports
= 8;
3322 if (ctx
.fragcoord_input
>= 0) {
3323 if (ctx
.bc
->chip_class
== CAYMAN
) {
3324 for (j
= 0 ; j
< 4; j
++) {
3325 struct r600_bytecode_alu alu
;
3326 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3327 alu
.op
= ALU_OP1_RECIP_IEEE
;
3328 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3329 alu
.src
[0].chan
= 3;
3331 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3333 alu
.dst
.write
= (j
== 3);
3335 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3339 struct r600_bytecode_alu alu
;
3340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3341 alu
.op
= ALU_OP1_RECIP_IEEE
;
3342 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3343 alu
.src
[0].chan
= 3;
3345 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3349 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3354 if (ctx
.thread_id_gpr
) {
3355 load_thread_id_gpr(&ctx
);
3358 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3359 struct r600_bytecode_alu alu
;
3362 /* GS thread with no output workaround - emit a cut at start of GS */
3363 if (ctx
.bc
->chip_class
== R600
)
3364 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3366 for (j
= 0; j
< 4; j
++) {
3367 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3368 alu
.op
= ALU_OP1_MOV
;
3369 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3370 alu
.src
[0].value
= 0;
3371 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3374 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3379 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3380 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3381 ctx
.gs_rotated_input
[0], 2,
3383 V_SQ_ALU_SRC_LITERAL
, 1);
3387 for (i
= 0; i
< 6; i
++) {
3388 int rotated
= (i
+ 4) % 6;
3389 int offset_reg
= i
/ 3;
3390 int offset_chan
= i
% 3;
3391 int rotated_offset_reg
= rotated
/ 3;
3392 int rotated_offset_chan
= rotated
% 3;
3394 if (offset_reg
== 0 && offset_chan
== 2)
3396 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3397 rotated_offset_chan
= 3;
3399 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3400 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3401 ctx
.gs_rotated_input
[0], 2,
3402 offset_reg
, offset_chan
,
3403 rotated_offset_reg
, rotated_offset_chan
);
3410 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3411 r600_fetch_tess_io_info(&ctx
);
3413 if (shader
->two_side
&& ctx
.colors_used
) {
3414 if ((r
= process_twoside_color_inputs(&ctx
)))
3418 tgsi_parse_init(&ctx
.parse
, tokens
);
3419 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3420 tgsi_parse_token(&ctx
.parse
);
3421 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3422 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3423 r
= tgsi_is_supported(&ctx
);
3426 ctx
.max_driver_temp_used
= 0;
3427 /* reserve first tmp for everyone */
3428 r600_get_temp(&ctx
);
3430 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3431 if ((r
= tgsi_split_constant(&ctx
)))
3433 if ((r
= tgsi_split_literal_constant(&ctx
)))
3435 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3436 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3438 } else if (lds_inputs
) {
3439 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3442 if (ctx
.bc
->chip_class
== CAYMAN
)
3443 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3444 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3445 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3447 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3448 r
= ctx
.inst_info
->process(&ctx
);
3452 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3453 r
= r600_store_tcs_output(&ctx
);
3463 /* Reset the temporary register counter. */
3464 ctx
.max_driver_temp_used
= 0;
3466 noutput
= shader
->noutput
;
3468 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3469 unsigned clipdist_temp
[2];
3471 clipdist_temp
[0] = r600_get_temp(&ctx
);
3472 clipdist_temp
[1] = r600_get_temp(&ctx
);
3474 /* need to convert a clipvertex write into clipdistance writes and not export
3475 the clip vertex anymore */
3477 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3478 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3479 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3481 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3482 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3485 /* reset spi_sid for clipvertex output to avoid confusing spi */
3486 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3488 shader
->clip_dist_write
= 0xFF;
3490 for (i
= 0; i
< 8; i
++) {
3494 for (j
= 0; j
< 4; j
++) {
3495 struct r600_bytecode_alu alu
;
3496 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3497 alu
.op
= ALU_OP2_DOT4
;
3498 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3499 alu
.src
[0].chan
= j
;
3501 alu
.src
[1].sel
= 512 + i
;
3502 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3503 alu
.src
[1].chan
= j
;
3505 alu
.dst
.sel
= clipdist_temp
[oreg
];
3507 alu
.dst
.write
= (j
== ochan
);
3510 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3517 /* Add stream outputs. */
3518 if (so
.num_outputs
) {
3520 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3522 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3525 emit_streamout(&ctx
, &so
, -1, NULL
);
3527 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3528 convert_edgeflag_to_int(&ctx
);
3530 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3531 r600_emit_tess_factor(&ctx
);
3534 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3535 if (ctx
.shader
->noutput
)
3536 emit_lds_vs_writes(&ctx
);
3538 } else if (ring_outputs
) {
3539 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3540 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3541 ctx
.gs_export_gpr_tregs
[1] = -1;
3542 ctx
.gs_export_gpr_tregs
[2] = -1;
3543 ctx
.gs_export_gpr_tregs
[3] = -1;
3545 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3549 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3551 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3552 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3553 output
[j
].gpr
= shader
->output
[i
].gpr
;
3554 output
[j
].elem_size
= 3;
3555 output
[j
].swizzle_x
= 0;
3556 output
[j
].swizzle_y
= 1;
3557 output
[j
].swizzle_z
= 2;
3558 output
[j
].swizzle_w
= 3;
3559 output
[j
].burst_count
= 1;
3560 output
[j
].type
= -1;
3561 output
[j
].op
= CF_OP_EXPORT
;
3563 case PIPE_SHADER_VERTEX
:
3564 case PIPE_SHADER_TESS_EVAL
:
3565 switch (shader
->output
[i
].name
) {
3566 case TGSI_SEMANTIC_POSITION
:
3567 output
[j
].array_base
= 60;
3568 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3572 case TGSI_SEMANTIC_PSIZE
:
3573 output
[j
].array_base
= 61;
3574 output
[j
].swizzle_y
= 7;
3575 output
[j
].swizzle_z
= 7;
3576 output
[j
].swizzle_w
= 7;
3577 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3580 case TGSI_SEMANTIC_EDGEFLAG
:
3581 output
[j
].array_base
= 61;
3582 output
[j
].swizzle_x
= 7;
3583 output
[j
].swizzle_y
= 0;
3584 output
[j
].swizzle_z
= 7;
3585 output
[j
].swizzle_w
= 7;
3586 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3589 case TGSI_SEMANTIC_LAYER
:
3590 /* spi_sid is 0 for outputs that are
3591 * not consumed by PS */
3592 if (shader
->output
[i
].spi_sid
) {
3593 output
[j
].array_base
= next_param_base
++;
3594 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3596 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3598 output
[j
].array_base
= 61;
3599 output
[j
].swizzle_x
= 7;
3600 output
[j
].swizzle_y
= 7;
3601 output
[j
].swizzle_z
= 0;
3602 output
[j
].swizzle_w
= 7;
3603 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3606 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3607 /* spi_sid is 0 for outputs that are
3608 * not consumed by PS */
3609 if (shader
->output
[i
].spi_sid
) {
3610 output
[j
].array_base
= next_param_base
++;
3611 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3613 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3615 output
[j
].array_base
= 61;
3616 output
[j
].swizzle_x
= 7;
3617 output
[j
].swizzle_y
= 7;
3618 output
[j
].swizzle_z
= 7;
3619 output
[j
].swizzle_w
= 0;
3620 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3623 case TGSI_SEMANTIC_CLIPVERTEX
:
3626 case TGSI_SEMANTIC_CLIPDIST
:
3627 output
[j
].array_base
= next_clip_base
++;
3628 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3630 /* spi_sid is 0 for clipdistance outputs that were generated
3631 * for clipvertex - we don't need to pass them to PS */
3632 if (shader
->output
[i
].spi_sid
) {
3634 /* duplicate it as PARAM to pass to the pixel shader */
3635 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3636 output
[j
].array_base
= next_param_base
++;
3637 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3640 case TGSI_SEMANTIC_FOG
:
3641 output
[j
].swizzle_y
= 4; /* 0 */
3642 output
[j
].swizzle_z
= 4; /* 0 */
3643 output
[j
].swizzle_w
= 5; /* 1 */
3645 case TGSI_SEMANTIC_PRIMID
:
3646 output
[j
].swizzle_x
= 2;
3647 output
[j
].swizzle_y
= 4; /* 0 */
3648 output
[j
].swizzle_z
= 4; /* 0 */
3649 output
[j
].swizzle_w
= 4; /* 0 */
3654 case PIPE_SHADER_FRAGMENT
:
3655 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3656 /* never export more colors than the number of CBs */
3657 if (shader
->output
[i
].sid
>= max_color_exports
) {
3662 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3663 output
[j
].array_base
= shader
->output
[i
].sid
;
3664 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3665 shader
->nr_ps_color_exports
++;
3666 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3667 for (k
= 1; k
< max_color_exports
; k
++) {
3669 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3670 output
[j
].gpr
= shader
->output
[i
].gpr
;
3671 output
[j
].elem_size
= 3;
3672 output
[j
].swizzle_x
= 0;
3673 output
[j
].swizzle_y
= 1;
3674 output
[j
].swizzle_z
= 2;
3675 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3676 output
[j
].burst_count
= 1;
3677 output
[j
].array_base
= k
;
3678 output
[j
].op
= CF_OP_EXPORT
;
3679 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3680 shader
->nr_ps_color_exports
++;
3683 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3684 output
[j
].array_base
= 61;
3685 output
[j
].swizzle_x
= 2;
3686 output
[j
].swizzle_y
= 7;
3687 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3688 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3689 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3690 output
[j
].array_base
= 61;
3691 output
[j
].swizzle_x
= 7;
3692 output
[j
].swizzle_y
= 1;
3693 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3694 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3695 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3696 output
[j
].array_base
= 61;
3697 output
[j
].swizzle_x
= 7;
3698 output
[j
].swizzle_y
= 7;
3699 output
[j
].swizzle_z
= 0;
3700 output
[j
].swizzle_w
= 7;
3701 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3703 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3708 case PIPE_SHADER_TESS_CTRL
:
3711 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3716 if (output
[j
].type
==-1) {
3717 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3718 output
[j
].array_base
= next_param_base
++;
3722 /* add fake position export */
3723 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3724 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3726 output
[j
].elem_size
= 3;
3727 output
[j
].swizzle_x
= 7;
3728 output
[j
].swizzle_y
= 7;
3729 output
[j
].swizzle_z
= 7;
3730 output
[j
].swizzle_w
= 7;
3731 output
[j
].burst_count
= 1;
3732 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3733 output
[j
].array_base
= 60;
3734 output
[j
].op
= CF_OP_EXPORT
;
3738 /* add fake param output for vertex shader if no param is exported */
3739 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3740 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3742 output
[j
].elem_size
= 3;
3743 output
[j
].swizzle_x
= 7;
3744 output
[j
].swizzle_y
= 7;
3745 output
[j
].swizzle_z
= 7;
3746 output
[j
].swizzle_w
= 7;
3747 output
[j
].burst_count
= 1;
3748 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3749 output
[j
].array_base
= 0;
3750 output
[j
].op
= CF_OP_EXPORT
;
3754 /* add fake pixel export */
3755 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3756 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3758 output
[j
].elem_size
= 3;
3759 output
[j
].swizzle_x
= 7;
3760 output
[j
].swizzle_y
= 7;
3761 output
[j
].swizzle_z
= 7;
3762 output
[j
].swizzle_w
= 7;
3763 output
[j
].burst_count
= 1;
3764 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3765 output
[j
].array_base
= 0;
3766 output
[j
].op
= CF_OP_EXPORT
;
3768 shader
->nr_ps_color_exports
++;
3773 /* set export done on last export of each type */
3774 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
3775 if (!(output_done
& (1 << output
[i
].type
))) {
3776 output_done
|= (1 << output
[i
].type
);
3777 output
[i
].op
= CF_OP_EXPORT_DONE
;
3780 /* add output to bytecode */
3781 for (i
= 0; i
< noutput
; i
++) {
3782 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3788 /* add program end */
3789 if (ctx
.bc
->chip_class
== CAYMAN
)
3790 cm_bytecode_add_cf_end(ctx
.bc
);
3792 const struct cf_op_info
*last
= NULL
;
3794 if (ctx
.bc
->cf_last
)
3795 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3797 /* alu clause instructions don't have EOP bit, so add NOP */
3798 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
)
3799 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3801 ctx
.bc
->cf_last
->end_of_program
= 1;
3804 /* check GPR limit - we have 124 = 128 - 4
3805 * (4 are reserved as alu clause temporary registers) */
3806 if (ctx
.bc
->ngpr
> 124) {
3807 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3812 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3813 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3818 tgsi_parse_free(&ctx
.parse
);
3822 tgsi_parse_free(&ctx
.parse
);
3826 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3828 const unsigned tgsi_opcode
=
3829 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3830 R600_ERR("%s tgsi opcode unsupported\n",
3831 tgsi_get_opcode_name(tgsi_opcode
));
3835 static int tgsi_end(struct r600_shader_ctx
*ctx
)
3840 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3841 const struct r600_shader_src
*shader_src
,
3844 bc_src
->sel
= shader_src
->sel
;
3845 bc_src
->chan
= shader_src
->swizzle
[chan
];
3846 bc_src
->neg
= shader_src
->neg
;
3847 bc_src
->abs
= shader_src
->abs
;
3848 bc_src
->rel
= shader_src
->rel
;
3849 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3850 bc_src
->kc_bank
= shader_src
->kc_bank
;
3851 bc_src
->kc_rel
= shader_src
->kc_rel
;
3854 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3860 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3862 bc_src
->neg
= !bc_src
->neg
;
3865 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3866 const struct tgsi_full_dst_register
*tgsi_dst
,
3868 struct r600_bytecode_alu_dst
*r600_dst
)
3870 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3872 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
3873 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
3874 r600_dst
->chan
= swizzle
;
3875 r600_dst
->write
= 1;
3876 if (inst
->Instruction
.Saturate
) {
3877 r600_dst
->clamp
= 1;
3879 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
3880 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
3884 if (tgsi_dst
->Register
.Indirect
)
3885 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
3889 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
)
3891 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3892 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3893 struct r600_bytecode_alu alu
;
3894 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3898 switch (write_mask
) {
3916 lasti
= tgsi_last_instruction(write_mask
);
3917 for (i
= 0; i
<= lasti
; i
++) {
3919 if (!(write_mask
& (1 << i
)))
3922 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3925 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3927 alu
.dst
.sel
= ctx
->temp_reg
;
3931 if (i
== 1 || i
== 3)
3934 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3936 alu
.op
= ctx
->inst_info
->op
;
3937 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
3938 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3940 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3941 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
3944 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
3945 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
3948 /* handle some special cases */
3949 if (i
== 1 || i
== 3) {
3950 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
3951 case TGSI_OPCODE_DABS
:
3952 r600_bytecode_src_set_abs(&alu
.src
[0]);
3961 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3967 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3969 /* move result from temp to dst */
3970 for (i
= 0; i
<= lasti
; i
++) {
3971 if (!(write_mask
& (1 << i
)))
3974 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3975 alu
.op
= ALU_OP1_MOV
;
3976 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3977 alu
.src
[0].sel
= ctx
->temp_reg
;
3978 alu
.src
[0].chan
= use_tmp
- 1;
3979 alu
.last
= (i
== lasti
);
3981 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3989 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
3991 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3992 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3993 /* confirm writemasking */
3994 if ((write_mask
& 0x3) != 0x3 &&
3995 (write_mask
& 0xc) != 0xc) {
3996 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
3999 return tgsi_op2_64_params(ctx
, false, false);
4002 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4004 return tgsi_op2_64_params(ctx
, true, false);
4007 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4009 return tgsi_op2_64_params(ctx
, true, true);
4012 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4014 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4015 struct r600_bytecode_alu alu
;
4018 int tmp
= r600_get_temp(ctx
);
4020 for (i
= 0; i
< lasti
+ 1; i
++) {
4022 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4023 alu
.op
= ctx
->inst_info
->op
;
4024 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4025 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4028 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4029 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4045 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4047 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4048 struct r600_bytecode_alu alu
;
4049 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4050 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4051 /* use temp register if trans_only and more than one dst component */
4052 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4053 unsigned op
= ctx
->inst_info
->op
;
4055 if (op
== ALU_OP2_MUL_IEEE
&&
4056 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4059 for (i
= 0; i
<= lasti
; i
++) {
4060 if (!(write_mask
& (1 << i
)))
4063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4065 alu
.dst
.sel
= ctx
->temp_reg
;
4069 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4073 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4074 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4077 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4078 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4080 if (i
== lasti
|| trans_only
) {
4083 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4089 /* move result from temp to dst */
4090 for (i
= 0; i
<= lasti
; i
++) {
4091 if (!(write_mask
& (1 << i
)))
4094 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4095 alu
.op
= ALU_OP1_MOV
;
4096 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4097 alu
.src
[0].sel
= ctx
->temp_reg
;
4098 alu
.src
[0].chan
= i
;
4099 alu
.last
= (i
== lasti
);
4101 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4109 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4111 return tgsi_op2_s(ctx
, 0, 0);
4114 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4116 return tgsi_op2_s(ctx
, 1, 0);
4119 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4121 return tgsi_op2_s(ctx
, 0, 1);
4124 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4126 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4127 struct r600_bytecode_alu alu
;
4129 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4131 for (i
= 0; i
< lasti
+ 1; i
++) {
4133 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4135 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4136 alu
.op
= ctx
->inst_info
->op
;
4138 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4140 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4142 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4147 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4155 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4157 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4158 struct r600_bytecode_alu alu
;
4160 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4162 for (i
= 0; i
< lasti
+ 1; i
++) {
4164 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4167 alu
.op
= ALU_OP1_MOV
;
4169 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4171 if (i
== 1 || i
== 3)
4172 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4173 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4178 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4186 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4188 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4189 struct r600_bytecode_alu alu
;
4190 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4193 for (i
= 0; i
<= 3; i
++) {
4194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4195 alu
.op
= ctx
->inst_info
->op
;
4197 alu
.dst
.sel
= ctx
->temp_reg
;
4200 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4201 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4207 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4212 /* Replicate significand result across channels. */
4213 for (i
= 0; i
<= 3; i
++) {
4214 if (!(write_mask
& (1 << i
)))
4217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4218 alu
.op
= ALU_OP1_MOV
;
4219 alu
.src
[0].chan
= (i
& 1) + 2;
4220 alu
.src
[0].sel
= ctx
->temp_reg
;
4222 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4230 for (i
= 0; i
<= 3; i
++) {
4231 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4232 /* MOV third channels to writemask dst1 */
4233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4234 alu
.op
= ALU_OP1_MOV
;
4235 alu
.src
[0].chan
= 1;
4236 alu
.src
[0].sel
= ctx
->temp_reg
;
4238 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4240 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4250 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4252 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4253 struct r600_bytecode_alu alu
;
4255 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4257 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4258 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4260 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4261 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4262 alu
.op
= ctx
->inst_info
->op
;
4264 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4265 alu
.dst
.sel
= ctx
->temp_reg
;
4270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4275 for (i
= 0; i
<= lasti
; i
++) {
4276 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4277 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4279 alu
.src
[0].chan
= i
/2;
4281 alu
.src
[0].sel
= ctx
->temp_reg
;
4283 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4284 alu
.src
[0].value
= 0x0;
4286 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4287 alu
.last
= i
== lasti
;
4289 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4297 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4299 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4300 struct r600_bytecode_alu alu
;
4302 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4304 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4305 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4307 for (i
= 0; i
<= lasti
; i
++) {
4308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4309 alu
.op
= ALU_OP1_FLT64_TO_FLT32
;
4311 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], fp64_switch(i
));
4313 alu
.dst
.sel
= ctx
->temp_reg
;
4314 alu
.dst
.write
= i
%2 == 0;
4315 alu
.last
= i
== lasti
;
4317 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4322 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4323 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4324 alu
.op
= ctx
->inst_info
->op
;
4326 alu
.src
[0].chan
= i
*2;
4327 alu
.src
[0].sel
= ctx
->temp_reg
;
4328 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4331 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4339 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4342 struct r600_shader_src
*src
,
4345 struct r600_bytecode_alu alu
;
4346 const int last_slot
= 3;
4349 /* these have to write the result to X/Y by the looks of it */
4350 for (int i
= 0 ; i
< last_slot
; i
++) {
4351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4354 r600_bytecode_src(&alu
.src
[0], src
, 1);
4355 r600_bytecode_src(&alu
.src
[1], src
, 0);
4358 r600_bytecode_src_set_abs(&alu
.src
[1]);
4360 alu
.dst
.sel
= dst_reg
;
4362 alu
.dst
.write
= (i
== 0 || i
== 1);
4364 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4366 r
= r600_bytecode_add_alu(bc
, &alu
);
4374 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4376 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4378 struct r600_bytecode_alu alu
;
4379 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4380 int t1
= ctx
->temp_reg
;
4382 /* should only be one src regs */
4383 assert(inst
->Instruction
.NumSrcRegs
== 1);
4385 /* only support one double at a time */
4386 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4387 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4389 r
= cayman_emit_unary_double_raw(
4390 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4392 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4393 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4397 for (i
= 0 ; i
<= lasti
; i
++) {
4398 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4400 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4401 alu
.op
= ALU_OP1_MOV
;
4402 alu
.src
[0].sel
= t1
;
4403 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4404 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4408 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4415 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4417 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4419 struct r600_bytecode_alu alu
;
4420 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4422 for (i
= 0 ; i
< last_slot
; i
++) {
4423 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4424 alu
.op
= ctx
->inst_info
->op
;
4425 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4426 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4428 /* RSQ should take the absolute value of src */
4429 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4430 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4433 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4434 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4436 if (i
== last_slot
- 1)
4438 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4445 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4447 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4449 struct r600_bytecode_alu alu
;
4450 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4451 int t1
= ctx
->temp_reg
;
4453 for (k
= 0; k
<= lasti
; k
++) {
4454 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4457 for (i
= 0 ; i
< 4; i
++) {
4458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4459 alu
.op
= ctx
->inst_info
->op
;
4460 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4461 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4465 alu
.dst
.write
= (i
== k
);
4468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4474 for (i
= 0 ; i
<= lasti
; i
++) {
4475 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4477 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4478 alu
.op
= ALU_OP1_MOV
;
4479 alu
.src
[0].sel
= t1
;
4480 alu
.src
[0].chan
= i
;
4481 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4485 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4494 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4496 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4498 struct r600_bytecode_alu alu
;
4499 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4500 int t1
= ctx
->temp_reg
;
4502 /* t1 would get overwritten below if we actually tried to
4503 * multiply two pairs of doubles at a time. */
4504 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4505 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4507 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4509 for (i
= 0; i
< 4; i
++) {
4510 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4511 alu
.op
= ctx
->inst_info
->op
;
4512 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4513 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4520 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4525 for (i
= 0; i
<= lasti
; i
++) {
4526 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4529 alu
.op
= ALU_OP1_MOV
;
4530 alu
.src
[0].sel
= t1
;
4531 alu
.src
[0].chan
= i
;
4532 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4536 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4545 * Emit RECIP_64 + MUL_64 to implement division.
4547 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4549 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4551 struct r600_bytecode_alu alu
;
4552 int t1
= ctx
->temp_reg
;
4555 /* Only support one double at a time. This is the same constraint as
4556 * in DMUL lowering. */
4557 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4558 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4560 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4562 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4566 for (int i
= 0; i
< 4; i
++) {
4567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4568 alu
.op
= ALU_OP2_MUL_64
;
4570 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4572 alu
.src
[1].sel
= t1
;
4573 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4580 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4585 for (int i
= 0; i
< 2; i
++) {
4586 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4587 alu
.op
= ALU_OP1_MOV
;
4588 alu
.src
[0].sel
= t1
;
4589 alu
.src
[0].chan
= i
;
4590 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4594 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4602 * r600 - trunc to -PI..PI range
4603 * r700 - normalize by dividing by 2PI
4606 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4609 struct r600_bytecode_alu alu
;
4611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4612 alu
.op
= ALU_OP3_MULADD
;
4616 alu
.dst
.sel
= ctx
->temp_reg
;
4619 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4621 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4622 alu
.src
[1].chan
= 0;
4623 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4624 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4625 alu
.src
[2].chan
= 0;
4627 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4632 alu
.op
= ALU_OP1_FRACT
;
4635 alu
.dst
.sel
= ctx
->temp_reg
;
4638 alu
.src
[0].sel
= ctx
->temp_reg
;
4639 alu
.src
[0].chan
= 0;
4641 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4645 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4646 alu
.op
= ALU_OP3_MULADD
;
4650 alu
.dst
.sel
= ctx
->temp_reg
;
4653 alu
.src
[0].sel
= ctx
->temp_reg
;
4654 alu
.src
[0].chan
= 0;
4656 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4657 alu
.src
[1].chan
= 0;
4658 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4659 alu
.src
[2].chan
= 0;
4661 if (ctx
->bc
->chip_class
== R600
) {
4662 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4663 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4665 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4666 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4671 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4677 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4679 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4680 struct r600_bytecode_alu alu
;
4681 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4684 r
= tgsi_setup_trig(ctx
);
4689 for (i
= 0; i
< last_slot
; i
++) {
4690 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4691 alu
.op
= ctx
->inst_info
->op
;
4694 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4695 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4697 alu
.src
[0].sel
= ctx
->temp_reg
;
4698 alu
.src
[0].chan
= 0;
4699 if (i
== last_slot
- 1)
4701 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4708 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4710 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4711 struct r600_bytecode_alu alu
;
4713 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4715 r
= tgsi_setup_trig(ctx
);
4719 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4720 alu
.op
= ctx
->inst_info
->op
;
4722 alu
.dst
.sel
= ctx
->temp_reg
;
4725 alu
.src
[0].sel
= ctx
->temp_reg
;
4726 alu
.src
[0].chan
= 0;
4728 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4732 /* replicate result */
4733 for (i
= 0; i
< lasti
+ 1; i
++) {
4734 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4738 alu
.op
= ALU_OP1_MOV
;
4740 alu
.src
[0].sel
= ctx
->temp_reg
;
4741 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4744 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4751 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4753 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4754 struct r600_bytecode_alu alu
;
4757 for (i
= 0; i
< 4; i
++) {
4758 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4759 alu
.op
= ctx
->inst_info
->op
;
4763 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4765 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4766 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4769 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4774 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4779 /* kill must be last in ALU */
4780 ctx
->bc
->force_add_cf
= 1;
4781 ctx
->shader
->uses_kill
= TRUE
;
4785 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4787 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4788 struct r600_bytecode_alu alu
;
4791 /* tmp.x = max(src.y, 0.0) */
4792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4793 alu
.op
= ALU_OP2_MAX
;
4794 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4795 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4796 alu
.src
[1].chan
= 1;
4798 alu
.dst
.sel
= ctx
->temp_reg
;
4803 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4807 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4813 if (ctx
->bc
->chip_class
== CAYMAN
) {
4814 for (i
= 0; i
< 3; i
++) {
4815 /* tmp.z = log(tmp.x) */
4816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4817 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4818 alu
.src
[0].sel
= ctx
->temp_reg
;
4819 alu
.src
[0].chan
= 0;
4820 alu
.dst
.sel
= ctx
->temp_reg
;
4828 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4833 /* tmp.z = log(tmp.x) */
4834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4835 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4836 alu
.src
[0].sel
= ctx
->temp_reg
;
4837 alu
.src
[0].chan
= 0;
4838 alu
.dst
.sel
= ctx
->temp_reg
;
4842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4847 chan
= alu
.dst
.chan
;
4850 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
4851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4852 alu
.op
= ALU_OP3_MUL_LIT
;
4853 alu
.src
[0].sel
= sel
;
4854 alu
.src
[0].chan
= chan
;
4855 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
4856 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
4857 alu
.dst
.sel
= ctx
->temp_reg
;
4862 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4866 if (ctx
->bc
->chip_class
== CAYMAN
) {
4867 for (i
= 0; i
< 3; i
++) {
4868 /* dst.z = exp(tmp.x) */
4869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4870 alu
.op
= ALU_OP1_EXP_IEEE
;
4871 alu
.src
[0].sel
= ctx
->temp_reg
;
4872 alu
.src
[0].chan
= 0;
4873 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4879 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4884 /* dst.z = exp(tmp.x) */
4885 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4886 alu
.op
= ALU_OP1_EXP_IEEE
;
4887 alu
.src
[0].sel
= ctx
->temp_reg
;
4888 alu
.src
[0].chan
= 0;
4889 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4891 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4898 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4899 alu
.op
= ALU_OP1_MOV
;
4900 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
4901 alu
.src
[0].chan
= 0;
4902 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4903 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
4904 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4908 /* dst.y = max(src.x, 0.0) */
4909 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4910 alu
.op
= ALU_OP2_MAX
;
4911 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4912 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4913 alu
.src
[1].chan
= 0;
4914 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
4915 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
4916 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4922 alu
.op
= ALU_OP1_MOV
;
4923 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4924 alu
.src
[0].chan
= 0;
4925 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
4926 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
4928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4935 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
4937 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4938 struct r600_bytecode_alu alu
;
4941 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4943 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
4945 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4946 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4947 r600_bytecode_src_set_abs(&alu
.src
[i
]);
4949 alu
.dst
.sel
= ctx
->temp_reg
;
4952 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4955 /* replicate result */
4956 return tgsi_helper_tempx_replicate(ctx
);
4959 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
4961 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4962 struct r600_bytecode_alu alu
;
4965 for (i
= 0; i
< 4; i
++) {
4966 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4967 alu
.src
[0].sel
= ctx
->temp_reg
;
4968 alu
.op
= ALU_OP1_MOV
;
4970 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4971 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4981 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
4983 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4984 struct r600_bytecode_alu alu
;
4987 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4988 alu
.op
= ctx
->inst_info
->op
;
4989 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4990 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4992 alu
.dst
.sel
= ctx
->temp_reg
;
4995 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4998 /* replicate result */
4999 return tgsi_helper_tempx_replicate(ctx
);
5002 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5004 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5006 struct r600_bytecode_alu alu
;
5007 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5009 for (i
= 0; i
< 3; i
++) {
5010 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5011 alu
.op
= ALU_OP1_LOG_IEEE
;
5012 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5013 alu
.dst
.sel
= ctx
->temp_reg
;
5018 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5025 alu
.op
= ALU_OP2_MUL
;
5026 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5027 alu
.src
[1].sel
= ctx
->temp_reg
;
5028 alu
.dst
.sel
= ctx
->temp_reg
;
5031 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5035 for (i
= 0; i
< last_slot
; i
++) {
5036 /* POW(a,b) = EXP2(b * LOG2(a))*/
5037 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5038 alu
.op
= ALU_OP1_EXP_IEEE
;
5039 alu
.src
[0].sel
= ctx
->temp_reg
;
5041 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5042 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5043 if (i
== last_slot
- 1)
5045 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5052 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5054 struct r600_bytecode_alu alu
;
5058 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5059 alu
.op
= ALU_OP1_LOG_IEEE
;
5060 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5061 alu
.dst
.sel
= ctx
->temp_reg
;
5064 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5068 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5069 alu
.op
= ALU_OP2_MUL
;
5070 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5071 alu
.src
[1].sel
= ctx
->temp_reg
;
5072 alu
.dst
.sel
= ctx
->temp_reg
;
5075 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5078 /* POW(a,b) = EXP2(b * LOG2(a))*/
5079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5080 alu
.op
= ALU_OP1_EXP_IEEE
;
5081 alu
.src
[0].sel
= ctx
->temp_reg
;
5082 alu
.dst
.sel
= ctx
->temp_reg
;
5085 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5088 return tgsi_helper_tempx_replicate(ctx
);
5091 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5093 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5094 struct r600_bytecode_alu alu
;
5096 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5097 int tmp0
= ctx
->temp_reg
;
5098 int tmp1
= r600_get_temp(ctx
);
5099 int tmp2
= r600_get_temp(ctx
);
5100 int tmp3
= r600_get_temp(ctx
);
5103 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5105 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5106 * 2. tmp0.z = lo (tmp0.x * src2)
5107 * 3. tmp0.w = -tmp0.z
5108 * 4. tmp0.y = hi (tmp0.x * src2)
5109 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5110 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5111 * 7. tmp1.x = tmp0.x - tmp0.w
5112 * 8. tmp1.y = tmp0.x + tmp0.w
5113 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5114 * 10. tmp0.z = hi(tmp0.x * src1) = q
5115 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5117 * 12. tmp0.w = src1 - tmp0.y = r
5118 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5119 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5123 * 15. tmp1.z = tmp0.z + 1 = q + 1
5124 * 16. tmp1.w = tmp0.z - 1 = q - 1
5128 * 15. tmp1.z = tmp0.w - src2 = r - src2
5129 * 16. tmp1.w = tmp0.w + src2 = r + src2
5133 * 17. tmp1.x = tmp1.x & tmp1.y
5135 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5136 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5138 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5139 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5143 * Same as unsigned, using abs values of the operands,
5144 * and fixing the sign of the result in the end.
5147 for (i
= 0; i
< 4; i
++) {
5148 if (!(write_mask
& (1<<i
)))
5153 /* tmp2.x = -src0 */
5154 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5155 alu
.op
= ALU_OP2_SUB_INT
;
5161 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5163 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5166 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5169 /* tmp2.y = -src1 */
5170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5171 alu
.op
= ALU_OP2_SUB_INT
;
5177 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5179 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5182 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5185 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5186 /* it will be a sign of the quotient */
5189 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5190 alu
.op
= ALU_OP2_XOR_INT
;
5196 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5197 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5200 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5204 /* tmp2.x = |src0| */
5205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5206 alu
.op
= ALU_OP3_CNDGE_INT
;
5213 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5214 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5215 alu
.src
[2].sel
= tmp2
;
5216 alu
.src
[2].chan
= 0;
5219 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5222 /* tmp2.y = |src1| */
5223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5224 alu
.op
= ALU_OP3_CNDGE_INT
;
5231 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5232 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5233 alu
.src
[2].sel
= tmp2
;
5234 alu
.src
[2].chan
= 1;
5237 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5242 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5243 if (ctx
->bc
->chip_class
== CAYMAN
) {
5244 /* tmp3.x = u2f(src2) */
5245 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5246 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5253 alu
.src
[0].sel
= tmp2
;
5254 alu
.src
[0].chan
= 1;
5256 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5260 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5263 /* tmp0.x = recip(tmp3.x) */
5264 for (j
= 0 ; j
< 3; j
++) {
5265 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5266 alu
.op
= ALU_OP1_RECIP_IEEE
;
5270 alu
.dst
.write
= (j
== 0);
5272 alu
.src
[0].sel
= tmp3
;
5273 alu
.src
[0].chan
= 0;
5277 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5281 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5282 alu
.op
= ALU_OP2_MUL
;
5284 alu
.src
[0].sel
= tmp0
;
5285 alu
.src
[0].chan
= 0;
5287 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5288 alu
.src
[1].value
= 0x4f800000;
5293 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5298 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5304 alu
.src
[0].sel
= tmp3
;
5305 alu
.src
[0].chan
= 0;
5308 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5313 alu
.op
= ALU_OP1_RECIP_UINT
;
5320 alu
.src
[0].sel
= tmp2
;
5321 alu
.src
[0].chan
= 1;
5323 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5327 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5331 /* 2. tmp0.z = lo (tmp0.x * src2) */
5332 if (ctx
->bc
->chip_class
== CAYMAN
) {
5333 for (j
= 0 ; j
< 4; j
++) {
5334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5335 alu
.op
= ALU_OP2_MULLO_UINT
;
5339 alu
.dst
.write
= (j
== 2);
5341 alu
.src
[0].sel
= tmp0
;
5342 alu
.src
[0].chan
= 0;
5344 alu
.src
[1].sel
= tmp2
;
5345 alu
.src
[1].chan
= 1;
5347 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5350 alu
.last
= (j
== 3);
5351 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5356 alu
.op
= ALU_OP2_MULLO_UINT
;
5362 alu
.src
[0].sel
= tmp0
;
5363 alu
.src
[0].chan
= 0;
5365 alu
.src
[1].sel
= tmp2
;
5366 alu
.src
[1].chan
= 1;
5368 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5372 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5376 /* 3. tmp0.w = -tmp0.z */
5377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5378 alu
.op
= ALU_OP2_SUB_INT
;
5384 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5385 alu
.src
[1].sel
= tmp0
;
5386 alu
.src
[1].chan
= 2;
5389 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5392 /* 4. tmp0.y = hi (tmp0.x * src2) */
5393 if (ctx
->bc
->chip_class
== CAYMAN
) {
5394 for (j
= 0 ; j
< 4; j
++) {
5395 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5396 alu
.op
= ALU_OP2_MULHI_UINT
;
5400 alu
.dst
.write
= (j
== 1);
5402 alu
.src
[0].sel
= tmp0
;
5403 alu
.src
[0].chan
= 0;
5406 alu
.src
[1].sel
= tmp2
;
5407 alu
.src
[1].chan
= 1;
5409 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5411 alu
.last
= (j
== 3);
5412 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5417 alu
.op
= ALU_OP2_MULHI_UINT
;
5423 alu
.src
[0].sel
= tmp0
;
5424 alu
.src
[0].chan
= 0;
5427 alu
.src
[1].sel
= tmp2
;
5428 alu
.src
[1].chan
= 1;
5430 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5434 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5438 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5439 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5440 alu
.op
= ALU_OP3_CNDE_INT
;
5447 alu
.src
[0].sel
= tmp0
;
5448 alu
.src
[0].chan
= 1;
5449 alu
.src
[1].sel
= tmp0
;
5450 alu
.src
[1].chan
= 3;
5451 alu
.src
[2].sel
= tmp0
;
5452 alu
.src
[2].chan
= 2;
5455 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5458 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5459 if (ctx
->bc
->chip_class
== CAYMAN
) {
5460 for (j
= 0 ; j
< 4; j
++) {
5461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5462 alu
.op
= ALU_OP2_MULHI_UINT
;
5466 alu
.dst
.write
= (j
== 3);
5468 alu
.src
[0].sel
= tmp0
;
5469 alu
.src
[0].chan
= 2;
5471 alu
.src
[1].sel
= tmp0
;
5472 alu
.src
[1].chan
= 0;
5474 alu
.last
= (j
== 3);
5475 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5479 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5480 alu
.op
= ALU_OP2_MULHI_UINT
;
5486 alu
.src
[0].sel
= tmp0
;
5487 alu
.src
[0].chan
= 2;
5489 alu
.src
[1].sel
= tmp0
;
5490 alu
.src
[1].chan
= 0;
5493 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5497 /* 7. tmp1.x = tmp0.x - tmp0.w */
5498 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5499 alu
.op
= ALU_OP2_SUB_INT
;
5505 alu
.src
[0].sel
= tmp0
;
5506 alu
.src
[0].chan
= 0;
5507 alu
.src
[1].sel
= tmp0
;
5508 alu
.src
[1].chan
= 3;
5511 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5514 /* 8. tmp1.y = tmp0.x + tmp0.w */
5515 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5516 alu
.op
= ALU_OP2_ADD_INT
;
5522 alu
.src
[0].sel
= tmp0
;
5523 alu
.src
[0].chan
= 0;
5524 alu
.src
[1].sel
= tmp0
;
5525 alu
.src
[1].chan
= 3;
5528 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5531 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5533 alu
.op
= ALU_OP3_CNDE_INT
;
5540 alu
.src
[0].sel
= tmp0
;
5541 alu
.src
[0].chan
= 1;
5542 alu
.src
[1].sel
= tmp1
;
5543 alu
.src
[1].chan
= 1;
5544 alu
.src
[2].sel
= tmp1
;
5545 alu
.src
[2].chan
= 0;
5548 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5551 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5552 if (ctx
->bc
->chip_class
== CAYMAN
) {
5553 for (j
= 0 ; j
< 4; j
++) {
5554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5555 alu
.op
= ALU_OP2_MULHI_UINT
;
5559 alu
.dst
.write
= (j
== 2);
5561 alu
.src
[0].sel
= tmp0
;
5562 alu
.src
[0].chan
= 0;
5565 alu
.src
[1].sel
= tmp2
;
5566 alu
.src
[1].chan
= 0;
5568 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5571 alu
.last
= (j
== 3);
5572 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5576 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5577 alu
.op
= ALU_OP2_MULHI_UINT
;
5583 alu
.src
[0].sel
= tmp0
;
5584 alu
.src
[0].chan
= 0;
5587 alu
.src
[1].sel
= tmp2
;
5588 alu
.src
[1].chan
= 0;
5590 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5594 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5598 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5599 if (ctx
->bc
->chip_class
== CAYMAN
) {
5600 for (j
= 0 ; j
< 4; j
++) {
5601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5602 alu
.op
= ALU_OP2_MULLO_UINT
;
5606 alu
.dst
.write
= (j
== 1);
5609 alu
.src
[0].sel
= tmp2
;
5610 alu
.src
[0].chan
= 1;
5612 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5615 alu
.src
[1].sel
= tmp0
;
5616 alu
.src
[1].chan
= 2;
5618 alu
.last
= (j
== 3);
5619 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5623 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5624 alu
.op
= ALU_OP2_MULLO_UINT
;
5631 alu
.src
[0].sel
= tmp2
;
5632 alu
.src
[0].chan
= 1;
5634 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5637 alu
.src
[1].sel
= tmp0
;
5638 alu
.src
[1].chan
= 2;
5641 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5645 /* 12. tmp0.w = src1 - tmp0.y = r */
5646 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5647 alu
.op
= ALU_OP2_SUB_INT
;
5654 alu
.src
[0].sel
= tmp2
;
5655 alu
.src
[0].chan
= 0;
5657 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5660 alu
.src
[1].sel
= tmp0
;
5661 alu
.src
[1].chan
= 1;
5664 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5667 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5668 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5669 alu
.op
= ALU_OP2_SETGE_UINT
;
5675 alu
.src
[0].sel
= tmp0
;
5676 alu
.src
[0].chan
= 3;
5678 alu
.src
[1].sel
= tmp2
;
5679 alu
.src
[1].chan
= 1;
5681 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5685 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5688 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5689 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5690 alu
.op
= ALU_OP2_SETGE_UINT
;
5697 alu
.src
[0].sel
= tmp2
;
5698 alu
.src
[0].chan
= 0;
5700 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5703 alu
.src
[1].sel
= tmp0
;
5704 alu
.src
[1].chan
= 1;
5707 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5710 if (mod
) { /* UMOD */
5712 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5714 alu
.op
= ALU_OP2_SUB_INT
;
5720 alu
.src
[0].sel
= tmp0
;
5721 alu
.src
[0].chan
= 3;
5724 alu
.src
[1].sel
= tmp2
;
5725 alu
.src
[1].chan
= 1;
5727 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5731 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5734 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5735 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5736 alu
.op
= ALU_OP2_ADD_INT
;
5742 alu
.src
[0].sel
= tmp0
;
5743 alu
.src
[0].chan
= 3;
5745 alu
.src
[1].sel
= tmp2
;
5746 alu
.src
[1].chan
= 1;
5748 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5752 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5757 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5758 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5759 alu
.op
= ALU_OP2_ADD_INT
;
5765 alu
.src
[0].sel
= tmp0
;
5766 alu
.src
[0].chan
= 2;
5767 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5770 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5773 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5775 alu
.op
= ALU_OP2_ADD_INT
;
5781 alu
.src
[0].sel
= tmp0
;
5782 alu
.src
[0].chan
= 2;
5783 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5786 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5791 /* 17. tmp1.x = tmp1.x & tmp1.y */
5792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5793 alu
.op
= ALU_OP2_AND_INT
;
5799 alu
.src
[0].sel
= tmp1
;
5800 alu
.src
[0].chan
= 0;
5801 alu
.src
[1].sel
= tmp1
;
5802 alu
.src
[1].chan
= 1;
5805 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5808 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5809 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5810 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5811 alu
.op
= ALU_OP3_CNDE_INT
;
5818 alu
.src
[0].sel
= tmp1
;
5819 alu
.src
[0].chan
= 0;
5820 alu
.src
[1].sel
= tmp0
;
5821 alu
.src
[1].chan
= mod
? 3 : 2;
5822 alu
.src
[2].sel
= tmp1
;
5823 alu
.src
[2].chan
= 2;
5826 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5829 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5830 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5831 alu
.op
= ALU_OP3_CNDE_INT
;
5839 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5842 alu
.src
[0].sel
= tmp1
;
5843 alu
.src
[0].chan
= 1;
5844 alu
.src
[1].sel
= tmp1
;
5845 alu
.src
[1].chan
= 3;
5846 alu
.src
[2].sel
= tmp0
;
5847 alu
.src
[2].chan
= 2;
5850 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5855 /* fix the sign of the result */
5859 /* tmp0.x = -tmp0.z */
5860 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5861 alu
.op
= ALU_OP2_SUB_INT
;
5867 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5868 alu
.src
[1].sel
= tmp0
;
5869 alu
.src
[1].chan
= 2;
5872 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5875 /* sign of the remainder is the same as the sign of src0 */
5876 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
5877 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5878 alu
.op
= ALU_OP3_CNDGE_INT
;
5881 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5883 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5884 alu
.src
[1].sel
= tmp0
;
5885 alu
.src
[1].chan
= 2;
5886 alu
.src
[2].sel
= tmp0
;
5887 alu
.src
[2].chan
= 0;
5890 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5895 /* tmp0.x = -tmp0.z */
5896 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5897 alu
.op
= ALU_OP2_SUB_INT
;
5903 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5904 alu
.src
[1].sel
= tmp0
;
5905 alu
.src
[1].chan
= 2;
5908 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5911 /* fix the quotient sign (same as the sign of src0*src1) */
5912 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
5913 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5914 alu
.op
= ALU_OP3_CNDGE_INT
;
5917 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5919 alu
.src
[0].sel
= tmp2
;
5920 alu
.src
[0].chan
= 2;
5921 alu
.src
[1].sel
= tmp0
;
5922 alu
.src
[1].chan
= 2;
5923 alu
.src
[2].sel
= tmp0
;
5924 alu
.src
[2].chan
= 0;
5927 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5935 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
5937 return tgsi_divmod(ctx
, 0, 0);
5940 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
5942 return tgsi_divmod(ctx
, 1, 0);
5945 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
5947 return tgsi_divmod(ctx
, 0, 1);
5950 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
5952 return tgsi_divmod(ctx
, 1, 1);
5956 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
5958 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5959 struct r600_bytecode_alu alu
;
5961 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5962 int last_inst
= tgsi_last_instruction(write_mask
);
5964 for (i
= 0; i
< 4; i
++) {
5965 if (!(write_mask
& (1<<i
)))
5968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5969 alu
.op
= ALU_OP1_TRUNC
;
5971 alu
.dst
.sel
= ctx
->temp_reg
;
5975 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5978 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5983 for (i
= 0; i
< 4; i
++) {
5984 if (!(write_mask
& (1<<i
)))
5987 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5988 alu
.op
= ctx
->inst_info
->op
;
5990 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5992 alu
.src
[0].sel
= ctx
->temp_reg
;
5993 alu
.src
[0].chan
= i
;
5995 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
5997 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6005 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6007 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6008 struct r600_bytecode_alu alu
;
6010 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6011 int last_inst
= tgsi_last_instruction(write_mask
);
6014 for (i
= 0; i
< 4; i
++) {
6015 if (!(write_mask
& (1<<i
)))
6018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6019 alu
.op
= ALU_OP2_SUB_INT
;
6021 alu
.dst
.sel
= ctx
->temp_reg
;
6025 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6026 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6030 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6035 /* dst = (src >= 0 ? src : tmp) */
6036 for (i
= 0; i
< 4; i
++) {
6037 if (!(write_mask
& (1<<i
)))
6040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6041 alu
.op
= ALU_OP3_CNDGE_INT
;
6045 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6047 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6048 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6049 alu
.src
[2].sel
= ctx
->temp_reg
;
6050 alu
.src
[2].chan
= i
;
6054 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6061 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6063 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6064 struct r600_bytecode_alu alu
;
6066 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6067 int last_inst
= tgsi_last_instruction(write_mask
);
6069 /* tmp = (src >= 0 ? src : -1) */
6070 for (i
= 0; i
< 4; i
++) {
6071 if (!(write_mask
& (1<<i
)))
6074 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6075 alu
.op
= ALU_OP3_CNDGE_INT
;
6078 alu
.dst
.sel
= ctx
->temp_reg
;
6082 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6083 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6084 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6088 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6093 /* dst = (tmp > 0 ? 1 : tmp) */
6094 for (i
= 0; i
< 4; i
++) {
6095 if (!(write_mask
& (1<<i
)))
6098 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6099 alu
.op
= ALU_OP3_CNDGT_INT
;
6103 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6105 alu
.src
[0].sel
= ctx
->temp_reg
;
6106 alu
.src
[0].chan
= i
;
6108 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6110 alu
.src
[2].sel
= ctx
->temp_reg
;
6111 alu
.src
[2].chan
= i
;
6115 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6124 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6126 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6127 struct r600_bytecode_alu alu
;
6130 /* tmp = (src > 0 ? 1 : src) */
6131 for (i
= 0; i
< 4; i
++) {
6132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6133 alu
.op
= ALU_OP3_CNDGT
;
6136 alu
.dst
.sel
= ctx
->temp_reg
;
6139 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6140 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6141 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6145 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6150 /* dst = (-tmp > 0 ? -1 : tmp) */
6151 for (i
= 0; i
< 4; i
++) {
6152 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6153 alu
.op
= ALU_OP3_CNDGT
;
6155 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6157 alu
.src
[0].sel
= ctx
->temp_reg
;
6158 alu
.src
[0].chan
= i
;
6161 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6164 alu
.src
[2].sel
= ctx
->temp_reg
;
6165 alu
.src
[2].chan
= i
;
6169 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6176 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6178 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6179 struct r600_bytecode_alu alu
;
6182 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6183 int last_inst
= tgsi_last_instruction(write_mask
);
6185 t1
= r600_get_temp(ctx
);
6187 for (i
= 0; i
< 4; i
++) {
6188 if (!(write_mask
& (1<<i
)))
6191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6192 alu
.op
= ALU_OP2_SETGE_INT
;
6193 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6194 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6195 alu
.src
[1].value
= 32;
6196 alu
.dst
.sel
= ctx
->temp_reg
;
6199 alu
.last
= i
== last_inst
;
6200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6205 for (i
= 0; i
< 4; i
++) {
6206 if (!(write_mask
& (1<<i
)))
6209 /* create mask tmp */
6210 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6211 alu
.op
= ALU_OP2_BFM_INT
;
6215 alu
.last
= i
== last_inst
;
6217 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6218 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6220 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6225 t2
= r600_get_temp(ctx
);
6227 for (i
= 0; i
< 4; i
++) {
6228 if (!(write_mask
& (1<<i
)))
6231 /* shift insert left */
6232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6233 alu
.op
= ALU_OP2_LSHL_INT
;
6237 alu
.last
= i
== last_inst
;
6239 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6240 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6242 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6247 for (i
= 0; i
< 4; i
++) {
6248 if (!(write_mask
& (1<<i
)))
6251 /* actual bitfield insert */
6252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6253 alu
.op
= ALU_OP3_BFI_INT
;
6255 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6258 alu
.last
= i
== last_inst
;
6260 alu
.src
[0].sel
= t1
;
6261 alu
.src
[0].chan
= i
;
6262 alu
.src
[1].sel
= t2
;
6263 alu
.src
[1].chan
= i
;
6264 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6271 for (i
= 0; i
< 4; i
++) {
6272 if (!(write_mask
& (1<<i
)))
6274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6275 alu
.op
= ALU_OP3_CNDE_INT
;
6277 alu
.src
[0].sel
= ctx
->temp_reg
;
6278 alu
.src
[0].chan
= i
;
6279 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6281 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6283 alu
.src
[1].sel
= alu
.dst
.sel
;
6284 alu
.src
[1].chan
= i
;
6286 alu
.last
= i
== last_inst
;
6287 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6294 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6296 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6297 struct r600_bytecode_alu alu
;
6300 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6301 int last_inst
= tgsi_last_instruction(write_mask
);
6303 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6304 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6308 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6309 for (i
= 0; i
< 4; i
++) {
6310 if (!(write_mask
& (1<<i
)))
6313 /* t1 = FFBH_INT / FFBH_UINT */
6314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6315 alu
.op
= ctx
->inst_info
->op
;
6319 alu
.last
= i
== last_inst
;
6321 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6328 t2
= r600_get_temp(ctx
);
6330 for (i
= 0; i
< 4; i
++) {
6331 if (!(write_mask
& (1<<i
)))
6335 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6336 alu
.op
= ALU_OP2_SUB_INT
;
6340 alu
.last
= i
== last_inst
;
6342 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6343 alu
.src
[0].value
= 31;
6344 alu
.src
[1].sel
= t1
;
6345 alu
.src
[1].chan
= i
;
6347 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6352 for (i
= 0; i
< 4; i
++) {
6353 if (!(write_mask
& (1<<i
)))
6356 /* result = t1 >= 0 ? t2 : t1 */
6357 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6358 alu
.op
= ALU_OP3_CNDGE_INT
;
6360 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6363 alu
.last
= i
== last_inst
;
6365 alu
.src
[0].sel
= t1
;
6366 alu
.src
[0].chan
= i
;
6367 alu
.src
[1].sel
= t2
;
6368 alu
.src
[1].chan
= i
;
6369 alu
.src
[2].sel
= t1
;
6370 alu
.src
[2].chan
= i
;
6372 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6380 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6382 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6383 struct r600_bytecode_alu alu
;
6384 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6386 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6388 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6390 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6391 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6392 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6393 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6396 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6399 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6402 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6403 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6405 /* NOTE: currently offset is not perspective correct */
6406 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6407 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6408 int sample_gpr
= -1;
6409 int gradientsH
, gradientsV
;
6410 struct r600_bytecode_tex tex
;
6412 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6413 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6416 gradientsH
= r600_get_temp(ctx
);
6417 gradientsV
= r600_get_temp(ctx
);
6418 for (i
= 0; i
< 2; i
++) {
6419 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6420 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6421 tex
.src_gpr
= interp_gpr
;
6422 tex
.src_sel_x
= interp_base_chan
+ 0;
6423 tex
.src_sel_y
= interp_base_chan
+ 1;
6426 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6431 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6433 tex
.resource_id
= tex
.sampler_id
;
6434 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6439 for (i
= 0; i
< 2; i
++) {
6440 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6441 alu
.op
= ALU_OP3_MULADD
;
6443 alu
.src
[0].sel
= gradientsH
;
6444 alu
.src
[0].chan
= i
;
6445 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6446 alu
.src
[1].sel
= sample_gpr
;
6447 alu
.src
[1].chan
= 2;
6450 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6452 alu
.src
[2].sel
= interp_gpr
;
6453 alu
.src
[2].chan
= interp_base_chan
+ i
;
6454 alu
.dst
.sel
= ctx
->temp_reg
;
6458 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6463 for (i
= 0; i
< 2; i
++) {
6464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6465 alu
.op
= ALU_OP3_MULADD
;
6467 alu
.src
[0].sel
= gradientsV
;
6468 alu
.src
[0].chan
= i
;
6469 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6470 alu
.src
[1].sel
= sample_gpr
;
6471 alu
.src
[1].chan
= 3;
6474 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6476 alu
.src
[2].sel
= ctx
->temp_reg
;
6477 alu
.src
[2].chan
= i
;
6478 alu
.dst
.sel
= ctx
->temp_reg
;
6482 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6488 tmp
= r600_get_temp(ctx
);
6489 for (i
= 0; i
< 8; i
++) {
6490 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6491 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6494 if ((i
> 1 && i
< 6)) {
6500 alu
.dst
.chan
= i
% 4;
6502 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6503 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6504 alu
.src
[0].sel
= ctx
->temp_reg
;
6505 alu
.src
[0].chan
= 1 - (i
% 2);
6507 alu
.src
[0].sel
= interp_gpr
;
6508 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6510 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6511 alu
.src
[1].chan
= 0;
6513 alu
.last
= i
% 4 == 3;
6514 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6516 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6521 // INTERP can't swizzle dst
6522 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6523 for (i
= 0; i
<= lasti
; i
++) {
6524 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6528 alu
.op
= ALU_OP1_MOV
;
6529 alu
.src
[0].sel
= tmp
;
6530 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6531 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6533 alu
.last
= i
== lasti
;
6534 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6543 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6545 struct r600_bytecode_alu alu
;
6548 for (i
= 0; i
< 4; i
++) {
6549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6550 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6551 alu
.op
= ALU_OP0_NOP
;
6554 alu
.op
= ALU_OP1_MOV
;
6555 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6556 alu
.src
[0].sel
= ctx
->temp_reg
;
6557 alu
.src
[0].chan
= i
;
6562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6569 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6570 unsigned temp
, int chan
,
6571 struct r600_bytecode_alu_src
*bc_src
,
6572 const struct r600_shader_src
*shader_src
)
6574 struct r600_bytecode_alu alu
;
6577 r600_bytecode_src(bc_src
, shader_src
, chan
);
6579 /* op3 operands don't support abs modifier */
6581 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6583 alu
.op
= ALU_OP1_MOV
;
6585 alu
.dst
.chan
= chan
;
6588 alu
.src
[0] = *bc_src
;
6589 alu
.last
= true; // sufficient?
6590 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6594 memset(bc_src
, 0, sizeof(*bc_src
));
6596 bc_src
->chan
= chan
;
6601 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6603 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6604 struct r600_bytecode_alu alu
;
6606 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6608 unsigned op
= ctx
->inst_info
->op
;
6610 if (op
== ALU_OP3_MULADD_IEEE
&&
6611 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6612 op
= ALU_OP3_MULADD
;
6614 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6616 if (ctx
->src
[j
].abs
)
6617 temp_regs
[j
] = r600_get_temp(ctx
);
6619 for (i
= 0; i
< lasti
+ 1; i
++) {
6620 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6623 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6625 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6626 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6631 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6638 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6645 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6647 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6648 struct r600_bytecode_alu alu
;
6650 unsigned op
= ctx
->inst_info
->op
;
6651 if (op
== ALU_OP2_DOT4_IEEE
&&
6652 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6655 for (i
= 0; i
< 4; i
++) {
6656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6658 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6659 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6662 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6664 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6665 /* handle some special cases */
6666 switch (inst
->Instruction
.Opcode
) {
6667 case TGSI_OPCODE_DP2
:
6669 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6670 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6673 case TGSI_OPCODE_DP3
:
6675 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6676 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6685 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6692 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6695 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6696 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6697 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6698 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6699 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6700 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6703 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6706 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6707 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6710 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6712 struct r600_bytecode_vtx vtx
;
6713 struct r600_bytecode_alu alu
;
6714 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6716 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6718 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6719 if (src_requires_loading
) {
6720 for (i
= 0; i
< 4; i
++) {
6721 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6722 alu
.op
= ALU_OP1_MOV
;
6723 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6724 alu
.dst
.sel
= ctx
->temp_reg
;
6729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6733 src_gpr
= ctx
->temp_reg
;
6736 memset(&vtx
, 0, sizeof(vtx
));
6737 vtx
.op
= FETCH_OP_VFETCH
;
6738 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6739 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6740 vtx
.src_gpr
= src_gpr
;
6741 vtx
.mega_fetch_count
= 16;
6742 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6743 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6744 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6745 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6746 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6747 vtx
.use_const_fields
= 1;
6749 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6752 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6755 for (i
= 0; i
< 4; i
++) {
6756 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6757 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6761 alu
.op
= ALU_OP2_AND_INT
;
6764 alu
.dst
.sel
= vtx
.dst_gpr
;
6767 alu
.src
[0].sel
= vtx
.dst_gpr
;
6768 alu
.src
[0].chan
= i
;
6770 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6771 alu
.src
[1].sel
+= (id
* 2);
6772 alu
.src
[1].chan
= i
% 4;
6773 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6782 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6783 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6784 alu
.op
= ALU_OP2_OR_INT
;
6787 alu
.dst
.sel
= vtx
.dst_gpr
;
6790 alu
.src
[0].sel
= vtx
.dst_gpr
;
6791 alu
.src
[0].chan
= 3;
6793 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6794 alu
.src
[1].chan
= 0;
6795 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6798 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6805 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
6807 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6808 struct r600_bytecode_alu alu
;
6810 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6812 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6813 alu
.op
= ALU_OP1_MOV
;
6814 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6815 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6816 /* channel 0 or 2 of each word */
6817 alu
.src
[0].sel
+= (id
/ 2);
6818 alu
.src
[0].chan
= (id
% 2) * 2;
6820 /* r600 we have them at channel 2 of the second dword */
6821 alu
.src
[0].sel
+= (id
* 2) + 1;
6822 alu
.src
[0].chan
= 1;
6824 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6825 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6827 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6833 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6835 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6836 struct r600_bytecode_tex tex
;
6837 struct r600_bytecode_alu alu
;
6841 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
6842 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6843 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
6844 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
6846 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
6847 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6848 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
6850 /* Texture fetch instructions can only use gprs as source.
6851 * Also they cannot negate the source or take the absolute value */
6852 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
6853 tgsi_tex_src_requires_loading(ctx
, 0)) ||
6854 read_compressed_msaa
|| txf_add_offsets
;
6856 boolean src_loaded
= FALSE
;
6857 unsigned sampler_src_reg
= 1;
6858 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
6859 boolean has_txq_cube_array_z
= false;
6860 unsigned sampler_index_mode
;
6862 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
6863 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6864 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
6865 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
6866 ctx
->shader
->has_txq_cube_array_z_comp
= true;
6867 has_txq_cube_array_z
= true;
6870 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
6871 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6872 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
6873 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
6874 sampler_src_reg
= 2;
6876 /* TGSI moves the sampler to src reg 3 for TXD */
6877 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
6878 sampler_src_reg
= 3;
6880 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6882 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6884 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
6885 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
6886 ctx
->shader
->uses_tex_buffers
= true;
6887 return r600_do_buffer_txq(ctx
);
6889 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
6890 if (ctx
->bc
->chip_class
< EVERGREEN
)
6891 ctx
->shader
->uses_tex_buffers
= true;
6892 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
6896 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
6898 /* Add perspective divide */
6899 if (ctx
->bc
->chip_class
== CAYMAN
) {
6901 for (i
= 0; i
< 3; i
++) {
6902 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6903 alu
.op
= ALU_OP1_RECIP_IEEE
;
6904 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6906 alu
.dst
.sel
= ctx
->temp_reg
;
6912 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6919 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6920 alu
.op
= ALU_OP1_RECIP_IEEE
;
6921 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6923 alu
.dst
.sel
= ctx
->temp_reg
;
6924 alu
.dst
.chan
= out_chan
;
6927 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6932 for (i
= 0; i
< 3; i
++) {
6933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6934 alu
.op
= ALU_OP2_MUL
;
6935 alu
.src
[0].sel
= ctx
->temp_reg
;
6936 alu
.src
[0].chan
= out_chan
;
6937 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6938 alu
.dst
.sel
= ctx
->temp_reg
;
6941 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6946 alu
.op
= ALU_OP1_MOV
;
6947 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6948 alu
.src
[0].chan
= 0;
6949 alu
.dst
.sel
= ctx
->temp_reg
;
6953 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6957 src_gpr
= ctx
->temp_reg
;
6961 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
6962 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6963 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6964 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
6965 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
6967 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
6968 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
6970 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
6971 for (i
= 0; i
< 4; i
++) {
6972 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6973 alu
.op
= ALU_OP2_CUBE
;
6974 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
6975 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
6976 alu
.dst
.sel
= ctx
->temp_reg
;
6981 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6986 /* tmp1.z = RCP_e(|tmp1.z|) */
6987 if (ctx
->bc
->chip_class
== CAYMAN
) {
6988 for (i
= 0; i
< 3; i
++) {
6989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6990 alu
.op
= ALU_OP1_RECIP_IEEE
;
6991 alu
.src
[0].sel
= ctx
->temp_reg
;
6992 alu
.src
[0].chan
= 2;
6994 alu
.dst
.sel
= ctx
->temp_reg
;
7000 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7005 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7006 alu
.op
= ALU_OP1_RECIP_IEEE
;
7007 alu
.src
[0].sel
= ctx
->temp_reg
;
7008 alu
.src
[0].chan
= 2;
7010 alu
.dst
.sel
= ctx
->temp_reg
;
7014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7019 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7020 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7021 * muladd has no writemask, have to use another temp
7023 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7024 alu
.op
= ALU_OP3_MULADD
;
7027 alu
.src
[0].sel
= ctx
->temp_reg
;
7028 alu
.src
[0].chan
= 0;
7029 alu
.src
[1].sel
= ctx
->temp_reg
;
7030 alu
.src
[1].chan
= 2;
7032 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7033 alu
.src
[2].chan
= 0;
7034 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7036 alu
.dst
.sel
= ctx
->temp_reg
;
7040 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7045 alu
.op
= ALU_OP3_MULADD
;
7048 alu
.src
[0].sel
= ctx
->temp_reg
;
7049 alu
.src
[0].chan
= 1;
7050 alu
.src
[1].sel
= ctx
->temp_reg
;
7051 alu
.src
[1].chan
= 2;
7053 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7054 alu
.src
[2].chan
= 0;
7055 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7057 alu
.dst
.sel
= ctx
->temp_reg
;
7062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7065 /* write initial compare value into Z component
7066 - W src 0 for shadow cube
7067 - X src 1 for shadow cube array */
7068 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7069 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7070 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7071 alu
.op
= ALU_OP1_MOV
;
7072 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7073 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7075 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7076 alu
.dst
.sel
= ctx
->temp_reg
;
7080 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7085 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7086 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7087 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7088 int mytmp
= r600_get_temp(ctx
);
7089 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7090 alu
.op
= ALU_OP1_MOV
;
7091 alu
.src
[0].sel
= ctx
->temp_reg
;
7092 alu
.src
[0].chan
= 3;
7093 alu
.dst
.sel
= mytmp
;
7097 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7101 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7102 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7103 alu
.op
= ALU_OP3_MULADD
;
7105 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7106 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7107 alu
.src
[1].chan
= 0;
7108 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7109 alu
.src
[2].sel
= mytmp
;
7110 alu
.src
[2].chan
= 0;
7111 alu
.dst
.sel
= ctx
->temp_reg
;
7115 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7118 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7119 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7120 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7121 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7122 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7123 tex
.src_gpr
= r600_get_temp(ctx
);
7128 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7129 tex
.coord_type_x
= 1;
7130 tex
.coord_type_y
= 1;
7131 tex
.coord_type_z
= 1;
7132 tex
.coord_type_w
= 1;
7133 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7134 alu
.op
= ALU_OP1_MOV
;
7135 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7136 alu
.dst
.sel
= tex
.src_gpr
;
7140 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7144 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7151 /* for cube forms of lod and bias we need to route things */
7152 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7153 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7154 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7155 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7156 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7157 alu
.op
= ALU_OP1_MOV
;
7158 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7159 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7160 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7162 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7163 alu
.dst
.sel
= ctx
->temp_reg
;
7167 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7173 src_gpr
= ctx
->temp_reg
;
7176 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7177 int temp_h
= 0, temp_v
= 0;
7180 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7181 if (src_loaded
== TRUE
)
7185 for (i
= start_val
; i
< 3; i
++) {
7186 int treg
= r600_get_temp(ctx
);
7195 for (j
= 0; j
< 4; j
++) {
7196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7197 alu
.op
= ALU_OP1_MOV
;
7198 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7204 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7209 for (i
= 1; i
< 3; i
++) {
7210 /* set gradients h/v */
7211 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7212 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7213 FETCH_OP_SET_GRADIENTS_V
;
7214 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7215 tex
.sampler_index_mode
= sampler_index_mode
;
7216 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7217 tex
.resource_index_mode
= sampler_index_mode
;
7219 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7225 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7226 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7227 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7228 tex
.coord_type_x
= 1;
7229 tex
.coord_type_y
= 1;
7230 tex
.coord_type_z
= 1;
7231 tex
.coord_type_w
= 1;
7233 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7239 if (src_requires_loading
&& !src_loaded
) {
7240 for (i
= 0; i
< 4; i
++) {
7241 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7242 alu
.op
= ALU_OP1_MOV
;
7243 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7244 alu
.dst
.sel
= ctx
->temp_reg
;
7249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7254 src_gpr
= ctx
->temp_reg
;
7257 /* get offset values */
7258 if (inst
->Texture
.NumOffsets
) {
7259 assert(inst
->Texture
.NumOffsets
== 1);
7261 /* The texture offset feature doesn't work with the TXF instruction
7262 * and must be emulated by adding the offset to the texture coordinates. */
7263 if (txf_add_offsets
) {
7264 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7266 switch (inst
->Texture
.Texture
) {
7267 case TGSI_TEXTURE_3D
:
7268 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7269 alu
.op
= ALU_OP2_ADD_INT
;
7270 alu
.src
[0].sel
= src_gpr
;
7271 alu
.src
[0].chan
= 2;
7272 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7273 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7274 alu
.dst
.sel
= src_gpr
;
7278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7283 case TGSI_TEXTURE_2D
:
7284 case TGSI_TEXTURE_SHADOW2D
:
7285 case TGSI_TEXTURE_RECT
:
7286 case TGSI_TEXTURE_SHADOWRECT
:
7287 case TGSI_TEXTURE_2D_ARRAY
:
7288 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7290 alu
.op
= ALU_OP2_ADD_INT
;
7291 alu
.src
[0].sel
= src_gpr
;
7292 alu
.src
[0].chan
= 1;
7293 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7294 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7295 alu
.dst
.sel
= src_gpr
;
7299 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7304 case TGSI_TEXTURE_1D
:
7305 case TGSI_TEXTURE_SHADOW1D
:
7306 case TGSI_TEXTURE_1D_ARRAY
:
7307 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7309 alu
.op
= ALU_OP2_ADD_INT
;
7310 alu
.src
[0].sel
= src_gpr
;
7311 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7312 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7313 alu
.dst
.sel
= src_gpr
;
7316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7320 /* texture offsets do not apply to other texture targets */
7323 switch (inst
->Texture
.Texture
) {
7324 case TGSI_TEXTURE_3D
:
7325 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7327 case TGSI_TEXTURE_2D
:
7328 case TGSI_TEXTURE_SHADOW2D
:
7329 case TGSI_TEXTURE_RECT
:
7330 case TGSI_TEXTURE_SHADOWRECT
:
7331 case TGSI_TEXTURE_2D_ARRAY
:
7332 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7333 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7335 case TGSI_TEXTURE_1D
:
7336 case TGSI_TEXTURE_SHADOW1D
:
7337 case TGSI_TEXTURE_1D_ARRAY
:
7338 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7339 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7344 /* Obtain the sample index for reading a compressed MSAA color texture.
7345 * To read the FMASK, we use the ldfptr instruction, which tells us
7346 * where the samples are stored.
7347 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7348 * which is the identity mapping. Each nibble says which physical sample
7349 * should be fetched to get that sample.
7351 * Assume src.z contains the sample index. It should be modified like this:
7352 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7353 * Then fetch the texel with src.
7355 if (read_compressed_msaa
) {
7356 unsigned sample_chan
= 3;
7357 unsigned temp
= r600_get_temp(ctx
);
7360 /* temp.w = ldfptr() */
7361 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7362 tex
.op
= FETCH_OP_LD
;
7363 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7364 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7365 tex
.sampler_index_mode
= sampler_index_mode
;
7366 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7367 tex
.resource_index_mode
= sampler_index_mode
;
7368 tex
.src_gpr
= src_gpr
;
7370 tex
.dst_sel_x
= 7; /* mask out these components */
7373 tex
.dst_sel_w
= 0; /* store X */
7378 tex
.offset_x
= offset_x
;
7379 tex
.offset_y
= offset_y
;
7380 tex
.offset_z
= offset_z
;
7381 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7385 /* temp.x = sample_index*4 */
7386 if (ctx
->bc
->chip_class
== CAYMAN
) {
7387 for (i
= 0 ; i
< 4; i
++) {
7388 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7389 alu
.op
= ALU_OP2_MULLO_INT
;
7390 alu
.src
[0].sel
= src_gpr
;
7391 alu
.src
[0].chan
= sample_chan
;
7392 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7393 alu
.src
[1].value
= 4;
7396 alu
.dst
.write
= i
== 0;
7399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7404 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7405 alu
.op
= ALU_OP2_MULLO_INT
;
7406 alu
.src
[0].sel
= src_gpr
;
7407 alu
.src
[0].chan
= sample_chan
;
7408 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7409 alu
.src
[1].value
= 4;
7414 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7419 /* sample_index = temp.w >> temp.x */
7420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7421 alu
.op
= ALU_OP2_LSHR_INT
;
7422 alu
.src
[0].sel
= temp
;
7423 alu
.src
[0].chan
= 3;
7424 alu
.src
[1].sel
= temp
;
7425 alu
.src
[1].chan
= 0;
7426 alu
.dst
.sel
= src_gpr
;
7427 alu
.dst
.chan
= sample_chan
;
7430 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7434 /* sample_index & 0xF */
7435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7436 alu
.op
= ALU_OP2_AND_INT
;
7437 alu
.src
[0].sel
= src_gpr
;
7438 alu
.src
[0].chan
= sample_chan
;
7439 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7440 alu
.src
[1].value
= 0xF;
7441 alu
.dst
.sel
= src_gpr
;
7442 alu
.dst
.chan
= sample_chan
;
7445 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7449 /* visualize the FMASK */
7450 for (i
= 0; i
< 4; i
++) {
7451 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7452 alu
.op
= ALU_OP1_INT_TO_FLT
;
7453 alu
.src
[0].sel
= src_gpr
;
7454 alu
.src
[0].chan
= sample_chan
;
7455 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7459 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7467 /* does this shader want a num layers from TXQ for a cube array? */
7468 if (has_txq_cube_array_z
) {
7469 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7472 alu
.op
= ALU_OP1_MOV
;
7474 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7475 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7476 /* channel 1 or 3 of each word */
7477 alu
.src
[0].sel
+= (id
/ 2);
7478 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
7480 /* r600 we have them at channel 2 of the second dword */
7481 alu
.src
[0].sel
+= (id
* 2) + 1;
7482 alu
.src
[0].chan
= 2;
7484 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7485 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7487 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7490 /* disable writemask from texture instruction */
7491 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7494 opcode
= ctx
->inst_info
->op
;
7495 if (opcode
== FETCH_OP_GATHER4
&&
7496 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7497 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7498 opcode
= FETCH_OP_GATHER4_O
;
7500 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7501 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7502 encoded in the instruction are ignored. */
7503 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7504 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7505 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7506 tex
.sampler_index_mode
= sampler_index_mode
;
7507 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7508 tex
.resource_index_mode
= sampler_index_mode
;
7510 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7511 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7512 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7513 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7521 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7526 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7527 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7528 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7529 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7530 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7531 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7532 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7534 case FETCH_OP_SAMPLE
:
7535 opcode
= FETCH_OP_SAMPLE_C
;
7537 case FETCH_OP_SAMPLE_L
:
7538 opcode
= FETCH_OP_SAMPLE_C_L
;
7540 case FETCH_OP_SAMPLE_LB
:
7541 opcode
= FETCH_OP_SAMPLE_C_LB
;
7543 case FETCH_OP_SAMPLE_G
:
7544 opcode
= FETCH_OP_SAMPLE_C_G
;
7546 /* Texture gather variants */
7547 case FETCH_OP_GATHER4
:
7548 opcode
= FETCH_OP_GATHER4_C
;
7550 case FETCH_OP_GATHER4_O
:
7551 opcode
= FETCH_OP_GATHER4_C_O
;
7556 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7559 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7560 tex
.sampler_index_mode
= sampler_index_mode
;
7561 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7562 tex
.resource_index_mode
= sampler_index_mode
;
7563 tex
.src_gpr
= src_gpr
;
7564 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7566 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7567 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7568 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7571 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7572 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7573 tex
.inst_mod
= texture_component_select
;
7575 if (ctx
->bc
->chip_class
== CAYMAN
) {
7576 /* GATHER4 result order is different from TGSI TG4 */
7577 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7578 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7579 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7580 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7582 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7583 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7584 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7585 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7588 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7589 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7590 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7594 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7601 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7602 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7603 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7604 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7608 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7613 } else if (src_loaded
) {
7619 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7620 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7621 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7622 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7623 tex
.src_rel
= ctx
->src
[0].rel
;
7626 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7627 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7628 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7629 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7633 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7636 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7637 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7638 tex
.coord_type_x
= 1;
7639 tex
.coord_type_y
= 1;
7641 tex
.coord_type_z
= 1;
7642 tex
.coord_type_w
= 1;
7644 tex
.offset_x
= offset_x
;
7645 tex
.offset_y
= offset_y
;
7646 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7647 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7648 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7652 tex
.offset_z
= offset_z
;
7655 /* Put the depth for comparison in W.
7656 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7657 * Some instructions expect the depth in Z. */
7658 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7659 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7660 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7661 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7662 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7663 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7664 tex
.src_sel_w
= tex
.src_sel_z
;
7667 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7668 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7669 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7670 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7671 /* the array index is read from Y */
7672 tex
.coord_type_y
= 0;
7674 /* the array index is read from Z */
7675 tex
.coord_type_z
= 0;
7676 tex
.src_sel_z
= tex
.src_sel_y
;
7678 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7679 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7680 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7681 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7682 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7683 /* the array index is read from Z */
7684 tex
.coord_type_z
= 0;
7686 /* mask unused source components */
7687 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7688 switch (inst
->Texture
.Texture
) {
7689 case TGSI_TEXTURE_2D
:
7690 case TGSI_TEXTURE_RECT
:
7694 case TGSI_TEXTURE_1D_ARRAY
:
7698 case TGSI_TEXTURE_1D
:
7706 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7710 /* add shadow ambient support - gallium doesn't do it yet */
7714 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7715 struct tgsi_full_src_register
*src
)
7719 if (src
->Register
.Indirect
) {
7720 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7721 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7722 return ctx
->shader
->atomics
[i
].hw_idx
;
7725 uint32_t index
= src
->Register
.Index
;
7726 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7727 if (ctx
->shader
->atomics
[i
].buffer_id
!= src
->Dimension
.Index
)
7729 if (index
> ctx
->shader
->atomics
[i
].end
)
7731 if (index
< ctx
->shader
->atomics
[i
].start
)
7733 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7734 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7742 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
7744 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7746 struct r600_bytecode_gds gds
;
7748 int uav_index_mode
= 0;
7750 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7752 if (inst
->Src
[0].Register
.Indirect
)
7755 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7756 gds
.op
= FETCH_OP_GDS_READ_RET
;
7757 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7758 gds
.uav_id
= uav_id
;
7759 gds
.uav_index_mode
= uav_index_mode
;
7760 gds
.src_gpr
= ctx
->temp_reg
;
7768 gds
.src_gpr2
= ctx
->temp_reg
;
7769 gds
.alloc_consume
= 1;
7770 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7774 ctx
->bc
->cf_last
->vpm
= 1;
7778 static int tgsi_load(struct r600_shader_ctx
*ctx
)
7780 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7781 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
7782 return tgsi_load_gds(ctx
);
7786 static int get_gds_op(int opcode
)
7789 case TGSI_OPCODE_ATOMUADD
:
7790 return FETCH_OP_GDS_ADD_RET
;
7791 case TGSI_OPCODE_ATOMAND
:
7792 return FETCH_OP_GDS_AND_RET
;
7793 case TGSI_OPCODE_ATOMOR
:
7794 return FETCH_OP_GDS_OR_RET
;
7795 case TGSI_OPCODE_ATOMXOR
:
7796 return FETCH_OP_GDS_XOR_RET
;
7797 case TGSI_OPCODE_ATOMUMIN
:
7798 return FETCH_OP_GDS_MIN_UINT_RET
;
7799 case TGSI_OPCODE_ATOMUMAX
:
7800 return FETCH_OP_GDS_MAX_UINT_RET
;
7801 case TGSI_OPCODE_ATOMXCHG
:
7802 return FETCH_OP_GDS_XCHG_RET
;
7803 case TGSI_OPCODE_ATOMCAS
:
7804 return FETCH_OP_GDS_CMP_XCHG_RET
;
7810 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
7812 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7813 struct r600_bytecode_gds gds
;
7814 struct r600_bytecode_alu alu
;
7815 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
7818 int uav_index_mode
= 0;
7821 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
7825 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7827 if (inst
->Src
[0].Register
.Indirect
)
7830 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
7831 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
7832 int abs_value
= abs(value
);
7833 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
7834 gds_op
= FETCH_OP_GDS_SUB_RET
;
7835 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7836 alu
.op
= ALU_OP1_MOV
;
7837 alu
.dst
.sel
= ctx
->temp_reg
;
7839 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
7840 alu
.src
[0].value
= abs_value
;
7843 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7847 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7848 alu
.op
= ALU_OP1_MOV
;
7849 alu
.dst
.sel
= ctx
->temp_reg
;
7851 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
7854 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7859 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7861 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7862 gds
.uav_id
= uav_id
;
7863 gds
.uav_index_mode
= uav_index_mode
;
7864 gds
.src_gpr
= ctx
->temp_reg
;
7865 gds
.src_gpr2
= ctx
->temp_reg
;
7873 gds
.alloc_consume
= 1;
7874 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7877 ctx
->bc
->cf_last
->vpm
= 1;
7881 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
7883 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7884 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
7885 return tgsi_atomic_op_gds(ctx
);
7889 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
7891 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7892 struct r600_bytecode_alu alu
;
7893 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7894 unsigned i
, temp_regs
[2];
7897 /* optimize if it's just an equal balance */
7898 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
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_OP2_ADD
;
7905 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
7906 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7908 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7913 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7921 for (i
= 0; i
< lasti
+ 1; i
++) {
7922 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7926 alu
.op
= ALU_OP2_ADD
;
7927 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7928 alu
.src
[0].chan
= 0;
7929 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7930 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
7931 alu
.dst
.sel
= ctx
->temp_reg
;
7937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7942 /* (1 - src0) * src2 */
7943 for (i
= 0; i
< lasti
+ 1; i
++) {
7944 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7948 alu
.op
= ALU_OP2_MUL
;
7949 alu
.src
[0].sel
= ctx
->temp_reg
;
7950 alu
.src
[0].chan
= i
;
7951 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7952 alu
.dst
.sel
= ctx
->temp_reg
;
7958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7963 /* src0 * src1 + (1 - src0) * src2 */
7964 if (ctx
->src
[0].abs
)
7965 temp_regs
[0] = r600_get_temp(ctx
);
7968 if (ctx
->src
[1].abs
)
7969 temp_regs
[1] = r600_get_temp(ctx
);
7973 for (i
= 0; i
< lasti
+ 1; i
++) {
7974 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7978 alu
.op
= ALU_OP3_MULADD
;
7980 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
7983 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
7986 alu
.src
[2].sel
= ctx
->temp_reg
;
7987 alu
.src
[2].chan
= i
;
7989 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7994 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8001 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
8003 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8004 struct r600_bytecode_alu alu
;
8006 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8010 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
8012 ctx
->src
[0].abs
= 0;
8013 ctx
->src
[0].neg
= 0;
8018 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
8020 if (ctx
->src
[j
].abs
)
8021 temp_regs
[j
] = r600_get_temp(ctx
);
8024 for (i
= 0; i
< lasti
+ 1; i
++) {
8025 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8030 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8033 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
8036 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
8039 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8045 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8052 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
8054 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8055 struct r600_bytecode_alu alu
;
8057 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8059 for (i
= 0; i
< lasti
+ 1; i
++) {
8060 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8064 alu
.op
= ALU_OP3_CNDE_INT
;
8065 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8066 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8067 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
8068 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8081 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
8083 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8084 struct r600_bytecode_alu alu
;
8088 /* result.x = 2^floor(src); */
8089 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8090 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8092 alu
.op
= ALU_OP1_FLOOR
;
8093 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8095 alu
.dst
.sel
= ctx
->temp_reg
;
8099 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8103 if (ctx
->bc
->chip_class
== CAYMAN
) {
8104 for (i
= 0; i
< 3; i
++) {
8105 alu
.op
= ALU_OP1_EXP_IEEE
;
8106 alu
.src
[0].sel
= ctx
->temp_reg
;
8107 alu
.src
[0].chan
= 0;
8109 alu
.dst
.sel
= ctx
->temp_reg
;
8111 alu
.dst
.write
= i
== 0;
8113 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8118 alu
.op
= ALU_OP1_EXP_IEEE
;
8119 alu
.src
[0].sel
= ctx
->temp_reg
;
8120 alu
.src
[0].chan
= 0;
8122 alu
.dst
.sel
= ctx
->temp_reg
;
8126 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8132 /* result.y = tmp - floor(tmp); */
8133 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8134 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8136 alu
.op
= ALU_OP1_FRACT
;
8137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8139 alu
.dst
.sel
= ctx
->temp_reg
;
8141 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8150 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8155 /* result.z = RoughApprox2ToX(tmp);*/
8156 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
8157 if (ctx
->bc
->chip_class
== CAYMAN
) {
8158 for (i
= 0; i
< 3; i
++) {
8159 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8160 alu
.op
= ALU_OP1_EXP_IEEE
;
8161 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8163 alu
.dst
.sel
= ctx
->temp_reg
;
8170 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8175 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8176 alu
.op
= ALU_OP1_EXP_IEEE
;
8177 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8179 alu
.dst
.sel
= ctx
->temp_reg
;
8185 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8191 /* result.w = 1.0;*/
8192 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
8193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8195 alu
.op
= ALU_OP1_MOV
;
8196 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8197 alu
.src
[0].chan
= 0;
8199 alu
.dst
.sel
= ctx
->temp_reg
;
8203 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8207 return tgsi_helper_copy(ctx
, inst
);
8210 static int tgsi_log(struct r600_shader_ctx
*ctx
)
8212 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8213 struct r600_bytecode_alu alu
;
8217 /* result.x = floor(log2(|src|)); */
8218 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8219 if (ctx
->bc
->chip_class
== CAYMAN
) {
8220 for (i
= 0; i
< 3; i
++) {
8221 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8223 alu
.op
= ALU_OP1_LOG_IEEE
;
8224 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8225 r600_bytecode_src_set_abs(&alu
.src
[0]);
8227 alu
.dst
.sel
= ctx
->temp_reg
;
8233 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8239 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8241 alu
.op
= ALU_OP1_LOG_IEEE
;
8242 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8243 r600_bytecode_src_set_abs(&alu
.src
[0]);
8245 alu
.dst
.sel
= ctx
->temp_reg
;
8249 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8254 alu
.op
= ALU_OP1_FLOOR
;
8255 alu
.src
[0].sel
= ctx
->temp_reg
;
8256 alu
.src
[0].chan
= 0;
8258 alu
.dst
.sel
= ctx
->temp_reg
;
8263 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8268 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
8269 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8271 if (ctx
->bc
->chip_class
== CAYMAN
) {
8272 for (i
= 0; i
< 3; i
++) {
8273 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8275 alu
.op
= ALU_OP1_LOG_IEEE
;
8276 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8277 r600_bytecode_src_set_abs(&alu
.src
[0]);
8279 alu
.dst
.sel
= ctx
->temp_reg
;
8286 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8291 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8293 alu
.op
= ALU_OP1_LOG_IEEE
;
8294 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8295 r600_bytecode_src_set_abs(&alu
.src
[0]);
8297 alu
.dst
.sel
= ctx
->temp_reg
;
8302 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8309 alu
.op
= ALU_OP1_FLOOR
;
8310 alu
.src
[0].sel
= ctx
->temp_reg
;
8311 alu
.src
[0].chan
= 1;
8313 alu
.dst
.sel
= ctx
->temp_reg
;
8318 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8322 if (ctx
->bc
->chip_class
== CAYMAN
) {
8323 for (i
= 0; i
< 3; i
++) {
8324 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8325 alu
.op
= ALU_OP1_EXP_IEEE
;
8326 alu
.src
[0].sel
= ctx
->temp_reg
;
8327 alu
.src
[0].chan
= 1;
8329 alu
.dst
.sel
= ctx
->temp_reg
;
8336 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8341 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8342 alu
.op
= ALU_OP1_EXP_IEEE
;
8343 alu
.src
[0].sel
= ctx
->temp_reg
;
8344 alu
.src
[0].chan
= 1;
8346 alu
.dst
.sel
= ctx
->temp_reg
;
8351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8356 if (ctx
->bc
->chip_class
== CAYMAN
) {
8357 for (i
= 0; i
< 3; i
++) {
8358 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8359 alu
.op
= ALU_OP1_RECIP_IEEE
;
8360 alu
.src
[0].sel
= ctx
->temp_reg
;
8361 alu
.src
[0].chan
= 1;
8363 alu
.dst
.sel
= ctx
->temp_reg
;
8370 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8375 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8376 alu
.op
= ALU_OP1_RECIP_IEEE
;
8377 alu
.src
[0].sel
= ctx
->temp_reg
;
8378 alu
.src
[0].chan
= 1;
8380 alu
.dst
.sel
= ctx
->temp_reg
;
8385 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8392 alu
.op
= ALU_OP2_MUL
;
8394 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8395 r600_bytecode_src_set_abs(&alu
.src
[0]);
8397 alu
.src
[1].sel
= ctx
->temp_reg
;
8398 alu
.src
[1].chan
= 1;
8400 alu
.dst
.sel
= ctx
->temp_reg
;
8405 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8410 /* result.z = log2(|src|);*/
8411 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
8412 if (ctx
->bc
->chip_class
== CAYMAN
) {
8413 for (i
= 0; i
< 3; i
++) {
8414 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8416 alu
.op
= ALU_OP1_LOG_IEEE
;
8417 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8418 r600_bytecode_src_set_abs(&alu
.src
[0]);
8420 alu
.dst
.sel
= ctx
->temp_reg
;
8427 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8432 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8434 alu
.op
= ALU_OP1_LOG_IEEE
;
8435 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8436 r600_bytecode_src_set_abs(&alu
.src
[0]);
8438 alu
.dst
.sel
= ctx
->temp_reg
;
8443 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8449 /* result.w = 1.0; */
8450 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
8451 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8453 alu
.op
= ALU_OP1_MOV
;
8454 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8455 alu
.src
[0].chan
= 0;
8457 alu
.dst
.sel
= ctx
->temp_reg
;
8462 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8467 return tgsi_helper_copy(ctx
, inst
);
8470 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
8472 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8473 struct r600_bytecode_alu alu
;
8475 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8476 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
8478 assert(inst
->Dst
[0].Register
.Index
< 3);
8479 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8481 switch (inst
->Instruction
.Opcode
) {
8482 case TGSI_OPCODE_ARL
:
8483 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
8485 case TGSI_OPCODE_ARR
:
8486 alu
.op
= ALU_OP1_FLT_TO_INT
;
8488 case TGSI_OPCODE_UARL
:
8489 alu
.op
= ALU_OP1_MOV
;
8496 for (i
= 0; i
<= lasti
; ++i
) {
8497 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8499 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8500 alu
.last
= i
== lasti
;
8504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8509 if (inst
->Dst
[0].Register
.Index
> 0)
8510 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
8512 ctx
->bc
->ar_loaded
= 0;
8516 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
8518 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8519 struct r600_bytecode_alu alu
;
8521 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8523 switch (inst
->Instruction
.Opcode
) {
8524 case TGSI_OPCODE_ARL
:
8525 memset(&alu
, 0, sizeof(alu
));
8526 alu
.op
= ALU_OP1_FLOOR
;
8527 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8529 for (i
= 0; i
<= lasti
; ++i
) {
8530 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8532 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8533 alu
.last
= i
== lasti
;
8534 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8539 memset(&alu
, 0, sizeof(alu
));
8540 alu
.op
= ALU_OP1_FLT_TO_INT
;
8541 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
8542 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8544 /* FLT_TO_INT is trans-only on r600/r700 */
8546 for (i
= 0; i
<= lasti
; ++i
) {
8548 alu
.src
[0].chan
= i
;
8549 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8553 case TGSI_OPCODE_ARR
:
8554 memset(&alu
, 0, sizeof(alu
));
8555 alu
.op
= ALU_OP1_FLT_TO_INT
;
8556 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8558 /* FLT_TO_INT is trans-only on r600/r700 */
8560 for (i
= 0; i
<= lasti
; ++i
) {
8561 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8563 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8564 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8569 case TGSI_OPCODE_UARL
:
8570 memset(&alu
, 0, sizeof(alu
));
8571 alu
.op
= ALU_OP1_MOV
;
8572 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8574 for (i
= 0; i
<= lasti
; ++i
) {
8575 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8577 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8578 alu
.last
= i
== lasti
;
8579 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8589 ctx
->bc
->ar_loaded
= 0;
8593 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
8595 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8596 struct r600_bytecode_alu alu
;
8599 for (i
= 0; i
< 4; i
++) {
8600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8602 alu
.op
= ALU_OP2_MUL
;
8603 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8605 if (i
== 0 || i
== 3) {
8606 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8608 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8611 if (i
== 0 || i
== 2) {
8612 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
8614 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8618 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8625 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
8627 struct r600_bytecode_alu alu
;
8630 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8632 alu
.execute_mask
= 1;
8633 alu
.update_pred
= 1;
8635 alu
.dst
.sel
= ctx
->temp_reg
;
8639 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8640 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
8641 alu
.src
[1].chan
= 0;
8645 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
8651 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
8653 unsigned force_pop
= ctx
->bc
->force_add_cf
;
8657 if (ctx
->bc
->cf_last
) {
8658 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
8660 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
8665 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
8666 ctx
->bc
->force_add_cf
= 1;
8667 } else if (alu_pop
== 2) {
8668 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
8669 ctx
->bc
->force_add_cf
= 1;
8676 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
8677 ctx
->bc
->cf_last
->pop_count
= pops
;
8678 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8684 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
8687 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
8688 unsigned elements
, entries
;
8690 unsigned entry_size
= stack
->entry_size
;
8692 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
8693 elements
+= stack
->push
;
8695 switch (ctx
->bc
->chip_class
) {
8698 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
8699 * the stack must be reserved to hold the current active/continue
8701 if (reason
== FC_PUSH_VPM
) {
8707 /* r9xx: any stack operation on empty stack consumes 2 additional
8712 /* FIXME: do the two elements added above cover the cases for the
8716 /* r8xx+: 2 extra elements are not always required, but one extra
8717 * element must be added for each of the following cases:
8718 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
8720 * (Currently we don't use ALU_ELSE_AFTER.)
8721 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
8722 * PUSH instruction executed.
8724 * NOTE: it seems we also need to reserve additional element in some
8725 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
8726 * then STACK_SIZE should be 2 instead of 1 */
8727 if (reason
== FC_PUSH_VPM
) {
8737 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
8738 * for all chips, so we use 4 in the final formula, not the real entry_size
8742 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
8744 if (entries
> stack
->max_entries
)
8745 stack
->max_entries
= entries
;
8748 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
8752 --ctx
->bc
->stack
.push
;
8753 assert(ctx
->bc
->stack
.push
>= 0);
8756 --ctx
->bc
->stack
.push_wqm
;
8757 assert(ctx
->bc
->stack
.push_wqm
>= 0);
8760 --ctx
->bc
->stack
.loop
;
8761 assert(ctx
->bc
->stack
.loop
>= 0);
8769 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
8773 ++ctx
->bc
->stack
.push
;
8776 ++ctx
->bc
->stack
.push_wqm
;
8778 ++ctx
->bc
->stack
.loop
;
8784 callstack_update_max_depth(ctx
, reason
);
8787 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
8789 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
8791 sp
->mid
= realloc((void *)sp
->mid
,
8792 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
8793 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
8797 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
8799 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
8800 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
8801 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
8805 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
8807 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
8817 static int emit_return(struct r600_shader_ctx
*ctx
)
8819 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
8823 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
8826 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
8827 ctx
->bc
->cf_last
->pop_count
= pops
;
8828 /* XXX work out offset */
8832 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
8837 static void emit_testflag(struct r600_shader_ctx
*ctx
)
8842 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
8845 emit_jump_to_offset(ctx
, 1, 4);
8846 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
8847 pops(ctx
, ifidx
+ 1);
8851 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
8855 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8856 ctx
->bc
->cf_last
->pop_count
= 1;
8858 fc_set_mid(ctx
, fc_sp
);
8864 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
8866 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
8868 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
8869 * LOOP_STARTxxx for nested loops may put the branch stack into a state
8870 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
8871 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
8872 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
8873 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
8874 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8875 alu_type
= CF_OP_ALU
;
8878 emit_logic_pred(ctx
, opcode
, alu_type
);
8880 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
8882 fc_pushlevel(ctx
, FC_IF
);
8884 callstack_push(ctx
, FC_PUSH_VPM
);
8888 static int tgsi_if(struct r600_shader_ctx
*ctx
)
8890 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
8893 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
8895 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
8898 static int tgsi_else(struct r600_shader_ctx
*ctx
)
8900 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
8901 ctx
->bc
->cf_last
->pop_count
= 1;
8903 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
8904 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
8908 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
8911 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
8912 R600_ERR("if/endif unbalanced in shader\n");
8916 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
8917 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8918 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
8920 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8924 callstack_pop(ctx
, FC_PUSH_VPM
);
8928 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
8930 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
8931 * limited to 4096 iterations, like the other LOOP_* instructions. */
8932 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
8934 fc_pushlevel(ctx
, FC_LOOP
);
8936 /* check stack depth */
8937 callstack_push(ctx
, FC_LOOP
);
8941 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
8945 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
8947 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
8948 R600_ERR("loop/endloop in shader code are not paired.\n");
8952 /* fixup loop pointers - from r600isa
8953 LOOP END points to CF after LOOP START,
8954 LOOP START point to CF after LOOP END
8955 BRK/CONT point to LOOP END CF
8957 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
8959 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8961 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
8962 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
8964 /* XXX add LOOPRET support */
8966 callstack_pop(ctx
, FC_LOOP
);
8970 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
8974 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
8976 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
8981 R600_ERR("Break not inside loop/endloop pair\n");
8985 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8987 fc_set_mid(ctx
, fscp
- 1);
8992 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
8994 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8995 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
8998 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
8999 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
9001 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9003 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
9004 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9005 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
9010 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
9012 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9013 struct r600_bytecode_alu alu
;
9015 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9018 for (i
= 0; i
< lasti
+ 1; i
++) {
9019 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9022 if (ctx
->bc
->chip_class
== CAYMAN
) {
9023 for (j
= 0 ; j
< 4; j
++) {
9024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9026 alu
.op
= ALU_OP2_MULLO_UINT
;
9027 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
9028 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
9031 alu
.dst
.sel
= ctx
->temp_reg
;
9032 alu
.dst
.write
= (j
== i
);
9035 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9043 alu
.dst
.sel
= ctx
->temp_reg
;
9046 alu
.op
= ALU_OP2_MULLO_UINT
;
9047 for (j
= 0; j
< 2; j
++) {
9048 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
9052 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9059 for (i
= 0; i
< lasti
+ 1; i
++) {
9060 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9064 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9066 alu
.op
= ALU_OP2_ADD_INT
;
9068 alu
.src
[0].sel
= ctx
->temp_reg
;
9069 alu
.src
[0].chan
= i
;
9071 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9075 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9082 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
9084 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9085 struct r600_bytecode_alu alu
;
9087 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9089 /* temp.xy = f32_to_f16(src) */
9090 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9091 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
9093 alu
.dst
.sel
= ctx
->temp_reg
;
9095 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9096 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9100 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
9102 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9106 /* dst.x = temp.y * 0x10000 + temp.x */
9107 for (i
= 0; i
< lasti
+ 1; i
++) {
9108 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9111 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9112 alu
.op
= ALU_OP3_MULADD_UINT24
;
9114 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9115 alu
.last
= i
== lasti
;
9116 alu
.src
[0].sel
= ctx
->temp_reg
;
9117 alu
.src
[0].chan
= 1;
9118 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9119 alu
.src
[1].value
= 0x10000;
9120 alu
.src
[2].sel
= ctx
->temp_reg
;
9121 alu
.src
[2].chan
= 0;
9122 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9130 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
9132 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9133 struct r600_bytecode_alu alu
;
9135 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9137 /* temp.x = src.x */
9138 /* note: no need to mask out the high bits */
9139 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9140 alu
.op
= ALU_OP1_MOV
;
9142 alu
.dst
.sel
= ctx
->temp_reg
;
9144 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9145 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9149 /* temp.y = src.x >> 16 */
9150 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9151 alu
.op
= ALU_OP2_LSHR_INT
;
9153 alu
.dst
.sel
= ctx
->temp_reg
;
9155 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9156 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9157 alu
.src
[1].value
= 16;
9159 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9163 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
9164 for (i
= 0; i
< lasti
+ 1; i
++) {
9165 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9168 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9169 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
9170 alu
.src
[0].sel
= ctx
->temp_reg
;
9171 alu
.src
[0].chan
= i
% 2;
9172 alu
.last
= i
== lasti
;
9173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9181 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
9183 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9184 struct r600_bytecode_alu alu
;
9185 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9192 for (i
= 0; i
< lasti
+ 1; i
++) {
9193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9194 alu
.op
= ALU_OP2_SETGE_INT
;
9195 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
9196 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9197 alu
.src
[1].value
= 32;
9198 alu
.dst
.sel
= ctx
->temp_reg
;
9203 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9208 for (i
= 0; i
< lasti
+ 1; i
++) {
9209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9210 alu
.op
= ALU_OP3_CNDE_INT
;
9212 alu
.src
[0].sel
= ctx
->temp_reg
;
9213 alu
.src
[1].chan
= i
;
9215 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9216 alu
.src
[1].sel
= alu
.dst
.sel
;
9217 alu
.src
[1].chan
= i
;
9218 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
9222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9230 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
9231 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9232 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9233 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9235 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9237 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
9238 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9239 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9240 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9241 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9242 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9243 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9244 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9245 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
9246 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9247 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9248 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9249 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9250 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9251 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9252 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9253 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9254 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9255 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9256 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9257 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9258 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9259 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9260 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9261 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9262 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9263 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9264 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9265 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9266 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9267 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9268 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9269 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9270 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9271 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9272 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9273 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9274 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9275 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9276 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9277 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9278 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9279 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9280 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9281 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9282 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9283 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9284 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9285 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9286 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9287 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9288 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9289 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9290 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9291 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9292 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9293 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9294 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9295 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9296 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9297 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9298 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9299 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9300 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9301 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9302 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9303 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9304 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9305 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9306 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9307 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9308 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9309 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9310 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9311 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9312 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9313 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9314 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
9315 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9316 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9317 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9318 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9319 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9320 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
9321 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9322 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9323 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9324 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9325 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9326 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9327 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9328 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9329 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9330 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9331 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9332 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9333 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9334 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9335 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9336 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9337 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9338 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9339 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9340 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9341 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9342 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9343 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9344 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9345 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9346 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9347 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9348 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9349 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9350 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9351 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9352 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
9353 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9354 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9355 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9356 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9357 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9358 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
9359 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9360 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
9361 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9362 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9363 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9364 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9365 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9366 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9367 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9368 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9369 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9370 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9371 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
9372 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9373 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
9374 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9375 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9376 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9377 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9378 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9379 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9380 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9381 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9382 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9383 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9384 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9385 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9386 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9387 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9388 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9389 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9390 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
9391 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9392 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9393 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9394 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9395 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9396 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9397 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9398 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9399 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9400 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9401 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9402 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9403 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9404 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9405 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9406 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9407 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9408 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9409 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9410 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9411 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9412 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9413 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9414 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9415 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
9416 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
9417 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
9418 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
9419 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9420 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
9421 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
9422 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
9423 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
9424 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
9425 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9426 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9427 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9428 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9431 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
9432 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9433 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9434 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9435 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9436 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
9437 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9438 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9439 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9440 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9441 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9442 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9443 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9444 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9445 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9446 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9447 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9448 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9449 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9450 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
9451 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9452 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9453 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9454 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9455 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9456 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9457 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9458 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9459 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9460 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9461 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9462 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9463 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9464 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9465 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9466 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9467 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9468 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9469 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9470 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9471 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
9472 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9473 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9474 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9475 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9476 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9477 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9478 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9479 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9480 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9481 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9482 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9483 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9484 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9485 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9486 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
9487 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9488 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9489 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9490 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9491 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9492 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9493 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9494 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9495 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9496 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9497 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9498 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9499 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9500 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9501 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9502 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9503 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9504 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9505 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9506 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9507 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9508 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9509 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9510 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9511 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9512 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9513 [83] = { ALU_OP0_NOP
, tgsi_unsupported
},
9514 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9515 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9516 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9517 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9518 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9519 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9520 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9521 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9522 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9523 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9524 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9525 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9526 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9527 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9528 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9529 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9530 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9531 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9532 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9533 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9534 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9535 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9536 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9537 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9538 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9539 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9540 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9541 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9542 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9543 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9544 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9545 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9546 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9547 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9548 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9549 /* Refer below for TGSI_OPCODE_DFMA */
9550 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
9551 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9552 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9553 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9554 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9555 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9556 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9557 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9558 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
9559 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9560 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9561 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9562 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9563 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9564 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9565 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9566 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9567 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9568 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9569 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9570 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9571 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9572 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9573 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9574 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9575 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9576 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9577 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9578 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9579 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9580 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9581 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9582 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9583 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9584 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9585 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9586 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9587 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9588 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
9589 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9590 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9591 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9592 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
9593 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9594 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9595 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9596 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9597 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9598 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
9599 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
9600 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
9601 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
9602 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
9603 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
9604 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
9605 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
9606 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
9607 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
9608 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9609 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9610 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9611 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9612 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9613 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
9614 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
9615 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
9616 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
9617 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
9618 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
9619 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
9620 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
9621 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
9622 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
9623 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9624 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9625 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9626 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
9627 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
9628 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
9629 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
9630 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
9631 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
9632 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
9633 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
9634 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
9635 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
9636 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
9637 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
9638 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
9639 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
9640 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
9641 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9642 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9643 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
9644 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
9645 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
9646 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
9647 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
9648 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
9649 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
9650 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
9651 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9654 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
9655 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9656 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9657 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9658 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
9659 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
9660 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9661 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9662 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9663 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9664 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9665 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9666 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9667 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9668 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9669 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9670 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9671 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9672 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9673 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
9674 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
9675 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9676 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9677 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9678 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9679 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9680 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9681 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9682 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
9683 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
9684 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
9685 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9686 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9687 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9688 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9689 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9690 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
9691 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9692 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9693 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9694 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
9695 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9696 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9697 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9698 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9699 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9700 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9701 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9702 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
9703 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9704 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9705 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9706 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9707 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9708 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9709 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
9710 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9711 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9712 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9713 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9714 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9715 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9716 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9717 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9718 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9719 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9720 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9721 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9722 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9723 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9724 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9725 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9726 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9727 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9728 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9729 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9730 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9731 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9732 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9733 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9734 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9735 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9736 [83] = { ALU_OP0_NOP
, tgsi_unsupported
},
9737 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9738 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
9739 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9740 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9741 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9742 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9743 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9744 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9745 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9746 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9747 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9748 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9749 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9750 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9751 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9752 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9753 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9754 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9755 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9756 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9757 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9758 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9759 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9760 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9761 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9762 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9763 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9764 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9765 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9766 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9767 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9768 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9769 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9770 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9771 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9772 /* Refer below for TGSI_OPCODE_DFMA */
9773 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
9774 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9775 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9776 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9777 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9778 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9779 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9780 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9781 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
9782 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
9783 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9784 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9785 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9786 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9787 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9788 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9789 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
9790 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9791 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9792 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9793 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9794 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9795 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9796 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9797 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9798 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9799 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9800 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9801 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9802 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9803 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9804 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9805 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9806 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9807 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9808 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9809 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9810 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9811 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
9812 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9813 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9814 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9815 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
9816 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9817 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9818 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9819 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9820 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9821 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
9822 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
9823 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
9824 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
9825 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
9826 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
9827 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
9828 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
9829 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
9830 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
9831 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9832 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9833 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9834 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
9835 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
9836 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
9837 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
9838 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
9839 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
9840 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
9841 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
9842 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
9843 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
9844 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
9845 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
9846 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9847 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9848 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9849 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
9850 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
9851 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
9852 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
9853 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
9854 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
9855 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
9856 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
9857 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
9858 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
9859 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
9860 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
9861 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
9862 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
9863 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
9864 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9865 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9866 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
9867 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
9868 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
9869 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
9870 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
9871 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
9872 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
9873 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
9874 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},