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 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1115 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1116 /* Needs sample positions, currently those are always available */
1118 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1121 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1122 k
= eg_get_interpolator_index(interpolate
, location
);
1124 ctx
->eg_interpolators
[k
].enabled
= true;
1126 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1127 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1128 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1129 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1130 if (d
->Semantic
.Name
== inputs
[k
].name
||
1131 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1132 inputs
[k
].enabled
= true;
1139 tgsi_parse_free(&parse
);
1141 if (ctx
->info
.reads_samplemask
&&
1142 (ctx
->info
.uses_linear_sample
|| ctx
->info
.uses_linear_sample
)) {
1143 inputs
[1].enabled
= true;
1146 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1148 /* assign gpr to each interpolator according to priority */
1149 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1150 if (ctx
->eg_interpolators
[i
].enabled
) {
1151 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1155 num_baryc
= (num_baryc
+ 1) >> 1;
1156 gpr_offset
+= num_baryc
;
1159 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1160 boolean enabled
= inputs
[i
].enabled
;
1161 int *reg
= inputs
[i
].reg
;
1162 unsigned name
= inputs
[i
].name
;
1165 int gpr
= gpr_offset
+ num_regs
++;
1166 ctx
->shader
->nsys_inputs
++;
1168 // add to inputs, allocate a gpr
1169 k
= ctx
->shader
->ninput
++;
1170 ctx
->shader
->input
[k
].name
= name
;
1171 ctx
->shader
->input
[k
].sid
= 0;
1172 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1173 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1174 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1178 return gpr_offset
+ num_regs
;
1182 * for evergreen we need to scan the shader to find the number of GPRs we need to
1183 * reserve for interpolation and system values
1185 * we need to know if we are going to emit any sample or centroid inputs
1186 * if perspective and linear are required
1188 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1192 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1195 * Could get this information from the shader info. But right now
1196 * we interpolate all declared inputs, whereas the shader info will
1197 * only contain the bits if the inputs are actually used, so it might
1200 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1202 /* skip position/face/mask/sampleid */
1203 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1204 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1205 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1206 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1209 k
= eg_get_interpolator_index(
1210 ctx
->info
.input_interpolate
[i
],
1211 ctx
->info
.input_interpolate_loc
[i
]);
1213 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1216 /* XXX PULL MODEL and LINE STIPPLE */
1218 return allocate_system_value_inputs(ctx
, 0);
1221 /* sample_id_sel == NULL means fetch for current sample */
1222 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1224 struct r600_bytecode_vtx vtx
;
1227 t1
= r600_get_temp(ctx
);
1229 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1230 vtx
.op
= FETCH_OP_VFETCH
;
1231 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1232 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1233 if (sample_id
== NULL
) {
1234 assert(ctx
->fixed_pt_position_gpr
!= -1);
1236 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1240 struct r600_bytecode_alu alu
;
1242 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1243 alu
.op
= ALU_OP1_MOV
;
1244 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1248 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1255 vtx
.mega_fetch_count
= 16;
1261 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1262 vtx
.num_format_all
= 2;
1263 vtx
.format_comp_all
= 1;
1264 vtx
.use_const_fields
= 0;
1266 vtx
.endian
= r600_endian_swap(32);
1267 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1269 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1276 static int eg_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1279 struct r600_bytecode_alu alu
;
1281 /* do a vtx fetch with wqm set on the vtx fetch */
1282 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1283 alu
.op
= ALU_OP1_MOV
;
1284 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1286 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1287 alu
.src
[0].value
= 0xffffffff;
1290 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1294 /* do a vtx fetch in VPM mode */
1295 struct r600_bytecode_vtx vtx
;
1296 memset(&vtx
, 0, sizeof(vtx
));
1297 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
1298 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1299 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1301 vtx
.mega_fetch_count
= 16; /* no idea here really... */
1302 vtx
.dst_gpr
= ctx
->helper_invoc_reg
;
1304 vtx
.dst_sel_y
= 7; /* SEL_Y */
1305 vtx
.dst_sel_z
= 7; /* SEL_Z */
1306 vtx
.dst_sel_w
= 7; /* SEL_W */
1307 vtx
.data_format
= FMT_32
;
1308 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
1310 ctx
->bc
->cf_last
->vpm
= 1;
1314 static int cm_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1317 struct r600_bytecode_alu alu
;
1319 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1320 alu
.op
= ALU_OP1_MOV
;
1321 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1323 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1324 alu
.src
[0].value
= 0xffffffff;
1327 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1331 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1332 alu
.op
= ALU_OP1_MOV
;
1333 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1335 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1338 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_VALID_PIXEL_MODE
);
1342 return ctx
->helper_invoc_reg
;
1345 static int load_block_grid_size(struct r600_shader_ctx
*ctx
, bool load_block
)
1347 struct r600_bytecode_vtx vtx
;
1350 if (ctx
->cs_block_size_loaded
)
1351 return ctx
->cs_block_size_reg
;
1352 if (ctx
->cs_grid_size_loaded
)
1353 return ctx
->cs_grid_size_reg
;
1355 t1
= load_block
? ctx
->cs_block_size_reg
: ctx
->cs_grid_size_reg
;
1356 struct r600_bytecode_alu alu
;
1357 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1358 alu
.op
= ALU_OP1_MOV
;
1359 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1363 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1367 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1368 vtx
.op
= FETCH_OP_VFETCH
;
1369 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1370 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1374 vtx
.mega_fetch_count
= 16;
1380 vtx
.data_format
= FMT_32_32_32_32
;
1381 vtx
.num_format_all
= 1;
1382 vtx
.format_comp_all
= 0;
1383 vtx
.use_const_fields
= 0;
1384 vtx
.offset
= load_block
? 0 : 16; // first element is size of buffer
1385 vtx
.endian
= r600_endian_swap(32);
1386 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1388 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1393 ctx
->cs_block_size_loaded
= true;
1395 ctx
->cs_grid_size_loaded
= true;
1399 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1400 const struct tgsi_full_src_register
*tgsi_src
,
1401 struct r600_shader_src
*r600_src
)
1403 memset(r600_src
, 0, sizeof(*r600_src
));
1404 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1405 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1406 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1407 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1408 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1409 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1411 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1413 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1414 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1415 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1417 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1418 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1419 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1422 index
= tgsi_src
->Register
.Index
;
1423 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1424 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1425 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1426 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1427 r600_src
->swizzle
[0] = 2; // Z value
1428 r600_src
->swizzle
[1] = 2;
1429 r600_src
->swizzle
[2] = 2;
1430 r600_src
->swizzle
[3] = 2;
1431 r600_src
->sel
= ctx
->face_gpr
;
1432 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1433 r600_src
->swizzle
[0] = 3; // W value
1434 r600_src
->swizzle
[1] = 3;
1435 r600_src
->swizzle
[2] = 3;
1436 r600_src
->swizzle
[3] = 3;
1437 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1438 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1439 r600_src
->swizzle
[0] = 0;
1440 r600_src
->swizzle
[1] = 1;
1441 r600_src
->swizzle
[2] = 4;
1442 r600_src
->swizzle
[3] = 4;
1443 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1444 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1445 r600_src
->swizzle
[0] = 3;
1446 r600_src
->swizzle
[1] = 3;
1447 r600_src
->swizzle
[2] = 3;
1448 r600_src
->swizzle
[3] = 3;
1450 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1451 r600_src
->swizzle
[0] = 0;
1452 r600_src
->swizzle
[1] = 0;
1453 r600_src
->swizzle
[2] = 0;
1454 r600_src
->swizzle
[3] = 0;
1456 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_THREAD_ID
) {
1458 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_ID
) {
1460 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1461 r600_src
->swizzle
[0] = 3;
1462 r600_src
->swizzle
[1] = 3;
1463 r600_src
->swizzle
[2] = 3;
1464 r600_src
->swizzle
[3] = 3;
1466 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1467 r600_src
->swizzle
[0] = 2;
1468 r600_src
->swizzle
[1] = 2;
1469 r600_src
->swizzle
[2] = 2;
1470 r600_src
->swizzle
[3] = 2;
1472 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1474 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1476 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1478 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1479 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1480 r600_src
->sel
= ctx
->tess_input_info
;
1481 r600_src
->swizzle
[0] = 2;
1482 r600_src
->swizzle
[1] = 2;
1483 r600_src
->swizzle
[2] = 2;
1484 r600_src
->swizzle
[3] = 2;
1486 r600_src
->sel
= ctx
->tess_input_info
;
1487 r600_src
->swizzle
[0] = 3;
1488 r600_src
->swizzle
[1] = 3;
1489 r600_src
->swizzle
[2] = 3;
1490 r600_src
->swizzle
[3] = 3;
1492 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1494 r600_src
->swizzle
[0] = 0;
1495 r600_src
->swizzle
[1] = 0;
1496 r600_src
->swizzle
[2] = 0;
1497 r600_src
->swizzle
[3] = 0;
1498 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1500 r600_src
->swizzle
[0] = 3;
1501 r600_src
->swizzle
[1] = 3;
1502 r600_src
->swizzle
[2] = 3;
1503 r600_src
->swizzle
[3] = 3;
1504 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_GRID_SIZE
) {
1505 r600_src
->sel
= load_block_grid_size(ctx
, false);
1506 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_SIZE
) {
1507 r600_src
->sel
= load_block_grid_size(ctx
, true);
1508 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
1509 r600_src
->sel
= ctx
->helper_invoc_reg
;
1510 r600_src
->swizzle
[0] = 0;
1511 r600_src
->swizzle
[1] = 0;
1512 r600_src
->swizzle
[2] = 0;
1513 r600_src
->swizzle
[3] = 0;
1516 if (tgsi_src
->Register
.Indirect
)
1517 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1518 r600_src
->sel
= tgsi_src
->Register
.Index
;
1519 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1521 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1522 if (tgsi_src
->Register
.Dimension
) {
1523 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1524 if (tgsi_src
->Dimension
.Indirect
) {
1525 r600_src
->kc_rel
= 1;
1531 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1532 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1533 unsigned int dst_reg
)
1535 struct r600_bytecode_vtx vtx
;
1536 unsigned int ar_reg
;
1540 struct r600_bytecode_alu alu
;
1542 memset(&alu
, 0, sizeof(alu
));
1544 alu
.op
= ALU_OP2_ADD_INT
;
1545 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1546 alu
.src
[0].chan
= ar_chan
;
1548 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1549 alu
.src
[1].value
= offset
;
1551 alu
.dst
.sel
= dst_reg
;
1552 alu
.dst
.chan
= ar_chan
;
1556 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1561 ar_reg
= ctx
->bc
->ar_reg
;
1564 memset(&vtx
, 0, sizeof(vtx
));
1565 vtx
.buffer_id
= cb_idx
;
1566 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1567 vtx
.src_gpr
= ar_reg
;
1568 vtx
.src_sel_x
= ar_chan
;
1569 vtx
.mega_fetch_count
= 16;
1570 vtx
.dst_gpr
= dst_reg
;
1571 vtx
.dst_sel_x
= 0; /* SEL_X */
1572 vtx
.dst_sel_y
= 1; /* SEL_Y */
1573 vtx
.dst_sel_z
= 2; /* SEL_Z */
1574 vtx
.dst_sel_w
= 3; /* SEL_W */
1575 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1576 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1577 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1578 vtx
.endian
= r600_endian_swap(32);
1579 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1581 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1587 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1589 struct r600_bytecode_vtx vtx
;
1591 unsigned index
= src
->Register
.Index
;
1592 unsigned vtx_id
= src
->Dimension
.Index
;
1593 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1594 int offset_chan
= vtx_id
% 3;
1597 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1598 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1600 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1603 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1604 t2
= r600_get_temp(ctx
);
1606 if (src
->Dimension
.Indirect
) {
1608 struct r600_bytecode_alu alu
;
1611 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1612 if (src
->DimIndirect
.Index
> 0) {
1613 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1621 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1622 at least this is what fglrx seems to do. */
1623 for (i
= 0; i
< 3; i
++) {
1624 treg
[i
] = r600_get_temp(ctx
);
1626 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1628 for (i
= 0; i
< 3; i
++) {
1629 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1630 alu
.op
= ALU_OP1_MOV
;
1631 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1632 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1633 alu
.dst
.sel
= treg
[i
];
1637 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1641 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1642 alu
.op
= ALU_OP1_MOV
;
1643 alu
.src
[0].sel
= treg
[0];
1648 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1655 if (src
->Register
.Indirect
) {
1657 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1659 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1661 /* pull the value from index_reg */
1662 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1665 V_SQ_ALU_SRC_LITERAL
, first
);
1668 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1671 V_SQ_ALU_SRC_LITERAL
, 4,
1672 offset_reg
, offset_chan
);
1677 index
= src
->Register
.Index
- first
;
1680 memset(&vtx
, 0, sizeof(vtx
));
1681 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1682 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1683 vtx
.src_gpr
= offset_reg
;
1684 vtx
.src_sel_x
= offset_chan
;
1685 vtx
.offset
= index
* 16; /*bytes*/
1686 vtx
.mega_fetch_count
= 16;
1687 vtx
.dst_gpr
= dst_reg
;
1688 vtx
.dst_sel_x
= 0; /* SEL_X */
1689 vtx
.dst_sel_y
= 1; /* SEL_Y */
1690 vtx
.dst_sel_z
= 2; /* SEL_Z */
1691 vtx
.dst_sel_w
= 3; /* SEL_W */
1692 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1693 vtx
.use_const_fields
= 1;
1695 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1698 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1704 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1706 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1709 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1710 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1712 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1713 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1714 /* primitive id is in R0.z */
1715 ctx
->src
[i
].sel
= 0;
1716 ctx
->src
[i
].swizzle
[0] = 2;
1719 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1720 int treg
= r600_get_temp(ctx
);
1722 fetch_gs_input(ctx
, src
, treg
);
1723 ctx
->src
[i
].sel
= treg
;
1724 ctx
->src
[i
].rel
= 0;
1731 /* Tessellation shaders pass outputs to the next shader using LDS.
1733 * LS outputs = TCS(HS) inputs
1734 * TCS(HS) outputs = TES(DS) inputs
1736 * The LDS layout is:
1737 * - TCS inputs for patch 0
1738 * - TCS inputs for patch 1
1739 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1741 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1742 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1743 * - TCS outputs for patch 1
1744 * - Per-patch TCS outputs for patch 1
1745 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1746 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1749 * All three shaders VS(LS), TCS, TES share the same LDS space.
1751 /* this will return with the dw address in temp_reg.x */
1752 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1753 const struct tgsi_full_dst_register
*dst
,
1754 const struct tgsi_full_src_register
*src
,
1755 int stride_bytes_reg
, int stride_bytes_chan
)
1757 struct tgsi_full_dst_register reg
;
1758 ubyte
*name
, *index
, *array_first
;
1761 struct tgsi_shader_info
*info
= &ctx
->info
;
1762 /* Set the register description. The address computation is the same
1763 * for sources and destinations. */
1765 reg
.Register
.File
= src
->Register
.File
;
1766 reg
.Register
.Index
= src
->Register
.Index
;
1767 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1768 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1769 reg
.Indirect
= src
->Indirect
;
1770 reg
.Dimension
= src
->Dimension
;
1771 reg
.DimIndirect
= src
->DimIndirect
;
1775 /* If the register is 2-dimensional (e.g. an array of vertices
1776 * in a primitive), calculate the base address of the vertex. */
1777 if (reg
.Register
.Dimension
) {
1779 if (reg
.Dimension
.Indirect
) {
1781 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1783 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1784 /* pull the value from index_reg */
1788 sel
= V_SQ_ALU_SRC_LITERAL
;
1789 chan
= reg
.Dimension
.Index
;
1792 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1794 stride_bytes_reg
, stride_bytes_chan
,
1801 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1802 name
= info
->input_semantic_name
;
1803 index
= info
->input_semantic_index
;
1804 array_first
= info
->input_array_first
;
1805 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1806 name
= info
->output_semantic_name
;
1807 index
= info
->output_semantic_index
;
1808 array_first
= info
->output_array_first
;
1813 if (reg
.Register
.Indirect
) {
1816 /* Add the relative address of the element. */
1817 if (reg
.Indirect
.ArrayID
)
1818 first
= array_first
[reg
.Indirect
.ArrayID
];
1820 first
= reg
.Register
.Index
;
1822 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1824 /* pull the value from index_reg */
1825 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1827 V_SQ_ALU_SRC_LITERAL
, 16,
1833 param
= r600_get_lds_unique_index(name
[first
],
1837 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1838 index
[reg
.Register
.Index
]);
1841 /* add to base_addr - passed in temp_reg.x */
1843 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1846 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1854 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1855 unsigned dst_reg
, unsigned mask
)
1857 struct r600_bytecode_alu alu
;
1860 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1861 ctx
->bc
->force_add_cf
= 1;
1863 lasti
= tgsi_last_instruction(mask
);
1864 for (i
= 1; i
<= lasti
; i
++) {
1865 if (!(mask
& (1 << i
)))
1868 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1871 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1875 for (i
= 0; i
<= lasti
; i
++) {
1876 if (!(mask
& (1 << i
)))
1879 /* emit an LDS_READ_RET */
1880 memset(&alu
, 0, sizeof(alu
));
1881 alu
.op
= LDS_OP1_LDS_READ_RET
;
1882 alu
.src
[0].sel
= temp_reg
;
1883 alu
.src
[0].chan
= i
;
1884 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1885 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1887 alu
.is_lds_idx_op
= true;
1889 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1893 for (i
= 0; i
<= lasti
; i
++) {
1894 if (!(mask
& (1 << i
)))
1897 /* then read from LDS_OQ_A_POP */
1898 memset(&alu
, 0, sizeof(alu
));
1900 alu
.op
= ALU_OP1_MOV
;
1901 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1902 alu
.src
[0].chan
= 0;
1903 alu
.dst
.sel
= dst_reg
;
1907 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1914 static int fetch_mask(struct tgsi_src_register
*reg
)
1917 mask
|= 1 << reg
->SwizzleX
;
1918 mask
|= 1 << reg
->SwizzleY
;
1919 mask
|= 1 << reg
->SwizzleZ
;
1920 mask
|= 1 << reg
->SwizzleW
;
1924 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1927 unsigned temp_reg
= r600_get_temp(ctx
);
1929 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1930 src
->Register
.Dimension
? false : true);
1934 /* the base address is now in temp.x */
1935 r
= r600_get_byte_address(ctx
, temp_reg
,
1936 NULL
, src
, ctx
->tess_output_info
, 1);
1940 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1946 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1949 unsigned temp_reg
= r600_get_temp(ctx
);
1951 /* t.x = ips * r0.y */
1952 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1954 ctx
->tess_input_info
, 0,
1960 /* the base address is now in temp.x */
1961 r
= r600_get_byte_address(ctx
, temp_reg
,
1962 NULL
, src
, ctx
->tess_input_info
, 1);
1966 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1972 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1975 unsigned temp_reg
= r600_get_temp(ctx
);
1977 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1978 src
->Register
.Dimension
? false : true);
1981 /* the base address is now in temp.x */
1982 r
= r600_get_byte_address(ctx
, temp_reg
,
1984 ctx
->tess_output_info
, 1);
1988 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1994 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1996 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1999 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2000 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
2002 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2003 int treg
= r600_get_temp(ctx
);
2004 fetch_tes_input(ctx
, src
, treg
);
2005 ctx
->src
[i
].sel
= treg
;
2006 ctx
->src
[i
].rel
= 0;
2008 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2009 int treg
= r600_get_temp(ctx
);
2010 fetch_tcs_input(ctx
, src
, treg
);
2011 ctx
->src
[i
].sel
= treg
;
2012 ctx
->src
[i
].rel
= 0;
2014 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
2015 int treg
= r600_get_temp(ctx
);
2016 fetch_tcs_output(ctx
, src
, treg
);
2017 ctx
->src
[i
].sel
= treg
;
2018 ctx
->src
[i
].rel
= 0;
2024 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
2026 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2027 struct r600_bytecode_alu alu
;
2028 int i
, j
, k
, nconst
, r
;
2030 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2031 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
2034 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
2036 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2037 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
2041 if (ctx
->src
[i
].rel
) {
2042 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
2043 int treg
= r600_get_temp(ctx
);
2044 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
2047 ctx
->src
[i
].kc_bank
= 0;
2048 ctx
->src
[i
].kc_rel
= 0;
2049 ctx
->src
[i
].sel
= treg
;
2050 ctx
->src
[i
].rel
= 0;
2053 int treg
= r600_get_temp(ctx
);
2054 for (k
= 0; k
< 4; k
++) {
2055 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2056 alu
.op
= ALU_OP1_MOV
;
2057 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2058 alu
.src
[0].chan
= k
;
2059 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
2060 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
2061 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
2067 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2071 ctx
->src
[i
].sel
= treg
;
2079 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
2080 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
2082 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2083 struct r600_bytecode_alu alu
;
2084 int i
, j
, k
, nliteral
, r
;
2086 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2087 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2091 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2092 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2093 int treg
= r600_get_temp(ctx
);
2094 for (k
= 0; k
< 4; k
++) {
2095 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2096 alu
.op
= ALU_OP1_MOV
;
2097 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2098 alu
.src
[0].chan
= k
;
2099 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2105 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2109 ctx
->src
[i
].sel
= treg
;
2116 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2118 int i
, r
, count
= ctx
->shader
->ninput
;
2120 for (i
= 0; i
< count
; i
++) {
2121 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2122 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2130 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2131 int stream
, unsigned *stream_item_size UNUSED
)
2133 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2134 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2138 /* Sanity checking. */
2139 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2140 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2144 for (i
= 0; i
< so
->num_outputs
; i
++) {
2145 if (so
->output
[i
].output_buffer
>= 4) {
2146 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2147 so
->output
[i
].output_buffer
);
2153 /* Initialize locations where the outputs are stored. */
2154 for (i
= 0; i
< so
->num_outputs
; i
++) {
2156 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2157 start_comp
[i
] = so
->output
[i
].start_component
;
2158 /* Lower outputs with dst_offset < start_component.
2160 * We can only output 4D vectors with a write mask, e.g. we can
2161 * only output the W component at offset 3, etc. If we want
2162 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2163 * to move it to X and output X. */
2164 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2165 unsigned tmp
= r600_get_temp(ctx
);
2167 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2168 struct r600_bytecode_alu alu
;
2169 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2170 alu
.op
= ALU_OP1_MOV
;
2171 alu
.src
[0].sel
= so_gpr
[i
];
2172 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2177 if (j
== so
->output
[i
].num_components
- 1)
2179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2188 /* Write outputs to buffers. */
2189 for (i
= 0; i
< so
->num_outputs
; i
++) {
2190 struct r600_bytecode_output output
;
2192 if (stream
!= -1 && stream
!= so
->output
[i
].stream
)
2195 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2196 output
.gpr
= so_gpr
[i
];
2197 output
.elem_size
= so
->output
[i
].num_components
- 1;
2198 if (output
.elem_size
== 2)
2199 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2200 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2201 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2202 output
.burst_count
= 1;
2203 /* array_size is an upper limit for the burst_count
2204 * with MEM_STREAM instructions */
2205 output
.array_size
= 0xFFF;
2206 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2208 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2209 switch (so
->output
[i
].output_buffer
) {
2211 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2214 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2217 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2220 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2223 output
.op
+= so
->output
[i
].stream
* 4;
2224 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2225 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2227 switch (so
->output
[i
].output_buffer
) {
2229 output
.op
= CF_OP_MEM_STREAM0
;
2232 output
.op
= CF_OP_MEM_STREAM1
;
2235 output
.op
= CF_OP_MEM_STREAM2
;
2238 output
.op
= CF_OP_MEM_STREAM3
;
2241 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2243 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2252 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2254 struct r600_bytecode_alu alu
;
2257 if (!ctx
->shader
->vs_out_edgeflag
)
2260 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2262 /* clamp(x, 0, 1) */
2263 memset(&alu
, 0, sizeof(alu
));
2264 alu
.op
= ALU_OP1_MOV
;
2265 alu
.src
[0].sel
= reg
;
2270 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2272 memset(&alu
, 0, sizeof(alu
));
2273 alu
.op
= ALU_OP1_FLT_TO_INT
;
2274 alu
.src
[0].sel
= reg
;
2278 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2281 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2282 struct r600_pipe_shader
*gs
,
2283 struct pipe_stream_output_info
*so
)
2285 struct r600_shader_ctx ctx
= {};
2286 struct r600_shader
*gs_shader
= &gs
->shader
;
2287 struct r600_pipe_shader
*cshader
;
2288 unsigned ocnt
= gs_shader
->noutput
;
2289 struct r600_bytecode_alu alu
;
2290 struct r600_bytecode_vtx vtx
;
2291 struct r600_bytecode_output output
;
2292 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2293 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2294 int next_clip_pos
= 61, next_param
= 0;
2297 bool only_ring_0
= true;
2298 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2302 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2303 sizeof(struct r600_shader_io
));
2305 cshader
->shader
.noutput
= ocnt
;
2307 ctx
.shader
= &cshader
->shader
;
2308 ctx
.bc
= &ctx
.shader
->bc
;
2309 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2311 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2312 rctx
->screen
->has_compressed_msaa_texturing
);
2314 ctx
.bc
->isa
= rctx
->isa
;
2317 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2319 /* R0.x = R0.x & 0x3fffffff */
2320 memset(&alu
, 0, sizeof(alu
));
2321 alu
.op
= ALU_OP2_AND_INT
;
2322 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2323 alu
.src
[1].value
= 0x3fffffff;
2325 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2327 /* R0.y = R0.x >> 30 */
2328 memset(&alu
, 0, sizeof(alu
));
2329 alu
.op
= ALU_OP2_LSHR_INT
;
2330 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2331 alu
.src
[1].value
= 0x1e;
2335 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2337 /* fetch vertex data from GSVS ring */
2338 for (i
= 0; i
< ocnt
; ++i
) {
2339 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2342 out
->ring_offset
= i
* 16;
2344 memset(&vtx
, 0, sizeof(vtx
));
2345 vtx
.op
= FETCH_OP_VFETCH
;
2346 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2347 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2348 vtx
.mega_fetch_count
= 16;
2349 vtx
.offset
= out
->ring_offset
;
2350 vtx
.dst_gpr
= out
->gpr
;
2356 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2357 vtx
.use_const_fields
= 1;
2359 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2362 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2364 ctx
.temp_reg
= i
+ 1;
2365 for (ring
= 3; ring
>= 0; --ring
) {
2366 bool enabled
= false;
2367 for (i
= 0; i
< so
->num_outputs
; i
++) {
2368 if (so
->output
[i
].stream
== ring
) {
2371 only_ring_0
= false;
2375 if (ring
!= 0 && !enabled
) {
2376 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2381 // Patch up jump label
2382 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2383 cf_pop
= ctx
.bc
->cf_last
;
2385 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2386 cf_jump
->pop_count
= 1;
2387 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2388 cf_pop
->pop_count
= 1;
2391 /* PRED_SETE_INT __, R0.y, ring */
2392 memset(&alu
, 0, sizeof(alu
));
2393 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2394 alu
.src
[0].chan
= 1;
2395 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2396 alu
.src
[1].value
= ring
;
2397 alu
.execute_mask
= 1;
2398 alu
.update_pred
= 1;
2400 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2402 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2403 cf_jump
= ctx
.bc
->cf_last
;
2406 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2407 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2410 /* bc adds nops - copy it */
2411 if (ctx
.bc
->chip_class
== R600
) {
2412 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2413 alu
.op
= ALU_OP0_NOP
;
2415 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2417 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2420 /* export vertex data */
2421 /* XXX factor out common code with r600_shader_from_tgsi ? */
2422 for (i
= 0; i
< ocnt
; ++i
) {
2423 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2424 bool instream0
= true;
2425 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2428 for (j
= 0; j
< so
->num_outputs
; j
++) {
2429 if (so
->output
[j
].register_index
== i
) {
2430 if (so
->output
[j
].stream
== 0)
2432 if (so
->output
[j
].stream
> 0)
2438 memset(&output
, 0, sizeof(output
));
2439 output
.gpr
= out
->gpr
;
2440 output
.elem_size
= 3;
2441 output
.swizzle_x
= 0;
2442 output
.swizzle_y
= 1;
2443 output
.swizzle_z
= 2;
2444 output
.swizzle_w
= 3;
2445 output
.burst_count
= 1;
2446 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2447 output
.op
= CF_OP_EXPORT
;
2448 switch (out
->name
) {
2449 case TGSI_SEMANTIC_POSITION
:
2450 output
.array_base
= 60;
2451 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2454 case TGSI_SEMANTIC_PSIZE
:
2455 output
.array_base
= 61;
2456 if (next_clip_pos
== 61)
2458 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2459 output
.swizzle_y
= 7;
2460 output
.swizzle_z
= 7;
2461 output
.swizzle_w
= 7;
2462 ctx
.shader
->vs_out_misc_write
= 1;
2463 ctx
.shader
->vs_out_point_size
= 1;
2465 case TGSI_SEMANTIC_LAYER
:
2467 /* duplicate it as PARAM to pass to the pixel shader */
2468 output
.array_base
= next_param
++;
2469 r600_bytecode_add_output(ctx
.bc
, &output
);
2470 last_exp_param
= ctx
.bc
->cf_last
;
2472 output
.array_base
= 61;
2473 if (next_clip_pos
== 61)
2475 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2476 output
.swizzle_x
= 7;
2477 output
.swizzle_y
= 7;
2478 output
.swizzle_z
= 0;
2479 output
.swizzle_w
= 7;
2480 ctx
.shader
->vs_out_misc_write
= 1;
2481 ctx
.shader
->vs_out_layer
= 1;
2483 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2485 /* duplicate it as PARAM to pass to the pixel shader */
2486 output
.array_base
= next_param
++;
2487 r600_bytecode_add_output(ctx
.bc
, &output
);
2488 last_exp_param
= ctx
.bc
->cf_last
;
2490 output
.array_base
= 61;
2491 if (next_clip_pos
== 61)
2493 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2494 ctx
.shader
->vs_out_misc_write
= 1;
2495 ctx
.shader
->vs_out_viewport
= 1;
2496 output
.swizzle_x
= 7;
2497 output
.swizzle_y
= 7;
2498 output
.swizzle_z
= 7;
2499 output
.swizzle_w
= 0;
2501 case TGSI_SEMANTIC_CLIPDIST
:
2502 /* spi_sid is 0 for clipdistance outputs that were generated
2503 * for clipvertex - we don't need to pass them to PS */
2504 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2505 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2506 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2508 /* duplicate it as PARAM to pass to the pixel shader */
2509 output
.array_base
= next_param
++;
2510 r600_bytecode_add_output(ctx
.bc
, &output
);
2511 last_exp_param
= ctx
.bc
->cf_last
;
2513 output
.array_base
= next_clip_pos
++;
2514 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2516 case TGSI_SEMANTIC_FOG
:
2517 output
.swizzle_y
= 4; /* 0 */
2518 output
.swizzle_z
= 4; /* 0 */
2519 output
.swizzle_w
= 5; /* 1 */
2522 output
.array_base
= next_param
++;
2525 r600_bytecode_add_output(ctx
.bc
, &output
);
2526 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2527 last_exp_param
= ctx
.bc
->cf_last
;
2529 last_exp_pos
= ctx
.bc
->cf_last
;
2532 if (!last_exp_pos
) {
2533 memset(&output
, 0, sizeof(output
));
2535 output
.elem_size
= 3;
2536 output
.swizzle_x
= 7;
2537 output
.swizzle_y
= 7;
2538 output
.swizzle_z
= 7;
2539 output
.swizzle_w
= 7;
2540 output
.burst_count
= 1;
2542 output
.op
= CF_OP_EXPORT
;
2543 output
.array_base
= 60;
2544 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2545 r600_bytecode_add_output(ctx
.bc
, &output
);
2546 last_exp_pos
= ctx
.bc
->cf_last
;
2549 if (!last_exp_param
) {
2550 memset(&output
, 0, sizeof(output
));
2552 output
.elem_size
= 3;
2553 output
.swizzle_x
= 7;
2554 output
.swizzle_y
= 7;
2555 output
.swizzle_z
= 7;
2556 output
.swizzle_w
= 7;
2557 output
.burst_count
= 1;
2559 output
.op
= CF_OP_EXPORT
;
2560 output
.array_base
= next_param
++;
2561 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2562 r600_bytecode_add_output(ctx
.bc
, &output
);
2563 last_exp_param
= ctx
.bc
->cf_last
;
2566 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2567 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2569 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2570 cf_pop
= ctx
.bc
->cf_last
;
2572 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2573 cf_jump
->pop_count
= 1;
2574 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2575 cf_pop
->pop_count
= 1;
2577 if (ctx
.bc
->chip_class
== CAYMAN
)
2578 cm_bytecode_add_cf_end(ctx
.bc
);
2580 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2581 ctx
.bc
->cf_last
->end_of_program
= 1;
2584 gs
->gs_copy_shader
= cshader
;
2585 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2589 return r600_bytecode_build(ctx
.bc
);
2592 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2595 struct r600_bytecode_alu alu
;
2598 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2599 alu
.op
= ALU_OP2_ADD_INT
;
2600 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2601 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2602 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2603 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2606 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2613 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2615 struct r600_bytecode_output output
;
2618 int effective_stream
= stream
== -1 ? 0 : stream
;
2621 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2622 if (ctx
->gs_for_vs
) {
2623 /* for ES we need to lookup corresponding ring offset expected by GS
2624 * (map this output to GS input by name and sid) */
2625 /* FIXME precompute offsets */
2627 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2628 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2629 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2630 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2631 ring_offset
= in
->ring_offset
;
2634 if (ring_offset
== -1)
2637 ring_offset
= idx
* 16;
2641 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2643 /* next_ring_offset after parsing input decls contains total size of
2644 * single vertex data, gs_next_vertex - current vertex index */
2646 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2648 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2649 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2650 output
.elem_size
= 3;
2651 output
.comp_mask
= 0xF;
2652 output
.burst_count
= 1;
2655 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2657 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2662 output
.op
= CF_OP_MEM_RING
; break;
2664 output
.op
= CF_OP_MEM_RING1
; break;
2666 output
.op
= CF_OP_MEM_RING2
; break;
2668 output
.op
= CF_OP_MEM_RING3
; break;
2672 output
.array_base
= ring_offset
>> 2; /* in dwords */
2673 output
.array_size
= 0xfff;
2674 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2676 output
.array_base
= ring_offset
>> 2; /* in dwords */
2677 r600_bytecode_add_output(ctx
->bc
, &output
);
2680 ++ctx
->gs_next_vertex
;
2685 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2688 struct r600_bytecode_vtx vtx
;
2689 int temp_val
= ctx
->temp_reg
;
2690 /* need to store the TCS output somewhere */
2691 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2693 V_SQ_ALU_SRC_LITERAL
, 0,
2698 /* used by VS/TCS */
2699 if (ctx
->tess_input_info
) {
2700 /* fetch tcs input values into resv space */
2701 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2702 vtx
.op
= FETCH_OP_VFETCH
;
2703 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2704 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2705 vtx
.mega_fetch_count
= 16;
2706 vtx
.data_format
= FMT_32_32_32_32
;
2707 vtx
.num_format_all
= 2;
2708 vtx
.format_comp_all
= 1;
2709 vtx
.use_const_fields
= 0;
2710 vtx
.endian
= r600_endian_swap(32);
2711 vtx
.srf_mode_all
= 1;
2713 vtx
.dst_gpr
= ctx
->tess_input_info
;
2718 vtx
.src_gpr
= temp_val
;
2721 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2726 /* used by TCS/TES */
2727 if (ctx
->tess_output_info
) {
2728 /* fetch tcs output values into resv space */
2729 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2730 vtx
.op
= FETCH_OP_VFETCH
;
2731 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2732 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2733 vtx
.mega_fetch_count
= 16;
2734 vtx
.data_format
= FMT_32_32_32_32
;
2735 vtx
.num_format_all
= 2;
2736 vtx
.format_comp_all
= 1;
2737 vtx
.use_const_fields
= 0;
2738 vtx
.endian
= r600_endian_swap(32);
2739 vtx
.srf_mode_all
= 1;
2741 vtx
.dst_gpr
= ctx
->tess_output_info
;
2746 vtx
.src_gpr
= temp_val
;
2749 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2756 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2762 /* fetch tcs input values into input_vals */
2763 ctx
->tess_input_info
= r600_get_temp(ctx
);
2764 ctx
->tess_output_info
= 0;
2765 r
= r600_fetch_tess_io_info(ctx
);
2769 temp_reg
= r600_get_temp(ctx
);
2770 /* dst reg contains LDS address stride * idx */
2771 /* MUL vertexID, vertex_dw_stride */
2772 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2774 ctx
->tess_input_info
, 1,
2775 0, 1); /* rel id in r0.y? */
2779 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2780 struct r600_bytecode_alu alu
;
2781 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2784 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2787 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2792 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2794 temp_reg
, param
? 1 : 0,
2795 V_SQ_ALU_SRC_LITERAL
, 8);
2800 for (j
= 0; j
< 2; j
++) {
2801 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2802 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2803 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2804 alu
.src
[0].sel
= temp_reg
;
2805 alu
.src
[0].chan
= chan
;
2806 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2807 alu
.src
[1].chan
= j
* 2;
2808 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2809 alu
.src
[2].chan
= (j
* 2) + 1;
2813 alu
.is_lds_idx_op
= true;
2814 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2822 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2824 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2825 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2827 int temp_reg
= r600_get_temp(ctx
);
2828 struct r600_bytecode_alu alu
;
2829 unsigned write_mask
= dst
->Register
.WriteMask
;
2831 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2834 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2838 /* the base address is now in temp.x */
2839 r
= r600_get_byte_address(ctx
, temp_reg
,
2840 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2845 lasti
= tgsi_last_instruction(write_mask
);
2846 for (i
= 1; i
<= lasti
; i
++) {
2848 if (!(write_mask
& (1 << i
)))
2850 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2853 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2858 for (i
= 0; i
<= lasti
; i
++) {
2859 if (!(write_mask
& (1 << i
)))
2862 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2863 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2865 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2866 alu
.src
[0].sel
= temp_reg
;
2867 alu
.src
[0].chan
= i
;
2869 alu
.src
[1].sel
= dst
->Register
.Index
;
2870 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2871 alu
.src
[1].chan
= i
;
2873 alu
.src
[2].sel
= dst
->Register
.Index
;
2874 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2875 alu
.src
[2].chan
= i
+ 1;
2879 alu
.is_lds_idx_op
= true;
2880 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2886 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2887 alu
.op
= LDS_OP2_LDS_WRITE
;
2888 alu
.src
[0].sel
= temp_reg
;
2889 alu
.src
[0].chan
= i
;
2891 alu
.src
[1].sel
= dst
->Register
.Index
;
2892 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2893 alu
.src
[1].chan
= i
;
2895 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2898 alu
.is_lds_idx_op
= true;
2899 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2906 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2907 int output_idx
, int nc
)
2910 unsigned temp_reg
= r600_get_temp(ctx
);
2911 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2912 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2915 param
= r600_get_lds_unique_index(name
, 0);
2916 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2921 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2924 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2929 do_lds_fetch_values(ctx
, temp_reg
, dreg
, ((1u << nc
) - 1));
2933 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2935 int stride
, outer_comps
, inner_comps
;
2936 int tessinner_idx
= -1, tessouter_idx
= -1;
2939 int temp_reg
= r600_get_temp(ctx
);
2940 int treg
[3] = {-1, -1, -1};
2941 struct r600_bytecode_alu alu
;
2942 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2944 /* only execute factor emission for invocation 0 */
2945 /* PRED_SETE_INT __, R0.x, 0 */
2946 memset(&alu
, 0, sizeof(alu
));
2947 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2948 alu
.src
[0].chan
= 2;
2949 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2950 alu
.execute_mask
= 1;
2951 alu
.update_pred
= 1;
2953 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2955 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2956 cf_jump
= ctx
->bc
->cf_last
;
2958 treg
[0] = r600_get_temp(ctx
);
2959 switch (ctx
->shader
->tcs_prim_mode
) {
2960 case PIPE_PRIM_LINES
:
2961 stride
= 8; /* 2 dwords, 1 vec2 store */
2965 case PIPE_PRIM_TRIANGLES
:
2966 stride
= 16; /* 4 dwords, 1 vec4 store */
2969 treg
[1] = r600_get_temp(ctx
);
2971 case PIPE_PRIM_QUADS
:
2972 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2975 treg
[1] = r600_get_temp(ctx
);
2976 treg
[2] = r600_get_temp(ctx
);
2983 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2984 /* TF_WRITE takes index in R.x, value in R.y */
2985 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
2986 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
2988 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
2992 if (tessouter_idx
== -1)
2995 if (tessinner_idx
== -1 && inner_comps
)
2998 if (tessouter_idx
!= -1) {
2999 r
= r600_tess_factor_read(ctx
, tessouter_idx
, outer_comps
);
3004 if (tessinner_idx
!= -1) {
3005 r
= r600_tess_factor_read(ctx
, tessinner_idx
, inner_comps
);
3010 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
3011 /* r.x = relpatchid(r0.y) * tf_stride */
3013 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
3014 /* add incoming r0.w to it: t.x = t.x + r0.w */
3015 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3018 V_SQ_ALU_SRC_LITERAL
, stride
,
3023 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3024 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
3025 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
3027 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
3030 else if (out_comp
== 0)
3034 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3035 treg
[i
/ 2], (2 * (i
% 2)),
3037 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3040 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
3041 treg
[i
/ 2], 1 + (2 * (i
%2)),
3042 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
3047 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3048 struct r600_bytecode_gds gds
;
3050 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
3051 gds
.src_gpr
= treg
[i
/ 2];
3052 gds
.src_sel_x
= 2 * (i
% 2);
3053 gds
.src_sel_y
= 1 + (2 * (i
% 2));
3059 gds
.op
= FETCH_OP_TF_WRITE
;
3060 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
3065 // Patch up jump label
3066 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
3067 cf_pop
= ctx
->bc
->cf_last
;
3069 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
3070 cf_jump
->pop_count
= 1;
3071 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
3072 cf_pop
->pop_count
= 1;
3078 * We have to work out the thread ID for load and atomic
3079 * operations, which store the returned value to an index
3080 * in an intermediate buffer.
3081 * The index is calculated by taking the thread id,
3082 * calculated from the MBCNT instructions.
3083 * Then the shader engine ID is multiplied by 256,
3084 * and the wave id is added.
3085 * Then the result is multipled by 64 and thread id is
3088 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
3090 struct r600_bytecode_alu alu
;
3093 if (ctx
->thread_id_gpr_loaded
)
3096 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3097 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
3098 alu
.dst
.sel
= ctx
->temp_reg
;
3100 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3101 alu
.src
[0].value
= 0xffffffff;
3103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3107 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3108 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3109 alu
.dst
.sel
= ctx
->temp_reg
;
3111 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3112 alu
.src
[0].value
= 0xffffffff;
3114 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3118 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3119 alu
.op
= ALU_OP3_MULADD_UINT24
;
3120 alu
.dst
.sel
= ctx
->temp_reg
;
3122 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3123 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3124 alu
.src
[1].value
= 256;
3125 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3133 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3134 ctx
->thread_id_gpr
, 1,
3136 V_SQ_ALU_SRC_LITERAL
, 0x40,
3140 ctx
->thread_id_gpr_loaded
= true;
3144 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3145 struct r600_pipe_shader
*pipeshader
,
3146 union r600_shader_key key
)
3148 struct r600_screen
*rscreen
= rctx
->screen
;
3149 struct r600_shader
*shader
= &pipeshader
->shader
;
3150 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3151 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3152 struct tgsi_full_immediate
*immediate
;
3153 struct r600_shader_ctx ctx
;
3154 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3155 unsigned output_done
, noutput
;
3159 int next_param_base
= 0, next_clip_base
;
3160 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3162 bool ring_outputs
= false;
3163 bool lds_outputs
= false;
3164 bool lds_inputs
= false;
3165 bool pos_emitted
= false;
3167 ctx
.bc
= &shader
->bc
;
3168 ctx
.shader
= shader
;
3170 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3171 rscreen
->has_compressed_msaa_texturing
);
3172 ctx
.tokens
= tokens
;
3173 tgsi_scan_shader(tokens
, &ctx
.info
);
3174 shader
->indirect_files
= ctx
.info
.indirect_files
;
3176 shader
->uses_helper_invocation
= false;
3177 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3178 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3179 shader
->nsys_inputs
= 0;
3181 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3182 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3183 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3184 tgsi_parse_init(&ctx
.parse
, tokens
);
3185 ctx
.type
= ctx
.info
.processor
;
3186 shader
->processor_type
= ctx
.type
;
3187 ctx
.bc
->type
= shader
->processor_type
;
3190 case PIPE_SHADER_VERTEX
:
3191 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3192 shader
->vs_as_es
= key
.vs
.as_es
;
3193 shader
->vs_as_ls
= key
.vs
.as_ls
;
3194 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3195 if (shader
->vs_as_es
)
3196 ring_outputs
= true;
3197 if (shader
->vs_as_ls
)
3200 case PIPE_SHADER_GEOMETRY
:
3201 ring_outputs
= true;
3202 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3203 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3205 case PIPE_SHADER_TESS_CTRL
:
3206 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3207 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3211 case PIPE_SHADER_TESS_EVAL
:
3212 shader
->tes_as_es
= key
.tes
.as_es
;
3213 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3215 if (shader
->tes_as_es
)
3216 ring_outputs
= true;
3218 case PIPE_SHADER_FRAGMENT
:
3219 shader
->two_side
= key
.ps
.color_two_side
;
3220 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3221 shader
->rat_base
= key
.ps
.nr_cbufs
;
3222 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3224 case PIPE_SHADER_COMPUTE
:
3225 shader
->rat_base
= 0;
3226 shader
->image_size_const_offset
= ctx
.info
.file_count
[TGSI_FILE_SAMPLER
];
3232 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3233 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3235 ctx
.gs_for_vs
= NULL
;
3238 ctx
.next_ring_offset
= 0;
3239 ctx
.gs_out_ring_offset
= 0;
3240 ctx
.gs_next_vertex
= 0;
3241 ctx
.gs_stream_output_info
= &so
;
3244 ctx
.fixed_pt_position_gpr
= -1;
3245 ctx
.fragcoord_input
= -1;
3246 ctx
.colors_used
= 0;
3247 ctx
.clip_vertex_write
= 0;
3248 ctx
.thread_id_gpr_loaded
= false;
3250 ctx
.helper_invoc_reg
= -1;
3251 ctx
.cs_block_size_reg
= -1;
3252 ctx
.cs_grid_size_reg
= -1;
3253 ctx
.cs_block_size_loaded
= false;
3254 ctx
.cs_grid_size_loaded
= false;
3256 shader
->nr_ps_color_exports
= 0;
3257 shader
->nr_ps_max_color_exports
= 0;
3260 /* register allocations */
3261 /* Values [0,127] correspond to GPR[0..127].
3262 * Values [128,159] correspond to constant buffer bank 0
3263 * Values [160,191] correspond to constant buffer bank 1
3264 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3265 * Values [256,287] correspond to constant buffer bank 2 (EG)
3266 * Values [288,319] correspond to constant buffer bank 3 (EG)
3267 * Other special values are shown in the list below.
3268 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3269 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3270 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3271 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3272 * 248 SQ_ALU_SRC_0: special constant 0.0.
3273 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3274 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3275 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3276 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3277 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3278 * 254 SQ_ALU_SRC_PV: previous vector result.
3279 * 255 SQ_ALU_SRC_PS: previous scalar result.
3281 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3282 ctx
.file_offset
[i
] = 0;
3285 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3287 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3288 if (ctx
.info
.num_inputs
)
3289 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3291 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3292 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3293 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3295 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3297 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3298 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
3299 ctx
.helper_invoc_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3300 shader
->uses_helper_invocation
= true;
3304 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3305 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3306 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3308 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3309 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3310 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3311 bool add_tesscoord
= false, add_tess_inout
= false;
3312 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3313 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3314 /* if we have tesscoord save one reg */
3315 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3316 add_tesscoord
= true;
3317 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3318 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3319 add_tess_inout
= true;
3321 if (add_tesscoord
|| add_tess_inout
)
3322 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3324 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3326 if (ctx
.type
== PIPE_SHADER_COMPUTE
) {
3327 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3328 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3329 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_GRID_SIZE
)
3330 ctx
.cs_grid_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3331 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_BLOCK_SIZE
)
3332 ctx
.cs_block_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3336 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3337 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3338 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3339 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3340 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3342 /* Outside the GPR range. This will be translated to one of the
3343 * kcache banks later. */
3344 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3346 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3348 int regno
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3349 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
];
3350 ctx
.bc
->ar_reg
= ++regno
;
3351 ctx
.bc
->index_reg
[0] = ++regno
;
3352 ctx
.bc
->index_reg
[1] = ++regno
;
3354 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3355 ctx
.tess_input_info
= ++regno
;
3356 ctx
.tess_output_info
= ++regno
;
3357 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3358 ctx
.tess_input_info
= 0;
3359 ctx
.tess_output_info
= ++regno
;
3360 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3361 ctx
.gs_export_gpr_tregs
[0] = ++regno
;
3362 ctx
.gs_export_gpr_tregs
[1] = ++regno
;
3363 ctx
.gs_export_gpr_tregs
[2] = ++regno
;
3364 ctx
.gs_export_gpr_tregs
[3] = ++regno
;
3365 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3366 ctx
.gs_rotated_input
[0] = ++regno
;
3367 ctx
.gs_rotated_input
[1] = ++regno
;
3369 ctx
.gs_rotated_input
[0] = 0;
3370 ctx
.gs_rotated_input
[1] = 1;
3374 if (shader
->uses_images
) {
3375 ctx
.thread_id_gpr
= ++regno
;
3376 ctx
.thread_id_gpr_loaded
= false;
3378 ctx
.temp_reg
= ++regno
;
3380 shader
->max_arrays
= 0;
3381 shader
->num_arrays
= 0;
3382 if (indirect_gprs
) {
3384 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3385 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3386 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3387 ctx
.file_offset
[TGSI_FILE_INPUT
],
3390 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3391 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3392 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3393 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3399 ctx
.literals
= NULL
;
3400 ctx
.max_driver_temp_used
= 0;
3402 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3403 ctx
.info
.colors_written
== 1;
3404 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3405 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3407 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3408 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3409 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3410 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3411 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3412 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3413 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3416 if (shader
->vs_as_gs_a
)
3417 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3419 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3420 r600_fetch_tess_io_info(&ctx
);
3422 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3423 tgsi_parse_token(&ctx
.parse
);
3424 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3425 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3426 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3427 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3428 if(ctx
.literals
== NULL
) {
3432 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3433 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3434 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3435 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3438 case TGSI_TOKEN_TYPE_DECLARATION
:
3439 r
= tgsi_declaration(&ctx
);
3443 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3444 case TGSI_TOKEN_TYPE_PROPERTY
:
3447 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3453 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3454 shader
->ring_item_sizes
[1] = 0;
3455 shader
->ring_item_sizes
[2] = 0;
3456 shader
->ring_item_sizes
[3] = 0;
3458 /* Process two side if needed */
3459 if (shader
->two_side
&& ctx
.colors_used
) {
3460 int i
, count
= ctx
.shader
->ninput
;
3461 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3463 /* additional inputs will be allocated right after the existing inputs,
3464 * we won't need them after the color selection, so we don't need to
3465 * reserve these gprs for the rest of the shader code and to adjust
3466 * output offsets etc. */
3467 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3468 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3470 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3471 if (ctx
.face_gpr
== -1) {
3472 i
= ctx
.shader
->ninput
++;
3473 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3474 ctx
.shader
->input
[i
].spi_sid
= 0;
3475 ctx
.shader
->input
[i
].gpr
= gpr
++;
3476 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3479 for (i
= 0; i
< count
; i
++) {
3480 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3481 int ni
= ctx
.shader
->ninput
++;
3482 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3483 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3484 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3485 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3486 // TGSI to LLVM needs to know the lds position of inputs.
3487 // Non LLVM path computes it later (in process_twoside_color)
3488 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3489 ctx
.shader
->input
[i
].back_color_input
= ni
;
3490 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3491 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3498 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3499 shader
->nr_ps_max_color_exports
= 8;
3501 if (ctx
.shader
->uses_helper_invocation
) {
3502 if (ctx
.bc
->chip_class
== CAYMAN
)
3503 r
= cm_load_helper_invocation(&ctx
);
3505 r
= eg_load_helper_invocation(&ctx
);
3511 * XXX this relies on fixed_pt_position_gpr only being present when
3512 * this shader should be executed per sample. Should be the case for now...
3514 if (ctx
.fixed_pt_position_gpr
!= -1 && ctx
.info
.reads_samplemask
) {
3516 * Fix up sample mask. The hw always gives us coverage mask for
3517 * the pixel. However, for per-sample shading, we need the
3518 * coverage for the shader invocation only.
3519 * Also, with disabled msaa, only the first bit should be set
3520 * (luckily the same fixup works for both problems).
3521 * For now, we can only do it if we know this shader is always
3522 * executed per sample (due to usage of bits in the shader
3523 * forcing per-sample execution).
3524 * If the fb is not multisampled, we'd do unnecessary work but
3525 * it should still be correct.
3526 * It will however do nothing for sample shading according
3527 * to MinSampleShading.
3529 struct r600_bytecode_alu alu
;
3530 int tmp
= r600_get_temp(&ctx
);
3531 assert(ctx
.face_gpr
!= -1);
3532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3534 alu
.op
= ALU_OP2_LSHL_INT
;
3535 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3536 alu
.src
[0].value
= 0x1;
3537 alu
.src
[1].sel
= ctx
.fixed_pt_position_gpr
;
3538 alu
.src
[1].chan
= 3;
3543 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3546 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3547 alu
.op
= ALU_OP2_AND_INT
;
3548 alu
.src
[0].sel
= tmp
;
3549 alu
.src
[1].sel
= ctx
.face_gpr
;
3550 alu
.src
[1].chan
= 2;
3551 alu
.dst
.sel
= ctx
.face_gpr
;
3555 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3559 if (ctx
.fragcoord_input
>= 0) {
3560 if (ctx
.bc
->chip_class
== CAYMAN
) {
3561 for (j
= 0 ; j
< 4; j
++) {
3562 struct r600_bytecode_alu alu
;
3563 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3564 alu
.op
= ALU_OP1_RECIP_IEEE
;
3565 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3566 alu
.src
[0].chan
= 3;
3568 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3570 alu
.dst
.write
= (j
== 3);
3572 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3576 struct r600_bytecode_alu alu
;
3577 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3578 alu
.op
= ALU_OP1_RECIP_IEEE
;
3579 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3580 alu
.src
[0].chan
= 3;
3582 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3586 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3591 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3592 struct r600_bytecode_alu alu
;
3595 /* GS thread with no output workaround - emit a cut at start of GS */
3596 if (ctx
.bc
->chip_class
== R600
)
3597 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3599 for (j
= 0; j
< 4; j
++) {
3600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3601 alu
.op
= ALU_OP1_MOV
;
3602 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3603 alu
.src
[0].value
= 0;
3604 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3607 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3612 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3613 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3614 ctx
.gs_rotated_input
[0], 2,
3616 V_SQ_ALU_SRC_LITERAL
, 1);
3620 for (i
= 0; i
< 6; i
++) {
3621 int rotated
= (i
+ 4) % 6;
3622 int offset_reg
= i
/ 3;
3623 int offset_chan
= i
% 3;
3624 int rotated_offset_reg
= rotated
/ 3;
3625 int rotated_offset_chan
= rotated
% 3;
3627 if (offset_reg
== 0 && offset_chan
== 2)
3629 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3630 rotated_offset_chan
= 3;
3632 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3633 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3634 ctx
.gs_rotated_input
[0], 2,
3635 offset_reg
, offset_chan
,
3636 rotated_offset_reg
, rotated_offset_chan
);
3643 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3644 r600_fetch_tess_io_info(&ctx
);
3646 if (shader
->two_side
&& ctx
.colors_used
) {
3647 if ((r
= process_twoside_color_inputs(&ctx
)))
3651 tgsi_parse_init(&ctx
.parse
, tokens
);
3652 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3653 tgsi_parse_token(&ctx
.parse
);
3654 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3655 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3656 r
= tgsi_is_supported(&ctx
);
3659 ctx
.max_driver_temp_used
= 0;
3660 /* reserve first tmp for everyone */
3661 r600_get_temp(&ctx
);
3663 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3664 if ((r
= tgsi_split_constant(&ctx
)))
3666 if ((r
= tgsi_split_literal_constant(&ctx
)))
3668 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3669 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3671 } else if (lds_inputs
) {
3672 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3675 if (ctx
.bc
->chip_class
== CAYMAN
)
3676 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3677 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3678 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3680 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3681 r
= ctx
.inst_info
->process(&ctx
);
3685 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3686 r
= r600_store_tcs_output(&ctx
);
3696 /* Reset the temporary register counter. */
3697 ctx
.max_driver_temp_used
= 0;
3699 noutput
= shader
->noutput
;
3701 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3702 unsigned clipdist_temp
[2];
3704 clipdist_temp
[0] = r600_get_temp(&ctx
);
3705 clipdist_temp
[1] = r600_get_temp(&ctx
);
3707 /* need to convert a clipvertex write into clipdistance writes and not export
3708 the clip vertex anymore */
3710 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3711 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3712 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3714 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3715 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3718 /* reset spi_sid for clipvertex output to avoid confusing spi */
3719 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3721 shader
->clip_dist_write
= 0xFF;
3722 shader
->cc_dist_mask
= 0xFF;
3724 for (i
= 0; i
< 8; i
++) {
3728 for (j
= 0; j
< 4; j
++) {
3729 struct r600_bytecode_alu alu
;
3730 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3731 alu
.op
= ALU_OP2_DOT4
;
3732 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3733 alu
.src
[0].chan
= j
;
3735 alu
.src
[1].sel
= 512 + i
;
3736 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3737 alu
.src
[1].chan
= j
;
3739 alu
.dst
.sel
= clipdist_temp
[oreg
];
3741 alu
.dst
.write
= (j
== ochan
);
3744 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3751 /* Add stream outputs. */
3752 if (so
.num_outputs
) {
3754 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3756 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3759 emit_streamout(&ctx
, &so
, -1, NULL
);
3761 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3762 convert_edgeflag_to_int(&ctx
);
3764 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3765 r600_emit_tess_factor(&ctx
);
3768 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3769 if (ctx
.shader
->noutput
)
3770 emit_lds_vs_writes(&ctx
);
3772 } else if (ring_outputs
) {
3773 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3774 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3775 ctx
.gs_export_gpr_tregs
[1] = -1;
3776 ctx
.gs_export_gpr_tregs
[2] = -1;
3777 ctx
.gs_export_gpr_tregs
[3] = -1;
3779 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3783 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3785 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3786 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3787 output
[j
].gpr
= shader
->output
[i
].gpr
;
3788 output
[j
].elem_size
= 3;
3789 output
[j
].swizzle_x
= 0;
3790 output
[j
].swizzle_y
= 1;
3791 output
[j
].swizzle_z
= 2;
3792 output
[j
].swizzle_w
= 3;
3793 output
[j
].burst_count
= 1;
3794 output
[j
].type
= 0xffffffff;
3795 output
[j
].op
= CF_OP_EXPORT
;
3797 case PIPE_SHADER_VERTEX
:
3798 case PIPE_SHADER_TESS_EVAL
:
3799 switch (shader
->output
[i
].name
) {
3800 case TGSI_SEMANTIC_POSITION
:
3801 output
[j
].array_base
= 60;
3802 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3806 case TGSI_SEMANTIC_PSIZE
:
3807 output
[j
].array_base
= 61;
3808 output
[j
].swizzle_y
= 7;
3809 output
[j
].swizzle_z
= 7;
3810 output
[j
].swizzle_w
= 7;
3811 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3814 case TGSI_SEMANTIC_EDGEFLAG
:
3815 output
[j
].array_base
= 61;
3816 output
[j
].swizzle_x
= 7;
3817 output
[j
].swizzle_y
= 0;
3818 output
[j
].swizzle_z
= 7;
3819 output
[j
].swizzle_w
= 7;
3820 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3823 case TGSI_SEMANTIC_LAYER
:
3824 /* spi_sid is 0 for outputs that are
3825 * not consumed by PS */
3826 if (shader
->output
[i
].spi_sid
) {
3827 output
[j
].array_base
= next_param_base
++;
3828 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3830 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3832 output
[j
].array_base
= 61;
3833 output
[j
].swizzle_x
= 7;
3834 output
[j
].swizzle_y
= 7;
3835 output
[j
].swizzle_z
= 0;
3836 output
[j
].swizzle_w
= 7;
3837 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3840 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3841 /* spi_sid is 0 for outputs that are
3842 * not consumed by PS */
3843 if (shader
->output
[i
].spi_sid
) {
3844 output
[j
].array_base
= next_param_base
++;
3845 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3847 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3849 output
[j
].array_base
= 61;
3850 output
[j
].swizzle_x
= 7;
3851 output
[j
].swizzle_y
= 7;
3852 output
[j
].swizzle_z
= 7;
3853 output
[j
].swizzle_w
= 0;
3854 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3857 case TGSI_SEMANTIC_CLIPVERTEX
:
3860 case TGSI_SEMANTIC_CLIPDIST
:
3861 output
[j
].array_base
= next_clip_base
++;
3862 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3864 /* spi_sid is 0 for clipdistance outputs that were generated
3865 * for clipvertex - we don't need to pass them to PS */
3866 if (shader
->output
[i
].spi_sid
) {
3868 /* duplicate it as PARAM to pass to the pixel shader */
3869 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3870 output
[j
].array_base
= next_param_base
++;
3871 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3874 case TGSI_SEMANTIC_FOG
:
3875 output
[j
].swizzle_y
= 4; /* 0 */
3876 output
[j
].swizzle_z
= 4; /* 0 */
3877 output
[j
].swizzle_w
= 5; /* 1 */
3879 case TGSI_SEMANTIC_PRIMID
:
3880 output
[j
].swizzle_x
= 2;
3881 output
[j
].swizzle_y
= 4; /* 0 */
3882 output
[j
].swizzle_z
= 4; /* 0 */
3883 output
[j
].swizzle_w
= 4; /* 0 */
3888 case PIPE_SHADER_FRAGMENT
:
3889 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3890 /* never export more colors than the number of CBs */
3891 if (shader
->output
[i
].sid
>= max_color_exports
) {
3896 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3897 output
[j
].array_base
= shader
->output
[i
].sid
;
3898 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3899 shader
->nr_ps_color_exports
++;
3900 shader
->ps_color_export_mask
|= (0xf << (shader
->output
[i
].sid
* 4));
3902 /* If the i-th target format is set, all previous target formats must
3903 * be non-zero to avoid hangs. - from radeonsi, seems to apply to eg as well.
3905 if (shader
->output
[i
].sid
> 0)
3906 for (unsigned x
= 0; x
< shader
->output
[i
].sid
; x
++)
3907 shader
->ps_color_export_mask
|= (1 << (x
*4));
3909 if (shader
->output
[i
].sid
> shader
->ps_export_highest
)
3910 shader
->ps_export_highest
= shader
->output
[i
].sid
;
3911 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3912 for (k
= 1; k
< max_color_exports
; k
++) {
3914 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3915 output
[j
].gpr
= shader
->output
[i
].gpr
;
3916 output
[j
].elem_size
= 3;
3917 output
[j
].swizzle_x
= 0;
3918 output
[j
].swizzle_y
= 1;
3919 output
[j
].swizzle_z
= 2;
3920 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3921 output
[j
].burst_count
= 1;
3922 output
[j
].array_base
= k
;
3923 output
[j
].op
= CF_OP_EXPORT
;
3924 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3925 shader
->nr_ps_color_exports
++;
3926 shader
->ps_color_export_mask
|= (0xf << (j
* 4));
3929 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3930 output
[j
].array_base
= 61;
3931 output
[j
].swizzle_x
= 2;
3932 output
[j
].swizzle_y
= 7;
3933 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3934 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3935 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3936 output
[j
].array_base
= 61;
3937 output
[j
].swizzle_x
= 7;
3938 output
[j
].swizzle_y
= 1;
3939 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3940 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3941 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3942 output
[j
].array_base
= 61;
3943 output
[j
].swizzle_x
= 7;
3944 output
[j
].swizzle_y
= 7;
3945 output
[j
].swizzle_z
= 0;
3946 output
[j
].swizzle_w
= 7;
3947 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3949 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3954 case PIPE_SHADER_TESS_CTRL
:
3957 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3962 if (output
[j
].type
== 0xffffffff) {
3963 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3964 output
[j
].array_base
= next_param_base
++;
3968 /* add fake position export */
3969 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3970 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3972 output
[j
].elem_size
= 3;
3973 output
[j
].swizzle_x
= 7;
3974 output
[j
].swizzle_y
= 7;
3975 output
[j
].swizzle_z
= 7;
3976 output
[j
].swizzle_w
= 7;
3977 output
[j
].burst_count
= 1;
3978 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3979 output
[j
].array_base
= 60;
3980 output
[j
].op
= CF_OP_EXPORT
;
3984 /* add fake param output for vertex shader if no param is exported */
3985 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3986 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3988 output
[j
].elem_size
= 3;
3989 output
[j
].swizzle_x
= 7;
3990 output
[j
].swizzle_y
= 7;
3991 output
[j
].swizzle_z
= 7;
3992 output
[j
].swizzle_w
= 7;
3993 output
[j
].burst_count
= 1;
3994 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3995 output
[j
].array_base
= 0;
3996 output
[j
].op
= CF_OP_EXPORT
;
4000 /* add fake pixel export */
4001 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
4002 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4004 output
[j
].elem_size
= 3;
4005 output
[j
].swizzle_x
= 7;
4006 output
[j
].swizzle_y
= 7;
4007 output
[j
].swizzle_z
= 7;
4008 output
[j
].swizzle_w
= 7;
4009 output
[j
].burst_count
= 1;
4010 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4011 output
[j
].array_base
= 0;
4012 output
[j
].op
= CF_OP_EXPORT
;
4014 shader
->nr_ps_color_exports
++;
4015 shader
->ps_color_export_mask
= 0xf;
4020 /* set export done on last export of each type */
4021 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
4022 if (!(output_done
& (1 << output
[k
].type
))) {
4023 output_done
|= (1 << output
[k
].type
);
4024 output
[k
].op
= CF_OP_EXPORT_DONE
;
4027 /* add output to bytecode */
4028 for (i
= 0; i
< noutput
; i
++) {
4029 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
4035 /* add program end */
4036 if (ctx
.bc
->chip_class
== CAYMAN
)
4037 cm_bytecode_add_cf_end(ctx
.bc
);
4039 const struct cf_op_info
*last
= NULL
;
4041 if (ctx
.bc
->cf_last
)
4042 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
4044 /* alu clause instructions don't have EOP bit, so add NOP */
4045 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
4046 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
4048 ctx
.bc
->cf_last
->end_of_program
= 1;
4051 /* check GPR limit - we have 124 = 128 - 4
4052 * (4 are reserved as alu clause temporary registers) */
4053 if (ctx
.bc
->ngpr
> 124) {
4054 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
4059 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
4060 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
4065 tgsi_parse_free(&ctx
.parse
);
4069 tgsi_parse_free(&ctx
.parse
);
4073 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
4075 const unsigned tgsi_opcode
=
4076 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
4077 R600_ERR("%s tgsi opcode unsupported\n",
4078 tgsi_get_opcode_name(tgsi_opcode
));
4082 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
4087 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
4088 const struct r600_shader_src
*shader_src
,
4091 bc_src
->sel
= shader_src
->sel
;
4092 bc_src
->chan
= shader_src
->swizzle
[chan
];
4093 bc_src
->neg
= shader_src
->neg
;
4094 bc_src
->abs
= shader_src
->abs
;
4095 bc_src
->rel
= shader_src
->rel
;
4096 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
4097 bc_src
->kc_bank
= shader_src
->kc_bank
;
4098 bc_src
->kc_rel
= shader_src
->kc_rel
;
4101 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
4107 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
4109 bc_src
->neg
= !bc_src
->neg
;
4112 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
4113 const struct tgsi_full_dst_register
*tgsi_dst
,
4115 struct r600_bytecode_alu_dst
*r600_dst
)
4117 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4119 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
4120 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
4121 r600_dst
->chan
= swizzle
;
4122 r600_dst
->write
= 1;
4123 if (inst
->Instruction
.Saturate
) {
4124 r600_dst
->clamp
= 1;
4126 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
4127 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
4131 if (tgsi_dst
->Register
.Indirect
)
4132 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4136 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4138 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4139 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4140 struct r600_bytecode_alu alu
;
4141 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4143 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4146 switch (write_mask
) {
4148 if (swizzle_x
== 2) {
4155 if (swizzle_x
== 2) {
4164 if (swizzle_x
== 0) {
4171 if (swizzle_x
== 0) {
4182 lasti
= tgsi_last_instruction(write_mask
);
4183 for (i
= 0; i
<= lasti
; i
++) {
4185 if (!(write_mask
& (1 << i
)))
4188 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4191 if (use_tmp
|| dest_temp
) {
4192 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4196 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4198 if (i
== 1 || i
== 3)
4201 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4203 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4204 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4205 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4207 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4208 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4211 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4212 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4215 /* handle some special cases */
4216 if (i
== 1 || i
== 3) {
4217 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4218 case TGSI_OPCODE_DABS
:
4219 r600_bytecode_src_set_abs(&alu
.src
[0]);
4228 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4234 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4236 lasti
= tgsi_last_instruction(write_mask
);
4237 /* move result from temp to dst */
4238 for (i
= 0; i
<= lasti
; i
++) {
4239 if (!(write_mask
& (1 << i
)))
4242 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4243 alu
.op
= ALU_OP1_MOV
;
4246 alu
.dst
.sel
= dest_temp
;
4250 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4251 alu
.src
[0].sel
= ctx
->temp_reg
;
4252 alu
.src
[0].chan
= use_tmp
- 1;
4253 alu
.last
= (i
== lasti
);
4255 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4263 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4265 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4266 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4267 /* confirm writemasking */
4268 if ((write_mask
& 0x3) != 0x3 &&
4269 (write_mask
& 0xc) != 0xc) {
4270 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4273 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4276 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4278 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4281 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4283 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4286 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4288 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4289 struct r600_bytecode_alu alu
;
4292 int tmp
= r600_get_temp(ctx
);
4294 for (i
= 0; i
< lasti
+ 1; i
++) {
4296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4297 alu
.op
= ctx
->inst_info
->op
;
4298 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4299 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4302 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4303 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4312 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4319 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4321 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4322 struct r600_bytecode_alu alu
;
4323 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4324 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4325 /* use temp register if trans_only and more than one dst component */
4326 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4327 unsigned op
= ctx
->inst_info
->op
;
4329 if (op
== ALU_OP2_MUL_IEEE
&&
4330 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4333 for (i
= 0; i
<= lasti
; i
++) {
4334 if (!(write_mask
& (1 << i
)))
4337 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4339 alu
.dst
.sel
= ctx
->temp_reg
;
4343 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4347 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4348 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4351 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4352 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4354 if (i
== lasti
|| trans_only
) {
4357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4363 /* move result from temp to dst */
4364 for (i
= 0; i
<= lasti
; i
++) {
4365 if (!(write_mask
& (1 << i
)))
4368 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4369 alu
.op
= ALU_OP1_MOV
;
4370 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4371 alu
.src
[0].sel
= ctx
->temp_reg
;
4372 alu
.src
[0].chan
= i
;
4373 alu
.last
= (i
== lasti
);
4375 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4383 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4385 return tgsi_op2_s(ctx
, 0, 0);
4388 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4390 return tgsi_op2_s(ctx
, 1, 0);
4393 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4395 return tgsi_op2_s(ctx
, 0, 1);
4398 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4400 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4401 struct r600_bytecode_alu alu
;
4403 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4405 for (i
= 0; i
< lasti
+ 1; i
++) {
4407 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4409 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4410 alu
.op
= ctx
->inst_info
->op
;
4412 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4414 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4416 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4421 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4429 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4431 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4432 struct r600_bytecode_alu alu
;
4434 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4436 for (i
= 0; i
< lasti
+ 1; i
++) {
4438 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4440 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4441 alu
.op
= ALU_OP1_MOV
;
4443 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4445 if (i
== 1 || i
== 3)
4446 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4447 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4460 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4462 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4463 struct r600_bytecode_alu alu
;
4464 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4467 for (i
= 0; i
<= 3; i
++) {
4468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4469 alu
.op
= ctx
->inst_info
->op
;
4471 alu
.dst
.sel
= ctx
->temp_reg
;
4474 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4475 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4481 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4486 /* Replicate significand result across channels. */
4487 for (i
= 0; i
<= 3; i
++) {
4488 if (!(write_mask
& (1 << i
)))
4491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4492 alu
.op
= ALU_OP1_MOV
;
4493 alu
.src
[0].chan
= (i
& 1) + 2;
4494 alu
.src
[0].sel
= ctx
->temp_reg
;
4496 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4499 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4504 for (i
= 0; i
<= 3; i
++) {
4505 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4506 /* MOV third channels to writemask dst1 */
4507 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4508 alu
.op
= ALU_OP1_MOV
;
4509 alu
.src
[0].chan
= 1;
4510 alu
.src
[0].sel
= ctx
->temp_reg
;
4512 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4514 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4524 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4526 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4527 struct r600_bytecode_alu alu
;
4529 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4530 int temp_reg
= r600_get_temp(ctx
);
4532 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4533 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4535 for (c
= 0; c
< 2; c
++) {
4537 if (write_mask
& (0x3 << dchan
)) {
4538 /* split into 24-bit int and 8-bit int */
4539 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4540 alu
.op
= ALU_OP2_AND_INT
;
4541 alu
.dst
.sel
= temp_reg
;
4542 alu
.dst
.chan
= dchan
;
4543 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4544 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4545 alu
.src
[1].value
= 0xffffff00;
4547 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4551 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4552 alu
.op
= ALU_OP2_AND_INT
;
4553 alu
.dst
.sel
= temp_reg
;
4554 alu
.dst
.chan
= dchan
+ 1;
4555 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4556 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4557 alu
.src
[1].value
= 0xff;
4560 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4566 for (c
= 0; c
< 2; c
++) {
4568 if (write_mask
& (0x3 << dchan
)) {
4569 for (i
= dchan
; i
<= dchan
+ 1; i
++) {
4570 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4571 alu
.op
= i
== dchan
? ctx
->inst_info
->op
: ALU_OP1_UINT_TO_FLT
;
4573 alu
.src
[0].sel
= temp_reg
;
4574 alu
.src
[0].chan
= i
;
4575 alu
.dst
.sel
= temp_reg
;
4578 if (ctx
->bc
->chip_class
== CAYMAN
)
4579 alu
.last
= i
== dchan
+ 1;
4581 alu
.last
= 1; /* trans only ops on evergreen */
4583 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4590 for (c
= 0; c
< 2; c
++) {
4592 if (write_mask
& (0x3 << dchan
)) {
4593 for (i
= 0; i
< 4; i
++) {
4594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4595 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4597 alu
.src
[0].chan
= dchan
+ (i
/ 2);
4598 if (i
== 0 || i
== 2)
4599 alu
.src
[0].sel
= temp_reg
;
4601 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4602 alu
.src
[0].value
= 0x0;
4604 alu
.dst
.sel
= ctx
->temp_reg
;
4609 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4614 for (i
= 0; i
<= 1; i
++) {
4615 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4616 alu
.op
= ALU_OP2_ADD_64
;
4618 alu
.src
[0].chan
= fp64_switch(i
);
4619 alu
.src
[0].sel
= ctx
->temp_reg
;
4621 alu
.src
[1].chan
= fp64_switch(i
+ 2);
4622 alu
.src
[1].sel
= ctx
->temp_reg
;
4623 tgsi_dst(ctx
, &inst
->Dst
[0], dchan
+ i
, &alu
.dst
);
4626 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4636 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4638 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4639 struct r600_bytecode_alu alu
;
4641 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4642 int treg
= r600_get_temp(ctx
);
4643 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4644 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4646 /* do a 64->32 into a temp register */
4647 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4651 for (i
= 0; i
<= lasti
; i
++) {
4652 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4655 alu
.op
= ctx
->inst_info
->op
;
4657 alu
.src
[0].chan
= i
;
4658 alu
.src
[0].sel
= treg
;
4659 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4660 alu
.last
= (i
== lasti
);
4662 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4670 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4673 struct r600_shader_src
*src
,
4676 struct r600_bytecode_alu alu
;
4677 const int last_slot
= 3;
4680 /* these have to write the result to X/Y by the looks of it */
4681 for (int i
= 0 ; i
< last_slot
; i
++) {
4682 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4685 r600_bytecode_src(&alu
.src
[0], src
, 1);
4686 r600_bytecode_src(&alu
.src
[1], src
, 0);
4689 r600_bytecode_src_set_abs(&alu
.src
[1]);
4691 alu
.dst
.sel
= dst_reg
;
4693 alu
.dst
.write
= (i
== 0 || i
== 1);
4695 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4697 r
= r600_bytecode_add_alu(bc
, &alu
);
4705 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4707 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4709 struct r600_bytecode_alu alu
;
4710 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4711 int t1
= ctx
->temp_reg
;
4713 /* should only be one src regs */
4714 assert(inst
->Instruction
.NumSrcRegs
== 1);
4716 /* only support one double at a time */
4717 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4718 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4720 r
= cayman_emit_unary_double_raw(
4721 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4723 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4724 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4728 for (i
= 0 ; i
<= lasti
; i
++) {
4729 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4732 alu
.op
= ALU_OP1_MOV
;
4733 alu
.src
[0].sel
= t1
;
4734 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4735 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4739 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4746 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4748 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4750 struct r600_bytecode_alu alu
;
4751 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4753 for (i
= 0 ; i
< last_slot
; i
++) {
4754 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4755 alu
.op
= ctx
->inst_info
->op
;
4756 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4757 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4759 /* RSQ should take the absolute value of src */
4760 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4761 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4764 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4765 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4767 if (i
== last_slot
- 1)
4769 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4776 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4778 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4780 struct r600_bytecode_alu alu
;
4781 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4782 int t1
= ctx
->temp_reg
;
4784 for (k
= 0; k
<= lasti
; k
++) {
4785 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4788 for (i
= 0 ; i
< 4; i
++) {
4789 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4790 alu
.op
= ctx
->inst_info
->op
;
4791 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4792 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4796 alu
.dst
.write
= (i
== k
);
4799 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4805 for (i
= 0 ; i
<= lasti
; i
++) {
4806 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4808 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4809 alu
.op
= ALU_OP1_MOV
;
4810 alu
.src
[0].sel
= t1
;
4811 alu
.src
[0].chan
= i
;
4812 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4816 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4825 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4827 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4829 struct r600_bytecode_alu alu
;
4830 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4831 int t1
= ctx
->temp_reg
;
4833 /* t1 would get overwritten below if we actually tried to
4834 * multiply two pairs of doubles at a time. */
4835 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4836 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4838 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4840 for (i
= 0; i
< 4; i
++) {
4841 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4842 alu
.op
= ctx
->inst_info
->op
;
4843 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4844 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4851 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4856 for (i
= 0; i
<= lasti
; i
++) {
4857 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4859 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4860 alu
.op
= ALU_OP1_MOV
;
4861 alu
.src
[0].sel
= t1
;
4862 alu
.src
[0].chan
= i
;
4863 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4876 * Emit RECIP_64 + MUL_64 to implement division.
4878 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4880 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4882 struct r600_bytecode_alu alu
;
4883 int t1
= ctx
->temp_reg
;
4886 /* Only support one double at a time. This is the same constraint as
4887 * in DMUL lowering. */
4888 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4889 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4891 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4893 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4897 for (int i
= 0; i
< 4; i
++) {
4898 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4899 alu
.op
= ALU_OP2_MUL_64
;
4901 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4903 alu
.src
[1].sel
= t1
;
4904 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4911 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4916 for (int i
= 0; i
< 2; i
++) {
4917 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4918 alu
.op
= ALU_OP1_MOV
;
4919 alu
.src
[0].sel
= t1
;
4920 alu
.src
[0].chan
= i
;
4921 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4925 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4933 * r600 - trunc to -PI..PI range
4934 * r700 - normalize by dividing by 2PI
4937 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4940 struct r600_bytecode_alu alu
;
4942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4943 alu
.op
= ALU_OP3_MULADD
;
4947 alu
.dst
.sel
= ctx
->temp_reg
;
4950 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4952 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4953 alu
.src
[1].chan
= 0;
4954 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4955 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4956 alu
.src
[2].chan
= 0;
4958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4962 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4963 alu
.op
= ALU_OP1_FRACT
;
4966 alu
.dst
.sel
= ctx
->temp_reg
;
4969 alu
.src
[0].sel
= ctx
->temp_reg
;
4970 alu
.src
[0].chan
= 0;
4972 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4976 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4977 alu
.op
= ALU_OP3_MULADD
;
4981 alu
.dst
.sel
= ctx
->temp_reg
;
4984 alu
.src
[0].sel
= ctx
->temp_reg
;
4985 alu
.src
[0].chan
= 0;
4987 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4988 alu
.src
[1].chan
= 0;
4989 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4990 alu
.src
[2].chan
= 0;
4992 if (ctx
->bc
->chip_class
== R600
) {
4993 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4994 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4996 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4997 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
5002 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5008 static int cayman_trig(struct r600_shader_ctx
*ctx
)
5010 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5011 struct r600_bytecode_alu alu
;
5012 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5015 r
= tgsi_setup_trig(ctx
);
5020 for (i
= 0; i
< last_slot
; i
++) {
5021 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5022 alu
.op
= ctx
->inst_info
->op
;
5025 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5026 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5028 alu
.src
[0].sel
= ctx
->temp_reg
;
5029 alu
.src
[0].chan
= 0;
5030 if (i
== last_slot
- 1)
5032 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5039 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
5041 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5042 struct r600_bytecode_alu alu
;
5044 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5046 r
= tgsi_setup_trig(ctx
);
5050 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5051 alu
.op
= ctx
->inst_info
->op
;
5053 alu
.dst
.sel
= ctx
->temp_reg
;
5056 alu
.src
[0].sel
= ctx
->temp_reg
;
5057 alu
.src
[0].chan
= 0;
5059 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5063 /* replicate result */
5064 for (i
= 0; i
< lasti
+ 1; i
++) {
5065 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5068 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5069 alu
.op
= ALU_OP1_MOV
;
5071 alu
.src
[0].sel
= ctx
->temp_reg
;
5072 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5075 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5082 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
5084 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5085 struct r600_bytecode_alu alu
;
5088 for (i
= 0; i
< 4; i
++) {
5089 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5090 alu
.op
= ctx
->inst_info
->op
;
5094 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5096 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
5097 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5100 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5105 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5110 /* kill must be last in ALU */
5111 ctx
->bc
->force_add_cf
= 1;
5112 ctx
->shader
->uses_kill
= TRUE
;
5116 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
5118 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5119 struct r600_bytecode_alu alu
;
5122 /* tmp.x = max(src.y, 0.0) */
5123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5124 alu
.op
= ALU_OP2_MAX
;
5125 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
5126 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5127 alu
.src
[1].chan
= 1;
5129 alu
.dst
.sel
= ctx
->temp_reg
;
5134 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5138 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
5144 if (ctx
->bc
->chip_class
== CAYMAN
) {
5145 for (i
= 0; i
< 3; i
++) {
5146 /* tmp.z = log(tmp.x) */
5147 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5148 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5149 alu
.src
[0].sel
= ctx
->temp_reg
;
5150 alu
.src
[0].chan
= 0;
5151 alu
.dst
.sel
= ctx
->temp_reg
;
5159 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5164 /* tmp.z = log(tmp.x) */
5165 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5166 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5167 alu
.src
[0].sel
= ctx
->temp_reg
;
5168 alu
.src
[0].chan
= 0;
5169 alu
.dst
.sel
= ctx
->temp_reg
;
5173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5178 chan
= alu
.dst
.chan
;
5181 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
5182 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5183 alu
.op
= ALU_OP3_MUL_LIT
;
5184 alu
.src
[0].sel
= sel
;
5185 alu
.src
[0].chan
= chan
;
5186 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
5187 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
5188 alu
.dst
.sel
= ctx
->temp_reg
;
5193 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5197 if (ctx
->bc
->chip_class
== CAYMAN
) {
5198 for (i
= 0; i
< 3; i
++) {
5199 /* dst.z = exp(tmp.x) */
5200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5201 alu
.op
= ALU_OP1_EXP_IEEE
;
5202 alu
.src
[0].sel
= ctx
->temp_reg
;
5203 alu
.src
[0].chan
= 0;
5204 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5210 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5215 /* dst.z = exp(tmp.x) */
5216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5217 alu
.op
= ALU_OP1_EXP_IEEE
;
5218 alu
.src
[0].sel
= ctx
->temp_reg
;
5219 alu
.src
[0].chan
= 0;
5220 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5230 alu
.op
= ALU_OP1_MOV
;
5231 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5232 alu
.src
[0].chan
= 0;
5233 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5234 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5235 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5239 /* dst.y = max(src.x, 0.0) */
5240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5241 alu
.op
= ALU_OP2_MAX
;
5242 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5243 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5244 alu
.src
[1].chan
= 0;
5245 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5246 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5247 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5253 alu
.op
= ALU_OP1_MOV
;
5254 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5255 alu
.src
[0].chan
= 0;
5256 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5257 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5259 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5266 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5268 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5269 struct r600_bytecode_alu alu
;
5272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5274 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5276 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5277 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5278 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5280 alu
.dst
.sel
= ctx
->temp_reg
;
5283 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5286 /* replicate result */
5287 return tgsi_helper_tempx_replicate(ctx
);
5290 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5292 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5293 struct r600_bytecode_alu alu
;
5296 for (i
= 0; i
< 4; i
++) {
5297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5298 alu
.src
[0].sel
= ctx
->temp_reg
;
5299 alu
.op
= ALU_OP1_MOV
;
5301 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5302 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5312 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5314 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5315 struct r600_bytecode_alu alu
;
5318 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5319 alu
.op
= ctx
->inst_info
->op
;
5320 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5321 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5323 alu
.dst
.sel
= ctx
->temp_reg
;
5326 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5329 /* replicate result */
5330 return tgsi_helper_tempx_replicate(ctx
);
5333 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5335 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5337 struct r600_bytecode_alu alu
;
5338 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5340 for (i
= 0; i
< 3; i
++) {
5341 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5342 alu
.op
= ALU_OP1_LOG_IEEE
;
5343 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5344 alu
.dst
.sel
= ctx
->temp_reg
;
5349 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5356 alu
.op
= ALU_OP2_MUL
;
5357 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5358 alu
.src
[1].sel
= ctx
->temp_reg
;
5359 alu
.dst
.sel
= ctx
->temp_reg
;
5362 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5366 for (i
= 0; i
< last_slot
; i
++) {
5367 /* POW(a,b) = EXP2(b * LOG2(a))*/
5368 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5369 alu
.op
= ALU_OP1_EXP_IEEE
;
5370 alu
.src
[0].sel
= ctx
->temp_reg
;
5372 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5373 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5374 if (i
== last_slot
- 1)
5376 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5383 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5385 struct r600_bytecode_alu alu
;
5389 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5390 alu
.op
= ALU_OP1_LOG_IEEE
;
5391 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5392 alu
.dst
.sel
= ctx
->temp_reg
;
5395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5399 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5400 alu
.op
= ALU_OP2_MUL
;
5401 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5402 alu
.src
[1].sel
= ctx
->temp_reg
;
5403 alu
.dst
.sel
= ctx
->temp_reg
;
5406 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5409 /* POW(a,b) = EXP2(b * LOG2(a))*/
5410 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5411 alu
.op
= ALU_OP1_EXP_IEEE
;
5412 alu
.src
[0].sel
= ctx
->temp_reg
;
5413 alu
.dst
.sel
= ctx
->temp_reg
;
5416 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5419 return tgsi_helper_tempx_replicate(ctx
);
5422 static int emit_mul_int_op(struct r600_bytecode
*bc
,
5423 struct r600_bytecode_alu
*alu_src
)
5425 struct r600_bytecode_alu alu
;
5428 if (bc
->chip_class
== CAYMAN
) {
5429 for (i
= 0; i
< 4; i
++) {
5431 alu
.dst
.write
= (i
== alu_src
->dst
.chan
);
5432 alu
.last
= (i
== 3);
5434 r
= r600_bytecode_add_alu(bc
, &alu
);
5440 r
= r600_bytecode_add_alu(bc
, &alu
);
5447 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5449 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5450 struct r600_bytecode_alu alu
;
5452 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5453 int tmp0
= ctx
->temp_reg
;
5454 int tmp1
= r600_get_temp(ctx
);
5455 int tmp2
= r600_get_temp(ctx
);
5456 int tmp3
= r600_get_temp(ctx
);
5459 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5461 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5462 * 2. tmp0.z = lo (tmp0.x * src2)
5463 * 3. tmp0.w = -tmp0.z
5464 * 4. tmp0.y = hi (tmp0.x * src2)
5465 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5466 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5467 * 7. tmp1.x = tmp0.x - tmp0.w
5468 * 8. tmp1.y = tmp0.x + tmp0.w
5469 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5470 * 10. tmp0.z = hi(tmp0.x * src1) = q
5471 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5473 * 12. tmp0.w = src1 - tmp0.y = r
5474 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5475 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5479 * 15. tmp1.z = tmp0.z + 1 = q + 1
5480 * 16. tmp1.w = tmp0.z - 1 = q - 1
5484 * 15. tmp1.z = tmp0.w - src2 = r - src2
5485 * 16. tmp1.w = tmp0.w + src2 = r + src2
5489 * 17. tmp1.x = tmp1.x & tmp1.y
5491 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5492 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5494 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5495 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5499 * Same as unsigned, using abs values of the operands,
5500 * and fixing the sign of the result in the end.
5503 for (i
= 0; i
< 4; i
++) {
5504 if (!(write_mask
& (1<<i
)))
5509 /* tmp2.x = -src0 */
5510 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5511 alu
.op
= ALU_OP2_SUB_INT
;
5517 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5519 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5522 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5525 /* tmp2.y = -src1 */
5526 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5527 alu
.op
= ALU_OP2_SUB_INT
;
5533 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5535 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5538 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5541 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5542 /* it will be a sign of the quotient */
5545 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5546 alu
.op
= ALU_OP2_XOR_INT
;
5552 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5553 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5556 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5560 /* tmp2.x = |src0| */
5561 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5562 alu
.op
= ALU_OP3_CNDGE_INT
;
5569 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5570 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5571 alu
.src
[2].sel
= tmp2
;
5572 alu
.src
[2].chan
= 0;
5575 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5578 /* tmp2.y = |src1| */
5579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5580 alu
.op
= ALU_OP3_CNDGE_INT
;
5587 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5588 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5589 alu
.src
[2].sel
= tmp2
;
5590 alu
.src
[2].chan
= 1;
5593 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5598 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5599 if (ctx
->bc
->chip_class
== CAYMAN
) {
5600 /* tmp3.x = u2f(src2) */
5601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5602 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5609 alu
.src
[0].sel
= tmp2
;
5610 alu
.src
[0].chan
= 1;
5612 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5616 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5619 /* tmp0.x = recip(tmp3.x) */
5620 for (j
= 0 ; j
< 3; j
++) {
5621 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5622 alu
.op
= ALU_OP1_RECIP_IEEE
;
5626 alu
.dst
.write
= (j
== 0);
5628 alu
.src
[0].sel
= tmp3
;
5629 alu
.src
[0].chan
= 0;
5633 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5637 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5638 alu
.op
= ALU_OP2_MUL
;
5640 alu
.src
[0].sel
= tmp0
;
5641 alu
.src
[0].chan
= 0;
5643 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5644 alu
.src
[1].value
= 0x4f800000;
5649 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5654 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5660 alu
.src
[0].sel
= tmp3
;
5661 alu
.src
[0].chan
= 0;
5664 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5668 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5669 alu
.op
= ALU_OP1_RECIP_UINT
;
5676 alu
.src
[0].sel
= tmp2
;
5677 alu
.src
[0].chan
= 1;
5679 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5683 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5687 /* 2. tmp0.z = lo (tmp0.x * src2) */
5688 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5689 alu
.op
= ALU_OP2_MULLO_UINT
;
5695 alu
.src
[0].sel
= tmp0
;
5696 alu
.src
[0].chan
= 0;
5698 alu
.src
[1].sel
= tmp2
;
5699 alu
.src
[1].chan
= 1;
5701 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5704 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5707 /* 3. tmp0.w = -tmp0.z */
5708 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5709 alu
.op
= ALU_OP2_SUB_INT
;
5715 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5716 alu
.src
[1].sel
= tmp0
;
5717 alu
.src
[1].chan
= 2;
5720 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5723 /* 4. tmp0.y = hi (tmp0.x * src2) */
5724 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5725 alu
.op
= ALU_OP2_MULHI_UINT
;
5731 alu
.src
[0].sel
= tmp0
;
5732 alu
.src
[0].chan
= 0;
5735 alu
.src
[1].sel
= tmp2
;
5736 alu
.src
[1].chan
= 1;
5738 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5741 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5744 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5745 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5746 alu
.op
= ALU_OP3_CNDE_INT
;
5753 alu
.src
[0].sel
= tmp0
;
5754 alu
.src
[0].chan
= 1;
5755 alu
.src
[1].sel
= tmp0
;
5756 alu
.src
[1].chan
= 3;
5757 alu
.src
[2].sel
= tmp0
;
5758 alu
.src
[2].chan
= 2;
5761 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5764 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5765 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5766 alu
.op
= ALU_OP2_MULHI_UINT
;
5772 alu
.src
[0].sel
= tmp0
;
5773 alu
.src
[0].chan
= 2;
5775 alu
.src
[1].sel
= tmp0
;
5776 alu
.src
[1].chan
= 0;
5778 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5781 /* 7. tmp1.x = tmp0.x - tmp0.w */
5782 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5783 alu
.op
= ALU_OP2_SUB_INT
;
5789 alu
.src
[0].sel
= tmp0
;
5790 alu
.src
[0].chan
= 0;
5791 alu
.src
[1].sel
= tmp0
;
5792 alu
.src
[1].chan
= 3;
5795 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5798 /* 8. tmp1.y = tmp0.x + tmp0.w */
5799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5800 alu
.op
= ALU_OP2_ADD_INT
;
5806 alu
.src
[0].sel
= tmp0
;
5807 alu
.src
[0].chan
= 0;
5808 alu
.src
[1].sel
= tmp0
;
5809 alu
.src
[1].chan
= 3;
5812 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5815 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5817 alu
.op
= ALU_OP3_CNDE_INT
;
5824 alu
.src
[0].sel
= tmp0
;
5825 alu
.src
[0].chan
= 1;
5826 alu
.src
[1].sel
= tmp1
;
5827 alu
.src
[1].chan
= 1;
5828 alu
.src
[2].sel
= tmp1
;
5829 alu
.src
[2].chan
= 0;
5832 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5835 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5836 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5837 alu
.op
= ALU_OP2_MULHI_UINT
;
5843 alu
.src
[0].sel
= tmp0
;
5844 alu
.src
[0].chan
= 0;
5847 alu
.src
[1].sel
= tmp2
;
5848 alu
.src
[1].chan
= 0;
5850 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5853 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5856 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5857 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5858 alu
.op
= ALU_OP2_MULLO_UINT
;
5865 alu
.src
[0].sel
= tmp2
;
5866 alu
.src
[0].chan
= 1;
5868 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5871 alu
.src
[1].sel
= tmp0
;
5872 alu
.src
[1].chan
= 2;
5874 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5877 /* 12. tmp0.w = src1 - tmp0.y = r */
5878 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5879 alu
.op
= ALU_OP2_SUB_INT
;
5886 alu
.src
[0].sel
= tmp2
;
5887 alu
.src
[0].chan
= 0;
5889 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5892 alu
.src
[1].sel
= tmp0
;
5893 alu
.src
[1].chan
= 1;
5896 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5899 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5901 alu
.op
= ALU_OP2_SETGE_UINT
;
5907 alu
.src
[0].sel
= tmp0
;
5908 alu
.src
[0].chan
= 3;
5910 alu
.src
[1].sel
= tmp2
;
5911 alu
.src
[1].chan
= 1;
5913 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5917 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5920 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5922 alu
.op
= ALU_OP2_SETGE_UINT
;
5929 alu
.src
[0].sel
= tmp2
;
5930 alu
.src
[0].chan
= 0;
5932 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5935 alu
.src
[1].sel
= tmp0
;
5936 alu
.src
[1].chan
= 1;
5939 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5942 if (mod
) { /* UMOD */
5944 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5946 alu
.op
= ALU_OP2_SUB_INT
;
5952 alu
.src
[0].sel
= tmp0
;
5953 alu
.src
[0].chan
= 3;
5956 alu
.src
[1].sel
= tmp2
;
5957 alu
.src
[1].chan
= 1;
5959 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5963 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5966 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5967 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5968 alu
.op
= ALU_OP2_ADD_INT
;
5974 alu
.src
[0].sel
= tmp0
;
5975 alu
.src
[0].chan
= 3;
5977 alu
.src
[1].sel
= tmp2
;
5978 alu
.src
[1].chan
= 1;
5980 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5984 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5989 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5990 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5991 alu
.op
= ALU_OP2_ADD_INT
;
5997 alu
.src
[0].sel
= tmp0
;
5998 alu
.src
[0].chan
= 2;
5999 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6002 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6005 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
6006 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6007 alu
.op
= ALU_OP2_ADD_INT
;
6013 alu
.src
[0].sel
= tmp0
;
6014 alu
.src
[0].chan
= 2;
6015 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
6018 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6023 /* 17. tmp1.x = tmp1.x & tmp1.y */
6024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6025 alu
.op
= ALU_OP2_AND_INT
;
6031 alu
.src
[0].sel
= tmp1
;
6032 alu
.src
[0].chan
= 0;
6033 alu
.src
[1].sel
= tmp1
;
6034 alu
.src
[1].chan
= 1;
6037 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6040 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
6041 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
6042 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6043 alu
.op
= ALU_OP3_CNDE_INT
;
6050 alu
.src
[0].sel
= tmp1
;
6051 alu
.src
[0].chan
= 0;
6052 alu
.src
[1].sel
= tmp0
;
6053 alu
.src
[1].chan
= mod
? 3 : 2;
6054 alu
.src
[2].sel
= tmp1
;
6055 alu
.src
[2].chan
= 2;
6058 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6061 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
6062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6063 alu
.op
= ALU_OP3_CNDE_INT
;
6071 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6074 alu
.src
[0].sel
= tmp1
;
6075 alu
.src
[0].chan
= 1;
6076 alu
.src
[1].sel
= tmp1
;
6077 alu
.src
[1].chan
= 3;
6078 alu
.src
[2].sel
= tmp0
;
6079 alu
.src
[2].chan
= 2;
6082 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6087 /* fix the sign of the result */
6091 /* tmp0.x = -tmp0.z */
6092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6093 alu
.op
= ALU_OP2_SUB_INT
;
6099 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6100 alu
.src
[1].sel
= tmp0
;
6101 alu
.src
[1].chan
= 2;
6104 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6107 /* sign of the remainder is the same as the sign of src0 */
6108 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6109 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6110 alu
.op
= ALU_OP3_CNDGE_INT
;
6113 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6115 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6116 alu
.src
[1].sel
= tmp0
;
6117 alu
.src
[1].chan
= 2;
6118 alu
.src
[2].sel
= tmp0
;
6119 alu
.src
[2].chan
= 0;
6122 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6127 /* tmp0.x = -tmp0.z */
6128 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6129 alu
.op
= ALU_OP2_SUB_INT
;
6135 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6136 alu
.src
[1].sel
= tmp0
;
6137 alu
.src
[1].chan
= 2;
6140 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6143 /* fix the quotient sign (same as the sign of src0*src1) */
6144 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6145 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6146 alu
.op
= ALU_OP3_CNDGE_INT
;
6149 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6151 alu
.src
[0].sel
= tmp2
;
6152 alu
.src
[0].chan
= 2;
6153 alu
.src
[1].sel
= tmp0
;
6154 alu
.src
[1].chan
= 2;
6155 alu
.src
[2].sel
= tmp0
;
6156 alu
.src
[2].chan
= 0;
6159 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6167 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6169 return tgsi_divmod(ctx
, 0, 0);
6172 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6174 return tgsi_divmod(ctx
, 1, 0);
6177 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6179 return tgsi_divmod(ctx
, 0, 1);
6182 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6184 return tgsi_divmod(ctx
, 1, 1);
6188 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6190 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6191 struct r600_bytecode_alu alu
;
6193 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6194 int last_inst
= tgsi_last_instruction(write_mask
);
6196 for (i
= 0; i
< 4; i
++) {
6197 if (!(write_mask
& (1<<i
)))
6200 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6201 alu
.op
= ALU_OP1_TRUNC
;
6203 alu
.dst
.sel
= ctx
->temp_reg
;
6207 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6210 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6215 for (i
= 0; i
< 4; i
++) {
6216 if (!(write_mask
& (1<<i
)))
6219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6220 alu
.op
= ctx
->inst_info
->op
;
6222 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6224 alu
.src
[0].sel
= ctx
->temp_reg
;
6225 alu
.src
[0].chan
= i
;
6227 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6229 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6237 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6239 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6240 struct r600_bytecode_alu alu
;
6242 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6243 int last_inst
= tgsi_last_instruction(write_mask
);
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_OP2_SUB_INT
;
6253 alu
.dst
.sel
= ctx
->temp_reg
;
6257 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6258 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6262 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6267 /* dst = (src >= 0 ? src : tmp) */
6268 for (i
= 0; i
< 4; i
++) {
6269 if (!(write_mask
& (1<<i
)))
6272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6273 alu
.op
= ALU_OP3_CNDGE_INT
;
6277 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6279 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6280 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6281 alu
.src
[2].sel
= ctx
->temp_reg
;
6282 alu
.src
[2].chan
= i
;
6286 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6293 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6295 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6296 struct r600_bytecode_alu alu
;
6298 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6299 int last_inst
= tgsi_last_instruction(write_mask
);
6301 /* tmp = (src >= 0 ? src : -1) */
6302 for (i
= 0; i
< 4; i
++) {
6303 if (!(write_mask
& (1<<i
)))
6306 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6307 alu
.op
= ALU_OP3_CNDGE_INT
;
6310 alu
.dst
.sel
= ctx
->temp_reg
;
6314 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6315 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6316 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6320 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6325 /* dst = (tmp > 0 ? 1 : tmp) */
6326 for (i
= 0; i
< 4; i
++) {
6327 if (!(write_mask
& (1<<i
)))
6330 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6331 alu
.op
= ALU_OP3_CNDGT_INT
;
6335 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6337 alu
.src
[0].sel
= ctx
->temp_reg
;
6338 alu
.src
[0].chan
= i
;
6340 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6342 alu
.src
[2].sel
= ctx
->temp_reg
;
6343 alu
.src
[2].chan
= i
;
6347 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6356 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6358 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6359 struct r600_bytecode_alu alu
;
6362 /* tmp = (src > 0 ? 1 : src) */
6363 for (i
= 0; i
< 4; i
++) {
6364 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6365 alu
.op
= ALU_OP3_CNDGT
;
6368 alu
.dst
.sel
= ctx
->temp_reg
;
6371 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6372 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6373 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6377 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6382 /* dst = (-tmp > 0 ? -1 : tmp) */
6383 for (i
= 0; i
< 4; i
++) {
6384 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6385 alu
.op
= ALU_OP3_CNDGT
;
6387 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6389 alu
.src
[0].sel
= ctx
->temp_reg
;
6390 alu
.src
[0].chan
= i
;
6393 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6396 alu
.src
[2].sel
= ctx
->temp_reg
;
6397 alu
.src
[2].chan
= i
;
6401 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6408 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6410 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6411 struct r600_bytecode_alu alu
;
6414 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6415 int last_inst
= tgsi_last_instruction(write_mask
);
6417 t1
= r600_get_temp(ctx
);
6419 for (i
= 0; i
< 4; i
++) {
6420 if (!(write_mask
& (1<<i
)))
6423 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6424 alu
.op
= ALU_OP2_SETGE_INT
;
6425 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6426 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6427 alu
.src
[1].value
= 32;
6428 alu
.dst
.sel
= ctx
->temp_reg
;
6431 alu
.last
= i
== last_inst
;
6432 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6437 for (i
= 0; i
< 4; i
++) {
6438 if (!(write_mask
& (1<<i
)))
6441 /* create mask tmp */
6442 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6443 alu
.op
= ALU_OP2_BFM_INT
;
6447 alu
.last
= i
== last_inst
;
6449 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6450 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6457 t2
= r600_get_temp(ctx
);
6459 for (i
= 0; i
< 4; i
++) {
6460 if (!(write_mask
& (1<<i
)))
6463 /* shift insert left */
6464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6465 alu
.op
= ALU_OP2_LSHL_INT
;
6469 alu
.last
= i
== last_inst
;
6471 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6472 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6474 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6479 for (i
= 0; i
< 4; i
++) {
6480 if (!(write_mask
& (1<<i
)))
6483 /* actual bitfield insert */
6484 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6485 alu
.op
= ALU_OP3_BFI_INT
;
6487 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6490 alu
.last
= i
== last_inst
;
6492 alu
.src
[0].sel
= t1
;
6493 alu
.src
[0].chan
= i
;
6494 alu
.src
[1].sel
= t2
;
6495 alu
.src
[1].chan
= i
;
6496 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6498 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6503 for (i
= 0; i
< 4; i
++) {
6504 if (!(write_mask
& (1<<i
)))
6506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6507 alu
.op
= ALU_OP3_CNDE_INT
;
6509 alu
.src
[0].sel
= ctx
->temp_reg
;
6510 alu
.src
[0].chan
= i
;
6511 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6513 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6515 alu
.src
[1].sel
= alu
.dst
.sel
;
6516 alu
.src
[1].chan
= i
;
6518 alu
.last
= i
== last_inst
;
6519 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6526 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6528 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6529 struct r600_bytecode_alu alu
;
6532 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6533 int last_inst
= tgsi_last_instruction(write_mask
);
6535 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6536 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6540 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6541 for (i
= 0; i
< 4; i
++) {
6542 if (!(write_mask
& (1<<i
)))
6545 /* t1 = FFBH_INT / FFBH_UINT */
6546 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6547 alu
.op
= ctx
->inst_info
->op
;
6551 alu
.last
= i
== last_inst
;
6553 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6555 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6560 t2
= r600_get_temp(ctx
);
6562 for (i
= 0; i
< 4; i
++) {
6563 if (!(write_mask
& (1<<i
)))
6567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6568 alu
.op
= ALU_OP2_SUB_INT
;
6572 alu
.last
= i
== last_inst
;
6574 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6575 alu
.src
[0].value
= 31;
6576 alu
.src
[1].sel
= t1
;
6577 alu
.src
[1].chan
= i
;
6579 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6584 for (i
= 0; i
< 4; i
++) {
6585 if (!(write_mask
& (1<<i
)))
6588 /* result = t1 >= 0 ? t2 : t1 */
6589 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6590 alu
.op
= ALU_OP3_CNDGE_INT
;
6592 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6595 alu
.last
= i
== last_inst
;
6597 alu
.src
[0].sel
= t1
;
6598 alu
.src
[0].chan
= i
;
6599 alu
.src
[1].sel
= t2
;
6600 alu
.src
[1].chan
= i
;
6601 alu
.src
[2].sel
= t1
;
6602 alu
.src
[2].chan
= i
;
6604 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6612 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6614 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6615 struct r600_bytecode_alu alu
;
6616 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6618 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6620 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6622 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6623 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6624 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6625 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6628 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6631 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6634 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6635 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6637 /* NOTE: currently offset is not perspective correct */
6638 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6639 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6640 int sample_gpr
= -1;
6641 int gradientsH
, gradientsV
;
6642 struct r600_bytecode_tex tex
;
6644 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6645 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6648 gradientsH
= r600_get_temp(ctx
);
6649 gradientsV
= r600_get_temp(ctx
);
6650 for (i
= 0; i
< 2; i
++) {
6651 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6652 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6653 tex
.src_gpr
= interp_gpr
;
6654 tex
.src_sel_x
= interp_base_chan
+ 0;
6655 tex
.src_sel_y
= interp_base_chan
+ 1;
6658 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6663 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6665 tex
.resource_id
= tex
.sampler_id
;
6666 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6671 for (i
= 0; i
< 2; i
++) {
6672 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6673 alu
.op
= ALU_OP3_MULADD
;
6675 alu
.src
[0].sel
= gradientsH
;
6676 alu
.src
[0].chan
= i
;
6677 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6678 alu
.src
[1].sel
= sample_gpr
;
6679 alu
.src
[1].chan
= 2;
6682 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6684 alu
.src
[2].sel
= interp_gpr
;
6685 alu
.src
[2].chan
= interp_base_chan
+ i
;
6686 alu
.dst
.sel
= ctx
->temp_reg
;
6690 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6695 for (i
= 0; i
< 2; i
++) {
6696 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6697 alu
.op
= ALU_OP3_MULADD
;
6699 alu
.src
[0].sel
= gradientsV
;
6700 alu
.src
[0].chan
= i
;
6701 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6702 alu
.src
[1].sel
= sample_gpr
;
6703 alu
.src
[1].chan
= 3;
6706 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6708 alu
.src
[2].sel
= ctx
->temp_reg
;
6709 alu
.src
[2].chan
= i
;
6710 alu
.dst
.sel
= ctx
->temp_reg
;
6714 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6720 tmp
= r600_get_temp(ctx
);
6721 for (i
= 0; i
< 8; i
++) {
6722 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6723 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6726 if ((i
> 1 && i
< 6)) {
6732 alu
.dst
.chan
= i
% 4;
6734 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6735 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6736 alu
.src
[0].sel
= ctx
->temp_reg
;
6737 alu
.src
[0].chan
= 1 - (i
% 2);
6739 alu
.src
[0].sel
= interp_gpr
;
6740 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6742 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6743 alu
.src
[1].chan
= 0;
6745 alu
.last
= i
% 4 == 3;
6746 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6753 // INTERP can't swizzle dst
6754 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6755 for (i
= 0; i
<= lasti
; i
++) {
6756 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6760 alu
.op
= ALU_OP1_MOV
;
6761 alu
.src
[0].sel
= tmp
;
6762 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6763 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6765 alu
.last
= i
== lasti
;
6766 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6775 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6777 struct r600_bytecode_alu alu
;
6780 for (i
= 0; i
< 4; i
++) {
6781 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6782 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6783 alu
.op
= ALU_OP0_NOP
;
6786 alu
.op
= ALU_OP1_MOV
;
6787 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6788 alu
.src
[0].sel
= ctx
->temp_reg
;
6789 alu
.src
[0].chan
= i
;
6794 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6801 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6802 unsigned temp
, int chan
,
6803 struct r600_bytecode_alu_src
*bc_src
,
6804 const struct r600_shader_src
*shader_src
)
6806 struct r600_bytecode_alu alu
;
6809 r600_bytecode_src(bc_src
, shader_src
, chan
);
6811 /* op3 operands don't support abs modifier */
6813 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6815 alu
.op
= ALU_OP1_MOV
;
6817 alu
.dst
.chan
= chan
;
6820 alu
.src
[0] = *bc_src
;
6821 alu
.last
= true; // sufficient?
6822 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6826 memset(bc_src
, 0, sizeof(*bc_src
));
6828 bc_src
->chan
= chan
;
6833 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
6835 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6836 struct r600_bytecode_alu alu
;
6838 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6840 unsigned op
= ctx
->inst_info
->op
;
6842 if (op
== ALU_OP3_MULADD_IEEE
&&
6843 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6844 op
= ALU_OP3_MULADD
;
6846 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6848 if (ctx
->src
[j
].abs
)
6849 temp_regs
[j
] = r600_get_temp(ctx
);
6851 for (i
= 0; i
< lasti
+ 1; i
++) {
6852 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6857 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6858 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6864 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6874 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6881 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6883 return tgsi_op3_dst(ctx
, -1);
6886 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6888 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6889 struct r600_bytecode_alu alu
;
6891 unsigned op
= ctx
->inst_info
->op
;
6892 if (op
== ALU_OP2_DOT4_IEEE
&&
6893 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6896 for (i
= 0; i
< 4; i
++) {
6897 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6899 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6900 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6903 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6905 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6906 /* handle some special cases */
6907 switch (inst
->Instruction
.Opcode
) {
6908 case TGSI_OPCODE_DP2
:
6910 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6911 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6914 case TGSI_OPCODE_DP3
:
6916 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6917 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6926 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6933 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6936 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6937 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6938 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6939 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6940 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6941 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6944 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6947 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6948 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6951 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6953 struct r600_bytecode_vtx vtx
;
6954 struct r600_bytecode_alu alu
;
6955 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6957 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6958 int sampler_index_mode
= inst
->Src
[1].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6960 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6961 if (src_requires_loading
) {
6962 for (i
= 0; i
< 4; i
++) {
6963 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6964 alu
.op
= ALU_OP1_MOV
;
6965 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6966 alu
.dst
.sel
= ctx
->temp_reg
;
6971 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6975 src_gpr
= ctx
->temp_reg
;
6978 memset(&vtx
, 0, sizeof(vtx
));
6979 vtx
.op
= FETCH_OP_VFETCH
;
6980 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6981 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6982 vtx
.src_gpr
= src_gpr
;
6983 vtx
.mega_fetch_count
= 16;
6984 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6985 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6986 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6987 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6988 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6989 vtx
.use_const_fields
= 1;
6990 vtx
.buffer_index_mode
= sampler_index_mode
;
6992 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6995 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6998 for (i
= 0; i
< 4; i
++) {
6999 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7000 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7003 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7004 alu
.op
= ALU_OP2_AND_INT
;
7007 alu
.dst
.sel
= vtx
.dst_gpr
;
7010 alu
.src
[0].sel
= vtx
.dst_gpr
;
7011 alu
.src
[0].chan
= i
;
7013 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7014 alu
.src
[1].sel
+= (id
* 2);
7015 alu
.src
[1].chan
= i
% 4;
7016 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7020 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7025 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
7026 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7027 alu
.op
= ALU_OP2_OR_INT
;
7030 alu
.dst
.sel
= vtx
.dst_gpr
;
7033 alu
.src
[0].sel
= vtx
.dst_gpr
;
7034 alu
.src
[0].chan
= 3;
7036 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
7037 alu
.src
[1].chan
= 0;
7038 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7041 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7048 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
, int eg_buffer_base
)
7050 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7052 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
7053 int sampler_index_mode
= inst
->Src
[reg_idx
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7055 if (ctx
->bc
->chip_class
< EVERGREEN
) {
7056 struct r600_bytecode_alu alu
;
7057 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7058 alu
.op
= ALU_OP1_MOV
;
7059 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7060 /* r600 we have them at channel 2 of the second dword */
7061 alu
.src
[0].sel
+= (id
* 2) + 1;
7062 alu
.src
[0].chan
= 1;
7063 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7064 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
7066 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7071 struct r600_bytecode_vtx vtx
;
7072 memset(&vtx
, 0, sizeof(vtx
));
7073 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
7074 vtx
.buffer_id
= id
+ eg_buffer_base
;
7075 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7077 vtx
.mega_fetch_count
= 16; /* no idea here really... */
7078 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7079 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7080 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 4 : 7; /* SEL_Y */
7081 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 4 : 7; /* SEL_Z */
7082 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 4 : 7; /* SEL_W */
7083 vtx
.data_format
= FMT_32_32_32_32
;
7084 vtx
.buffer_index_mode
= sampler_index_mode
;
7086 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
7093 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
7095 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7096 struct r600_bytecode_tex tex
;
7097 struct r600_bytecode_alu alu
;
7101 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7102 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7103 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7104 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7106 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7107 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7108 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7110 /* Texture fetch instructions can only use gprs as source.
7111 * Also they cannot negate the source or take the absolute value */
7112 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7113 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7114 read_compressed_msaa
|| txf_add_offsets
;
7116 boolean src_loaded
= FALSE
;
7117 unsigned sampler_src_reg
= 1;
7118 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7119 boolean has_txq_cube_array_z
= false;
7120 unsigned sampler_index_mode
;
7122 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7123 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7124 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7125 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7126 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7127 has_txq_cube_array_z
= true;
7130 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7131 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7132 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7133 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7134 sampler_src_reg
= 2;
7136 /* TGSI moves the sampler to src reg 3 for TXD */
7137 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7138 sampler_src_reg
= 3;
7140 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7142 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7144 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7145 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7146 if (ctx
->bc
->chip_class
< EVERGREEN
)
7147 ctx
->shader
->uses_tex_buffers
= true;
7148 return r600_do_buffer_txq(ctx
, 1, 0, R600_MAX_CONST_BUFFERS
);
7150 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7151 if (ctx
->bc
->chip_class
< EVERGREEN
)
7152 ctx
->shader
->uses_tex_buffers
= true;
7153 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7157 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7159 /* Add perspective divide */
7160 if (ctx
->bc
->chip_class
== CAYMAN
) {
7162 for (i
= 0; i
< 3; i
++) {
7163 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7164 alu
.op
= ALU_OP1_RECIP_IEEE
;
7165 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7167 alu
.dst
.sel
= ctx
->temp_reg
;
7173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7180 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7181 alu
.op
= ALU_OP1_RECIP_IEEE
;
7182 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7184 alu
.dst
.sel
= ctx
->temp_reg
;
7185 alu
.dst
.chan
= out_chan
;
7188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7193 for (i
= 0; i
< 3; i
++) {
7194 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7195 alu
.op
= ALU_OP2_MUL
;
7196 alu
.src
[0].sel
= ctx
->temp_reg
;
7197 alu
.src
[0].chan
= out_chan
;
7198 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7199 alu
.dst
.sel
= ctx
->temp_reg
;
7202 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7206 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7207 alu
.op
= ALU_OP1_MOV
;
7208 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7209 alu
.src
[0].chan
= 0;
7210 alu
.dst
.sel
= ctx
->temp_reg
;
7214 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7218 src_gpr
= ctx
->temp_reg
;
7222 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7223 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7224 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7225 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7226 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7228 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7229 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7231 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7232 for (i
= 0; i
< 4; i
++) {
7233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7234 alu
.op
= ALU_OP2_CUBE
;
7235 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7236 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7237 alu
.dst
.sel
= ctx
->temp_reg
;
7242 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7247 /* tmp1.z = RCP_e(|tmp1.z|) */
7248 if (ctx
->bc
->chip_class
== CAYMAN
) {
7249 for (i
= 0; i
< 3; i
++) {
7250 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7251 alu
.op
= ALU_OP1_RECIP_IEEE
;
7252 alu
.src
[0].sel
= ctx
->temp_reg
;
7253 alu
.src
[0].chan
= 2;
7255 alu
.dst
.sel
= ctx
->temp_reg
;
7261 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7267 alu
.op
= ALU_OP1_RECIP_IEEE
;
7268 alu
.src
[0].sel
= ctx
->temp_reg
;
7269 alu
.src
[0].chan
= 2;
7271 alu
.dst
.sel
= ctx
->temp_reg
;
7275 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7280 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7281 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7282 * muladd has no writemask, have to use another temp
7284 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7285 alu
.op
= ALU_OP3_MULADD
;
7288 alu
.src
[0].sel
= ctx
->temp_reg
;
7289 alu
.src
[0].chan
= 0;
7290 alu
.src
[1].sel
= ctx
->temp_reg
;
7291 alu
.src
[1].chan
= 2;
7293 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7294 alu
.src
[2].chan
= 0;
7295 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7297 alu
.dst
.sel
= ctx
->temp_reg
;
7301 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7306 alu
.op
= ALU_OP3_MULADD
;
7309 alu
.src
[0].sel
= ctx
->temp_reg
;
7310 alu
.src
[0].chan
= 1;
7311 alu
.src
[1].sel
= ctx
->temp_reg
;
7312 alu
.src
[1].chan
= 2;
7314 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7315 alu
.src
[2].chan
= 0;
7316 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7318 alu
.dst
.sel
= ctx
->temp_reg
;
7323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7326 /* write initial compare value into Z component
7327 - W src 0 for shadow cube
7328 - X src 1 for shadow cube array */
7329 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7330 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7331 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7332 alu
.op
= ALU_OP1_MOV
;
7333 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7334 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7336 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7337 alu
.dst
.sel
= ctx
->temp_reg
;
7341 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7346 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7347 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7348 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7349 int mytmp
= r600_get_temp(ctx
);
7350 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7351 alu
.op
= ALU_OP1_MOV
;
7352 alu
.src
[0].sel
= ctx
->temp_reg
;
7353 alu
.src
[0].chan
= 3;
7354 alu
.dst
.sel
= mytmp
;
7358 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7362 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7363 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7364 alu
.op
= ALU_OP3_MULADD
;
7366 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7367 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7368 alu
.src
[1].chan
= 0;
7369 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7370 alu
.src
[2].sel
= mytmp
;
7371 alu
.src
[2].chan
= 0;
7372 alu
.dst
.sel
= ctx
->temp_reg
;
7376 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7379 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7380 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7381 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7382 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7383 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7384 tex
.src_gpr
= r600_get_temp(ctx
);
7389 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7390 tex
.coord_type_x
= 1;
7391 tex
.coord_type_y
= 1;
7392 tex
.coord_type_z
= 1;
7393 tex
.coord_type_w
= 1;
7394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7395 alu
.op
= ALU_OP1_MOV
;
7396 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7397 alu
.dst
.sel
= tex
.src_gpr
;
7401 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7405 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7412 /* for cube forms of lod and bias we need to route things */
7413 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7414 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7415 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7416 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7417 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7418 alu
.op
= ALU_OP1_MOV
;
7419 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7420 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7421 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7423 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7424 alu
.dst
.sel
= ctx
->temp_reg
;
7428 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7434 src_gpr
= ctx
->temp_reg
;
7437 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7438 int temp_h
= 0, temp_v
= 0;
7441 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7442 if (src_loaded
== TRUE
)
7446 for (i
= start_val
; i
< 3; i
++) {
7447 int treg
= r600_get_temp(ctx
);
7456 for (j
= 0; j
< 4; j
++) {
7457 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7458 alu
.op
= ALU_OP1_MOV
;
7459 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7465 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7470 for (i
= 1; i
< 3; i
++) {
7471 /* set gradients h/v */
7472 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7473 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7474 FETCH_OP_SET_GRADIENTS_V
;
7475 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7476 tex
.sampler_index_mode
= sampler_index_mode
;
7477 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7478 tex
.resource_index_mode
= sampler_index_mode
;
7480 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7486 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7487 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7488 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7489 tex
.coord_type_x
= 1;
7490 tex
.coord_type_y
= 1;
7491 tex
.coord_type_z
= 1;
7492 tex
.coord_type_w
= 1;
7494 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7500 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7501 /* Gather4 should follow the same rules as bilinear filtering, but the hardware
7502 * incorrectly forces nearest filtering if the texture format is integer.
7503 * The only effect it has on Gather4, which always returns 4 texels for
7504 * bilinear filtering, is that the final coordinates are off by 0.5 of
7507 * The workaround is to subtract 0.5 from the unnormalized coordinates,
7508 * or (0.5 / size) from the normalized coordinates.
7510 if (inst
->Texture
.ReturnType
== TGSI_RETURN_TYPE_SINT
||
7511 inst
->Texture
.ReturnType
== TGSI_RETURN_TYPE_UINT
) {
7512 int treg
= r600_get_temp(ctx
);
7514 /* mov array and comparison oordinate to temp_reg if needed */
7515 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7516 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7517 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
) && !src_loaded
) {
7518 int end
= inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
? 3 : 2;
7519 for (i
= 2; i
<= end
; i
++) {
7520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7521 alu
.op
= ALU_OP1_MOV
;
7522 alu
.dst
.sel
= ctx
->temp_reg
;
7525 alu
.last
= (i
== end
);
7526 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7527 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7533 if (inst
->Texture
.Texture
== TGSI_TEXTURE_RECT
||
7534 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
) {
7535 for (i
= 0; i
< 2; i
++) {
7536 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7537 alu
.op
= ALU_OP2_ADD
;
7538 alu
.dst
.sel
= ctx
->temp_reg
;
7543 alu
.src
[0].sel
= ctx
->temp_reg
;
7544 alu
.src
[0].chan
= i
;
7546 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7547 alu
.src
[1].sel
= V_SQ_ALU_SRC_0_5
;
7549 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7555 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7556 tex
.op
= FETCH_OP_GET_TEXTURE_RESINFO
;
7557 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7558 tex
.sampler_index_mode
= sampler_index_mode
;
7559 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7560 tex
.resource_index_mode
= sampler_index_mode
;
7570 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7574 /* coord.xy = -0.5 * (1.0/int_to_flt(size)) + coord.xy */
7575 if (ctx
->bc
->chip_class
== CAYMAN
) {
7577 for (i
= 0; i
< 2; i
++) {
7578 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7579 alu
.op
= ALU_OP1_INT_TO_FLT
;
7583 alu
.src
[0].sel
= treg
;
7584 alu
.src
[0].chan
= i
;
7585 alu
.last
= (i
== 1) ? 1 : 0;
7586 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7590 for (j
= 0; j
< 2; j
++) {
7591 for (i
= 0; i
< 3; i
++) {
7592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7593 alu
.op
= ALU_OP1_RECIP_IEEE
;
7594 alu
.src
[0].sel
= treg
;
7595 alu
.src
[0].chan
= j
;
7602 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7608 for (i
= 0; i
< 2; i
++) {
7609 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7610 alu
.op
= ALU_OP1_INT_TO_FLT
;
7614 alu
.src
[0].sel
= treg
;
7615 alu
.src
[0].chan
= i
;
7617 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7621 for (i
= 0; i
< 2; i
++) {
7622 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7623 alu
.op
= ALU_OP1_RECIP_IEEE
;
7624 alu
.src
[0].sel
= treg
;
7625 alu
.src
[0].chan
= i
;
7630 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7635 for (i
= 0; i
< 2; i
++) {
7636 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7637 alu
.op
= ALU_OP3_MULADD
;
7639 alu
.dst
.sel
= ctx
->temp_reg
;
7643 alu
.src
[0].sel
= treg
;
7644 alu
.src
[0].chan
= i
;
7645 alu
.src
[1].sel
= V_SQ_ALU_SRC_0_5
;
7648 alu
.src
[2].sel
= ctx
->temp_reg
;
7649 alu
.src
[2].chan
= i
;
7651 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
7652 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7658 src_gpr
= ctx
->temp_reg
;
7662 if (src_requires_loading
&& !src_loaded
) {
7663 for (i
= 0; i
< 4; i
++) {
7664 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7665 alu
.op
= ALU_OP1_MOV
;
7666 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7667 alu
.dst
.sel
= ctx
->temp_reg
;
7672 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7677 src_gpr
= ctx
->temp_reg
;
7680 /* get offset values */
7681 if (inst
->Texture
.NumOffsets
) {
7682 assert(inst
->Texture
.NumOffsets
== 1);
7684 /* The texture offset feature doesn't work with the TXF instruction
7685 * and must be emulated by adding the offset to the texture coordinates. */
7686 if (txf_add_offsets
) {
7687 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7689 switch (inst
->Texture
.Texture
) {
7690 case TGSI_TEXTURE_3D
:
7691 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7692 alu
.op
= ALU_OP2_ADD_INT
;
7693 alu
.src
[0].sel
= src_gpr
;
7694 alu
.src
[0].chan
= 2;
7695 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7696 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7697 alu
.dst
.sel
= src_gpr
;
7701 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7706 case TGSI_TEXTURE_2D
:
7707 case TGSI_TEXTURE_SHADOW2D
:
7708 case TGSI_TEXTURE_RECT
:
7709 case TGSI_TEXTURE_SHADOWRECT
:
7710 case TGSI_TEXTURE_2D_ARRAY
:
7711 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7712 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7713 alu
.op
= ALU_OP2_ADD_INT
;
7714 alu
.src
[0].sel
= src_gpr
;
7715 alu
.src
[0].chan
= 1;
7716 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7717 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7718 alu
.dst
.sel
= src_gpr
;
7722 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7727 case TGSI_TEXTURE_1D
:
7728 case TGSI_TEXTURE_SHADOW1D
:
7729 case TGSI_TEXTURE_1D_ARRAY
:
7730 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7731 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7732 alu
.op
= ALU_OP2_ADD_INT
;
7733 alu
.src
[0].sel
= src_gpr
;
7734 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7735 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7736 alu
.dst
.sel
= src_gpr
;
7739 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7743 /* texture offsets do not apply to other texture targets */
7746 switch (inst
->Texture
.Texture
) {
7747 case TGSI_TEXTURE_3D
:
7748 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7750 case TGSI_TEXTURE_2D
:
7751 case TGSI_TEXTURE_SHADOW2D
:
7752 case TGSI_TEXTURE_RECT
:
7753 case TGSI_TEXTURE_SHADOWRECT
:
7754 case TGSI_TEXTURE_2D_ARRAY
:
7755 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7756 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7758 case TGSI_TEXTURE_1D
:
7759 case TGSI_TEXTURE_SHADOW1D
:
7760 case TGSI_TEXTURE_1D_ARRAY
:
7761 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7762 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7767 /* Obtain the sample index for reading a compressed MSAA color texture.
7768 * To read the FMASK, we use the ldfptr instruction, which tells us
7769 * where the samples are stored.
7770 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7771 * which is the identity mapping. Each nibble says which physical sample
7772 * should be fetched to get that sample.
7774 * Assume src.z contains the sample index. It should be modified like this:
7775 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7776 * Then fetch the texel with src.
7778 if (read_compressed_msaa
) {
7779 unsigned sample_chan
= 3;
7780 unsigned temp
= r600_get_temp(ctx
);
7783 /* temp.w = ldfptr() */
7784 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7785 tex
.op
= FETCH_OP_LD
;
7786 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7787 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7788 tex
.sampler_index_mode
= sampler_index_mode
;
7789 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7790 tex
.resource_index_mode
= sampler_index_mode
;
7791 tex
.src_gpr
= src_gpr
;
7793 tex
.dst_sel_x
= 7; /* mask out these components */
7796 tex
.dst_sel_w
= 0; /* store X */
7801 tex
.offset_x
= offset_x
;
7802 tex
.offset_y
= offset_y
;
7803 tex
.offset_z
= offset_z
;
7804 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7808 /* temp.x = sample_index*4 */
7809 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7810 alu
.op
= ALU_OP2_MULLO_INT
;
7811 alu
.src
[0].sel
= src_gpr
;
7812 alu
.src
[0].chan
= sample_chan
;
7813 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7814 alu
.src
[1].value
= 4;
7818 r
= emit_mul_int_op(ctx
->bc
, &alu
);
7822 /* sample_index = temp.w >> temp.x */
7823 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7824 alu
.op
= ALU_OP2_LSHR_INT
;
7825 alu
.src
[0].sel
= temp
;
7826 alu
.src
[0].chan
= 3;
7827 alu
.src
[1].sel
= temp
;
7828 alu
.src
[1].chan
= 0;
7829 alu
.dst
.sel
= src_gpr
;
7830 alu
.dst
.chan
= sample_chan
;
7833 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7837 /* sample_index & 0xF */
7838 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7839 alu
.op
= ALU_OP2_AND_INT
;
7840 alu
.src
[0].sel
= src_gpr
;
7841 alu
.src
[0].chan
= sample_chan
;
7842 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7843 alu
.src
[1].value
= 0xF;
7844 alu
.dst
.sel
= src_gpr
;
7845 alu
.dst
.chan
= sample_chan
;
7848 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7852 /* visualize the FMASK */
7853 for (i
= 0; i
< 4; i
++) {
7854 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7855 alu
.op
= ALU_OP1_INT_TO_FLT
;
7856 alu
.src
[0].sel
= src_gpr
;
7857 alu
.src
[0].chan
= sample_chan
;
7858 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7862 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7870 /* does this shader want a num layers from TXQ for a cube array? */
7871 if (has_txq_cube_array_z
) {
7872 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7874 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7875 alu
.op
= ALU_OP1_MOV
;
7877 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7878 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7879 /* with eg each dword is number of cubes */
7880 alu
.src
[0].sel
+= id
/ 4;
7881 alu
.src
[0].chan
= id
% 4;
7883 /* r600 we have them at channel 2 of the second dword */
7884 alu
.src
[0].sel
+= (id
* 2) + 1;
7885 alu
.src
[0].chan
= 2;
7887 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7888 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7890 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7893 /* disable writemask from texture instruction */
7894 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7897 opcode
= ctx
->inst_info
->op
;
7898 if (opcode
== FETCH_OP_GATHER4
&&
7899 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7900 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7901 opcode
= FETCH_OP_GATHER4_O
;
7903 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7904 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7905 encoded in the instruction are ignored. */
7906 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7907 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7908 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7909 tex
.sampler_index_mode
= sampler_index_mode
;
7910 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7911 tex
.resource_index_mode
= sampler_index_mode
;
7913 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7914 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7915 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7916 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7924 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7929 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7930 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7931 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7932 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7933 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7934 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7935 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7937 case FETCH_OP_SAMPLE
:
7938 opcode
= FETCH_OP_SAMPLE_C
;
7940 case FETCH_OP_SAMPLE_L
:
7941 opcode
= FETCH_OP_SAMPLE_C_L
;
7943 case FETCH_OP_SAMPLE_LB
:
7944 opcode
= FETCH_OP_SAMPLE_C_LB
;
7946 case FETCH_OP_SAMPLE_G
:
7947 opcode
= FETCH_OP_SAMPLE_C_G
;
7949 /* Texture gather variants */
7950 case FETCH_OP_GATHER4
:
7951 opcode
= FETCH_OP_GATHER4_C
;
7953 case FETCH_OP_GATHER4_O
:
7954 opcode
= FETCH_OP_GATHER4_C_O
;
7959 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7962 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7963 tex
.sampler_index_mode
= sampler_index_mode
;
7964 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7965 tex
.resource_index_mode
= sampler_index_mode
;
7966 tex
.src_gpr
= src_gpr
;
7967 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7969 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7970 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7971 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7974 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7975 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7976 tex
.inst_mod
= texture_component_select
;
7978 if (ctx
->bc
->chip_class
== CAYMAN
) {
7979 /* GATHER4 result order is different from TGSI TG4 */
7980 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7981 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7982 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7983 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7985 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7986 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7987 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7988 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7991 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7992 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7993 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7997 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
8004 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8005 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8006 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8007 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8011 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
8016 } else if (src_loaded
) {
8022 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
8023 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
8024 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
8025 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
8026 tex
.src_rel
= ctx
->src
[0].rel
;
8029 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
8030 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
8031 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
8032 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
8036 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
8039 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
8040 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
8041 tex
.coord_type_x
= 1;
8042 tex
.coord_type_y
= 1;
8044 tex
.coord_type_z
= 1;
8045 tex
.coord_type_w
= 1;
8047 tex
.offset_x
= offset_x
;
8048 tex
.offset_y
= offset_y
;
8049 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
8050 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8051 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
8055 tex
.offset_z
= offset_z
;
8058 /* Put the depth for comparison in W.
8059 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
8060 * Some instructions expect the depth in Z. */
8061 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
8062 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
8063 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
8064 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
8065 opcode
!= FETCH_OP_SAMPLE_C_L
&&
8066 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
8067 tex
.src_sel_w
= tex
.src_sel_z
;
8070 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
8071 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
8072 if (opcode
== FETCH_OP_SAMPLE_C_L
||
8073 opcode
== FETCH_OP_SAMPLE_C_LB
) {
8074 /* the array index is read from Y */
8075 tex
.coord_type_y
= 0;
8077 /* the array index is read from Z */
8078 tex
.coord_type_z
= 0;
8079 tex
.src_sel_z
= tex
.src_sel_y
;
8081 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8082 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
8083 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
8084 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
8085 (ctx
->bc
->chip_class
>= EVERGREEN
)))
8086 /* the array index is read from Z */
8087 tex
.coord_type_z
= 0;
8089 /* mask unused source components */
8090 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
8091 switch (inst
->Texture
.Texture
) {
8092 case TGSI_TEXTURE_2D
:
8093 case TGSI_TEXTURE_RECT
:
8097 case TGSI_TEXTURE_1D_ARRAY
:
8101 case TGSI_TEXTURE_1D
:
8109 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8113 /* add shadow ambient support - gallium doesn't do it yet */
8117 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
8118 struct tgsi_full_src_register
*src
)
8122 if (src
->Register
.Indirect
) {
8123 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
8124 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
8125 return ctx
->shader
->atomics
[i
].hw_idx
;
8128 uint32_t index
= src
->Register
.Index
;
8129 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
8130 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
8132 if (index
> ctx
->shader
->atomics
[i
].end
)
8134 if (index
< ctx
->shader
->atomics
[i
].start
)
8136 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
8137 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
8144 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
8145 int *uav_id_p
, int *uav_index_mode_p
)
8147 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8148 int uav_id
, uav_index_mode
= 0;
8150 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8152 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
8154 if (inst
->Src
[0].Register
.Indirect
) {
8156 struct r600_bytecode_alu alu
;
8157 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8158 alu
.op
= ALU_OP2_LSHL_INT
;
8159 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
8160 alu
.src
[0].chan
= 0;
8161 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8162 alu
.src
[1].value
= 2;
8163 alu
.dst
.sel
= ctx
->temp_reg
;
8167 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8171 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8174 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
8180 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8182 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
8188 *uav_index_mode_p
= uav_index_mode
;
8192 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
8194 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8196 struct r600_bytecode_gds gds
;
8198 int uav_index_mode
= 0;
8199 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8201 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8205 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8206 gds
.op
= FETCH_OP_GDS_READ_RET
;
8207 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8208 gds
.uav_id
= is_cm
? 0 : uav_id
;
8209 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8210 gds
.src_gpr
= ctx
->temp_reg
;
8211 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
8219 gds
.alloc_consume
= !is_cm
;
8220 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8224 ctx
->bc
->cf_last
->vpm
= 1;
8228 /* this fixes up 1D arrays properly */
8229 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
8231 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8233 struct r600_bytecode_alu alu
;
8234 int temp_reg
= r600_get_temp(ctx
);
8236 for (i
= 0; i
< 4; i
++) {
8237 bool def_val
= true, write_zero
= false;
8238 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8239 alu
.op
= ALU_OP1_MOV
;
8240 alu
.dst
.sel
= temp_reg
;
8243 switch (inst
->Memory
.Texture
) {
8244 case TGSI_TEXTURE_BUFFER
:
8245 case TGSI_TEXTURE_1D
:
8246 if (i
== 1 || i
== 2 || i
== 3) {
8250 case TGSI_TEXTURE_1D_ARRAY
:
8251 if (i
== 1 || i
== 3)
8254 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8258 case TGSI_TEXTURE_2D
:
8259 if (i
== 2 || i
== 3)
8269 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8270 alu
.src
[0].value
= 0;
8271 } else if (def_val
) {
8272 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8282 *idx_gpr
= temp_reg
;
8286 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8289 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8291 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8292 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8293 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8295 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8300 struct r600_bytecode_alu alu
;
8301 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8302 alu
.op
= ALU_OP2_LSHR_INT
;
8303 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8304 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8305 alu
.src
[1].value
= 2;
8306 alu
.dst
.sel
= temp_reg
;
8309 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8316 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8318 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8319 /* have to work out the offset into the RAT immediate return buffer */
8320 struct r600_bytecode_vtx vtx
;
8321 struct r600_bytecode_cf
*cf
;
8323 int temp_reg
= r600_get_temp(ctx
);
8324 unsigned rat_index_mode
;
8327 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8328 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8330 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8333 ctx
->bc
->cf_last
->barrier
= 1;
8334 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8335 vtx
.op
= FETCH_OP_VFETCH
;
8336 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8337 vtx
.buffer_index_mode
= rat_index_mode
;
8338 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8339 vtx
.src_gpr
= temp_reg
;
8341 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8342 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8343 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8344 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8345 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8346 vtx
.num_format_all
= 1;
8347 vtx
.format_comp_all
= 1;
8348 vtx
.srf_mode_all
= 0;
8350 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8351 vtx
.data_format
= FMT_32_32_32_32
;
8352 vtx
.use_const_fields
= 0;
8353 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8354 vtx
.data_format
= FMT_32_32_32
;
8355 vtx
.use_const_fields
= 0;
8356 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8357 vtx
.data_format
= FMT_32_32
;
8358 vtx
.use_const_fields
= 0;
8360 vtx
.data_format
= FMT_32
;
8361 vtx
.use_const_fields
= 0;
8364 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8367 cf
= ctx
->bc
->cf_last
;
8372 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8374 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8375 /* have to work out the offset into the RAT immediate return buffer */
8376 struct r600_bytecode_vtx vtx
;
8377 struct r600_bytecode_cf
*cf
;
8380 unsigned format
, num_format
, format_comp
, endian
;
8381 const struct util_format_description
*desc
;
8382 unsigned rat_index_mode
;
8383 unsigned immed_base
;
8385 r
= load_thread_id_gpr(ctx
);
8389 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8391 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8392 r
= load_index_src(ctx
, 1, &idx_gpr
);
8397 egcm_load_index_reg(ctx
->bc
, 1, false);
8399 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8400 cf
= ctx
->bc
->cf_last
;
8402 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8403 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8404 cf
->rat
.index_mode
= rat_index_mode
;
8405 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8406 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8407 cf
->output
.index_gpr
= idx_gpr
;
8408 cf
->output
.comp_mask
= 0xf;
8409 cf
->output
.burst_count
= 1;
8413 cf
->output
.elem_size
= 0;
8415 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8416 cf
= ctx
->bc
->cf_last
;
8419 desc
= util_format_description(inst
->Memory
.Format
);
8420 r600_vertex_data_type(inst
->Memory
.Format
,
8421 &format
, &num_format
, &format_comp
, &endian
);
8422 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8423 vtx
.op
= FETCH_OP_VFETCH
;
8424 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8425 vtx
.buffer_index_mode
= rat_index_mode
;
8426 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8427 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8429 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8430 vtx
.dst_sel_x
= desc
->swizzle
[0];
8431 vtx
.dst_sel_y
= desc
->swizzle
[1];
8432 vtx
.dst_sel_z
= desc
->swizzle
[2];
8433 vtx
.dst_sel_w
= desc
->swizzle
[3];
8434 vtx
.srf_mode_all
= 1;
8435 vtx
.data_format
= format
;
8436 vtx
.num_format_all
= num_format
;
8437 vtx
.format_comp_all
= format_comp
;
8438 vtx
.endian
= endian
;
8440 vtx
.mega_fetch_count
= 3;
8441 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8444 cf
= ctx
->bc
->cf_last
;
8449 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8451 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8452 struct r600_bytecode_alu alu
;
8454 int temp_reg
= r600_get_temp(ctx
);
8456 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8457 alu
.op
= ALU_OP1_MOV
;
8458 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8459 alu
.dst
.sel
= temp_reg
;
8462 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8466 r
= do_lds_fetch_values(ctx
, temp_reg
,
8467 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8473 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8475 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8476 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8477 return tgsi_load_rat(ctx
);
8478 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8479 return tgsi_load_gds(ctx
);
8480 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8481 return tgsi_load_buffer(ctx
);
8482 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8483 return tgsi_load_lds(ctx
);
8487 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8489 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8490 struct r600_bytecode_cf
*cf
;
8492 unsigned rat_index_mode
;
8494 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8496 r
= load_buffer_coord(ctx
, 0, treg2
);
8500 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8502 egcm_load_index_reg(ctx
->bc
, 1, false);
8504 for (i
= 0; i
<= 3; i
++) {
8505 struct r600_bytecode_alu alu
;
8506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8507 alu
.op
= ALU_OP1_MOV
;
8508 alu
.dst
.sel
= temp_reg
;
8510 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8511 alu
.last
= (i
== 3);
8513 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8518 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8519 for (i
= 0; i
<= lasti
; i
++) {
8520 struct r600_bytecode_alu alu
;
8521 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8524 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8527 V_SQ_ALU_SRC_LITERAL
, i
);
8531 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8532 alu
.op
= ALU_OP1_MOV
;
8533 alu
.dst
.sel
= ctx
->temp_reg
;
8536 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8539 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8543 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8544 cf
= ctx
->bc
->cf_last
;
8546 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8547 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8548 cf
->rat
.index_mode
= rat_index_mode
;
8549 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8550 cf
->output
.gpr
= ctx
->temp_reg
;
8551 cf
->output
.index_gpr
= temp_reg
;
8552 cf
->output
.comp_mask
= 1;
8553 cf
->output
.burst_count
= 1;
8556 cf
->output
.elem_size
= 0;
8561 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8563 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8564 struct r600_bytecode_cf
*cf
;
8565 bool src_requires_loading
= false;
8566 int val_gpr
, idx_gpr
;
8568 unsigned rat_index_mode
;
8570 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8572 r
= load_index_src(ctx
, 0, &idx_gpr
);
8576 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8577 src_requires_loading
= true;
8579 if (src_requires_loading
) {
8580 struct r600_bytecode_alu alu
;
8581 for (i
= 0; i
< 4; i
++) {
8582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8583 alu
.op
= ALU_OP1_MOV
;
8584 alu
.dst
.sel
= ctx
->temp_reg
;
8587 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8591 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8595 val_gpr
= ctx
->temp_reg
;
8597 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8599 egcm_load_index_reg(ctx
->bc
, 1, false);
8601 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8602 cf
= ctx
->bc
->cf_last
;
8604 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8605 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8606 cf
->rat
.index_mode
= rat_index_mode
;
8607 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8608 cf
->output
.gpr
= val_gpr
;
8609 cf
->output
.index_gpr
= idx_gpr
;
8610 cf
->output
.comp_mask
= 0xf;
8611 cf
->output
.burst_count
= 1;
8614 cf
->output
.elem_size
= 0;
8618 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8620 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8621 struct r600_bytecode_alu alu
;
8623 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8624 int temp_reg
= r600_get_temp(ctx
);
8627 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8628 alu
.op
= ALU_OP1_MOV
;
8629 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8630 alu
.dst
.sel
= temp_reg
;
8633 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8637 lasti
= tgsi_last_instruction(write_mask
);
8638 for (i
= 1; i
<= lasti
; i
++) {
8639 if (!(write_mask
& (1 << i
)))
8641 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8644 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8648 for (i
= 0; i
<= lasti
; i
++) {
8649 if (!(write_mask
& (1 << i
)))
8652 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8653 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8654 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8655 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8657 alu
.src
[0].sel
= temp_reg
;
8658 alu
.src
[0].chan
= i
;
8659 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8660 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8662 alu
.is_lds_idx_op
= true;
8664 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8670 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8671 alu
.op
= LDS_OP2_LDS_WRITE
;
8673 alu
.src
[0].sel
= temp_reg
;
8674 alu
.src
[0].chan
= i
;
8675 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8678 alu
.is_lds_idx_op
= true;
8680 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8687 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8689 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8690 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8691 return tgsi_store_buffer_rat(ctx
);
8692 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8693 return tgsi_store_lds(ctx
);
8695 return tgsi_store_rat(ctx
);
8698 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8700 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8701 /* have to work out the offset into the RAT immediate return buffer */
8702 struct r600_bytecode_alu alu
;
8703 struct r600_bytecode_vtx vtx
;
8704 struct r600_bytecode_cf
*cf
;
8707 unsigned format
, num_format
, format_comp
, endian
;
8708 const struct util_format_description
*desc
;
8709 unsigned rat_index_mode
;
8710 unsigned immed_base
;
8713 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8714 rat_base
= ctx
->shader
->rat_base
;
8716 r
= load_thread_id_gpr(ctx
);
8720 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8721 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8722 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8724 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8727 idx_gpr
= ctx
->temp_reg
;
8729 r
= load_index_src(ctx
, 1, &idx_gpr
);
8734 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8736 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8737 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8738 alu
.op
= ALU_OP1_MOV
;
8739 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8742 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8744 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8748 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8749 alu
.op
= ALU_OP1_MOV
;
8750 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8751 if (ctx
->bc
->chip_class
== CAYMAN
)
8756 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8758 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8763 alu
.op
= ALU_OP1_MOV
;
8764 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8767 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8769 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8775 egcm_load_index_reg(ctx
->bc
, 1, false);
8776 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8777 cf
= ctx
->bc
->cf_last
;
8779 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
8780 cf
->rat
.inst
= ctx
->inst_info
->op
;
8781 cf
->rat
.index_mode
= rat_index_mode
;
8782 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8783 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8784 cf
->output
.index_gpr
= idx_gpr
;
8785 cf
->output
.comp_mask
= 0xf;
8786 cf
->output
.burst_count
= 1;
8790 cf
->output
.elem_size
= 0;
8791 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8792 cf
= ctx
->bc
->cf_last
;
8796 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8797 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
8798 desc
= util_format_description(inst
->Memory
.Format
);
8799 r600_vertex_data_type(inst
->Memory
.Format
,
8800 &format
, &num_format
, &format_comp
, &endian
);
8801 vtx
.dst_sel_x
= desc
->swizzle
[0];
8809 vtx
.op
= FETCH_OP_VFETCH
;
8810 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8811 vtx
.buffer_index_mode
= rat_index_mode
;
8812 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8813 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8815 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8819 vtx
.use_const_fields
= 0;
8820 vtx
.srf_mode_all
= 1;
8821 vtx
.data_format
= format
;
8822 vtx
.num_format_all
= num_format
;
8823 vtx
.format_comp_all
= format_comp
;
8824 vtx
.endian
= endian
;
8826 vtx
.mega_fetch_count
= 0xf;
8827 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8830 cf
= ctx
->bc
->cf_last
;
8836 static int get_gds_op(int opcode
)
8839 case TGSI_OPCODE_ATOMUADD
:
8840 return FETCH_OP_GDS_ADD_RET
;
8841 case TGSI_OPCODE_ATOMAND
:
8842 return FETCH_OP_GDS_AND_RET
;
8843 case TGSI_OPCODE_ATOMOR
:
8844 return FETCH_OP_GDS_OR_RET
;
8845 case TGSI_OPCODE_ATOMXOR
:
8846 return FETCH_OP_GDS_XOR_RET
;
8847 case TGSI_OPCODE_ATOMUMIN
:
8848 return FETCH_OP_GDS_MIN_UINT_RET
;
8849 case TGSI_OPCODE_ATOMUMAX
:
8850 return FETCH_OP_GDS_MAX_UINT_RET
;
8851 case TGSI_OPCODE_ATOMXCHG
:
8852 return FETCH_OP_GDS_XCHG_RET
;
8853 case TGSI_OPCODE_ATOMCAS
:
8854 return FETCH_OP_GDS_CMP_XCHG_RET
;
8860 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8862 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8863 struct r600_bytecode_gds gds
;
8864 struct r600_bytecode_alu alu
;
8865 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8868 int uav_index_mode
= 0;
8869 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8872 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8876 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8880 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
) {
8881 if (inst
->Src
[3].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8882 int value
= (ctx
->literals
[4 * inst
->Src
[3].Register
.Index
+ inst
->Src
[3].Register
.SwizzleX
]);
8883 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8884 alu
.op
= ALU_OP1_MOV
;
8885 alu
.dst
.sel
= ctx
->temp_reg
;
8886 alu
.dst
.chan
= is_cm
? 2 : 1;
8887 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8888 alu
.src
[0].value
= value
;
8891 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8895 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8896 alu
.op
= ALU_OP1_MOV
;
8897 alu
.dst
.sel
= ctx
->temp_reg
;
8898 alu
.dst
.chan
= is_cm
? 2 : 1;
8899 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8902 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8907 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8908 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8909 int abs_value
= abs(value
);
8910 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8911 gds_op
= FETCH_OP_GDS_SUB_RET
;
8912 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8913 alu
.op
= ALU_OP1_MOV
;
8914 alu
.dst
.sel
= ctx
->temp_reg
;
8915 alu
.dst
.chan
= is_cm
? 1 : 0;
8916 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8917 alu
.src
[0].value
= abs_value
;
8920 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8925 alu
.op
= ALU_OP1_MOV
;
8926 alu
.dst
.sel
= ctx
->temp_reg
;
8927 alu
.dst
.chan
= is_cm
? 1 : 0;
8928 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8931 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8937 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8939 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8940 gds
.uav_id
= is_cm
? 0 : uav_id
;
8941 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8942 gds
.src_gpr
= ctx
->temp_reg
;
8944 gds
.src_sel_x
= is_cm
? 0 : 4;
8945 gds
.src_sel_y
= is_cm
? 1 : 0;
8946 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
)
8947 gds
.src_sel_z
= is_cm
? 2 : 1;
8954 gds
.alloc_consume
= !is_cm
;
8956 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8959 ctx
->bc
->cf_last
->vpm
= 1;
8963 static int get_lds_op(int opcode
)
8966 case TGSI_OPCODE_ATOMUADD
:
8967 return LDS_OP2_LDS_ADD_RET
;
8968 case TGSI_OPCODE_ATOMAND
:
8969 return LDS_OP2_LDS_AND_RET
;
8970 case TGSI_OPCODE_ATOMOR
:
8971 return LDS_OP2_LDS_OR_RET
;
8972 case TGSI_OPCODE_ATOMXOR
:
8973 return LDS_OP2_LDS_XOR_RET
;
8974 case TGSI_OPCODE_ATOMUMIN
:
8975 return LDS_OP2_LDS_MIN_UINT_RET
;
8976 case TGSI_OPCODE_ATOMUMAX
:
8977 return LDS_OP2_LDS_MAX_UINT_RET
;
8978 case TGSI_OPCODE_ATOMIMIN
:
8979 return LDS_OP2_LDS_MIN_INT_RET
;
8980 case TGSI_OPCODE_ATOMIMAX
:
8981 return LDS_OP2_LDS_MAX_INT_RET
;
8982 case TGSI_OPCODE_ATOMXCHG
:
8983 return LDS_OP2_LDS_XCHG_RET
;
8984 case TGSI_OPCODE_ATOMCAS
:
8985 return LDS_OP3_LDS_CMP_XCHG_RET
;
8991 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
8993 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8994 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
8997 struct r600_bytecode_alu alu
;
8998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9000 alu
.is_lds_idx_op
= true;
9002 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
9003 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
9004 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
9005 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
9007 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
9008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9012 /* then read from LDS_OQ_A_POP */
9013 memset(&alu
, 0, sizeof(alu
));
9015 alu
.op
= ALU_OP1_MOV
;
9016 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
9017 alu
.src
[0].chan
= 0;
9018 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
9021 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9028 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
9030 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9031 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
9032 return tgsi_atomic_op_rat(ctx
);
9033 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
9034 return tgsi_atomic_op_gds(ctx
);
9035 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
9036 return tgsi_atomic_op_rat(ctx
);
9037 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
9038 return tgsi_atomic_op_lds(ctx
);
9042 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
9044 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9045 unsigned sampler_index_mode
;
9046 struct r600_bytecode_tex tex
;
9048 boolean has_txq_cube_array_z
= false;
9050 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
9051 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
9052 if (ctx
->bc
->chip_class
< EVERGREEN
)
9053 ctx
->shader
->uses_tex_buffers
= true;
9054 unsigned eg_buffer_base
= 0;
9055 eg_buffer_base
= R600_IMAGE_REAL_RESOURCE_OFFSET
;
9056 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
9057 eg_buffer_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
9058 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
, eg_buffer_base
);
9061 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
9062 inst
->Dst
[0].Register
.WriteMask
& 4) {
9063 ctx
->shader
->has_txq_cube_array_z_comp
= true;
9064 has_txq_cube_array_z
= true;
9067 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
9068 if (sampler_index_mode
)
9069 egcm_load_index_reg(ctx
->bc
, 1, false);
9072 /* does this shader want a num layers from TXQ for a cube array? */
9073 if (has_txq_cube_array_z
) {
9074 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
9075 struct r600_bytecode_alu alu
;
9077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9078 alu
.op
= ALU_OP1_MOV
;
9080 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
9081 /* with eg each dword is either number of cubes */
9082 alu
.src
[0].sel
+= id
/ 4;
9083 alu
.src
[0].chan
= id
% 4;
9084 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
9085 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
9087 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9090 /* disable writemask from texture instruction */
9091 inst
->Dst
[0].Register
.WriteMask
&= ~4;
9093 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
9094 tex
.op
= ctx
->inst_info
->op
;
9095 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
9096 tex
.sampler_index_mode
= sampler_index_mode
;
9097 tex
.resource_id
= tex
.sampler_id
;
9098 tex
.resource_index_mode
= sampler_index_mode
;
9103 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
9104 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
9105 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
9106 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
9107 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9108 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
9115 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
9117 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9118 struct r600_bytecode_alu alu
;
9119 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9120 unsigned i
, temp_regs
[2];
9123 /* optimize if it's just an equal balance */
9124 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
9125 for (i
= 0; i
< lasti
+ 1; i
++) {
9126 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9129 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9130 alu
.op
= ALU_OP2_ADD
;
9131 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
9132 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9134 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9139 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9147 for (i
= 0; i
< lasti
+ 1; i
++) {
9148 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9151 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9152 alu
.op
= ALU_OP2_ADD
;
9153 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9154 alu
.src
[0].chan
= 0;
9155 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
9156 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
9157 alu
.dst
.sel
= ctx
->temp_reg
;
9163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9168 /* (1 - src0) * src2 */
9169 for (i
= 0; i
< lasti
+ 1; i
++) {
9170 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9173 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9174 alu
.op
= ALU_OP2_MUL
;
9175 alu
.src
[0].sel
= ctx
->temp_reg
;
9176 alu
.src
[0].chan
= i
;
9177 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9178 alu
.dst
.sel
= ctx
->temp_reg
;
9184 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9189 /* src0 * src1 + (1 - src0) * src2 */
9190 if (ctx
->src
[0].abs
)
9191 temp_regs
[0] = r600_get_temp(ctx
);
9194 if (ctx
->src
[1].abs
)
9195 temp_regs
[1] = r600_get_temp(ctx
);
9199 for (i
= 0; i
< lasti
+ 1; i
++) {
9200 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9203 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9204 alu
.op
= ALU_OP3_MULADD
;
9206 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9209 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
9212 alu
.src
[2].sel
= ctx
->temp_reg
;
9213 alu
.src
[2].chan
= i
;
9215 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9220 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9227 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
9229 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9230 struct r600_bytecode_alu alu
;
9232 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9236 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
9238 ctx
->src
[0].abs
= 0;
9239 ctx
->src
[0].neg
= 0;
9244 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
9246 if (ctx
->src
[j
].abs
)
9247 temp_regs
[j
] = r600_get_temp(ctx
);
9250 for (i
= 0; i
< lasti
+ 1; i
++) {
9251 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9254 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9256 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9259 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
9262 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
9265 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9271 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9278 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9280 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9281 struct r600_bytecode_alu alu
;
9283 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9285 for (i
= 0; i
< lasti
+ 1; i
++) {
9286 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9290 alu
.op
= ALU_OP3_CNDE_INT
;
9291 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9292 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9293 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9294 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9300 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9307 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9309 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9310 struct r600_bytecode_alu alu
;
9314 /* result.x = 2^floor(src); */
9315 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9316 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9318 alu
.op
= ALU_OP1_FLOOR
;
9319 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9321 alu
.dst
.sel
= ctx
->temp_reg
;
9325 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9329 if (ctx
->bc
->chip_class
== CAYMAN
) {
9330 for (i
= 0; i
< 3; i
++) {
9331 alu
.op
= ALU_OP1_EXP_IEEE
;
9332 alu
.src
[0].sel
= ctx
->temp_reg
;
9333 alu
.src
[0].chan
= 0;
9335 alu
.dst
.sel
= ctx
->temp_reg
;
9337 alu
.dst
.write
= i
== 0;
9339 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9344 alu
.op
= ALU_OP1_EXP_IEEE
;
9345 alu
.src
[0].sel
= ctx
->temp_reg
;
9346 alu
.src
[0].chan
= 0;
9348 alu
.dst
.sel
= ctx
->temp_reg
;
9352 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9358 /* result.y = tmp - floor(tmp); */
9359 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9360 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9362 alu
.op
= ALU_OP1_FRACT
;
9363 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9365 alu
.dst
.sel
= ctx
->temp_reg
;
9367 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9376 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9381 /* result.z = RoughApprox2ToX(tmp);*/
9382 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9383 if (ctx
->bc
->chip_class
== CAYMAN
) {
9384 for (i
= 0; i
< 3; i
++) {
9385 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9386 alu
.op
= ALU_OP1_EXP_IEEE
;
9387 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9389 alu
.dst
.sel
= ctx
->temp_reg
;
9396 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9401 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9402 alu
.op
= ALU_OP1_EXP_IEEE
;
9403 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9405 alu
.dst
.sel
= ctx
->temp_reg
;
9411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9417 /* result.w = 1.0;*/
9418 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9419 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9421 alu
.op
= ALU_OP1_MOV
;
9422 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9423 alu
.src
[0].chan
= 0;
9425 alu
.dst
.sel
= ctx
->temp_reg
;
9429 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9433 return tgsi_helper_copy(ctx
, inst
);
9436 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9438 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9439 struct r600_bytecode_alu alu
;
9443 /* result.x = floor(log2(|src|)); */
9444 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9445 if (ctx
->bc
->chip_class
== CAYMAN
) {
9446 for (i
= 0; i
< 3; i
++) {
9447 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9449 alu
.op
= ALU_OP1_LOG_IEEE
;
9450 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9451 r600_bytecode_src_set_abs(&alu
.src
[0]);
9453 alu
.dst
.sel
= ctx
->temp_reg
;
9459 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9465 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9467 alu
.op
= ALU_OP1_LOG_IEEE
;
9468 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9469 r600_bytecode_src_set_abs(&alu
.src
[0]);
9471 alu
.dst
.sel
= ctx
->temp_reg
;
9475 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9480 alu
.op
= ALU_OP1_FLOOR
;
9481 alu
.src
[0].sel
= ctx
->temp_reg
;
9482 alu
.src
[0].chan
= 0;
9484 alu
.dst
.sel
= ctx
->temp_reg
;
9489 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9494 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9495 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9497 if (ctx
->bc
->chip_class
== CAYMAN
) {
9498 for (i
= 0; i
< 3; i
++) {
9499 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9501 alu
.op
= ALU_OP1_LOG_IEEE
;
9502 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9503 r600_bytecode_src_set_abs(&alu
.src
[0]);
9505 alu
.dst
.sel
= ctx
->temp_reg
;
9512 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9517 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9519 alu
.op
= ALU_OP1_LOG_IEEE
;
9520 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9521 r600_bytecode_src_set_abs(&alu
.src
[0]);
9523 alu
.dst
.sel
= ctx
->temp_reg
;
9528 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9533 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9535 alu
.op
= ALU_OP1_FLOOR
;
9536 alu
.src
[0].sel
= ctx
->temp_reg
;
9537 alu
.src
[0].chan
= 1;
9539 alu
.dst
.sel
= ctx
->temp_reg
;
9544 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9548 if (ctx
->bc
->chip_class
== CAYMAN
) {
9549 for (i
= 0; i
< 3; i
++) {
9550 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9551 alu
.op
= ALU_OP1_EXP_IEEE
;
9552 alu
.src
[0].sel
= ctx
->temp_reg
;
9553 alu
.src
[0].chan
= 1;
9555 alu
.dst
.sel
= ctx
->temp_reg
;
9562 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9568 alu
.op
= ALU_OP1_EXP_IEEE
;
9569 alu
.src
[0].sel
= ctx
->temp_reg
;
9570 alu
.src
[0].chan
= 1;
9572 alu
.dst
.sel
= ctx
->temp_reg
;
9577 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9582 if (ctx
->bc
->chip_class
== CAYMAN
) {
9583 for (i
= 0; i
< 3; i
++) {
9584 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9585 alu
.op
= ALU_OP1_RECIP_IEEE
;
9586 alu
.src
[0].sel
= ctx
->temp_reg
;
9587 alu
.src
[0].chan
= 1;
9589 alu
.dst
.sel
= ctx
->temp_reg
;
9596 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9602 alu
.op
= ALU_OP1_RECIP_IEEE
;
9603 alu
.src
[0].sel
= ctx
->temp_reg
;
9604 alu
.src
[0].chan
= 1;
9606 alu
.dst
.sel
= ctx
->temp_reg
;
9611 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9616 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9618 alu
.op
= ALU_OP2_MUL
;
9620 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9621 r600_bytecode_src_set_abs(&alu
.src
[0]);
9623 alu
.src
[1].sel
= ctx
->temp_reg
;
9624 alu
.src
[1].chan
= 1;
9626 alu
.dst
.sel
= ctx
->temp_reg
;
9631 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9636 /* result.z = log2(|src|);*/
9637 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9638 if (ctx
->bc
->chip_class
== CAYMAN
) {
9639 for (i
= 0; i
< 3; i
++) {
9640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9642 alu
.op
= ALU_OP1_LOG_IEEE
;
9643 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9644 r600_bytecode_src_set_abs(&alu
.src
[0]);
9646 alu
.dst
.sel
= ctx
->temp_reg
;
9653 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9658 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9660 alu
.op
= ALU_OP1_LOG_IEEE
;
9661 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9662 r600_bytecode_src_set_abs(&alu
.src
[0]);
9664 alu
.dst
.sel
= ctx
->temp_reg
;
9669 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9675 /* result.w = 1.0; */
9676 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9677 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9679 alu
.op
= ALU_OP1_MOV
;
9680 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9681 alu
.src
[0].chan
= 0;
9683 alu
.dst
.sel
= ctx
->temp_reg
;
9688 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9693 return tgsi_helper_copy(ctx
, inst
);
9696 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9698 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9699 struct r600_bytecode_alu alu
;
9701 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9702 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9704 assert(inst
->Dst
[0].Register
.Index
< 3);
9705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9707 switch (inst
->Instruction
.Opcode
) {
9708 case TGSI_OPCODE_ARL
:
9709 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9711 case TGSI_OPCODE_ARR
:
9712 alu
.op
= ALU_OP1_FLT_TO_INT
;
9714 case TGSI_OPCODE_UARL
:
9715 alu
.op
= ALU_OP1_MOV
;
9722 for (i
= 0; i
<= lasti
; ++i
) {
9723 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9725 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9726 alu
.last
= i
== lasti
;
9730 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9735 if (inst
->Dst
[0].Register
.Index
> 0)
9736 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
9738 ctx
->bc
->ar_loaded
= 0;
9742 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
9744 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9745 struct r600_bytecode_alu alu
;
9747 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9749 switch (inst
->Instruction
.Opcode
) {
9750 case TGSI_OPCODE_ARL
:
9751 memset(&alu
, 0, sizeof(alu
));
9752 alu
.op
= ALU_OP1_FLOOR
;
9753 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9755 for (i
= 0; i
<= lasti
; ++i
) {
9756 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9758 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9759 alu
.last
= i
== lasti
;
9760 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9765 memset(&alu
, 0, sizeof(alu
));
9766 alu
.op
= ALU_OP1_FLT_TO_INT
;
9767 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
9768 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9770 /* FLT_TO_INT is trans-only on r600/r700 */
9772 for (i
= 0; i
<= lasti
; ++i
) {
9774 alu
.src
[0].chan
= i
;
9775 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9779 case TGSI_OPCODE_ARR
:
9780 memset(&alu
, 0, sizeof(alu
));
9781 alu
.op
= ALU_OP1_FLT_TO_INT
;
9782 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9784 /* FLT_TO_INT is trans-only on r600/r700 */
9786 for (i
= 0; i
<= lasti
; ++i
) {
9787 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9789 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9790 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9795 case TGSI_OPCODE_UARL
:
9796 memset(&alu
, 0, sizeof(alu
));
9797 alu
.op
= ALU_OP1_MOV
;
9798 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9800 for (i
= 0; i
<= lasti
; ++i
) {
9801 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9803 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9804 alu
.last
= i
== lasti
;
9805 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9815 ctx
->bc
->ar_loaded
= 0;
9819 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9821 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9822 struct r600_bytecode_alu alu
;
9825 for (i
= 0; i
< 4; i
++) {
9826 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9828 alu
.op
= ALU_OP2_MUL
;
9829 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9831 if (i
== 0 || i
== 3) {
9832 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9834 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9837 if (i
== 0 || i
== 2) {
9838 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9840 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9844 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9851 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
,
9852 struct r600_bytecode_alu_src
*src
)
9854 struct r600_bytecode_alu alu
;
9857 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9859 alu
.execute_mask
= 1;
9860 alu
.update_pred
= 1;
9862 alu
.dst
.sel
= ctx
->temp_reg
;
9867 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9868 alu
.src
[1].chan
= 0;
9872 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9878 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9880 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9884 if (ctx
->bc
->cf_last
) {
9885 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9887 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9892 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9893 ctx
->bc
->force_add_cf
= 1;
9894 } else if (alu_pop
== 2) {
9895 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9896 ctx
->bc
->force_add_cf
= 1;
9903 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9904 ctx
->bc
->cf_last
->pop_count
= pops
;
9905 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9911 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9914 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9918 unsigned entry_size
= stack
->entry_size
;
9920 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9921 elements
+= stack
->push
;
9923 switch (ctx
->bc
->chip_class
) {
9926 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9927 * the stack must be reserved to hold the current active/continue
9929 if (reason
== FC_PUSH_VPM
) {
9935 /* r9xx: any stack operation on empty stack consumes 2 additional
9940 /* FIXME: do the two elements added above cover the cases for the
9944 /* r8xx+: 2 extra elements are not always required, but one extra
9945 * element must be added for each of the following cases:
9946 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9948 * (Currently we don't use ALU_ELSE_AFTER.)
9949 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9950 * PUSH instruction executed.
9952 * NOTE: it seems we also need to reserve additional element in some
9953 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9954 * then STACK_SIZE should be 2 instead of 1 */
9955 if (reason
== FC_PUSH_VPM
) {
9965 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9966 * for all chips, so we use 4 in the final formula, not the real entry_size
9970 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9972 if (entries
> stack
->max_entries
)
9973 stack
->max_entries
= entries
;
9976 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9980 --ctx
->bc
->stack
.push
;
9981 assert(ctx
->bc
->stack
.push
>= 0);
9984 --ctx
->bc
->stack
.push_wqm
;
9985 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9988 --ctx
->bc
->stack
.loop
;
9989 assert(ctx
->bc
->stack
.loop
>= 0);
9997 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
10001 ++ctx
->bc
->stack
.push
;
10004 ++ctx
->bc
->stack
.push_wqm
;
10006 ++ctx
->bc
->stack
.loop
;
10012 callstack_update_max_depth(ctx
, reason
);
10015 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
10017 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
10019 sp
->mid
= realloc((void *)sp
->mid
,
10020 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
10021 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
10025 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
10027 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
10028 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
10029 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
10033 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
10035 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
10045 static int emit_return(struct r600_shader_ctx
*ctx
)
10047 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
10051 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
10054 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
10055 ctx
->bc
->cf_last
->pop_count
= pops
;
10056 /* XXX work out offset */
10060 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
10065 static void emit_testflag(struct r600_shader_ctx
*ctx
)
10070 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
10072 emit_testflag(ctx
);
10073 emit_jump_to_offset(ctx
, 1, 4);
10074 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
10075 pops(ctx
, ifidx
+ 1);
10079 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
10081 emit_testflag(ctx
);
10083 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10084 ctx
->bc
->cf_last
->pop_count
= 1;
10086 fc_set_mid(ctx
, fc_sp
);
10092 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
,
10093 struct r600_bytecode_alu_src
*src
)
10095 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
10097 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
10098 * LOOP_STARTxxx for nested loops may put the branch stack into a state
10099 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
10100 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
10101 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
10102 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
10103 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10104 alu_type
= CF_OP_ALU
;
10107 emit_logic_pred(ctx
, opcode
, alu_type
, src
);
10109 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
10111 fc_pushlevel(ctx
, FC_IF
);
10113 callstack_push(ctx
, FC_PUSH_VPM
);
10117 static int tgsi_if(struct r600_shader_ctx
*ctx
)
10119 struct r600_bytecode_alu_src alu_src
;
10120 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
10122 return emit_if(ctx
, ALU_OP2_PRED_SETNE
, &alu_src
);
10125 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
10127 struct r600_bytecode_alu_src alu_src
;
10128 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
10129 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10132 static int tgsi_else(struct r600_shader_ctx
*ctx
)
10134 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
10135 ctx
->bc
->cf_last
->pop_count
= 1;
10137 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
10138 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
10142 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
10145 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
10146 R600_ERR("if/endif unbalanced in shader\n");
10150 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
10151 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10152 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
10154 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10158 callstack_pop(ctx
, FC_PUSH_VPM
);
10162 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
10164 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
10165 * limited to 4096 iterations, like the other LOOP_* instructions. */
10166 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
10168 fc_pushlevel(ctx
, FC_LOOP
);
10170 /* check stack depth */
10171 callstack_push(ctx
, FC_LOOP
);
10175 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
10179 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
10181 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
10182 R600_ERR("loop/endloop in shader code are not paired.\n");
10186 /* fixup loop pointers - from r600isa
10187 LOOP END points to CF after LOOP START,
10188 LOOP START point to CF after LOOP END
10189 BRK/CONT point to LOOP END CF
10191 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
10193 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10195 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
10196 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
10198 /* XXX add LOOPRET support */
10200 callstack_pop(ctx
, FC_LOOP
);
10204 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
10208 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
10210 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
10215 R600_ERR("Break not inside loop/endloop pair\n");
10219 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10221 fc_set_mid(ctx
, fscp
- 1);
10226 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
10228 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10229 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
10232 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10233 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
10235 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10237 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
10238 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10239 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
10244 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
10246 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10247 struct r600_bytecode_alu alu
;
10249 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10252 for (i
= 0; i
< lasti
+ 1; i
++) {
10253 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10259 alu
.dst
.sel
= ctx
->temp_reg
;
10262 alu
.op
= ALU_OP2_MULLO_UINT
;
10263 for (j
= 0; j
< 2; j
++) {
10264 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10268 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10274 for (i
= 0; i
< lasti
+ 1; i
++) {
10275 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10278 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10279 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10281 alu
.op
= ALU_OP2_ADD_INT
;
10283 alu
.src
[0].sel
= ctx
->temp_reg
;
10284 alu
.src
[0].chan
= i
;
10286 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10290 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10297 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10299 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10300 struct r600_bytecode_alu alu
;
10302 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10304 /* temp.xy = f32_to_f16(src) */
10305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10306 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10308 alu
.dst
.sel
= ctx
->temp_reg
;
10310 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10311 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10315 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10317 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10321 /* dst.x = temp.y * 0x10000 + temp.x */
10322 for (i
= 0; i
< lasti
+ 1; i
++) {
10323 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10326 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10327 alu
.op
= ALU_OP3_MULADD_UINT24
;
10329 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10330 alu
.last
= i
== lasti
;
10331 alu
.src
[0].sel
= ctx
->temp_reg
;
10332 alu
.src
[0].chan
= 1;
10333 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10334 alu
.src
[1].value
= 0x10000;
10335 alu
.src
[2].sel
= ctx
->temp_reg
;
10336 alu
.src
[2].chan
= 0;
10337 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10345 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10347 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10348 struct r600_bytecode_alu alu
;
10350 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10352 /* temp.x = src.x */
10353 /* note: no need to mask out the high bits */
10354 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10355 alu
.op
= ALU_OP1_MOV
;
10357 alu
.dst
.sel
= ctx
->temp_reg
;
10359 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10360 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10364 /* temp.y = src.x >> 16 */
10365 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10366 alu
.op
= ALU_OP2_LSHR_INT
;
10368 alu
.dst
.sel
= ctx
->temp_reg
;
10370 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10371 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10372 alu
.src
[1].value
= 16;
10374 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10378 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10379 for (i
= 0; i
< lasti
+ 1; i
++) {
10380 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10382 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10383 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10384 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10385 alu
.src
[0].sel
= ctx
->temp_reg
;
10386 alu
.src
[0].chan
= i
% 2;
10387 alu
.last
= i
== lasti
;
10388 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10396 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10398 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10399 struct r600_bytecode_alu alu
;
10400 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10404 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10405 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10406 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10407 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10408 dst
= r600_get_temp(ctx
);
10410 r
= tgsi_op3_dst(ctx
, dst
);
10414 for (i
= 0; i
< lasti
+ 1; i
++) {
10415 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10416 alu
.op
= ALU_OP2_SETGE_INT
;
10417 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10418 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10419 alu
.src
[1].value
= 32;
10420 alu
.dst
.sel
= ctx
->temp_reg
;
10425 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10430 for (i
= 0; i
< lasti
+ 1; i
++) {
10431 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10432 alu
.op
= ALU_OP3_CNDE_INT
;
10434 alu
.src
[0].sel
= ctx
->temp_reg
;
10435 alu
.src
[0].chan
= i
;
10437 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10439 alu
.src
[1].sel
= dst
;
10441 alu
.src
[1].sel
= alu
.dst
.sel
;
10442 alu
.src
[1].chan
= i
;
10443 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10447 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10455 static int tgsi_clock(struct r600_shader_ctx
*ctx
)
10457 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10458 struct r600_bytecode_alu alu
;
10461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10462 alu
.op
= ALU_OP1_MOV
;
10463 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10464 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_LO
;
10465 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10469 alu
.op
= ALU_OP1_MOV
;
10470 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10471 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_HI
;
10472 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10478 static int emit_u64add(struct r600_shader_ctx
*ctx
, int op
,
10480 int src0_sel
, int src0_chan
,
10481 int src1_sel
, int src1_chan
)
10483 struct r600_bytecode_alu alu
;
10487 if (op
== ALU_OP2_ADD_INT
)
10488 opc
= ALU_OP2_ADDC_UINT
;
10490 opc
= ALU_OP2_SUBB_UINT
;
10492 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10494 alu
.dst
.sel
= treg
;
10497 alu
.src
[0].sel
= src0_sel
;
10498 alu
.src
[0].chan
= src0_chan
+ 0;
10499 alu
.src
[1].sel
= src1_sel
;
10500 alu
.src
[1].chan
= src1_chan
+ 0;
10501 alu
.src
[1].neg
= 0;
10502 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10508 alu
.dst
.sel
= treg
;
10511 alu
.src
[0].sel
= src0_sel
;
10512 alu
.src
[0].chan
= src0_chan
+ 1;
10513 alu
.src
[1].sel
= src1_sel
;
10514 alu
.src
[1].chan
= src1_chan
+ 1;
10515 alu
.src
[1].neg
= 0;
10516 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10522 alu
.dst
.sel
= treg
;
10526 alu
.src
[0].sel
= src0_sel
;
10527 alu
.src
[0].chan
= src0_chan
+ 0;
10528 alu
.src
[1].sel
= src1_sel
;
10529 alu
.src
[1].chan
= src1_chan
+ 0;
10530 alu
.src
[1].neg
= 0;
10531 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10535 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10537 alu
.dst
.sel
= treg
;
10540 alu
.src
[0].sel
= treg
;
10541 alu
.src
[0].chan
= 1;
10542 alu
.src
[1].sel
= treg
;
10543 alu
.src
[1].chan
= 2;
10545 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10551 static int egcm_u64add(struct r600_shader_ctx
*ctx
)
10553 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10554 struct r600_bytecode_alu alu
;
10556 int treg
= ctx
->temp_reg
;
10557 int op
= ALU_OP2_ADD_INT
, opc
= ALU_OP2_ADDC_UINT
;
10559 if (ctx
->src
[1].neg
) {
10560 op
= ALU_OP2_SUB_INT
;
10561 opc
= ALU_OP2_SUBB_UINT
;
10563 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10565 alu
.dst
.sel
= treg
;
10568 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10569 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10570 alu
.src
[1].neg
= 0;
10571 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10575 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10577 alu
.dst
.sel
= treg
;
10580 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10581 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10582 alu
.src
[1].neg
= 0;
10583 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10587 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10589 alu
.dst
.sel
= treg
;
10593 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10594 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10595 alu
.src
[1].neg
= 0;
10596 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10602 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10603 alu
.src
[0].sel
= treg
;
10604 alu
.src
[0].chan
= 1;
10605 alu
.src
[1].sel
= treg
;
10606 alu
.src
[1].chan
= 2;
10608 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10612 alu
.op
= ALU_OP1_MOV
;
10613 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10614 alu
.src
[0].sel
= treg
;
10615 alu
.src
[0].chan
= 0;
10617 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10623 /* result.y = mul_high a, b
10625 result.y += a.x * b.y + a.y * b.x;
10627 static int egcm_u64mul(struct r600_shader_ctx
*ctx
)
10629 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10630 struct r600_bytecode_alu alu
;
10632 int treg
= ctx
->temp_reg
;
10634 /* temp.x = mul_lo a.x, b.x */
10635 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10636 alu
.op
= ALU_OP2_MULLO_UINT
;
10637 alu
.dst
.sel
= treg
;
10640 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10641 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10642 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10646 /* temp.y = mul_hi a.x, b.x */
10647 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10648 alu
.op
= ALU_OP2_MULHI_UINT
;
10649 alu
.dst
.sel
= treg
;
10652 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10653 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10654 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10658 /* temp.z = mul a.x, b.y */
10659 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10660 alu
.op
= ALU_OP2_MULLO_UINT
;
10661 alu
.dst
.sel
= treg
;
10664 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10665 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10666 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10670 /* temp.w = mul a.y, b.x */
10671 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10672 alu
.op
= ALU_OP2_MULLO_UINT
;
10673 alu
.dst
.sel
= treg
;
10676 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10677 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10678 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10682 /* temp.z = temp.z + temp.w */
10683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10684 alu
.op
= ALU_OP2_ADD_INT
;
10685 alu
.dst
.sel
= treg
;
10688 alu
.src
[0].sel
= treg
;
10689 alu
.src
[0].chan
= 2;
10690 alu
.src
[1].sel
= treg
;
10691 alu
.src
[1].chan
= 3;
10693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10697 /* temp.y = temp.y + temp.z */
10698 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10699 alu
.op
= ALU_OP2_ADD_INT
;
10700 alu
.dst
.sel
= treg
;
10703 alu
.src
[0].sel
= treg
;
10704 alu
.src
[0].chan
= 1;
10705 alu
.src
[1].sel
= treg
;
10706 alu
.src
[1].chan
= 2;
10708 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10712 /* dst.x = temp.x */
10713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10714 alu
.op
= ALU_OP1_MOV
;
10715 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10716 alu
.src
[0].sel
= treg
;
10717 alu
.src
[0].chan
= 0;
10718 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10722 /* dst.y = temp.y */
10723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10724 alu
.op
= ALU_OP1_MOV
;
10725 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10726 alu
.src
[0].sel
= treg
;
10727 alu
.src
[0].chan
= 1;
10729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10736 static int emit_u64sge(struct r600_shader_ctx
*ctx
,
10738 int src0_sel
, int src0_base_chan
,
10739 int src1_sel
, int src1_base_chan
)
10742 /* for 64-bit sge */
10743 /* result = (src0.y > src1.y) || ((src0.y == src1.y) && src0.x >= src1.x)) */
10744 r
= single_alu_op2(ctx
, ALU_OP2_SETGT_UINT
,
10746 src0_sel
, src0_base_chan
+ 1,
10747 src1_sel
, src1_base_chan
+ 1);
10751 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10753 src0_sel
, src0_base_chan
,
10754 src1_sel
, src1_base_chan
);
10758 r
= single_alu_op2(ctx
, ALU_OP2_SETE_INT
,
10760 src0_sel
, src0_base_chan
+ 1,
10761 src1_sel
, src1_base_chan
+ 1);
10765 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10772 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10781 /* this isn't a complete div it's just enough for qbo shader to work */
10782 static int egcm_u64div(struct r600_shader_ctx
*ctx
)
10784 struct r600_bytecode_alu alu
;
10785 struct r600_bytecode_alu_src alu_num_hi
, alu_num_lo
, alu_denom_hi
, alu_denom_lo
, alu_src
;
10787 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10789 /* make sure we are dividing my a const with 0 in the high bits */
10790 if (ctx
->src
[1].sel
!= V_SQ_ALU_SRC_LITERAL
)
10792 if (ctx
->src
[1].value
[ctx
->src
[1].swizzle
[1]] != 0)
10794 /* make sure we are doing one division */
10795 if (inst
->Dst
[0].Register
.WriteMask
!= 0x3)
10798 /* emit_if uses ctx->temp_reg so we can't */
10799 int treg
= r600_get_temp(ctx
);
10800 int tmp_num
= r600_get_temp(ctx
);
10801 int sub_tmp
= r600_get_temp(ctx
);
10803 /* tmp quot are tmp_num.zw */
10804 r600_bytecode_src(&alu_num_lo
, &ctx
->src
[0], 0);
10805 r600_bytecode_src(&alu_num_hi
, &ctx
->src
[0], 1);
10806 r600_bytecode_src(&alu_denom_lo
, &ctx
->src
[1], 0);
10807 r600_bytecode_src(&alu_denom_hi
, &ctx
->src
[1], 1);
10809 /* MOV tmp_num.xy, numerator */
10810 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10812 alu_num_lo
.sel
, alu_num_lo
.chan
,
10816 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10818 alu_num_hi
.sel
, alu_num_hi
.chan
,
10823 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10825 V_SQ_ALU_SRC_LITERAL
, 0,
10830 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10832 V_SQ_ALU_SRC_LITERAL
, 0,
10837 /* treg 0 is log2_denom */
10838 /* normally this gets the MSB for the denom high value
10839 - however we know this will always be 0 here. */
10840 r
= single_alu_op2(ctx
,
10843 V_SQ_ALU_SRC_LITERAL
, 32,
10848 /* normally check demon hi for 0, but we know it is already */
10849 /* t0.z = num_hi >= denom_lo */
10850 r
= single_alu_op2(ctx
,
10851 ALU_OP2_SETGE_UINT
,
10853 alu_num_hi
.sel
, alu_num_hi
.chan
,
10854 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10858 memset(&alu_src
, 0, sizeof(alu_src
));
10859 alu_src
.sel
= treg
;
10861 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10865 /* for loops in here */
10866 /* get msb t0.x = msb(src[1].x) first */
10867 int msb_lo
= util_last_bit(alu_denom_lo
.value
);
10868 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10870 V_SQ_ALU_SRC_LITERAL
, msb_lo
,
10875 /* unroll the asm here */
10876 for (i
= 0; i
< 31; i
++) {
10877 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10879 V_SQ_ALU_SRC_LITERAL
, i
,
10884 /* we can do this on the CPU */
10885 uint32_t denom_lo_shl
= alu_denom_lo
.value
<< (31 - i
);
10886 /* t0.z = tmp_num.y >= t0.z */
10887 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10890 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
10894 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10901 memset(&alu_src
, 0, sizeof(alu_src
));
10902 alu_src
.sel
= treg
;
10904 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10908 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
10911 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
10915 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10918 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
10922 r
= tgsi_endif(ctx
);
10927 /* log2_denom is always <= 31, so manually peel the last loop
10930 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10933 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10937 memset(&alu_src
, 0, sizeof(alu_src
));
10938 alu_src
.sel
= treg
;
10940 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10944 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
10947 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10951 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10954 V_SQ_ALU_SRC_LITERAL
, 1U);
10957 r
= tgsi_endif(ctx
);
10961 r
= tgsi_endif(ctx
);
10965 /* onto the second loop to unroll */
10966 for (i
= 0; i
< 31; i
++) {
10967 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10969 V_SQ_ALU_SRC_LITERAL
, (63 - (31 - i
)),
10974 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
<< (31 - i
);
10975 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10977 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
10982 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10984 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
10989 r
= emit_u64sge(ctx
, sub_tmp
,
10995 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11002 memset(&alu_src
, 0, sizeof(alu_src
));
11003 alu_src
.sel
= treg
;
11005 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11010 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
11017 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11024 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11031 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11034 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
11038 r
= tgsi_endif(ctx
);
11043 /* log2_denom is always <= 63, so manually peel the last loop
11046 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
;
11047 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11049 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
11054 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11056 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
11061 r
= emit_u64sge(ctx
, sub_tmp
,
11067 memset(&alu_src
, 0, sizeof(alu_src
));
11068 alu_src
.sel
= sub_tmp
;
11070 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11074 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
11081 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11084 V_SQ_ALU_SRC_LITERAL
, 1U);
11087 r
= tgsi_endif(ctx
);
11091 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11092 alu
.op
= ALU_OP1_MOV
;
11093 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11094 alu
.src
[0].sel
= tmp_num
;
11095 alu
.src
[0].chan
= 2;
11096 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11100 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11101 alu
.op
= ALU_OP1_MOV
;
11102 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
11103 alu
.src
[0].sel
= tmp_num
;
11104 alu
.src
[0].chan
= 3;
11106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11112 static int egcm_u64sne(struct r600_shader_ctx
*ctx
)
11114 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
11115 struct r600_bytecode_alu alu
;
11117 int treg
= ctx
->temp_reg
;
11119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11120 alu
.op
= ALU_OP2_SETNE_INT
;
11121 alu
.dst
.sel
= treg
;
11124 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11125 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11126 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11130 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11131 alu
.op
= ALU_OP2_SETNE_INT
;
11132 alu
.dst
.sel
= treg
;
11135 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
11136 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
11138 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11143 alu
.op
= ALU_OP2_OR_INT
;
11144 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11145 alu
.src
[0].sel
= treg
;
11146 alu
.src
[0].chan
= 0;
11147 alu
.src
[1].sel
= treg
;
11148 alu
.src
[1].chan
= 1;
11150 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11156 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
11157 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11158 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11159 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11161 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11163 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11164 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11165 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11166 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11167 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11168 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11169 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11170 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11171 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
11172 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11173 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11174 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11175 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11176 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11177 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11178 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11179 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11180 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11181 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11182 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11183 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11184 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11185 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11186 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11187 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11188 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11189 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11190 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11191 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11192 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11193 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11194 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11195 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11196 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11197 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11198 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11199 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11200 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11201 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11202 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11203 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11204 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11205 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11206 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11207 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11208 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11209 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11210 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11211 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11212 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11213 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11214 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11215 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11216 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11217 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11218 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11219 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11220 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11221 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11222 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11223 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11224 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11225 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11226 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11227 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11228 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11229 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11230 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11231 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11232 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11233 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11234 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11235 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11236 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11237 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11238 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11239 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11240 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
11241 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11242 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11243 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11244 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11245 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11246 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
11247 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11248 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11249 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11250 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11251 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11252 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11253 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11254 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11255 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11256 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11257 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11258 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11259 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11260 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11261 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11262 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11263 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11264 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11265 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11266 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11267 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11268 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11269 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11270 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11271 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11272 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11273 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11274 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11275 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11276 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11277 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11278 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
11279 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11280 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11281 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11282 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11283 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11284 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
11285 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11286 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
11287 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11288 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11289 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11290 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11291 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11292 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11293 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11294 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11295 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11296 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11297 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
11298 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11299 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
11300 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11301 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11302 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11303 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11304 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11305 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11306 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11307 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11308 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11309 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11310 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11311 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11312 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11313 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11314 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11315 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11316 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
11317 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11318 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11319 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11320 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11321 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11322 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11323 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11324 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11325 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11326 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11327 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11328 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11329 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11330 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11331 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11332 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11333 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11334 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11335 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11336 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11337 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11338 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11339 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11340 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11341 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
11342 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
11343 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
11344 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
11345 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11346 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
11347 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
11348 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
11349 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
11350 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
11351 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11352 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11353 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11354 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11357 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
11358 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11359 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11360 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11361 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11362 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11363 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11364 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11365 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11366 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11367 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11368 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11369 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11370 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11371 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11372 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11373 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11374 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11375 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11376 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11377 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11378 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11379 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11380 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11381 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11382 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11383 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11384 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11385 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11386 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11387 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11388 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11389 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11390 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11391 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11392 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11393 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11394 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11395 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11396 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11397 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11398 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11399 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11400 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11401 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11402 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11403 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11404 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11405 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11406 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11407 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11408 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11409 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11410 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11411 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11412 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11413 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11414 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11415 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11416 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11417 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11418 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11419 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11420 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11421 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11422 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11423 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11424 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11425 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11426 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11427 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11428 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11429 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11430 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11431 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11432 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11433 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11434 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11435 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11436 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11437 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11438 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11439 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11440 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11441 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11442 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11443 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11444 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11445 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11446 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11447 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11448 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11449 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11450 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11451 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11452 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11453 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11454 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11455 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11456 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11457 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11458 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11459 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11460 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11461 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11462 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11463 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11464 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11465 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11466 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11467 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11468 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11469 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11470 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11471 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11472 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11473 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11474 /* Refer below for TGSI_OPCODE_DFMA */
11475 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
11476 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11477 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11478 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11479 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11480 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11481 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11482 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11483 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
11484 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11485 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11486 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11487 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11488 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11489 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11490 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11491 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11492 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11493 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11494 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11495 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11496 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11497 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11498 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11499 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11500 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11501 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11502 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11503 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11504 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11505 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11506 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11507 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11508 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11509 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11510 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11511 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11512 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11513 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11514 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11515 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11516 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11517 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11518 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11519 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11520 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11521 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11522 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11523 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11524 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11525 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11526 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11527 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11528 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11529 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11530 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11531 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11532 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11533 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11534 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11535 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11536 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11537 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11538 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11539 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11540 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11541 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11542 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11543 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11544 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11545 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11546 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11547 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11548 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11549 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11550 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11551 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11552 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11553 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11554 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11555 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11556 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11557 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11558 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11559 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11560 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11561 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11562 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11563 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11564 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11565 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11566 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11567 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11568 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11569 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11570 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11571 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11572 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11573 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11574 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11575 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11576 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11577 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11578 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11579 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11580 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11583 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
11584 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11585 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11586 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11587 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
11588 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
11589 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11590 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11591 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11592 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11593 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11594 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11595 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11596 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11597 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11598 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11599 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11600 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11601 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11602 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11603 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
11604 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11605 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11606 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11607 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11608 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11609 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11610 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11611 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
11612 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
11613 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
11614 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11615 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11616 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11617 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11618 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11619 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
11620 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11621 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11622 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11623 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11624 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11625 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11626 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11627 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11628 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11629 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11630 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11631 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
11632 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11633 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11634 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11635 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11636 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11637 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11638 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11639 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11640 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11641 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11642 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11643 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11644 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11645 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11646 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11647 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11648 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11649 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11650 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11651 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11652 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11653 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11654 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11655 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11656 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11657 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11658 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11659 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11660 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11661 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11662 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11663 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11664 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11665 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11666 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
11667 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11668 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11669 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11670 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11671 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11672 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11673 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11674 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11675 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11676 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11677 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11678 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11679 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11680 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11681 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11682 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11683 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11684 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11685 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11686 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11687 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11688 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11689 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11690 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11691 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11692 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11693 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11694 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11695 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11696 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11697 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11698 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11699 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11700 /* Refer below for TGSI_OPCODE_DFMA */
11701 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
11702 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11703 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11704 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11705 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11706 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11707 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11708 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11709 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
11710 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
11711 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11712 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11713 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11714 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11715 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11716 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11717 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
11718 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11719 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11720 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11721 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11722 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11723 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11724 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11725 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11726 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11727 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11728 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11729 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11730 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11731 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11732 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11733 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11734 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11735 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11736 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11737 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11738 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11739 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11740 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11741 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11742 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11743 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11744 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11745 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11746 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11747 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11748 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11749 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11750 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11751 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11752 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11753 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11754 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11755 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11756 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11757 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11758 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11759 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11760 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11761 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11762 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
11763 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
11764 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11765 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11766 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11767 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11768 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11769 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11770 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11771 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11772 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11773 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11774 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11775 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11776 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11777 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11778 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11779 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11780 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11781 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11782 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11783 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11784 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11785 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11786 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11787 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11788 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11789 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11790 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11791 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11792 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11793 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11794 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11795 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11796 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11797 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11798 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11799 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11800 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11801 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11802 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11803 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11804 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11805 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11806 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},