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
);
193 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_COMPUTE
);
195 /* disable SB for shaders using doubles */
196 use_sb
&= !shader
->shader
.uses_doubles
;
198 use_sb
&= !shader
->shader
.uses_atomics
;
199 use_sb
&= !shader
->shader
.uses_images
;
200 use_sb
&= !shader
->shader
.uses_helper_invocation
;
202 /* Check if the bytecode has already been built. */
203 if (!shader
->shader
.bc
.bytecode
) {
204 r
= r600_bytecode_build(&shader
->shader
.bc
);
206 R600_ERR("building bytecode failed !\n");
211 if (dump
&& !sb_disasm
) {
212 fprintf(stderr
, "--------------------------------------------------------------\n");
213 r600_bytecode_disasm(&shader
->shader
.bc
);
214 fprintf(stderr
, "______________________________________________________________\n");
215 } else if ((dump
&& sb_disasm
) || use_sb
) {
216 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
219 R600_ERR("r600_sb_bytecode_process failed !\n");
224 if (shader
->gs_copy_shader
) {
227 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
228 &shader
->gs_copy_shader
->shader
, dump
, 0);
233 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
237 /* Store the shader in a buffer. */
238 if ((r
= store_shader(ctx
, shader
)))
242 switch (shader
->shader
.processor_type
) {
243 case PIPE_SHADER_TESS_CTRL
:
244 evergreen_update_hs_state(ctx
, shader
);
246 case PIPE_SHADER_TESS_EVAL
:
248 evergreen_update_es_state(ctx
, shader
);
250 evergreen_update_vs_state(ctx
, shader
);
252 case PIPE_SHADER_GEOMETRY
:
253 if (rctx
->b
.chip_class
>= EVERGREEN
) {
254 evergreen_update_gs_state(ctx
, shader
);
255 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
257 r600_update_gs_state(ctx
, shader
);
258 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
261 case PIPE_SHADER_VERTEX
:
262 export_shader
= key
.vs
.as_es
;
263 if (rctx
->b
.chip_class
>= EVERGREEN
) {
265 evergreen_update_ls_state(ctx
, shader
);
266 else if (key
.vs
.as_es
)
267 evergreen_update_es_state(ctx
, shader
);
269 evergreen_update_vs_state(ctx
, shader
);
272 r600_update_es_state(ctx
, shader
);
274 r600_update_vs_state(ctx
, shader
);
277 case PIPE_SHADER_FRAGMENT
:
278 if (rctx
->b
.chip_class
>= EVERGREEN
) {
279 evergreen_update_ps_state(ctx
, shader
);
281 r600_update_ps_state(ctx
, shader
);
284 case PIPE_SHADER_COMPUTE
:
285 evergreen_update_ls_state(ctx
, shader
);
294 r600_pipe_shader_destroy(ctx
, shader
);
298 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
300 r600_resource_reference(&shader
->bo
, NULL
);
301 r600_bytecode_clear(&shader
->shader
.bc
);
302 r600_release_command_buffer(&shader
->command_buffer
);
306 * tgsi -> r600 shader
308 struct r600_shader_tgsi_instruction
;
310 struct r600_shader_src
{
317 boolean kc_rel
; /* true if cache bank is indexed */
326 struct r600_shader_ctx
{
327 struct tgsi_shader_info info
;
328 struct tgsi_parse_context parse
;
329 const struct tgsi_token
*tokens
;
331 unsigned file_offset
[TGSI_FILE_COUNT
];
333 const struct r600_shader_tgsi_instruction
*inst_info
;
334 struct r600_bytecode
*bc
;
335 struct r600_shader
*shader
;
336 struct r600_shader_src src
[4];
339 uint32_t max_driver_temp_used
;
340 /* needed for evergreen interpolation */
341 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
342 /* evergreen/cayman also store sample mask in face register */
344 /* sample id is .w component stored in fixed point position register */
345 int fixed_pt_position_gpr
;
347 boolean clip_vertex_write
;
349 unsigned edgeflag_output
;
350 int helper_invoc_reg
;
351 int cs_block_size_reg
;
352 int cs_grid_size_reg
;
353 bool cs_block_size_loaded
, cs_grid_size_loaded
;
355 int next_ring_offset
;
356 int gs_out_ring_offset
;
358 struct r600_shader
*gs_for_vs
;
359 int gs_export_gpr_tregs
[4];
360 int gs_rotated_input
[2];
361 const struct pipe_stream_output_info
*gs_stream_output_info
;
362 unsigned enabled_stream_buffers_mask
;
363 unsigned tess_input_info
; /* temp with tess input offsets */
364 unsigned tess_output_info
; /* temp with tess input offsets */
365 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
366 bool thread_id_gpr_loaded
;
369 struct r600_shader_tgsi_instruction
{
371 int (*process
)(struct r600_shader_ctx
*ctx
);
374 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
375 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
376 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
377 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
378 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
379 static int tgsi_else(struct r600_shader_ctx
*ctx
);
380 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
381 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
382 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
383 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
384 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
385 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
386 unsigned int dst_reg
);
387 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
388 const struct r600_shader_src
*shader_src
,
390 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
391 unsigned dst_reg
, unsigned mask
);
393 static int tgsi_last_instruction(unsigned writemask
)
397 for (i
= 0; i
< 4; i
++) {
398 if (writemask
& (1 << i
)) {
405 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
407 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
410 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
411 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
415 if (i
->Instruction
.Label
) {
416 R600_ERR("label unsupported\n");
420 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
421 if (i
->Src
[j
].Register
.Dimension
) {
422 switch (i
->Src
[j
].Register
.File
) {
423 case TGSI_FILE_CONSTANT
:
424 case TGSI_FILE_HW_ATOMIC
:
426 case TGSI_FILE_INPUT
:
427 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
428 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
429 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
431 case TGSI_FILE_OUTPUT
:
432 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
435 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
436 i
->Src
[j
].Register
.File
,
437 i
->Src
[j
].Register
.Dimension
);
442 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
443 if (i
->Dst
[j
].Register
.Dimension
) {
444 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
446 R600_ERR("unsupported dst (dimension)\n");
453 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
455 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
456 interpolate
== TGSI_INTERPOLATE_LINEAR
||
457 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
459 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
463 case TGSI_INTERPOLATE_LOC_CENTER
:
466 case TGSI_INTERPOLATE_LOC_CENTROID
:
469 case TGSI_INTERPOLATE_LOC_SAMPLE
:
474 return is_linear
* 3 + loc
;
480 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
483 int i
= eg_get_interpolator_index(
484 ctx
->shader
->input
[input
].interpolate
,
485 ctx
->shader
->input
[input
].interpolate_location
);
487 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
490 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
493 struct r600_bytecode_alu alu
;
494 int gpr
= 0, base_chan
= 0;
495 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
497 /* work out gpr and base_chan from index */
499 base_chan
= (2 * (ij_index
% 2)) + 1;
501 for (i
= 0; i
< 8; i
++) {
502 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
505 alu
.op
= ALU_OP2_INTERP_ZW
;
507 alu
.op
= ALU_OP2_INTERP_XY
;
509 if ((i
> 1) && (i
< 6)) {
510 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
514 alu
.dst
.chan
= i
% 4;
516 alu
.src
[0].sel
= gpr
;
517 alu
.src
[0].chan
= (base_chan
- (i
% 2));
519 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
521 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
524 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
531 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
534 struct r600_bytecode_alu alu
;
536 for (i
= 0; i
< 4; i
++) {
537 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
539 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
541 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
546 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
551 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
559 * Special export handling in shaders
561 * shader export ARRAY_BASE for EXPORT_POS:
564 * 62, 63 are clip distance vectors
566 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
567 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
568 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
569 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
570 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
571 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
572 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
573 * exclusive from render target index)
574 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
577 * shader export ARRAY_BASE for EXPORT_PIXEL:
579 * 61 computed Z vector
581 * The use of the values exported in the computed Z vector are controlled
582 * by DB_SHADER_CONTROL:
583 * Z_EXPORT_ENABLE - Z as a float in RED
584 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
585 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
586 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
587 * DB_SOURCE_FORMAT - export control restrictions
592 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
593 static int r600_spi_sid(struct r600_shader_io
* io
)
595 int index
, name
= io
->name
;
597 /* These params are handled differently, they don't need
598 * semantic indices, so we'll use 0 for them.
600 if (name
== TGSI_SEMANTIC_POSITION
||
601 name
== TGSI_SEMANTIC_PSIZE
||
602 name
== TGSI_SEMANTIC_EDGEFLAG
||
603 name
== TGSI_SEMANTIC_FACE
||
604 name
== TGSI_SEMANTIC_SAMPLEMASK
)
607 if (name
== TGSI_SEMANTIC_GENERIC
) {
608 /* For generic params simply use sid from tgsi */
611 /* For non-generic params - pack name and sid into 8 bits */
612 index
= 0x80 | (name
<<3) | (io
->sid
);
615 /* Make sure that all really used indices have nonzero value, so
616 * we can just compare it to 0 later instead of comparing the name
617 * with different values to detect special cases. */
624 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
625 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
627 switch (semantic_name
) {
628 case TGSI_SEMANTIC_POSITION
:
630 case TGSI_SEMANTIC_PSIZE
:
632 case TGSI_SEMANTIC_CLIPDIST
:
635 case TGSI_SEMANTIC_GENERIC
:
637 return 4 + index
- 9;
639 /* same explanation as in the default statement,
640 * the only user hitting this is st/nine.
644 /* patch indices are completely separate and thus start from 0 */
645 case TGSI_SEMANTIC_TESSOUTER
:
647 case TGSI_SEMANTIC_TESSINNER
:
649 case TGSI_SEMANTIC_PATCH
:
653 /* Don't fail here. The result of this function is only used
654 * for LS, TCS, TES, and GS, where legacy GL semantics can't
655 * occur, but this function is called for all vertex shaders
656 * before it's known whether LS will be compiled or not.
662 /* turn input into interpolate on EG */
663 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
667 if (ctx
->shader
->input
[index
].spi_sid
) {
668 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
669 if (ctx
->shader
->input
[index
].interpolate
> 0) {
670 evergreen_interp_assign_ij_index(ctx
, index
);
671 r
= evergreen_interp_alu(ctx
, index
);
673 r
= evergreen_interp_flat(ctx
, index
);
679 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
681 struct r600_bytecode_alu alu
;
683 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
684 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
686 for (i
= 0; i
< 4; i
++) {
687 memset(&alu
, 0, sizeof(alu
));
688 alu
.op
= ALU_OP3_CNDGT
;
691 alu
.dst
.sel
= gpr_front
;
692 alu
.src
[0].sel
= ctx
->face_gpr
;
693 alu
.src
[1].sel
= gpr_front
;
694 alu
.src
[2].sel
= gpr_back
;
701 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
708 /* execute a single slot ALU calculation */
709 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
710 int dst_sel
, int dst_chan
,
711 int src0_sel
, unsigned src0_chan_val
,
712 int src1_sel
, unsigned src1_chan_val
)
714 struct r600_bytecode_alu alu
;
717 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
718 for (i
= 0; i
< 4; i
++) {
719 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
721 alu
.src
[0].sel
= src0_sel
;
722 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
723 alu
.src
[0].value
= src0_chan_val
;
725 alu
.src
[0].chan
= src0_chan_val
;
726 alu
.src
[1].sel
= src1_sel
;
727 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
728 alu
.src
[1].value
= src1_chan_val
;
730 alu
.src
[1].chan
= src1_chan_val
;
731 alu
.dst
.sel
= dst_sel
;
733 alu
.dst
.write
= i
== dst_chan
;
735 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
742 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
744 alu
.src
[0].sel
= src0_sel
;
745 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
746 alu
.src
[0].value
= src0_chan_val
;
748 alu
.src
[0].chan
= src0_chan_val
;
749 alu
.src
[1].sel
= src1_sel
;
750 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
751 alu
.src
[1].value
= src1_chan_val
;
753 alu
.src
[1].chan
= src1_chan_val
;
754 alu
.dst
.sel
= dst_sel
;
755 alu
.dst
.chan
= dst_chan
;
758 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
764 /* execute a single slot ALU calculation */
765 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
766 int dst_sel
, int dst_chan
,
767 int src0_sel
, unsigned src0_chan_val
,
768 int src1_sel
, unsigned src1_chan_val
,
769 int src2_sel
, unsigned src2_chan_val
)
771 struct r600_bytecode_alu alu
;
774 /* validate this for other ops */
775 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
|| op
== ALU_OP3_BFE_UINT
);
776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
778 alu
.src
[0].sel
= src0_sel
;
779 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
780 alu
.src
[0].value
= src0_chan_val
;
782 alu
.src
[0].chan
= src0_chan_val
;
783 alu
.src
[1].sel
= src1_sel
;
784 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
785 alu
.src
[1].value
= src1_chan_val
;
787 alu
.src
[1].chan
= src1_chan_val
;
788 alu
.src
[2].sel
= src2_sel
;
789 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
790 alu
.src
[2].value
= src2_chan_val
;
792 alu
.src
[2].chan
= src2_chan_val
;
793 alu
.dst
.sel
= dst_sel
;
794 alu
.dst
.chan
= dst_chan
;
797 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
803 /* put it in temp_reg.x */
804 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
806 int temp_reg
, bool is_patch_var
)
810 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
812 Dimension - patch0_offset (input_vals.z),
813 Non-dim - patch0_data_offset (input_vals.w)
815 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
817 ctx
->tess_output_info
, 0,
819 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
825 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
827 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
830 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
832 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
835 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
838 i
= ctx
->shader
->noutput
++;
839 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
840 ctx
->shader
->output
[i
].sid
= 0;
841 ctx
->shader
->output
[i
].gpr
= 0;
842 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
843 ctx
->shader
->output
[i
].write_mask
= 0x4;
844 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
849 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
851 struct r600_bytecode_alu alu
;
854 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
855 alu
.op
= ctx
->inst_info
->op
;
858 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
864 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
866 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
867 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
869 switch (d
->Declaration
.File
) {
870 case TGSI_FILE_INPUT
:
871 for (j
= 0; j
< count
; j
++) {
872 i
= ctx
->shader
->ninput
+ j
;
873 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
874 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
875 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
876 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
877 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
878 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
879 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
880 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
881 switch (ctx
->shader
->input
[i
].name
) {
882 case TGSI_SEMANTIC_FACE
:
883 if (ctx
->face_gpr
!= -1)
884 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
886 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
888 case TGSI_SEMANTIC_COLOR
:
891 case TGSI_SEMANTIC_POSITION
:
892 ctx
->fragcoord_input
= i
;
894 case TGSI_SEMANTIC_PRIMID
:
895 /* set this for now */
896 ctx
->shader
->gs_prim_id_input
= true;
897 ctx
->shader
->ps_prim_id_input
= i
;
900 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
901 if ((r
= evergreen_interp_input(ctx
, i
)))
904 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
905 /* FIXME probably skip inputs if they aren't passed in the ring */
906 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
907 ctx
->next_ring_offset
+= 16;
908 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
909 ctx
->shader
->gs_prim_id_input
= true;
912 ctx
->shader
->ninput
+= count
;
914 case TGSI_FILE_OUTPUT
:
915 for (j
= 0; j
< count
; j
++) {
916 i
= ctx
->shader
->noutput
+ j
;
917 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
918 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
919 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
920 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
921 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
922 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
923 if (ctx
->type
== PIPE_SHADER_VERTEX
||
924 ctx
->type
== PIPE_SHADER_GEOMETRY
||
925 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
926 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
927 switch (d
->Semantic
.Name
) {
928 case TGSI_SEMANTIC_CLIPDIST
:
930 case TGSI_SEMANTIC_PSIZE
:
931 ctx
->shader
->vs_out_misc_write
= 1;
932 ctx
->shader
->vs_out_point_size
= 1;
934 case TGSI_SEMANTIC_EDGEFLAG
:
935 ctx
->shader
->vs_out_misc_write
= 1;
936 ctx
->shader
->vs_out_edgeflag
= 1;
937 ctx
->edgeflag_output
= i
;
939 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
940 ctx
->shader
->vs_out_misc_write
= 1;
941 ctx
->shader
->vs_out_viewport
= 1;
943 case TGSI_SEMANTIC_LAYER
:
944 ctx
->shader
->vs_out_misc_write
= 1;
945 ctx
->shader
->vs_out_layer
= 1;
947 case TGSI_SEMANTIC_CLIPVERTEX
:
948 ctx
->clip_vertex_write
= TRUE
;
952 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
953 ctx
->gs_out_ring_offset
+= 16;
955 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
956 switch (d
->Semantic
.Name
) {
957 case TGSI_SEMANTIC_COLOR
:
958 ctx
->shader
->nr_ps_max_color_exports
++;
963 ctx
->shader
->noutput
+= count
;
965 case TGSI_FILE_TEMPORARY
:
966 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
967 if (d
->Array
.ArrayID
) {
968 r600_add_gpr_array(ctx
->shader
,
969 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
971 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
976 case TGSI_FILE_CONSTANT
:
977 case TGSI_FILE_SAMPLER
:
978 case TGSI_FILE_SAMPLER_VIEW
:
979 case TGSI_FILE_ADDRESS
:
980 case TGSI_FILE_BUFFER
:
981 case TGSI_FILE_IMAGE
:
982 case TGSI_FILE_MEMORY
:
985 case TGSI_FILE_HW_ATOMIC
:
986 i
= ctx
->shader
->nhwatomic_ranges
;
987 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
988 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
989 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
990 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
991 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
992 ctx
->shader
->nhwatomic_ranges
++;
993 ctx
->shader
->nhwatomic
+= count
;
996 case TGSI_FILE_SYSTEM_VALUE
:
997 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
998 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
999 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
1000 break; /* Already handled from allocate_system_value_inputs */
1001 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
1003 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1005 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1007 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1008 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1009 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1010 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1011 unsigned temp_reg
= r600_get_temp(ctx
);
1013 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1017 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1020 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1024 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
1026 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1030 for (i
= 0; i
< 2; i
++) {
1031 struct r600_bytecode_alu alu
;
1032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1033 alu
.op
= ALU_OP1_MOV
;
1035 alu
.src
[0].chan
= 0 + i
;
1037 alu
.dst
.chan
= 0 + i
;
1039 alu
.last
= (i
== 1) ? 1 : 0;
1040 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1043 /* ADD r1.z, 1.0f, -r0.x */
1044 struct r600_bytecode_alu alu
;
1045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1046 alu
.op
= ALU_OP2_ADD
;
1047 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1049 alu
.src
[1].chan
= 0;
1055 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1058 /* ADD r1.z, r1.z, -r1.y */
1059 alu
.op
= ALU_OP2_ADD
;
1061 alu
.src
[0].chan
= 2;
1063 alu
.src
[1].chan
= 1;
1069 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1075 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1081 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1083 struct tgsi_parse_context parse
;
1087 unsigned name
, alternate_name
;
1089 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1091 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1096 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1100 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1101 while (!tgsi_parse_end_of_tokens(&parse
)) {
1102 tgsi_parse_token(&parse
);
1104 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1105 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1106 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1107 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1108 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1110 int interpolate
, location
, k
;
1112 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1113 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1114 inputs
[1].enabled
= true; /* needs SAMPLEID */
1115 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1116 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1117 /* Needs sample positions, currently those are always available */
1119 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1122 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1123 k
= eg_get_interpolator_index(interpolate
, location
);
1125 ctx
->eg_interpolators
[k
].enabled
= true;
1127 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1128 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1129 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1130 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1131 if (d
->Semantic
.Name
== inputs
[k
].name
||
1132 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1133 inputs
[k
].enabled
= true;
1140 tgsi_parse_free(&parse
);
1142 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1143 boolean enabled
= inputs
[i
].enabled
;
1144 int *reg
= inputs
[i
].reg
;
1145 unsigned name
= inputs
[i
].name
;
1148 int gpr
= gpr_offset
+ num_regs
++;
1149 ctx
->shader
->nsys_inputs
++;
1151 // add to inputs, allocate a gpr
1152 k
= ctx
->shader
->ninput
++;
1153 ctx
->shader
->input
[k
].name
= name
;
1154 ctx
->shader
->input
[k
].sid
= 0;
1155 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1156 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1157 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1161 return gpr_offset
+ num_regs
;
1165 * for evergreen we need to scan the shader to find the number of GPRs we need to
1166 * reserve for interpolation and system values
1168 * we need to know if we are going to emit
1169 * any sample or centroid inputs
1170 * if perspective and linear are required
1172 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1176 struct tgsi_parse_context parse
;
1178 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1180 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1182 /* skip position/face/mask/sampleid */
1183 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1184 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1185 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1186 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1189 k
= eg_get_interpolator_index(
1190 ctx
->info
.input_interpolate
[i
],
1191 ctx
->info
.input_interpolate_loc
[i
]);
1193 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1196 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1200 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1201 while (!tgsi_parse_end_of_tokens(&parse
)) {
1202 tgsi_parse_token(&parse
);
1204 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1205 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1206 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1207 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1208 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1210 int interpolate
, location
, k
;
1212 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1213 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1214 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1215 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1217 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1220 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1221 k
= eg_get_interpolator_index(interpolate
, location
);
1223 ctx
->eg_interpolators
[k
].enabled
= true;
1228 tgsi_parse_free(&parse
);
1230 /* assign gpr to each interpolator according to priority */
1232 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1233 if (ctx
->eg_interpolators
[i
].enabled
) {
1234 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1239 /* XXX PULL MODEL and LINE STIPPLE */
1241 num_baryc
= (num_baryc
+ 1) >> 1;
1242 return allocate_system_value_inputs(ctx
, num_baryc
);
1245 /* sample_id_sel == NULL means fetch for current sample */
1246 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1248 struct r600_bytecode_vtx vtx
;
1251 assert(ctx
->fixed_pt_position_gpr
!= -1);
1253 t1
= r600_get_temp(ctx
);
1255 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1256 vtx
.op
= FETCH_OP_VFETCH
;
1257 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1258 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1259 if (sample_id
== NULL
) {
1260 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1264 struct r600_bytecode_alu alu
;
1266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1267 alu
.op
= ALU_OP1_MOV
;
1268 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1272 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1279 vtx
.mega_fetch_count
= 16;
1285 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1286 vtx
.num_format_all
= 2;
1287 vtx
.format_comp_all
= 1;
1288 vtx
.use_const_fields
= 0;
1290 vtx
.endian
= r600_endian_swap(32);
1291 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1293 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1300 static int eg_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1303 struct r600_bytecode_alu alu
;
1305 /* do a vtx fetch with wqm set on the vtx fetch */
1306 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1307 alu
.op
= ALU_OP1_MOV
;
1308 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1310 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1311 alu
.src
[0].value
= 0xffffffff;
1314 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1318 /* do a vtx fetch in VPM mode */
1319 struct r600_bytecode_vtx vtx
;
1320 memset(&vtx
, 0, sizeof(vtx
));
1321 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
1322 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1323 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1325 vtx
.mega_fetch_count
= 16; /* no idea here really... */
1326 vtx
.dst_gpr
= ctx
->helper_invoc_reg
;
1328 vtx
.dst_sel_y
= 7; /* SEL_Y */
1329 vtx
.dst_sel_z
= 7; /* SEL_Z */
1330 vtx
.dst_sel_w
= 7; /* SEL_W */
1331 vtx
.data_format
= FMT_32
;
1332 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
1334 ctx
->bc
->cf_last
->vpm
= 1;
1338 static int cm_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1341 struct r600_bytecode_alu alu
;
1343 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1344 alu
.op
= ALU_OP1_MOV
;
1345 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1347 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1348 alu
.src
[0].value
= 0xffffffff;
1351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1356 alu
.op
= ALU_OP1_MOV
;
1357 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1359 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1362 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_VALID_PIXEL_MODE
);
1366 return ctx
->helper_invoc_reg
;
1369 static int load_block_grid_size(struct r600_shader_ctx
*ctx
, bool load_block
)
1371 struct r600_bytecode_vtx vtx
;
1374 if (ctx
->cs_block_size_loaded
)
1375 return ctx
->cs_block_size_reg
;
1376 if (ctx
->cs_grid_size_loaded
)
1377 return ctx
->cs_grid_size_reg
;
1379 t1
= load_block
? ctx
->cs_block_size_reg
: ctx
->cs_grid_size_reg
;
1380 struct r600_bytecode_alu alu
;
1381 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1382 alu
.op
= ALU_OP1_MOV
;
1383 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1387 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1391 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1392 vtx
.op
= FETCH_OP_VFETCH
;
1393 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1394 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1398 vtx
.mega_fetch_count
= 16;
1404 vtx
.data_format
= FMT_32_32_32_32
;
1405 vtx
.num_format_all
= 1;
1406 vtx
.format_comp_all
= 0;
1407 vtx
.use_const_fields
= 0;
1408 vtx
.offset
= load_block
? 0 : 16; // first element is size of buffer
1409 vtx
.endian
= r600_endian_swap(32);
1410 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1412 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1417 ctx
->cs_block_size_loaded
= true;
1419 ctx
->cs_grid_size_loaded
= true;
1423 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1424 const struct tgsi_full_src_register
*tgsi_src
,
1425 struct r600_shader_src
*r600_src
)
1427 memset(r600_src
, 0, sizeof(*r600_src
));
1428 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1429 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1430 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1431 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1432 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1433 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1435 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1437 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1438 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1439 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1441 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1442 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1443 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1446 index
= tgsi_src
->Register
.Index
;
1447 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1448 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1449 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1450 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1451 r600_src
->swizzle
[0] = 2; // Z value
1452 r600_src
->swizzle
[1] = 2;
1453 r600_src
->swizzle
[2] = 2;
1454 r600_src
->swizzle
[3] = 2;
1455 r600_src
->sel
= ctx
->face_gpr
;
1456 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1457 r600_src
->swizzle
[0] = 3; // W value
1458 r600_src
->swizzle
[1] = 3;
1459 r600_src
->swizzle
[2] = 3;
1460 r600_src
->swizzle
[3] = 3;
1461 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1462 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1463 r600_src
->swizzle
[0] = 0;
1464 r600_src
->swizzle
[1] = 1;
1465 r600_src
->swizzle
[2] = 4;
1466 r600_src
->swizzle
[3] = 4;
1467 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1468 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1469 r600_src
->swizzle
[0] = 3;
1470 r600_src
->swizzle
[1] = 3;
1471 r600_src
->swizzle
[2] = 3;
1472 r600_src
->swizzle
[3] = 3;
1474 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1475 r600_src
->swizzle
[0] = 0;
1476 r600_src
->swizzle
[1] = 0;
1477 r600_src
->swizzle
[2] = 0;
1478 r600_src
->swizzle
[3] = 0;
1480 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_THREAD_ID
) {
1482 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_ID
) {
1484 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1485 r600_src
->swizzle
[0] = 3;
1486 r600_src
->swizzle
[1] = 3;
1487 r600_src
->swizzle
[2] = 3;
1488 r600_src
->swizzle
[3] = 3;
1490 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1491 r600_src
->swizzle
[0] = 2;
1492 r600_src
->swizzle
[1] = 2;
1493 r600_src
->swizzle
[2] = 2;
1494 r600_src
->swizzle
[3] = 2;
1496 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1498 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1500 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1502 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1503 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1504 r600_src
->sel
= ctx
->tess_input_info
;
1505 r600_src
->swizzle
[0] = 2;
1506 r600_src
->swizzle
[1] = 2;
1507 r600_src
->swizzle
[2] = 2;
1508 r600_src
->swizzle
[3] = 2;
1510 r600_src
->sel
= ctx
->tess_input_info
;
1511 r600_src
->swizzle
[0] = 3;
1512 r600_src
->swizzle
[1] = 3;
1513 r600_src
->swizzle
[2] = 3;
1514 r600_src
->swizzle
[3] = 3;
1516 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1518 r600_src
->swizzle
[0] = 0;
1519 r600_src
->swizzle
[1] = 0;
1520 r600_src
->swizzle
[2] = 0;
1521 r600_src
->swizzle
[3] = 0;
1522 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1524 r600_src
->swizzle
[0] = 3;
1525 r600_src
->swizzle
[1] = 3;
1526 r600_src
->swizzle
[2] = 3;
1527 r600_src
->swizzle
[3] = 3;
1528 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_GRID_SIZE
) {
1529 r600_src
->sel
= load_block_grid_size(ctx
, false);
1530 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_SIZE
) {
1531 r600_src
->sel
= load_block_grid_size(ctx
, true);
1532 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
1533 r600_src
->sel
= ctx
->helper_invoc_reg
;
1534 r600_src
->swizzle
[0] = 0;
1535 r600_src
->swizzle
[1] = 0;
1536 r600_src
->swizzle
[2] = 0;
1537 r600_src
->swizzle
[3] = 0;
1540 if (tgsi_src
->Register
.Indirect
)
1541 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1542 r600_src
->sel
= tgsi_src
->Register
.Index
;
1543 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1545 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1546 if (tgsi_src
->Register
.Dimension
) {
1547 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1548 if (tgsi_src
->Dimension
.Indirect
) {
1549 r600_src
->kc_rel
= 1;
1555 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1556 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1557 unsigned int dst_reg
)
1559 struct r600_bytecode_vtx vtx
;
1560 unsigned int ar_reg
;
1564 struct r600_bytecode_alu alu
;
1566 memset(&alu
, 0, sizeof(alu
));
1568 alu
.op
= ALU_OP2_ADD_INT
;
1569 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1570 alu
.src
[0].chan
= ar_chan
;
1572 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1573 alu
.src
[1].value
= offset
;
1575 alu
.dst
.sel
= dst_reg
;
1576 alu
.dst
.chan
= ar_chan
;
1580 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1585 ar_reg
= ctx
->bc
->ar_reg
;
1588 memset(&vtx
, 0, sizeof(vtx
));
1589 vtx
.buffer_id
= cb_idx
;
1590 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1591 vtx
.src_gpr
= ar_reg
;
1592 vtx
.src_sel_x
= ar_chan
;
1593 vtx
.mega_fetch_count
= 16;
1594 vtx
.dst_gpr
= dst_reg
;
1595 vtx
.dst_sel_x
= 0; /* SEL_X */
1596 vtx
.dst_sel_y
= 1; /* SEL_Y */
1597 vtx
.dst_sel_z
= 2; /* SEL_Z */
1598 vtx
.dst_sel_w
= 3; /* SEL_W */
1599 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1600 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1601 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1602 vtx
.endian
= r600_endian_swap(32);
1603 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1605 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1611 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1613 struct r600_bytecode_vtx vtx
;
1615 unsigned index
= src
->Register
.Index
;
1616 unsigned vtx_id
= src
->Dimension
.Index
;
1617 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1618 int offset_chan
= vtx_id
% 3;
1621 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1622 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1624 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1627 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1628 t2
= r600_get_temp(ctx
);
1630 if (src
->Dimension
.Indirect
) {
1632 struct r600_bytecode_alu alu
;
1635 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1636 if (src
->DimIndirect
.Index
> 0) {
1637 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1645 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1646 at least this is what fglrx seems to do. */
1647 for (i
= 0; i
< 3; i
++) {
1648 treg
[i
] = r600_get_temp(ctx
);
1650 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1652 for (i
= 0; i
< 3; i
++) {
1653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1654 alu
.op
= ALU_OP1_MOV
;
1655 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1656 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1657 alu
.dst
.sel
= treg
[i
];
1661 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1665 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1666 alu
.op
= ALU_OP1_MOV
;
1667 alu
.src
[0].sel
= treg
[0];
1672 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1679 if (src
->Register
.Indirect
) {
1681 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1683 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1685 /* pull the value from index_reg */
1686 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1689 V_SQ_ALU_SRC_LITERAL
, first
);
1692 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1695 V_SQ_ALU_SRC_LITERAL
, 4,
1696 offset_reg
, offset_chan
);
1701 index
= src
->Register
.Index
- first
;
1704 memset(&vtx
, 0, sizeof(vtx
));
1705 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1706 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1707 vtx
.src_gpr
= offset_reg
;
1708 vtx
.src_sel_x
= offset_chan
;
1709 vtx
.offset
= index
* 16; /*bytes*/
1710 vtx
.mega_fetch_count
= 16;
1711 vtx
.dst_gpr
= dst_reg
;
1712 vtx
.dst_sel_x
= 0; /* SEL_X */
1713 vtx
.dst_sel_y
= 1; /* SEL_Y */
1714 vtx
.dst_sel_z
= 2; /* SEL_Z */
1715 vtx
.dst_sel_w
= 3; /* SEL_W */
1716 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1717 vtx
.use_const_fields
= 1;
1719 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1722 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1728 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1730 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1733 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1734 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1736 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1737 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1738 /* primitive id is in R0.z */
1739 ctx
->src
[i
].sel
= 0;
1740 ctx
->src
[i
].swizzle
[0] = 2;
1743 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1744 int treg
= r600_get_temp(ctx
);
1746 fetch_gs_input(ctx
, src
, treg
);
1747 ctx
->src
[i
].sel
= treg
;
1748 ctx
->src
[i
].rel
= 0;
1755 /* Tessellation shaders pass outputs to the next shader using LDS.
1757 * LS outputs = TCS(HS) inputs
1758 * TCS(HS) outputs = TES(DS) inputs
1760 * The LDS layout is:
1761 * - TCS inputs for patch 0
1762 * - TCS inputs for patch 1
1763 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1765 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1766 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1767 * - TCS outputs for patch 1
1768 * - Per-patch TCS outputs for patch 1
1769 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1770 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1773 * All three shaders VS(LS), TCS, TES share the same LDS space.
1775 /* this will return with the dw address in temp_reg.x */
1776 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1777 const struct tgsi_full_dst_register
*dst
,
1778 const struct tgsi_full_src_register
*src
,
1779 int stride_bytes_reg
, int stride_bytes_chan
)
1781 struct tgsi_full_dst_register reg
;
1782 ubyte
*name
, *index
, *array_first
;
1785 struct tgsi_shader_info
*info
= &ctx
->info
;
1786 /* Set the register description. The address computation is the same
1787 * for sources and destinations. */
1789 reg
.Register
.File
= src
->Register
.File
;
1790 reg
.Register
.Index
= src
->Register
.Index
;
1791 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1792 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1793 reg
.Indirect
= src
->Indirect
;
1794 reg
.Dimension
= src
->Dimension
;
1795 reg
.DimIndirect
= src
->DimIndirect
;
1799 /* If the register is 2-dimensional (e.g. an array of vertices
1800 * in a primitive), calculate the base address of the vertex. */
1801 if (reg
.Register
.Dimension
) {
1803 if (reg
.Dimension
.Indirect
) {
1805 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1807 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1808 /* pull the value from index_reg */
1812 sel
= V_SQ_ALU_SRC_LITERAL
;
1813 chan
= reg
.Dimension
.Index
;
1816 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1818 stride_bytes_reg
, stride_bytes_chan
,
1825 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1826 name
= info
->input_semantic_name
;
1827 index
= info
->input_semantic_index
;
1828 array_first
= info
->input_array_first
;
1829 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1830 name
= info
->output_semantic_name
;
1831 index
= info
->output_semantic_index
;
1832 array_first
= info
->output_array_first
;
1837 if (reg
.Register
.Indirect
) {
1840 /* Add the relative address of the element. */
1841 if (reg
.Indirect
.ArrayID
)
1842 first
= array_first
[reg
.Indirect
.ArrayID
];
1844 first
= reg
.Register
.Index
;
1846 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1848 /* pull the value from index_reg */
1849 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1851 V_SQ_ALU_SRC_LITERAL
, 16,
1857 param
= r600_get_lds_unique_index(name
[first
],
1861 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1862 index
[reg
.Register
.Index
]);
1865 /* add to base_addr - passed in temp_reg.x */
1867 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1870 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1878 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1879 unsigned dst_reg
, unsigned mask
)
1881 struct r600_bytecode_alu alu
;
1884 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1885 ctx
->bc
->force_add_cf
= 1;
1887 lasti
= tgsi_last_instruction(mask
);
1888 for (i
= 1; i
<= lasti
; i
++) {
1889 if (!(mask
& (1 << i
)))
1892 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1895 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1899 for (i
= 0; i
<= lasti
; i
++) {
1900 if (!(mask
& (1 << i
)))
1903 /* emit an LDS_READ_RET */
1904 memset(&alu
, 0, sizeof(alu
));
1905 alu
.op
= LDS_OP1_LDS_READ_RET
;
1906 alu
.src
[0].sel
= temp_reg
;
1907 alu
.src
[0].chan
= i
;
1908 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1909 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1911 alu
.is_lds_idx_op
= true;
1913 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1917 for (i
= 0; i
<= lasti
; i
++) {
1918 if (!(mask
& (1 << i
)))
1921 /* then read from LDS_OQ_A_POP */
1922 memset(&alu
, 0, sizeof(alu
));
1924 alu
.op
= ALU_OP1_MOV
;
1925 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1926 alu
.src
[0].chan
= 0;
1927 alu
.dst
.sel
= dst_reg
;
1931 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1938 static int fetch_mask(struct tgsi_src_register
*reg
)
1941 mask
|= 1 << reg
->SwizzleX
;
1942 mask
|= 1 << reg
->SwizzleY
;
1943 mask
|= 1 << reg
->SwizzleZ
;
1944 mask
|= 1 << reg
->SwizzleW
;
1948 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1951 unsigned temp_reg
= r600_get_temp(ctx
);
1953 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1954 src
->Register
.Dimension
? false : true);
1958 /* the base address is now in temp.x */
1959 r
= r600_get_byte_address(ctx
, temp_reg
,
1960 NULL
, src
, ctx
->tess_output_info
, 1);
1964 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1970 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1973 unsigned temp_reg
= r600_get_temp(ctx
);
1975 /* t.x = ips * r0.y */
1976 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1978 ctx
->tess_input_info
, 0,
1984 /* the base address is now in temp.x */
1985 r
= r600_get_byte_address(ctx
, temp_reg
,
1986 NULL
, src
, ctx
->tess_input_info
, 1);
1990 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1996 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1999 unsigned temp_reg
= r600_get_temp(ctx
);
2001 r
= get_lds_offset0(ctx
, 1, temp_reg
,
2002 src
->Register
.Dimension
? false : true);
2005 /* the base address is now in temp.x */
2006 r
= r600_get_byte_address(ctx
, temp_reg
,
2008 ctx
->tess_output_info
, 1);
2012 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2018 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
2020 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2023 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2024 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
2026 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2027 int treg
= r600_get_temp(ctx
);
2028 fetch_tes_input(ctx
, src
, treg
);
2029 ctx
->src
[i
].sel
= treg
;
2030 ctx
->src
[i
].rel
= 0;
2032 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2033 int treg
= r600_get_temp(ctx
);
2034 fetch_tcs_input(ctx
, src
, treg
);
2035 ctx
->src
[i
].sel
= treg
;
2036 ctx
->src
[i
].rel
= 0;
2038 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
2039 int treg
= r600_get_temp(ctx
);
2040 fetch_tcs_output(ctx
, src
, treg
);
2041 ctx
->src
[i
].sel
= treg
;
2042 ctx
->src
[i
].rel
= 0;
2048 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
2050 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2051 struct r600_bytecode_alu alu
;
2052 int i
, j
, k
, nconst
, r
;
2054 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2055 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
2058 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
2060 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2061 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
2065 if (ctx
->src
[i
].rel
) {
2066 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
2067 int treg
= r600_get_temp(ctx
);
2068 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
2071 ctx
->src
[i
].kc_bank
= 0;
2072 ctx
->src
[i
].kc_rel
= 0;
2073 ctx
->src
[i
].sel
= treg
;
2074 ctx
->src
[i
].rel
= 0;
2077 int treg
= r600_get_temp(ctx
);
2078 for (k
= 0; k
< 4; k
++) {
2079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2080 alu
.op
= ALU_OP1_MOV
;
2081 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2082 alu
.src
[0].chan
= k
;
2083 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
2084 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
2085 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
2091 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2095 ctx
->src
[i
].sel
= treg
;
2103 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
2104 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
2106 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2107 struct r600_bytecode_alu alu
;
2108 int i
, j
, k
, nliteral
, r
;
2110 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2111 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2115 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2116 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2117 int treg
= r600_get_temp(ctx
);
2118 for (k
= 0; k
< 4; k
++) {
2119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2120 alu
.op
= ALU_OP1_MOV
;
2121 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2122 alu
.src
[0].chan
= k
;
2123 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2133 ctx
->src
[i
].sel
= treg
;
2140 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2142 int i
, r
, count
= ctx
->shader
->ninput
;
2144 for (i
= 0; i
< count
; i
++) {
2145 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2146 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2154 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2155 int stream
, unsigned *stream_item_size UNUSED
)
2157 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2158 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2162 /* Sanity checking. */
2163 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2164 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2168 for (i
= 0; i
< so
->num_outputs
; i
++) {
2169 if (so
->output
[i
].output_buffer
>= 4) {
2170 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2171 so
->output
[i
].output_buffer
);
2177 /* Initialize locations where the outputs are stored. */
2178 for (i
= 0; i
< so
->num_outputs
; i
++) {
2180 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2181 start_comp
[i
] = so
->output
[i
].start_component
;
2182 /* Lower outputs with dst_offset < start_component.
2184 * We can only output 4D vectors with a write mask, e.g. we can
2185 * only output the W component at offset 3, etc. If we want
2186 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2187 * to move it to X and output X. */
2188 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2189 unsigned tmp
= r600_get_temp(ctx
);
2191 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2192 struct r600_bytecode_alu alu
;
2193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2194 alu
.op
= ALU_OP1_MOV
;
2195 alu
.src
[0].sel
= so_gpr
[i
];
2196 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2201 if (j
== so
->output
[i
].num_components
- 1)
2203 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2212 /* Write outputs to buffers. */
2213 for (i
= 0; i
< so
->num_outputs
; i
++) {
2214 struct r600_bytecode_output output
;
2216 if (stream
!= -1 && stream
!= so
->output
[i
].stream
)
2219 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2220 output
.gpr
= so_gpr
[i
];
2221 output
.elem_size
= so
->output
[i
].num_components
- 1;
2222 if (output
.elem_size
== 2)
2223 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2224 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2225 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2226 output
.burst_count
= 1;
2227 /* array_size is an upper limit for the burst_count
2228 * with MEM_STREAM instructions */
2229 output
.array_size
= 0xFFF;
2230 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2232 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2233 switch (so
->output
[i
].output_buffer
) {
2235 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2238 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2241 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2244 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2247 output
.op
+= so
->output
[i
].stream
* 4;
2248 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2249 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2251 switch (so
->output
[i
].output_buffer
) {
2253 output
.op
= CF_OP_MEM_STREAM0
;
2256 output
.op
= CF_OP_MEM_STREAM1
;
2259 output
.op
= CF_OP_MEM_STREAM2
;
2262 output
.op
= CF_OP_MEM_STREAM3
;
2265 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2267 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2276 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2278 struct r600_bytecode_alu alu
;
2281 if (!ctx
->shader
->vs_out_edgeflag
)
2284 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2286 /* clamp(x, 0, 1) */
2287 memset(&alu
, 0, sizeof(alu
));
2288 alu
.op
= ALU_OP1_MOV
;
2289 alu
.src
[0].sel
= reg
;
2294 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2296 memset(&alu
, 0, sizeof(alu
));
2297 alu
.op
= ALU_OP1_FLT_TO_INT
;
2298 alu
.src
[0].sel
= reg
;
2302 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2305 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2306 struct r600_pipe_shader
*gs
,
2307 struct pipe_stream_output_info
*so
)
2309 struct r600_shader_ctx ctx
= {};
2310 struct r600_shader
*gs_shader
= &gs
->shader
;
2311 struct r600_pipe_shader
*cshader
;
2312 unsigned ocnt
= gs_shader
->noutput
;
2313 struct r600_bytecode_alu alu
;
2314 struct r600_bytecode_vtx vtx
;
2315 struct r600_bytecode_output output
;
2316 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2317 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2318 int next_clip_pos
= 61, next_param
= 0;
2321 bool only_ring_0
= true;
2322 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2326 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2327 sizeof(struct r600_shader_io
));
2329 cshader
->shader
.noutput
= ocnt
;
2331 ctx
.shader
= &cshader
->shader
;
2332 ctx
.bc
= &ctx
.shader
->bc
;
2333 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2335 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2336 rctx
->screen
->has_compressed_msaa_texturing
);
2338 ctx
.bc
->isa
= rctx
->isa
;
2341 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2343 /* R0.x = R0.x & 0x3fffffff */
2344 memset(&alu
, 0, sizeof(alu
));
2345 alu
.op
= ALU_OP2_AND_INT
;
2346 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2347 alu
.src
[1].value
= 0x3fffffff;
2349 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2351 /* R0.y = R0.x >> 30 */
2352 memset(&alu
, 0, sizeof(alu
));
2353 alu
.op
= ALU_OP2_LSHR_INT
;
2354 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2355 alu
.src
[1].value
= 0x1e;
2359 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2361 /* fetch vertex data from GSVS ring */
2362 for (i
= 0; i
< ocnt
; ++i
) {
2363 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2366 out
->ring_offset
= i
* 16;
2368 memset(&vtx
, 0, sizeof(vtx
));
2369 vtx
.op
= FETCH_OP_VFETCH
;
2370 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2371 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2372 vtx
.mega_fetch_count
= 16;
2373 vtx
.offset
= out
->ring_offset
;
2374 vtx
.dst_gpr
= out
->gpr
;
2380 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2381 vtx
.use_const_fields
= 1;
2383 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2386 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2388 ctx
.temp_reg
= i
+ 1;
2389 for (ring
= 3; ring
>= 0; --ring
) {
2390 bool enabled
= false;
2391 for (i
= 0; i
< so
->num_outputs
; i
++) {
2392 if (so
->output
[i
].stream
== ring
) {
2395 only_ring_0
= false;
2399 if (ring
!= 0 && !enabled
) {
2400 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2405 // Patch up jump label
2406 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2407 cf_pop
= ctx
.bc
->cf_last
;
2409 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2410 cf_jump
->pop_count
= 1;
2411 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2412 cf_pop
->pop_count
= 1;
2415 /* PRED_SETE_INT __, R0.y, ring */
2416 memset(&alu
, 0, sizeof(alu
));
2417 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2418 alu
.src
[0].chan
= 1;
2419 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2420 alu
.src
[1].value
= ring
;
2421 alu
.execute_mask
= 1;
2422 alu
.update_pred
= 1;
2424 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2426 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2427 cf_jump
= ctx
.bc
->cf_last
;
2430 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2431 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2434 /* bc adds nops - copy it */
2435 if (ctx
.bc
->chip_class
== R600
) {
2436 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2437 alu
.op
= ALU_OP0_NOP
;
2439 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2441 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2444 /* export vertex data */
2445 /* XXX factor out common code with r600_shader_from_tgsi ? */
2446 for (i
= 0; i
< ocnt
; ++i
) {
2447 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2448 bool instream0
= true;
2449 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2452 for (j
= 0; j
< so
->num_outputs
; j
++) {
2453 if (so
->output
[j
].register_index
== i
) {
2454 if (so
->output
[j
].stream
== 0)
2456 if (so
->output
[j
].stream
> 0)
2462 memset(&output
, 0, sizeof(output
));
2463 output
.gpr
= out
->gpr
;
2464 output
.elem_size
= 3;
2465 output
.swizzle_x
= 0;
2466 output
.swizzle_y
= 1;
2467 output
.swizzle_z
= 2;
2468 output
.swizzle_w
= 3;
2469 output
.burst_count
= 1;
2470 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2471 output
.op
= CF_OP_EXPORT
;
2472 switch (out
->name
) {
2473 case TGSI_SEMANTIC_POSITION
:
2474 output
.array_base
= 60;
2475 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2478 case TGSI_SEMANTIC_PSIZE
:
2479 output
.array_base
= 61;
2480 if (next_clip_pos
== 61)
2482 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2483 output
.swizzle_y
= 7;
2484 output
.swizzle_z
= 7;
2485 output
.swizzle_w
= 7;
2486 ctx
.shader
->vs_out_misc_write
= 1;
2487 ctx
.shader
->vs_out_point_size
= 1;
2489 case TGSI_SEMANTIC_LAYER
:
2491 /* duplicate it as PARAM to pass to the pixel shader */
2492 output
.array_base
= next_param
++;
2493 r600_bytecode_add_output(ctx
.bc
, &output
);
2494 last_exp_param
= ctx
.bc
->cf_last
;
2496 output
.array_base
= 61;
2497 if (next_clip_pos
== 61)
2499 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2500 output
.swizzle_x
= 7;
2501 output
.swizzle_y
= 7;
2502 output
.swizzle_z
= 0;
2503 output
.swizzle_w
= 7;
2504 ctx
.shader
->vs_out_misc_write
= 1;
2505 ctx
.shader
->vs_out_layer
= 1;
2507 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2509 /* duplicate it as PARAM to pass to the pixel shader */
2510 output
.array_base
= next_param
++;
2511 r600_bytecode_add_output(ctx
.bc
, &output
);
2512 last_exp_param
= ctx
.bc
->cf_last
;
2514 output
.array_base
= 61;
2515 if (next_clip_pos
== 61)
2517 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2518 ctx
.shader
->vs_out_misc_write
= 1;
2519 ctx
.shader
->vs_out_viewport
= 1;
2520 output
.swizzle_x
= 7;
2521 output
.swizzle_y
= 7;
2522 output
.swizzle_z
= 7;
2523 output
.swizzle_w
= 0;
2525 case TGSI_SEMANTIC_CLIPDIST
:
2526 /* spi_sid is 0 for clipdistance outputs that were generated
2527 * for clipvertex - we don't need to pass them to PS */
2528 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2529 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2530 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2532 /* duplicate it as PARAM to pass to the pixel shader */
2533 output
.array_base
= next_param
++;
2534 r600_bytecode_add_output(ctx
.bc
, &output
);
2535 last_exp_param
= ctx
.bc
->cf_last
;
2537 output
.array_base
= next_clip_pos
++;
2538 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2540 case TGSI_SEMANTIC_FOG
:
2541 output
.swizzle_y
= 4; /* 0 */
2542 output
.swizzle_z
= 4; /* 0 */
2543 output
.swizzle_w
= 5; /* 1 */
2546 output
.array_base
= next_param
++;
2549 r600_bytecode_add_output(ctx
.bc
, &output
);
2550 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2551 last_exp_param
= ctx
.bc
->cf_last
;
2553 last_exp_pos
= ctx
.bc
->cf_last
;
2556 if (!last_exp_pos
) {
2557 memset(&output
, 0, sizeof(output
));
2559 output
.elem_size
= 3;
2560 output
.swizzle_x
= 7;
2561 output
.swizzle_y
= 7;
2562 output
.swizzle_z
= 7;
2563 output
.swizzle_w
= 7;
2564 output
.burst_count
= 1;
2566 output
.op
= CF_OP_EXPORT
;
2567 output
.array_base
= 60;
2568 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2569 r600_bytecode_add_output(ctx
.bc
, &output
);
2570 last_exp_pos
= ctx
.bc
->cf_last
;
2573 if (!last_exp_param
) {
2574 memset(&output
, 0, sizeof(output
));
2576 output
.elem_size
= 3;
2577 output
.swizzle_x
= 7;
2578 output
.swizzle_y
= 7;
2579 output
.swizzle_z
= 7;
2580 output
.swizzle_w
= 7;
2581 output
.burst_count
= 1;
2583 output
.op
= CF_OP_EXPORT
;
2584 output
.array_base
= next_param
++;
2585 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2586 r600_bytecode_add_output(ctx
.bc
, &output
);
2587 last_exp_param
= ctx
.bc
->cf_last
;
2590 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2591 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2593 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2594 cf_pop
= ctx
.bc
->cf_last
;
2596 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2597 cf_jump
->pop_count
= 1;
2598 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2599 cf_pop
->pop_count
= 1;
2601 if (ctx
.bc
->chip_class
== CAYMAN
)
2602 cm_bytecode_add_cf_end(ctx
.bc
);
2604 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2605 ctx
.bc
->cf_last
->end_of_program
= 1;
2608 gs
->gs_copy_shader
= cshader
;
2609 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2613 return r600_bytecode_build(ctx
.bc
);
2616 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2619 struct r600_bytecode_alu alu
;
2622 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2623 alu
.op
= ALU_OP2_ADD_INT
;
2624 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2625 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2626 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2627 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2630 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2637 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2639 struct r600_bytecode_output output
;
2642 int effective_stream
= stream
== -1 ? 0 : stream
;
2645 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2646 if (ctx
->gs_for_vs
) {
2647 /* for ES we need to lookup corresponding ring offset expected by GS
2648 * (map this output to GS input by name and sid) */
2649 /* FIXME precompute offsets */
2651 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2652 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2653 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2654 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2655 ring_offset
= in
->ring_offset
;
2658 if (ring_offset
== -1)
2661 ring_offset
= idx
* 16;
2665 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2667 /* next_ring_offset after parsing input decls contains total size of
2668 * single vertex data, gs_next_vertex - current vertex index */
2670 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2672 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2673 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2674 output
.elem_size
= 3;
2675 output
.comp_mask
= 0xF;
2676 output
.burst_count
= 1;
2679 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2681 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2686 output
.op
= CF_OP_MEM_RING
; break;
2688 output
.op
= CF_OP_MEM_RING1
; break;
2690 output
.op
= CF_OP_MEM_RING2
; break;
2692 output
.op
= CF_OP_MEM_RING3
; break;
2696 output
.array_base
= ring_offset
>> 2; /* in dwords */
2697 output
.array_size
= 0xfff;
2698 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2700 output
.array_base
= ring_offset
>> 2; /* in dwords */
2701 r600_bytecode_add_output(ctx
->bc
, &output
);
2704 ++ctx
->gs_next_vertex
;
2709 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2712 struct r600_bytecode_vtx vtx
;
2713 int temp_val
= ctx
->temp_reg
;
2714 /* need to store the TCS output somewhere */
2715 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2717 V_SQ_ALU_SRC_LITERAL
, 0,
2722 /* used by VS/TCS */
2723 if (ctx
->tess_input_info
) {
2724 /* fetch tcs input values into resv space */
2725 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2726 vtx
.op
= FETCH_OP_VFETCH
;
2727 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2728 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2729 vtx
.mega_fetch_count
= 16;
2730 vtx
.data_format
= FMT_32_32_32_32
;
2731 vtx
.num_format_all
= 2;
2732 vtx
.format_comp_all
= 1;
2733 vtx
.use_const_fields
= 0;
2734 vtx
.endian
= r600_endian_swap(32);
2735 vtx
.srf_mode_all
= 1;
2737 vtx
.dst_gpr
= ctx
->tess_input_info
;
2742 vtx
.src_gpr
= temp_val
;
2745 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2750 /* used by TCS/TES */
2751 if (ctx
->tess_output_info
) {
2752 /* fetch tcs output values into resv space */
2753 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2754 vtx
.op
= FETCH_OP_VFETCH
;
2755 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2756 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2757 vtx
.mega_fetch_count
= 16;
2758 vtx
.data_format
= FMT_32_32_32_32
;
2759 vtx
.num_format_all
= 2;
2760 vtx
.format_comp_all
= 1;
2761 vtx
.use_const_fields
= 0;
2762 vtx
.endian
= r600_endian_swap(32);
2763 vtx
.srf_mode_all
= 1;
2765 vtx
.dst_gpr
= ctx
->tess_output_info
;
2770 vtx
.src_gpr
= temp_val
;
2773 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2780 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2786 /* fetch tcs input values into input_vals */
2787 ctx
->tess_input_info
= r600_get_temp(ctx
);
2788 ctx
->tess_output_info
= 0;
2789 r
= r600_fetch_tess_io_info(ctx
);
2793 temp_reg
= r600_get_temp(ctx
);
2794 /* dst reg contains LDS address stride * idx */
2795 /* MUL vertexID, vertex_dw_stride */
2796 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2798 ctx
->tess_input_info
, 1,
2799 0, 1); /* rel id in r0.y? */
2803 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2804 struct r600_bytecode_alu alu
;
2805 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2808 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2811 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2816 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2818 temp_reg
, param
? 1 : 0,
2819 V_SQ_ALU_SRC_LITERAL
, 8);
2824 for (j
= 0; j
< 2; j
++) {
2825 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2826 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2827 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2828 alu
.src
[0].sel
= temp_reg
;
2829 alu
.src
[0].chan
= chan
;
2830 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2831 alu
.src
[1].chan
= j
* 2;
2832 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2833 alu
.src
[2].chan
= (j
* 2) + 1;
2837 alu
.is_lds_idx_op
= true;
2838 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2846 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2848 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2849 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2851 int temp_reg
= r600_get_temp(ctx
);
2852 struct r600_bytecode_alu alu
;
2853 unsigned write_mask
= dst
->Register
.WriteMask
;
2855 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2858 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2862 /* the base address is now in temp.x */
2863 r
= r600_get_byte_address(ctx
, temp_reg
,
2864 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2869 lasti
= tgsi_last_instruction(write_mask
);
2870 for (i
= 1; i
<= lasti
; i
++) {
2872 if (!(write_mask
& (1 << i
)))
2874 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2877 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2882 for (i
= 0; i
<= lasti
; i
++) {
2883 if (!(write_mask
& (1 << i
)))
2886 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2887 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2888 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2889 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2890 alu
.src
[0].sel
= temp_reg
;
2891 alu
.src
[0].chan
= i
;
2893 alu
.src
[1].sel
= dst
->Register
.Index
;
2894 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2895 alu
.src
[1].chan
= i
;
2897 alu
.src
[2].sel
= dst
->Register
.Index
;
2898 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2899 alu
.src
[2].chan
= i
+ 1;
2903 alu
.is_lds_idx_op
= true;
2904 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2910 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2911 alu
.op
= LDS_OP2_LDS_WRITE
;
2912 alu
.src
[0].sel
= temp_reg
;
2913 alu
.src
[0].chan
= i
;
2915 alu
.src
[1].sel
= dst
->Register
.Index
;
2916 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2917 alu
.src
[1].chan
= i
;
2919 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2922 alu
.is_lds_idx_op
= true;
2923 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2930 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2931 int output_idx
, int nc
)
2934 unsigned temp_reg
= r600_get_temp(ctx
);
2935 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2936 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2939 param
= r600_get_lds_unique_index(name
, 0);
2940 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2945 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2948 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2953 do_lds_fetch_values(ctx
, temp_reg
, dreg
, ((1u << nc
) - 1));
2957 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2959 int stride
, outer_comps
, inner_comps
;
2960 int tessinner_idx
= -1, tessouter_idx
= -1;
2963 int temp_reg
= r600_get_temp(ctx
);
2964 int treg
[3] = {-1, -1, -1};
2965 struct r600_bytecode_alu alu
;
2966 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2968 /* only execute factor emission for invocation 0 */
2969 /* PRED_SETE_INT __, R0.x, 0 */
2970 memset(&alu
, 0, sizeof(alu
));
2971 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2972 alu
.src
[0].chan
= 2;
2973 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2974 alu
.execute_mask
= 1;
2975 alu
.update_pred
= 1;
2977 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2979 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2980 cf_jump
= ctx
->bc
->cf_last
;
2982 treg
[0] = r600_get_temp(ctx
);
2983 switch (ctx
->shader
->tcs_prim_mode
) {
2984 case PIPE_PRIM_LINES
:
2985 stride
= 8; /* 2 dwords, 1 vec2 store */
2989 case PIPE_PRIM_TRIANGLES
:
2990 stride
= 16; /* 4 dwords, 1 vec4 store */
2993 treg
[1] = r600_get_temp(ctx
);
2995 case PIPE_PRIM_QUADS
:
2996 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2999 treg
[1] = r600_get_temp(ctx
);
3000 treg
[2] = r600_get_temp(ctx
);
3007 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
3008 /* TF_WRITE takes index in R.x, value in R.y */
3009 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
3010 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
3012 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
3016 if (tessouter_idx
== -1)
3019 if (tessinner_idx
== -1 && inner_comps
)
3022 if (tessouter_idx
!= -1) {
3023 r
= r600_tess_factor_read(ctx
, tessouter_idx
, outer_comps
);
3028 if (tessinner_idx
!= -1) {
3029 r
= r600_tess_factor_read(ctx
, tessinner_idx
, inner_comps
);
3034 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
3035 /* r.x = relpatchid(r0.y) * tf_stride */
3037 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
3038 /* add incoming r0.w to it: t.x = t.x + r0.w */
3039 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3042 V_SQ_ALU_SRC_LITERAL
, stride
,
3047 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3048 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
3049 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
3051 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
3054 else if (out_comp
== 0)
3058 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3059 treg
[i
/ 2], (2 * (i
% 2)),
3061 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3064 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
3065 treg
[i
/ 2], 1 + (2 * (i
%2)),
3066 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
3071 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3072 struct r600_bytecode_gds gds
;
3074 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
3075 gds
.src_gpr
= treg
[i
/ 2];
3076 gds
.src_sel_x
= 2 * (i
% 2);
3077 gds
.src_sel_y
= 1 + (2 * (i
% 2));
3083 gds
.op
= FETCH_OP_TF_WRITE
;
3084 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
3089 // Patch up jump label
3090 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
3091 cf_pop
= ctx
->bc
->cf_last
;
3093 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
3094 cf_jump
->pop_count
= 1;
3095 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
3096 cf_pop
->pop_count
= 1;
3102 * We have to work out the thread ID for load and atomic
3103 * operations, which store the returned value to an index
3104 * in an intermediate buffer.
3105 * The index is calculated by taking the thread id,
3106 * calculated from the MBCNT instructions.
3107 * Then the shader engine ID is multiplied by 256,
3108 * and the wave id is added.
3109 * Then the result is multipled by 64 and thread id is
3112 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
3114 struct r600_bytecode_alu alu
;
3117 if (ctx
->thread_id_gpr_loaded
)
3120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3121 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
3122 alu
.dst
.sel
= ctx
->temp_reg
;
3124 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3125 alu
.src
[0].value
= 0xffffffff;
3127 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3131 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3132 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3133 alu
.dst
.sel
= ctx
->temp_reg
;
3135 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3136 alu
.src
[0].value
= 0xffffffff;
3138 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3143 alu
.op
= ALU_OP3_MULADD_UINT24
;
3144 alu
.dst
.sel
= ctx
->temp_reg
;
3146 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3147 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3148 alu
.src
[1].value
= 256;
3149 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3153 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3157 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3158 ctx
->thread_id_gpr
, 1,
3160 V_SQ_ALU_SRC_LITERAL
, 0x40,
3164 ctx
->thread_id_gpr_loaded
= true;
3168 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3169 struct r600_pipe_shader
*pipeshader
,
3170 union r600_shader_key key
)
3172 struct r600_screen
*rscreen
= rctx
->screen
;
3173 struct r600_shader
*shader
= &pipeshader
->shader
;
3174 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3175 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3176 struct tgsi_full_immediate
*immediate
;
3177 struct r600_shader_ctx ctx
;
3178 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3179 unsigned output_done
, noutput
;
3183 int next_param_base
= 0, next_clip_base
;
3184 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3186 bool ring_outputs
= false;
3187 bool lds_outputs
= false;
3188 bool lds_inputs
= false;
3189 bool pos_emitted
= false;
3191 ctx
.bc
= &shader
->bc
;
3192 ctx
.shader
= shader
;
3194 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3195 rscreen
->has_compressed_msaa_texturing
);
3196 ctx
.tokens
= tokens
;
3197 tgsi_scan_shader(tokens
, &ctx
.info
);
3198 shader
->indirect_files
= ctx
.info
.indirect_files
;
3200 shader
->uses_helper_invocation
= false;
3201 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3202 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3203 shader
->nsys_inputs
= 0;
3205 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3206 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3207 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3208 tgsi_parse_init(&ctx
.parse
, tokens
);
3209 ctx
.type
= ctx
.info
.processor
;
3210 shader
->processor_type
= ctx
.type
;
3211 ctx
.bc
->type
= shader
->processor_type
;
3214 case PIPE_SHADER_VERTEX
:
3215 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3216 shader
->vs_as_es
= key
.vs
.as_es
;
3217 shader
->vs_as_ls
= key
.vs
.as_ls
;
3218 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3219 if (shader
->vs_as_es
)
3220 ring_outputs
= true;
3221 if (shader
->vs_as_ls
)
3224 case PIPE_SHADER_GEOMETRY
:
3225 ring_outputs
= true;
3226 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3227 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3229 case PIPE_SHADER_TESS_CTRL
:
3230 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3231 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3235 case PIPE_SHADER_TESS_EVAL
:
3236 shader
->tes_as_es
= key
.tes
.as_es
;
3237 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3239 if (shader
->tes_as_es
)
3240 ring_outputs
= true;
3242 case PIPE_SHADER_FRAGMENT
:
3243 shader
->two_side
= key
.ps
.color_two_side
;
3244 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3245 shader
->rat_base
= key
.ps
.nr_cbufs
;
3246 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3248 case PIPE_SHADER_COMPUTE
:
3249 shader
->rat_base
= 0;
3250 shader
->image_size_const_offset
= ctx
.info
.file_count
[TGSI_FILE_SAMPLER
];
3256 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3257 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3259 ctx
.gs_for_vs
= NULL
;
3262 ctx
.next_ring_offset
= 0;
3263 ctx
.gs_out_ring_offset
= 0;
3264 ctx
.gs_next_vertex
= 0;
3265 ctx
.gs_stream_output_info
= &so
;
3268 ctx
.fixed_pt_position_gpr
= -1;
3269 ctx
.fragcoord_input
= -1;
3270 ctx
.colors_used
= 0;
3271 ctx
.clip_vertex_write
= 0;
3272 ctx
.thread_id_gpr_loaded
= false;
3274 ctx
.helper_invoc_reg
= -1;
3275 ctx
.cs_block_size_reg
= -1;
3276 ctx
.cs_grid_size_reg
= -1;
3277 ctx
.cs_block_size_loaded
= false;
3278 ctx
.cs_grid_size_loaded
= false;
3280 shader
->nr_ps_color_exports
= 0;
3281 shader
->nr_ps_max_color_exports
= 0;
3284 /* register allocations */
3285 /* Values [0,127] correspond to GPR[0..127].
3286 * Values [128,159] correspond to constant buffer bank 0
3287 * Values [160,191] correspond to constant buffer bank 1
3288 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3289 * Values [256,287] correspond to constant buffer bank 2 (EG)
3290 * Values [288,319] correspond to constant buffer bank 3 (EG)
3291 * Other special values are shown in the list below.
3292 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3293 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3294 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3295 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3296 * 248 SQ_ALU_SRC_0: special constant 0.0.
3297 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3298 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3299 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3300 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3301 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3302 * 254 SQ_ALU_SRC_PV: previous vector result.
3303 * 255 SQ_ALU_SRC_PS: previous scalar result.
3305 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3306 ctx
.file_offset
[i
] = 0;
3309 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3311 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3312 if (ctx
.info
.num_inputs
)
3313 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3315 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3316 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3317 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3319 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3321 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3322 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
3323 ctx
.helper_invoc_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3324 shader
->uses_helper_invocation
= true;
3328 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3329 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3330 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3332 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3333 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3334 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3335 bool add_tesscoord
= false, add_tess_inout
= false;
3336 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3337 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3338 /* if we have tesscoord save one reg */
3339 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3340 add_tesscoord
= true;
3341 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3342 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3343 add_tess_inout
= true;
3345 if (add_tesscoord
|| add_tess_inout
)
3346 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3348 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3350 if (ctx
.type
== PIPE_SHADER_COMPUTE
) {
3351 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3352 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3353 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_GRID_SIZE
)
3354 ctx
.cs_grid_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3355 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_BLOCK_SIZE
)
3356 ctx
.cs_block_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3360 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3361 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3362 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3363 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3364 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3366 /* Outside the GPR range. This will be translated to one of the
3367 * kcache banks later. */
3368 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3370 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3371 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3372 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3373 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3374 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3376 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3377 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3378 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3379 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3380 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3381 ctx
.tess_input_info
= 0;
3382 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3383 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3384 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3385 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3386 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3387 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3388 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3389 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3390 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3391 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3392 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3395 ctx
.gs_rotated_input
[0] = 0;
3396 ctx
.gs_rotated_input
[1] = 1;
3399 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3402 if (shader
->uses_images
) {
3403 ctx
.thread_id_gpr
= ctx
.temp_reg
++;
3404 ctx
.thread_id_gpr_loaded
= false;
3407 shader
->max_arrays
= 0;
3408 shader
->num_arrays
= 0;
3409 if (indirect_gprs
) {
3411 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3412 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3413 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3414 ctx
.file_offset
[TGSI_FILE_INPUT
],
3417 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3418 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3419 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3420 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3426 ctx
.literals
= NULL
;
3427 ctx
.max_driver_temp_used
= 0;
3429 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3430 ctx
.info
.colors_written
== 1;
3431 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3432 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3434 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3435 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3436 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3437 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3438 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3439 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3440 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3443 if (shader
->vs_as_gs_a
)
3444 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3446 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3447 r600_fetch_tess_io_info(&ctx
);
3449 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3450 tgsi_parse_token(&ctx
.parse
);
3451 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3452 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3453 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3454 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3455 if(ctx
.literals
== NULL
) {
3459 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3460 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3461 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3462 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3465 case TGSI_TOKEN_TYPE_DECLARATION
:
3466 r
= tgsi_declaration(&ctx
);
3470 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3471 case TGSI_TOKEN_TYPE_PROPERTY
:
3474 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3480 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3481 shader
->ring_item_sizes
[1] = 0;
3482 shader
->ring_item_sizes
[2] = 0;
3483 shader
->ring_item_sizes
[3] = 0;
3485 /* Process two side if needed */
3486 if (shader
->two_side
&& ctx
.colors_used
) {
3487 int i
, count
= ctx
.shader
->ninput
;
3488 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3490 /* additional inputs will be allocated right after the existing inputs,
3491 * we won't need them after the color selection, so we don't need to
3492 * reserve these gprs for the rest of the shader code and to adjust
3493 * output offsets etc. */
3494 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3495 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3497 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3498 if (ctx
.face_gpr
== -1) {
3499 i
= ctx
.shader
->ninput
++;
3500 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3501 ctx
.shader
->input
[i
].spi_sid
= 0;
3502 ctx
.shader
->input
[i
].gpr
= gpr
++;
3503 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3506 for (i
= 0; i
< count
; i
++) {
3507 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3508 int ni
= ctx
.shader
->ninput
++;
3509 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3510 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3511 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3512 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3513 // TGSI to LLVM needs to know the lds position of inputs.
3514 // Non LLVM path computes it later (in process_twoside_color)
3515 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3516 ctx
.shader
->input
[i
].back_color_input
= ni
;
3517 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3518 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3525 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3526 shader
->nr_ps_max_color_exports
= 8;
3528 if (ctx
.shader
->uses_helper_invocation
) {
3529 if (ctx
.bc
->chip_class
== CAYMAN
)
3530 r
= cm_load_helper_invocation(&ctx
);
3532 r
= eg_load_helper_invocation(&ctx
);
3537 if (ctx
.fragcoord_input
>= 0) {
3538 if (ctx
.bc
->chip_class
== CAYMAN
) {
3539 for (j
= 0 ; j
< 4; j
++) {
3540 struct r600_bytecode_alu alu
;
3541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3542 alu
.op
= ALU_OP1_RECIP_IEEE
;
3543 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3544 alu
.src
[0].chan
= 3;
3546 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3548 alu
.dst
.write
= (j
== 3);
3550 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3554 struct r600_bytecode_alu alu
;
3555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3556 alu
.op
= ALU_OP1_RECIP_IEEE
;
3557 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3558 alu
.src
[0].chan
= 3;
3560 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3564 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3569 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3570 struct r600_bytecode_alu alu
;
3573 /* GS thread with no output workaround - emit a cut at start of GS */
3574 if (ctx
.bc
->chip_class
== R600
)
3575 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3577 for (j
= 0; j
< 4; j
++) {
3578 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3579 alu
.op
= ALU_OP1_MOV
;
3580 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3581 alu
.src
[0].value
= 0;
3582 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3585 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3590 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3591 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3592 ctx
.gs_rotated_input
[0], 2,
3594 V_SQ_ALU_SRC_LITERAL
, 1);
3598 for (i
= 0; i
< 6; i
++) {
3599 int rotated
= (i
+ 4) % 6;
3600 int offset_reg
= i
/ 3;
3601 int offset_chan
= i
% 3;
3602 int rotated_offset_reg
= rotated
/ 3;
3603 int rotated_offset_chan
= rotated
% 3;
3605 if (offset_reg
== 0 && offset_chan
== 2)
3607 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3608 rotated_offset_chan
= 3;
3610 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3611 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3612 ctx
.gs_rotated_input
[0], 2,
3613 offset_reg
, offset_chan
,
3614 rotated_offset_reg
, rotated_offset_chan
);
3621 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3622 r600_fetch_tess_io_info(&ctx
);
3624 if (shader
->two_side
&& ctx
.colors_used
) {
3625 if ((r
= process_twoside_color_inputs(&ctx
)))
3629 tgsi_parse_init(&ctx
.parse
, tokens
);
3630 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3631 tgsi_parse_token(&ctx
.parse
);
3632 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3633 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3634 r
= tgsi_is_supported(&ctx
);
3637 ctx
.max_driver_temp_used
= 0;
3638 /* reserve first tmp for everyone */
3639 r600_get_temp(&ctx
);
3641 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3642 if ((r
= tgsi_split_constant(&ctx
)))
3644 if ((r
= tgsi_split_literal_constant(&ctx
)))
3646 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3647 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3649 } else if (lds_inputs
) {
3650 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3653 if (ctx
.bc
->chip_class
== CAYMAN
)
3654 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3655 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3656 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3658 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3659 r
= ctx
.inst_info
->process(&ctx
);
3663 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3664 r
= r600_store_tcs_output(&ctx
);
3674 /* Reset the temporary register counter. */
3675 ctx
.max_driver_temp_used
= 0;
3677 noutput
= shader
->noutput
;
3679 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3680 unsigned clipdist_temp
[2];
3682 clipdist_temp
[0] = r600_get_temp(&ctx
);
3683 clipdist_temp
[1] = r600_get_temp(&ctx
);
3685 /* need to convert a clipvertex write into clipdistance writes and not export
3686 the clip vertex anymore */
3688 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3689 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3690 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3692 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3693 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3696 /* reset spi_sid for clipvertex output to avoid confusing spi */
3697 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3699 shader
->clip_dist_write
= 0xFF;
3700 shader
->cc_dist_mask
= 0xFF;
3702 for (i
= 0; i
< 8; i
++) {
3706 for (j
= 0; j
< 4; j
++) {
3707 struct r600_bytecode_alu alu
;
3708 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3709 alu
.op
= ALU_OP2_DOT4
;
3710 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3711 alu
.src
[0].chan
= j
;
3713 alu
.src
[1].sel
= 512 + i
;
3714 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3715 alu
.src
[1].chan
= j
;
3717 alu
.dst
.sel
= clipdist_temp
[oreg
];
3719 alu
.dst
.write
= (j
== ochan
);
3722 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3729 /* Add stream outputs. */
3730 if (so
.num_outputs
) {
3732 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3734 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3737 emit_streamout(&ctx
, &so
, -1, NULL
);
3739 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3740 convert_edgeflag_to_int(&ctx
);
3742 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3743 r600_emit_tess_factor(&ctx
);
3746 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3747 if (ctx
.shader
->noutput
)
3748 emit_lds_vs_writes(&ctx
);
3750 } else if (ring_outputs
) {
3751 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3752 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3753 ctx
.gs_export_gpr_tregs
[1] = -1;
3754 ctx
.gs_export_gpr_tregs
[2] = -1;
3755 ctx
.gs_export_gpr_tregs
[3] = -1;
3757 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3761 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3763 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3764 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3765 output
[j
].gpr
= shader
->output
[i
].gpr
;
3766 output
[j
].elem_size
= 3;
3767 output
[j
].swizzle_x
= 0;
3768 output
[j
].swizzle_y
= 1;
3769 output
[j
].swizzle_z
= 2;
3770 output
[j
].swizzle_w
= 3;
3771 output
[j
].burst_count
= 1;
3772 output
[j
].type
= 0xffffffff;
3773 output
[j
].op
= CF_OP_EXPORT
;
3775 case PIPE_SHADER_VERTEX
:
3776 case PIPE_SHADER_TESS_EVAL
:
3777 switch (shader
->output
[i
].name
) {
3778 case TGSI_SEMANTIC_POSITION
:
3779 output
[j
].array_base
= 60;
3780 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3784 case TGSI_SEMANTIC_PSIZE
:
3785 output
[j
].array_base
= 61;
3786 output
[j
].swizzle_y
= 7;
3787 output
[j
].swizzle_z
= 7;
3788 output
[j
].swizzle_w
= 7;
3789 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3792 case TGSI_SEMANTIC_EDGEFLAG
:
3793 output
[j
].array_base
= 61;
3794 output
[j
].swizzle_x
= 7;
3795 output
[j
].swizzle_y
= 0;
3796 output
[j
].swizzle_z
= 7;
3797 output
[j
].swizzle_w
= 7;
3798 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3801 case TGSI_SEMANTIC_LAYER
:
3802 /* spi_sid is 0 for outputs that are
3803 * not consumed by PS */
3804 if (shader
->output
[i
].spi_sid
) {
3805 output
[j
].array_base
= next_param_base
++;
3806 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3808 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3810 output
[j
].array_base
= 61;
3811 output
[j
].swizzle_x
= 7;
3812 output
[j
].swizzle_y
= 7;
3813 output
[j
].swizzle_z
= 0;
3814 output
[j
].swizzle_w
= 7;
3815 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3818 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3819 /* spi_sid is 0 for outputs that are
3820 * not consumed by PS */
3821 if (shader
->output
[i
].spi_sid
) {
3822 output
[j
].array_base
= next_param_base
++;
3823 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3825 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3827 output
[j
].array_base
= 61;
3828 output
[j
].swizzle_x
= 7;
3829 output
[j
].swizzle_y
= 7;
3830 output
[j
].swizzle_z
= 7;
3831 output
[j
].swizzle_w
= 0;
3832 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3835 case TGSI_SEMANTIC_CLIPVERTEX
:
3838 case TGSI_SEMANTIC_CLIPDIST
:
3839 output
[j
].array_base
= next_clip_base
++;
3840 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3842 /* spi_sid is 0 for clipdistance outputs that were generated
3843 * for clipvertex - we don't need to pass them to PS */
3844 if (shader
->output
[i
].spi_sid
) {
3846 /* duplicate it as PARAM to pass to the pixel shader */
3847 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3848 output
[j
].array_base
= next_param_base
++;
3849 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3852 case TGSI_SEMANTIC_FOG
:
3853 output
[j
].swizzle_y
= 4; /* 0 */
3854 output
[j
].swizzle_z
= 4; /* 0 */
3855 output
[j
].swizzle_w
= 5; /* 1 */
3857 case TGSI_SEMANTIC_PRIMID
:
3858 output
[j
].swizzle_x
= 2;
3859 output
[j
].swizzle_y
= 4; /* 0 */
3860 output
[j
].swizzle_z
= 4; /* 0 */
3861 output
[j
].swizzle_w
= 4; /* 0 */
3866 case PIPE_SHADER_FRAGMENT
:
3867 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3868 /* never export more colors than the number of CBs */
3869 if (shader
->output
[i
].sid
>= max_color_exports
) {
3874 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3875 output
[j
].array_base
= shader
->output
[i
].sid
;
3876 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3877 shader
->nr_ps_color_exports
++;
3878 shader
->ps_color_export_mask
|= (0xf << (shader
->output
[i
].sid
* 4));
3880 /* If the i-th target format is set, all previous target formats must
3881 * be non-zero to avoid hangs. - from radeonsi, seems to apply to eg as well.
3883 if (shader
->output
[i
].sid
> 0)
3884 for (unsigned x
= 0; x
< shader
->output
[i
].sid
; x
++)
3885 shader
->ps_color_export_mask
|= (1 << (x
*4));
3887 if (shader
->output
[i
].sid
> shader
->ps_export_highest
)
3888 shader
->ps_export_highest
= shader
->output
[i
].sid
;
3889 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3890 for (k
= 1; k
< max_color_exports
; k
++) {
3892 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3893 output
[j
].gpr
= shader
->output
[i
].gpr
;
3894 output
[j
].elem_size
= 3;
3895 output
[j
].swizzle_x
= 0;
3896 output
[j
].swizzle_y
= 1;
3897 output
[j
].swizzle_z
= 2;
3898 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3899 output
[j
].burst_count
= 1;
3900 output
[j
].array_base
= k
;
3901 output
[j
].op
= CF_OP_EXPORT
;
3902 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3903 shader
->nr_ps_color_exports
++;
3904 shader
->ps_color_export_mask
|= (0xf << (j
* 4));
3907 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3908 output
[j
].array_base
= 61;
3909 output
[j
].swizzle_x
= 2;
3910 output
[j
].swizzle_y
= 7;
3911 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3912 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3913 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3914 output
[j
].array_base
= 61;
3915 output
[j
].swizzle_x
= 7;
3916 output
[j
].swizzle_y
= 1;
3917 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3918 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3919 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3920 output
[j
].array_base
= 61;
3921 output
[j
].swizzle_x
= 7;
3922 output
[j
].swizzle_y
= 7;
3923 output
[j
].swizzle_z
= 0;
3924 output
[j
].swizzle_w
= 7;
3925 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3927 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3932 case PIPE_SHADER_TESS_CTRL
:
3935 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3940 if (output
[j
].type
== 0xffffffff) {
3941 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3942 output
[j
].array_base
= next_param_base
++;
3946 /* add fake position export */
3947 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3948 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3950 output
[j
].elem_size
= 3;
3951 output
[j
].swizzle_x
= 7;
3952 output
[j
].swizzle_y
= 7;
3953 output
[j
].swizzle_z
= 7;
3954 output
[j
].swizzle_w
= 7;
3955 output
[j
].burst_count
= 1;
3956 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3957 output
[j
].array_base
= 60;
3958 output
[j
].op
= CF_OP_EXPORT
;
3962 /* add fake param output for vertex shader if no param is exported */
3963 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3964 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3966 output
[j
].elem_size
= 3;
3967 output
[j
].swizzle_x
= 7;
3968 output
[j
].swizzle_y
= 7;
3969 output
[j
].swizzle_z
= 7;
3970 output
[j
].swizzle_w
= 7;
3971 output
[j
].burst_count
= 1;
3972 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3973 output
[j
].array_base
= 0;
3974 output
[j
].op
= CF_OP_EXPORT
;
3978 /* add fake pixel export */
3979 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3980 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3982 output
[j
].elem_size
= 3;
3983 output
[j
].swizzle_x
= 7;
3984 output
[j
].swizzle_y
= 7;
3985 output
[j
].swizzle_z
= 7;
3986 output
[j
].swizzle_w
= 7;
3987 output
[j
].burst_count
= 1;
3988 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3989 output
[j
].array_base
= 0;
3990 output
[j
].op
= CF_OP_EXPORT
;
3992 shader
->nr_ps_color_exports
++;
3993 shader
->ps_color_export_mask
= 0xf;
3998 /* set export done on last export of each type */
3999 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
4000 if (!(output_done
& (1 << output
[k
].type
))) {
4001 output_done
|= (1 << output
[k
].type
);
4002 output
[k
].op
= CF_OP_EXPORT_DONE
;
4005 /* add output to bytecode */
4006 for (i
= 0; i
< noutput
; i
++) {
4007 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
4013 /* add program end */
4014 if (ctx
.bc
->chip_class
== CAYMAN
)
4015 cm_bytecode_add_cf_end(ctx
.bc
);
4017 const struct cf_op_info
*last
= NULL
;
4019 if (ctx
.bc
->cf_last
)
4020 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
4022 /* alu clause instructions don't have EOP bit, so add NOP */
4023 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
4024 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
4026 ctx
.bc
->cf_last
->end_of_program
= 1;
4029 /* check GPR limit - we have 124 = 128 - 4
4030 * (4 are reserved as alu clause temporary registers) */
4031 if (ctx
.bc
->ngpr
> 124) {
4032 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
4037 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
4038 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
4043 tgsi_parse_free(&ctx
.parse
);
4047 tgsi_parse_free(&ctx
.parse
);
4051 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
4053 const unsigned tgsi_opcode
=
4054 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
4055 R600_ERR("%s tgsi opcode unsupported\n",
4056 tgsi_get_opcode_name(tgsi_opcode
));
4060 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
4065 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
4066 const struct r600_shader_src
*shader_src
,
4069 bc_src
->sel
= shader_src
->sel
;
4070 bc_src
->chan
= shader_src
->swizzle
[chan
];
4071 bc_src
->neg
= shader_src
->neg
;
4072 bc_src
->abs
= shader_src
->abs
;
4073 bc_src
->rel
= shader_src
->rel
;
4074 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
4075 bc_src
->kc_bank
= shader_src
->kc_bank
;
4076 bc_src
->kc_rel
= shader_src
->kc_rel
;
4079 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
4085 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
4087 bc_src
->neg
= !bc_src
->neg
;
4090 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
4091 const struct tgsi_full_dst_register
*tgsi_dst
,
4093 struct r600_bytecode_alu_dst
*r600_dst
)
4095 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4097 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
4098 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
4099 r600_dst
->chan
= swizzle
;
4100 r600_dst
->write
= 1;
4101 if (inst
->Instruction
.Saturate
) {
4102 r600_dst
->clamp
= 1;
4104 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
4105 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
4109 if (tgsi_dst
->Register
.Indirect
)
4110 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4114 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4116 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4117 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4118 struct r600_bytecode_alu alu
;
4119 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4121 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4124 switch (write_mask
) {
4126 if (swizzle_x
== 2) {
4133 if (swizzle_x
== 2) {
4142 if (swizzle_x
== 0) {
4149 if (swizzle_x
== 0) {
4160 lasti
= tgsi_last_instruction(write_mask
);
4161 for (i
= 0; i
<= lasti
; i
++) {
4163 if (!(write_mask
& (1 << i
)))
4166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4169 if (use_tmp
|| dest_temp
) {
4170 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4174 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4176 if (i
== 1 || i
== 3)
4179 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4181 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4182 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4183 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4185 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4186 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4189 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4190 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4193 /* handle some special cases */
4194 if (i
== 1 || i
== 3) {
4195 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4196 case TGSI_OPCODE_DABS
:
4197 r600_bytecode_src_set_abs(&alu
.src
[0]);
4206 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4212 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4214 lasti
= tgsi_last_instruction(write_mask
);
4215 /* move result from temp to dst */
4216 for (i
= 0; i
<= lasti
; i
++) {
4217 if (!(write_mask
& (1 << i
)))
4220 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4221 alu
.op
= ALU_OP1_MOV
;
4224 alu
.dst
.sel
= dest_temp
;
4228 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4229 alu
.src
[0].sel
= ctx
->temp_reg
;
4230 alu
.src
[0].chan
= use_tmp
- 1;
4231 alu
.last
= (i
== lasti
);
4233 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4241 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4243 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4244 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4245 /* confirm writemasking */
4246 if ((write_mask
& 0x3) != 0x3 &&
4247 (write_mask
& 0xc) != 0xc) {
4248 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4251 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4254 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4256 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4259 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4261 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4264 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4266 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4267 struct r600_bytecode_alu alu
;
4270 int tmp
= r600_get_temp(ctx
);
4272 for (i
= 0; i
< lasti
+ 1; i
++) {
4274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4275 alu
.op
= ctx
->inst_info
->op
;
4276 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4277 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4280 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4281 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4290 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4297 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4299 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4300 struct r600_bytecode_alu alu
;
4301 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4302 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4303 /* use temp register if trans_only and more than one dst component */
4304 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4305 unsigned op
= ctx
->inst_info
->op
;
4307 if (op
== ALU_OP2_MUL_IEEE
&&
4308 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4311 for (i
= 0; i
<= lasti
; i
++) {
4312 if (!(write_mask
& (1 << i
)))
4315 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4317 alu
.dst
.sel
= ctx
->temp_reg
;
4321 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4325 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4326 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4329 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4330 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4332 if (i
== lasti
|| trans_only
) {
4335 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4341 /* move result from temp to dst */
4342 for (i
= 0; i
<= lasti
; i
++) {
4343 if (!(write_mask
& (1 << i
)))
4346 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4347 alu
.op
= ALU_OP1_MOV
;
4348 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4349 alu
.src
[0].sel
= ctx
->temp_reg
;
4350 alu
.src
[0].chan
= i
;
4351 alu
.last
= (i
== lasti
);
4353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4361 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4363 return tgsi_op2_s(ctx
, 0, 0);
4366 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4368 return tgsi_op2_s(ctx
, 1, 0);
4371 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4373 return tgsi_op2_s(ctx
, 0, 1);
4376 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4378 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4379 struct r600_bytecode_alu alu
;
4381 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4383 for (i
= 0; i
< lasti
+ 1; i
++) {
4385 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4388 alu
.op
= ctx
->inst_info
->op
;
4390 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4392 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4394 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4407 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4409 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4410 struct r600_bytecode_alu alu
;
4412 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4414 for (i
= 0; i
< lasti
+ 1; i
++) {
4416 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4418 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4419 alu
.op
= ALU_OP1_MOV
;
4421 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4423 if (i
== 1 || i
== 3)
4424 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4425 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4430 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4438 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4440 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4441 struct r600_bytecode_alu alu
;
4442 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4445 for (i
= 0; i
<= 3; i
++) {
4446 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4447 alu
.op
= ctx
->inst_info
->op
;
4449 alu
.dst
.sel
= ctx
->temp_reg
;
4452 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4453 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4459 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4464 /* Replicate significand result across channels. */
4465 for (i
= 0; i
<= 3; i
++) {
4466 if (!(write_mask
& (1 << i
)))
4469 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4470 alu
.op
= ALU_OP1_MOV
;
4471 alu
.src
[0].chan
= (i
& 1) + 2;
4472 alu
.src
[0].sel
= ctx
->temp_reg
;
4474 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4477 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4482 for (i
= 0; i
<= 3; i
++) {
4483 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4484 /* MOV third channels to writemask dst1 */
4485 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4486 alu
.op
= ALU_OP1_MOV
;
4487 alu
.src
[0].chan
= 1;
4488 alu
.src
[0].sel
= ctx
->temp_reg
;
4490 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4492 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4502 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4504 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4505 struct r600_bytecode_alu alu
;
4507 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4508 int temp_reg
= r600_get_temp(ctx
);
4510 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4511 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4513 for (c
= 0; c
< 2; c
++) {
4515 if (write_mask
& (0x3 << dchan
)) {
4516 /* split into 24-bit int and 8-bit int */
4517 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4518 alu
.op
= ALU_OP2_AND_INT
;
4519 alu
.dst
.sel
= temp_reg
;
4520 alu
.dst
.chan
= dchan
;
4521 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4522 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4523 alu
.src
[1].value
= 0xffffff00;
4525 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4530 alu
.op
= ALU_OP2_AND_INT
;
4531 alu
.dst
.sel
= temp_reg
;
4532 alu
.dst
.chan
= dchan
+ 1;
4533 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4534 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4535 alu
.src
[1].value
= 0xff;
4538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4544 for (c
= 0; c
< 2; c
++) {
4546 if (write_mask
& (0x3 << dchan
)) {
4547 for (i
= dchan
; i
<= dchan
+ 1; i
++) {
4548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4549 alu
.op
= i
== dchan
? ctx
->inst_info
->op
: ALU_OP1_UINT_TO_FLT
;
4551 alu
.src
[0].sel
= temp_reg
;
4552 alu
.src
[0].chan
= i
;
4553 alu
.dst
.sel
= temp_reg
;
4556 if (ctx
->bc
->chip_class
== CAYMAN
)
4557 alu
.last
= i
== dchan
+ 1;
4559 alu
.last
= 1; /* trans only ops on evergreen */
4561 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4568 for (c
= 0; c
< 2; c
++) {
4570 if (write_mask
& (0x3 << dchan
)) {
4571 for (i
= 0; i
< 4; i
++) {
4572 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4573 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4575 alu
.src
[0].chan
= dchan
+ (i
/ 2);
4576 if (i
== 0 || i
== 2)
4577 alu
.src
[0].sel
= temp_reg
;
4579 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4580 alu
.src
[0].value
= 0x0;
4582 alu
.dst
.sel
= ctx
->temp_reg
;
4587 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4592 for (i
= 0; i
<= 1; i
++) {
4593 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4594 alu
.op
= ALU_OP2_ADD_64
;
4596 alu
.src
[0].chan
= fp64_switch(i
);
4597 alu
.src
[0].sel
= ctx
->temp_reg
;
4599 alu
.src
[1].chan
= fp64_switch(i
+ 2);
4600 alu
.src
[1].sel
= ctx
->temp_reg
;
4601 tgsi_dst(ctx
, &inst
->Dst
[0], dchan
+ i
, &alu
.dst
);
4604 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4614 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4616 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4617 struct r600_bytecode_alu alu
;
4619 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4620 int treg
= r600_get_temp(ctx
);
4621 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4622 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4624 /* do a 64->32 into a temp register */
4625 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4629 for (i
= 0; i
<= lasti
; i
++) {
4630 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4633 alu
.op
= ctx
->inst_info
->op
;
4635 alu
.src
[0].chan
= i
;
4636 alu
.src
[0].sel
= treg
;
4637 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4638 alu
.last
= (i
== lasti
);
4640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4648 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4651 struct r600_shader_src
*src
,
4654 struct r600_bytecode_alu alu
;
4655 const int last_slot
= 3;
4658 /* these have to write the result to X/Y by the looks of it */
4659 for (int i
= 0 ; i
< last_slot
; i
++) {
4660 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4663 r600_bytecode_src(&alu
.src
[0], src
, 1);
4664 r600_bytecode_src(&alu
.src
[1], src
, 0);
4667 r600_bytecode_src_set_abs(&alu
.src
[1]);
4669 alu
.dst
.sel
= dst_reg
;
4671 alu
.dst
.write
= (i
== 0 || i
== 1);
4673 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4675 r
= r600_bytecode_add_alu(bc
, &alu
);
4683 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4685 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4687 struct r600_bytecode_alu alu
;
4688 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4689 int t1
= ctx
->temp_reg
;
4691 /* should only be one src regs */
4692 assert(inst
->Instruction
.NumSrcRegs
== 1);
4694 /* only support one double at a time */
4695 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4696 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4698 r
= cayman_emit_unary_double_raw(
4699 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4701 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4702 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4706 for (i
= 0 ; i
<= lasti
; i
++) {
4707 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4710 alu
.op
= ALU_OP1_MOV
;
4711 alu
.src
[0].sel
= t1
;
4712 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4713 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4724 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4726 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4728 struct r600_bytecode_alu alu
;
4729 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4731 for (i
= 0 ; i
< last_slot
; i
++) {
4732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4733 alu
.op
= ctx
->inst_info
->op
;
4734 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4735 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4737 /* RSQ should take the absolute value of src */
4738 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4739 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4742 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4743 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4745 if (i
== last_slot
- 1)
4747 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4754 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4756 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4758 struct r600_bytecode_alu alu
;
4759 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4760 int t1
= ctx
->temp_reg
;
4762 for (k
= 0; k
<= lasti
; k
++) {
4763 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4766 for (i
= 0 ; i
< 4; i
++) {
4767 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4768 alu
.op
= ctx
->inst_info
->op
;
4769 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4770 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4774 alu
.dst
.write
= (i
== k
);
4777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4783 for (i
= 0 ; i
<= lasti
; i
++) {
4784 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4787 alu
.op
= ALU_OP1_MOV
;
4788 alu
.src
[0].sel
= t1
;
4789 alu
.src
[0].chan
= i
;
4790 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4794 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4803 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4805 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4807 struct r600_bytecode_alu alu
;
4808 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4809 int t1
= ctx
->temp_reg
;
4811 /* t1 would get overwritten below if we actually tried to
4812 * multiply two pairs of doubles at a time. */
4813 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4814 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4816 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4818 for (i
= 0; i
< 4; i
++) {
4819 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4820 alu
.op
= ctx
->inst_info
->op
;
4821 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4822 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4829 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4834 for (i
= 0; i
<= lasti
; i
++) {
4835 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4837 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4838 alu
.op
= ALU_OP1_MOV
;
4839 alu
.src
[0].sel
= t1
;
4840 alu
.src
[0].chan
= i
;
4841 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4845 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4854 * Emit RECIP_64 + MUL_64 to implement division.
4856 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4858 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4860 struct r600_bytecode_alu alu
;
4861 int t1
= ctx
->temp_reg
;
4864 /* Only support one double at a time. This is the same constraint as
4865 * in DMUL lowering. */
4866 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4867 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4869 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4871 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4875 for (int i
= 0; i
< 4; i
++) {
4876 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4877 alu
.op
= ALU_OP2_MUL_64
;
4879 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4881 alu
.src
[1].sel
= t1
;
4882 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4889 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4894 for (int i
= 0; i
< 2; i
++) {
4895 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4896 alu
.op
= ALU_OP1_MOV
;
4897 alu
.src
[0].sel
= t1
;
4898 alu
.src
[0].chan
= i
;
4899 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4903 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4911 * r600 - trunc to -PI..PI range
4912 * r700 - normalize by dividing by 2PI
4915 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4918 struct r600_bytecode_alu alu
;
4920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4921 alu
.op
= ALU_OP3_MULADD
;
4925 alu
.dst
.sel
= ctx
->temp_reg
;
4928 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4930 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4931 alu
.src
[1].chan
= 0;
4932 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4933 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4934 alu
.src
[2].chan
= 0;
4936 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4940 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4941 alu
.op
= ALU_OP1_FRACT
;
4944 alu
.dst
.sel
= ctx
->temp_reg
;
4947 alu
.src
[0].sel
= ctx
->temp_reg
;
4948 alu
.src
[0].chan
= 0;
4950 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4954 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4955 alu
.op
= ALU_OP3_MULADD
;
4959 alu
.dst
.sel
= ctx
->temp_reg
;
4962 alu
.src
[0].sel
= ctx
->temp_reg
;
4963 alu
.src
[0].chan
= 0;
4965 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4966 alu
.src
[1].chan
= 0;
4967 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4968 alu
.src
[2].chan
= 0;
4970 if (ctx
->bc
->chip_class
== R600
) {
4971 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4972 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4974 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4975 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4986 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4988 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4989 struct r600_bytecode_alu alu
;
4990 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4993 r
= tgsi_setup_trig(ctx
);
4998 for (i
= 0; i
< last_slot
; i
++) {
4999 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5000 alu
.op
= ctx
->inst_info
->op
;
5003 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5004 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5006 alu
.src
[0].sel
= ctx
->temp_reg
;
5007 alu
.src
[0].chan
= 0;
5008 if (i
== last_slot
- 1)
5010 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5017 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
5019 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5020 struct r600_bytecode_alu alu
;
5022 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5024 r
= tgsi_setup_trig(ctx
);
5028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5029 alu
.op
= ctx
->inst_info
->op
;
5031 alu
.dst
.sel
= ctx
->temp_reg
;
5034 alu
.src
[0].sel
= ctx
->temp_reg
;
5035 alu
.src
[0].chan
= 0;
5037 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5041 /* replicate result */
5042 for (i
= 0; i
< lasti
+ 1; i
++) {
5043 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5047 alu
.op
= ALU_OP1_MOV
;
5049 alu
.src
[0].sel
= ctx
->temp_reg
;
5050 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5053 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5060 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
5062 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5063 struct r600_bytecode_alu alu
;
5066 for (i
= 0; i
< 4; i
++) {
5067 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5068 alu
.op
= ctx
->inst_info
->op
;
5072 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5074 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
5075 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5078 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5083 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5088 /* kill must be last in ALU */
5089 ctx
->bc
->force_add_cf
= 1;
5090 ctx
->shader
->uses_kill
= TRUE
;
5094 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
5096 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5097 struct r600_bytecode_alu alu
;
5100 /* tmp.x = max(src.y, 0.0) */
5101 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5102 alu
.op
= ALU_OP2_MAX
;
5103 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
5104 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5105 alu
.src
[1].chan
= 1;
5107 alu
.dst
.sel
= ctx
->temp_reg
;
5112 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5116 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
5122 if (ctx
->bc
->chip_class
== CAYMAN
) {
5123 for (i
= 0; i
< 3; i
++) {
5124 /* tmp.z = log(tmp.x) */
5125 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5126 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5127 alu
.src
[0].sel
= ctx
->temp_reg
;
5128 alu
.src
[0].chan
= 0;
5129 alu
.dst
.sel
= ctx
->temp_reg
;
5137 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5142 /* tmp.z = log(tmp.x) */
5143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5144 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5145 alu
.src
[0].sel
= ctx
->temp_reg
;
5146 alu
.src
[0].chan
= 0;
5147 alu
.dst
.sel
= ctx
->temp_reg
;
5151 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5156 chan
= alu
.dst
.chan
;
5159 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
5160 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5161 alu
.op
= ALU_OP3_MUL_LIT
;
5162 alu
.src
[0].sel
= sel
;
5163 alu
.src
[0].chan
= chan
;
5164 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
5165 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
5166 alu
.dst
.sel
= ctx
->temp_reg
;
5171 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5175 if (ctx
->bc
->chip_class
== CAYMAN
) {
5176 for (i
= 0; i
< 3; i
++) {
5177 /* dst.z = exp(tmp.x) */
5178 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5179 alu
.op
= ALU_OP1_EXP_IEEE
;
5180 alu
.src
[0].sel
= ctx
->temp_reg
;
5181 alu
.src
[0].chan
= 0;
5182 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5193 /* dst.z = exp(tmp.x) */
5194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5195 alu
.op
= ALU_OP1_EXP_IEEE
;
5196 alu
.src
[0].sel
= ctx
->temp_reg
;
5197 alu
.src
[0].chan
= 0;
5198 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5200 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5208 alu
.op
= ALU_OP1_MOV
;
5209 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5210 alu
.src
[0].chan
= 0;
5211 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5212 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5217 /* dst.y = max(src.x, 0.0) */
5218 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5219 alu
.op
= ALU_OP2_MAX
;
5220 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5221 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5222 alu
.src
[1].chan
= 0;
5223 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5224 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5230 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5231 alu
.op
= ALU_OP1_MOV
;
5232 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5233 alu
.src
[0].chan
= 0;
5234 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5235 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5237 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5244 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5246 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5247 struct r600_bytecode_alu alu
;
5250 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5252 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5254 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5255 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5256 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5258 alu
.dst
.sel
= ctx
->temp_reg
;
5261 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5264 /* replicate result */
5265 return tgsi_helper_tempx_replicate(ctx
);
5268 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5270 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5271 struct r600_bytecode_alu alu
;
5274 for (i
= 0; i
< 4; i
++) {
5275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5276 alu
.src
[0].sel
= ctx
->temp_reg
;
5277 alu
.op
= ALU_OP1_MOV
;
5279 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5280 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5283 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5290 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5292 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5293 struct r600_bytecode_alu alu
;
5296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5297 alu
.op
= ctx
->inst_info
->op
;
5298 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5299 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5301 alu
.dst
.sel
= ctx
->temp_reg
;
5304 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5307 /* replicate result */
5308 return tgsi_helper_tempx_replicate(ctx
);
5311 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5313 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5315 struct r600_bytecode_alu alu
;
5316 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5318 for (i
= 0; i
< 3; i
++) {
5319 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5320 alu
.op
= ALU_OP1_LOG_IEEE
;
5321 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5322 alu
.dst
.sel
= ctx
->temp_reg
;
5327 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5333 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5334 alu
.op
= ALU_OP2_MUL
;
5335 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5336 alu
.src
[1].sel
= ctx
->temp_reg
;
5337 alu
.dst
.sel
= ctx
->temp_reg
;
5340 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5344 for (i
= 0; i
< last_slot
; i
++) {
5345 /* POW(a,b) = EXP2(b * LOG2(a))*/
5346 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5347 alu
.op
= ALU_OP1_EXP_IEEE
;
5348 alu
.src
[0].sel
= ctx
->temp_reg
;
5350 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5351 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5352 if (i
== last_slot
- 1)
5354 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5361 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5363 struct r600_bytecode_alu alu
;
5367 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5368 alu
.op
= ALU_OP1_LOG_IEEE
;
5369 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5370 alu
.dst
.sel
= ctx
->temp_reg
;
5373 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5377 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5378 alu
.op
= ALU_OP2_MUL
;
5379 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5380 alu
.src
[1].sel
= ctx
->temp_reg
;
5381 alu
.dst
.sel
= ctx
->temp_reg
;
5384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5387 /* POW(a,b) = EXP2(b * LOG2(a))*/
5388 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5389 alu
.op
= ALU_OP1_EXP_IEEE
;
5390 alu
.src
[0].sel
= ctx
->temp_reg
;
5391 alu
.dst
.sel
= ctx
->temp_reg
;
5394 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5397 return tgsi_helper_tempx_replicate(ctx
);
5400 static int emit_mul_int_op(struct r600_bytecode
*bc
,
5401 struct r600_bytecode_alu
*alu_src
)
5403 struct r600_bytecode_alu alu
;
5406 if (bc
->chip_class
== CAYMAN
) {
5407 for (i
= 0; i
< 4; i
++) {
5409 alu
.dst
.write
= (i
== alu_src
->dst
.chan
);
5410 alu
.last
= (i
== 3);
5412 r
= r600_bytecode_add_alu(bc
, &alu
);
5418 r
= r600_bytecode_add_alu(bc
, &alu
);
5425 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5427 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5428 struct r600_bytecode_alu alu
;
5430 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5431 int tmp0
= ctx
->temp_reg
;
5432 int tmp1
= r600_get_temp(ctx
);
5433 int tmp2
= r600_get_temp(ctx
);
5434 int tmp3
= r600_get_temp(ctx
);
5437 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5439 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5440 * 2. tmp0.z = lo (tmp0.x * src2)
5441 * 3. tmp0.w = -tmp0.z
5442 * 4. tmp0.y = hi (tmp0.x * src2)
5443 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5444 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5445 * 7. tmp1.x = tmp0.x - tmp0.w
5446 * 8. tmp1.y = tmp0.x + tmp0.w
5447 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5448 * 10. tmp0.z = hi(tmp0.x * src1) = q
5449 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5451 * 12. tmp0.w = src1 - tmp0.y = r
5452 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5453 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5457 * 15. tmp1.z = tmp0.z + 1 = q + 1
5458 * 16. tmp1.w = tmp0.z - 1 = q - 1
5462 * 15. tmp1.z = tmp0.w - src2 = r - src2
5463 * 16. tmp1.w = tmp0.w + src2 = r + src2
5467 * 17. tmp1.x = tmp1.x & tmp1.y
5469 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5470 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5472 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5473 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5477 * Same as unsigned, using abs values of the operands,
5478 * and fixing the sign of the result in the end.
5481 for (i
= 0; i
< 4; i
++) {
5482 if (!(write_mask
& (1<<i
)))
5487 /* tmp2.x = -src0 */
5488 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5489 alu
.op
= ALU_OP2_SUB_INT
;
5495 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5497 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5500 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5503 /* tmp2.y = -src1 */
5504 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5505 alu
.op
= ALU_OP2_SUB_INT
;
5511 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5513 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5516 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5519 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5520 /* it will be a sign of the quotient */
5523 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5524 alu
.op
= ALU_OP2_XOR_INT
;
5530 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5531 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5534 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5538 /* tmp2.x = |src0| */
5539 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5540 alu
.op
= ALU_OP3_CNDGE_INT
;
5547 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5548 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5549 alu
.src
[2].sel
= tmp2
;
5550 alu
.src
[2].chan
= 0;
5553 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5556 /* tmp2.y = |src1| */
5557 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5558 alu
.op
= ALU_OP3_CNDGE_INT
;
5565 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5566 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5567 alu
.src
[2].sel
= tmp2
;
5568 alu
.src
[2].chan
= 1;
5571 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5576 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5577 if (ctx
->bc
->chip_class
== CAYMAN
) {
5578 /* tmp3.x = u2f(src2) */
5579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5580 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5587 alu
.src
[0].sel
= tmp2
;
5588 alu
.src
[0].chan
= 1;
5590 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5594 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5597 /* tmp0.x = recip(tmp3.x) */
5598 for (j
= 0 ; j
< 3; j
++) {
5599 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5600 alu
.op
= ALU_OP1_RECIP_IEEE
;
5604 alu
.dst
.write
= (j
== 0);
5606 alu
.src
[0].sel
= tmp3
;
5607 alu
.src
[0].chan
= 0;
5611 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5616 alu
.op
= ALU_OP2_MUL
;
5618 alu
.src
[0].sel
= tmp0
;
5619 alu
.src
[0].chan
= 0;
5621 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5622 alu
.src
[1].value
= 0x4f800000;
5627 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5632 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5638 alu
.src
[0].sel
= tmp3
;
5639 alu
.src
[0].chan
= 0;
5642 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5646 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5647 alu
.op
= ALU_OP1_RECIP_UINT
;
5654 alu
.src
[0].sel
= tmp2
;
5655 alu
.src
[0].chan
= 1;
5657 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5661 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5665 /* 2. tmp0.z = lo (tmp0.x * src2) */
5666 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5667 alu
.op
= ALU_OP2_MULLO_UINT
;
5673 alu
.src
[0].sel
= tmp0
;
5674 alu
.src
[0].chan
= 0;
5676 alu
.src
[1].sel
= tmp2
;
5677 alu
.src
[1].chan
= 1;
5679 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5682 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5685 /* 3. tmp0.w = -tmp0.z */
5686 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5687 alu
.op
= ALU_OP2_SUB_INT
;
5693 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5694 alu
.src
[1].sel
= tmp0
;
5695 alu
.src
[1].chan
= 2;
5698 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5701 /* 4. tmp0.y = hi (tmp0.x * src2) */
5702 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5703 alu
.op
= ALU_OP2_MULHI_UINT
;
5709 alu
.src
[0].sel
= tmp0
;
5710 alu
.src
[0].chan
= 0;
5713 alu
.src
[1].sel
= tmp2
;
5714 alu
.src
[1].chan
= 1;
5716 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5719 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5722 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5724 alu
.op
= ALU_OP3_CNDE_INT
;
5731 alu
.src
[0].sel
= tmp0
;
5732 alu
.src
[0].chan
= 1;
5733 alu
.src
[1].sel
= tmp0
;
5734 alu
.src
[1].chan
= 3;
5735 alu
.src
[2].sel
= tmp0
;
5736 alu
.src
[2].chan
= 2;
5739 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5742 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5743 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5744 alu
.op
= ALU_OP2_MULHI_UINT
;
5750 alu
.src
[0].sel
= tmp0
;
5751 alu
.src
[0].chan
= 2;
5753 alu
.src
[1].sel
= tmp0
;
5754 alu
.src
[1].chan
= 0;
5756 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5759 /* 7. tmp1.x = tmp0.x - tmp0.w */
5760 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5761 alu
.op
= ALU_OP2_SUB_INT
;
5767 alu
.src
[0].sel
= tmp0
;
5768 alu
.src
[0].chan
= 0;
5769 alu
.src
[1].sel
= tmp0
;
5770 alu
.src
[1].chan
= 3;
5773 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5776 /* 8. tmp1.y = tmp0.x + tmp0.w */
5777 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5778 alu
.op
= ALU_OP2_ADD_INT
;
5784 alu
.src
[0].sel
= tmp0
;
5785 alu
.src
[0].chan
= 0;
5786 alu
.src
[1].sel
= tmp0
;
5787 alu
.src
[1].chan
= 3;
5790 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5793 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5794 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5795 alu
.op
= ALU_OP3_CNDE_INT
;
5802 alu
.src
[0].sel
= tmp0
;
5803 alu
.src
[0].chan
= 1;
5804 alu
.src
[1].sel
= tmp1
;
5805 alu
.src
[1].chan
= 1;
5806 alu
.src
[2].sel
= tmp1
;
5807 alu
.src
[2].chan
= 0;
5810 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5813 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5815 alu
.op
= ALU_OP2_MULHI_UINT
;
5821 alu
.src
[0].sel
= tmp0
;
5822 alu
.src
[0].chan
= 0;
5825 alu
.src
[1].sel
= tmp2
;
5826 alu
.src
[1].chan
= 0;
5828 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5831 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5834 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5835 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5836 alu
.op
= ALU_OP2_MULLO_UINT
;
5843 alu
.src
[0].sel
= tmp2
;
5844 alu
.src
[0].chan
= 1;
5846 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5849 alu
.src
[1].sel
= tmp0
;
5850 alu
.src
[1].chan
= 2;
5852 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5855 /* 12. tmp0.w = src1 - tmp0.y = r */
5856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5857 alu
.op
= ALU_OP2_SUB_INT
;
5864 alu
.src
[0].sel
= tmp2
;
5865 alu
.src
[0].chan
= 0;
5867 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5870 alu
.src
[1].sel
= tmp0
;
5871 alu
.src
[1].chan
= 1;
5874 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5877 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5878 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5879 alu
.op
= ALU_OP2_SETGE_UINT
;
5885 alu
.src
[0].sel
= tmp0
;
5886 alu
.src
[0].chan
= 3;
5888 alu
.src
[1].sel
= tmp2
;
5889 alu
.src
[1].chan
= 1;
5891 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5895 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5898 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5900 alu
.op
= ALU_OP2_SETGE_UINT
;
5907 alu
.src
[0].sel
= tmp2
;
5908 alu
.src
[0].chan
= 0;
5910 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5913 alu
.src
[1].sel
= tmp0
;
5914 alu
.src
[1].chan
= 1;
5917 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5920 if (mod
) { /* UMOD */
5922 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5923 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5924 alu
.op
= ALU_OP2_SUB_INT
;
5930 alu
.src
[0].sel
= tmp0
;
5931 alu
.src
[0].chan
= 3;
5934 alu
.src
[1].sel
= tmp2
;
5935 alu
.src
[1].chan
= 1;
5937 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5941 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5944 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5946 alu
.op
= ALU_OP2_ADD_INT
;
5952 alu
.src
[0].sel
= tmp0
;
5953 alu
.src
[0].chan
= 3;
5955 alu
.src
[1].sel
= tmp2
;
5956 alu
.src
[1].chan
= 1;
5958 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5962 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5967 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5968 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5969 alu
.op
= ALU_OP2_ADD_INT
;
5975 alu
.src
[0].sel
= tmp0
;
5976 alu
.src
[0].chan
= 2;
5977 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5980 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5983 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5984 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5985 alu
.op
= ALU_OP2_ADD_INT
;
5991 alu
.src
[0].sel
= tmp0
;
5992 alu
.src
[0].chan
= 2;
5993 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5996 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6001 /* 17. tmp1.x = tmp1.x & tmp1.y */
6002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6003 alu
.op
= ALU_OP2_AND_INT
;
6009 alu
.src
[0].sel
= tmp1
;
6010 alu
.src
[0].chan
= 0;
6011 alu
.src
[1].sel
= tmp1
;
6012 alu
.src
[1].chan
= 1;
6015 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6018 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
6019 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
6020 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6021 alu
.op
= ALU_OP3_CNDE_INT
;
6028 alu
.src
[0].sel
= tmp1
;
6029 alu
.src
[0].chan
= 0;
6030 alu
.src
[1].sel
= tmp0
;
6031 alu
.src
[1].chan
= mod
? 3 : 2;
6032 alu
.src
[2].sel
= tmp1
;
6033 alu
.src
[2].chan
= 2;
6036 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6039 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
6040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6041 alu
.op
= ALU_OP3_CNDE_INT
;
6049 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6052 alu
.src
[0].sel
= tmp1
;
6053 alu
.src
[0].chan
= 1;
6054 alu
.src
[1].sel
= tmp1
;
6055 alu
.src
[1].chan
= 3;
6056 alu
.src
[2].sel
= tmp0
;
6057 alu
.src
[2].chan
= 2;
6060 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6065 /* fix the sign of the result */
6069 /* tmp0.x = -tmp0.z */
6070 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6071 alu
.op
= ALU_OP2_SUB_INT
;
6077 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6078 alu
.src
[1].sel
= tmp0
;
6079 alu
.src
[1].chan
= 2;
6082 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6085 /* sign of the remainder is the same as the sign of src0 */
6086 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6088 alu
.op
= ALU_OP3_CNDGE_INT
;
6091 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6093 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6094 alu
.src
[1].sel
= tmp0
;
6095 alu
.src
[1].chan
= 2;
6096 alu
.src
[2].sel
= tmp0
;
6097 alu
.src
[2].chan
= 0;
6100 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6105 /* tmp0.x = -tmp0.z */
6106 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6107 alu
.op
= ALU_OP2_SUB_INT
;
6113 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6114 alu
.src
[1].sel
= tmp0
;
6115 alu
.src
[1].chan
= 2;
6118 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6121 /* fix the quotient sign (same as the sign of src0*src1) */
6122 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6124 alu
.op
= ALU_OP3_CNDGE_INT
;
6127 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6129 alu
.src
[0].sel
= tmp2
;
6130 alu
.src
[0].chan
= 2;
6131 alu
.src
[1].sel
= tmp0
;
6132 alu
.src
[1].chan
= 2;
6133 alu
.src
[2].sel
= tmp0
;
6134 alu
.src
[2].chan
= 0;
6137 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6145 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6147 return tgsi_divmod(ctx
, 0, 0);
6150 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6152 return tgsi_divmod(ctx
, 1, 0);
6155 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6157 return tgsi_divmod(ctx
, 0, 1);
6160 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6162 return tgsi_divmod(ctx
, 1, 1);
6166 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6168 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6169 struct r600_bytecode_alu alu
;
6171 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6172 int last_inst
= tgsi_last_instruction(write_mask
);
6174 for (i
= 0; i
< 4; i
++) {
6175 if (!(write_mask
& (1<<i
)))
6178 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6179 alu
.op
= ALU_OP1_TRUNC
;
6181 alu
.dst
.sel
= ctx
->temp_reg
;
6185 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6193 for (i
= 0; i
< 4; i
++) {
6194 if (!(write_mask
& (1<<i
)))
6197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6198 alu
.op
= ctx
->inst_info
->op
;
6200 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6202 alu
.src
[0].sel
= ctx
->temp_reg
;
6203 alu
.src
[0].chan
= i
;
6205 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6207 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6215 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6217 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6218 struct r600_bytecode_alu alu
;
6220 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6221 int last_inst
= tgsi_last_instruction(write_mask
);
6224 for (i
= 0; i
< 4; i
++) {
6225 if (!(write_mask
& (1<<i
)))
6228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6229 alu
.op
= ALU_OP2_SUB_INT
;
6231 alu
.dst
.sel
= ctx
->temp_reg
;
6235 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6236 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6240 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6245 /* dst = (src >= 0 ? src : tmp) */
6246 for (i
= 0; i
< 4; i
++) {
6247 if (!(write_mask
& (1<<i
)))
6250 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6251 alu
.op
= ALU_OP3_CNDGE_INT
;
6255 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6257 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6258 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6259 alu
.src
[2].sel
= ctx
->temp_reg
;
6260 alu
.src
[2].chan
= i
;
6264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6271 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6273 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6274 struct r600_bytecode_alu alu
;
6276 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6277 int last_inst
= tgsi_last_instruction(write_mask
);
6279 /* tmp = (src >= 0 ? src : -1) */
6280 for (i
= 0; i
< 4; i
++) {
6281 if (!(write_mask
& (1<<i
)))
6284 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6285 alu
.op
= ALU_OP3_CNDGE_INT
;
6288 alu
.dst
.sel
= ctx
->temp_reg
;
6292 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6293 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6294 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6298 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6303 /* dst = (tmp > 0 ? 1 : tmp) */
6304 for (i
= 0; i
< 4; i
++) {
6305 if (!(write_mask
& (1<<i
)))
6308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6309 alu
.op
= ALU_OP3_CNDGT_INT
;
6313 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6315 alu
.src
[0].sel
= ctx
->temp_reg
;
6316 alu
.src
[0].chan
= i
;
6318 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6320 alu
.src
[2].sel
= ctx
->temp_reg
;
6321 alu
.src
[2].chan
= i
;
6325 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6334 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6336 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6337 struct r600_bytecode_alu alu
;
6340 /* tmp = (src > 0 ? 1 : src) */
6341 for (i
= 0; i
< 4; i
++) {
6342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6343 alu
.op
= ALU_OP3_CNDGT
;
6346 alu
.dst
.sel
= ctx
->temp_reg
;
6349 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6350 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6351 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6355 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6360 /* dst = (-tmp > 0 ? -1 : tmp) */
6361 for (i
= 0; i
< 4; i
++) {
6362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6363 alu
.op
= ALU_OP3_CNDGT
;
6365 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6367 alu
.src
[0].sel
= ctx
->temp_reg
;
6368 alu
.src
[0].chan
= i
;
6371 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6374 alu
.src
[2].sel
= ctx
->temp_reg
;
6375 alu
.src
[2].chan
= i
;
6379 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6386 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6388 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6389 struct r600_bytecode_alu alu
;
6392 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6393 int last_inst
= tgsi_last_instruction(write_mask
);
6395 t1
= r600_get_temp(ctx
);
6397 for (i
= 0; i
< 4; i
++) {
6398 if (!(write_mask
& (1<<i
)))
6401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6402 alu
.op
= ALU_OP2_SETGE_INT
;
6403 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6404 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6405 alu
.src
[1].value
= 32;
6406 alu
.dst
.sel
= ctx
->temp_reg
;
6409 alu
.last
= i
== last_inst
;
6410 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6415 for (i
= 0; i
< 4; i
++) {
6416 if (!(write_mask
& (1<<i
)))
6419 /* create mask tmp */
6420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6421 alu
.op
= ALU_OP2_BFM_INT
;
6425 alu
.last
= i
== last_inst
;
6427 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6428 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6430 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6435 t2
= r600_get_temp(ctx
);
6437 for (i
= 0; i
< 4; i
++) {
6438 if (!(write_mask
& (1<<i
)))
6441 /* shift insert left */
6442 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6443 alu
.op
= ALU_OP2_LSHL_INT
;
6447 alu
.last
= i
== last_inst
;
6449 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6450 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6457 for (i
= 0; i
< 4; i
++) {
6458 if (!(write_mask
& (1<<i
)))
6461 /* actual bitfield insert */
6462 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6463 alu
.op
= ALU_OP3_BFI_INT
;
6465 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6468 alu
.last
= i
== last_inst
;
6470 alu
.src
[0].sel
= t1
;
6471 alu
.src
[0].chan
= i
;
6472 alu
.src
[1].sel
= t2
;
6473 alu
.src
[1].chan
= i
;
6474 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6476 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6481 for (i
= 0; i
< 4; i
++) {
6482 if (!(write_mask
& (1<<i
)))
6484 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6485 alu
.op
= ALU_OP3_CNDE_INT
;
6487 alu
.src
[0].sel
= ctx
->temp_reg
;
6488 alu
.src
[0].chan
= i
;
6489 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6491 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6493 alu
.src
[1].sel
= alu
.dst
.sel
;
6494 alu
.src
[1].chan
= i
;
6496 alu
.last
= i
== last_inst
;
6497 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6504 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6506 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6507 struct r600_bytecode_alu alu
;
6510 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6511 int last_inst
= tgsi_last_instruction(write_mask
);
6513 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6514 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6518 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6519 for (i
= 0; i
< 4; i
++) {
6520 if (!(write_mask
& (1<<i
)))
6523 /* t1 = FFBH_INT / FFBH_UINT */
6524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6525 alu
.op
= ctx
->inst_info
->op
;
6529 alu
.last
= i
== last_inst
;
6531 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6533 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6538 t2
= r600_get_temp(ctx
);
6540 for (i
= 0; i
< 4; i
++) {
6541 if (!(write_mask
& (1<<i
)))
6545 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6546 alu
.op
= ALU_OP2_SUB_INT
;
6550 alu
.last
= i
== last_inst
;
6552 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6553 alu
.src
[0].value
= 31;
6554 alu
.src
[1].sel
= t1
;
6555 alu
.src
[1].chan
= i
;
6557 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6562 for (i
= 0; i
< 4; i
++) {
6563 if (!(write_mask
& (1<<i
)))
6566 /* result = t1 >= 0 ? t2 : t1 */
6567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6568 alu
.op
= ALU_OP3_CNDGE_INT
;
6570 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6573 alu
.last
= i
== last_inst
;
6575 alu
.src
[0].sel
= t1
;
6576 alu
.src
[0].chan
= i
;
6577 alu
.src
[1].sel
= t2
;
6578 alu
.src
[1].chan
= i
;
6579 alu
.src
[2].sel
= t1
;
6580 alu
.src
[2].chan
= i
;
6582 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6590 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6592 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6593 struct r600_bytecode_alu alu
;
6594 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6596 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6598 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6600 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6601 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6602 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6603 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6606 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6609 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6612 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6613 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6615 /* NOTE: currently offset is not perspective correct */
6616 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6617 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6618 int sample_gpr
= -1;
6619 int gradientsH
, gradientsV
;
6620 struct r600_bytecode_tex tex
;
6622 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6623 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6626 gradientsH
= r600_get_temp(ctx
);
6627 gradientsV
= r600_get_temp(ctx
);
6628 for (i
= 0; i
< 2; i
++) {
6629 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6630 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6631 tex
.src_gpr
= interp_gpr
;
6632 tex
.src_sel_x
= interp_base_chan
+ 0;
6633 tex
.src_sel_y
= interp_base_chan
+ 1;
6636 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6641 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6643 tex
.resource_id
= tex
.sampler_id
;
6644 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6649 for (i
= 0; i
< 2; i
++) {
6650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6651 alu
.op
= ALU_OP3_MULADD
;
6653 alu
.src
[0].sel
= gradientsH
;
6654 alu
.src
[0].chan
= i
;
6655 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6656 alu
.src
[1].sel
= sample_gpr
;
6657 alu
.src
[1].chan
= 2;
6660 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6662 alu
.src
[2].sel
= interp_gpr
;
6663 alu
.src
[2].chan
= interp_base_chan
+ i
;
6664 alu
.dst
.sel
= ctx
->temp_reg
;
6668 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6673 for (i
= 0; i
< 2; i
++) {
6674 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6675 alu
.op
= ALU_OP3_MULADD
;
6677 alu
.src
[0].sel
= gradientsV
;
6678 alu
.src
[0].chan
= i
;
6679 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6680 alu
.src
[1].sel
= sample_gpr
;
6681 alu
.src
[1].chan
= 3;
6684 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6686 alu
.src
[2].sel
= ctx
->temp_reg
;
6687 alu
.src
[2].chan
= i
;
6688 alu
.dst
.sel
= ctx
->temp_reg
;
6692 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6698 tmp
= r600_get_temp(ctx
);
6699 for (i
= 0; i
< 8; i
++) {
6700 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6701 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6704 if ((i
> 1 && i
< 6)) {
6710 alu
.dst
.chan
= i
% 4;
6712 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6713 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6714 alu
.src
[0].sel
= ctx
->temp_reg
;
6715 alu
.src
[0].chan
= 1 - (i
% 2);
6717 alu
.src
[0].sel
= interp_gpr
;
6718 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6720 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6721 alu
.src
[1].chan
= 0;
6723 alu
.last
= i
% 4 == 3;
6724 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6731 // INTERP can't swizzle dst
6732 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6733 for (i
= 0; i
<= lasti
; i
++) {
6734 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6738 alu
.op
= ALU_OP1_MOV
;
6739 alu
.src
[0].sel
= tmp
;
6740 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6741 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6743 alu
.last
= i
== lasti
;
6744 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6753 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6755 struct r600_bytecode_alu alu
;
6758 for (i
= 0; i
< 4; i
++) {
6759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6760 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6761 alu
.op
= ALU_OP0_NOP
;
6764 alu
.op
= ALU_OP1_MOV
;
6765 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6766 alu
.src
[0].sel
= ctx
->temp_reg
;
6767 alu
.src
[0].chan
= i
;
6772 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6779 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6780 unsigned temp
, int chan
,
6781 struct r600_bytecode_alu_src
*bc_src
,
6782 const struct r600_shader_src
*shader_src
)
6784 struct r600_bytecode_alu alu
;
6787 r600_bytecode_src(bc_src
, shader_src
, chan
);
6789 /* op3 operands don't support abs modifier */
6791 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6793 alu
.op
= ALU_OP1_MOV
;
6795 alu
.dst
.chan
= chan
;
6798 alu
.src
[0] = *bc_src
;
6799 alu
.last
= true; // sufficient?
6800 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6804 memset(bc_src
, 0, sizeof(*bc_src
));
6806 bc_src
->chan
= chan
;
6811 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
6813 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6814 struct r600_bytecode_alu alu
;
6816 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6818 unsigned op
= ctx
->inst_info
->op
;
6820 if (op
== ALU_OP3_MULADD_IEEE
&&
6821 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6822 op
= ALU_OP3_MULADD
;
6824 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6826 if (ctx
->src
[j
].abs
)
6827 temp_regs
[j
] = r600_get_temp(ctx
);
6829 for (i
= 0; i
< lasti
+ 1; i
++) {
6830 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6833 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6835 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6836 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6842 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6852 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6859 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6861 return tgsi_op3_dst(ctx
, -1);
6864 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6866 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6867 struct r600_bytecode_alu alu
;
6869 unsigned op
= ctx
->inst_info
->op
;
6870 if (op
== ALU_OP2_DOT4_IEEE
&&
6871 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6874 for (i
= 0; i
< 4; i
++) {
6875 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6877 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6878 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6881 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6883 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6884 /* handle some special cases */
6885 switch (inst
->Instruction
.Opcode
) {
6886 case TGSI_OPCODE_DP2
:
6888 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6889 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6892 case TGSI_OPCODE_DP3
:
6894 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6895 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6904 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6911 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6914 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6915 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6916 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6917 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6918 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6919 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6922 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6925 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6926 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6929 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6931 struct r600_bytecode_vtx vtx
;
6932 struct r600_bytecode_alu alu
;
6933 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6935 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6936 int sampler_index_mode
= inst
->Src
[1].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6938 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6939 if (src_requires_loading
) {
6940 for (i
= 0; i
< 4; i
++) {
6941 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6942 alu
.op
= ALU_OP1_MOV
;
6943 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6944 alu
.dst
.sel
= ctx
->temp_reg
;
6949 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6953 src_gpr
= ctx
->temp_reg
;
6956 memset(&vtx
, 0, sizeof(vtx
));
6957 vtx
.op
= FETCH_OP_VFETCH
;
6958 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6959 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6960 vtx
.src_gpr
= src_gpr
;
6961 vtx
.mega_fetch_count
= 16;
6962 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6963 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6964 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6965 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6966 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6967 vtx
.use_const_fields
= 1;
6968 vtx
.buffer_index_mode
= sampler_index_mode
;
6970 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6973 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6976 for (i
= 0; i
< 4; i
++) {
6977 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6978 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6981 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6982 alu
.op
= ALU_OP2_AND_INT
;
6985 alu
.dst
.sel
= vtx
.dst_gpr
;
6988 alu
.src
[0].sel
= vtx
.dst_gpr
;
6989 alu
.src
[0].chan
= i
;
6991 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6992 alu
.src
[1].sel
+= (id
* 2);
6993 alu
.src
[1].chan
= i
% 4;
6994 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6998 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7003 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
7004 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7005 alu
.op
= ALU_OP2_OR_INT
;
7008 alu
.dst
.sel
= vtx
.dst_gpr
;
7011 alu
.src
[0].sel
= vtx
.dst_gpr
;
7012 alu
.src
[0].chan
= 3;
7014 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
7015 alu
.src
[1].chan
= 0;
7016 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7026 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
, int eg_buffer_base
)
7028 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7030 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
7031 int sampler_index_mode
= inst
->Src
[reg_idx
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7033 if (ctx
->bc
->chip_class
< EVERGREEN
) {
7034 struct r600_bytecode_alu alu
;
7035 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7036 alu
.op
= ALU_OP1_MOV
;
7037 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7038 /* r600 we have them at channel 2 of the second dword */
7039 alu
.src
[0].sel
+= (id
* 2) + 1;
7040 alu
.src
[0].chan
= 1;
7041 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7042 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
7044 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7049 struct r600_bytecode_vtx vtx
;
7050 memset(&vtx
, 0, sizeof(vtx
));
7051 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
7052 vtx
.buffer_id
= id
+ eg_buffer_base
;
7053 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7055 vtx
.mega_fetch_count
= 16; /* no idea here really... */
7056 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7057 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7058 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 4 : 7; /* SEL_Y */
7059 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 4 : 7; /* SEL_Z */
7060 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 4 : 7; /* SEL_W */
7061 vtx
.data_format
= FMT_32_32_32_32
;
7062 vtx
.buffer_index_mode
= sampler_index_mode
;
7064 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
7071 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
7073 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7074 struct r600_bytecode_tex tex
;
7075 struct r600_bytecode_alu alu
;
7079 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7080 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7081 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7082 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7084 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7085 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7086 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7088 /* Texture fetch instructions can only use gprs as source.
7089 * Also they cannot negate the source or take the absolute value */
7090 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7091 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7092 read_compressed_msaa
|| txf_add_offsets
;
7094 boolean src_loaded
= FALSE
;
7095 unsigned sampler_src_reg
= 1;
7096 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7097 boolean has_txq_cube_array_z
= false;
7098 unsigned sampler_index_mode
;
7100 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7101 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7102 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7103 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7104 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7105 has_txq_cube_array_z
= true;
7108 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7109 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7110 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7111 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7112 sampler_src_reg
= 2;
7114 /* TGSI moves the sampler to src reg 3 for TXD */
7115 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7116 sampler_src_reg
= 3;
7118 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7120 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7122 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7123 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7124 if (ctx
->bc
->chip_class
< EVERGREEN
)
7125 ctx
->shader
->uses_tex_buffers
= true;
7126 return r600_do_buffer_txq(ctx
, 1, 0, R600_MAX_CONST_BUFFERS
);
7128 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7129 if (ctx
->bc
->chip_class
< EVERGREEN
)
7130 ctx
->shader
->uses_tex_buffers
= true;
7131 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7135 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7137 /* Add perspective divide */
7138 if (ctx
->bc
->chip_class
== CAYMAN
) {
7140 for (i
= 0; i
< 3; i
++) {
7141 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7142 alu
.op
= ALU_OP1_RECIP_IEEE
;
7143 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7145 alu
.dst
.sel
= ctx
->temp_reg
;
7151 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7158 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7159 alu
.op
= ALU_OP1_RECIP_IEEE
;
7160 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7162 alu
.dst
.sel
= ctx
->temp_reg
;
7163 alu
.dst
.chan
= out_chan
;
7166 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7171 for (i
= 0; i
< 3; i
++) {
7172 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7173 alu
.op
= ALU_OP2_MUL
;
7174 alu
.src
[0].sel
= ctx
->temp_reg
;
7175 alu
.src
[0].chan
= out_chan
;
7176 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7177 alu
.dst
.sel
= ctx
->temp_reg
;
7180 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7184 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7185 alu
.op
= ALU_OP1_MOV
;
7186 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7187 alu
.src
[0].chan
= 0;
7188 alu
.dst
.sel
= ctx
->temp_reg
;
7192 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7196 src_gpr
= ctx
->temp_reg
;
7200 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7201 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7202 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7203 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7204 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7206 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7207 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7209 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7210 for (i
= 0; i
< 4; i
++) {
7211 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7212 alu
.op
= ALU_OP2_CUBE
;
7213 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7214 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7215 alu
.dst
.sel
= ctx
->temp_reg
;
7220 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7225 /* tmp1.z = RCP_e(|tmp1.z|) */
7226 if (ctx
->bc
->chip_class
== CAYMAN
) {
7227 for (i
= 0; i
< 3; i
++) {
7228 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7229 alu
.op
= ALU_OP1_RECIP_IEEE
;
7230 alu
.src
[0].sel
= ctx
->temp_reg
;
7231 alu
.src
[0].chan
= 2;
7233 alu
.dst
.sel
= ctx
->temp_reg
;
7239 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7244 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7245 alu
.op
= ALU_OP1_RECIP_IEEE
;
7246 alu
.src
[0].sel
= ctx
->temp_reg
;
7247 alu
.src
[0].chan
= 2;
7249 alu
.dst
.sel
= ctx
->temp_reg
;
7253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7258 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7259 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7260 * muladd has no writemask, have to use another temp
7262 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7263 alu
.op
= ALU_OP3_MULADD
;
7266 alu
.src
[0].sel
= ctx
->temp_reg
;
7267 alu
.src
[0].chan
= 0;
7268 alu
.src
[1].sel
= ctx
->temp_reg
;
7269 alu
.src
[1].chan
= 2;
7271 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7272 alu
.src
[2].chan
= 0;
7273 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7275 alu
.dst
.sel
= ctx
->temp_reg
;
7279 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7283 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7284 alu
.op
= ALU_OP3_MULADD
;
7287 alu
.src
[0].sel
= ctx
->temp_reg
;
7288 alu
.src
[0].chan
= 1;
7289 alu
.src
[1].sel
= ctx
->temp_reg
;
7290 alu
.src
[1].chan
= 2;
7292 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7293 alu
.src
[2].chan
= 0;
7294 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7296 alu
.dst
.sel
= ctx
->temp_reg
;
7301 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7304 /* write initial compare value into Z component
7305 - W src 0 for shadow cube
7306 - X src 1 for shadow cube array */
7307 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7308 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7309 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7310 alu
.op
= ALU_OP1_MOV
;
7311 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7312 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7314 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7315 alu
.dst
.sel
= ctx
->temp_reg
;
7319 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7324 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7325 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7326 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7327 int mytmp
= r600_get_temp(ctx
);
7328 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7329 alu
.op
= ALU_OP1_MOV
;
7330 alu
.src
[0].sel
= ctx
->temp_reg
;
7331 alu
.src
[0].chan
= 3;
7332 alu
.dst
.sel
= mytmp
;
7336 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7340 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7341 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7342 alu
.op
= ALU_OP3_MULADD
;
7344 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7345 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7346 alu
.src
[1].chan
= 0;
7347 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7348 alu
.src
[2].sel
= mytmp
;
7349 alu
.src
[2].chan
= 0;
7350 alu
.dst
.sel
= ctx
->temp_reg
;
7354 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7357 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7358 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7359 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7360 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7361 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7362 tex
.src_gpr
= r600_get_temp(ctx
);
7367 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7368 tex
.coord_type_x
= 1;
7369 tex
.coord_type_y
= 1;
7370 tex
.coord_type_z
= 1;
7371 tex
.coord_type_w
= 1;
7372 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7373 alu
.op
= ALU_OP1_MOV
;
7374 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7375 alu
.dst
.sel
= tex
.src_gpr
;
7379 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7383 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7390 /* for cube forms of lod and bias we need to route things */
7391 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7392 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7393 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7394 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7395 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7396 alu
.op
= ALU_OP1_MOV
;
7397 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7398 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7399 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7401 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7402 alu
.dst
.sel
= ctx
->temp_reg
;
7406 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7412 src_gpr
= ctx
->temp_reg
;
7415 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7416 int temp_h
= 0, temp_v
= 0;
7419 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7420 if (src_loaded
== TRUE
)
7424 for (i
= start_val
; i
< 3; i
++) {
7425 int treg
= r600_get_temp(ctx
);
7434 for (j
= 0; j
< 4; j
++) {
7435 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7436 alu
.op
= ALU_OP1_MOV
;
7437 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7443 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7448 for (i
= 1; i
< 3; i
++) {
7449 /* set gradients h/v */
7450 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7451 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7452 FETCH_OP_SET_GRADIENTS_V
;
7453 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7454 tex
.sampler_index_mode
= sampler_index_mode
;
7455 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7456 tex
.resource_index_mode
= sampler_index_mode
;
7458 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7464 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7465 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7466 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7467 tex
.coord_type_x
= 1;
7468 tex
.coord_type_y
= 1;
7469 tex
.coord_type_z
= 1;
7470 tex
.coord_type_w
= 1;
7472 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7478 if (src_requires_loading
&& !src_loaded
) {
7479 for (i
= 0; i
< 4; i
++) {
7480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7481 alu
.op
= ALU_OP1_MOV
;
7482 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7483 alu
.dst
.sel
= ctx
->temp_reg
;
7488 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7493 src_gpr
= ctx
->temp_reg
;
7496 /* get offset values */
7497 if (inst
->Texture
.NumOffsets
) {
7498 assert(inst
->Texture
.NumOffsets
== 1);
7500 /* The texture offset feature doesn't work with the TXF instruction
7501 * and must be emulated by adding the offset to the texture coordinates. */
7502 if (txf_add_offsets
) {
7503 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7505 switch (inst
->Texture
.Texture
) {
7506 case TGSI_TEXTURE_3D
:
7507 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7508 alu
.op
= ALU_OP2_ADD_INT
;
7509 alu
.src
[0].sel
= src_gpr
;
7510 alu
.src
[0].chan
= 2;
7511 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7512 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7513 alu
.dst
.sel
= src_gpr
;
7517 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7522 case TGSI_TEXTURE_2D
:
7523 case TGSI_TEXTURE_SHADOW2D
:
7524 case TGSI_TEXTURE_RECT
:
7525 case TGSI_TEXTURE_SHADOWRECT
:
7526 case TGSI_TEXTURE_2D_ARRAY
:
7527 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7529 alu
.op
= ALU_OP2_ADD_INT
;
7530 alu
.src
[0].sel
= src_gpr
;
7531 alu
.src
[0].chan
= 1;
7532 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7533 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7534 alu
.dst
.sel
= src_gpr
;
7538 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7543 case TGSI_TEXTURE_1D
:
7544 case TGSI_TEXTURE_SHADOW1D
:
7545 case TGSI_TEXTURE_1D_ARRAY
:
7546 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7547 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7548 alu
.op
= ALU_OP2_ADD_INT
;
7549 alu
.src
[0].sel
= src_gpr
;
7550 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7551 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7552 alu
.dst
.sel
= src_gpr
;
7555 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7559 /* texture offsets do not apply to other texture targets */
7562 switch (inst
->Texture
.Texture
) {
7563 case TGSI_TEXTURE_3D
:
7564 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7566 case TGSI_TEXTURE_2D
:
7567 case TGSI_TEXTURE_SHADOW2D
:
7568 case TGSI_TEXTURE_RECT
:
7569 case TGSI_TEXTURE_SHADOWRECT
:
7570 case TGSI_TEXTURE_2D_ARRAY
:
7571 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7572 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7574 case TGSI_TEXTURE_1D
:
7575 case TGSI_TEXTURE_SHADOW1D
:
7576 case TGSI_TEXTURE_1D_ARRAY
:
7577 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7578 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7583 /* Obtain the sample index for reading a compressed MSAA color texture.
7584 * To read the FMASK, we use the ldfptr instruction, which tells us
7585 * where the samples are stored.
7586 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7587 * which is the identity mapping. Each nibble says which physical sample
7588 * should be fetched to get that sample.
7590 * Assume src.z contains the sample index. It should be modified like this:
7591 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7592 * Then fetch the texel with src.
7594 if (read_compressed_msaa
) {
7595 unsigned sample_chan
= 3;
7596 unsigned temp
= r600_get_temp(ctx
);
7599 /* temp.w = ldfptr() */
7600 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7601 tex
.op
= FETCH_OP_LD
;
7602 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7603 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7604 tex
.sampler_index_mode
= sampler_index_mode
;
7605 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7606 tex
.resource_index_mode
= sampler_index_mode
;
7607 tex
.src_gpr
= src_gpr
;
7609 tex
.dst_sel_x
= 7; /* mask out these components */
7612 tex
.dst_sel_w
= 0; /* store X */
7617 tex
.offset_x
= offset_x
;
7618 tex
.offset_y
= offset_y
;
7619 tex
.offset_z
= offset_z
;
7620 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7624 /* temp.x = sample_index*4 */
7625 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7626 alu
.op
= ALU_OP2_MULLO_INT
;
7627 alu
.src
[0].sel
= src_gpr
;
7628 alu
.src
[0].chan
= sample_chan
;
7629 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7630 alu
.src
[1].value
= 4;
7634 r
= emit_mul_int_op(ctx
->bc
, &alu
);
7638 /* sample_index = temp.w >> temp.x */
7639 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7640 alu
.op
= ALU_OP2_LSHR_INT
;
7641 alu
.src
[0].sel
= temp
;
7642 alu
.src
[0].chan
= 3;
7643 alu
.src
[1].sel
= temp
;
7644 alu
.src
[1].chan
= 0;
7645 alu
.dst
.sel
= src_gpr
;
7646 alu
.dst
.chan
= sample_chan
;
7649 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7653 /* sample_index & 0xF */
7654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7655 alu
.op
= ALU_OP2_AND_INT
;
7656 alu
.src
[0].sel
= src_gpr
;
7657 alu
.src
[0].chan
= sample_chan
;
7658 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7659 alu
.src
[1].value
= 0xF;
7660 alu
.dst
.sel
= src_gpr
;
7661 alu
.dst
.chan
= sample_chan
;
7664 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7668 /* visualize the FMASK */
7669 for (i
= 0; i
< 4; i
++) {
7670 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7671 alu
.op
= ALU_OP1_INT_TO_FLT
;
7672 alu
.src
[0].sel
= src_gpr
;
7673 alu
.src
[0].chan
= sample_chan
;
7674 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7678 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7686 /* does this shader want a num layers from TXQ for a cube array? */
7687 if (has_txq_cube_array_z
) {
7688 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7690 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7691 alu
.op
= ALU_OP1_MOV
;
7693 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7694 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7695 /* with eg each dword is number of cubes */
7696 alu
.src
[0].sel
+= id
/ 4;
7697 alu
.src
[0].chan
= id
% 4;
7699 /* r600 we have them at channel 2 of the second dword */
7700 alu
.src
[0].sel
+= (id
* 2) + 1;
7701 alu
.src
[0].chan
= 2;
7703 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7704 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7706 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7709 /* disable writemask from texture instruction */
7710 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7713 opcode
= ctx
->inst_info
->op
;
7714 if (opcode
== FETCH_OP_GATHER4
&&
7715 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7716 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7717 opcode
= FETCH_OP_GATHER4_O
;
7719 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7720 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7721 encoded in the instruction are ignored. */
7722 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7723 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7724 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7725 tex
.sampler_index_mode
= sampler_index_mode
;
7726 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7727 tex
.resource_index_mode
= sampler_index_mode
;
7729 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7730 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7731 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7732 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7740 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7745 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7746 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7747 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7748 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7749 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7750 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7751 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7753 case FETCH_OP_SAMPLE
:
7754 opcode
= FETCH_OP_SAMPLE_C
;
7756 case FETCH_OP_SAMPLE_L
:
7757 opcode
= FETCH_OP_SAMPLE_C_L
;
7759 case FETCH_OP_SAMPLE_LB
:
7760 opcode
= FETCH_OP_SAMPLE_C_LB
;
7762 case FETCH_OP_SAMPLE_G
:
7763 opcode
= FETCH_OP_SAMPLE_C_G
;
7765 /* Texture gather variants */
7766 case FETCH_OP_GATHER4
:
7767 opcode
= FETCH_OP_GATHER4_C
;
7769 case FETCH_OP_GATHER4_O
:
7770 opcode
= FETCH_OP_GATHER4_C_O
;
7775 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7778 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7779 tex
.sampler_index_mode
= sampler_index_mode
;
7780 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7781 tex
.resource_index_mode
= sampler_index_mode
;
7782 tex
.src_gpr
= src_gpr
;
7783 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7785 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7786 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7787 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7790 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7791 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7792 tex
.inst_mod
= texture_component_select
;
7794 if (ctx
->bc
->chip_class
== CAYMAN
) {
7795 /* GATHER4 result order is different from TGSI TG4 */
7796 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7797 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7798 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7799 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7801 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7802 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7803 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7804 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7807 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7808 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7809 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7813 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7820 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7821 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7822 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7823 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7827 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7832 } else if (src_loaded
) {
7838 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7839 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7840 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7841 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7842 tex
.src_rel
= ctx
->src
[0].rel
;
7845 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7846 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7847 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7848 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7852 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7855 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7856 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7857 tex
.coord_type_x
= 1;
7858 tex
.coord_type_y
= 1;
7860 tex
.coord_type_z
= 1;
7861 tex
.coord_type_w
= 1;
7863 tex
.offset_x
= offset_x
;
7864 tex
.offset_y
= offset_y
;
7865 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7866 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7867 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7871 tex
.offset_z
= offset_z
;
7874 /* Put the depth for comparison in W.
7875 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7876 * Some instructions expect the depth in Z. */
7877 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7878 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7879 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7880 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7881 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7882 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7883 tex
.src_sel_w
= tex
.src_sel_z
;
7886 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7887 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7888 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7889 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7890 /* the array index is read from Y */
7891 tex
.coord_type_y
= 0;
7893 /* the array index is read from Z */
7894 tex
.coord_type_z
= 0;
7895 tex
.src_sel_z
= tex
.src_sel_y
;
7897 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7898 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7899 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7900 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7901 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7902 /* the array index is read from Z */
7903 tex
.coord_type_z
= 0;
7905 /* mask unused source components */
7906 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7907 switch (inst
->Texture
.Texture
) {
7908 case TGSI_TEXTURE_2D
:
7909 case TGSI_TEXTURE_RECT
:
7913 case TGSI_TEXTURE_1D_ARRAY
:
7917 case TGSI_TEXTURE_1D
:
7925 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7929 /* add shadow ambient support - gallium doesn't do it yet */
7933 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7934 struct tgsi_full_src_register
*src
)
7938 if (src
->Register
.Indirect
) {
7939 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7940 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7941 return ctx
->shader
->atomics
[i
].hw_idx
;
7944 uint32_t index
= src
->Register
.Index
;
7945 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7946 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
7948 if (index
> ctx
->shader
->atomics
[i
].end
)
7950 if (index
< ctx
->shader
->atomics
[i
].start
)
7952 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7953 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7960 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
7961 int *uav_id_p
, int *uav_index_mode_p
)
7963 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7964 int uav_id
, uav_index_mode
= 0;
7966 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7968 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7970 if (inst
->Src
[0].Register
.Indirect
) {
7972 struct r600_bytecode_alu alu
;
7973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7974 alu
.op
= ALU_OP2_LSHL_INT
;
7975 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
7976 alu
.src
[0].chan
= 0;
7977 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7978 alu
.src
[1].value
= 2;
7979 alu
.dst
.sel
= ctx
->temp_reg
;
7983 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7987 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
7990 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
7996 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
7998 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
8004 *uav_index_mode_p
= uav_index_mode
;
8008 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
8010 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8012 struct r600_bytecode_gds gds
;
8014 int uav_index_mode
= 0;
8015 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8017 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8021 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8022 gds
.op
= FETCH_OP_GDS_READ_RET
;
8023 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8024 gds
.uav_id
= is_cm
? 0 : uav_id
;
8025 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8026 gds
.src_gpr
= ctx
->temp_reg
;
8027 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
8035 gds
.alloc_consume
= !is_cm
;
8036 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8040 ctx
->bc
->cf_last
->vpm
= 1;
8044 /* this fixes up 1D arrays properly */
8045 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
8047 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8049 struct r600_bytecode_alu alu
;
8050 int temp_reg
= r600_get_temp(ctx
);
8052 for (i
= 0; i
< 4; i
++) {
8053 bool def_val
= true, write_zero
= false;
8054 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8055 alu
.op
= ALU_OP1_MOV
;
8056 alu
.dst
.sel
= temp_reg
;
8059 switch (inst
->Memory
.Texture
) {
8060 case TGSI_TEXTURE_BUFFER
:
8061 case TGSI_TEXTURE_1D
:
8062 if (i
== 1 || i
== 2 || i
== 3) {
8066 case TGSI_TEXTURE_1D_ARRAY
:
8067 if (i
== 1 || i
== 3)
8070 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8074 case TGSI_TEXTURE_2D
:
8075 if (i
== 2 || i
== 3)
8085 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8086 alu
.src
[0].value
= 0;
8087 } else if (def_val
) {
8088 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8098 *idx_gpr
= temp_reg
;
8102 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8105 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8107 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8108 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8109 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8111 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8116 struct r600_bytecode_alu alu
;
8117 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8118 alu
.op
= ALU_OP2_LSHR_INT
;
8119 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8120 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8121 alu
.src
[1].value
= 2;
8122 alu
.dst
.sel
= temp_reg
;
8125 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8132 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8134 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8135 /* have to work out the offset into the RAT immediate return buffer */
8136 struct r600_bytecode_vtx vtx
;
8137 struct r600_bytecode_cf
*cf
;
8139 int temp_reg
= r600_get_temp(ctx
);
8140 unsigned rat_index_mode
;
8143 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8144 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8146 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8149 ctx
->bc
->cf_last
->barrier
= 1;
8150 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8151 vtx
.op
= FETCH_OP_VFETCH
;
8152 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8153 vtx
.buffer_index_mode
= rat_index_mode
;
8154 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8155 vtx
.src_gpr
= temp_reg
;
8157 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8158 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8159 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8160 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8161 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8162 vtx
.num_format_all
= 1;
8163 vtx
.format_comp_all
= 1;
8164 vtx
.srf_mode_all
= 0;
8166 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8167 vtx
.data_format
= FMT_32_32_32_32
;
8168 vtx
.use_const_fields
= 0;
8169 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8170 vtx
.data_format
= FMT_32_32_32
;
8171 vtx
.use_const_fields
= 0;
8172 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8173 vtx
.data_format
= FMT_32_32
;
8174 vtx
.use_const_fields
= 0;
8176 vtx
.data_format
= FMT_32
;
8177 vtx
.use_const_fields
= 0;
8180 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8183 cf
= ctx
->bc
->cf_last
;
8188 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8190 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8191 /* have to work out the offset into the RAT immediate return buffer */
8192 struct r600_bytecode_vtx vtx
;
8193 struct r600_bytecode_cf
*cf
;
8196 unsigned format
, num_format
, format_comp
, endian
;
8197 const struct util_format_description
*desc
;
8198 unsigned rat_index_mode
;
8199 unsigned immed_base
;
8201 r
= load_thread_id_gpr(ctx
);
8205 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8207 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8208 r
= load_index_src(ctx
, 1, &idx_gpr
);
8213 egcm_load_index_reg(ctx
->bc
, 1, false);
8215 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8216 cf
= ctx
->bc
->cf_last
;
8218 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8219 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8220 cf
->rat
.index_mode
= rat_index_mode
;
8221 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8222 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8223 cf
->output
.index_gpr
= idx_gpr
;
8224 cf
->output
.comp_mask
= 0xf;
8225 cf
->output
.burst_count
= 1;
8229 cf
->output
.elem_size
= 0;
8231 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8232 cf
= ctx
->bc
->cf_last
;
8235 desc
= util_format_description(inst
->Memory
.Format
);
8236 r600_vertex_data_type(inst
->Memory
.Format
,
8237 &format
, &num_format
, &format_comp
, &endian
);
8238 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8239 vtx
.op
= FETCH_OP_VFETCH
;
8240 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8241 vtx
.buffer_index_mode
= rat_index_mode
;
8242 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8243 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8245 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8246 vtx
.dst_sel_x
= desc
->swizzle
[0];
8247 vtx
.dst_sel_y
= desc
->swizzle
[1];
8248 vtx
.dst_sel_z
= desc
->swizzle
[2];
8249 vtx
.dst_sel_w
= desc
->swizzle
[3];
8250 vtx
.srf_mode_all
= 1;
8251 vtx
.data_format
= format
;
8252 vtx
.num_format_all
= num_format
;
8253 vtx
.format_comp_all
= format_comp
;
8254 vtx
.endian
= endian
;
8256 vtx
.mega_fetch_count
= 3;
8257 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8260 cf
= ctx
->bc
->cf_last
;
8265 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8267 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8268 struct r600_bytecode_alu alu
;
8270 int temp_reg
= r600_get_temp(ctx
);
8272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8273 alu
.op
= ALU_OP1_MOV
;
8274 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8275 alu
.dst
.sel
= temp_reg
;
8278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8282 r
= do_lds_fetch_values(ctx
, temp_reg
,
8283 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8289 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8291 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8292 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8293 return tgsi_load_rat(ctx
);
8294 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8295 return tgsi_load_gds(ctx
);
8296 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8297 return tgsi_load_buffer(ctx
);
8298 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8299 return tgsi_load_lds(ctx
);
8303 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8305 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8306 struct r600_bytecode_cf
*cf
;
8308 unsigned rat_index_mode
;
8310 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8312 r
= load_buffer_coord(ctx
, 0, treg2
);
8316 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8318 egcm_load_index_reg(ctx
->bc
, 1, false);
8320 for (i
= 0; i
<= 3; i
++) {
8321 struct r600_bytecode_alu alu
;
8322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8323 alu
.op
= ALU_OP1_MOV
;
8324 alu
.dst
.sel
= temp_reg
;
8326 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8327 alu
.last
= (i
== 3);
8329 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8334 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8335 for (i
= 0; i
<= lasti
; i
++) {
8336 struct r600_bytecode_alu alu
;
8337 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8340 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8343 V_SQ_ALU_SRC_LITERAL
, i
);
8347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8348 alu
.op
= ALU_OP1_MOV
;
8349 alu
.dst
.sel
= ctx
->temp_reg
;
8352 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8355 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8359 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8360 cf
= ctx
->bc
->cf_last
;
8362 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8363 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8364 cf
->rat
.index_mode
= rat_index_mode
;
8365 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8366 cf
->output
.gpr
= ctx
->temp_reg
;
8367 cf
->output
.index_gpr
= temp_reg
;
8368 cf
->output
.comp_mask
= 1;
8369 cf
->output
.burst_count
= 1;
8372 cf
->output
.elem_size
= 0;
8377 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8379 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8380 struct r600_bytecode_cf
*cf
;
8381 bool src_requires_loading
= false;
8382 int val_gpr
, idx_gpr
;
8384 unsigned rat_index_mode
;
8386 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8388 r
= load_index_src(ctx
, 0, &idx_gpr
);
8392 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8393 src_requires_loading
= true;
8395 if (src_requires_loading
) {
8396 struct r600_bytecode_alu alu
;
8397 for (i
= 0; i
< 4; i
++) {
8398 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8399 alu
.op
= ALU_OP1_MOV
;
8400 alu
.dst
.sel
= ctx
->temp_reg
;
8403 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8407 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8411 val_gpr
= ctx
->temp_reg
;
8413 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8415 egcm_load_index_reg(ctx
->bc
, 1, false);
8417 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8418 cf
= ctx
->bc
->cf_last
;
8420 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8421 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8422 cf
->rat
.index_mode
= rat_index_mode
;
8423 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8424 cf
->output
.gpr
= val_gpr
;
8425 cf
->output
.index_gpr
= idx_gpr
;
8426 cf
->output
.comp_mask
= 0xf;
8427 cf
->output
.burst_count
= 1;
8430 cf
->output
.elem_size
= 0;
8434 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8436 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8437 struct r600_bytecode_alu alu
;
8439 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8440 int temp_reg
= r600_get_temp(ctx
);
8443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8444 alu
.op
= ALU_OP1_MOV
;
8445 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8446 alu
.dst
.sel
= temp_reg
;
8449 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8453 lasti
= tgsi_last_instruction(write_mask
);
8454 for (i
= 1; i
<= lasti
; i
++) {
8455 if (!(write_mask
& (1 << i
)))
8457 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8460 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8464 for (i
= 0; i
<= lasti
; i
++) {
8465 if (!(write_mask
& (1 << i
)))
8468 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8469 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8470 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8471 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8473 alu
.src
[0].sel
= temp_reg
;
8474 alu
.src
[0].chan
= i
;
8475 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8476 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8478 alu
.is_lds_idx_op
= true;
8480 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8486 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8487 alu
.op
= LDS_OP2_LDS_WRITE
;
8489 alu
.src
[0].sel
= temp_reg
;
8490 alu
.src
[0].chan
= i
;
8491 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8494 alu
.is_lds_idx_op
= true;
8496 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8503 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8505 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8506 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8507 return tgsi_store_buffer_rat(ctx
);
8508 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8509 return tgsi_store_lds(ctx
);
8511 return tgsi_store_rat(ctx
);
8514 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8516 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8517 /* have to work out the offset into the RAT immediate return buffer */
8518 struct r600_bytecode_alu alu
;
8519 struct r600_bytecode_vtx vtx
;
8520 struct r600_bytecode_cf
*cf
;
8523 unsigned format
, num_format
, format_comp
, endian
;
8524 const struct util_format_description
*desc
;
8525 unsigned rat_index_mode
;
8526 unsigned immed_base
;
8529 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8530 rat_base
= ctx
->shader
->rat_base
;
8532 r
= load_thread_id_gpr(ctx
);
8536 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8537 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8538 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8540 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8543 idx_gpr
= ctx
->temp_reg
;
8545 r
= load_index_src(ctx
, 1, &idx_gpr
);
8550 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8552 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8554 alu
.op
= ALU_OP1_MOV
;
8555 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8558 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8560 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8565 alu
.op
= ALU_OP1_MOV
;
8566 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8567 if (ctx
->bc
->chip_class
== CAYMAN
)
8572 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8574 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8578 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8579 alu
.op
= ALU_OP1_MOV
;
8580 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8583 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8585 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8591 egcm_load_index_reg(ctx
->bc
, 1, false);
8592 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8593 cf
= ctx
->bc
->cf_last
;
8595 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
8596 cf
->rat
.inst
= ctx
->inst_info
->op
;
8597 cf
->rat
.index_mode
= rat_index_mode
;
8598 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8599 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8600 cf
->output
.index_gpr
= idx_gpr
;
8601 cf
->output
.comp_mask
= 0xf;
8602 cf
->output
.burst_count
= 1;
8606 cf
->output
.elem_size
= 0;
8607 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8608 cf
= ctx
->bc
->cf_last
;
8612 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8613 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
8614 desc
= util_format_description(inst
->Memory
.Format
);
8615 r600_vertex_data_type(inst
->Memory
.Format
,
8616 &format
, &num_format
, &format_comp
, &endian
);
8617 vtx
.dst_sel_x
= desc
->swizzle
[0];
8625 vtx
.op
= FETCH_OP_VFETCH
;
8626 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8627 vtx
.buffer_index_mode
= rat_index_mode
;
8628 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8629 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8631 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8635 vtx
.use_const_fields
= 0;
8636 vtx
.srf_mode_all
= 1;
8637 vtx
.data_format
= format
;
8638 vtx
.num_format_all
= num_format
;
8639 vtx
.format_comp_all
= format_comp
;
8640 vtx
.endian
= endian
;
8642 vtx
.mega_fetch_count
= 0xf;
8643 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8646 cf
= ctx
->bc
->cf_last
;
8652 static int get_gds_op(int opcode
)
8655 case TGSI_OPCODE_ATOMUADD
:
8656 return FETCH_OP_GDS_ADD_RET
;
8657 case TGSI_OPCODE_ATOMAND
:
8658 return FETCH_OP_GDS_AND_RET
;
8659 case TGSI_OPCODE_ATOMOR
:
8660 return FETCH_OP_GDS_OR_RET
;
8661 case TGSI_OPCODE_ATOMXOR
:
8662 return FETCH_OP_GDS_XOR_RET
;
8663 case TGSI_OPCODE_ATOMUMIN
:
8664 return FETCH_OP_GDS_MIN_UINT_RET
;
8665 case TGSI_OPCODE_ATOMUMAX
:
8666 return FETCH_OP_GDS_MAX_UINT_RET
;
8667 case TGSI_OPCODE_ATOMXCHG
:
8668 return FETCH_OP_GDS_XCHG_RET
;
8669 case TGSI_OPCODE_ATOMCAS
:
8670 return FETCH_OP_GDS_CMP_XCHG_RET
;
8676 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8678 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8679 struct r600_bytecode_gds gds
;
8680 struct r600_bytecode_alu alu
;
8681 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8684 int uav_index_mode
= 0;
8685 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8688 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8692 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8696 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
) {
8697 if (inst
->Src
[3].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8698 int value
= (ctx
->literals
[4 * inst
->Src
[3].Register
.Index
+ inst
->Src
[3].Register
.SwizzleX
]);
8699 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8700 alu
.op
= ALU_OP1_MOV
;
8701 alu
.dst
.sel
= ctx
->temp_reg
;
8702 alu
.dst
.chan
= is_cm
? 2 : 1;
8703 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8704 alu
.src
[0].value
= value
;
8707 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8711 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8712 alu
.op
= ALU_OP1_MOV
;
8713 alu
.dst
.sel
= ctx
->temp_reg
;
8714 alu
.dst
.chan
= is_cm
? 2 : 1;
8715 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8718 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8723 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8724 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8725 int abs_value
= abs(value
);
8726 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8727 gds_op
= FETCH_OP_GDS_SUB_RET
;
8728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8729 alu
.op
= ALU_OP1_MOV
;
8730 alu
.dst
.sel
= ctx
->temp_reg
;
8731 alu
.dst
.chan
= is_cm
? 1 : 0;
8732 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8733 alu
.src
[0].value
= abs_value
;
8736 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8740 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8741 alu
.op
= ALU_OP1_MOV
;
8742 alu
.dst
.sel
= ctx
->temp_reg
;
8743 alu
.dst
.chan
= is_cm
? 1 : 0;
8744 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8747 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8753 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8755 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8756 gds
.uav_id
= is_cm
? 0 : uav_id
;
8757 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8758 gds
.src_gpr
= ctx
->temp_reg
;
8760 gds
.src_sel_x
= is_cm
? 0 : 4;
8761 gds
.src_sel_y
= is_cm
? 1 : 0;
8762 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
)
8763 gds
.src_sel_z
= is_cm
? 2 : 1;
8770 gds
.alloc_consume
= !is_cm
;
8772 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8775 ctx
->bc
->cf_last
->vpm
= 1;
8779 static int get_lds_op(int opcode
)
8782 case TGSI_OPCODE_ATOMUADD
:
8783 return LDS_OP2_LDS_ADD_RET
;
8784 case TGSI_OPCODE_ATOMAND
:
8785 return LDS_OP2_LDS_AND_RET
;
8786 case TGSI_OPCODE_ATOMOR
:
8787 return LDS_OP2_LDS_OR_RET
;
8788 case TGSI_OPCODE_ATOMXOR
:
8789 return LDS_OP2_LDS_XOR_RET
;
8790 case TGSI_OPCODE_ATOMUMIN
:
8791 return LDS_OP2_LDS_MIN_UINT_RET
;
8792 case TGSI_OPCODE_ATOMUMAX
:
8793 return LDS_OP2_LDS_MAX_UINT_RET
;
8794 case TGSI_OPCODE_ATOMIMIN
:
8795 return LDS_OP2_LDS_MIN_INT_RET
;
8796 case TGSI_OPCODE_ATOMIMAX
:
8797 return LDS_OP2_LDS_MAX_INT_RET
;
8798 case TGSI_OPCODE_ATOMXCHG
:
8799 return LDS_OP2_LDS_XCHG_RET
;
8800 case TGSI_OPCODE_ATOMCAS
:
8801 return LDS_OP3_LDS_CMP_XCHG_RET
;
8807 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
8809 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8810 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
8813 struct r600_bytecode_alu alu
;
8814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8816 alu
.is_lds_idx_op
= true;
8818 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8819 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
8820 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
8821 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
8823 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
8824 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8828 /* then read from LDS_OQ_A_POP */
8829 memset(&alu
, 0, sizeof(alu
));
8831 alu
.op
= ALU_OP1_MOV
;
8832 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
8833 alu
.src
[0].chan
= 0;
8834 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
8837 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8844 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
8846 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8847 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8848 return tgsi_atomic_op_rat(ctx
);
8849 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8850 return tgsi_atomic_op_gds(ctx
);
8851 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8852 return tgsi_atomic_op_rat(ctx
);
8853 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8854 return tgsi_atomic_op_lds(ctx
);
8858 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
8860 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8861 unsigned sampler_index_mode
;
8862 struct r600_bytecode_tex tex
;
8864 boolean has_txq_cube_array_z
= false;
8866 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
8867 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
8868 if (ctx
->bc
->chip_class
< EVERGREEN
)
8869 ctx
->shader
->uses_tex_buffers
= true;
8870 unsigned eg_buffer_base
= 0;
8871 eg_buffer_base
= R600_IMAGE_REAL_RESOURCE_OFFSET
;
8872 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8873 eg_buffer_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8874 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
, eg_buffer_base
);
8877 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
8878 inst
->Dst
[0].Register
.WriteMask
& 4) {
8879 ctx
->shader
->has_txq_cube_array_z_comp
= true;
8880 has_txq_cube_array_z
= true;
8883 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8884 if (sampler_index_mode
)
8885 egcm_load_index_reg(ctx
->bc
, 1, false);
8888 /* does this shader want a num layers from TXQ for a cube array? */
8889 if (has_txq_cube_array_z
) {
8890 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
8891 struct r600_bytecode_alu alu
;
8893 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8894 alu
.op
= ALU_OP1_MOV
;
8896 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8897 /* with eg each dword is either number of cubes */
8898 alu
.src
[0].sel
+= id
/ 4;
8899 alu
.src
[0].chan
= id
% 4;
8900 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8901 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8903 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8906 /* disable writemask from texture instruction */
8907 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8909 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8910 tex
.op
= ctx
->inst_info
->op
;
8911 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
8912 tex
.sampler_index_mode
= sampler_index_mode
;
8913 tex
.resource_id
= tex
.sampler_id
;
8914 tex
.resource_index_mode
= sampler_index_mode
;
8919 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8920 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8921 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8922 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8923 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8924 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8931 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
8933 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8934 struct r600_bytecode_alu alu
;
8935 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8936 unsigned i
, temp_regs
[2];
8939 /* optimize if it's just an equal balance */
8940 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
8941 for (i
= 0; i
< lasti
+ 1; i
++) {
8942 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8946 alu
.op
= ALU_OP2_ADD
;
8947 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8948 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8950 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8963 for (i
= 0; i
< lasti
+ 1; i
++) {
8964 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8967 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8968 alu
.op
= ALU_OP2_ADD
;
8969 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8970 alu
.src
[0].chan
= 0;
8971 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
8972 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
8973 alu
.dst
.sel
= ctx
->temp_reg
;
8979 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8984 /* (1 - src0) * src2 */
8985 for (i
= 0; i
< lasti
+ 1; i
++) {
8986 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8990 alu
.op
= ALU_OP2_MUL
;
8991 alu
.src
[0].sel
= ctx
->temp_reg
;
8992 alu
.src
[0].chan
= i
;
8993 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8994 alu
.dst
.sel
= ctx
->temp_reg
;
9000 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9005 /* src0 * src1 + (1 - src0) * src2 */
9006 if (ctx
->src
[0].abs
)
9007 temp_regs
[0] = r600_get_temp(ctx
);
9010 if (ctx
->src
[1].abs
)
9011 temp_regs
[1] = r600_get_temp(ctx
);
9015 for (i
= 0; i
< lasti
+ 1; i
++) {
9016 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9019 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9020 alu
.op
= ALU_OP3_MULADD
;
9022 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9025 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
9028 alu
.src
[2].sel
= ctx
->temp_reg
;
9029 alu
.src
[2].chan
= i
;
9031 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9036 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9043 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
9045 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9046 struct r600_bytecode_alu alu
;
9048 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9052 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
9054 ctx
->src
[0].abs
= 0;
9055 ctx
->src
[0].neg
= 0;
9060 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
9062 if (ctx
->src
[j
].abs
)
9063 temp_regs
[j
] = r600_get_temp(ctx
);
9066 for (i
= 0; i
< lasti
+ 1; i
++) {
9067 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9070 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9072 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9075 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
9078 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
9081 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9087 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9094 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9096 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9097 struct r600_bytecode_alu alu
;
9099 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9101 for (i
= 0; i
< lasti
+ 1; i
++) {
9102 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9105 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9106 alu
.op
= ALU_OP3_CNDE_INT
;
9107 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9108 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9109 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9110 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9116 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9123 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9125 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9126 struct r600_bytecode_alu alu
;
9130 /* result.x = 2^floor(src); */
9131 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9134 alu
.op
= ALU_OP1_FLOOR
;
9135 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9137 alu
.dst
.sel
= ctx
->temp_reg
;
9141 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9145 if (ctx
->bc
->chip_class
== CAYMAN
) {
9146 for (i
= 0; i
< 3; i
++) {
9147 alu
.op
= ALU_OP1_EXP_IEEE
;
9148 alu
.src
[0].sel
= ctx
->temp_reg
;
9149 alu
.src
[0].chan
= 0;
9151 alu
.dst
.sel
= ctx
->temp_reg
;
9153 alu
.dst
.write
= i
== 0;
9155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9160 alu
.op
= ALU_OP1_EXP_IEEE
;
9161 alu
.src
[0].sel
= ctx
->temp_reg
;
9162 alu
.src
[0].chan
= 0;
9164 alu
.dst
.sel
= ctx
->temp_reg
;
9168 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9174 /* result.y = tmp - floor(tmp); */
9175 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9178 alu
.op
= ALU_OP1_FRACT
;
9179 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9181 alu
.dst
.sel
= ctx
->temp_reg
;
9183 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9192 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9197 /* result.z = RoughApprox2ToX(tmp);*/
9198 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9199 if (ctx
->bc
->chip_class
== CAYMAN
) {
9200 for (i
= 0; i
< 3; i
++) {
9201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9202 alu
.op
= ALU_OP1_EXP_IEEE
;
9203 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9205 alu
.dst
.sel
= ctx
->temp_reg
;
9212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9217 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9218 alu
.op
= ALU_OP1_EXP_IEEE
;
9219 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9221 alu
.dst
.sel
= ctx
->temp_reg
;
9227 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9233 /* result.w = 1.0;*/
9234 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9235 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9237 alu
.op
= ALU_OP1_MOV
;
9238 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9239 alu
.src
[0].chan
= 0;
9241 alu
.dst
.sel
= ctx
->temp_reg
;
9245 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9249 return tgsi_helper_copy(ctx
, inst
);
9252 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9254 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9255 struct r600_bytecode_alu alu
;
9259 /* result.x = floor(log2(|src|)); */
9260 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9261 if (ctx
->bc
->chip_class
== CAYMAN
) {
9262 for (i
= 0; i
< 3; i
++) {
9263 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9265 alu
.op
= ALU_OP1_LOG_IEEE
;
9266 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9267 r600_bytecode_src_set_abs(&alu
.src
[0]);
9269 alu
.dst
.sel
= ctx
->temp_reg
;
9275 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9281 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9283 alu
.op
= ALU_OP1_LOG_IEEE
;
9284 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9285 r600_bytecode_src_set_abs(&alu
.src
[0]);
9287 alu
.dst
.sel
= ctx
->temp_reg
;
9291 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9296 alu
.op
= ALU_OP1_FLOOR
;
9297 alu
.src
[0].sel
= ctx
->temp_reg
;
9298 alu
.src
[0].chan
= 0;
9300 alu
.dst
.sel
= ctx
->temp_reg
;
9305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9310 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9311 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9313 if (ctx
->bc
->chip_class
== CAYMAN
) {
9314 for (i
= 0; i
< 3; i
++) {
9315 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9317 alu
.op
= ALU_OP1_LOG_IEEE
;
9318 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9319 r600_bytecode_src_set_abs(&alu
.src
[0]);
9321 alu
.dst
.sel
= ctx
->temp_reg
;
9328 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9333 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9335 alu
.op
= ALU_OP1_LOG_IEEE
;
9336 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9337 r600_bytecode_src_set_abs(&alu
.src
[0]);
9339 alu
.dst
.sel
= ctx
->temp_reg
;
9344 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9349 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9351 alu
.op
= ALU_OP1_FLOOR
;
9352 alu
.src
[0].sel
= ctx
->temp_reg
;
9353 alu
.src
[0].chan
= 1;
9355 alu
.dst
.sel
= ctx
->temp_reg
;
9360 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9364 if (ctx
->bc
->chip_class
== CAYMAN
) {
9365 for (i
= 0; i
< 3; i
++) {
9366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9367 alu
.op
= ALU_OP1_EXP_IEEE
;
9368 alu
.src
[0].sel
= ctx
->temp_reg
;
9369 alu
.src
[0].chan
= 1;
9371 alu
.dst
.sel
= ctx
->temp_reg
;
9378 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9384 alu
.op
= ALU_OP1_EXP_IEEE
;
9385 alu
.src
[0].sel
= ctx
->temp_reg
;
9386 alu
.src
[0].chan
= 1;
9388 alu
.dst
.sel
= ctx
->temp_reg
;
9393 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9398 if (ctx
->bc
->chip_class
== CAYMAN
) {
9399 for (i
= 0; i
< 3; i
++) {
9400 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9401 alu
.op
= ALU_OP1_RECIP_IEEE
;
9402 alu
.src
[0].sel
= ctx
->temp_reg
;
9403 alu
.src
[0].chan
= 1;
9405 alu
.dst
.sel
= ctx
->temp_reg
;
9412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9417 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9418 alu
.op
= ALU_OP1_RECIP_IEEE
;
9419 alu
.src
[0].sel
= ctx
->temp_reg
;
9420 alu
.src
[0].chan
= 1;
9422 alu
.dst
.sel
= ctx
->temp_reg
;
9427 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9432 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9434 alu
.op
= ALU_OP2_MUL
;
9436 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9437 r600_bytecode_src_set_abs(&alu
.src
[0]);
9439 alu
.src
[1].sel
= ctx
->temp_reg
;
9440 alu
.src
[1].chan
= 1;
9442 alu
.dst
.sel
= ctx
->temp_reg
;
9447 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9452 /* result.z = log2(|src|);*/
9453 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9454 if (ctx
->bc
->chip_class
== CAYMAN
) {
9455 for (i
= 0; i
< 3; i
++) {
9456 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9458 alu
.op
= ALU_OP1_LOG_IEEE
;
9459 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9460 r600_bytecode_src_set_abs(&alu
.src
[0]);
9462 alu
.dst
.sel
= ctx
->temp_reg
;
9469 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9476 alu
.op
= ALU_OP1_LOG_IEEE
;
9477 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9478 r600_bytecode_src_set_abs(&alu
.src
[0]);
9480 alu
.dst
.sel
= ctx
->temp_reg
;
9485 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9491 /* result.w = 1.0; */
9492 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9495 alu
.op
= ALU_OP1_MOV
;
9496 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9497 alu
.src
[0].chan
= 0;
9499 alu
.dst
.sel
= ctx
->temp_reg
;
9504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9509 return tgsi_helper_copy(ctx
, inst
);
9512 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9514 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9515 struct r600_bytecode_alu alu
;
9517 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9518 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9520 assert(inst
->Dst
[0].Register
.Index
< 3);
9521 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9523 switch (inst
->Instruction
.Opcode
) {
9524 case TGSI_OPCODE_ARL
:
9525 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9527 case TGSI_OPCODE_ARR
:
9528 alu
.op
= ALU_OP1_FLT_TO_INT
;
9530 case TGSI_OPCODE_UARL
:
9531 alu
.op
= ALU_OP1_MOV
;
9538 for (i
= 0; i
<= lasti
; ++i
) {
9539 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9541 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9542 alu
.last
= i
== lasti
;
9546 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9551 if (inst
->Dst
[0].Register
.Index
> 0)
9552 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
9554 ctx
->bc
->ar_loaded
= 0;
9558 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
9560 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9561 struct r600_bytecode_alu alu
;
9563 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9565 switch (inst
->Instruction
.Opcode
) {
9566 case TGSI_OPCODE_ARL
:
9567 memset(&alu
, 0, sizeof(alu
));
9568 alu
.op
= ALU_OP1_FLOOR
;
9569 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9571 for (i
= 0; i
<= lasti
; ++i
) {
9572 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9574 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9575 alu
.last
= i
== lasti
;
9576 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9581 memset(&alu
, 0, sizeof(alu
));
9582 alu
.op
= ALU_OP1_FLT_TO_INT
;
9583 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
9584 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9586 /* FLT_TO_INT is trans-only on r600/r700 */
9588 for (i
= 0; i
<= lasti
; ++i
) {
9590 alu
.src
[0].chan
= i
;
9591 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9595 case TGSI_OPCODE_ARR
:
9596 memset(&alu
, 0, sizeof(alu
));
9597 alu
.op
= ALU_OP1_FLT_TO_INT
;
9598 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9600 /* FLT_TO_INT is trans-only on r600/r700 */
9602 for (i
= 0; i
<= lasti
; ++i
) {
9603 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9605 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9606 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9611 case TGSI_OPCODE_UARL
:
9612 memset(&alu
, 0, sizeof(alu
));
9613 alu
.op
= ALU_OP1_MOV
;
9614 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9616 for (i
= 0; i
<= lasti
; ++i
) {
9617 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9619 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9620 alu
.last
= i
== lasti
;
9621 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9631 ctx
->bc
->ar_loaded
= 0;
9635 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9637 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9638 struct r600_bytecode_alu alu
;
9641 for (i
= 0; i
< 4; i
++) {
9642 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9644 alu
.op
= ALU_OP2_MUL
;
9645 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9647 if (i
== 0 || i
== 3) {
9648 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9650 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9653 if (i
== 0 || i
== 2) {
9654 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9656 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9660 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9667 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
,
9668 struct r600_bytecode_alu_src
*src
)
9670 struct r600_bytecode_alu alu
;
9673 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9675 alu
.execute_mask
= 1;
9676 alu
.update_pred
= 1;
9678 alu
.dst
.sel
= ctx
->temp_reg
;
9683 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9684 alu
.src
[1].chan
= 0;
9688 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9694 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9696 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9700 if (ctx
->bc
->cf_last
) {
9701 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9703 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9708 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9709 ctx
->bc
->force_add_cf
= 1;
9710 } else if (alu_pop
== 2) {
9711 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9712 ctx
->bc
->force_add_cf
= 1;
9719 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9720 ctx
->bc
->cf_last
->pop_count
= pops
;
9721 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9727 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9730 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9734 unsigned entry_size
= stack
->entry_size
;
9736 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9737 elements
+= stack
->push
;
9739 switch (ctx
->bc
->chip_class
) {
9742 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9743 * the stack must be reserved to hold the current active/continue
9745 if (reason
== FC_PUSH_VPM
) {
9751 /* r9xx: any stack operation on empty stack consumes 2 additional
9756 /* FIXME: do the two elements added above cover the cases for the
9760 /* r8xx+: 2 extra elements are not always required, but one extra
9761 * element must be added for each of the following cases:
9762 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9764 * (Currently we don't use ALU_ELSE_AFTER.)
9765 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9766 * PUSH instruction executed.
9768 * NOTE: it seems we also need to reserve additional element in some
9769 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9770 * then STACK_SIZE should be 2 instead of 1 */
9771 if (reason
== FC_PUSH_VPM
) {
9781 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9782 * for all chips, so we use 4 in the final formula, not the real entry_size
9786 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9788 if (entries
> stack
->max_entries
)
9789 stack
->max_entries
= entries
;
9792 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9796 --ctx
->bc
->stack
.push
;
9797 assert(ctx
->bc
->stack
.push
>= 0);
9800 --ctx
->bc
->stack
.push_wqm
;
9801 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9804 --ctx
->bc
->stack
.loop
;
9805 assert(ctx
->bc
->stack
.loop
>= 0);
9813 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
9817 ++ctx
->bc
->stack
.push
;
9820 ++ctx
->bc
->stack
.push_wqm
;
9822 ++ctx
->bc
->stack
.loop
;
9828 callstack_update_max_depth(ctx
, reason
);
9831 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
9833 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
9835 sp
->mid
= realloc((void *)sp
->mid
,
9836 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
9837 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
9841 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
9843 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
9844 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
9845 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
9849 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
9851 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
9861 static int emit_return(struct r600_shader_ctx
*ctx
)
9863 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
9867 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
9870 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
9871 ctx
->bc
->cf_last
->pop_count
= pops
;
9872 /* XXX work out offset */
9876 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
9881 static void emit_testflag(struct r600_shader_ctx
*ctx
)
9886 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
9889 emit_jump_to_offset(ctx
, 1, 4);
9890 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
9891 pops(ctx
, ifidx
+ 1);
9895 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
9899 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9900 ctx
->bc
->cf_last
->pop_count
= 1;
9902 fc_set_mid(ctx
, fc_sp
);
9908 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
,
9909 struct r600_bytecode_alu_src
*src
)
9911 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
9913 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
9914 * LOOP_STARTxxx for nested loops may put the branch stack into a state
9915 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
9916 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
9917 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
9918 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
9919 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9920 alu_type
= CF_OP_ALU
;
9923 emit_logic_pred(ctx
, opcode
, alu_type
, src
);
9925 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
9927 fc_pushlevel(ctx
, FC_IF
);
9929 callstack_push(ctx
, FC_PUSH_VPM
);
9933 static int tgsi_if(struct r600_shader_ctx
*ctx
)
9935 struct r600_bytecode_alu_src alu_src
;
9936 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
9938 return emit_if(ctx
, ALU_OP2_PRED_SETNE
, &alu_src
);
9941 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
9943 struct r600_bytecode_alu_src alu_src
;
9944 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
9945 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
9948 static int tgsi_else(struct r600_shader_ctx
*ctx
)
9950 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
9951 ctx
->bc
->cf_last
->pop_count
= 1;
9953 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
9954 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
9958 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
9961 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
9962 R600_ERR("if/endif unbalanced in shader\n");
9966 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
9967 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9968 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
9970 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9974 callstack_pop(ctx
, FC_PUSH_VPM
);
9978 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
9980 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
9981 * limited to 4096 iterations, like the other LOOP_* instructions. */
9982 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
9984 fc_pushlevel(ctx
, FC_LOOP
);
9986 /* check stack depth */
9987 callstack_push(ctx
, FC_LOOP
);
9991 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
9995 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
9997 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
9998 R600_ERR("loop/endloop in shader code are not paired.\n");
10002 /* fixup loop pointers - from r600isa
10003 LOOP END points to CF after LOOP START,
10004 LOOP START point to CF after LOOP END
10005 BRK/CONT point to LOOP END CF
10007 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
10009 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10011 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
10012 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
10014 /* XXX add LOOPRET support */
10016 callstack_pop(ctx
, FC_LOOP
);
10020 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
10024 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
10026 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
10031 R600_ERR("Break not inside loop/endloop pair\n");
10035 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10037 fc_set_mid(ctx
, fscp
- 1);
10042 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
10044 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10045 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
10048 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10049 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
10051 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10053 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
10054 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10055 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
10060 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
10062 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10063 struct r600_bytecode_alu alu
;
10065 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10068 for (i
= 0; i
< lasti
+ 1; i
++) {
10069 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10075 alu
.dst
.sel
= ctx
->temp_reg
;
10078 alu
.op
= ALU_OP2_MULLO_UINT
;
10079 for (j
= 0; j
< 2; j
++) {
10080 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10084 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10090 for (i
= 0; i
< lasti
+ 1; i
++) {
10091 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10094 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10095 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10097 alu
.op
= ALU_OP2_ADD_INT
;
10099 alu
.src
[0].sel
= ctx
->temp_reg
;
10100 alu
.src
[0].chan
= i
;
10102 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10113 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10115 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10116 struct r600_bytecode_alu alu
;
10118 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10120 /* temp.xy = f32_to_f16(src) */
10121 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10122 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10124 alu
.dst
.sel
= ctx
->temp_reg
;
10126 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10127 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10131 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10133 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10137 /* dst.x = temp.y * 0x10000 + temp.x */
10138 for (i
= 0; i
< lasti
+ 1; i
++) {
10139 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10143 alu
.op
= ALU_OP3_MULADD_UINT24
;
10145 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10146 alu
.last
= i
== lasti
;
10147 alu
.src
[0].sel
= ctx
->temp_reg
;
10148 alu
.src
[0].chan
= 1;
10149 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10150 alu
.src
[1].value
= 0x10000;
10151 alu
.src
[2].sel
= ctx
->temp_reg
;
10152 alu
.src
[2].chan
= 0;
10153 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10161 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10163 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10164 struct r600_bytecode_alu alu
;
10166 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10168 /* temp.x = src.x */
10169 /* note: no need to mask out the high bits */
10170 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10171 alu
.op
= ALU_OP1_MOV
;
10173 alu
.dst
.sel
= ctx
->temp_reg
;
10175 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10176 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10180 /* temp.y = src.x >> 16 */
10181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10182 alu
.op
= ALU_OP2_LSHR_INT
;
10184 alu
.dst
.sel
= ctx
->temp_reg
;
10186 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10187 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10188 alu
.src
[1].value
= 16;
10190 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10194 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10195 for (i
= 0; i
< lasti
+ 1; i
++) {
10196 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10198 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10199 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10200 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10201 alu
.src
[0].sel
= ctx
->temp_reg
;
10202 alu
.src
[0].chan
= i
% 2;
10203 alu
.last
= i
== lasti
;
10204 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10212 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10214 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10215 struct r600_bytecode_alu alu
;
10216 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10220 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10221 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10222 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10223 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10224 dst
= r600_get_temp(ctx
);
10226 r
= tgsi_op3_dst(ctx
, dst
);
10230 for (i
= 0; i
< lasti
+ 1; i
++) {
10231 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10232 alu
.op
= ALU_OP2_SETGE_INT
;
10233 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10234 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10235 alu
.src
[1].value
= 32;
10236 alu
.dst
.sel
= ctx
->temp_reg
;
10241 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10246 for (i
= 0; i
< lasti
+ 1; i
++) {
10247 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10248 alu
.op
= ALU_OP3_CNDE_INT
;
10250 alu
.src
[0].sel
= ctx
->temp_reg
;
10251 alu
.src
[0].chan
= i
;
10253 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10255 alu
.src
[1].sel
= dst
;
10257 alu
.src
[1].sel
= alu
.dst
.sel
;
10258 alu
.src
[1].chan
= i
;
10259 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10263 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10271 static int tgsi_clock(struct r600_shader_ctx
*ctx
)
10273 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10274 struct r600_bytecode_alu alu
;
10277 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10278 alu
.op
= ALU_OP1_MOV
;
10279 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10280 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_LO
;
10281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10284 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10285 alu
.op
= ALU_OP1_MOV
;
10286 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10287 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_HI
;
10288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10294 static int emit_u64add(struct r600_shader_ctx
*ctx
, int op
,
10296 int src0_sel
, int src0_chan
,
10297 int src1_sel
, int src1_chan
)
10299 struct r600_bytecode_alu alu
;
10303 if (op
== ALU_OP2_ADD_INT
)
10304 opc
= ALU_OP2_ADDC_UINT
;
10306 opc
= ALU_OP2_SUBB_UINT
;
10308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10310 alu
.dst
.sel
= treg
;
10313 alu
.src
[0].sel
= src0_sel
;
10314 alu
.src
[0].chan
= src0_chan
+ 0;
10315 alu
.src
[1].sel
= src1_sel
;
10316 alu
.src
[1].chan
= src1_chan
+ 0;
10317 alu
.src
[1].neg
= 0;
10318 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10324 alu
.dst
.sel
= treg
;
10327 alu
.src
[0].sel
= src0_sel
;
10328 alu
.src
[0].chan
= src0_chan
+ 1;
10329 alu
.src
[1].sel
= src1_sel
;
10330 alu
.src
[1].chan
= src1_chan
+ 1;
10331 alu
.src
[1].neg
= 0;
10332 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10336 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10338 alu
.dst
.sel
= treg
;
10342 alu
.src
[0].sel
= src0_sel
;
10343 alu
.src
[0].chan
= src0_chan
+ 0;
10344 alu
.src
[1].sel
= src1_sel
;
10345 alu
.src
[1].chan
= src1_chan
+ 0;
10346 alu
.src
[1].neg
= 0;
10347 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10351 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10353 alu
.dst
.sel
= treg
;
10356 alu
.src
[0].sel
= treg
;
10357 alu
.src
[0].chan
= 1;
10358 alu
.src
[1].sel
= treg
;
10359 alu
.src
[1].chan
= 2;
10361 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10367 static int egcm_u64add(struct r600_shader_ctx
*ctx
)
10369 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10370 struct r600_bytecode_alu alu
;
10372 int treg
= ctx
->temp_reg
;
10373 int op
= ALU_OP2_ADD_INT
, opc
= ALU_OP2_ADDC_UINT
;
10375 if (ctx
->src
[1].neg
) {
10376 op
= ALU_OP2_SUB_INT
;
10377 opc
= ALU_OP2_SUBB_UINT
;
10379 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10381 alu
.dst
.sel
= treg
;
10384 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10385 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10386 alu
.src
[1].neg
= 0;
10387 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10391 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10393 alu
.dst
.sel
= treg
;
10396 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10397 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10398 alu
.src
[1].neg
= 0;
10399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10403 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10405 alu
.dst
.sel
= treg
;
10409 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10410 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10411 alu
.src
[1].neg
= 0;
10412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10418 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10419 alu
.src
[0].sel
= treg
;
10420 alu
.src
[0].chan
= 1;
10421 alu
.src
[1].sel
= treg
;
10422 alu
.src
[1].chan
= 2;
10424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10428 alu
.op
= ALU_OP1_MOV
;
10429 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10430 alu
.src
[0].sel
= treg
;
10431 alu
.src
[0].chan
= 0;
10433 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10439 /* result.y = mul_high a, b
10441 result.y += a.x * b.y + a.y * b.x;
10443 static int egcm_u64mul(struct r600_shader_ctx
*ctx
)
10445 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10446 struct r600_bytecode_alu alu
;
10448 int treg
= ctx
->temp_reg
;
10450 /* temp.x = mul_lo a.x, b.x */
10451 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10452 alu
.op
= ALU_OP2_MULLO_UINT
;
10453 alu
.dst
.sel
= treg
;
10456 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10457 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10458 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10462 /* temp.y = mul_hi a.x, b.x */
10463 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10464 alu
.op
= ALU_OP2_MULHI_UINT
;
10465 alu
.dst
.sel
= treg
;
10468 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10469 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10470 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10474 /* temp.z = mul a.x, b.y */
10475 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10476 alu
.op
= ALU_OP2_MULLO_UINT
;
10477 alu
.dst
.sel
= treg
;
10480 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10481 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10482 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10486 /* temp.w = mul a.y, b.x */
10487 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10488 alu
.op
= ALU_OP2_MULLO_UINT
;
10489 alu
.dst
.sel
= treg
;
10492 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10493 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10494 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10498 /* temp.z = temp.z + temp.w */
10499 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10500 alu
.op
= ALU_OP2_ADD_INT
;
10501 alu
.dst
.sel
= treg
;
10504 alu
.src
[0].sel
= treg
;
10505 alu
.src
[0].chan
= 2;
10506 alu
.src
[1].sel
= treg
;
10507 alu
.src
[1].chan
= 3;
10509 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10513 /* temp.y = temp.y + temp.z */
10514 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10515 alu
.op
= ALU_OP2_ADD_INT
;
10516 alu
.dst
.sel
= treg
;
10519 alu
.src
[0].sel
= treg
;
10520 alu
.src
[0].chan
= 1;
10521 alu
.src
[1].sel
= treg
;
10522 alu
.src
[1].chan
= 2;
10524 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10528 /* dst.x = temp.x */
10529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10530 alu
.op
= ALU_OP1_MOV
;
10531 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10532 alu
.src
[0].sel
= treg
;
10533 alu
.src
[0].chan
= 0;
10534 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10538 /* dst.y = temp.y */
10539 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10540 alu
.op
= ALU_OP1_MOV
;
10541 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10542 alu
.src
[0].sel
= treg
;
10543 alu
.src
[0].chan
= 1;
10545 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10552 static int emit_u64sge(struct r600_shader_ctx
*ctx
,
10554 int src0_sel
, int src0_base_chan
,
10555 int src1_sel
, int src1_base_chan
)
10558 /* for 64-bit sge */
10559 /* result = (src0.y > src1.y) || ((src0.y == src1.y) && src0.x >= src1.x)) */
10560 r
= single_alu_op2(ctx
, ALU_OP2_SETGT_UINT
,
10562 src0_sel
, src0_base_chan
+ 1,
10563 src1_sel
, src1_base_chan
+ 1);
10567 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10569 src0_sel
, src0_base_chan
,
10570 src1_sel
, src1_base_chan
);
10574 r
= single_alu_op2(ctx
, ALU_OP2_SETE_INT
,
10576 src0_sel
, src0_base_chan
+ 1,
10577 src1_sel
, src1_base_chan
+ 1);
10581 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10588 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10597 /* this isn't a complete div it's just enough for qbo shader to work */
10598 static int egcm_u64div(struct r600_shader_ctx
*ctx
)
10600 struct r600_bytecode_alu alu
;
10601 struct r600_bytecode_alu_src alu_num_hi
, alu_num_lo
, alu_denom_hi
, alu_denom_lo
, alu_src
;
10603 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10605 /* make sure we are dividing my a const with 0 in the high bits */
10606 if (ctx
->src
[1].sel
!= V_SQ_ALU_SRC_LITERAL
)
10608 if (ctx
->src
[1].value
[ctx
->src
[1].swizzle
[1]] != 0)
10610 /* make sure we are doing one division */
10611 if (inst
->Dst
[0].Register
.WriteMask
!= 0x3)
10614 /* emit_if uses ctx->temp_reg so we can't */
10615 int treg
= r600_get_temp(ctx
);
10616 int tmp_num
= r600_get_temp(ctx
);
10617 int sub_tmp
= r600_get_temp(ctx
);
10619 /* tmp quot are tmp_num.zw */
10620 r600_bytecode_src(&alu_num_lo
, &ctx
->src
[0], 0);
10621 r600_bytecode_src(&alu_num_hi
, &ctx
->src
[0], 1);
10622 r600_bytecode_src(&alu_denom_lo
, &ctx
->src
[1], 0);
10623 r600_bytecode_src(&alu_denom_hi
, &ctx
->src
[1], 1);
10625 /* MOV tmp_num.xy, numerator */
10626 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10628 alu_num_lo
.sel
, alu_num_lo
.chan
,
10632 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10634 alu_num_hi
.sel
, alu_num_hi
.chan
,
10639 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10641 V_SQ_ALU_SRC_LITERAL
, 0,
10646 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10648 V_SQ_ALU_SRC_LITERAL
, 0,
10653 /* treg 0 is log2_denom */
10654 /* normally this gets the MSB for the denom high value
10655 - however we know this will always be 0 here. */
10656 r
= single_alu_op2(ctx
,
10659 V_SQ_ALU_SRC_LITERAL
, 32,
10664 /* normally check demon hi for 0, but we know it is already */
10665 /* t0.z = num_hi >= denom_lo */
10666 r
= single_alu_op2(ctx
,
10667 ALU_OP2_SETGE_UINT
,
10669 alu_num_hi
.sel
, alu_num_hi
.chan
,
10670 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10674 memset(&alu_src
, 0, sizeof(alu_src
));
10675 alu_src
.sel
= treg
;
10677 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10681 /* for loops in here */
10682 /* get msb t0.x = msb(src[1].x) first */
10683 int msb_lo
= util_last_bit(alu_denom_lo
.value
);
10684 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10686 V_SQ_ALU_SRC_LITERAL
, msb_lo
,
10691 /* unroll the asm here */
10692 for (i
= 0; i
< 31; i
++) {
10693 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10695 V_SQ_ALU_SRC_LITERAL
, i
,
10700 /* we can do this on the CPU */
10701 uint32_t denom_lo_shl
= alu_denom_lo
.value
<< (31 - i
);
10702 /* t0.z = tmp_num.y >= t0.z */
10703 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10706 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
10710 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10717 memset(&alu_src
, 0, sizeof(alu_src
));
10718 alu_src
.sel
= treg
;
10720 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10724 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
10727 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
10731 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10734 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
10738 r
= tgsi_endif(ctx
);
10743 /* log2_denom is always <= 31, so manually peel the last loop
10746 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10749 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10753 memset(&alu_src
, 0, sizeof(alu_src
));
10754 alu_src
.sel
= treg
;
10756 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10760 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
10763 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10767 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10770 V_SQ_ALU_SRC_LITERAL
, 1U);
10773 r
= tgsi_endif(ctx
);
10777 r
= tgsi_endif(ctx
);
10781 /* onto the second loop to unroll */
10782 for (i
= 0; i
< 31; i
++) {
10783 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10785 V_SQ_ALU_SRC_LITERAL
, (63 - (31 - i
)),
10790 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
<< (31 - i
);
10791 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10793 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
10798 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10800 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
10805 r
= emit_u64sge(ctx
, sub_tmp
,
10811 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10818 memset(&alu_src
, 0, sizeof(alu_src
));
10819 alu_src
.sel
= treg
;
10821 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10826 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
10833 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10840 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10847 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10850 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
10854 r
= tgsi_endif(ctx
);
10859 /* log2_denom is always <= 63, so manually peel the last loop
10862 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
;
10863 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10865 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
10870 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10872 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
10877 r
= emit_u64sge(ctx
, sub_tmp
,
10883 memset(&alu_src
, 0, sizeof(alu_src
));
10884 alu_src
.sel
= sub_tmp
;
10886 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10890 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
10897 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10900 V_SQ_ALU_SRC_LITERAL
, 1U);
10903 r
= tgsi_endif(ctx
);
10907 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10908 alu
.op
= ALU_OP1_MOV
;
10909 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10910 alu
.src
[0].sel
= tmp_num
;
10911 alu
.src
[0].chan
= 2;
10912 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10916 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10917 alu
.op
= ALU_OP1_MOV
;
10918 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10919 alu
.src
[0].sel
= tmp_num
;
10920 alu
.src
[0].chan
= 3;
10922 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10928 static int egcm_u64sne(struct r600_shader_ctx
*ctx
)
10930 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10931 struct r600_bytecode_alu alu
;
10933 int treg
= ctx
->temp_reg
;
10935 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10936 alu
.op
= ALU_OP2_SETNE_INT
;
10937 alu
.dst
.sel
= treg
;
10940 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10941 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10942 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10946 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10947 alu
.op
= ALU_OP2_SETNE_INT
;
10948 alu
.dst
.sel
= treg
;
10951 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10952 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10954 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10958 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10959 alu
.op
= ALU_OP2_OR_INT
;
10960 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10961 alu
.src
[0].sel
= treg
;
10962 alu
.src
[0].chan
= 0;
10963 alu
.src
[1].sel
= treg
;
10964 alu
.src
[1].chan
= 1;
10966 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10972 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
10973 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10974 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10975 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10977 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10979 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10980 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10981 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10982 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10983 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10984 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10985 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10986 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10987 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
10988 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10989 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10990 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10991 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10992 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10993 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10994 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10995 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10996 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10997 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10998 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10999 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11000 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11001 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11002 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11003 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11004 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11005 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11006 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11007 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11008 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11009 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11010 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11011 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11012 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11013 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11014 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11015 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11016 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11017 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11018 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11019 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11020 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11021 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11022 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11023 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11024 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11025 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11026 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11027 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11028 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11029 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11030 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11031 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11032 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11033 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11034 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11035 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11036 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11037 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11038 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11039 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11040 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11041 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11042 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11043 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11044 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11045 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11046 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11047 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11048 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11049 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11050 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11051 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11052 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11053 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11054 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11055 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11056 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
11057 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11058 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11059 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11060 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11061 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11062 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
11063 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11064 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11065 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11066 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11067 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11068 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11069 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11070 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11071 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11072 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11073 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11074 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11075 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11076 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11077 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11078 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11079 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11080 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11081 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11082 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11083 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11084 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11085 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11086 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11087 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11088 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11089 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11090 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11091 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11092 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11093 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11094 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
11095 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11096 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11097 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11098 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11099 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11100 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
11101 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11102 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
11103 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11104 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11105 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11106 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11107 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11108 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11109 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11110 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11111 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11112 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11113 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
11114 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11115 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
11116 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11117 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11118 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11119 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11120 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11121 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11122 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11123 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11124 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11125 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11126 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11127 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11128 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11129 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11130 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11131 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11132 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
11133 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11134 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11135 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11136 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11137 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11138 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11139 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11140 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11141 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11142 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11143 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11144 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11145 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11146 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11147 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11148 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11149 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11150 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11151 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11152 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11153 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11154 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11155 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11156 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11157 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
11158 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
11159 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
11160 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
11161 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11162 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
11163 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
11164 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
11165 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
11166 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
11167 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11168 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11169 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11170 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11173 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
11174 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11175 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11176 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11177 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11178 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11179 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11180 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11181 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11182 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11183 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11184 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11185 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11186 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11187 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11188 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11189 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11190 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11191 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11192 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11193 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11194 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11195 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11196 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11197 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11198 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11199 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11200 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11201 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11202 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11203 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11204 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11205 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11206 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11207 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11208 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11209 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11210 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11211 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11212 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11213 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11214 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11215 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11216 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11217 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11218 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11219 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11220 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11221 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11222 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11223 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11224 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11225 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11226 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11227 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11228 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11229 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11230 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11231 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11232 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11233 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11234 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11235 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11236 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11237 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11238 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11239 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11240 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11241 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11242 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11243 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11244 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11245 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11246 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11247 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11248 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11249 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11250 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11251 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11252 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11253 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11254 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11255 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11256 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11257 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11258 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11259 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11260 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11261 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11262 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11263 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11264 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11265 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11266 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11267 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11268 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11269 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11270 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11271 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11272 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11273 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11274 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11275 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11276 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11277 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11278 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11279 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11280 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11281 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11282 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11283 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11284 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11285 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11286 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11287 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11288 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11289 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11290 /* Refer below for TGSI_OPCODE_DFMA */
11291 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
11292 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11293 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11294 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11295 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11296 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11297 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11298 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11299 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
11300 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11301 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11302 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11303 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11304 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11305 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11306 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11307 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11308 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11309 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11310 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11311 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11312 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11313 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11314 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11315 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11316 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11317 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11318 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11319 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11320 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11321 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11322 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11323 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11324 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11325 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11326 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11327 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11328 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11329 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11330 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11331 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11332 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11333 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11334 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11335 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11336 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11337 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11338 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11339 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11340 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11341 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11342 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11343 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11344 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11345 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11346 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11347 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11348 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11349 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11350 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11351 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11352 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11353 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11354 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11355 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11356 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11357 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11358 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11359 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11360 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11361 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11362 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11363 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11364 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11365 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11366 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11367 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11368 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11369 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11370 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11371 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11372 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11373 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11374 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11375 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11376 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11377 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11378 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11379 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11380 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11381 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11382 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11383 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11384 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11385 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11386 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11387 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11388 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11389 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11390 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11391 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11392 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11393 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11394 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11395 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11396 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11399 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
11400 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11401 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11402 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11403 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
11404 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
11405 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11406 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11407 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11408 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11409 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11410 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11411 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11412 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11413 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11414 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11415 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11416 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11417 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11418 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11419 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
11420 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11421 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11422 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11423 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11424 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11425 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11426 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11427 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
11428 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
11429 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
11430 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11431 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11432 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11433 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11434 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11435 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
11436 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11437 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11438 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11439 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11440 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11441 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11442 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11443 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11444 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11445 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11446 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11447 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
11448 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11449 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11450 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11451 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11452 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11453 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11454 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11455 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11456 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11457 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11458 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11459 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11460 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11461 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11462 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11463 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11464 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11465 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11466 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11467 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11468 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11469 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11470 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11471 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11472 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11473 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11474 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11475 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11476 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11477 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11478 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11479 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11480 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11481 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11482 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
11483 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11484 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11485 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11486 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11487 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11488 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11489 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11490 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11491 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11492 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11493 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11494 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11495 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11496 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11497 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11498 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11499 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11500 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11501 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11502 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11503 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11504 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11505 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11506 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11507 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11508 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11509 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11510 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11511 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11512 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11513 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11514 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11515 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11516 /* Refer below for TGSI_OPCODE_DFMA */
11517 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
11518 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11519 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11520 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11521 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11522 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11523 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11524 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11525 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
11526 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
11527 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11528 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11529 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11530 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11531 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11532 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11533 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
11534 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11535 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11536 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11537 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11538 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11539 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11540 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11541 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11542 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11543 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11544 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11545 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11546 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11547 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11548 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11549 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11550 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11551 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11552 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11553 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11554 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11555 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11556 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11557 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11558 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11559 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11560 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11561 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11562 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11563 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11564 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11565 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11566 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11567 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11568 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11569 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11570 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11571 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11572 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11573 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11574 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11575 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11576 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11577 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11578 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
11579 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
11580 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11581 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11582 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11583 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11584 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11585 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11586 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11587 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11588 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11589 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11590 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11591 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11592 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11593 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11594 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11595 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11596 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11597 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11598 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11599 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11600 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11601 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11602 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11603 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11604 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11605 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11606 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11607 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11608 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11609 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11610 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11611 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11612 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11613 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11614 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11615 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11616 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11617 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11618 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11619 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11620 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11621 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11622 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},