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
;
198 use_sb
&= !shader
->shader
.uses_images
;
200 /* Check if the bytecode has already been built. */
201 if (!shader
->shader
.bc
.bytecode
) {
202 r
= r600_bytecode_build(&shader
->shader
.bc
);
204 R600_ERR("building bytecode failed !\n");
209 if (dump
&& !sb_disasm
) {
210 fprintf(stderr
, "--------------------------------------------------------------\n");
211 r600_bytecode_disasm(&shader
->shader
.bc
);
212 fprintf(stderr
, "______________________________________________________________\n");
213 } else if ((dump
&& sb_disasm
) || use_sb
) {
214 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
217 R600_ERR("r600_sb_bytecode_process failed !\n");
222 if (shader
->gs_copy_shader
) {
225 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
226 &shader
->gs_copy_shader
->shader
, dump
, 0);
231 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
235 /* Store the shader in a buffer. */
236 if ((r
= store_shader(ctx
, shader
)))
240 switch (shader
->shader
.processor_type
) {
241 case PIPE_SHADER_TESS_CTRL
:
242 evergreen_update_hs_state(ctx
, shader
);
244 case PIPE_SHADER_TESS_EVAL
:
246 evergreen_update_es_state(ctx
, shader
);
248 evergreen_update_vs_state(ctx
, shader
);
250 case PIPE_SHADER_GEOMETRY
:
251 if (rctx
->b
.chip_class
>= EVERGREEN
) {
252 evergreen_update_gs_state(ctx
, shader
);
253 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
255 r600_update_gs_state(ctx
, shader
);
256 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
259 case PIPE_SHADER_VERTEX
:
260 export_shader
= key
.vs
.as_es
;
261 if (rctx
->b
.chip_class
>= EVERGREEN
) {
263 evergreen_update_ls_state(ctx
, shader
);
264 else if (key
.vs
.as_es
)
265 evergreen_update_es_state(ctx
, shader
);
267 evergreen_update_vs_state(ctx
, shader
);
270 r600_update_es_state(ctx
, shader
);
272 r600_update_vs_state(ctx
, shader
);
275 case PIPE_SHADER_FRAGMENT
:
276 if (rctx
->b
.chip_class
>= EVERGREEN
) {
277 evergreen_update_ps_state(ctx
, shader
);
279 r600_update_ps_state(ctx
, shader
);
289 r600_pipe_shader_destroy(ctx
, shader
);
293 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
295 r600_resource_reference(&shader
->bo
, NULL
);
296 r600_bytecode_clear(&shader
->shader
.bc
);
297 r600_release_command_buffer(&shader
->command_buffer
);
301 * tgsi -> r600 shader
303 struct r600_shader_tgsi_instruction
;
305 struct r600_shader_src
{
312 boolean kc_rel
; /* true if cache bank is indexed */
321 struct r600_shader_ctx
{
322 struct tgsi_shader_info info
;
323 struct tgsi_parse_context parse
;
324 const struct tgsi_token
*tokens
;
326 unsigned file_offset
[TGSI_FILE_COUNT
];
328 const struct r600_shader_tgsi_instruction
*inst_info
;
329 struct r600_bytecode
*bc
;
330 struct r600_shader
*shader
;
331 struct r600_shader_src src
[4];
334 uint32_t max_driver_temp_used
;
335 /* needed for evergreen interpolation */
336 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
337 /* evergreen/cayman also store sample mask in face register */
339 /* sample id is .w component stored in fixed point position register */
340 int fixed_pt_position_gpr
;
342 boolean clip_vertex_write
;
344 unsigned edgeflag_output
;
347 int next_ring_offset
;
348 int gs_out_ring_offset
;
350 struct r600_shader
*gs_for_vs
;
351 int gs_export_gpr_tregs
[4];
352 int gs_rotated_input
[2];
353 const struct pipe_stream_output_info
*gs_stream_output_info
;
354 unsigned enabled_stream_buffers_mask
;
355 unsigned tess_input_info
; /* temp with tess input offsets */
356 unsigned tess_output_info
; /* temp with tess input offsets */
357 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
360 struct r600_shader_tgsi_instruction
{
362 int (*process
)(struct r600_shader_ctx
*ctx
);
365 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
366 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
367 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
368 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
369 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
370 static int tgsi_else(struct r600_shader_ctx
*ctx
);
371 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
372 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
373 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
374 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
375 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
376 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
377 unsigned int dst_reg
);
378 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
379 const struct r600_shader_src
*shader_src
,
381 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
382 unsigned dst_reg
, unsigned mask
);
384 static int tgsi_last_instruction(unsigned writemask
)
388 for (i
= 0; i
< 4; i
++) {
389 if (writemask
& (1 << i
)) {
396 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
398 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
401 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
402 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
406 if (i
->Instruction
.Label
) {
407 R600_ERR("label unsupported\n");
411 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
412 if (i
->Src
[j
].Register
.Dimension
) {
413 switch (i
->Src
[j
].Register
.File
) {
414 case TGSI_FILE_CONSTANT
:
415 case TGSI_FILE_HW_ATOMIC
:
417 case TGSI_FILE_INPUT
:
418 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
419 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
420 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
422 case TGSI_FILE_OUTPUT
:
423 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
426 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
427 i
->Src
[j
].Register
.File
,
428 i
->Src
[j
].Register
.Dimension
);
433 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
434 if (i
->Dst
[j
].Register
.Dimension
) {
435 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
437 R600_ERR("unsupported dst (dimension)\n");
444 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
446 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
447 interpolate
== TGSI_INTERPOLATE_LINEAR
||
448 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
450 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
454 case TGSI_INTERPOLATE_LOC_CENTER
:
457 case TGSI_INTERPOLATE_LOC_CENTROID
:
460 case TGSI_INTERPOLATE_LOC_SAMPLE
:
465 return is_linear
* 3 + loc
;
471 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
474 int i
= eg_get_interpolator_index(
475 ctx
->shader
->input
[input
].interpolate
,
476 ctx
->shader
->input
[input
].interpolate_location
);
478 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
481 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
484 struct r600_bytecode_alu alu
;
485 int gpr
= 0, base_chan
= 0;
486 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
488 /* work out gpr and base_chan from index */
490 base_chan
= (2 * (ij_index
% 2)) + 1;
492 for (i
= 0; i
< 8; i
++) {
493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
496 alu
.op
= ALU_OP2_INTERP_ZW
;
498 alu
.op
= ALU_OP2_INTERP_XY
;
500 if ((i
> 1) && (i
< 6)) {
501 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
505 alu
.dst
.chan
= i
% 4;
507 alu
.src
[0].sel
= gpr
;
508 alu
.src
[0].chan
= (base_chan
- (i
% 2));
510 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
512 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
515 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
522 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
525 struct r600_bytecode_alu alu
;
527 for (i
= 0; i
< 4; i
++) {
528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
530 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
532 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
537 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
550 * Special export handling in shaders
552 * shader export ARRAY_BASE for EXPORT_POS:
555 * 62, 63 are clip distance vectors
557 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
558 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
559 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
560 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
561 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
562 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
563 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
564 * exclusive from render target index)
565 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
568 * shader export ARRAY_BASE for EXPORT_PIXEL:
570 * 61 computed Z vector
572 * The use of the values exported in the computed Z vector are controlled
573 * by DB_SHADER_CONTROL:
574 * Z_EXPORT_ENABLE - Z as a float in RED
575 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
576 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
577 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
578 * DB_SOURCE_FORMAT - export control restrictions
583 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
584 static int r600_spi_sid(struct r600_shader_io
* io
)
586 int index
, name
= io
->name
;
588 /* These params are handled differently, they don't need
589 * semantic indices, so we'll use 0 for them.
591 if (name
== TGSI_SEMANTIC_POSITION
||
592 name
== TGSI_SEMANTIC_PSIZE
||
593 name
== TGSI_SEMANTIC_EDGEFLAG
||
594 name
== TGSI_SEMANTIC_FACE
||
595 name
== TGSI_SEMANTIC_SAMPLEMASK
)
598 if (name
== TGSI_SEMANTIC_GENERIC
) {
599 /* For generic params simply use sid from tgsi */
602 /* For non-generic params - pack name and sid into 8 bits */
603 index
= 0x80 | (name
<<3) | (io
->sid
);
606 /* Make sure that all really used indices have nonzero value, so
607 * we can just compare it to 0 later instead of comparing the name
608 * with different values to detect special cases. */
615 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
616 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
618 switch (semantic_name
) {
619 case TGSI_SEMANTIC_POSITION
:
621 case TGSI_SEMANTIC_PSIZE
:
623 case TGSI_SEMANTIC_CLIPDIST
:
626 case TGSI_SEMANTIC_GENERIC
:
628 return 4 + index
- 9;
630 /* same explanation as in the default statement,
631 * the only user hitting this is st/nine.
635 /* patch indices are completely separate and thus start from 0 */
636 case TGSI_SEMANTIC_TESSOUTER
:
638 case TGSI_SEMANTIC_TESSINNER
:
640 case TGSI_SEMANTIC_PATCH
:
644 /* Don't fail here. The result of this function is only used
645 * for LS, TCS, TES, and GS, where legacy GL semantics can't
646 * occur, but this function is called for all vertex shaders
647 * before it's known whether LS will be compiled or not.
653 /* turn input into interpolate on EG */
654 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
658 if (ctx
->shader
->input
[index
].spi_sid
) {
659 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
660 if (ctx
->shader
->input
[index
].interpolate
> 0) {
661 evergreen_interp_assign_ij_index(ctx
, index
);
662 r
= evergreen_interp_alu(ctx
, index
);
664 r
= evergreen_interp_flat(ctx
, index
);
670 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
672 struct r600_bytecode_alu alu
;
674 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
675 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
677 for (i
= 0; i
< 4; i
++) {
678 memset(&alu
, 0, sizeof(alu
));
679 alu
.op
= ALU_OP3_CNDGT
;
682 alu
.dst
.sel
= gpr_front
;
683 alu
.src
[0].sel
= ctx
->face_gpr
;
684 alu
.src
[1].sel
= gpr_front
;
685 alu
.src
[2].sel
= gpr_back
;
692 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
699 /* execute a single slot ALU calculation */
700 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
701 int dst_sel
, int dst_chan
,
702 int src0_sel
, unsigned src0_chan_val
,
703 int src1_sel
, unsigned src1_chan_val
)
705 struct r600_bytecode_alu alu
;
708 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
709 for (i
= 0; i
< 4; i
++) {
710 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
712 alu
.src
[0].sel
= src0_sel
;
713 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
714 alu
.src
[0].value
= src0_chan_val
;
716 alu
.src
[0].chan
= src0_chan_val
;
717 alu
.src
[1].sel
= src1_sel
;
718 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
719 alu
.src
[1].value
= src1_chan_val
;
721 alu
.src
[1].chan
= src1_chan_val
;
722 alu
.dst
.sel
= dst_sel
;
724 alu
.dst
.write
= i
== dst_chan
;
726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
733 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
735 alu
.src
[0].sel
= src0_sel
;
736 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
737 alu
.src
[0].value
= src0_chan_val
;
739 alu
.src
[0].chan
= src0_chan_val
;
740 alu
.src
[1].sel
= src1_sel
;
741 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
742 alu
.src
[1].value
= src1_chan_val
;
744 alu
.src
[1].chan
= src1_chan_val
;
745 alu
.dst
.sel
= dst_sel
;
746 alu
.dst
.chan
= dst_chan
;
749 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
755 /* execute a single slot ALU calculation */
756 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
757 int dst_sel
, int dst_chan
,
758 int src0_sel
, unsigned src0_chan_val
,
759 int src1_sel
, unsigned src1_chan_val
,
760 int src2_sel
, unsigned src2_chan_val
)
762 struct r600_bytecode_alu alu
;
765 /* validate this for other ops */
766 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
);
767 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
769 alu
.src
[0].sel
= src0_sel
;
770 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
771 alu
.src
[0].value
= src0_chan_val
;
773 alu
.src
[0].chan
= src0_chan_val
;
774 alu
.src
[1].sel
= src1_sel
;
775 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
776 alu
.src
[1].value
= src1_chan_val
;
778 alu
.src
[1].chan
= src1_chan_val
;
779 alu
.src
[2].sel
= src2_sel
;
780 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
781 alu
.src
[2].value
= src2_chan_val
;
783 alu
.src
[2].chan
= src2_chan_val
;
784 alu
.dst
.sel
= dst_sel
;
785 alu
.dst
.chan
= dst_chan
;
788 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
794 /* put it in temp_reg.x */
795 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
797 int temp_reg
, bool is_patch_var
)
801 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
803 Dimension - patch0_offset (input_vals.z),
804 Non-dim - patch0_data_offset (input_vals.w)
806 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
808 ctx
->tess_output_info
, 0,
810 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
816 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
818 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
821 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
823 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
826 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
829 i
= ctx
->shader
->noutput
++;
830 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
831 ctx
->shader
->output
[i
].sid
= 0;
832 ctx
->shader
->output
[i
].gpr
= 0;
833 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
834 ctx
->shader
->output
[i
].write_mask
= 0x4;
835 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
840 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
842 struct r600_bytecode_alu alu
;
845 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
846 alu
.op
= ctx
->inst_info
->op
;
849 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
855 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
857 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
858 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
860 switch (d
->Declaration
.File
) {
861 case TGSI_FILE_INPUT
:
862 for (j
= 0; j
< count
; j
++) {
863 i
= ctx
->shader
->ninput
+ j
;
864 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
865 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
866 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
867 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
868 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
869 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
870 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
871 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
872 switch (ctx
->shader
->input
[i
].name
) {
873 case TGSI_SEMANTIC_FACE
:
874 if (ctx
->face_gpr
!= -1)
875 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
877 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
879 case TGSI_SEMANTIC_COLOR
:
882 case TGSI_SEMANTIC_POSITION
:
883 ctx
->fragcoord_input
= i
;
885 case TGSI_SEMANTIC_PRIMID
:
886 /* set this for now */
887 ctx
->shader
->gs_prim_id_input
= true;
888 ctx
->shader
->ps_prim_id_input
= i
;
891 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
892 if ((r
= evergreen_interp_input(ctx
, i
)))
895 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
896 /* FIXME probably skip inputs if they aren't passed in the ring */
897 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
898 ctx
->next_ring_offset
+= 16;
899 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
900 ctx
->shader
->gs_prim_id_input
= true;
903 ctx
->shader
->ninput
+= count
;
905 case TGSI_FILE_OUTPUT
:
906 for (j
= 0; j
< count
; j
++) {
907 i
= ctx
->shader
->noutput
+ j
;
908 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
909 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
910 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
911 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
912 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
913 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
914 if (ctx
->type
== PIPE_SHADER_VERTEX
||
915 ctx
->type
== PIPE_SHADER_GEOMETRY
||
916 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
917 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
918 switch (d
->Semantic
.Name
) {
919 case TGSI_SEMANTIC_CLIPDIST
:
921 case TGSI_SEMANTIC_PSIZE
:
922 ctx
->shader
->vs_out_misc_write
= 1;
923 ctx
->shader
->vs_out_point_size
= 1;
925 case TGSI_SEMANTIC_EDGEFLAG
:
926 ctx
->shader
->vs_out_misc_write
= 1;
927 ctx
->shader
->vs_out_edgeflag
= 1;
928 ctx
->edgeflag_output
= i
;
930 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
931 ctx
->shader
->vs_out_misc_write
= 1;
932 ctx
->shader
->vs_out_viewport
= 1;
934 case TGSI_SEMANTIC_LAYER
:
935 ctx
->shader
->vs_out_misc_write
= 1;
936 ctx
->shader
->vs_out_layer
= 1;
938 case TGSI_SEMANTIC_CLIPVERTEX
:
939 ctx
->clip_vertex_write
= TRUE
;
943 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
944 ctx
->gs_out_ring_offset
+= 16;
946 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
947 switch (d
->Semantic
.Name
) {
948 case TGSI_SEMANTIC_COLOR
:
949 ctx
->shader
->nr_ps_max_color_exports
++;
954 ctx
->shader
->noutput
+= count
;
956 case TGSI_FILE_TEMPORARY
:
957 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
958 if (d
->Array
.ArrayID
) {
959 r600_add_gpr_array(ctx
->shader
,
960 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
962 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
967 case TGSI_FILE_CONSTANT
:
968 case TGSI_FILE_SAMPLER
:
969 case TGSI_FILE_SAMPLER_VIEW
:
970 case TGSI_FILE_ADDRESS
:
971 case TGSI_FILE_IMAGE
:
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
, 0xf);
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 */
1101 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1105 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1106 while (!tgsi_parse_end_of_tokens(&parse
)) {
1107 tgsi_parse_token(&parse
);
1109 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1110 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1111 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1112 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1113 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1115 int interpolate
, location
, k
;
1117 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1118 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1119 inputs
[1].enabled
= true; /* needs SAMPLEID */
1120 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1121 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1122 /* Needs sample positions, currently those are always available */
1124 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1127 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1128 k
= eg_get_interpolator_index(interpolate
, location
);
1130 ctx
->eg_interpolators
[k
].enabled
= true;
1132 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1133 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1134 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1135 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1136 if (d
->Semantic
.Name
== inputs
[k
].name
||
1137 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1138 inputs
[k
].enabled
= true;
1145 tgsi_parse_free(&parse
);
1147 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1148 boolean enabled
= inputs
[i
].enabled
;
1149 int *reg
= inputs
[i
].reg
;
1150 unsigned name
= inputs
[i
].name
;
1153 int gpr
= gpr_offset
+ num_regs
++;
1154 ctx
->shader
->nsys_inputs
++;
1156 // add to inputs, allocate a gpr
1157 k
= ctx
->shader
->ninput
++;
1158 ctx
->shader
->input
[k
].name
= name
;
1159 ctx
->shader
->input
[k
].sid
= 0;
1160 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1161 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1162 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1166 return gpr_offset
+ num_regs
;
1170 * for evergreen we need to scan the shader to find the number of GPRs we need to
1171 * reserve for interpolation and system values
1173 * we need to know if we are going to emit
1174 * any sample or centroid inputs
1175 * if perspective and linear are required
1177 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1181 struct tgsi_parse_context parse
;
1183 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1185 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1187 /* skip position/face/mask/sampleid */
1188 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1189 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1190 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1191 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1194 k
= eg_get_interpolator_index(
1195 ctx
->info
.input_interpolate
[i
],
1196 ctx
->info
.input_interpolate_loc
[i
]);
1198 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1201 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1205 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1206 while (!tgsi_parse_end_of_tokens(&parse
)) {
1207 tgsi_parse_token(&parse
);
1209 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1210 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1211 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1212 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1213 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1215 int interpolate
, location
, k
;
1217 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1218 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1219 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1220 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1222 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1225 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1226 k
= eg_get_interpolator_index(interpolate
, location
);
1228 ctx
->eg_interpolators
[k
].enabled
= true;
1233 tgsi_parse_free(&parse
);
1235 /* assign gpr to each interpolator according to priority */
1237 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1238 if (ctx
->eg_interpolators
[i
].enabled
) {
1239 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1244 /* XXX PULL MODEL and LINE STIPPLE */
1246 num_baryc
= (num_baryc
+ 1) >> 1;
1247 return allocate_system_value_inputs(ctx
, num_baryc
);
1250 /* sample_id_sel == NULL means fetch for current sample */
1251 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1253 struct r600_bytecode_vtx vtx
;
1256 assert(ctx
->fixed_pt_position_gpr
!= -1);
1258 t1
= r600_get_temp(ctx
);
1260 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1261 vtx
.op
= FETCH_OP_VFETCH
;
1262 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1263 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1264 if (sample_id
== NULL
) {
1265 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1269 struct r600_bytecode_alu alu
;
1271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1272 alu
.op
= ALU_OP1_MOV
;
1273 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1277 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1284 vtx
.mega_fetch_count
= 16;
1290 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1291 vtx
.num_format_all
= 2;
1292 vtx
.format_comp_all
= 1;
1293 vtx
.use_const_fields
= 0;
1294 vtx
.offset
= 1; // first element is size of buffer
1295 vtx
.endian
= r600_endian_swap(32);
1296 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1298 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1305 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1306 const struct tgsi_full_src_register
*tgsi_src
,
1307 struct r600_shader_src
*r600_src
)
1309 memset(r600_src
, 0, sizeof(*r600_src
));
1310 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1311 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1312 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1313 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1314 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1315 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1317 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1319 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1320 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1321 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1323 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1324 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1325 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1328 index
= tgsi_src
->Register
.Index
;
1329 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1330 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1331 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1332 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1333 r600_src
->swizzle
[0] = 2; // Z value
1334 r600_src
->swizzle
[1] = 2;
1335 r600_src
->swizzle
[2] = 2;
1336 r600_src
->swizzle
[3] = 2;
1337 r600_src
->sel
= ctx
->face_gpr
;
1338 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1339 r600_src
->swizzle
[0] = 3; // W value
1340 r600_src
->swizzle
[1] = 3;
1341 r600_src
->swizzle
[2] = 3;
1342 r600_src
->swizzle
[3] = 3;
1343 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1344 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1345 r600_src
->swizzle
[0] = 0;
1346 r600_src
->swizzle
[1] = 1;
1347 r600_src
->swizzle
[2] = 4;
1348 r600_src
->swizzle
[3] = 4;
1349 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1350 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1351 r600_src
->swizzle
[0] = 3;
1352 r600_src
->swizzle
[1] = 3;
1353 r600_src
->swizzle
[2] = 3;
1354 r600_src
->swizzle
[3] = 3;
1356 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1357 r600_src
->swizzle
[0] = 0;
1358 r600_src
->swizzle
[1] = 0;
1359 r600_src
->swizzle
[2] = 0;
1360 r600_src
->swizzle
[3] = 0;
1362 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1363 r600_src
->swizzle
[0] = 3;
1364 r600_src
->swizzle
[1] = 3;
1365 r600_src
->swizzle
[2] = 3;
1366 r600_src
->swizzle
[3] = 3;
1368 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1369 r600_src
->swizzle
[0] = 2;
1370 r600_src
->swizzle
[1] = 2;
1371 r600_src
->swizzle
[2] = 2;
1372 r600_src
->swizzle
[3] = 2;
1374 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1376 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1378 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1380 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1381 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1382 r600_src
->sel
= ctx
->tess_input_info
;
1383 r600_src
->swizzle
[0] = 2;
1384 r600_src
->swizzle
[1] = 2;
1385 r600_src
->swizzle
[2] = 2;
1386 r600_src
->swizzle
[3] = 2;
1388 r600_src
->sel
= ctx
->tess_input_info
;
1389 r600_src
->swizzle
[0] = 3;
1390 r600_src
->swizzle
[1] = 3;
1391 r600_src
->swizzle
[2] = 3;
1392 r600_src
->swizzle
[3] = 3;
1394 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1396 r600_src
->swizzle
[0] = 0;
1397 r600_src
->swizzle
[1] = 0;
1398 r600_src
->swizzle
[2] = 0;
1399 r600_src
->swizzle
[3] = 0;
1400 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1402 r600_src
->swizzle
[0] = 3;
1403 r600_src
->swizzle
[1] = 3;
1404 r600_src
->swizzle
[2] = 3;
1405 r600_src
->swizzle
[3] = 3;
1408 if (tgsi_src
->Register
.Indirect
)
1409 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1410 r600_src
->sel
= tgsi_src
->Register
.Index
;
1411 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1413 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1414 if (tgsi_src
->Register
.Dimension
) {
1415 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1416 if (tgsi_src
->Dimension
.Indirect
) {
1417 r600_src
->kc_rel
= 1;
1423 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1424 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1425 unsigned int dst_reg
)
1427 struct r600_bytecode_vtx vtx
;
1428 unsigned int ar_reg
;
1432 struct r600_bytecode_alu alu
;
1434 memset(&alu
, 0, sizeof(alu
));
1436 alu
.op
= ALU_OP2_ADD_INT
;
1437 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1438 alu
.src
[0].chan
= ar_chan
;
1440 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1441 alu
.src
[1].value
= offset
;
1443 alu
.dst
.sel
= dst_reg
;
1444 alu
.dst
.chan
= ar_chan
;
1448 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1453 ar_reg
= ctx
->bc
->ar_reg
;
1456 memset(&vtx
, 0, sizeof(vtx
));
1457 vtx
.buffer_id
= cb_idx
;
1458 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1459 vtx
.src_gpr
= ar_reg
;
1460 vtx
.src_sel_x
= ar_chan
;
1461 vtx
.mega_fetch_count
= 16;
1462 vtx
.dst_gpr
= dst_reg
;
1463 vtx
.dst_sel_x
= 0; /* SEL_X */
1464 vtx
.dst_sel_y
= 1; /* SEL_Y */
1465 vtx
.dst_sel_z
= 2; /* SEL_Z */
1466 vtx
.dst_sel_w
= 3; /* SEL_W */
1467 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1468 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1469 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1470 vtx
.endian
= r600_endian_swap(32);
1471 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1473 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1479 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1481 struct r600_bytecode_vtx vtx
;
1483 unsigned index
= src
->Register
.Index
;
1484 unsigned vtx_id
= src
->Dimension
.Index
;
1485 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1486 int offset_chan
= vtx_id
% 3;
1489 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1490 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1492 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1495 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1496 t2
= r600_get_temp(ctx
);
1498 if (src
->Dimension
.Indirect
) {
1500 struct r600_bytecode_alu alu
;
1503 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1504 if (src
->DimIndirect
.Index
> 0) {
1505 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1513 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1514 at least this is what fglrx seems to do. */
1515 for (i
= 0; i
< 3; i
++) {
1516 treg
[i
] = r600_get_temp(ctx
);
1518 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1520 for (i
= 0; i
< 3; i
++) {
1521 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1522 alu
.op
= ALU_OP1_MOV
;
1523 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1524 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1525 alu
.dst
.sel
= treg
[i
];
1529 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1533 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1534 alu
.op
= ALU_OP1_MOV
;
1535 alu
.src
[0].sel
= treg
[0];
1540 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1547 if (src
->Register
.Indirect
) {
1549 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1551 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1553 /* pull the value from index_reg */
1554 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1557 V_SQ_ALU_SRC_LITERAL
, first
);
1560 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1563 V_SQ_ALU_SRC_LITERAL
, 4,
1564 offset_reg
, offset_chan
);
1569 index
= src
->Register
.Index
- first
;
1572 memset(&vtx
, 0, sizeof(vtx
));
1573 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1574 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1575 vtx
.src_gpr
= offset_reg
;
1576 vtx
.src_sel_x
= offset_chan
;
1577 vtx
.offset
= index
* 16; /*bytes*/
1578 vtx
.mega_fetch_count
= 16;
1579 vtx
.dst_gpr
= dst_reg
;
1580 vtx
.dst_sel_x
= 0; /* SEL_X */
1581 vtx
.dst_sel_y
= 1; /* SEL_Y */
1582 vtx
.dst_sel_z
= 2; /* SEL_Z */
1583 vtx
.dst_sel_w
= 3; /* SEL_W */
1584 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1585 vtx
.use_const_fields
= 1;
1587 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1590 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1596 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1598 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1601 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1602 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1604 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1605 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1606 /* primitive id is in R0.z */
1607 ctx
->src
[i
].sel
= 0;
1608 ctx
->src
[i
].swizzle
[0] = 2;
1611 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1612 int treg
= r600_get_temp(ctx
);
1614 fetch_gs_input(ctx
, src
, treg
);
1615 ctx
->src
[i
].sel
= treg
;
1616 ctx
->src
[i
].rel
= 0;
1623 /* Tessellation shaders pass outputs to the next shader using LDS.
1625 * LS outputs = TCS(HS) inputs
1626 * TCS(HS) outputs = TES(DS) inputs
1628 * The LDS layout is:
1629 * - TCS inputs for patch 0
1630 * - TCS inputs for patch 1
1631 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1633 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1634 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1635 * - TCS outputs for patch 1
1636 * - Per-patch TCS outputs for patch 1
1637 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1638 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1641 * All three shaders VS(LS), TCS, TES share the same LDS space.
1643 /* this will return with the dw address in temp_reg.x */
1644 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1645 const struct tgsi_full_dst_register
*dst
,
1646 const struct tgsi_full_src_register
*src
,
1647 int stride_bytes_reg
, int stride_bytes_chan
)
1649 struct tgsi_full_dst_register reg
;
1650 ubyte
*name
, *index
, *array_first
;
1653 struct tgsi_shader_info
*info
= &ctx
->info
;
1654 /* Set the register description. The address computation is the same
1655 * for sources and destinations. */
1657 reg
.Register
.File
= src
->Register
.File
;
1658 reg
.Register
.Index
= src
->Register
.Index
;
1659 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1660 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1661 reg
.Indirect
= src
->Indirect
;
1662 reg
.Dimension
= src
->Dimension
;
1663 reg
.DimIndirect
= src
->DimIndirect
;
1667 /* If the register is 2-dimensional (e.g. an array of vertices
1668 * in a primitive), calculate the base address of the vertex. */
1669 if (reg
.Register
.Dimension
) {
1671 if (reg
.Dimension
.Indirect
) {
1673 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1675 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1676 /* pull the value from index_reg */
1680 sel
= V_SQ_ALU_SRC_LITERAL
;
1681 chan
= reg
.Dimension
.Index
;
1684 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1686 stride_bytes_reg
, stride_bytes_chan
,
1693 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1694 name
= info
->input_semantic_name
;
1695 index
= info
->input_semantic_index
;
1696 array_first
= info
->input_array_first
;
1697 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1698 name
= info
->output_semantic_name
;
1699 index
= info
->output_semantic_index
;
1700 array_first
= info
->output_array_first
;
1705 if (reg
.Register
.Indirect
) {
1708 /* Add the relative address of the element. */
1709 if (reg
.Indirect
.ArrayID
)
1710 first
= array_first
[reg
.Indirect
.ArrayID
];
1712 first
= reg
.Register
.Index
;
1714 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1716 /* pull the value from index_reg */
1717 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1719 V_SQ_ALU_SRC_LITERAL
, 16,
1725 param
= r600_get_lds_unique_index(name
[first
],
1729 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1730 index
[reg
.Register
.Index
]);
1733 /* add to base_addr - passed in temp_reg.x */
1735 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1738 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1746 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1747 unsigned dst_reg
, unsigned mask
)
1749 struct r600_bytecode_alu alu
;
1752 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1753 ctx
->bc
->force_add_cf
= 1;
1755 for (i
= 1; i
< 4; i
++) {
1756 if (!(mask
& (1 << i
)))
1759 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1762 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1766 for (i
= 0; i
< 4; i
++) {
1767 if (! (mask
& (1 << i
)))
1770 /* emit an LDS_READ_RET */
1771 memset(&alu
, 0, sizeof(alu
));
1772 alu
.op
= LDS_OP1_LDS_READ_RET
;
1773 alu
.src
[0].sel
= temp_reg
;
1774 alu
.src
[0].chan
= i
;
1775 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1776 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1778 alu
.is_lds_idx_op
= true;
1780 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1784 for (i
= 0; i
< 4; i
++) {
1785 if (! (mask
& (1 << i
)))
1787 /* then read from LDS_OQ_A_POP */
1788 memset(&alu
, 0, sizeof(alu
));
1790 alu
.op
= ALU_OP1_MOV
;
1791 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1792 alu
.src
[0].chan
= 0;
1793 alu
.dst
.sel
= dst_reg
;
1797 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1804 static int fetch_mask(struct tgsi_src_register
*reg
)
1807 mask
|= 1 << reg
->SwizzleX
;
1808 mask
|= 1 << reg
->SwizzleY
;
1809 mask
|= 1 << reg
->SwizzleZ
;
1810 mask
|= 1 << reg
->SwizzleW
;
1814 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1817 unsigned temp_reg
= r600_get_temp(ctx
);
1819 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1820 src
->Register
.Dimension
? false : true);
1824 /* the base address is now in temp.x */
1825 r
= r600_get_byte_address(ctx
, temp_reg
,
1826 NULL
, src
, ctx
->tess_output_info
, 1);
1830 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1836 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1839 unsigned temp_reg
= r600_get_temp(ctx
);
1841 /* t.x = ips * r0.y */
1842 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1844 ctx
->tess_input_info
, 0,
1850 /* the base address is now in temp.x */
1851 r
= r600_get_byte_address(ctx
, temp_reg
,
1852 NULL
, src
, ctx
->tess_input_info
, 1);
1856 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1862 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1865 unsigned temp_reg
= r600_get_temp(ctx
);
1867 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1868 src
->Register
.Dimension
? false : true);
1871 /* the base address is now in temp.x */
1872 r
= r600_get_byte_address(ctx
, temp_reg
,
1874 ctx
->tess_output_info
, 1);
1878 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1884 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1886 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1889 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1890 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1892 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1893 int treg
= r600_get_temp(ctx
);
1894 fetch_tes_input(ctx
, src
, treg
);
1895 ctx
->src
[i
].sel
= treg
;
1896 ctx
->src
[i
].rel
= 0;
1898 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1899 int treg
= r600_get_temp(ctx
);
1900 fetch_tcs_input(ctx
, src
, treg
);
1901 ctx
->src
[i
].sel
= treg
;
1902 ctx
->src
[i
].rel
= 0;
1904 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1905 int treg
= r600_get_temp(ctx
);
1906 fetch_tcs_output(ctx
, src
, treg
);
1907 ctx
->src
[i
].sel
= treg
;
1908 ctx
->src
[i
].rel
= 0;
1914 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1916 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1917 struct r600_bytecode_alu alu
;
1918 int i
, j
, k
, nconst
, r
;
1920 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1921 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1924 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1926 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1927 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1931 if (ctx
->src
[i
].rel
) {
1932 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1933 int treg
= r600_get_temp(ctx
);
1934 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1937 ctx
->src
[i
].kc_bank
= 0;
1938 ctx
->src
[i
].kc_rel
= 0;
1939 ctx
->src
[i
].sel
= treg
;
1940 ctx
->src
[i
].rel
= 0;
1943 int treg
= r600_get_temp(ctx
);
1944 for (k
= 0; k
< 4; k
++) {
1945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1946 alu
.op
= ALU_OP1_MOV
;
1947 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1948 alu
.src
[0].chan
= k
;
1949 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1950 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1951 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1957 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1961 ctx
->src
[i
].sel
= treg
;
1969 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1970 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1972 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1973 struct r600_bytecode_alu alu
;
1974 int i
, j
, k
, nliteral
, r
;
1976 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1977 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1981 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1982 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1983 int treg
= r600_get_temp(ctx
);
1984 for (k
= 0; k
< 4; k
++) {
1985 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1986 alu
.op
= ALU_OP1_MOV
;
1987 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1988 alu
.src
[0].chan
= k
;
1989 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1995 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1999 ctx
->src
[i
].sel
= treg
;
2006 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2008 int i
, r
, count
= ctx
->shader
->ninput
;
2010 for (i
= 0; i
< count
; i
++) {
2011 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2012 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2020 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2021 int stream
, unsigned *stream_item_size UNUSED
)
2023 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2024 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2028 /* Sanity checking. */
2029 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2030 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2034 for (i
= 0; i
< so
->num_outputs
; i
++) {
2035 if (so
->output
[i
].output_buffer
>= 4) {
2036 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2037 so
->output
[i
].output_buffer
);
2043 /* Initialize locations where the outputs are stored. */
2044 for (i
= 0; i
< so
->num_outputs
; i
++) {
2046 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2047 start_comp
[i
] = so
->output
[i
].start_component
;
2048 /* Lower outputs with dst_offset < start_component.
2050 * We can only output 4D vectors with a write mask, e.g. we can
2051 * only output the W component at offset 3, etc. If we want
2052 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2053 * to move it to X and output X. */
2054 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2055 unsigned tmp
= r600_get_temp(ctx
);
2057 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2058 struct r600_bytecode_alu alu
;
2059 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2060 alu
.op
= ALU_OP1_MOV
;
2061 alu
.src
[0].sel
= so_gpr
[i
];
2062 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2067 if (j
== so
->output
[i
].num_components
- 1)
2069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2078 /* Write outputs to buffers. */
2079 for (i
= 0; i
< so
->num_outputs
; i
++) {
2080 struct r600_bytecode_output output
;
2082 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2085 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2086 output
.gpr
= so_gpr
[i
];
2087 output
.elem_size
= so
->output
[i
].num_components
- 1;
2088 if (output
.elem_size
== 2)
2089 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2090 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2091 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2092 output
.burst_count
= 1;
2093 /* array_size is an upper limit for the burst_count
2094 * with MEM_STREAM instructions */
2095 output
.array_size
= 0xFFF;
2096 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2098 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2099 switch (so
->output
[i
].output_buffer
) {
2101 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2104 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2107 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2110 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2113 output
.op
+= so
->output
[i
].stream
* 4;
2114 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2115 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2117 switch (so
->output
[i
].output_buffer
) {
2119 output
.op
= CF_OP_MEM_STREAM0
;
2122 output
.op
= CF_OP_MEM_STREAM1
;
2125 output
.op
= CF_OP_MEM_STREAM2
;
2128 output
.op
= CF_OP_MEM_STREAM3
;
2131 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2133 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2142 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2144 struct r600_bytecode_alu alu
;
2147 if (!ctx
->shader
->vs_out_edgeflag
)
2150 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2152 /* clamp(x, 0, 1) */
2153 memset(&alu
, 0, sizeof(alu
));
2154 alu
.op
= ALU_OP1_MOV
;
2155 alu
.src
[0].sel
= reg
;
2160 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2162 memset(&alu
, 0, sizeof(alu
));
2163 alu
.op
= ALU_OP1_FLT_TO_INT
;
2164 alu
.src
[0].sel
= reg
;
2168 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2171 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2172 struct r600_pipe_shader
*gs
,
2173 struct pipe_stream_output_info
*so
)
2175 struct r600_shader_ctx ctx
= {};
2176 struct r600_shader
*gs_shader
= &gs
->shader
;
2177 struct r600_pipe_shader
*cshader
;
2178 unsigned ocnt
= gs_shader
->noutput
;
2179 struct r600_bytecode_alu alu
;
2180 struct r600_bytecode_vtx vtx
;
2181 struct r600_bytecode_output output
;
2182 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2183 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2184 int next_clip_pos
= 61, next_param
= 0;
2187 bool only_ring_0
= true;
2188 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2192 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2193 sizeof(struct r600_shader_io
));
2195 cshader
->shader
.noutput
= ocnt
;
2197 ctx
.shader
= &cshader
->shader
;
2198 ctx
.bc
= &ctx
.shader
->bc
;
2199 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2201 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2202 rctx
->screen
->has_compressed_msaa_texturing
);
2204 ctx
.bc
->isa
= rctx
->isa
;
2207 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2209 /* R0.x = R0.x & 0x3fffffff */
2210 memset(&alu
, 0, sizeof(alu
));
2211 alu
.op
= ALU_OP2_AND_INT
;
2212 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2213 alu
.src
[1].value
= 0x3fffffff;
2215 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2217 /* R0.y = R0.x >> 30 */
2218 memset(&alu
, 0, sizeof(alu
));
2219 alu
.op
= ALU_OP2_LSHR_INT
;
2220 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2221 alu
.src
[1].value
= 0x1e;
2225 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2227 /* fetch vertex data from GSVS ring */
2228 for (i
= 0; i
< ocnt
; ++i
) {
2229 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2232 out
->ring_offset
= i
* 16;
2234 memset(&vtx
, 0, sizeof(vtx
));
2235 vtx
.op
= FETCH_OP_VFETCH
;
2236 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2237 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2238 vtx
.mega_fetch_count
= 16;
2239 vtx
.offset
= out
->ring_offset
;
2240 vtx
.dst_gpr
= out
->gpr
;
2246 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2247 vtx
.use_const_fields
= 1;
2249 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2252 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2254 ctx
.temp_reg
= i
+ 1;
2255 for (ring
= 3; ring
>= 0; --ring
) {
2256 bool enabled
= false;
2257 for (i
= 0; i
< so
->num_outputs
; i
++) {
2258 if (so
->output
[i
].stream
== ring
) {
2261 only_ring_0
= false;
2265 if (ring
!= 0 && !enabled
) {
2266 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2271 // Patch up jump label
2272 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2273 cf_pop
= ctx
.bc
->cf_last
;
2275 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2276 cf_jump
->pop_count
= 1;
2277 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2278 cf_pop
->pop_count
= 1;
2281 /* PRED_SETE_INT __, R0.y, ring */
2282 memset(&alu
, 0, sizeof(alu
));
2283 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2284 alu
.src
[0].chan
= 1;
2285 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2286 alu
.src
[1].value
= ring
;
2287 alu
.execute_mask
= 1;
2288 alu
.update_pred
= 1;
2290 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2292 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2293 cf_jump
= ctx
.bc
->cf_last
;
2296 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2297 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2300 /* bc adds nops - copy it */
2301 if (ctx
.bc
->chip_class
== R600
) {
2302 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2303 alu
.op
= ALU_OP0_NOP
;
2305 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2307 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2310 /* export vertex data */
2311 /* XXX factor out common code with r600_shader_from_tgsi ? */
2312 for (i
= 0; i
< ocnt
; ++i
) {
2313 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2314 bool instream0
= true;
2315 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2318 for (j
= 0; j
< so
->num_outputs
; j
++) {
2319 if (so
->output
[j
].register_index
== i
) {
2320 if (so
->output
[j
].stream
== 0)
2322 if (so
->output
[j
].stream
> 0)
2328 memset(&output
, 0, sizeof(output
));
2329 output
.gpr
= out
->gpr
;
2330 output
.elem_size
= 3;
2331 output
.swizzle_x
= 0;
2332 output
.swizzle_y
= 1;
2333 output
.swizzle_z
= 2;
2334 output
.swizzle_w
= 3;
2335 output
.burst_count
= 1;
2336 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2337 output
.op
= CF_OP_EXPORT
;
2338 switch (out
->name
) {
2339 case TGSI_SEMANTIC_POSITION
:
2340 output
.array_base
= 60;
2341 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2344 case TGSI_SEMANTIC_PSIZE
:
2345 output
.array_base
= 61;
2346 if (next_clip_pos
== 61)
2348 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2349 output
.swizzle_y
= 7;
2350 output
.swizzle_z
= 7;
2351 output
.swizzle_w
= 7;
2352 ctx
.shader
->vs_out_misc_write
= 1;
2353 ctx
.shader
->vs_out_point_size
= 1;
2355 case TGSI_SEMANTIC_LAYER
:
2357 /* duplicate it as PARAM to pass to the pixel shader */
2358 output
.array_base
= next_param
++;
2359 r600_bytecode_add_output(ctx
.bc
, &output
);
2360 last_exp_param
= ctx
.bc
->cf_last
;
2362 output
.array_base
= 61;
2363 if (next_clip_pos
== 61)
2365 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2366 output
.swizzle_x
= 7;
2367 output
.swizzle_y
= 7;
2368 output
.swizzle_z
= 0;
2369 output
.swizzle_w
= 7;
2370 ctx
.shader
->vs_out_misc_write
= 1;
2371 ctx
.shader
->vs_out_layer
= 1;
2373 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2375 /* duplicate it as PARAM to pass to the pixel shader */
2376 output
.array_base
= next_param
++;
2377 r600_bytecode_add_output(ctx
.bc
, &output
);
2378 last_exp_param
= ctx
.bc
->cf_last
;
2380 output
.array_base
= 61;
2381 if (next_clip_pos
== 61)
2383 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2384 ctx
.shader
->vs_out_misc_write
= 1;
2385 ctx
.shader
->vs_out_viewport
= 1;
2386 output
.swizzle_x
= 7;
2387 output
.swizzle_y
= 7;
2388 output
.swizzle_z
= 7;
2389 output
.swizzle_w
= 0;
2391 case TGSI_SEMANTIC_CLIPDIST
:
2392 /* spi_sid is 0 for clipdistance outputs that were generated
2393 * for clipvertex - we don't need to pass them to PS */
2394 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2395 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2396 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2398 /* duplicate it as PARAM to pass to the pixel shader */
2399 output
.array_base
= next_param
++;
2400 r600_bytecode_add_output(ctx
.bc
, &output
);
2401 last_exp_param
= ctx
.bc
->cf_last
;
2403 output
.array_base
= next_clip_pos
++;
2404 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2406 case TGSI_SEMANTIC_FOG
:
2407 output
.swizzle_y
= 4; /* 0 */
2408 output
.swizzle_z
= 4; /* 0 */
2409 output
.swizzle_w
= 5; /* 1 */
2412 output
.array_base
= next_param
++;
2415 r600_bytecode_add_output(ctx
.bc
, &output
);
2416 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2417 last_exp_param
= ctx
.bc
->cf_last
;
2419 last_exp_pos
= ctx
.bc
->cf_last
;
2422 if (!last_exp_pos
) {
2423 memset(&output
, 0, sizeof(output
));
2425 output
.elem_size
= 3;
2426 output
.swizzle_x
= 7;
2427 output
.swizzle_y
= 7;
2428 output
.swizzle_z
= 7;
2429 output
.swizzle_w
= 7;
2430 output
.burst_count
= 1;
2432 output
.op
= CF_OP_EXPORT
;
2433 output
.array_base
= 60;
2434 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2435 r600_bytecode_add_output(ctx
.bc
, &output
);
2436 last_exp_pos
= ctx
.bc
->cf_last
;
2439 if (!last_exp_param
) {
2440 memset(&output
, 0, sizeof(output
));
2442 output
.elem_size
= 3;
2443 output
.swizzle_x
= 7;
2444 output
.swizzle_y
= 7;
2445 output
.swizzle_z
= 7;
2446 output
.swizzle_w
= 7;
2447 output
.burst_count
= 1;
2449 output
.op
= CF_OP_EXPORT
;
2450 output
.array_base
= next_param
++;
2451 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2452 r600_bytecode_add_output(ctx
.bc
, &output
);
2453 last_exp_param
= ctx
.bc
->cf_last
;
2456 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2457 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2459 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2460 cf_pop
= ctx
.bc
->cf_last
;
2462 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2463 cf_jump
->pop_count
= 1;
2464 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2465 cf_pop
->pop_count
= 1;
2467 if (ctx
.bc
->chip_class
== CAYMAN
)
2468 cm_bytecode_add_cf_end(ctx
.bc
);
2470 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2471 ctx
.bc
->cf_last
->end_of_program
= 1;
2474 gs
->gs_copy_shader
= cshader
;
2475 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2479 return r600_bytecode_build(ctx
.bc
);
2482 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2485 struct r600_bytecode_alu alu
;
2488 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2489 alu
.op
= ALU_OP2_ADD_INT
;
2490 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2491 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2492 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2493 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2496 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2503 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2505 struct r600_bytecode_output output
;
2508 int effective_stream
= stream
== -1 ? 0 : stream
;
2511 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2512 if (ctx
->gs_for_vs
) {
2513 /* for ES we need to lookup corresponding ring offset expected by GS
2514 * (map this output to GS input by name and sid) */
2515 /* FIXME precompute offsets */
2517 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2518 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2519 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2520 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2521 ring_offset
= in
->ring_offset
;
2524 if (ring_offset
== -1)
2527 ring_offset
= idx
* 16;
2531 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2533 /* next_ring_offset after parsing input decls contains total size of
2534 * single vertex data, gs_next_vertex - current vertex index */
2536 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2538 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2539 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2540 output
.elem_size
= 3;
2541 output
.comp_mask
= 0xF;
2542 output
.burst_count
= 1;
2545 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2547 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2552 output
.op
= CF_OP_MEM_RING
; break;
2554 output
.op
= CF_OP_MEM_RING1
; break;
2556 output
.op
= CF_OP_MEM_RING2
; break;
2558 output
.op
= CF_OP_MEM_RING3
; break;
2562 output
.array_base
= ring_offset
>> 2; /* in dwords */
2563 output
.array_size
= 0xfff;
2564 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2566 output
.array_base
= ring_offset
>> 2; /* in dwords */
2567 r600_bytecode_add_output(ctx
->bc
, &output
);
2570 ++ctx
->gs_next_vertex
;
2575 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2578 struct r600_bytecode_vtx vtx
;
2579 int temp_val
= ctx
->temp_reg
;
2580 /* need to store the TCS output somewhere */
2581 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2583 V_SQ_ALU_SRC_LITERAL
, 0,
2588 /* used by VS/TCS */
2589 if (ctx
->tess_input_info
) {
2590 /* fetch tcs input values into resv space */
2591 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2592 vtx
.op
= FETCH_OP_VFETCH
;
2593 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2594 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2595 vtx
.mega_fetch_count
= 16;
2596 vtx
.data_format
= FMT_32_32_32_32
;
2597 vtx
.num_format_all
= 2;
2598 vtx
.format_comp_all
= 1;
2599 vtx
.use_const_fields
= 0;
2600 vtx
.endian
= r600_endian_swap(32);
2601 vtx
.srf_mode_all
= 1;
2603 vtx
.dst_gpr
= ctx
->tess_input_info
;
2608 vtx
.src_gpr
= temp_val
;
2611 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2616 /* used by TCS/TES */
2617 if (ctx
->tess_output_info
) {
2618 /* fetch tcs output values into resv space */
2619 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2620 vtx
.op
= FETCH_OP_VFETCH
;
2621 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2622 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2623 vtx
.mega_fetch_count
= 16;
2624 vtx
.data_format
= FMT_32_32_32_32
;
2625 vtx
.num_format_all
= 2;
2626 vtx
.format_comp_all
= 1;
2627 vtx
.use_const_fields
= 0;
2628 vtx
.endian
= r600_endian_swap(32);
2629 vtx
.srf_mode_all
= 1;
2631 vtx
.dst_gpr
= ctx
->tess_output_info
;
2636 vtx
.src_gpr
= temp_val
;
2639 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2646 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2652 /* fetch tcs input values into input_vals */
2653 ctx
->tess_input_info
= r600_get_temp(ctx
);
2654 ctx
->tess_output_info
= 0;
2655 r
= r600_fetch_tess_io_info(ctx
);
2659 temp_reg
= r600_get_temp(ctx
);
2660 /* dst reg contains LDS address stride * idx */
2661 /* MUL vertexID, vertex_dw_stride */
2662 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2664 ctx
->tess_input_info
, 1,
2665 0, 1); /* rel id in r0.y? */
2669 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2670 struct r600_bytecode_alu alu
;
2671 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2674 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2677 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2682 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2684 temp_reg
, param
? 1 : 0,
2685 V_SQ_ALU_SRC_LITERAL
, 8);
2690 for (j
= 0; j
< 2; j
++) {
2691 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2692 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2693 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2694 alu
.src
[0].sel
= temp_reg
;
2695 alu
.src
[0].chan
= chan
;
2696 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2697 alu
.src
[1].chan
= j
* 2;
2698 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2699 alu
.src
[2].chan
= (j
* 2) + 1;
2703 alu
.is_lds_idx_op
= true;
2704 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2712 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2714 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2715 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2717 int temp_reg
= r600_get_temp(ctx
);
2718 struct r600_bytecode_alu alu
;
2719 unsigned write_mask
= dst
->Register
.WriteMask
;
2721 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2724 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2728 /* the base address is now in temp.x */
2729 r
= r600_get_byte_address(ctx
, temp_reg
,
2730 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2735 lasti
= tgsi_last_instruction(write_mask
);
2736 for (i
= 1; i
<= lasti
; i
++) {
2738 if (!(write_mask
& (1 << i
)))
2740 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2743 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2748 for (i
= 0; i
<= lasti
; i
++) {
2749 if (!(write_mask
& (1 << i
)))
2752 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2753 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2754 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2755 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2756 alu
.src
[0].sel
= temp_reg
;
2757 alu
.src
[0].chan
= i
;
2759 alu
.src
[1].sel
= dst
->Register
.Index
;
2760 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2761 alu
.src
[1].chan
= i
;
2763 alu
.src
[2].sel
= dst
->Register
.Index
;
2764 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2765 alu
.src
[2].chan
= i
+ 1;
2769 alu
.is_lds_idx_op
= true;
2770 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2777 alu
.op
= LDS_OP2_LDS_WRITE
;
2778 alu
.src
[0].sel
= temp_reg
;
2779 alu
.src
[0].chan
= i
;
2781 alu
.src
[1].sel
= dst
->Register
.Index
;
2782 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2783 alu
.src
[1].chan
= i
;
2785 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2788 alu
.is_lds_idx_op
= true;
2789 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2796 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2800 unsigned temp_reg
= r600_get_temp(ctx
);
2801 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2802 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2805 param
= r600_get_lds_unique_index(name
, 0);
2806 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2810 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2813 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2817 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
2821 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2823 int stride
, outer_comps
, inner_comps
;
2824 int tessinner_idx
= -1, tessouter_idx
= -1;
2827 int temp_reg
= r600_get_temp(ctx
);
2828 int treg
[3] = {-1, -1, -1};
2829 struct r600_bytecode_alu alu
;
2830 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2832 /* only execute factor emission for invocation 0 */
2833 /* PRED_SETE_INT __, R0.x, 0 */
2834 memset(&alu
, 0, sizeof(alu
));
2835 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2836 alu
.src
[0].chan
= 2;
2837 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2838 alu
.execute_mask
= 1;
2839 alu
.update_pred
= 1;
2841 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2843 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2844 cf_jump
= ctx
->bc
->cf_last
;
2846 treg
[0] = r600_get_temp(ctx
);
2847 switch (ctx
->shader
->tcs_prim_mode
) {
2848 case PIPE_PRIM_LINES
:
2849 stride
= 8; /* 2 dwords, 1 vec2 store */
2853 case PIPE_PRIM_TRIANGLES
:
2854 stride
= 16; /* 4 dwords, 1 vec4 store */
2857 treg
[1] = r600_get_temp(ctx
);
2859 case PIPE_PRIM_QUADS
:
2860 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2863 treg
[1] = r600_get_temp(ctx
);
2864 treg
[2] = r600_get_temp(ctx
);
2871 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2872 /* TF_WRITE takes index in R.x, value in R.y */
2873 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
2874 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
2876 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
2880 if (tessouter_idx
== -1)
2883 if (tessinner_idx
== -1 && inner_comps
)
2886 if (tessouter_idx
!= -1) {
2887 r
= r600_tess_factor_read(ctx
, tessouter_idx
);
2892 if (tessinner_idx
!= -1) {
2893 r
= r600_tess_factor_read(ctx
, tessinner_idx
);
2898 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2899 /* r.x = relpatchid(r0.y) * tf_stride */
2901 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2902 /* add incoming r0.w to it: t.x = t.x + r0.w */
2903 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2906 V_SQ_ALU_SRC_LITERAL
, stride
,
2911 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2912 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2913 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2915 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
2918 else if (out_comp
== 0)
2922 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2923 treg
[i
/ 2], (2 * (i
% 2)),
2925 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2928 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2929 treg
[i
/ 2], 1 + (2 * (i
%2)),
2930 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
2935 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2936 struct r600_bytecode_gds gds
;
2938 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
2939 gds
.src_gpr
= treg
[i
/ 2];
2940 gds
.src_sel_x
= 2 * (i
% 2);
2941 gds
.src_sel_y
= 1 + (2 * (i
% 2));
2947 gds
.op
= FETCH_OP_TF_WRITE
;
2948 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
2953 // Patch up jump label
2954 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
2955 cf_pop
= ctx
->bc
->cf_last
;
2957 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2958 cf_jump
->pop_count
= 1;
2959 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2960 cf_pop
->pop_count
= 1;
2966 * We have to work out the thread ID for load and atomic
2967 * operations, which store the returned value to an index
2968 * in an intermediate buffer.
2969 * The index is calculated by taking the thread id,
2970 * calculated from the MBCNT instructions.
2971 * Then the shader engine ID is multiplied by 256,
2972 * and the wave id is added.
2973 * Then the result is multipled by 64 and thread id is
2976 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
2978 struct r600_bytecode_alu alu
;
2981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2982 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
2983 alu
.dst
.sel
= ctx
->temp_reg
;
2985 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2986 alu
.src
[0].value
= 0xffffffff;
2988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2992 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2993 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
2994 alu
.dst
.sel
= ctx
->temp_reg
;
2996 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2997 alu
.src
[0].value
= 0xffffffff;
2999 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3004 alu
.op
= ALU_OP3_MULADD_UINT24
;
3005 alu
.dst
.sel
= ctx
->temp_reg
;
3007 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3008 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3009 alu
.src
[1].value
= 256;
3010 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3018 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3019 ctx
->thread_id_gpr
, 1,
3021 V_SQ_ALU_SRC_LITERAL
, 0x40,
3028 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3029 struct r600_pipe_shader
*pipeshader
,
3030 union r600_shader_key key
)
3032 struct r600_screen
*rscreen
= rctx
->screen
;
3033 struct r600_shader
*shader
= &pipeshader
->shader
;
3034 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3035 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3036 struct tgsi_full_immediate
*immediate
;
3037 struct r600_shader_ctx ctx
;
3038 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3039 unsigned output_done
, noutput
;
3043 int next_param_base
= 0, next_clip_base
;
3044 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3046 bool ring_outputs
= false;
3047 bool lds_outputs
= false;
3048 bool lds_inputs
= false;
3049 bool pos_emitted
= false;
3051 ctx
.bc
= &shader
->bc
;
3052 ctx
.shader
= shader
;
3053 ctx
.native_integers
= true;
3055 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3056 rscreen
->has_compressed_msaa_texturing
);
3057 ctx
.tokens
= tokens
;
3058 tgsi_scan_shader(tokens
, &ctx
.info
);
3059 shader
->indirect_files
= ctx
.info
.indirect_files
;
3061 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3062 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3063 shader
->nsys_inputs
= 0;
3065 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0;
3066 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3067 tgsi_parse_init(&ctx
.parse
, tokens
);
3068 ctx
.type
= ctx
.info
.processor
;
3069 shader
->processor_type
= ctx
.type
;
3070 ctx
.bc
->type
= shader
->processor_type
;
3073 case PIPE_SHADER_VERTEX
:
3074 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3075 shader
->vs_as_es
= key
.vs
.as_es
;
3076 shader
->vs_as_ls
= key
.vs
.as_ls
;
3077 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3078 if (shader
->vs_as_es
)
3079 ring_outputs
= true;
3080 if (shader
->vs_as_ls
)
3083 case PIPE_SHADER_GEOMETRY
:
3084 ring_outputs
= true;
3085 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3086 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3088 case PIPE_SHADER_TESS_CTRL
:
3089 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3090 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3094 case PIPE_SHADER_TESS_EVAL
:
3095 shader
->tes_as_es
= key
.tes
.as_es
;
3096 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3098 if (shader
->tes_as_es
)
3099 ring_outputs
= true;
3101 case PIPE_SHADER_FRAGMENT
:
3102 shader
->two_side
= key
.ps
.color_two_side
;
3103 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3104 shader
->rat_base
= key
.ps
.nr_cbufs
;
3105 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3111 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3112 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3114 ctx
.gs_for_vs
= NULL
;
3117 ctx
.next_ring_offset
= 0;
3118 ctx
.gs_out_ring_offset
= 0;
3119 ctx
.gs_next_vertex
= 0;
3120 ctx
.gs_stream_output_info
= &so
;
3123 ctx
.fixed_pt_position_gpr
= -1;
3124 ctx
.fragcoord_input
= -1;
3125 ctx
.colors_used
= 0;
3126 ctx
.clip_vertex_write
= 0;
3128 shader
->nr_ps_color_exports
= 0;
3129 shader
->nr_ps_max_color_exports
= 0;
3132 /* register allocations */
3133 /* Values [0,127] correspond to GPR[0..127].
3134 * Values [128,159] correspond to constant buffer bank 0
3135 * Values [160,191] correspond to constant buffer bank 1
3136 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3137 * Values [256,287] correspond to constant buffer bank 2 (EG)
3138 * Values [288,319] correspond to constant buffer bank 3 (EG)
3139 * Other special values are shown in the list below.
3140 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3141 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3142 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3143 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3144 * 248 SQ_ALU_SRC_0: special constant 0.0.
3145 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3146 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3147 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3148 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3149 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3150 * 254 SQ_ALU_SRC_PV: previous vector result.
3151 * 255 SQ_ALU_SRC_PS: previous scalar result.
3153 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3154 ctx
.file_offset
[i
] = 0;
3157 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3159 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3160 if (ctx
.info
.num_inputs
)
3161 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3163 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3164 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3165 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3167 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3169 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3170 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3171 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3173 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3174 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3175 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3176 bool add_tesscoord
= false, add_tess_inout
= false;
3177 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3178 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3179 /* if we have tesscoord save one reg */
3180 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3181 add_tesscoord
= true;
3182 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3183 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3184 add_tess_inout
= true;
3186 if (add_tesscoord
|| add_tess_inout
)
3187 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3189 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3192 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3193 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3194 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3195 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3196 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3198 /* Outside the GPR range. This will be translated to one of the
3199 * kcache banks later. */
3200 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3202 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3203 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3204 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3205 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3206 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3208 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3209 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3210 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3211 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3212 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3213 ctx
.tess_input_info
= 0;
3214 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3215 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3216 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3217 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3218 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3219 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3220 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3221 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3222 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3223 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3224 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3227 ctx
.gs_rotated_input
[0] = 0;
3228 ctx
.gs_rotated_input
[1] = 1;
3231 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3234 if (shader
->uses_images
&& ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3235 ctx
.thread_id_gpr
= ctx
.temp_reg
;
3238 ctx
.thread_id_gpr
= 0;
3240 shader
->max_arrays
= 0;
3241 shader
->num_arrays
= 0;
3242 if (indirect_gprs
) {
3244 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3245 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3246 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3247 ctx
.file_offset
[TGSI_FILE_INPUT
],
3250 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3251 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3252 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3253 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3259 ctx
.literals
= NULL
;
3261 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3262 ctx
.info
.colors_written
== 1;
3263 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3264 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3266 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3267 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3268 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3269 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3270 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3271 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3272 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3275 if (shader
->vs_as_gs_a
)
3276 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3278 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3279 r600_fetch_tess_io_info(&ctx
);
3281 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3282 tgsi_parse_token(&ctx
.parse
);
3283 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3284 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3285 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3286 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3287 if(ctx
.literals
== NULL
) {
3291 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3292 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3293 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3294 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3297 case TGSI_TOKEN_TYPE_DECLARATION
:
3298 r
= tgsi_declaration(&ctx
);
3302 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3303 case TGSI_TOKEN_TYPE_PROPERTY
:
3306 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3312 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3313 shader
->ring_item_sizes
[1] = 0;
3314 shader
->ring_item_sizes
[2] = 0;
3315 shader
->ring_item_sizes
[3] = 0;
3317 /* Process two side if needed */
3318 if (shader
->two_side
&& ctx
.colors_used
) {
3319 int i
, count
= ctx
.shader
->ninput
;
3320 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3322 /* additional inputs will be allocated right after the existing inputs,
3323 * we won't need them after the color selection, so we don't need to
3324 * reserve these gprs for the rest of the shader code and to adjust
3325 * output offsets etc. */
3326 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3327 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3329 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3330 if (ctx
.face_gpr
== -1) {
3331 i
= ctx
.shader
->ninput
++;
3332 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3333 ctx
.shader
->input
[i
].spi_sid
= 0;
3334 ctx
.shader
->input
[i
].gpr
= gpr
++;
3335 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3338 for (i
= 0; i
< count
; i
++) {
3339 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3340 int ni
= ctx
.shader
->ninput
++;
3341 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3342 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3343 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3344 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3345 // TGSI to LLVM needs to know the lds position of inputs.
3346 // Non LLVM path computes it later (in process_twoside_color)
3347 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3348 ctx
.shader
->input
[i
].back_color_input
= ni
;
3349 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3350 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3357 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3358 shader
->nr_ps_max_color_exports
= 8;
3360 if (ctx
.fragcoord_input
>= 0) {
3361 if (ctx
.bc
->chip_class
== CAYMAN
) {
3362 for (j
= 0 ; j
< 4; j
++) {
3363 struct r600_bytecode_alu alu
;
3364 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3365 alu
.op
= ALU_OP1_RECIP_IEEE
;
3366 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3367 alu
.src
[0].chan
= 3;
3369 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3371 alu
.dst
.write
= (j
== 3);
3373 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3377 struct r600_bytecode_alu alu
;
3378 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3379 alu
.op
= ALU_OP1_RECIP_IEEE
;
3380 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3381 alu
.src
[0].chan
= 3;
3383 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3387 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3392 if (ctx
.thread_id_gpr
) {
3393 load_thread_id_gpr(&ctx
);
3396 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3397 struct r600_bytecode_alu alu
;
3400 /* GS thread with no output workaround - emit a cut at start of GS */
3401 if (ctx
.bc
->chip_class
== R600
)
3402 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3404 for (j
= 0; j
< 4; j
++) {
3405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3406 alu
.op
= ALU_OP1_MOV
;
3407 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3408 alu
.src
[0].value
= 0;
3409 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3412 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3417 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3418 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3419 ctx
.gs_rotated_input
[0], 2,
3421 V_SQ_ALU_SRC_LITERAL
, 1);
3425 for (i
= 0; i
< 6; i
++) {
3426 int rotated
= (i
+ 4) % 6;
3427 int offset_reg
= i
/ 3;
3428 int offset_chan
= i
% 3;
3429 int rotated_offset_reg
= rotated
/ 3;
3430 int rotated_offset_chan
= rotated
% 3;
3432 if (offset_reg
== 0 && offset_chan
== 2)
3434 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3435 rotated_offset_chan
= 3;
3437 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3438 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3439 ctx
.gs_rotated_input
[0], 2,
3440 offset_reg
, offset_chan
,
3441 rotated_offset_reg
, rotated_offset_chan
);
3448 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3449 r600_fetch_tess_io_info(&ctx
);
3451 if (shader
->two_side
&& ctx
.colors_used
) {
3452 if ((r
= process_twoside_color_inputs(&ctx
)))
3456 tgsi_parse_init(&ctx
.parse
, tokens
);
3457 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3458 tgsi_parse_token(&ctx
.parse
);
3459 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3460 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3461 r
= tgsi_is_supported(&ctx
);
3464 ctx
.max_driver_temp_used
= 0;
3465 /* reserve first tmp for everyone */
3466 r600_get_temp(&ctx
);
3468 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3469 if ((r
= tgsi_split_constant(&ctx
)))
3471 if ((r
= tgsi_split_literal_constant(&ctx
)))
3473 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3474 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3476 } else if (lds_inputs
) {
3477 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3480 if (ctx
.bc
->chip_class
== CAYMAN
)
3481 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3482 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3483 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3485 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3486 r
= ctx
.inst_info
->process(&ctx
);
3490 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3491 r
= r600_store_tcs_output(&ctx
);
3501 /* Reset the temporary register counter. */
3502 ctx
.max_driver_temp_used
= 0;
3504 noutput
= shader
->noutput
;
3506 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3507 unsigned clipdist_temp
[2];
3509 clipdist_temp
[0] = r600_get_temp(&ctx
);
3510 clipdist_temp
[1] = r600_get_temp(&ctx
);
3512 /* need to convert a clipvertex write into clipdistance writes and not export
3513 the clip vertex anymore */
3515 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3516 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3517 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3519 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3520 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3523 /* reset spi_sid for clipvertex output to avoid confusing spi */
3524 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3526 shader
->clip_dist_write
= 0xFF;
3527 shader
->cc_dist_mask
= 0xFF;
3529 for (i
= 0; i
< 8; i
++) {
3533 for (j
= 0; j
< 4; j
++) {
3534 struct r600_bytecode_alu alu
;
3535 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3536 alu
.op
= ALU_OP2_DOT4
;
3537 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3538 alu
.src
[0].chan
= j
;
3540 alu
.src
[1].sel
= 512 + i
;
3541 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3542 alu
.src
[1].chan
= j
;
3544 alu
.dst
.sel
= clipdist_temp
[oreg
];
3546 alu
.dst
.write
= (j
== ochan
);
3549 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3556 /* Add stream outputs. */
3557 if (so
.num_outputs
) {
3559 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3561 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3564 emit_streamout(&ctx
, &so
, -1, NULL
);
3566 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3567 convert_edgeflag_to_int(&ctx
);
3569 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3570 r600_emit_tess_factor(&ctx
);
3573 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3574 if (ctx
.shader
->noutput
)
3575 emit_lds_vs_writes(&ctx
);
3577 } else if (ring_outputs
) {
3578 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3579 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3580 ctx
.gs_export_gpr_tregs
[1] = -1;
3581 ctx
.gs_export_gpr_tregs
[2] = -1;
3582 ctx
.gs_export_gpr_tregs
[3] = -1;
3584 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3588 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3590 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3591 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3592 output
[j
].gpr
= shader
->output
[i
].gpr
;
3593 output
[j
].elem_size
= 3;
3594 output
[j
].swizzle_x
= 0;
3595 output
[j
].swizzle_y
= 1;
3596 output
[j
].swizzle_z
= 2;
3597 output
[j
].swizzle_w
= 3;
3598 output
[j
].burst_count
= 1;
3599 output
[j
].type
= 0xffffffff;
3600 output
[j
].op
= CF_OP_EXPORT
;
3602 case PIPE_SHADER_VERTEX
:
3603 case PIPE_SHADER_TESS_EVAL
:
3604 switch (shader
->output
[i
].name
) {
3605 case TGSI_SEMANTIC_POSITION
:
3606 output
[j
].array_base
= 60;
3607 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3611 case TGSI_SEMANTIC_PSIZE
:
3612 output
[j
].array_base
= 61;
3613 output
[j
].swizzle_y
= 7;
3614 output
[j
].swizzle_z
= 7;
3615 output
[j
].swizzle_w
= 7;
3616 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3619 case TGSI_SEMANTIC_EDGEFLAG
:
3620 output
[j
].array_base
= 61;
3621 output
[j
].swizzle_x
= 7;
3622 output
[j
].swizzle_y
= 0;
3623 output
[j
].swizzle_z
= 7;
3624 output
[j
].swizzle_w
= 7;
3625 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3628 case TGSI_SEMANTIC_LAYER
:
3629 /* spi_sid is 0 for outputs that are
3630 * not consumed by PS */
3631 if (shader
->output
[i
].spi_sid
) {
3632 output
[j
].array_base
= next_param_base
++;
3633 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3635 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3637 output
[j
].array_base
= 61;
3638 output
[j
].swizzle_x
= 7;
3639 output
[j
].swizzle_y
= 7;
3640 output
[j
].swizzle_z
= 0;
3641 output
[j
].swizzle_w
= 7;
3642 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3645 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3646 /* spi_sid is 0 for outputs that are
3647 * not consumed by PS */
3648 if (shader
->output
[i
].spi_sid
) {
3649 output
[j
].array_base
= next_param_base
++;
3650 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3652 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3654 output
[j
].array_base
= 61;
3655 output
[j
].swizzle_x
= 7;
3656 output
[j
].swizzle_y
= 7;
3657 output
[j
].swizzle_z
= 7;
3658 output
[j
].swizzle_w
= 0;
3659 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3662 case TGSI_SEMANTIC_CLIPVERTEX
:
3665 case TGSI_SEMANTIC_CLIPDIST
:
3666 output
[j
].array_base
= next_clip_base
++;
3667 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3669 /* spi_sid is 0 for clipdistance outputs that were generated
3670 * for clipvertex - we don't need to pass them to PS */
3671 if (shader
->output
[i
].spi_sid
) {
3673 /* duplicate it as PARAM to pass to the pixel shader */
3674 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3675 output
[j
].array_base
= next_param_base
++;
3676 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3679 case TGSI_SEMANTIC_FOG
:
3680 output
[j
].swizzle_y
= 4; /* 0 */
3681 output
[j
].swizzle_z
= 4; /* 0 */
3682 output
[j
].swizzle_w
= 5; /* 1 */
3684 case TGSI_SEMANTIC_PRIMID
:
3685 output
[j
].swizzle_x
= 2;
3686 output
[j
].swizzle_y
= 4; /* 0 */
3687 output
[j
].swizzle_z
= 4; /* 0 */
3688 output
[j
].swizzle_w
= 4; /* 0 */
3693 case PIPE_SHADER_FRAGMENT
:
3694 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3695 /* never export more colors than the number of CBs */
3696 if (shader
->output
[i
].sid
>= max_color_exports
) {
3701 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3702 output
[j
].array_base
= shader
->output
[i
].sid
;
3703 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3704 shader
->nr_ps_color_exports
++;
3705 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3706 for (k
= 1; k
< max_color_exports
; k
++) {
3708 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3709 output
[j
].gpr
= shader
->output
[i
].gpr
;
3710 output
[j
].elem_size
= 3;
3711 output
[j
].swizzle_x
= 0;
3712 output
[j
].swizzle_y
= 1;
3713 output
[j
].swizzle_z
= 2;
3714 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3715 output
[j
].burst_count
= 1;
3716 output
[j
].array_base
= k
;
3717 output
[j
].op
= CF_OP_EXPORT
;
3718 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3719 shader
->nr_ps_color_exports
++;
3722 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3723 output
[j
].array_base
= 61;
3724 output
[j
].swizzle_x
= 2;
3725 output
[j
].swizzle_y
= 7;
3726 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3727 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3728 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3729 output
[j
].array_base
= 61;
3730 output
[j
].swizzle_x
= 7;
3731 output
[j
].swizzle_y
= 1;
3732 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3733 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3734 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3735 output
[j
].array_base
= 61;
3736 output
[j
].swizzle_x
= 7;
3737 output
[j
].swizzle_y
= 7;
3738 output
[j
].swizzle_z
= 0;
3739 output
[j
].swizzle_w
= 7;
3740 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3742 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3747 case PIPE_SHADER_TESS_CTRL
:
3750 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3755 if (output
[j
].type
== 0xffffffff) {
3756 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3757 output
[j
].array_base
= next_param_base
++;
3761 /* add fake position export */
3762 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3763 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3765 output
[j
].elem_size
= 3;
3766 output
[j
].swizzle_x
= 7;
3767 output
[j
].swizzle_y
= 7;
3768 output
[j
].swizzle_z
= 7;
3769 output
[j
].swizzle_w
= 7;
3770 output
[j
].burst_count
= 1;
3771 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3772 output
[j
].array_base
= 60;
3773 output
[j
].op
= CF_OP_EXPORT
;
3777 /* add fake param output for vertex shader if no param is exported */
3778 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3779 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3781 output
[j
].elem_size
= 3;
3782 output
[j
].swizzle_x
= 7;
3783 output
[j
].swizzle_y
= 7;
3784 output
[j
].swizzle_z
= 7;
3785 output
[j
].swizzle_w
= 7;
3786 output
[j
].burst_count
= 1;
3787 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3788 output
[j
].array_base
= 0;
3789 output
[j
].op
= CF_OP_EXPORT
;
3793 /* add fake pixel export */
3794 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3795 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3797 output
[j
].elem_size
= 3;
3798 output
[j
].swizzle_x
= 7;
3799 output
[j
].swizzle_y
= 7;
3800 output
[j
].swizzle_z
= 7;
3801 output
[j
].swizzle_w
= 7;
3802 output
[j
].burst_count
= 1;
3803 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3804 output
[j
].array_base
= 0;
3805 output
[j
].op
= CF_OP_EXPORT
;
3807 shader
->nr_ps_color_exports
++;
3812 /* set export done on last export of each type */
3813 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
3814 if (!(output_done
& (1 << output
[k
].type
))) {
3815 output_done
|= (1 << output
[k
].type
);
3816 output
[k
].op
= CF_OP_EXPORT_DONE
;
3819 /* add output to bytecode */
3820 for (i
= 0; i
< noutput
; i
++) {
3821 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3827 /* add program end */
3828 if (ctx
.bc
->chip_class
== CAYMAN
)
3829 cm_bytecode_add_cf_end(ctx
.bc
);
3831 const struct cf_op_info
*last
= NULL
;
3833 if (ctx
.bc
->cf_last
)
3834 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3836 /* alu clause instructions don't have EOP bit, so add NOP */
3837 if (!last
|| last
->flags
& CF_ALU
)
3838 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3840 ctx
.bc
->cf_last
->end_of_program
= 1;
3843 /* check GPR limit - we have 124 = 128 - 4
3844 * (4 are reserved as alu clause temporary registers) */
3845 if (ctx
.bc
->ngpr
> 124) {
3846 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3851 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3852 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3857 tgsi_parse_free(&ctx
.parse
);
3861 tgsi_parse_free(&ctx
.parse
);
3865 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3867 const unsigned tgsi_opcode
=
3868 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3869 R600_ERR("%s tgsi opcode unsupported\n",
3870 tgsi_get_opcode_name(tgsi_opcode
));
3874 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
3879 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3880 const struct r600_shader_src
*shader_src
,
3883 bc_src
->sel
= shader_src
->sel
;
3884 bc_src
->chan
= shader_src
->swizzle
[chan
];
3885 bc_src
->neg
= shader_src
->neg
;
3886 bc_src
->abs
= shader_src
->abs
;
3887 bc_src
->rel
= shader_src
->rel
;
3888 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3889 bc_src
->kc_bank
= shader_src
->kc_bank
;
3890 bc_src
->kc_rel
= shader_src
->kc_rel
;
3893 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3899 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3901 bc_src
->neg
= !bc_src
->neg
;
3904 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3905 const struct tgsi_full_dst_register
*tgsi_dst
,
3907 struct r600_bytecode_alu_dst
*r600_dst
)
3909 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3911 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
3912 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
3913 r600_dst
->chan
= swizzle
;
3914 r600_dst
->write
= 1;
3915 if (inst
->Instruction
.Saturate
) {
3916 r600_dst
->clamp
= 1;
3918 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
3919 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
3923 if (tgsi_dst
->Register
.Indirect
)
3924 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
3928 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
)
3930 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3931 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3932 struct r600_bytecode_alu alu
;
3933 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3937 switch (write_mask
) {
3955 lasti
= tgsi_last_instruction(write_mask
);
3956 for (i
= 0; i
<= lasti
; i
++) {
3958 if (!(write_mask
& (1 << i
)))
3961 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3964 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3966 alu
.dst
.sel
= ctx
->temp_reg
;
3970 if (i
== 1 || i
== 3)
3973 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3975 alu
.op
= ctx
->inst_info
->op
;
3976 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
3977 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3979 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3980 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
3983 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
3984 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
3987 /* handle some special cases */
3988 if (i
== 1 || i
== 3) {
3989 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
3990 case TGSI_OPCODE_DABS
:
3991 r600_bytecode_src_set_abs(&alu
.src
[0]);
4000 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4006 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4008 /* move result from temp to dst */
4009 for (i
= 0; i
<= lasti
; i
++) {
4010 if (!(write_mask
& (1 << i
)))
4013 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4014 alu
.op
= ALU_OP1_MOV
;
4015 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4016 alu
.src
[0].sel
= ctx
->temp_reg
;
4017 alu
.src
[0].chan
= use_tmp
- 1;
4018 alu
.last
= (i
== lasti
);
4020 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4028 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4030 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4031 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4032 /* confirm writemasking */
4033 if ((write_mask
& 0x3) != 0x3 &&
4034 (write_mask
& 0xc) != 0xc) {
4035 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4038 return tgsi_op2_64_params(ctx
, false, false);
4041 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4043 return tgsi_op2_64_params(ctx
, true, false);
4046 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4048 return tgsi_op2_64_params(ctx
, true, true);
4051 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4053 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4054 struct r600_bytecode_alu alu
;
4057 int tmp
= r600_get_temp(ctx
);
4059 for (i
= 0; i
< lasti
+ 1; i
++) {
4061 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4062 alu
.op
= ctx
->inst_info
->op
;
4063 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4064 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4067 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4068 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4077 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4084 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4086 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4087 struct r600_bytecode_alu alu
;
4088 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4089 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4090 /* use temp register if trans_only and more than one dst component */
4091 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4092 unsigned op
= ctx
->inst_info
->op
;
4094 if (op
== ALU_OP2_MUL_IEEE
&&
4095 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4098 for (i
= 0; i
<= lasti
; i
++) {
4099 if (!(write_mask
& (1 << i
)))
4102 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4104 alu
.dst
.sel
= ctx
->temp_reg
;
4108 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4112 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4113 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4116 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4117 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4119 if (i
== lasti
|| trans_only
) {
4122 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4128 /* move result from temp to dst */
4129 for (i
= 0; i
<= lasti
; i
++) {
4130 if (!(write_mask
& (1 << i
)))
4133 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4134 alu
.op
= ALU_OP1_MOV
;
4135 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4136 alu
.src
[0].sel
= ctx
->temp_reg
;
4137 alu
.src
[0].chan
= i
;
4138 alu
.last
= (i
== lasti
);
4140 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4148 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4150 return tgsi_op2_s(ctx
, 0, 0);
4153 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4155 return tgsi_op2_s(ctx
, 1, 0);
4158 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4160 return tgsi_op2_s(ctx
, 0, 1);
4163 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4165 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4166 struct r600_bytecode_alu alu
;
4168 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4170 for (i
= 0; i
< lasti
+ 1; i
++) {
4172 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4174 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4175 alu
.op
= ctx
->inst_info
->op
;
4177 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4179 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4181 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4186 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4194 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4196 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4197 struct r600_bytecode_alu alu
;
4199 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4201 for (i
= 0; i
< lasti
+ 1; i
++) {
4203 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4205 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4206 alu
.op
= ALU_OP1_MOV
;
4208 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4210 if (i
== 1 || i
== 3)
4211 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4212 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4217 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4225 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4227 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4228 struct r600_bytecode_alu alu
;
4229 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4232 for (i
= 0; i
<= 3; i
++) {
4233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4234 alu
.op
= ctx
->inst_info
->op
;
4236 alu
.dst
.sel
= ctx
->temp_reg
;
4239 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4240 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4246 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4251 /* Replicate significand result across channels. */
4252 for (i
= 0; i
<= 3; i
++) {
4253 if (!(write_mask
& (1 << i
)))
4256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4257 alu
.op
= ALU_OP1_MOV
;
4258 alu
.src
[0].chan
= (i
& 1) + 2;
4259 alu
.src
[0].sel
= ctx
->temp_reg
;
4261 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4269 for (i
= 0; i
<= 3; i
++) {
4270 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4271 /* MOV third channels to writemask dst1 */
4272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4273 alu
.op
= ALU_OP1_MOV
;
4274 alu
.src
[0].chan
= 1;
4275 alu
.src
[0].sel
= ctx
->temp_reg
;
4277 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4279 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4289 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4291 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4292 struct r600_bytecode_alu alu
;
4294 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4296 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4297 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4299 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4301 alu
.op
= ctx
->inst_info
->op
;
4303 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4304 alu
.dst
.sel
= ctx
->temp_reg
;
4309 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4314 for (i
= 0; i
<= lasti
; i
++) {
4315 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4316 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4318 alu
.src
[0].chan
= i
/2;
4320 alu
.src
[0].sel
= ctx
->temp_reg
;
4322 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4323 alu
.src
[0].value
= 0x0;
4325 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4326 alu
.last
= i
== lasti
;
4328 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4336 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4338 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4339 struct r600_bytecode_alu alu
;
4341 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4343 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4344 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4346 for (i
= 0; i
<= lasti
; i
++) {
4347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4348 alu
.op
= ALU_OP1_FLT64_TO_FLT32
;
4350 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], fp64_switch(i
));
4352 alu
.dst
.sel
= ctx
->temp_reg
;
4353 alu
.dst
.write
= i
%2 == 0;
4354 alu
.last
= i
== lasti
;
4356 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4361 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4363 alu
.op
= ctx
->inst_info
->op
;
4365 alu
.src
[0].chan
= i
*2;
4366 alu
.src
[0].sel
= ctx
->temp_reg
;
4367 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4370 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4378 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4381 struct r600_shader_src
*src
,
4384 struct r600_bytecode_alu alu
;
4385 const int last_slot
= 3;
4388 /* these have to write the result to X/Y by the looks of it */
4389 for (int i
= 0 ; i
< last_slot
; i
++) {
4390 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4393 r600_bytecode_src(&alu
.src
[0], src
, 1);
4394 r600_bytecode_src(&alu
.src
[1], src
, 0);
4397 r600_bytecode_src_set_abs(&alu
.src
[1]);
4399 alu
.dst
.sel
= dst_reg
;
4401 alu
.dst
.write
= (i
== 0 || i
== 1);
4403 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4405 r
= r600_bytecode_add_alu(bc
, &alu
);
4413 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4415 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4417 struct r600_bytecode_alu alu
;
4418 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4419 int t1
= ctx
->temp_reg
;
4421 /* should only be one src regs */
4422 assert(inst
->Instruction
.NumSrcRegs
== 1);
4424 /* only support one double at a time */
4425 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4426 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4428 r
= cayman_emit_unary_double_raw(
4429 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4431 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4432 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4436 for (i
= 0 ; i
<= lasti
; i
++) {
4437 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4439 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4440 alu
.op
= ALU_OP1_MOV
;
4441 alu
.src
[0].sel
= t1
;
4442 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4443 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4447 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4454 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4456 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4458 struct r600_bytecode_alu alu
;
4459 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4461 for (i
= 0 ; i
< last_slot
; i
++) {
4462 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4463 alu
.op
= ctx
->inst_info
->op
;
4464 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4465 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4467 /* RSQ should take the absolute value of src */
4468 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4469 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4472 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4473 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4475 if (i
== last_slot
- 1)
4477 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4484 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4486 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4488 struct r600_bytecode_alu alu
;
4489 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4490 int t1
= ctx
->temp_reg
;
4492 for (k
= 0; k
<= lasti
; k
++) {
4493 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4496 for (i
= 0 ; i
< 4; i
++) {
4497 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4498 alu
.op
= ctx
->inst_info
->op
;
4499 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4500 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4504 alu
.dst
.write
= (i
== k
);
4507 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4513 for (i
= 0 ; i
<= lasti
; i
++) {
4514 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4516 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4517 alu
.op
= ALU_OP1_MOV
;
4518 alu
.src
[0].sel
= t1
;
4519 alu
.src
[0].chan
= i
;
4520 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4524 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4533 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4535 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4537 struct r600_bytecode_alu alu
;
4538 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4539 int t1
= ctx
->temp_reg
;
4541 /* t1 would get overwritten below if we actually tried to
4542 * multiply two pairs of doubles at a time. */
4543 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4544 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4546 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4548 for (i
= 0; i
< 4; i
++) {
4549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4550 alu
.op
= ctx
->inst_info
->op
;
4551 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4552 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4564 for (i
= 0; i
<= lasti
; i
++) {
4565 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4568 alu
.op
= ALU_OP1_MOV
;
4569 alu
.src
[0].sel
= t1
;
4570 alu
.src
[0].chan
= i
;
4571 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4584 * Emit RECIP_64 + MUL_64 to implement division.
4586 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4588 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4590 struct r600_bytecode_alu alu
;
4591 int t1
= ctx
->temp_reg
;
4594 /* Only support one double at a time. This is the same constraint as
4595 * in DMUL lowering. */
4596 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4597 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4599 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4601 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4605 for (int i
= 0; i
< 4; i
++) {
4606 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4607 alu
.op
= ALU_OP2_MUL_64
;
4609 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4611 alu
.src
[1].sel
= t1
;
4612 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4624 for (int i
= 0; i
< 2; i
++) {
4625 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4626 alu
.op
= ALU_OP1_MOV
;
4627 alu
.src
[0].sel
= t1
;
4628 alu
.src
[0].chan
= i
;
4629 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4633 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4641 * r600 - trunc to -PI..PI range
4642 * r700 - normalize by dividing by 2PI
4645 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4648 struct r600_bytecode_alu alu
;
4650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4651 alu
.op
= ALU_OP3_MULADD
;
4655 alu
.dst
.sel
= ctx
->temp_reg
;
4658 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4660 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4661 alu
.src
[1].chan
= 0;
4662 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4663 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4664 alu
.src
[2].chan
= 0;
4666 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4670 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4671 alu
.op
= ALU_OP1_FRACT
;
4674 alu
.dst
.sel
= ctx
->temp_reg
;
4677 alu
.src
[0].sel
= ctx
->temp_reg
;
4678 alu
.src
[0].chan
= 0;
4680 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4684 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4685 alu
.op
= ALU_OP3_MULADD
;
4689 alu
.dst
.sel
= ctx
->temp_reg
;
4692 alu
.src
[0].sel
= ctx
->temp_reg
;
4693 alu
.src
[0].chan
= 0;
4695 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4696 alu
.src
[1].chan
= 0;
4697 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4698 alu
.src
[2].chan
= 0;
4700 if (ctx
->bc
->chip_class
== R600
) {
4701 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4702 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4704 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4705 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4710 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4716 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4718 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4719 struct r600_bytecode_alu alu
;
4720 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4723 r
= tgsi_setup_trig(ctx
);
4728 for (i
= 0; i
< last_slot
; i
++) {
4729 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4730 alu
.op
= ctx
->inst_info
->op
;
4733 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4734 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4736 alu
.src
[0].sel
= ctx
->temp_reg
;
4737 alu
.src
[0].chan
= 0;
4738 if (i
== last_slot
- 1)
4740 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4747 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4749 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4750 struct r600_bytecode_alu alu
;
4752 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4754 r
= tgsi_setup_trig(ctx
);
4758 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4759 alu
.op
= ctx
->inst_info
->op
;
4761 alu
.dst
.sel
= ctx
->temp_reg
;
4764 alu
.src
[0].sel
= ctx
->temp_reg
;
4765 alu
.src
[0].chan
= 0;
4767 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4771 /* replicate result */
4772 for (i
= 0; i
< lasti
+ 1; i
++) {
4773 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4777 alu
.op
= ALU_OP1_MOV
;
4779 alu
.src
[0].sel
= ctx
->temp_reg
;
4780 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4783 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4790 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4792 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4793 struct r600_bytecode_alu alu
;
4796 for (i
= 0; i
< 4; i
++) {
4797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4798 alu
.op
= ctx
->inst_info
->op
;
4802 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4804 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4805 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4808 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4813 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4818 /* kill must be last in ALU */
4819 ctx
->bc
->force_add_cf
= 1;
4820 ctx
->shader
->uses_kill
= TRUE
;
4824 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4826 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4827 struct r600_bytecode_alu alu
;
4830 /* tmp.x = max(src.y, 0.0) */
4831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4832 alu
.op
= ALU_OP2_MAX
;
4833 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4834 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4835 alu
.src
[1].chan
= 1;
4837 alu
.dst
.sel
= ctx
->temp_reg
;
4842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4846 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4852 if (ctx
->bc
->chip_class
== CAYMAN
) {
4853 for (i
= 0; i
< 3; i
++) {
4854 /* tmp.z = log(tmp.x) */
4855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4856 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4857 alu
.src
[0].sel
= ctx
->temp_reg
;
4858 alu
.src
[0].chan
= 0;
4859 alu
.dst
.sel
= ctx
->temp_reg
;
4867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4872 /* tmp.z = log(tmp.x) */
4873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4874 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4875 alu
.src
[0].sel
= ctx
->temp_reg
;
4876 alu
.src
[0].chan
= 0;
4877 alu
.dst
.sel
= ctx
->temp_reg
;
4881 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4886 chan
= alu
.dst
.chan
;
4889 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
4890 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4891 alu
.op
= ALU_OP3_MUL_LIT
;
4892 alu
.src
[0].sel
= sel
;
4893 alu
.src
[0].chan
= chan
;
4894 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
4895 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
4896 alu
.dst
.sel
= ctx
->temp_reg
;
4901 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4905 if (ctx
->bc
->chip_class
== CAYMAN
) {
4906 for (i
= 0; i
< 3; i
++) {
4907 /* dst.z = exp(tmp.x) */
4908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4909 alu
.op
= ALU_OP1_EXP_IEEE
;
4910 alu
.src
[0].sel
= ctx
->temp_reg
;
4911 alu
.src
[0].chan
= 0;
4912 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4918 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4923 /* dst.z = exp(tmp.x) */
4924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4925 alu
.op
= ALU_OP1_EXP_IEEE
;
4926 alu
.src
[0].sel
= ctx
->temp_reg
;
4927 alu
.src
[0].chan
= 0;
4928 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4930 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4937 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4938 alu
.op
= ALU_OP1_MOV
;
4939 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
4940 alu
.src
[0].chan
= 0;
4941 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4942 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
4943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4947 /* dst.y = max(src.x, 0.0) */
4948 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4949 alu
.op
= ALU_OP2_MAX
;
4950 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4951 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4952 alu
.src
[1].chan
= 0;
4953 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
4954 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
4955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4961 alu
.op
= ALU_OP1_MOV
;
4962 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4963 alu
.src
[0].chan
= 0;
4964 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
4965 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
4967 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4974 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
4976 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4977 struct r600_bytecode_alu alu
;
4980 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4982 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
4984 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4985 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4986 r600_bytecode_src_set_abs(&alu
.src
[i
]);
4988 alu
.dst
.sel
= ctx
->temp_reg
;
4991 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4994 /* replicate result */
4995 return tgsi_helper_tempx_replicate(ctx
);
4998 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5000 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5001 struct r600_bytecode_alu alu
;
5004 for (i
= 0; i
< 4; i
++) {
5005 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5006 alu
.src
[0].sel
= ctx
->temp_reg
;
5007 alu
.op
= ALU_OP1_MOV
;
5009 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5010 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5020 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5022 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5023 struct r600_bytecode_alu alu
;
5026 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5027 alu
.op
= ctx
->inst_info
->op
;
5028 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5029 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5031 alu
.dst
.sel
= ctx
->temp_reg
;
5034 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5037 /* replicate result */
5038 return tgsi_helper_tempx_replicate(ctx
);
5041 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5043 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5045 struct r600_bytecode_alu alu
;
5046 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5048 for (i
= 0; i
< 3; i
++) {
5049 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5050 alu
.op
= ALU_OP1_LOG_IEEE
;
5051 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5052 alu
.dst
.sel
= ctx
->temp_reg
;
5057 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5064 alu
.op
= ALU_OP2_MUL
;
5065 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5066 alu
.src
[1].sel
= ctx
->temp_reg
;
5067 alu
.dst
.sel
= ctx
->temp_reg
;
5070 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5074 for (i
= 0; i
< last_slot
; i
++) {
5075 /* POW(a,b) = EXP2(b * LOG2(a))*/
5076 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5077 alu
.op
= ALU_OP1_EXP_IEEE
;
5078 alu
.src
[0].sel
= ctx
->temp_reg
;
5080 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5081 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5082 if (i
== last_slot
- 1)
5084 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5091 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5093 struct r600_bytecode_alu alu
;
5097 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5098 alu
.op
= ALU_OP1_LOG_IEEE
;
5099 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5100 alu
.dst
.sel
= ctx
->temp_reg
;
5103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5107 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5108 alu
.op
= ALU_OP2_MUL
;
5109 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5110 alu
.src
[1].sel
= ctx
->temp_reg
;
5111 alu
.dst
.sel
= ctx
->temp_reg
;
5114 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5117 /* POW(a,b) = EXP2(b * LOG2(a))*/
5118 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5119 alu
.op
= ALU_OP1_EXP_IEEE
;
5120 alu
.src
[0].sel
= ctx
->temp_reg
;
5121 alu
.dst
.sel
= ctx
->temp_reg
;
5124 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5127 return tgsi_helper_tempx_replicate(ctx
);
5130 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5132 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5133 struct r600_bytecode_alu alu
;
5135 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5136 int tmp0
= ctx
->temp_reg
;
5137 int tmp1
= r600_get_temp(ctx
);
5138 int tmp2
= r600_get_temp(ctx
);
5139 int tmp3
= r600_get_temp(ctx
);
5142 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5144 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5145 * 2. tmp0.z = lo (tmp0.x * src2)
5146 * 3. tmp0.w = -tmp0.z
5147 * 4. tmp0.y = hi (tmp0.x * src2)
5148 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5149 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5150 * 7. tmp1.x = tmp0.x - tmp0.w
5151 * 8. tmp1.y = tmp0.x + tmp0.w
5152 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5153 * 10. tmp0.z = hi(tmp0.x * src1) = q
5154 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5156 * 12. tmp0.w = src1 - tmp0.y = r
5157 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5158 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5162 * 15. tmp1.z = tmp0.z + 1 = q + 1
5163 * 16. tmp1.w = tmp0.z - 1 = q - 1
5167 * 15. tmp1.z = tmp0.w - src2 = r - src2
5168 * 16. tmp1.w = tmp0.w + src2 = r + src2
5172 * 17. tmp1.x = tmp1.x & tmp1.y
5174 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5175 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5177 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5178 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5182 * Same as unsigned, using abs values of the operands,
5183 * and fixing the sign of the result in the end.
5186 for (i
= 0; i
< 4; i
++) {
5187 if (!(write_mask
& (1<<i
)))
5192 /* tmp2.x = -src0 */
5193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5194 alu
.op
= ALU_OP2_SUB_INT
;
5200 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5202 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5205 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5208 /* tmp2.y = -src1 */
5209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5210 alu
.op
= ALU_OP2_SUB_INT
;
5216 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5218 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5221 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5224 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5225 /* it will be a sign of the quotient */
5228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5229 alu
.op
= ALU_OP2_XOR_INT
;
5235 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5236 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5239 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5243 /* tmp2.x = |src0| */
5244 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5245 alu
.op
= ALU_OP3_CNDGE_INT
;
5252 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5253 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5254 alu
.src
[2].sel
= tmp2
;
5255 alu
.src
[2].chan
= 0;
5258 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5261 /* tmp2.y = |src1| */
5262 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5263 alu
.op
= ALU_OP3_CNDGE_INT
;
5270 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5271 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5272 alu
.src
[2].sel
= tmp2
;
5273 alu
.src
[2].chan
= 1;
5276 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5281 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5282 if (ctx
->bc
->chip_class
== CAYMAN
) {
5283 /* tmp3.x = u2f(src2) */
5284 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5285 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5292 alu
.src
[0].sel
= tmp2
;
5293 alu
.src
[0].chan
= 1;
5295 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5299 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5302 /* tmp0.x = recip(tmp3.x) */
5303 for (j
= 0 ; j
< 3; j
++) {
5304 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5305 alu
.op
= ALU_OP1_RECIP_IEEE
;
5309 alu
.dst
.write
= (j
== 0);
5311 alu
.src
[0].sel
= tmp3
;
5312 alu
.src
[0].chan
= 0;
5316 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5320 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5321 alu
.op
= ALU_OP2_MUL
;
5323 alu
.src
[0].sel
= tmp0
;
5324 alu
.src
[0].chan
= 0;
5326 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5327 alu
.src
[1].value
= 0x4f800000;
5332 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5336 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5337 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5343 alu
.src
[0].sel
= tmp3
;
5344 alu
.src
[0].chan
= 0;
5347 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5352 alu
.op
= ALU_OP1_RECIP_UINT
;
5359 alu
.src
[0].sel
= tmp2
;
5360 alu
.src
[0].chan
= 1;
5362 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5366 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5370 /* 2. tmp0.z = lo (tmp0.x * src2) */
5371 if (ctx
->bc
->chip_class
== CAYMAN
) {
5372 for (j
= 0 ; j
< 4; j
++) {
5373 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5374 alu
.op
= ALU_OP2_MULLO_UINT
;
5378 alu
.dst
.write
= (j
== 2);
5380 alu
.src
[0].sel
= tmp0
;
5381 alu
.src
[0].chan
= 0;
5383 alu
.src
[1].sel
= tmp2
;
5384 alu
.src
[1].chan
= 1;
5386 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5389 alu
.last
= (j
== 3);
5390 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5395 alu
.op
= ALU_OP2_MULLO_UINT
;
5401 alu
.src
[0].sel
= tmp0
;
5402 alu
.src
[0].chan
= 0;
5404 alu
.src
[1].sel
= tmp2
;
5405 alu
.src
[1].chan
= 1;
5407 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5411 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5415 /* 3. tmp0.w = -tmp0.z */
5416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5417 alu
.op
= ALU_OP2_SUB_INT
;
5423 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5424 alu
.src
[1].sel
= tmp0
;
5425 alu
.src
[1].chan
= 2;
5428 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5431 /* 4. tmp0.y = hi (tmp0.x * src2) */
5432 if (ctx
->bc
->chip_class
== CAYMAN
) {
5433 for (j
= 0 ; j
< 4; j
++) {
5434 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5435 alu
.op
= ALU_OP2_MULHI_UINT
;
5439 alu
.dst
.write
= (j
== 1);
5441 alu
.src
[0].sel
= tmp0
;
5442 alu
.src
[0].chan
= 0;
5445 alu
.src
[1].sel
= tmp2
;
5446 alu
.src
[1].chan
= 1;
5448 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5450 alu
.last
= (j
== 3);
5451 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5455 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5456 alu
.op
= ALU_OP2_MULHI_UINT
;
5462 alu
.src
[0].sel
= tmp0
;
5463 alu
.src
[0].chan
= 0;
5466 alu
.src
[1].sel
= tmp2
;
5467 alu
.src
[1].chan
= 1;
5469 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5473 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5477 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5478 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5479 alu
.op
= ALU_OP3_CNDE_INT
;
5486 alu
.src
[0].sel
= tmp0
;
5487 alu
.src
[0].chan
= 1;
5488 alu
.src
[1].sel
= tmp0
;
5489 alu
.src
[1].chan
= 3;
5490 alu
.src
[2].sel
= tmp0
;
5491 alu
.src
[2].chan
= 2;
5494 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5497 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5498 if (ctx
->bc
->chip_class
== CAYMAN
) {
5499 for (j
= 0 ; j
< 4; j
++) {
5500 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5501 alu
.op
= ALU_OP2_MULHI_UINT
;
5505 alu
.dst
.write
= (j
== 3);
5507 alu
.src
[0].sel
= tmp0
;
5508 alu
.src
[0].chan
= 2;
5510 alu
.src
[1].sel
= tmp0
;
5511 alu
.src
[1].chan
= 0;
5513 alu
.last
= (j
== 3);
5514 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5519 alu
.op
= ALU_OP2_MULHI_UINT
;
5525 alu
.src
[0].sel
= tmp0
;
5526 alu
.src
[0].chan
= 2;
5528 alu
.src
[1].sel
= tmp0
;
5529 alu
.src
[1].chan
= 0;
5532 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5536 /* 7. tmp1.x = tmp0.x - tmp0.w */
5537 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5538 alu
.op
= ALU_OP2_SUB_INT
;
5544 alu
.src
[0].sel
= tmp0
;
5545 alu
.src
[0].chan
= 0;
5546 alu
.src
[1].sel
= tmp0
;
5547 alu
.src
[1].chan
= 3;
5550 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5553 /* 8. tmp1.y = tmp0.x + tmp0.w */
5554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5555 alu
.op
= ALU_OP2_ADD_INT
;
5561 alu
.src
[0].sel
= tmp0
;
5562 alu
.src
[0].chan
= 0;
5563 alu
.src
[1].sel
= tmp0
;
5564 alu
.src
[1].chan
= 3;
5567 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5570 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5571 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5572 alu
.op
= ALU_OP3_CNDE_INT
;
5579 alu
.src
[0].sel
= tmp0
;
5580 alu
.src
[0].chan
= 1;
5581 alu
.src
[1].sel
= tmp1
;
5582 alu
.src
[1].chan
= 1;
5583 alu
.src
[2].sel
= tmp1
;
5584 alu
.src
[2].chan
= 0;
5587 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5590 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5591 if (ctx
->bc
->chip_class
== CAYMAN
) {
5592 for (j
= 0 ; j
< 4; j
++) {
5593 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5594 alu
.op
= ALU_OP2_MULHI_UINT
;
5598 alu
.dst
.write
= (j
== 2);
5600 alu
.src
[0].sel
= tmp0
;
5601 alu
.src
[0].chan
= 0;
5604 alu
.src
[1].sel
= tmp2
;
5605 alu
.src
[1].chan
= 0;
5607 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5610 alu
.last
= (j
== 3);
5611 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5616 alu
.op
= ALU_OP2_MULHI_UINT
;
5622 alu
.src
[0].sel
= tmp0
;
5623 alu
.src
[0].chan
= 0;
5626 alu
.src
[1].sel
= tmp2
;
5627 alu
.src
[1].chan
= 0;
5629 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5633 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5637 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5638 if (ctx
->bc
->chip_class
== CAYMAN
) {
5639 for (j
= 0 ; j
< 4; j
++) {
5640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5641 alu
.op
= ALU_OP2_MULLO_UINT
;
5645 alu
.dst
.write
= (j
== 1);
5648 alu
.src
[0].sel
= tmp2
;
5649 alu
.src
[0].chan
= 1;
5651 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5654 alu
.src
[1].sel
= tmp0
;
5655 alu
.src
[1].chan
= 2;
5657 alu
.last
= (j
== 3);
5658 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5662 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5663 alu
.op
= ALU_OP2_MULLO_UINT
;
5670 alu
.src
[0].sel
= tmp2
;
5671 alu
.src
[0].chan
= 1;
5673 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5676 alu
.src
[1].sel
= tmp0
;
5677 alu
.src
[1].chan
= 2;
5680 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5684 /* 12. tmp0.w = src1 - tmp0.y = r */
5685 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5686 alu
.op
= ALU_OP2_SUB_INT
;
5693 alu
.src
[0].sel
= tmp2
;
5694 alu
.src
[0].chan
= 0;
5696 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5699 alu
.src
[1].sel
= tmp0
;
5700 alu
.src
[1].chan
= 1;
5703 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5706 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5707 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5708 alu
.op
= ALU_OP2_SETGE_UINT
;
5714 alu
.src
[0].sel
= tmp0
;
5715 alu
.src
[0].chan
= 3;
5717 alu
.src
[1].sel
= tmp2
;
5718 alu
.src
[1].chan
= 1;
5720 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5724 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5727 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5729 alu
.op
= ALU_OP2_SETGE_UINT
;
5736 alu
.src
[0].sel
= tmp2
;
5737 alu
.src
[0].chan
= 0;
5739 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5742 alu
.src
[1].sel
= tmp0
;
5743 alu
.src
[1].chan
= 1;
5746 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5749 if (mod
) { /* UMOD */
5751 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5752 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5753 alu
.op
= ALU_OP2_SUB_INT
;
5759 alu
.src
[0].sel
= tmp0
;
5760 alu
.src
[0].chan
= 3;
5763 alu
.src
[1].sel
= tmp2
;
5764 alu
.src
[1].chan
= 1;
5766 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5770 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5773 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
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
= 3;
5784 alu
.src
[1].sel
= tmp2
;
5785 alu
.src
[1].chan
= 1;
5787 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5791 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5796 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5798 alu
.op
= ALU_OP2_ADD_INT
;
5804 alu
.src
[0].sel
= tmp0
;
5805 alu
.src
[0].chan
= 2;
5806 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5809 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5812 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5813 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5814 alu
.op
= ALU_OP2_ADD_INT
;
5820 alu
.src
[0].sel
= tmp0
;
5821 alu
.src
[0].chan
= 2;
5822 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5825 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5830 /* 17. tmp1.x = tmp1.x & tmp1.y */
5831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5832 alu
.op
= ALU_OP2_AND_INT
;
5838 alu
.src
[0].sel
= tmp1
;
5839 alu
.src
[0].chan
= 0;
5840 alu
.src
[1].sel
= tmp1
;
5841 alu
.src
[1].chan
= 1;
5844 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5847 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5848 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5849 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5850 alu
.op
= ALU_OP3_CNDE_INT
;
5857 alu
.src
[0].sel
= tmp1
;
5858 alu
.src
[0].chan
= 0;
5859 alu
.src
[1].sel
= tmp0
;
5860 alu
.src
[1].chan
= mod
? 3 : 2;
5861 alu
.src
[2].sel
= tmp1
;
5862 alu
.src
[2].chan
= 2;
5865 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5868 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5870 alu
.op
= ALU_OP3_CNDE_INT
;
5878 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5881 alu
.src
[0].sel
= tmp1
;
5882 alu
.src
[0].chan
= 1;
5883 alu
.src
[1].sel
= tmp1
;
5884 alu
.src
[1].chan
= 3;
5885 alu
.src
[2].sel
= tmp0
;
5886 alu
.src
[2].chan
= 2;
5889 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5894 /* fix the sign of the result */
5898 /* tmp0.x = -tmp0.z */
5899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5900 alu
.op
= ALU_OP2_SUB_INT
;
5906 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5907 alu
.src
[1].sel
= tmp0
;
5908 alu
.src
[1].chan
= 2;
5911 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5914 /* sign of the remainder is the same as the sign of src0 */
5915 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
5916 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5917 alu
.op
= ALU_OP3_CNDGE_INT
;
5920 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5922 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5923 alu
.src
[1].sel
= tmp0
;
5924 alu
.src
[1].chan
= 2;
5925 alu
.src
[2].sel
= tmp0
;
5926 alu
.src
[2].chan
= 0;
5929 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5934 /* tmp0.x = -tmp0.z */
5935 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5936 alu
.op
= ALU_OP2_SUB_INT
;
5942 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5943 alu
.src
[1].sel
= tmp0
;
5944 alu
.src
[1].chan
= 2;
5947 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5950 /* fix the quotient sign (same as the sign of src0*src1) */
5951 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
5952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5953 alu
.op
= ALU_OP3_CNDGE_INT
;
5956 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5958 alu
.src
[0].sel
= tmp2
;
5959 alu
.src
[0].chan
= 2;
5960 alu
.src
[1].sel
= tmp0
;
5961 alu
.src
[1].chan
= 2;
5962 alu
.src
[2].sel
= tmp0
;
5963 alu
.src
[2].chan
= 0;
5966 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5974 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
5976 return tgsi_divmod(ctx
, 0, 0);
5979 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
5981 return tgsi_divmod(ctx
, 1, 0);
5984 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
5986 return tgsi_divmod(ctx
, 0, 1);
5989 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
5991 return tgsi_divmod(ctx
, 1, 1);
5995 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
5997 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5998 struct r600_bytecode_alu alu
;
6000 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6001 int last_inst
= tgsi_last_instruction(write_mask
);
6003 for (i
= 0; i
< 4; i
++) {
6004 if (!(write_mask
& (1<<i
)))
6007 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6008 alu
.op
= ALU_OP1_TRUNC
;
6010 alu
.dst
.sel
= ctx
->temp_reg
;
6014 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6017 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6022 for (i
= 0; i
< 4; i
++) {
6023 if (!(write_mask
& (1<<i
)))
6026 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6027 alu
.op
= ctx
->inst_info
->op
;
6029 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6031 alu
.src
[0].sel
= ctx
->temp_reg
;
6032 alu
.src
[0].chan
= i
;
6034 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6036 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6044 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6046 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6047 struct r600_bytecode_alu alu
;
6049 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6050 int last_inst
= tgsi_last_instruction(write_mask
);
6053 for (i
= 0; i
< 4; i
++) {
6054 if (!(write_mask
& (1<<i
)))
6057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6058 alu
.op
= ALU_OP2_SUB_INT
;
6060 alu
.dst
.sel
= ctx
->temp_reg
;
6064 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6065 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6074 /* dst = (src >= 0 ? src : tmp) */
6075 for (i
= 0; i
< 4; i
++) {
6076 if (!(write_mask
& (1<<i
)))
6079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6080 alu
.op
= ALU_OP3_CNDGE_INT
;
6084 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6086 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6087 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6088 alu
.src
[2].sel
= ctx
->temp_reg
;
6089 alu
.src
[2].chan
= i
;
6093 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6100 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6102 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6103 struct r600_bytecode_alu alu
;
6105 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6106 int last_inst
= tgsi_last_instruction(write_mask
);
6108 /* tmp = (src >= 0 ? src : -1) */
6109 for (i
= 0; i
< 4; i
++) {
6110 if (!(write_mask
& (1<<i
)))
6113 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6114 alu
.op
= ALU_OP3_CNDGE_INT
;
6117 alu
.dst
.sel
= ctx
->temp_reg
;
6121 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6122 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6123 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6127 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6132 /* dst = (tmp > 0 ? 1 : tmp) */
6133 for (i
= 0; i
< 4; i
++) {
6134 if (!(write_mask
& (1<<i
)))
6137 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6138 alu
.op
= ALU_OP3_CNDGT_INT
;
6142 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6144 alu
.src
[0].sel
= ctx
->temp_reg
;
6145 alu
.src
[0].chan
= i
;
6147 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6149 alu
.src
[2].sel
= ctx
->temp_reg
;
6150 alu
.src
[2].chan
= i
;
6154 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6163 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6165 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6166 struct r600_bytecode_alu alu
;
6169 /* tmp = (src > 0 ? 1 : src) */
6170 for (i
= 0; i
< 4; i
++) {
6171 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6172 alu
.op
= ALU_OP3_CNDGT
;
6175 alu
.dst
.sel
= ctx
->temp_reg
;
6178 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6179 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6180 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6184 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6189 /* dst = (-tmp > 0 ? -1 : tmp) */
6190 for (i
= 0; i
< 4; i
++) {
6191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6192 alu
.op
= ALU_OP3_CNDGT
;
6194 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6196 alu
.src
[0].sel
= ctx
->temp_reg
;
6197 alu
.src
[0].chan
= i
;
6200 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6203 alu
.src
[2].sel
= ctx
->temp_reg
;
6204 alu
.src
[2].chan
= i
;
6208 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6215 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6217 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6218 struct r600_bytecode_alu alu
;
6221 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6222 int last_inst
= tgsi_last_instruction(write_mask
);
6224 t1
= r600_get_temp(ctx
);
6226 for (i
= 0; i
< 4; i
++) {
6227 if (!(write_mask
& (1<<i
)))
6230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6231 alu
.op
= ALU_OP2_SETGE_INT
;
6232 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6233 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6234 alu
.src
[1].value
= 32;
6235 alu
.dst
.sel
= ctx
->temp_reg
;
6238 alu
.last
= i
== last_inst
;
6239 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6244 for (i
= 0; i
< 4; i
++) {
6245 if (!(write_mask
& (1<<i
)))
6248 /* create mask tmp */
6249 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6250 alu
.op
= ALU_OP2_BFM_INT
;
6254 alu
.last
= i
== last_inst
;
6256 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6257 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6259 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6264 t2
= r600_get_temp(ctx
);
6266 for (i
= 0; i
< 4; i
++) {
6267 if (!(write_mask
& (1<<i
)))
6270 /* shift insert left */
6271 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6272 alu
.op
= ALU_OP2_LSHL_INT
;
6276 alu
.last
= i
== last_inst
;
6278 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6279 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6286 for (i
= 0; i
< 4; i
++) {
6287 if (!(write_mask
& (1<<i
)))
6290 /* actual bitfield insert */
6291 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6292 alu
.op
= ALU_OP3_BFI_INT
;
6294 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6297 alu
.last
= i
== last_inst
;
6299 alu
.src
[0].sel
= t1
;
6300 alu
.src
[0].chan
= i
;
6301 alu
.src
[1].sel
= t2
;
6302 alu
.src
[1].chan
= i
;
6303 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6310 for (i
= 0; i
< 4; i
++) {
6311 if (!(write_mask
& (1<<i
)))
6313 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6314 alu
.op
= ALU_OP3_CNDE_INT
;
6316 alu
.src
[0].sel
= ctx
->temp_reg
;
6317 alu
.src
[0].chan
= i
;
6318 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6320 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6322 alu
.src
[1].sel
= alu
.dst
.sel
;
6323 alu
.src
[1].chan
= i
;
6325 alu
.last
= i
== last_inst
;
6326 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6333 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6335 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6336 struct r600_bytecode_alu alu
;
6339 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6340 int last_inst
= tgsi_last_instruction(write_mask
);
6342 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6343 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6347 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6348 for (i
= 0; i
< 4; i
++) {
6349 if (!(write_mask
& (1<<i
)))
6352 /* t1 = FFBH_INT / FFBH_UINT */
6353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6354 alu
.op
= ctx
->inst_info
->op
;
6358 alu
.last
= i
== last_inst
;
6360 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6362 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6367 t2
= r600_get_temp(ctx
);
6369 for (i
= 0; i
< 4; i
++) {
6370 if (!(write_mask
& (1<<i
)))
6374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6375 alu
.op
= ALU_OP2_SUB_INT
;
6379 alu
.last
= i
== last_inst
;
6381 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6382 alu
.src
[0].value
= 31;
6383 alu
.src
[1].sel
= t1
;
6384 alu
.src
[1].chan
= i
;
6386 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6391 for (i
= 0; i
< 4; i
++) {
6392 if (!(write_mask
& (1<<i
)))
6395 /* result = t1 >= 0 ? t2 : t1 */
6396 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6397 alu
.op
= ALU_OP3_CNDGE_INT
;
6399 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6402 alu
.last
= i
== last_inst
;
6404 alu
.src
[0].sel
= t1
;
6405 alu
.src
[0].chan
= i
;
6406 alu
.src
[1].sel
= t2
;
6407 alu
.src
[1].chan
= i
;
6408 alu
.src
[2].sel
= t1
;
6409 alu
.src
[2].chan
= i
;
6411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6419 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6421 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6422 struct r600_bytecode_alu alu
;
6423 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6425 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6427 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6429 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6430 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6431 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6432 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6435 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6438 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6441 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6442 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6444 /* NOTE: currently offset is not perspective correct */
6445 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6446 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6447 int sample_gpr
= -1;
6448 int gradientsH
, gradientsV
;
6449 struct r600_bytecode_tex tex
;
6451 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6452 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6455 gradientsH
= r600_get_temp(ctx
);
6456 gradientsV
= r600_get_temp(ctx
);
6457 for (i
= 0; i
< 2; i
++) {
6458 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6459 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6460 tex
.src_gpr
= interp_gpr
;
6461 tex
.src_sel_x
= interp_base_chan
+ 0;
6462 tex
.src_sel_y
= interp_base_chan
+ 1;
6465 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6470 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6472 tex
.resource_id
= tex
.sampler_id
;
6473 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6478 for (i
= 0; i
< 2; i
++) {
6479 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6480 alu
.op
= ALU_OP3_MULADD
;
6482 alu
.src
[0].sel
= gradientsH
;
6483 alu
.src
[0].chan
= i
;
6484 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6485 alu
.src
[1].sel
= sample_gpr
;
6486 alu
.src
[1].chan
= 2;
6489 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6491 alu
.src
[2].sel
= interp_gpr
;
6492 alu
.src
[2].chan
= interp_base_chan
+ i
;
6493 alu
.dst
.sel
= ctx
->temp_reg
;
6497 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6502 for (i
= 0; i
< 2; i
++) {
6503 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6504 alu
.op
= ALU_OP3_MULADD
;
6506 alu
.src
[0].sel
= gradientsV
;
6507 alu
.src
[0].chan
= i
;
6508 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6509 alu
.src
[1].sel
= sample_gpr
;
6510 alu
.src
[1].chan
= 3;
6513 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6515 alu
.src
[2].sel
= ctx
->temp_reg
;
6516 alu
.src
[2].chan
= i
;
6517 alu
.dst
.sel
= ctx
->temp_reg
;
6521 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6527 tmp
= r600_get_temp(ctx
);
6528 for (i
= 0; i
< 8; i
++) {
6529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6530 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6533 if ((i
> 1 && i
< 6)) {
6539 alu
.dst
.chan
= i
% 4;
6541 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6542 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6543 alu
.src
[0].sel
= ctx
->temp_reg
;
6544 alu
.src
[0].chan
= 1 - (i
% 2);
6546 alu
.src
[0].sel
= interp_gpr
;
6547 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6549 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6550 alu
.src
[1].chan
= 0;
6552 alu
.last
= i
% 4 == 3;
6553 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6555 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6560 // INTERP can't swizzle dst
6561 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6562 for (i
= 0; i
<= lasti
; i
++) {
6563 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6566 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6567 alu
.op
= ALU_OP1_MOV
;
6568 alu
.src
[0].sel
= tmp
;
6569 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6570 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6572 alu
.last
= i
== lasti
;
6573 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6582 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6584 struct r600_bytecode_alu alu
;
6587 for (i
= 0; i
< 4; i
++) {
6588 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6589 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6590 alu
.op
= ALU_OP0_NOP
;
6593 alu
.op
= ALU_OP1_MOV
;
6594 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6595 alu
.src
[0].sel
= ctx
->temp_reg
;
6596 alu
.src
[0].chan
= i
;
6601 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6608 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6609 unsigned temp
, int chan
,
6610 struct r600_bytecode_alu_src
*bc_src
,
6611 const struct r600_shader_src
*shader_src
)
6613 struct r600_bytecode_alu alu
;
6616 r600_bytecode_src(bc_src
, shader_src
, chan
);
6618 /* op3 operands don't support abs modifier */
6620 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6621 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6622 alu
.op
= ALU_OP1_MOV
;
6624 alu
.dst
.chan
= chan
;
6627 alu
.src
[0] = *bc_src
;
6628 alu
.last
= true; // sufficient?
6629 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6633 memset(bc_src
, 0, sizeof(*bc_src
));
6635 bc_src
->chan
= chan
;
6640 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6642 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6643 struct r600_bytecode_alu alu
;
6645 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6647 unsigned op
= ctx
->inst_info
->op
;
6649 if (op
== ALU_OP3_MULADD_IEEE
&&
6650 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6651 op
= ALU_OP3_MULADD
;
6653 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6655 if (ctx
->src
[j
].abs
)
6656 temp_regs
[j
] = r600_get_temp(ctx
);
6658 for (i
= 0; i
< lasti
+ 1; i
++) {
6659 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6662 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6664 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6665 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6670 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6677 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6684 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6686 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6687 struct r600_bytecode_alu alu
;
6689 unsigned op
= ctx
->inst_info
->op
;
6690 if (op
== ALU_OP2_DOT4_IEEE
&&
6691 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6694 for (i
= 0; i
< 4; i
++) {
6695 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6697 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6698 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6701 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6703 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6704 /* handle some special cases */
6705 switch (inst
->Instruction
.Opcode
) {
6706 case TGSI_OPCODE_DP2
:
6708 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6709 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6712 case TGSI_OPCODE_DP3
:
6714 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6715 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6724 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6731 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6734 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6735 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6736 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6737 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6738 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6739 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6742 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6745 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6746 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6749 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6751 struct r600_bytecode_vtx vtx
;
6752 struct r600_bytecode_alu alu
;
6753 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6755 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6757 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6758 if (src_requires_loading
) {
6759 for (i
= 0; i
< 4; i
++) {
6760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6761 alu
.op
= ALU_OP1_MOV
;
6762 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6763 alu
.dst
.sel
= ctx
->temp_reg
;
6768 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6772 src_gpr
= ctx
->temp_reg
;
6775 memset(&vtx
, 0, sizeof(vtx
));
6776 vtx
.op
= FETCH_OP_VFETCH
;
6777 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6778 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6779 vtx
.src_gpr
= src_gpr
;
6780 vtx
.mega_fetch_count
= 16;
6781 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6782 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6783 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6784 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6785 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6786 vtx
.use_const_fields
= 1;
6788 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6791 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6794 for (i
= 0; i
< 4; i
++) {
6795 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6796 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6800 alu
.op
= ALU_OP2_AND_INT
;
6803 alu
.dst
.sel
= vtx
.dst_gpr
;
6806 alu
.src
[0].sel
= vtx
.dst_gpr
;
6807 alu
.src
[0].chan
= i
;
6809 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6810 alu
.src
[1].sel
+= (id
* 2);
6811 alu
.src
[1].chan
= i
% 4;
6812 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6816 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6821 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6823 alu
.op
= ALU_OP2_OR_INT
;
6826 alu
.dst
.sel
= vtx
.dst_gpr
;
6829 alu
.src
[0].sel
= vtx
.dst_gpr
;
6830 alu
.src
[0].chan
= 3;
6832 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6833 alu
.src
[1].chan
= 0;
6834 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6837 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6844 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
)
6846 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6847 struct r600_bytecode_alu alu
;
6849 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
6851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6852 alu
.op
= ALU_OP1_MOV
;
6853 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6854 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6855 /* channel 0 or 2 of each word */
6856 alu
.src
[0].sel
+= (id
/ 2);
6857 alu
.src
[0].chan
= (id
% 2) * 2;
6859 /* r600 we have them at channel 2 of the second dword */
6860 alu
.src
[0].sel
+= (id
* 2) + 1;
6861 alu
.src
[0].chan
= 1;
6863 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6864 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6866 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6872 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6874 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6875 struct r600_bytecode_tex tex
;
6876 struct r600_bytecode_alu alu
;
6880 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
6881 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6882 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
6883 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
6885 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
6886 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6887 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
6889 /* Texture fetch instructions can only use gprs as source.
6890 * Also they cannot negate the source or take the absolute value */
6891 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
6892 tgsi_tex_src_requires_loading(ctx
, 0)) ||
6893 read_compressed_msaa
|| txf_add_offsets
;
6895 boolean src_loaded
= FALSE
;
6896 unsigned sampler_src_reg
= 1;
6897 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
6898 boolean has_txq_cube_array_z
= false;
6899 unsigned sampler_index_mode
;
6901 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
6902 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6903 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
6904 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
6905 ctx
->shader
->has_txq_cube_array_z_comp
= true;
6906 has_txq_cube_array_z
= true;
6909 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
6910 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6911 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
6912 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
6913 sampler_src_reg
= 2;
6915 /* TGSI moves the sampler to src reg 3 for TXD */
6916 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
6917 sampler_src_reg
= 3;
6919 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6921 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6923 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
6924 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
6925 ctx
->shader
->uses_tex_buffers
= true;
6926 return r600_do_buffer_txq(ctx
, 1, 0);
6928 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
6929 if (ctx
->bc
->chip_class
< EVERGREEN
)
6930 ctx
->shader
->uses_tex_buffers
= true;
6931 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
6935 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
6937 /* Add perspective divide */
6938 if (ctx
->bc
->chip_class
== CAYMAN
) {
6940 for (i
= 0; i
< 3; i
++) {
6941 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6942 alu
.op
= ALU_OP1_RECIP_IEEE
;
6943 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6945 alu
.dst
.sel
= ctx
->temp_reg
;
6951 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6958 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6959 alu
.op
= ALU_OP1_RECIP_IEEE
;
6960 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6962 alu
.dst
.sel
= ctx
->temp_reg
;
6963 alu
.dst
.chan
= out_chan
;
6966 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6971 for (i
= 0; i
< 3; i
++) {
6972 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6973 alu
.op
= ALU_OP2_MUL
;
6974 alu
.src
[0].sel
= ctx
->temp_reg
;
6975 alu
.src
[0].chan
= out_chan
;
6976 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6977 alu
.dst
.sel
= ctx
->temp_reg
;
6980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6985 alu
.op
= ALU_OP1_MOV
;
6986 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6987 alu
.src
[0].chan
= 0;
6988 alu
.dst
.sel
= ctx
->temp_reg
;
6992 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6996 src_gpr
= ctx
->temp_reg
;
7000 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7001 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7002 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7003 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7004 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7006 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7007 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7009 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7010 for (i
= 0; i
< 4; i
++) {
7011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7012 alu
.op
= ALU_OP2_CUBE
;
7013 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7014 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7015 alu
.dst
.sel
= ctx
->temp_reg
;
7020 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7025 /* tmp1.z = RCP_e(|tmp1.z|) */
7026 if (ctx
->bc
->chip_class
== CAYMAN
) {
7027 for (i
= 0; i
< 3; i
++) {
7028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7029 alu
.op
= ALU_OP1_RECIP_IEEE
;
7030 alu
.src
[0].sel
= ctx
->temp_reg
;
7031 alu
.src
[0].chan
= 2;
7033 alu
.dst
.sel
= ctx
->temp_reg
;
7039 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7045 alu
.op
= ALU_OP1_RECIP_IEEE
;
7046 alu
.src
[0].sel
= ctx
->temp_reg
;
7047 alu
.src
[0].chan
= 2;
7049 alu
.dst
.sel
= ctx
->temp_reg
;
7053 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7058 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7059 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7060 * muladd has no writemask, have to use another temp
7062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7063 alu
.op
= ALU_OP3_MULADD
;
7066 alu
.src
[0].sel
= ctx
->temp_reg
;
7067 alu
.src
[0].chan
= 0;
7068 alu
.src
[1].sel
= ctx
->temp_reg
;
7069 alu
.src
[1].chan
= 2;
7071 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7072 alu
.src
[2].chan
= 0;
7073 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7075 alu
.dst
.sel
= ctx
->temp_reg
;
7079 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7083 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7084 alu
.op
= ALU_OP3_MULADD
;
7087 alu
.src
[0].sel
= ctx
->temp_reg
;
7088 alu
.src
[0].chan
= 1;
7089 alu
.src
[1].sel
= ctx
->temp_reg
;
7090 alu
.src
[1].chan
= 2;
7092 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7093 alu
.src
[2].chan
= 0;
7094 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7096 alu
.dst
.sel
= ctx
->temp_reg
;
7101 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7104 /* write initial compare value into Z component
7105 - W src 0 for shadow cube
7106 - X src 1 for shadow cube array */
7107 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7108 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7109 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7110 alu
.op
= ALU_OP1_MOV
;
7111 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7112 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7114 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7115 alu
.dst
.sel
= ctx
->temp_reg
;
7119 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7124 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7125 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7126 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7127 int mytmp
= r600_get_temp(ctx
);
7128 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7129 alu
.op
= ALU_OP1_MOV
;
7130 alu
.src
[0].sel
= ctx
->temp_reg
;
7131 alu
.src
[0].chan
= 3;
7132 alu
.dst
.sel
= mytmp
;
7136 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7140 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7142 alu
.op
= ALU_OP3_MULADD
;
7144 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7145 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7146 alu
.src
[1].chan
= 0;
7147 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7148 alu
.src
[2].sel
= mytmp
;
7149 alu
.src
[2].chan
= 0;
7150 alu
.dst
.sel
= ctx
->temp_reg
;
7154 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7157 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7158 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7159 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7160 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7161 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7162 tex
.src_gpr
= r600_get_temp(ctx
);
7167 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7168 tex
.coord_type_x
= 1;
7169 tex
.coord_type_y
= 1;
7170 tex
.coord_type_z
= 1;
7171 tex
.coord_type_w
= 1;
7172 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7173 alu
.op
= ALU_OP1_MOV
;
7174 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7175 alu
.dst
.sel
= tex
.src_gpr
;
7179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7183 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7190 /* for cube forms of lod and bias we need to route things */
7191 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7192 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7193 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7194 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7196 alu
.op
= ALU_OP1_MOV
;
7197 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7198 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7199 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7201 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7202 alu
.dst
.sel
= ctx
->temp_reg
;
7206 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7212 src_gpr
= ctx
->temp_reg
;
7215 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7216 int temp_h
= 0, temp_v
= 0;
7219 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7220 if (src_loaded
== TRUE
)
7224 for (i
= start_val
; i
< 3; i
++) {
7225 int treg
= r600_get_temp(ctx
);
7234 for (j
= 0; j
< 4; j
++) {
7235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7236 alu
.op
= ALU_OP1_MOV
;
7237 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7243 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7248 for (i
= 1; i
< 3; i
++) {
7249 /* set gradients h/v */
7250 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7251 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7252 FETCH_OP_SET_GRADIENTS_V
;
7253 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7254 tex
.sampler_index_mode
= sampler_index_mode
;
7255 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7256 tex
.resource_index_mode
= sampler_index_mode
;
7258 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7264 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7265 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7266 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7267 tex
.coord_type_x
= 1;
7268 tex
.coord_type_y
= 1;
7269 tex
.coord_type_z
= 1;
7270 tex
.coord_type_w
= 1;
7272 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7278 if (src_requires_loading
&& !src_loaded
) {
7279 for (i
= 0; i
< 4; i
++) {
7280 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7281 alu
.op
= ALU_OP1_MOV
;
7282 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7283 alu
.dst
.sel
= ctx
->temp_reg
;
7288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7293 src_gpr
= ctx
->temp_reg
;
7296 /* get offset values */
7297 if (inst
->Texture
.NumOffsets
) {
7298 assert(inst
->Texture
.NumOffsets
== 1);
7300 /* The texture offset feature doesn't work with the TXF instruction
7301 * and must be emulated by adding the offset to the texture coordinates. */
7302 if (txf_add_offsets
) {
7303 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7305 switch (inst
->Texture
.Texture
) {
7306 case TGSI_TEXTURE_3D
:
7307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7308 alu
.op
= ALU_OP2_ADD_INT
;
7309 alu
.src
[0].sel
= src_gpr
;
7310 alu
.src
[0].chan
= 2;
7311 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7312 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7313 alu
.dst
.sel
= src_gpr
;
7317 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7322 case TGSI_TEXTURE_2D
:
7323 case TGSI_TEXTURE_SHADOW2D
:
7324 case TGSI_TEXTURE_RECT
:
7325 case TGSI_TEXTURE_SHADOWRECT
:
7326 case TGSI_TEXTURE_2D_ARRAY
:
7327 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7328 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7329 alu
.op
= ALU_OP2_ADD_INT
;
7330 alu
.src
[0].sel
= src_gpr
;
7331 alu
.src
[0].chan
= 1;
7332 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7333 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7334 alu
.dst
.sel
= src_gpr
;
7338 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7343 case TGSI_TEXTURE_1D
:
7344 case TGSI_TEXTURE_SHADOW1D
:
7345 case TGSI_TEXTURE_1D_ARRAY
:
7346 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7348 alu
.op
= ALU_OP2_ADD_INT
;
7349 alu
.src
[0].sel
= src_gpr
;
7350 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7351 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7352 alu
.dst
.sel
= src_gpr
;
7355 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7359 /* texture offsets do not apply to other texture targets */
7362 switch (inst
->Texture
.Texture
) {
7363 case TGSI_TEXTURE_3D
:
7364 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7366 case TGSI_TEXTURE_2D
:
7367 case TGSI_TEXTURE_SHADOW2D
:
7368 case TGSI_TEXTURE_RECT
:
7369 case TGSI_TEXTURE_SHADOWRECT
:
7370 case TGSI_TEXTURE_2D_ARRAY
:
7371 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7372 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7374 case TGSI_TEXTURE_1D
:
7375 case TGSI_TEXTURE_SHADOW1D
:
7376 case TGSI_TEXTURE_1D_ARRAY
:
7377 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7378 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7383 /* Obtain the sample index for reading a compressed MSAA color texture.
7384 * To read the FMASK, we use the ldfptr instruction, which tells us
7385 * where the samples are stored.
7386 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7387 * which is the identity mapping. Each nibble says which physical sample
7388 * should be fetched to get that sample.
7390 * Assume src.z contains the sample index. It should be modified like this:
7391 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7392 * Then fetch the texel with src.
7394 if (read_compressed_msaa
) {
7395 unsigned sample_chan
= 3;
7396 unsigned temp
= r600_get_temp(ctx
);
7399 /* temp.w = ldfptr() */
7400 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7401 tex
.op
= FETCH_OP_LD
;
7402 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7403 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7404 tex
.sampler_index_mode
= sampler_index_mode
;
7405 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7406 tex
.resource_index_mode
= sampler_index_mode
;
7407 tex
.src_gpr
= src_gpr
;
7409 tex
.dst_sel_x
= 7; /* mask out these components */
7412 tex
.dst_sel_w
= 0; /* store X */
7417 tex
.offset_x
= offset_x
;
7418 tex
.offset_y
= offset_y
;
7419 tex
.offset_z
= offset_z
;
7420 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7424 /* temp.x = sample_index*4 */
7425 if (ctx
->bc
->chip_class
== CAYMAN
) {
7426 for (i
= 0 ; i
< 4; i
++) {
7427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7428 alu
.op
= ALU_OP2_MULLO_INT
;
7429 alu
.src
[0].sel
= src_gpr
;
7430 alu
.src
[0].chan
= sample_chan
;
7431 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7432 alu
.src
[1].value
= 4;
7435 alu
.dst
.write
= i
== 0;
7438 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7444 alu
.op
= ALU_OP2_MULLO_INT
;
7445 alu
.src
[0].sel
= src_gpr
;
7446 alu
.src
[0].chan
= sample_chan
;
7447 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7448 alu
.src
[1].value
= 4;
7453 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7458 /* sample_index = temp.w >> temp.x */
7459 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7460 alu
.op
= ALU_OP2_LSHR_INT
;
7461 alu
.src
[0].sel
= temp
;
7462 alu
.src
[0].chan
= 3;
7463 alu
.src
[1].sel
= temp
;
7464 alu
.src
[1].chan
= 0;
7465 alu
.dst
.sel
= src_gpr
;
7466 alu
.dst
.chan
= sample_chan
;
7469 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7473 /* sample_index & 0xF */
7474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7475 alu
.op
= ALU_OP2_AND_INT
;
7476 alu
.src
[0].sel
= src_gpr
;
7477 alu
.src
[0].chan
= sample_chan
;
7478 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7479 alu
.src
[1].value
= 0xF;
7480 alu
.dst
.sel
= src_gpr
;
7481 alu
.dst
.chan
= sample_chan
;
7484 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7488 /* visualize the FMASK */
7489 for (i
= 0; i
< 4; i
++) {
7490 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7491 alu
.op
= ALU_OP1_INT_TO_FLT
;
7492 alu
.src
[0].sel
= src_gpr
;
7493 alu
.src
[0].chan
= sample_chan
;
7494 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7498 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7506 /* does this shader want a num layers from TXQ for a cube array? */
7507 if (has_txq_cube_array_z
) {
7508 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7510 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7511 alu
.op
= ALU_OP1_MOV
;
7513 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7514 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7515 /* channel 1 or 3 of each word */
7516 alu
.src
[0].sel
+= (id
/ 2);
7517 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
7519 /* r600 we have them at channel 2 of the second dword */
7520 alu
.src
[0].sel
+= (id
* 2) + 1;
7521 alu
.src
[0].chan
= 2;
7523 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7524 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7526 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7529 /* disable writemask from texture instruction */
7530 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7533 opcode
= ctx
->inst_info
->op
;
7534 if (opcode
== FETCH_OP_GATHER4
&&
7535 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7536 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7537 opcode
= FETCH_OP_GATHER4_O
;
7539 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7540 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7541 encoded in the instruction are ignored. */
7542 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7543 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7544 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7545 tex
.sampler_index_mode
= sampler_index_mode
;
7546 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7547 tex
.resource_index_mode
= sampler_index_mode
;
7549 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7550 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7551 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7552 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7560 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7565 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7566 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7567 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7568 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7569 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7570 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7571 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7573 case FETCH_OP_SAMPLE
:
7574 opcode
= FETCH_OP_SAMPLE_C
;
7576 case FETCH_OP_SAMPLE_L
:
7577 opcode
= FETCH_OP_SAMPLE_C_L
;
7579 case FETCH_OP_SAMPLE_LB
:
7580 opcode
= FETCH_OP_SAMPLE_C_LB
;
7582 case FETCH_OP_SAMPLE_G
:
7583 opcode
= FETCH_OP_SAMPLE_C_G
;
7585 /* Texture gather variants */
7586 case FETCH_OP_GATHER4
:
7587 opcode
= FETCH_OP_GATHER4_C
;
7589 case FETCH_OP_GATHER4_O
:
7590 opcode
= FETCH_OP_GATHER4_C_O
;
7595 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7598 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7599 tex
.sampler_index_mode
= sampler_index_mode
;
7600 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7601 tex
.resource_index_mode
= sampler_index_mode
;
7602 tex
.src_gpr
= src_gpr
;
7603 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7605 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7606 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7607 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7610 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7611 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7612 tex
.inst_mod
= texture_component_select
;
7614 if (ctx
->bc
->chip_class
== CAYMAN
) {
7615 /* GATHER4 result order is different from TGSI TG4 */
7616 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7617 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7618 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7619 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7621 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7622 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7623 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7624 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7627 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7628 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7629 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7633 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7640 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7641 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7642 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7643 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7647 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7652 } else if (src_loaded
) {
7658 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7659 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7660 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7661 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7662 tex
.src_rel
= ctx
->src
[0].rel
;
7665 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7666 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7667 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7668 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7672 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7675 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7676 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7677 tex
.coord_type_x
= 1;
7678 tex
.coord_type_y
= 1;
7680 tex
.coord_type_z
= 1;
7681 tex
.coord_type_w
= 1;
7683 tex
.offset_x
= offset_x
;
7684 tex
.offset_y
= offset_y
;
7685 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7686 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7687 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7691 tex
.offset_z
= offset_z
;
7694 /* Put the depth for comparison in W.
7695 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7696 * Some instructions expect the depth in Z. */
7697 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7698 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7699 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7700 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7701 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7702 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7703 tex
.src_sel_w
= tex
.src_sel_z
;
7706 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7707 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7708 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7709 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7710 /* the array index is read from Y */
7711 tex
.coord_type_y
= 0;
7713 /* the array index is read from Z */
7714 tex
.coord_type_z
= 0;
7715 tex
.src_sel_z
= tex
.src_sel_y
;
7717 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7718 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7719 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7720 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7721 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7722 /* the array index is read from Z */
7723 tex
.coord_type_z
= 0;
7725 /* mask unused source components */
7726 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7727 switch (inst
->Texture
.Texture
) {
7728 case TGSI_TEXTURE_2D
:
7729 case TGSI_TEXTURE_RECT
:
7733 case TGSI_TEXTURE_1D_ARRAY
:
7737 case TGSI_TEXTURE_1D
:
7745 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7749 /* add shadow ambient support - gallium doesn't do it yet */
7753 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7754 struct tgsi_full_src_register
*src
)
7758 if (src
->Register
.Indirect
) {
7759 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7760 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7761 return ctx
->shader
->atomics
[i
].hw_idx
;
7764 uint32_t index
= src
->Register
.Index
;
7765 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7766 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
7768 if (index
> ctx
->shader
->atomics
[i
].end
)
7770 if (index
< ctx
->shader
->atomics
[i
].start
)
7772 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7773 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7781 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
7783 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7785 struct r600_bytecode_gds gds
;
7787 int uav_index_mode
= 0;
7789 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7791 if (inst
->Src
[0].Register
.Indirect
)
7794 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7795 gds
.op
= FETCH_OP_GDS_READ_RET
;
7796 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7797 gds
.uav_id
= uav_id
;
7798 gds
.uav_index_mode
= uav_index_mode
;
7799 gds
.src_gpr
= ctx
->temp_reg
;
7807 gds
.src_gpr2
= ctx
->temp_reg
;
7808 gds
.alloc_consume
= 1;
7809 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7813 ctx
->bc
->cf_last
->vpm
= 1;
7817 /* this fixes up 1D arrays properly */
7818 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
7820 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7822 struct r600_bytecode_alu alu
;
7823 int temp_reg
= r600_get_temp(ctx
);
7825 for (i
= 0; i
< 4; i
++) {
7826 bool def_val
= true, write_zero
= false;
7827 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7828 alu
.op
= ALU_OP1_MOV
;
7829 alu
.dst
.sel
= temp_reg
;
7832 switch (inst
->Memory
.Texture
) {
7833 case TGSI_TEXTURE_BUFFER
:
7834 case TGSI_TEXTURE_1D
:
7835 if (i
== 1 || i
== 2 || i
== 3) {
7839 case TGSI_TEXTURE_1D_ARRAY
:
7840 if (i
== 1 || i
== 3)
7843 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
7847 case TGSI_TEXTURE_2D
:
7848 if (i
== 2 || i
== 3)
7858 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
7859 alu
.src
[0].value
= 0;
7860 } else if (def_val
) {
7861 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
7867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7871 *idx_gpr
= temp_reg
;
7875 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
7877 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7878 /* have to work out the offset into the RAT immediate return buffer */
7879 struct r600_bytecode_vtx vtx
;
7880 struct r600_bytecode_cf
*cf
;
7883 unsigned format
, num_format
, format_comp
, endian
;
7884 const struct util_format_description
*desc
;
7885 unsigned rat_index_mode
;
7886 unsigned immed_base
;
7888 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7890 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
7891 r
= load_index_src(ctx
, 1, &idx_gpr
);
7896 egcm_load_index_reg(ctx
->bc
, 1, false);
7898 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
7899 cf
= ctx
->bc
->cf_last
;
7901 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
7902 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
7903 cf
->rat
.index_mode
= rat_index_mode
;
7904 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
7905 cf
->output
.gpr
= ctx
->thread_id_gpr
;
7906 cf
->output
.index_gpr
= idx_gpr
;
7907 cf
->output
.comp_mask
= 0xf;
7908 cf
->output
.burst_count
= 1;
7912 cf
->output
.elem_size
= 0;
7914 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
7915 cf
= ctx
->bc
->cf_last
;
7918 desc
= util_format_description(inst
->Memory
.Format
);
7919 r600_vertex_data_type(inst
->Memory
.Format
,
7920 &format
, &num_format
, &format_comp
, &endian
);
7921 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
7922 vtx
.op
= FETCH_OP_VFETCH
;
7923 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
7924 vtx
.buffer_index_mode
= rat_index_mode
;
7925 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7926 vtx
.src_gpr
= ctx
->thread_id_gpr
;
7928 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7929 vtx
.dst_sel_x
= desc
->swizzle
[0];
7930 vtx
.dst_sel_y
= desc
->swizzle
[1];
7931 vtx
.dst_sel_z
= desc
->swizzle
[2];
7932 vtx
.dst_sel_w
= desc
->swizzle
[3];
7933 vtx
.srf_mode_all
= 1;
7934 vtx
.data_format
= format
;
7935 vtx
.num_format_all
= num_format
;
7936 vtx
.format_comp_all
= format_comp
;
7937 vtx
.endian
= endian
;
7939 vtx
.mega_fetch_count
= 3;
7940 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
7943 cf
= ctx
->bc
->cf_last
;
7948 static int tgsi_load(struct r600_shader_ctx
*ctx
)
7950 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7951 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
7952 return tgsi_load_rat(ctx
);
7953 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
7954 return tgsi_load_gds(ctx
);
7958 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
7960 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7961 struct r600_bytecode_cf
*cf
;
7962 bool src_requires_loading
= false;
7963 int val_gpr
, idx_gpr
;
7965 unsigned rat_index_mode
;
7967 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7969 r
= load_index_src(ctx
, 0, &idx_gpr
);
7973 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
7974 src_requires_loading
= true;
7976 if (src_requires_loading
) {
7977 struct r600_bytecode_alu alu
;
7978 for (i
= 0; i
< 4; i
++) {
7979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7980 alu
.op
= ALU_OP1_MOV
;
7981 alu
.dst
.sel
= ctx
->temp_reg
;
7984 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
7988 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7992 val_gpr
= ctx
->temp_reg
;
7994 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
7996 egcm_load_index_reg(ctx
->bc
, 1, false);
7998 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
7999 cf
= ctx
->bc
->cf_last
;
8001 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8002 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8003 cf
->rat
.index_mode
= rat_index_mode
;
8004 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8005 cf
->output
.gpr
= val_gpr
;
8006 cf
->output
.index_gpr
= idx_gpr
;
8007 cf
->output
.comp_mask
= 0xf;
8008 cf
->output
.burst_count
= 1;
8011 cf
->output
.elem_size
= 0;
8015 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8017 return tgsi_store_rat(ctx
);
8020 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8022 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8023 /* have to work out the offset into the RAT immediate return buffer */
8024 struct r600_bytecode_alu alu
;
8025 struct r600_bytecode_vtx vtx
;
8026 struct r600_bytecode_cf
*cf
;
8029 unsigned format
, num_format
, format_comp
, endian
;
8030 const struct util_format_description
*desc
;
8031 unsigned rat_index_mode
;
8032 unsigned immed_base
;
8034 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8036 assert (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
);
8037 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8039 r
= load_index_src(ctx
, 1, &idx_gpr
);
8043 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8045 alu
.op
= ALU_OP1_MOV
;
8046 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8049 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8051 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8056 alu
.op
= ALU_OP1_MOV
;
8057 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8060 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8066 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8067 alu
.op
= ALU_OP1_MOV
;
8068 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8071 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8079 egcm_load_index_reg(ctx
->bc
, 1, false);
8080 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8081 cf
= ctx
->bc
->cf_last
;
8083 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8084 cf
->rat
.inst
= ctx
->inst_info
->op
;
8085 cf
->rat
.index_mode
= rat_index_mode
;
8086 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8087 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8088 cf
->output
.index_gpr
= idx_gpr
;
8089 cf
->output
.comp_mask
= 0xf;
8090 cf
->output
.burst_count
= 1;
8094 cf
->output
.elem_size
= 0;
8095 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8096 cf
= ctx
->bc
->cf_last
;
8100 desc
= util_format_description(inst
->Memory
.Format
);
8101 r600_vertex_data_type(inst
->Memory
.Format
,
8102 &format
, &num_format
, &format_comp
, &endian
);
8103 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8104 vtx
.op
= FETCH_OP_VFETCH
;
8105 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8106 vtx
.buffer_index_mode
= rat_index_mode
;
8107 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8108 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8110 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8111 vtx
.dst_sel_x
= desc
->swizzle
[0];
8115 vtx
.use_const_fields
= 0;
8116 vtx
.srf_mode_all
= 1;
8117 vtx
.data_format
= format
;
8118 vtx
.num_format_all
= num_format
;
8119 vtx
.format_comp_all
= format_comp
;
8120 vtx
.endian
= endian
;
8122 vtx
.mega_fetch_count
= 0xf;
8123 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8126 cf
= ctx
->bc
->cf_last
;
8132 static int get_gds_op(int opcode
)
8135 case TGSI_OPCODE_ATOMUADD
:
8136 return FETCH_OP_GDS_ADD_RET
;
8137 case TGSI_OPCODE_ATOMAND
:
8138 return FETCH_OP_GDS_AND_RET
;
8139 case TGSI_OPCODE_ATOMOR
:
8140 return FETCH_OP_GDS_OR_RET
;
8141 case TGSI_OPCODE_ATOMXOR
:
8142 return FETCH_OP_GDS_XOR_RET
;
8143 case TGSI_OPCODE_ATOMUMIN
:
8144 return FETCH_OP_GDS_MIN_UINT_RET
;
8145 case TGSI_OPCODE_ATOMUMAX
:
8146 return FETCH_OP_GDS_MAX_UINT_RET
;
8147 case TGSI_OPCODE_ATOMXCHG
:
8148 return FETCH_OP_GDS_XCHG_RET
;
8149 case TGSI_OPCODE_ATOMCAS
:
8150 return FETCH_OP_GDS_CMP_XCHG_RET
;
8156 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8158 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8159 struct r600_bytecode_gds gds
;
8160 struct r600_bytecode_alu alu
;
8161 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8164 int uav_index_mode
= 0;
8167 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8171 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
8173 if (inst
->Src
[0].Register
.Indirect
)
8176 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8177 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8178 int abs_value
= abs(value
);
8179 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8180 gds_op
= FETCH_OP_GDS_SUB_RET
;
8181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8182 alu
.op
= ALU_OP1_MOV
;
8183 alu
.dst
.sel
= ctx
->temp_reg
;
8185 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8186 alu
.src
[0].value
= abs_value
;
8189 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8194 alu
.op
= ALU_OP1_MOV
;
8195 alu
.dst
.sel
= ctx
->temp_reg
;
8197 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8205 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8207 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8208 gds
.uav_id
= uav_id
;
8209 gds
.uav_index_mode
= uav_index_mode
;
8210 gds
.src_gpr
= ctx
->temp_reg
;
8211 gds
.src_gpr2
= ctx
->temp_reg
;
8219 gds
.alloc_consume
= 1;
8220 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8223 ctx
->bc
->cf_last
->vpm
= 1;
8227 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
8229 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8230 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8231 return tgsi_atomic_op_rat(ctx
);
8232 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8233 return tgsi_atomic_op_gds(ctx
);
8237 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
8239 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8240 unsigned sampler_index_mode
;
8241 struct r600_bytecode_tex tex
;
8243 boolean has_txq_cube_array_z
= false;
8245 if (inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
) {
8246 ctx
->shader
->uses_tex_buffers
= true;
8247 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
);
8250 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
8251 inst
->Dst
[0].Register
.WriteMask
& 4) {
8252 ctx
->shader
->has_txq_cube_array_z_comp
= true;
8253 has_txq_cube_array_z
= true;
8256 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8257 if (sampler_index_mode
)
8258 egcm_load_index_reg(ctx
->bc
, 1, false);
8261 /* does this shader want a num layers from TXQ for a cube array? */
8262 if (has_txq_cube_array_z
) {
8263 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
8264 struct r600_bytecode_alu alu
;
8266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8267 alu
.op
= ALU_OP1_MOV
;
8269 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8270 /* channel 1 or 3 of each word */
8271 alu
.src
[0].sel
+= (id
/ 2);
8272 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
8273 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8274 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8276 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8279 /* disable writemask from texture instruction */
8280 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8282 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8283 tex
.op
= ctx
->inst_info
->op
;
8284 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
8285 tex
.sampler_index_mode
= sampler_index_mode
;
8286 tex
.resource_id
= tex
.sampler_id
;
8287 tex
.resource_index_mode
= sampler_index_mode
;
8292 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8293 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8294 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8295 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8296 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8297 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8304 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
8306 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8307 struct r600_bytecode_alu alu
;
8308 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8309 unsigned i
, temp_regs
[2];
8312 /* optimize if it's just an equal balance */
8313 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
8314 for (i
= 0; i
< lasti
+ 1; i
++) {
8315 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8318 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8319 alu
.op
= ALU_OP2_ADD
;
8320 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8321 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8323 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8328 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8336 for (i
= 0; i
< lasti
+ 1; i
++) {
8337 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8341 alu
.op
= ALU_OP2_ADD
;
8342 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8343 alu
.src
[0].chan
= 0;
8344 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
8345 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
8346 alu
.dst
.sel
= ctx
->temp_reg
;
8352 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8357 /* (1 - src0) * src2 */
8358 for (i
= 0; i
< lasti
+ 1; i
++) {
8359 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8363 alu
.op
= ALU_OP2_MUL
;
8364 alu
.src
[0].sel
= ctx
->temp_reg
;
8365 alu
.src
[0].chan
= i
;
8366 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8367 alu
.dst
.sel
= ctx
->temp_reg
;
8373 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8378 /* src0 * src1 + (1 - src0) * src2 */
8379 if (ctx
->src
[0].abs
)
8380 temp_regs
[0] = r600_get_temp(ctx
);
8383 if (ctx
->src
[1].abs
)
8384 temp_regs
[1] = r600_get_temp(ctx
);
8388 for (i
= 0; i
< lasti
+ 1; i
++) {
8389 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8393 alu
.op
= ALU_OP3_MULADD
;
8395 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8398 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
8401 alu
.src
[2].sel
= ctx
->temp_reg
;
8402 alu
.src
[2].chan
= i
;
8404 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8409 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8416 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
8418 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8419 struct r600_bytecode_alu alu
;
8421 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8425 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
8427 ctx
->src
[0].abs
= 0;
8428 ctx
->src
[0].neg
= 0;
8433 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
8435 if (ctx
->src
[j
].abs
)
8436 temp_regs
[j
] = r600_get_temp(ctx
);
8439 for (i
= 0; i
< lasti
+ 1; i
++) {
8440 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8445 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8448 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
8451 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
8454 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8460 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8467 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
8469 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8470 struct r600_bytecode_alu alu
;
8472 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8474 for (i
= 0; i
< lasti
+ 1; i
++) {
8475 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8478 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8479 alu
.op
= ALU_OP3_CNDE_INT
;
8480 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8481 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8482 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
8483 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8489 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8496 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
8498 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8499 struct r600_bytecode_alu alu
;
8503 /* result.x = 2^floor(src); */
8504 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8505 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8507 alu
.op
= ALU_OP1_FLOOR
;
8508 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8510 alu
.dst
.sel
= ctx
->temp_reg
;
8514 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8518 if (ctx
->bc
->chip_class
== CAYMAN
) {
8519 for (i
= 0; i
< 3; i
++) {
8520 alu
.op
= ALU_OP1_EXP_IEEE
;
8521 alu
.src
[0].sel
= ctx
->temp_reg
;
8522 alu
.src
[0].chan
= 0;
8524 alu
.dst
.sel
= ctx
->temp_reg
;
8526 alu
.dst
.write
= i
== 0;
8528 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8533 alu
.op
= ALU_OP1_EXP_IEEE
;
8534 alu
.src
[0].sel
= ctx
->temp_reg
;
8535 alu
.src
[0].chan
= 0;
8537 alu
.dst
.sel
= ctx
->temp_reg
;
8541 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8547 /* result.y = tmp - floor(tmp); */
8548 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8551 alu
.op
= ALU_OP1_FRACT
;
8552 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8554 alu
.dst
.sel
= ctx
->temp_reg
;
8556 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8565 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8570 /* result.z = RoughApprox2ToX(tmp);*/
8571 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
8572 if (ctx
->bc
->chip_class
== CAYMAN
) {
8573 for (i
= 0; i
< 3; i
++) {
8574 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8575 alu
.op
= ALU_OP1_EXP_IEEE
;
8576 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8578 alu
.dst
.sel
= ctx
->temp_reg
;
8585 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8590 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8591 alu
.op
= ALU_OP1_EXP_IEEE
;
8592 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8594 alu
.dst
.sel
= ctx
->temp_reg
;
8600 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8606 /* result.w = 1.0;*/
8607 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
8608 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8610 alu
.op
= ALU_OP1_MOV
;
8611 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8612 alu
.src
[0].chan
= 0;
8614 alu
.dst
.sel
= ctx
->temp_reg
;
8618 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8622 return tgsi_helper_copy(ctx
, inst
);
8625 static int tgsi_log(struct r600_shader_ctx
*ctx
)
8627 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8628 struct r600_bytecode_alu alu
;
8632 /* result.x = floor(log2(|src|)); */
8633 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8634 if (ctx
->bc
->chip_class
== CAYMAN
) {
8635 for (i
= 0; i
< 3; i
++) {
8636 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8638 alu
.op
= ALU_OP1_LOG_IEEE
;
8639 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8640 r600_bytecode_src_set_abs(&alu
.src
[0]);
8642 alu
.dst
.sel
= ctx
->temp_reg
;
8648 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8656 alu
.op
= ALU_OP1_LOG_IEEE
;
8657 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8658 r600_bytecode_src_set_abs(&alu
.src
[0]);
8660 alu
.dst
.sel
= ctx
->temp_reg
;
8664 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8669 alu
.op
= ALU_OP1_FLOOR
;
8670 alu
.src
[0].sel
= ctx
->temp_reg
;
8671 alu
.src
[0].chan
= 0;
8673 alu
.dst
.sel
= ctx
->temp_reg
;
8678 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8683 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
8684 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8686 if (ctx
->bc
->chip_class
== CAYMAN
) {
8687 for (i
= 0; i
< 3; i
++) {
8688 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8690 alu
.op
= ALU_OP1_LOG_IEEE
;
8691 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8692 r600_bytecode_src_set_abs(&alu
.src
[0]);
8694 alu
.dst
.sel
= ctx
->temp_reg
;
8701 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8706 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8708 alu
.op
= ALU_OP1_LOG_IEEE
;
8709 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8710 r600_bytecode_src_set_abs(&alu
.src
[0]);
8712 alu
.dst
.sel
= ctx
->temp_reg
;
8717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8722 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8724 alu
.op
= ALU_OP1_FLOOR
;
8725 alu
.src
[0].sel
= ctx
->temp_reg
;
8726 alu
.src
[0].chan
= 1;
8728 alu
.dst
.sel
= ctx
->temp_reg
;
8733 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8737 if (ctx
->bc
->chip_class
== CAYMAN
) {
8738 for (i
= 0; i
< 3; i
++) {
8739 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8740 alu
.op
= ALU_OP1_EXP_IEEE
;
8741 alu
.src
[0].sel
= ctx
->temp_reg
;
8742 alu
.src
[0].chan
= 1;
8744 alu
.dst
.sel
= ctx
->temp_reg
;
8751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8756 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8757 alu
.op
= ALU_OP1_EXP_IEEE
;
8758 alu
.src
[0].sel
= ctx
->temp_reg
;
8759 alu
.src
[0].chan
= 1;
8761 alu
.dst
.sel
= ctx
->temp_reg
;
8766 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8771 if (ctx
->bc
->chip_class
== CAYMAN
) {
8772 for (i
= 0; i
< 3; i
++) {
8773 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8774 alu
.op
= ALU_OP1_RECIP_IEEE
;
8775 alu
.src
[0].sel
= ctx
->temp_reg
;
8776 alu
.src
[0].chan
= 1;
8778 alu
.dst
.sel
= ctx
->temp_reg
;
8785 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8790 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8791 alu
.op
= ALU_OP1_RECIP_IEEE
;
8792 alu
.src
[0].sel
= ctx
->temp_reg
;
8793 alu
.src
[0].chan
= 1;
8795 alu
.dst
.sel
= ctx
->temp_reg
;
8800 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8805 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8807 alu
.op
= ALU_OP2_MUL
;
8809 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8810 r600_bytecode_src_set_abs(&alu
.src
[0]);
8812 alu
.src
[1].sel
= ctx
->temp_reg
;
8813 alu
.src
[1].chan
= 1;
8815 alu
.dst
.sel
= ctx
->temp_reg
;
8820 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8825 /* result.z = log2(|src|);*/
8826 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
8827 if (ctx
->bc
->chip_class
== CAYMAN
) {
8828 for (i
= 0; i
< 3; i
++) {
8829 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8831 alu
.op
= ALU_OP1_LOG_IEEE
;
8832 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8833 r600_bytecode_src_set_abs(&alu
.src
[0]);
8835 alu
.dst
.sel
= ctx
->temp_reg
;
8842 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8847 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8849 alu
.op
= ALU_OP1_LOG_IEEE
;
8850 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8851 r600_bytecode_src_set_abs(&alu
.src
[0]);
8853 alu
.dst
.sel
= ctx
->temp_reg
;
8858 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8864 /* result.w = 1.0; */
8865 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
8866 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8868 alu
.op
= ALU_OP1_MOV
;
8869 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8870 alu
.src
[0].chan
= 0;
8872 alu
.dst
.sel
= ctx
->temp_reg
;
8877 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8882 return tgsi_helper_copy(ctx
, inst
);
8885 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
8887 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8888 struct r600_bytecode_alu alu
;
8890 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8891 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
8893 assert(inst
->Dst
[0].Register
.Index
< 3);
8894 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8896 switch (inst
->Instruction
.Opcode
) {
8897 case TGSI_OPCODE_ARL
:
8898 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
8900 case TGSI_OPCODE_ARR
:
8901 alu
.op
= ALU_OP1_FLT_TO_INT
;
8903 case TGSI_OPCODE_UARL
:
8904 alu
.op
= ALU_OP1_MOV
;
8911 for (i
= 0; i
<= lasti
; ++i
) {
8912 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8914 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8915 alu
.last
= i
== lasti
;
8919 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8924 if (inst
->Dst
[0].Register
.Index
> 0)
8925 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
8927 ctx
->bc
->ar_loaded
= 0;
8931 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
8933 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8934 struct r600_bytecode_alu alu
;
8936 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8938 switch (inst
->Instruction
.Opcode
) {
8939 case TGSI_OPCODE_ARL
:
8940 memset(&alu
, 0, sizeof(alu
));
8941 alu
.op
= ALU_OP1_FLOOR
;
8942 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8944 for (i
= 0; i
<= lasti
; ++i
) {
8945 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8947 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8948 alu
.last
= i
== lasti
;
8949 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8954 memset(&alu
, 0, sizeof(alu
));
8955 alu
.op
= ALU_OP1_FLT_TO_INT
;
8956 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
8957 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8959 /* FLT_TO_INT is trans-only on r600/r700 */
8961 for (i
= 0; i
<= lasti
; ++i
) {
8963 alu
.src
[0].chan
= i
;
8964 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8968 case TGSI_OPCODE_ARR
:
8969 memset(&alu
, 0, sizeof(alu
));
8970 alu
.op
= ALU_OP1_FLT_TO_INT
;
8971 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8973 /* FLT_TO_INT is trans-only on r600/r700 */
8975 for (i
= 0; i
<= lasti
; ++i
) {
8976 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8978 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8979 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8984 case TGSI_OPCODE_UARL
:
8985 memset(&alu
, 0, sizeof(alu
));
8986 alu
.op
= ALU_OP1_MOV
;
8987 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8989 for (i
= 0; i
<= lasti
; ++i
) {
8990 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8992 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8993 alu
.last
= i
== lasti
;
8994 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9004 ctx
->bc
->ar_loaded
= 0;
9008 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9010 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9011 struct r600_bytecode_alu alu
;
9014 for (i
= 0; i
< 4; i
++) {
9015 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9017 alu
.op
= ALU_OP2_MUL
;
9018 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9020 if (i
== 0 || i
== 3) {
9021 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9023 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9026 if (i
== 0 || i
== 2) {
9027 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9029 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9040 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
9042 struct r600_bytecode_alu alu
;
9045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9047 alu
.execute_mask
= 1;
9048 alu
.update_pred
= 1;
9050 alu
.dst
.sel
= ctx
->temp_reg
;
9054 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9055 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9056 alu
.src
[1].chan
= 0;
9060 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9066 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9068 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9072 if (ctx
->bc
->cf_last
) {
9073 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9075 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9080 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9081 ctx
->bc
->force_add_cf
= 1;
9082 } else if (alu_pop
== 2) {
9083 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9084 ctx
->bc
->force_add_cf
= 1;
9091 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9092 ctx
->bc
->cf_last
->pop_count
= pops
;
9093 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9099 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9102 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9106 unsigned entry_size
= stack
->entry_size
;
9108 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9109 elements
+= stack
->push
;
9111 switch (ctx
->bc
->chip_class
) {
9114 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9115 * the stack must be reserved to hold the current active/continue
9117 if (reason
== FC_PUSH_VPM
) {
9123 /* r9xx: any stack operation on empty stack consumes 2 additional
9128 /* FIXME: do the two elements added above cover the cases for the
9132 /* r8xx+: 2 extra elements are not always required, but one extra
9133 * element must be added for each of the following cases:
9134 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9136 * (Currently we don't use ALU_ELSE_AFTER.)
9137 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9138 * PUSH instruction executed.
9140 * NOTE: it seems we also need to reserve additional element in some
9141 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9142 * then STACK_SIZE should be 2 instead of 1 */
9143 if (reason
== FC_PUSH_VPM
) {
9153 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9154 * for all chips, so we use 4 in the final formula, not the real entry_size
9158 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9160 if (entries
> stack
->max_entries
)
9161 stack
->max_entries
= entries
;
9164 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9168 --ctx
->bc
->stack
.push
;
9169 assert(ctx
->bc
->stack
.push
>= 0);
9172 --ctx
->bc
->stack
.push_wqm
;
9173 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9176 --ctx
->bc
->stack
.loop
;
9177 assert(ctx
->bc
->stack
.loop
>= 0);
9185 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
9189 ++ctx
->bc
->stack
.push
;
9192 ++ctx
->bc
->stack
.push_wqm
;
9194 ++ctx
->bc
->stack
.loop
;
9200 callstack_update_max_depth(ctx
, reason
);
9203 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
9205 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
9207 sp
->mid
= realloc((void *)sp
->mid
,
9208 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
9209 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
9213 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
9215 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
9216 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
9217 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
9221 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
9223 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
9233 static int emit_return(struct r600_shader_ctx
*ctx
)
9235 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
9239 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
9242 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
9243 ctx
->bc
->cf_last
->pop_count
= pops
;
9244 /* XXX work out offset */
9248 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
9253 static void emit_testflag(struct r600_shader_ctx
*ctx
)
9258 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
9261 emit_jump_to_offset(ctx
, 1, 4);
9262 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
9263 pops(ctx
, ifidx
+ 1);
9267 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
9271 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9272 ctx
->bc
->cf_last
->pop_count
= 1;
9274 fc_set_mid(ctx
, fc_sp
);
9280 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
9282 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
9284 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
9285 * LOOP_STARTxxx for nested loops may put the branch stack into a state
9286 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
9287 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
9288 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
9289 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
9290 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9291 alu_type
= CF_OP_ALU
;
9294 emit_logic_pred(ctx
, opcode
, alu_type
);
9296 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
9298 fc_pushlevel(ctx
, FC_IF
);
9300 callstack_push(ctx
, FC_PUSH_VPM
);
9304 static int tgsi_if(struct r600_shader_ctx
*ctx
)
9306 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
9309 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
9311 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
9314 static int tgsi_else(struct r600_shader_ctx
*ctx
)
9316 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
9317 ctx
->bc
->cf_last
->pop_count
= 1;
9319 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
9320 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
9324 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
9327 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
9328 R600_ERR("if/endif unbalanced in shader\n");
9332 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
9333 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9334 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
9336 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9340 callstack_pop(ctx
, FC_PUSH_VPM
);
9344 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
9346 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
9347 * limited to 4096 iterations, like the other LOOP_* instructions. */
9348 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
9350 fc_pushlevel(ctx
, FC_LOOP
);
9352 /* check stack depth */
9353 callstack_push(ctx
, FC_LOOP
);
9357 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
9361 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
9363 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
9364 R600_ERR("loop/endloop in shader code are not paired.\n");
9368 /* fixup loop pointers - from r600isa
9369 LOOP END points to CF after LOOP START,
9370 LOOP START point to CF after LOOP END
9371 BRK/CONT point to LOOP END CF
9373 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
9375 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9377 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
9378 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
9380 /* XXX add LOOPRET support */
9382 callstack_pop(ctx
, FC_LOOP
);
9386 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
9390 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
9392 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
9397 R600_ERR("Break not inside loop/endloop pair\n");
9401 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9403 fc_set_mid(ctx
, fscp
- 1);
9408 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
9410 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9411 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
9414 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9415 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
9417 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9419 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
9420 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9421 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
9426 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
9428 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9429 struct r600_bytecode_alu alu
;
9431 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9434 for (i
= 0; i
< lasti
+ 1; i
++) {
9435 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9438 if (ctx
->bc
->chip_class
== CAYMAN
) {
9439 for (j
= 0 ; j
< 4; j
++) {
9440 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9442 alu
.op
= ALU_OP2_MULLO_UINT
;
9443 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
9444 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
9447 alu
.dst
.sel
= ctx
->temp_reg
;
9448 alu
.dst
.write
= (j
== i
);
9451 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9456 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9459 alu
.dst
.sel
= ctx
->temp_reg
;
9462 alu
.op
= ALU_OP2_MULLO_UINT
;
9463 for (j
= 0; j
< 2; j
++) {
9464 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
9468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9475 for (i
= 0; i
< lasti
+ 1; i
++) {
9476 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9479 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9480 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9482 alu
.op
= ALU_OP2_ADD_INT
;
9484 alu
.src
[0].sel
= ctx
->temp_reg
;
9485 alu
.src
[0].chan
= i
;
9487 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9491 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9498 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
9500 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9501 struct r600_bytecode_alu alu
;
9503 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9505 /* temp.xy = f32_to_f16(src) */
9506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9507 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
9509 alu
.dst
.sel
= ctx
->temp_reg
;
9511 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9512 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9516 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
9518 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9522 /* dst.x = temp.y * 0x10000 + temp.x */
9523 for (i
= 0; i
< lasti
+ 1; i
++) {
9524 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9527 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9528 alu
.op
= ALU_OP3_MULADD_UINT24
;
9530 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9531 alu
.last
= i
== lasti
;
9532 alu
.src
[0].sel
= ctx
->temp_reg
;
9533 alu
.src
[0].chan
= 1;
9534 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9535 alu
.src
[1].value
= 0x10000;
9536 alu
.src
[2].sel
= ctx
->temp_reg
;
9537 alu
.src
[2].chan
= 0;
9538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9546 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
9548 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9549 struct r600_bytecode_alu alu
;
9551 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9553 /* temp.x = src.x */
9554 /* note: no need to mask out the high bits */
9555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9556 alu
.op
= ALU_OP1_MOV
;
9558 alu
.dst
.sel
= ctx
->temp_reg
;
9560 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9565 /* temp.y = src.x >> 16 */
9566 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9567 alu
.op
= ALU_OP2_LSHR_INT
;
9569 alu
.dst
.sel
= ctx
->temp_reg
;
9571 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9572 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9573 alu
.src
[1].value
= 16;
9575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9579 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
9580 for (i
= 0; i
< lasti
+ 1; i
++) {
9581 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9583 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9584 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9585 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
9586 alu
.src
[0].sel
= ctx
->temp_reg
;
9587 alu
.src
[0].chan
= i
% 2;
9588 alu
.last
= i
== lasti
;
9589 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9597 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
9599 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9600 struct r600_bytecode_alu alu
;
9601 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9608 for (i
= 0; i
< lasti
+ 1; i
++) {
9609 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9610 alu
.op
= ALU_OP2_SETGE_INT
;
9611 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
9612 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9613 alu
.src
[1].value
= 32;
9614 alu
.dst
.sel
= ctx
->temp_reg
;
9619 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9624 for (i
= 0; i
< lasti
+ 1; i
++) {
9625 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9626 alu
.op
= ALU_OP3_CNDE_INT
;
9628 alu
.src
[0].sel
= ctx
->temp_reg
;
9629 alu
.src
[1].chan
= i
;
9631 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9632 alu
.src
[1].sel
= alu
.dst
.sel
;
9633 alu
.src
[1].chan
= i
;
9634 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
9638 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9646 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
9647 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9648 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9649 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9651 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9653 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
9654 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9655 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9656 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9657 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9658 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9659 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9660 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9661 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
9662 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9663 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9664 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9665 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9666 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9667 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9668 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9669 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9670 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9671 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9672 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9673 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9674 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9675 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9676 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9677 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9678 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9679 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9680 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9681 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9682 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9683 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9684 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9685 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9686 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9687 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9688 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9689 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9690 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9691 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9692 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9693 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9694 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9695 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9696 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9697 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9698 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9699 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9700 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9701 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9702 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9703 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9704 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9705 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9706 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9707 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9708 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9709 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9710 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9711 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9712 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9713 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9714 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9715 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9716 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9717 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9718 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9719 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9720 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9721 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9722 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9723 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9724 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9725 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9726 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9727 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9728 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9729 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9730 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
9731 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9732 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9733 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9734 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9735 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9736 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
9737 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9738 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9739 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9740 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9741 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9742 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9743 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9744 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9745 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9746 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9747 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9748 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9749 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9750 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9751 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9752 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9753 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9754 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9755 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9756 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9757 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9758 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9759 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9760 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9761 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9762 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9763 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9764 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9765 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9766 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9767 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9768 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
9769 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9770 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9771 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9772 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9773 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9774 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
9775 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9776 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
9777 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9778 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9779 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9780 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9781 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9782 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9783 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9784 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9785 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9786 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9787 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
9788 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9789 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
9790 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9791 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9792 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9793 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9794 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9795 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9796 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9797 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9798 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9799 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9800 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9801 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9802 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9803 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9804 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9805 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9806 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
9807 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9808 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9809 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9810 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9811 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9812 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
9813 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
9814 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
9815 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9816 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9817 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9818 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9819 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9820 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9821 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9822 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9823 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9824 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9825 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9826 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9827 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9828 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9829 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9830 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9831 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
9832 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
9833 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
9834 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
9835 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9836 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
9837 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
9838 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
9839 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
9840 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
9841 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9842 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9843 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9844 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9847 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
9848 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9849 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9850 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9851 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9852 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
9853 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9854 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9855 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
9856 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9857 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9858 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9859 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9860 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
9861 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
9862 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9863 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9864 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
9865 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9866 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
9867 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9868 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
9869 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9870 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9871 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9872 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
9873 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9874 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9875 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9876 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9877 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9878 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
9879 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9880 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
9881 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9882 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
9883 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9884 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9885 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9886 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9887 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
9888 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9889 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9890 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9891 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9892 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9893 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9894 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9895 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9896 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9897 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9898 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9899 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9900 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9901 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9902 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
9903 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9904 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9905 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9906 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9907 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9908 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9909 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9910 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9911 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9912 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9913 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9914 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
9915 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9916 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9917 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9918 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
9919 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9920 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9921 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9922 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9923 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9924 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9925 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9926 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9927 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9928 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
9929 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9930 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9931 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9932 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9933 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9934 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9935 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9936 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9937 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9938 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9939 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
9940 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9941 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9942 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9943 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9944 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9945 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9946 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9947 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9948 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9949 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9950 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9951 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
9952 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9953 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9954 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9955 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9956 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9957 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9958 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9959 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
9960 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9961 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
9962 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9963 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9964 /* Refer below for TGSI_OPCODE_DFMA */
9965 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
9966 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9967 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9968 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9969 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9970 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9971 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9972 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9973 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
9974 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9975 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9976 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9977 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9978 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9979 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9980 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9981 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9982 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9983 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9984 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9985 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9986 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9987 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9988 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9989 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9990 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9991 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9992 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9993 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9994 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9995 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9996 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9997 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9998 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9999 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10000 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10001 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10002 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10003 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10004 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10005 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10006 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10007 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10008 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10009 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10010 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10011 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10012 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10013 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10014 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10015 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10016 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10017 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10018 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10019 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10020 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10021 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10022 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10023 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10024 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10025 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10026 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10027 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10028 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10029 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10030 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10031 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10032 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10033 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10034 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10035 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10036 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10037 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10038 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10039 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10040 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10041 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10042 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10043 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10044 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10045 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10046 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10047 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10048 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10049 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10050 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10051 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10052 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10053 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10054 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10055 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10056 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10057 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10058 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10059 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10060 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10061 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10062 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10063 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10064 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10065 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10066 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10069 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
10070 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10071 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10072 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10073 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
10074 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
10075 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10076 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10077 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10078 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10079 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10080 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10081 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10082 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10083 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10084 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10085 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10086 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10087 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10088 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10089 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
10090 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10091 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10092 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10093 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10094 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10095 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10096 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10097 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
10098 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
10099 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
10100 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10101 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10102 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10103 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10104 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10105 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
10106 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10107 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10108 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10109 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10110 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10111 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10112 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10113 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10114 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10115 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10116 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10117 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
10118 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10119 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10120 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10121 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10122 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10123 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10124 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10125 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10126 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10127 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10128 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10129 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10130 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10131 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10132 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10133 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10134 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10135 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10136 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10137 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10138 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10139 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10140 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10141 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10142 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10143 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10144 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10145 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10146 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10147 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10148 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10149 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10150 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10151 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10152 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
10153 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10154 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10155 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10156 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10157 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10158 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10159 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10160 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10161 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10162 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10163 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10164 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10165 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10166 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10167 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10168 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10169 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10170 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10171 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10172 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10173 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10174 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10175 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10176 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10177 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10178 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10179 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10180 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10181 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10182 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10183 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10184 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10185 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10186 /* Refer below for TGSI_OPCODE_DFMA */
10187 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
10188 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10189 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10190 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10191 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10192 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10193 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10194 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10195 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
10196 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
10197 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10198 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10199 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10200 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10201 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10202 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10203 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
10204 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10205 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10206 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10207 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10208 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10209 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10210 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10211 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10212 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10213 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10214 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10215 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10216 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10217 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10218 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10219 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10220 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10221 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10222 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10223 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10224 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10225 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10226 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10227 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10228 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10229 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10230 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10231 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10232 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10233 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10234 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10235 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10236 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10237 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10238 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10239 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10240 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10241 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10242 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10243 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10244 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10245 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10246 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10247 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10248 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
10249 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
10250 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10251 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10252 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10253 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10254 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10255 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10256 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10257 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10258 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10259 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10260 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10261 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10262 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10263 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10264 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10265 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10266 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10267 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10268 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10269 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10270 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10271 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10272 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10273 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10274 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10275 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10276 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10277 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10278 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10279 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10280 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10281 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10282 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10283 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10284 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10285 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10286 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10287 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10288 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},