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
;
3347 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3348 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3349 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3350 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3352 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3353 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3354 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3355 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3356 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3357 ctx
.tess_input_info
= 0;
3358 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3359 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3360 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3361 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3362 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3363 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3364 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3365 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3366 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3367 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3368 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3371 ctx
.gs_rotated_input
[0] = 0;
3372 ctx
.gs_rotated_input
[1] = 1;
3375 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3378 if (shader
->uses_images
) {
3379 ctx
.thread_id_gpr
= ctx
.temp_reg
++;
3380 ctx
.thread_id_gpr_loaded
= false;
3383 shader
->max_arrays
= 0;
3384 shader
->num_arrays
= 0;
3385 if (indirect_gprs
) {
3387 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3388 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3389 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3390 ctx
.file_offset
[TGSI_FILE_INPUT
],
3393 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3394 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3395 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3396 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3402 ctx
.literals
= NULL
;
3403 ctx
.max_driver_temp_used
= 0;
3405 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3406 ctx
.info
.colors_written
== 1;
3407 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3408 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3410 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3411 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3412 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3413 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3414 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3415 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3416 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3419 if (shader
->vs_as_gs_a
)
3420 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3422 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3423 r600_fetch_tess_io_info(&ctx
);
3425 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3426 tgsi_parse_token(&ctx
.parse
);
3427 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3428 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3429 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3430 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3431 if(ctx
.literals
== NULL
) {
3435 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3436 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3437 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3438 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3441 case TGSI_TOKEN_TYPE_DECLARATION
:
3442 r
= tgsi_declaration(&ctx
);
3446 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3447 case TGSI_TOKEN_TYPE_PROPERTY
:
3450 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3456 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3457 shader
->ring_item_sizes
[1] = 0;
3458 shader
->ring_item_sizes
[2] = 0;
3459 shader
->ring_item_sizes
[3] = 0;
3461 /* Process two side if needed */
3462 if (shader
->two_side
&& ctx
.colors_used
) {
3463 int i
, count
= ctx
.shader
->ninput
;
3464 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3466 /* additional inputs will be allocated right after the existing inputs,
3467 * we won't need them after the color selection, so we don't need to
3468 * reserve these gprs for the rest of the shader code and to adjust
3469 * output offsets etc. */
3470 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3471 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3473 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3474 if (ctx
.face_gpr
== -1) {
3475 i
= ctx
.shader
->ninput
++;
3476 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3477 ctx
.shader
->input
[i
].spi_sid
= 0;
3478 ctx
.shader
->input
[i
].gpr
= gpr
++;
3479 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3482 for (i
= 0; i
< count
; i
++) {
3483 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3484 int ni
= ctx
.shader
->ninput
++;
3485 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3486 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3487 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3488 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3489 // TGSI to LLVM needs to know the lds position of inputs.
3490 // Non LLVM path computes it later (in process_twoside_color)
3491 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3492 ctx
.shader
->input
[i
].back_color_input
= ni
;
3493 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3494 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3501 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3502 shader
->nr_ps_max_color_exports
= 8;
3504 if (ctx
.shader
->uses_helper_invocation
) {
3505 if (ctx
.bc
->chip_class
== CAYMAN
)
3506 r
= cm_load_helper_invocation(&ctx
);
3508 r
= eg_load_helper_invocation(&ctx
);
3514 * XXX this relies on fixed_pt_position_gpr only being present when
3515 * this shader should be executed per sample. Should be the case for now...
3517 if (ctx
.fixed_pt_position_gpr
!= -1 && ctx
.info
.reads_samplemask
) {
3519 * Fix up sample mask. The hw always gives us coverage mask for
3520 * the pixel. However, for per-sample shading, we need the
3521 * coverage for the shader invocation only.
3522 * Also, with disabled msaa, only the first bit should be set
3523 * (luckily the same fixup works for both problems).
3524 * For now, we can only do it if we know this shader is always
3525 * executed per sample (due to usage of bits in the shader
3526 * forcing per-sample execution).
3527 * If the fb is not multisampled, we'd do unnecessary work but
3528 * it should still be correct.
3529 * It will however do nothing for sample shading according
3530 * to MinSampleShading.
3532 struct r600_bytecode_alu alu
;
3533 int tmp
= r600_get_temp(&ctx
);
3534 assert(ctx
.face_gpr
!= -1);
3535 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3537 alu
.op
= ALU_OP2_LSHL_INT
;
3538 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3539 alu
.src
[0].value
= 0x1;
3540 alu
.src
[1].sel
= ctx
.fixed_pt_position_gpr
;
3541 alu
.src
[1].chan
= 3;
3546 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3550 alu
.op
= ALU_OP2_AND_INT
;
3551 alu
.src
[0].sel
= tmp
;
3552 alu
.src
[1].sel
= ctx
.face_gpr
;
3553 alu
.src
[1].chan
= 2;
3554 alu
.dst
.sel
= ctx
.face_gpr
;
3558 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3562 if (ctx
.fragcoord_input
>= 0) {
3563 if (ctx
.bc
->chip_class
== CAYMAN
) {
3564 for (j
= 0 ; j
< 4; j
++) {
3565 struct r600_bytecode_alu alu
;
3566 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3567 alu
.op
= ALU_OP1_RECIP_IEEE
;
3568 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3569 alu
.src
[0].chan
= 3;
3571 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3573 alu
.dst
.write
= (j
== 3);
3575 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3579 struct r600_bytecode_alu alu
;
3580 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3581 alu
.op
= ALU_OP1_RECIP_IEEE
;
3582 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3583 alu
.src
[0].chan
= 3;
3585 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3589 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3594 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3595 struct r600_bytecode_alu alu
;
3598 /* GS thread with no output workaround - emit a cut at start of GS */
3599 if (ctx
.bc
->chip_class
== R600
)
3600 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3602 for (j
= 0; j
< 4; j
++) {
3603 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3604 alu
.op
= ALU_OP1_MOV
;
3605 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3606 alu
.src
[0].value
= 0;
3607 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3610 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3615 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3616 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3617 ctx
.gs_rotated_input
[0], 2,
3619 V_SQ_ALU_SRC_LITERAL
, 1);
3623 for (i
= 0; i
< 6; i
++) {
3624 int rotated
= (i
+ 4) % 6;
3625 int offset_reg
= i
/ 3;
3626 int offset_chan
= i
% 3;
3627 int rotated_offset_reg
= rotated
/ 3;
3628 int rotated_offset_chan
= rotated
% 3;
3630 if (offset_reg
== 0 && offset_chan
== 2)
3632 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3633 rotated_offset_chan
= 3;
3635 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3636 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3637 ctx
.gs_rotated_input
[0], 2,
3638 offset_reg
, offset_chan
,
3639 rotated_offset_reg
, rotated_offset_chan
);
3646 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3647 r600_fetch_tess_io_info(&ctx
);
3649 if (shader
->two_side
&& ctx
.colors_used
) {
3650 if ((r
= process_twoside_color_inputs(&ctx
)))
3654 tgsi_parse_init(&ctx
.parse
, tokens
);
3655 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3656 tgsi_parse_token(&ctx
.parse
);
3657 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3658 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3659 r
= tgsi_is_supported(&ctx
);
3662 ctx
.max_driver_temp_used
= 0;
3663 /* reserve first tmp for everyone */
3664 r600_get_temp(&ctx
);
3666 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3667 if ((r
= tgsi_split_constant(&ctx
)))
3669 if ((r
= tgsi_split_literal_constant(&ctx
)))
3671 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3672 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3674 } else if (lds_inputs
) {
3675 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3678 if (ctx
.bc
->chip_class
== CAYMAN
)
3679 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3680 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3681 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3683 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3684 r
= ctx
.inst_info
->process(&ctx
);
3688 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3689 r
= r600_store_tcs_output(&ctx
);
3699 /* Reset the temporary register counter. */
3700 ctx
.max_driver_temp_used
= 0;
3702 noutput
= shader
->noutput
;
3704 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3705 unsigned clipdist_temp
[2];
3707 clipdist_temp
[0] = r600_get_temp(&ctx
);
3708 clipdist_temp
[1] = r600_get_temp(&ctx
);
3710 /* need to convert a clipvertex write into clipdistance writes and not export
3711 the clip vertex anymore */
3713 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3714 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3715 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3717 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3718 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3721 /* reset spi_sid for clipvertex output to avoid confusing spi */
3722 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3724 shader
->clip_dist_write
= 0xFF;
3725 shader
->cc_dist_mask
= 0xFF;
3727 for (i
= 0; i
< 8; i
++) {
3731 for (j
= 0; j
< 4; j
++) {
3732 struct r600_bytecode_alu alu
;
3733 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3734 alu
.op
= ALU_OP2_DOT4
;
3735 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3736 alu
.src
[0].chan
= j
;
3738 alu
.src
[1].sel
= 512 + i
;
3739 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3740 alu
.src
[1].chan
= j
;
3742 alu
.dst
.sel
= clipdist_temp
[oreg
];
3744 alu
.dst
.write
= (j
== ochan
);
3747 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3754 /* Add stream outputs. */
3755 if (so
.num_outputs
) {
3757 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3759 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3762 emit_streamout(&ctx
, &so
, -1, NULL
);
3764 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3765 convert_edgeflag_to_int(&ctx
);
3767 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3768 r600_emit_tess_factor(&ctx
);
3771 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3772 if (ctx
.shader
->noutput
)
3773 emit_lds_vs_writes(&ctx
);
3775 } else if (ring_outputs
) {
3776 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3777 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3778 ctx
.gs_export_gpr_tregs
[1] = -1;
3779 ctx
.gs_export_gpr_tregs
[2] = -1;
3780 ctx
.gs_export_gpr_tregs
[3] = -1;
3782 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3786 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3788 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3789 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3790 output
[j
].gpr
= shader
->output
[i
].gpr
;
3791 output
[j
].elem_size
= 3;
3792 output
[j
].swizzle_x
= 0;
3793 output
[j
].swizzle_y
= 1;
3794 output
[j
].swizzle_z
= 2;
3795 output
[j
].swizzle_w
= 3;
3796 output
[j
].burst_count
= 1;
3797 output
[j
].type
= 0xffffffff;
3798 output
[j
].op
= CF_OP_EXPORT
;
3800 case PIPE_SHADER_VERTEX
:
3801 case PIPE_SHADER_TESS_EVAL
:
3802 switch (shader
->output
[i
].name
) {
3803 case TGSI_SEMANTIC_POSITION
:
3804 output
[j
].array_base
= 60;
3805 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3809 case TGSI_SEMANTIC_PSIZE
:
3810 output
[j
].array_base
= 61;
3811 output
[j
].swizzle_y
= 7;
3812 output
[j
].swizzle_z
= 7;
3813 output
[j
].swizzle_w
= 7;
3814 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3817 case TGSI_SEMANTIC_EDGEFLAG
:
3818 output
[j
].array_base
= 61;
3819 output
[j
].swizzle_x
= 7;
3820 output
[j
].swizzle_y
= 0;
3821 output
[j
].swizzle_z
= 7;
3822 output
[j
].swizzle_w
= 7;
3823 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3826 case TGSI_SEMANTIC_LAYER
:
3827 /* spi_sid is 0 for outputs that are
3828 * not consumed by PS */
3829 if (shader
->output
[i
].spi_sid
) {
3830 output
[j
].array_base
= next_param_base
++;
3831 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3833 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3835 output
[j
].array_base
= 61;
3836 output
[j
].swizzle_x
= 7;
3837 output
[j
].swizzle_y
= 7;
3838 output
[j
].swizzle_z
= 0;
3839 output
[j
].swizzle_w
= 7;
3840 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3843 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3844 /* spi_sid is 0 for outputs that are
3845 * not consumed by PS */
3846 if (shader
->output
[i
].spi_sid
) {
3847 output
[j
].array_base
= next_param_base
++;
3848 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3850 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3852 output
[j
].array_base
= 61;
3853 output
[j
].swizzle_x
= 7;
3854 output
[j
].swizzle_y
= 7;
3855 output
[j
].swizzle_z
= 7;
3856 output
[j
].swizzle_w
= 0;
3857 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3860 case TGSI_SEMANTIC_CLIPVERTEX
:
3863 case TGSI_SEMANTIC_CLIPDIST
:
3864 output
[j
].array_base
= next_clip_base
++;
3865 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3867 /* spi_sid is 0 for clipdistance outputs that were generated
3868 * for clipvertex - we don't need to pass them to PS */
3869 if (shader
->output
[i
].spi_sid
) {
3871 /* duplicate it as PARAM to pass to the pixel shader */
3872 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3873 output
[j
].array_base
= next_param_base
++;
3874 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3877 case TGSI_SEMANTIC_FOG
:
3878 output
[j
].swizzle_y
= 4; /* 0 */
3879 output
[j
].swizzle_z
= 4; /* 0 */
3880 output
[j
].swizzle_w
= 5; /* 1 */
3882 case TGSI_SEMANTIC_PRIMID
:
3883 output
[j
].swizzle_x
= 2;
3884 output
[j
].swizzle_y
= 4; /* 0 */
3885 output
[j
].swizzle_z
= 4; /* 0 */
3886 output
[j
].swizzle_w
= 4; /* 0 */
3891 case PIPE_SHADER_FRAGMENT
:
3892 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3893 /* never export more colors than the number of CBs */
3894 if (shader
->output
[i
].sid
>= max_color_exports
) {
3899 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3900 output
[j
].array_base
= shader
->output
[i
].sid
;
3901 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3902 shader
->nr_ps_color_exports
++;
3903 shader
->ps_color_export_mask
|= (0xf << (shader
->output
[i
].sid
* 4));
3905 /* If the i-th target format is set, all previous target formats must
3906 * be non-zero to avoid hangs. - from radeonsi, seems to apply to eg as well.
3908 if (shader
->output
[i
].sid
> 0)
3909 for (unsigned x
= 0; x
< shader
->output
[i
].sid
; x
++)
3910 shader
->ps_color_export_mask
|= (1 << (x
*4));
3912 if (shader
->output
[i
].sid
> shader
->ps_export_highest
)
3913 shader
->ps_export_highest
= shader
->output
[i
].sid
;
3914 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3915 for (k
= 1; k
< max_color_exports
; k
++) {
3917 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3918 output
[j
].gpr
= shader
->output
[i
].gpr
;
3919 output
[j
].elem_size
= 3;
3920 output
[j
].swizzle_x
= 0;
3921 output
[j
].swizzle_y
= 1;
3922 output
[j
].swizzle_z
= 2;
3923 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3924 output
[j
].burst_count
= 1;
3925 output
[j
].array_base
= k
;
3926 output
[j
].op
= CF_OP_EXPORT
;
3927 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3928 shader
->nr_ps_color_exports
++;
3929 shader
->ps_color_export_mask
|= (0xf << (j
* 4));
3932 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3933 output
[j
].array_base
= 61;
3934 output
[j
].swizzle_x
= 2;
3935 output
[j
].swizzle_y
= 7;
3936 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3937 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3938 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3939 output
[j
].array_base
= 61;
3940 output
[j
].swizzle_x
= 7;
3941 output
[j
].swizzle_y
= 1;
3942 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3943 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3944 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3945 output
[j
].array_base
= 61;
3946 output
[j
].swizzle_x
= 7;
3947 output
[j
].swizzle_y
= 7;
3948 output
[j
].swizzle_z
= 0;
3949 output
[j
].swizzle_w
= 7;
3950 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3952 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3957 case PIPE_SHADER_TESS_CTRL
:
3960 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3965 if (output
[j
].type
== 0xffffffff) {
3966 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3967 output
[j
].array_base
= next_param_base
++;
3971 /* add fake position export */
3972 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3973 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3975 output
[j
].elem_size
= 3;
3976 output
[j
].swizzle_x
= 7;
3977 output
[j
].swizzle_y
= 7;
3978 output
[j
].swizzle_z
= 7;
3979 output
[j
].swizzle_w
= 7;
3980 output
[j
].burst_count
= 1;
3981 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3982 output
[j
].array_base
= 60;
3983 output
[j
].op
= CF_OP_EXPORT
;
3987 /* add fake param output for vertex shader if no param is exported */
3988 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3989 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3991 output
[j
].elem_size
= 3;
3992 output
[j
].swizzle_x
= 7;
3993 output
[j
].swizzle_y
= 7;
3994 output
[j
].swizzle_z
= 7;
3995 output
[j
].swizzle_w
= 7;
3996 output
[j
].burst_count
= 1;
3997 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3998 output
[j
].array_base
= 0;
3999 output
[j
].op
= CF_OP_EXPORT
;
4003 /* add fake pixel export */
4004 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
4005 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4007 output
[j
].elem_size
= 3;
4008 output
[j
].swizzle_x
= 7;
4009 output
[j
].swizzle_y
= 7;
4010 output
[j
].swizzle_z
= 7;
4011 output
[j
].swizzle_w
= 7;
4012 output
[j
].burst_count
= 1;
4013 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4014 output
[j
].array_base
= 0;
4015 output
[j
].op
= CF_OP_EXPORT
;
4017 shader
->nr_ps_color_exports
++;
4018 shader
->ps_color_export_mask
= 0xf;
4023 /* set export done on last export of each type */
4024 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
4025 if (!(output_done
& (1 << output
[k
].type
))) {
4026 output_done
|= (1 << output
[k
].type
);
4027 output
[k
].op
= CF_OP_EXPORT_DONE
;
4030 /* add output to bytecode */
4031 for (i
= 0; i
< noutput
; i
++) {
4032 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
4038 /* add program end */
4039 if (ctx
.bc
->chip_class
== CAYMAN
)
4040 cm_bytecode_add_cf_end(ctx
.bc
);
4042 const struct cf_op_info
*last
= NULL
;
4044 if (ctx
.bc
->cf_last
)
4045 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
4047 /* alu clause instructions don't have EOP bit, so add NOP */
4048 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
4049 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
4051 ctx
.bc
->cf_last
->end_of_program
= 1;
4054 /* check GPR limit - we have 124 = 128 - 4
4055 * (4 are reserved as alu clause temporary registers) */
4056 if (ctx
.bc
->ngpr
> 124) {
4057 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
4062 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
4063 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
4068 tgsi_parse_free(&ctx
.parse
);
4072 tgsi_parse_free(&ctx
.parse
);
4076 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
4078 const unsigned tgsi_opcode
=
4079 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
4080 R600_ERR("%s tgsi opcode unsupported\n",
4081 tgsi_get_opcode_name(tgsi_opcode
));
4085 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
4090 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
4091 const struct r600_shader_src
*shader_src
,
4094 bc_src
->sel
= shader_src
->sel
;
4095 bc_src
->chan
= shader_src
->swizzle
[chan
];
4096 bc_src
->neg
= shader_src
->neg
;
4097 bc_src
->abs
= shader_src
->abs
;
4098 bc_src
->rel
= shader_src
->rel
;
4099 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
4100 bc_src
->kc_bank
= shader_src
->kc_bank
;
4101 bc_src
->kc_rel
= shader_src
->kc_rel
;
4104 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
4110 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
4112 bc_src
->neg
= !bc_src
->neg
;
4115 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
4116 const struct tgsi_full_dst_register
*tgsi_dst
,
4118 struct r600_bytecode_alu_dst
*r600_dst
)
4120 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4122 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
4123 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
4124 r600_dst
->chan
= swizzle
;
4125 r600_dst
->write
= 1;
4126 if (inst
->Instruction
.Saturate
) {
4127 r600_dst
->clamp
= 1;
4129 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
4130 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
4134 if (tgsi_dst
->Register
.Indirect
)
4135 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4139 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4141 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4142 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4143 struct r600_bytecode_alu alu
;
4144 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4146 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4149 switch (write_mask
) {
4151 if (swizzle_x
== 2) {
4158 if (swizzle_x
== 2) {
4167 if (swizzle_x
== 0) {
4174 if (swizzle_x
== 0) {
4185 lasti
= tgsi_last_instruction(write_mask
);
4186 for (i
= 0; i
<= lasti
; i
++) {
4188 if (!(write_mask
& (1 << i
)))
4191 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4194 if (use_tmp
|| dest_temp
) {
4195 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4199 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4201 if (i
== 1 || i
== 3)
4204 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4206 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4207 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4208 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4210 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4211 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4214 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4215 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4218 /* handle some special cases */
4219 if (i
== 1 || i
== 3) {
4220 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4221 case TGSI_OPCODE_DABS
:
4222 r600_bytecode_src_set_abs(&alu
.src
[0]);
4231 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4237 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4239 lasti
= tgsi_last_instruction(write_mask
);
4240 /* move result from temp to dst */
4241 for (i
= 0; i
<= lasti
; i
++) {
4242 if (!(write_mask
& (1 << i
)))
4245 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4246 alu
.op
= ALU_OP1_MOV
;
4249 alu
.dst
.sel
= dest_temp
;
4253 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4254 alu
.src
[0].sel
= ctx
->temp_reg
;
4255 alu
.src
[0].chan
= use_tmp
- 1;
4256 alu
.last
= (i
== lasti
);
4258 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4266 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4268 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4269 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4270 /* confirm writemasking */
4271 if ((write_mask
& 0x3) != 0x3 &&
4272 (write_mask
& 0xc) != 0xc) {
4273 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4276 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4279 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4281 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4284 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4286 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4289 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4291 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4292 struct r600_bytecode_alu alu
;
4295 int tmp
= r600_get_temp(ctx
);
4297 for (i
= 0; i
< lasti
+ 1; i
++) {
4299 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4300 alu
.op
= ctx
->inst_info
->op
;
4301 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4302 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4305 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4306 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4315 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4322 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4324 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4325 struct r600_bytecode_alu alu
;
4326 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4327 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4328 /* use temp register if trans_only and more than one dst component */
4329 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4330 unsigned op
= ctx
->inst_info
->op
;
4332 if (op
== ALU_OP2_MUL_IEEE
&&
4333 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4336 for (i
= 0; i
<= lasti
; i
++) {
4337 if (!(write_mask
& (1 << i
)))
4340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4342 alu
.dst
.sel
= ctx
->temp_reg
;
4346 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4350 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4351 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4354 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4355 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4357 if (i
== lasti
|| trans_only
) {
4360 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4366 /* move result from temp to dst */
4367 for (i
= 0; i
<= lasti
; i
++) {
4368 if (!(write_mask
& (1 << i
)))
4371 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4372 alu
.op
= ALU_OP1_MOV
;
4373 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4374 alu
.src
[0].sel
= ctx
->temp_reg
;
4375 alu
.src
[0].chan
= i
;
4376 alu
.last
= (i
== lasti
);
4378 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4386 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4388 return tgsi_op2_s(ctx
, 0, 0);
4391 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4393 return tgsi_op2_s(ctx
, 1, 0);
4396 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4398 return tgsi_op2_s(ctx
, 0, 1);
4401 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4403 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4404 struct r600_bytecode_alu alu
;
4406 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4408 for (i
= 0; i
< lasti
+ 1; i
++) {
4410 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4412 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4413 alu
.op
= ctx
->inst_info
->op
;
4415 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4417 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4419 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4432 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4434 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4435 struct r600_bytecode_alu alu
;
4437 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4439 for (i
= 0; i
< lasti
+ 1; i
++) {
4441 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4444 alu
.op
= ALU_OP1_MOV
;
4446 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4448 if (i
== 1 || i
== 3)
4449 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4450 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4455 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4463 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4465 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4466 struct r600_bytecode_alu alu
;
4467 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4470 for (i
= 0; i
<= 3; i
++) {
4471 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4472 alu
.op
= ctx
->inst_info
->op
;
4474 alu
.dst
.sel
= ctx
->temp_reg
;
4477 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4478 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4484 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4489 /* Replicate significand result across channels. */
4490 for (i
= 0; i
<= 3; i
++) {
4491 if (!(write_mask
& (1 << i
)))
4494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4495 alu
.op
= ALU_OP1_MOV
;
4496 alu
.src
[0].chan
= (i
& 1) + 2;
4497 alu
.src
[0].sel
= ctx
->temp_reg
;
4499 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4502 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4507 for (i
= 0; i
<= 3; i
++) {
4508 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4509 /* MOV third channels to writemask dst1 */
4510 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4511 alu
.op
= ALU_OP1_MOV
;
4512 alu
.src
[0].chan
= 1;
4513 alu
.src
[0].sel
= ctx
->temp_reg
;
4515 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4517 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4527 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4529 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4530 struct r600_bytecode_alu alu
;
4532 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4533 int temp_reg
= r600_get_temp(ctx
);
4535 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4536 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4538 for (c
= 0; c
< 2; c
++) {
4540 if (write_mask
& (0x3 << dchan
)) {
4541 /* split into 24-bit int and 8-bit int */
4542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4543 alu
.op
= ALU_OP2_AND_INT
;
4544 alu
.dst
.sel
= temp_reg
;
4545 alu
.dst
.chan
= dchan
;
4546 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4547 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4548 alu
.src
[1].value
= 0xffffff00;
4550 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4555 alu
.op
= ALU_OP2_AND_INT
;
4556 alu
.dst
.sel
= temp_reg
;
4557 alu
.dst
.chan
= dchan
+ 1;
4558 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4559 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4560 alu
.src
[1].value
= 0xff;
4563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4569 for (c
= 0; c
< 2; c
++) {
4571 if (write_mask
& (0x3 << dchan
)) {
4572 for (i
= dchan
; i
<= dchan
+ 1; i
++) {
4573 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4574 alu
.op
= i
== dchan
? ctx
->inst_info
->op
: ALU_OP1_UINT_TO_FLT
;
4576 alu
.src
[0].sel
= temp_reg
;
4577 alu
.src
[0].chan
= i
;
4578 alu
.dst
.sel
= temp_reg
;
4581 if (ctx
->bc
->chip_class
== CAYMAN
)
4582 alu
.last
= i
== dchan
+ 1;
4584 alu
.last
= 1; /* trans only ops on evergreen */
4586 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4593 for (c
= 0; c
< 2; c
++) {
4595 if (write_mask
& (0x3 << dchan
)) {
4596 for (i
= 0; i
< 4; i
++) {
4597 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4598 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4600 alu
.src
[0].chan
= dchan
+ (i
/ 2);
4601 if (i
== 0 || i
== 2)
4602 alu
.src
[0].sel
= temp_reg
;
4604 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4605 alu
.src
[0].value
= 0x0;
4607 alu
.dst
.sel
= ctx
->temp_reg
;
4612 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4617 for (i
= 0; i
<= 1; i
++) {
4618 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4619 alu
.op
= ALU_OP2_ADD_64
;
4621 alu
.src
[0].chan
= fp64_switch(i
);
4622 alu
.src
[0].sel
= ctx
->temp_reg
;
4624 alu
.src
[1].chan
= fp64_switch(i
+ 2);
4625 alu
.src
[1].sel
= ctx
->temp_reg
;
4626 tgsi_dst(ctx
, &inst
->Dst
[0], dchan
+ i
, &alu
.dst
);
4629 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4639 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4641 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4642 struct r600_bytecode_alu alu
;
4644 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4645 int treg
= r600_get_temp(ctx
);
4646 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4647 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4649 /* do a 64->32 into a temp register */
4650 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4654 for (i
= 0; i
<= lasti
; i
++) {
4655 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4657 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4658 alu
.op
= ctx
->inst_info
->op
;
4660 alu
.src
[0].chan
= i
;
4661 alu
.src
[0].sel
= treg
;
4662 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4663 alu
.last
= (i
== lasti
);
4665 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4673 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4676 struct r600_shader_src
*src
,
4679 struct r600_bytecode_alu alu
;
4680 const int last_slot
= 3;
4683 /* these have to write the result to X/Y by the looks of it */
4684 for (int i
= 0 ; i
< last_slot
; i
++) {
4685 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4688 r600_bytecode_src(&alu
.src
[0], src
, 1);
4689 r600_bytecode_src(&alu
.src
[1], src
, 0);
4692 r600_bytecode_src_set_abs(&alu
.src
[1]);
4694 alu
.dst
.sel
= dst_reg
;
4696 alu
.dst
.write
= (i
== 0 || i
== 1);
4698 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4700 r
= r600_bytecode_add_alu(bc
, &alu
);
4708 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4710 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4712 struct r600_bytecode_alu alu
;
4713 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4714 int t1
= ctx
->temp_reg
;
4716 /* should only be one src regs */
4717 assert(inst
->Instruction
.NumSrcRegs
== 1);
4719 /* only support one double at a time */
4720 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4721 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4723 r
= cayman_emit_unary_double_raw(
4724 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4726 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4727 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4731 for (i
= 0 ; i
<= lasti
; i
++) {
4732 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4734 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4735 alu
.op
= ALU_OP1_MOV
;
4736 alu
.src
[0].sel
= t1
;
4737 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4738 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4742 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4749 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4751 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4753 struct r600_bytecode_alu alu
;
4754 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4756 for (i
= 0 ; i
< last_slot
; i
++) {
4757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4758 alu
.op
= ctx
->inst_info
->op
;
4759 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4760 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4762 /* RSQ should take the absolute value of src */
4763 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4764 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4767 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4768 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4770 if (i
== last_slot
- 1)
4772 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4779 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4781 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4783 struct r600_bytecode_alu alu
;
4784 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4785 int t1
= ctx
->temp_reg
;
4787 for (k
= 0; k
<= lasti
; k
++) {
4788 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4791 for (i
= 0 ; i
< 4; i
++) {
4792 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4793 alu
.op
= ctx
->inst_info
->op
;
4794 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4795 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4799 alu
.dst
.write
= (i
== k
);
4802 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4808 for (i
= 0 ; i
<= lasti
; i
++) {
4809 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4811 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4812 alu
.op
= ALU_OP1_MOV
;
4813 alu
.src
[0].sel
= t1
;
4814 alu
.src
[0].chan
= i
;
4815 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4819 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4828 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4830 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4832 struct r600_bytecode_alu alu
;
4833 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4834 int t1
= ctx
->temp_reg
;
4836 /* t1 would get overwritten below if we actually tried to
4837 * multiply two pairs of doubles at a time. */
4838 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4839 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4841 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4843 for (i
= 0; i
< 4; i
++) {
4844 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4845 alu
.op
= ctx
->inst_info
->op
;
4846 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4847 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4854 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4859 for (i
= 0; i
<= lasti
; i
++) {
4860 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4862 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4863 alu
.op
= ALU_OP1_MOV
;
4864 alu
.src
[0].sel
= t1
;
4865 alu
.src
[0].chan
= i
;
4866 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4870 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4879 * Emit RECIP_64 + MUL_64 to implement division.
4881 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4883 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4885 struct r600_bytecode_alu alu
;
4886 int t1
= ctx
->temp_reg
;
4889 /* Only support one double at a time. This is the same constraint as
4890 * in DMUL lowering. */
4891 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4892 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4894 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4896 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4900 for (int i
= 0; i
< 4; i
++) {
4901 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4902 alu
.op
= ALU_OP2_MUL_64
;
4904 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4906 alu
.src
[1].sel
= t1
;
4907 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4914 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4919 for (int i
= 0; i
< 2; i
++) {
4920 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4921 alu
.op
= ALU_OP1_MOV
;
4922 alu
.src
[0].sel
= t1
;
4923 alu
.src
[0].chan
= i
;
4924 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4936 * r600 - trunc to -PI..PI range
4937 * r700 - normalize by dividing by 2PI
4940 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4943 struct r600_bytecode_alu alu
;
4945 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4946 alu
.op
= ALU_OP3_MULADD
;
4950 alu
.dst
.sel
= ctx
->temp_reg
;
4953 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4955 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4956 alu
.src
[1].chan
= 0;
4957 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4958 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4959 alu
.src
[2].chan
= 0;
4961 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4965 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4966 alu
.op
= ALU_OP1_FRACT
;
4969 alu
.dst
.sel
= ctx
->temp_reg
;
4972 alu
.src
[0].sel
= ctx
->temp_reg
;
4973 alu
.src
[0].chan
= 0;
4975 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4979 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4980 alu
.op
= ALU_OP3_MULADD
;
4984 alu
.dst
.sel
= ctx
->temp_reg
;
4987 alu
.src
[0].sel
= ctx
->temp_reg
;
4988 alu
.src
[0].chan
= 0;
4990 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4991 alu
.src
[1].chan
= 0;
4992 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4993 alu
.src
[2].chan
= 0;
4995 if (ctx
->bc
->chip_class
== R600
) {
4996 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4997 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4999 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5000 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
5005 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5011 static int cayman_trig(struct r600_shader_ctx
*ctx
)
5013 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5014 struct r600_bytecode_alu alu
;
5015 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5018 r
= tgsi_setup_trig(ctx
);
5023 for (i
= 0; i
< last_slot
; i
++) {
5024 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5025 alu
.op
= ctx
->inst_info
->op
;
5028 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5029 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5031 alu
.src
[0].sel
= ctx
->temp_reg
;
5032 alu
.src
[0].chan
= 0;
5033 if (i
== last_slot
- 1)
5035 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5042 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
5044 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5045 struct r600_bytecode_alu alu
;
5047 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5049 r
= tgsi_setup_trig(ctx
);
5053 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5054 alu
.op
= ctx
->inst_info
->op
;
5056 alu
.dst
.sel
= ctx
->temp_reg
;
5059 alu
.src
[0].sel
= ctx
->temp_reg
;
5060 alu
.src
[0].chan
= 0;
5062 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5066 /* replicate result */
5067 for (i
= 0; i
< lasti
+ 1; i
++) {
5068 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5071 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5072 alu
.op
= ALU_OP1_MOV
;
5074 alu
.src
[0].sel
= ctx
->temp_reg
;
5075 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5078 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5085 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
5087 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5088 struct r600_bytecode_alu alu
;
5091 for (i
= 0; i
< 4; i
++) {
5092 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5093 alu
.op
= ctx
->inst_info
->op
;
5097 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5099 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
5100 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5103 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5108 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5113 /* kill must be last in ALU */
5114 ctx
->bc
->force_add_cf
= 1;
5115 ctx
->shader
->uses_kill
= TRUE
;
5119 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
5121 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5122 struct r600_bytecode_alu alu
;
5125 /* tmp.x = max(src.y, 0.0) */
5126 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5127 alu
.op
= ALU_OP2_MAX
;
5128 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
5129 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5130 alu
.src
[1].chan
= 1;
5132 alu
.dst
.sel
= ctx
->temp_reg
;
5137 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5141 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
5147 if (ctx
->bc
->chip_class
== CAYMAN
) {
5148 for (i
= 0; i
< 3; i
++) {
5149 /* tmp.z = log(tmp.x) */
5150 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5151 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5152 alu
.src
[0].sel
= ctx
->temp_reg
;
5153 alu
.src
[0].chan
= 0;
5154 alu
.dst
.sel
= ctx
->temp_reg
;
5162 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5167 /* tmp.z = log(tmp.x) */
5168 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5169 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5170 alu
.src
[0].sel
= ctx
->temp_reg
;
5171 alu
.src
[0].chan
= 0;
5172 alu
.dst
.sel
= ctx
->temp_reg
;
5176 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5181 chan
= alu
.dst
.chan
;
5184 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
5185 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5186 alu
.op
= ALU_OP3_MUL_LIT
;
5187 alu
.src
[0].sel
= sel
;
5188 alu
.src
[0].chan
= chan
;
5189 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
5190 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
5191 alu
.dst
.sel
= ctx
->temp_reg
;
5196 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5200 if (ctx
->bc
->chip_class
== CAYMAN
) {
5201 for (i
= 0; i
< 3; i
++) {
5202 /* dst.z = exp(tmp.x) */
5203 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5204 alu
.op
= ALU_OP1_EXP_IEEE
;
5205 alu
.src
[0].sel
= ctx
->temp_reg
;
5206 alu
.src
[0].chan
= 0;
5207 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5218 /* dst.z = exp(tmp.x) */
5219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5220 alu
.op
= ALU_OP1_EXP_IEEE
;
5221 alu
.src
[0].sel
= ctx
->temp_reg
;
5222 alu
.src
[0].chan
= 0;
5223 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5225 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5232 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5233 alu
.op
= ALU_OP1_MOV
;
5234 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5235 alu
.src
[0].chan
= 0;
5236 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5237 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5238 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5242 /* dst.y = max(src.x, 0.0) */
5243 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5244 alu
.op
= ALU_OP2_MAX
;
5245 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5246 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5247 alu
.src
[1].chan
= 0;
5248 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5249 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5250 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5255 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5256 alu
.op
= ALU_OP1_MOV
;
5257 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5258 alu
.src
[0].chan
= 0;
5259 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5260 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5262 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5269 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5271 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5272 struct r600_bytecode_alu alu
;
5275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5277 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5279 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5280 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5281 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5283 alu
.dst
.sel
= ctx
->temp_reg
;
5286 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5289 /* replicate result */
5290 return tgsi_helper_tempx_replicate(ctx
);
5293 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5295 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5296 struct r600_bytecode_alu alu
;
5299 for (i
= 0; i
< 4; i
++) {
5300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5301 alu
.src
[0].sel
= ctx
->temp_reg
;
5302 alu
.op
= ALU_OP1_MOV
;
5304 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5305 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5308 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5315 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5317 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5318 struct r600_bytecode_alu alu
;
5321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5322 alu
.op
= ctx
->inst_info
->op
;
5323 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5324 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5326 alu
.dst
.sel
= ctx
->temp_reg
;
5329 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5332 /* replicate result */
5333 return tgsi_helper_tempx_replicate(ctx
);
5336 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5338 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5340 struct r600_bytecode_alu alu
;
5341 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5343 for (i
= 0; i
< 3; i
++) {
5344 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5345 alu
.op
= ALU_OP1_LOG_IEEE
;
5346 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5347 alu
.dst
.sel
= ctx
->temp_reg
;
5352 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5358 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5359 alu
.op
= ALU_OP2_MUL
;
5360 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5361 alu
.src
[1].sel
= ctx
->temp_reg
;
5362 alu
.dst
.sel
= ctx
->temp_reg
;
5365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5369 for (i
= 0; i
< last_slot
; i
++) {
5370 /* POW(a,b) = EXP2(b * LOG2(a))*/
5371 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5372 alu
.op
= ALU_OP1_EXP_IEEE
;
5373 alu
.src
[0].sel
= ctx
->temp_reg
;
5375 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5376 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5377 if (i
== last_slot
- 1)
5379 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5386 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5388 struct r600_bytecode_alu alu
;
5392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5393 alu
.op
= ALU_OP1_LOG_IEEE
;
5394 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5395 alu
.dst
.sel
= ctx
->temp_reg
;
5398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5402 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5403 alu
.op
= ALU_OP2_MUL
;
5404 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5405 alu
.src
[1].sel
= ctx
->temp_reg
;
5406 alu
.dst
.sel
= ctx
->temp_reg
;
5409 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5412 /* POW(a,b) = EXP2(b * LOG2(a))*/
5413 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5414 alu
.op
= ALU_OP1_EXP_IEEE
;
5415 alu
.src
[0].sel
= ctx
->temp_reg
;
5416 alu
.dst
.sel
= ctx
->temp_reg
;
5419 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5422 return tgsi_helper_tempx_replicate(ctx
);
5425 static int emit_mul_int_op(struct r600_bytecode
*bc
,
5426 struct r600_bytecode_alu
*alu_src
)
5428 struct r600_bytecode_alu alu
;
5431 if (bc
->chip_class
== CAYMAN
) {
5432 for (i
= 0; i
< 4; i
++) {
5434 alu
.dst
.write
= (i
== alu_src
->dst
.chan
);
5435 alu
.last
= (i
== 3);
5437 r
= r600_bytecode_add_alu(bc
, &alu
);
5443 r
= r600_bytecode_add_alu(bc
, &alu
);
5450 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5452 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5453 struct r600_bytecode_alu alu
;
5455 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5456 int tmp0
= ctx
->temp_reg
;
5457 int tmp1
= r600_get_temp(ctx
);
5458 int tmp2
= r600_get_temp(ctx
);
5459 int tmp3
= r600_get_temp(ctx
);
5462 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5464 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5465 * 2. tmp0.z = lo (tmp0.x * src2)
5466 * 3. tmp0.w = -tmp0.z
5467 * 4. tmp0.y = hi (tmp0.x * src2)
5468 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5469 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5470 * 7. tmp1.x = tmp0.x - tmp0.w
5471 * 8. tmp1.y = tmp0.x + tmp0.w
5472 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5473 * 10. tmp0.z = hi(tmp0.x * src1) = q
5474 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5476 * 12. tmp0.w = src1 - tmp0.y = r
5477 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5478 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5482 * 15. tmp1.z = tmp0.z + 1 = q + 1
5483 * 16. tmp1.w = tmp0.z - 1 = q - 1
5487 * 15. tmp1.z = tmp0.w - src2 = r - src2
5488 * 16. tmp1.w = tmp0.w + src2 = r + src2
5492 * 17. tmp1.x = tmp1.x & tmp1.y
5494 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5495 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5497 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5498 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5502 * Same as unsigned, using abs values of the operands,
5503 * and fixing the sign of the result in the end.
5506 for (i
= 0; i
< 4; i
++) {
5507 if (!(write_mask
& (1<<i
)))
5512 /* tmp2.x = -src0 */
5513 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5514 alu
.op
= ALU_OP2_SUB_INT
;
5520 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5522 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5525 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5528 /* tmp2.y = -src1 */
5529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5530 alu
.op
= ALU_OP2_SUB_INT
;
5536 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5538 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5541 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5544 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5545 /* it will be a sign of the quotient */
5548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5549 alu
.op
= ALU_OP2_XOR_INT
;
5555 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5556 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5559 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5563 /* tmp2.x = |src0| */
5564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5565 alu
.op
= ALU_OP3_CNDGE_INT
;
5572 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5573 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5574 alu
.src
[2].sel
= tmp2
;
5575 alu
.src
[2].chan
= 0;
5578 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5581 /* tmp2.y = |src1| */
5582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5583 alu
.op
= ALU_OP3_CNDGE_INT
;
5590 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5591 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5592 alu
.src
[2].sel
= tmp2
;
5593 alu
.src
[2].chan
= 1;
5596 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5601 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5602 if (ctx
->bc
->chip_class
== CAYMAN
) {
5603 /* tmp3.x = u2f(src2) */
5604 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5605 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5612 alu
.src
[0].sel
= tmp2
;
5613 alu
.src
[0].chan
= 1;
5615 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5619 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5622 /* tmp0.x = recip(tmp3.x) */
5623 for (j
= 0 ; j
< 3; j
++) {
5624 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5625 alu
.op
= ALU_OP1_RECIP_IEEE
;
5629 alu
.dst
.write
= (j
== 0);
5631 alu
.src
[0].sel
= tmp3
;
5632 alu
.src
[0].chan
= 0;
5636 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5641 alu
.op
= ALU_OP2_MUL
;
5643 alu
.src
[0].sel
= tmp0
;
5644 alu
.src
[0].chan
= 0;
5646 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5647 alu
.src
[1].value
= 0x4f800000;
5652 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5657 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5663 alu
.src
[0].sel
= tmp3
;
5664 alu
.src
[0].chan
= 0;
5667 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5671 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5672 alu
.op
= ALU_OP1_RECIP_UINT
;
5679 alu
.src
[0].sel
= tmp2
;
5680 alu
.src
[0].chan
= 1;
5682 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5686 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5690 /* 2. tmp0.z = lo (tmp0.x * src2) */
5691 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5692 alu
.op
= ALU_OP2_MULLO_UINT
;
5698 alu
.src
[0].sel
= tmp0
;
5699 alu
.src
[0].chan
= 0;
5701 alu
.src
[1].sel
= tmp2
;
5702 alu
.src
[1].chan
= 1;
5704 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5707 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5710 /* 3. tmp0.w = -tmp0.z */
5711 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5712 alu
.op
= ALU_OP2_SUB_INT
;
5718 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5719 alu
.src
[1].sel
= tmp0
;
5720 alu
.src
[1].chan
= 2;
5723 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5726 /* 4. tmp0.y = hi (tmp0.x * src2) */
5727 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5728 alu
.op
= ALU_OP2_MULHI_UINT
;
5734 alu
.src
[0].sel
= tmp0
;
5735 alu
.src
[0].chan
= 0;
5738 alu
.src
[1].sel
= tmp2
;
5739 alu
.src
[1].chan
= 1;
5741 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5744 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5747 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5748 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5749 alu
.op
= ALU_OP3_CNDE_INT
;
5756 alu
.src
[0].sel
= tmp0
;
5757 alu
.src
[0].chan
= 1;
5758 alu
.src
[1].sel
= tmp0
;
5759 alu
.src
[1].chan
= 3;
5760 alu
.src
[2].sel
= tmp0
;
5761 alu
.src
[2].chan
= 2;
5764 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5767 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5768 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5769 alu
.op
= ALU_OP2_MULHI_UINT
;
5775 alu
.src
[0].sel
= tmp0
;
5776 alu
.src
[0].chan
= 2;
5778 alu
.src
[1].sel
= tmp0
;
5779 alu
.src
[1].chan
= 0;
5781 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5784 /* 7. tmp1.x = tmp0.x - tmp0.w */
5785 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5786 alu
.op
= ALU_OP2_SUB_INT
;
5792 alu
.src
[0].sel
= tmp0
;
5793 alu
.src
[0].chan
= 0;
5794 alu
.src
[1].sel
= tmp0
;
5795 alu
.src
[1].chan
= 3;
5798 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5801 /* 8. tmp1.y = tmp0.x + tmp0.w */
5802 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5803 alu
.op
= ALU_OP2_ADD_INT
;
5809 alu
.src
[0].sel
= tmp0
;
5810 alu
.src
[0].chan
= 0;
5811 alu
.src
[1].sel
= tmp0
;
5812 alu
.src
[1].chan
= 3;
5815 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5818 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5819 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5820 alu
.op
= ALU_OP3_CNDE_INT
;
5827 alu
.src
[0].sel
= tmp0
;
5828 alu
.src
[0].chan
= 1;
5829 alu
.src
[1].sel
= tmp1
;
5830 alu
.src
[1].chan
= 1;
5831 alu
.src
[2].sel
= tmp1
;
5832 alu
.src
[2].chan
= 0;
5835 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5838 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5839 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5840 alu
.op
= ALU_OP2_MULHI_UINT
;
5846 alu
.src
[0].sel
= tmp0
;
5847 alu
.src
[0].chan
= 0;
5850 alu
.src
[1].sel
= tmp2
;
5851 alu
.src
[1].chan
= 0;
5853 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5856 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5859 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5860 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5861 alu
.op
= ALU_OP2_MULLO_UINT
;
5868 alu
.src
[0].sel
= tmp2
;
5869 alu
.src
[0].chan
= 1;
5871 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5874 alu
.src
[1].sel
= tmp0
;
5875 alu
.src
[1].chan
= 2;
5877 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5880 /* 12. tmp0.w = src1 - tmp0.y = r */
5881 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5882 alu
.op
= ALU_OP2_SUB_INT
;
5889 alu
.src
[0].sel
= tmp2
;
5890 alu
.src
[0].chan
= 0;
5892 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5895 alu
.src
[1].sel
= tmp0
;
5896 alu
.src
[1].chan
= 1;
5899 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5902 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5903 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5904 alu
.op
= ALU_OP2_SETGE_UINT
;
5910 alu
.src
[0].sel
= tmp0
;
5911 alu
.src
[0].chan
= 3;
5913 alu
.src
[1].sel
= tmp2
;
5914 alu
.src
[1].chan
= 1;
5916 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5920 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5923 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5925 alu
.op
= ALU_OP2_SETGE_UINT
;
5932 alu
.src
[0].sel
= tmp2
;
5933 alu
.src
[0].chan
= 0;
5935 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5938 alu
.src
[1].sel
= tmp0
;
5939 alu
.src
[1].chan
= 1;
5942 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5945 if (mod
) { /* UMOD */
5947 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5948 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5949 alu
.op
= ALU_OP2_SUB_INT
;
5955 alu
.src
[0].sel
= tmp0
;
5956 alu
.src
[0].chan
= 3;
5959 alu
.src
[1].sel
= tmp2
;
5960 alu
.src
[1].chan
= 1;
5962 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5966 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5969 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5970 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5971 alu
.op
= ALU_OP2_ADD_INT
;
5977 alu
.src
[0].sel
= tmp0
;
5978 alu
.src
[0].chan
= 3;
5980 alu
.src
[1].sel
= tmp2
;
5981 alu
.src
[1].chan
= 1;
5983 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5987 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5992 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5993 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5994 alu
.op
= ALU_OP2_ADD_INT
;
6000 alu
.src
[0].sel
= tmp0
;
6001 alu
.src
[0].chan
= 2;
6002 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6005 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6008 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
6009 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6010 alu
.op
= ALU_OP2_ADD_INT
;
6016 alu
.src
[0].sel
= tmp0
;
6017 alu
.src
[0].chan
= 2;
6018 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
6021 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6026 /* 17. tmp1.x = tmp1.x & tmp1.y */
6027 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6028 alu
.op
= ALU_OP2_AND_INT
;
6034 alu
.src
[0].sel
= tmp1
;
6035 alu
.src
[0].chan
= 0;
6036 alu
.src
[1].sel
= tmp1
;
6037 alu
.src
[1].chan
= 1;
6040 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6043 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
6044 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
6045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6046 alu
.op
= ALU_OP3_CNDE_INT
;
6053 alu
.src
[0].sel
= tmp1
;
6054 alu
.src
[0].chan
= 0;
6055 alu
.src
[1].sel
= tmp0
;
6056 alu
.src
[1].chan
= mod
? 3 : 2;
6057 alu
.src
[2].sel
= tmp1
;
6058 alu
.src
[2].chan
= 2;
6061 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6064 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
6065 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6066 alu
.op
= ALU_OP3_CNDE_INT
;
6074 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6077 alu
.src
[0].sel
= tmp1
;
6078 alu
.src
[0].chan
= 1;
6079 alu
.src
[1].sel
= tmp1
;
6080 alu
.src
[1].chan
= 3;
6081 alu
.src
[2].sel
= tmp0
;
6082 alu
.src
[2].chan
= 2;
6085 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6090 /* fix the sign of the result */
6094 /* tmp0.x = -tmp0.z */
6095 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6096 alu
.op
= ALU_OP2_SUB_INT
;
6102 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6103 alu
.src
[1].sel
= tmp0
;
6104 alu
.src
[1].chan
= 2;
6107 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6110 /* sign of the remainder is the same as the sign of src0 */
6111 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6112 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6113 alu
.op
= ALU_OP3_CNDGE_INT
;
6116 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6118 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6119 alu
.src
[1].sel
= tmp0
;
6120 alu
.src
[1].chan
= 2;
6121 alu
.src
[2].sel
= tmp0
;
6122 alu
.src
[2].chan
= 0;
6125 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6130 /* tmp0.x = -tmp0.z */
6131 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6132 alu
.op
= ALU_OP2_SUB_INT
;
6138 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6139 alu
.src
[1].sel
= tmp0
;
6140 alu
.src
[1].chan
= 2;
6143 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6146 /* fix the quotient sign (same as the sign of src0*src1) */
6147 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6148 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6149 alu
.op
= ALU_OP3_CNDGE_INT
;
6152 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6154 alu
.src
[0].sel
= tmp2
;
6155 alu
.src
[0].chan
= 2;
6156 alu
.src
[1].sel
= tmp0
;
6157 alu
.src
[1].chan
= 2;
6158 alu
.src
[2].sel
= tmp0
;
6159 alu
.src
[2].chan
= 0;
6162 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6170 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6172 return tgsi_divmod(ctx
, 0, 0);
6175 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6177 return tgsi_divmod(ctx
, 1, 0);
6180 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6182 return tgsi_divmod(ctx
, 0, 1);
6185 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6187 return tgsi_divmod(ctx
, 1, 1);
6191 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6193 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6194 struct r600_bytecode_alu alu
;
6196 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6197 int last_inst
= tgsi_last_instruction(write_mask
);
6199 for (i
= 0; i
< 4; i
++) {
6200 if (!(write_mask
& (1<<i
)))
6203 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6204 alu
.op
= ALU_OP1_TRUNC
;
6206 alu
.dst
.sel
= ctx
->temp_reg
;
6210 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6218 for (i
= 0; i
< 4; i
++) {
6219 if (!(write_mask
& (1<<i
)))
6222 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6223 alu
.op
= ctx
->inst_info
->op
;
6225 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6227 alu
.src
[0].sel
= ctx
->temp_reg
;
6228 alu
.src
[0].chan
= i
;
6230 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6232 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6240 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6242 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6243 struct r600_bytecode_alu alu
;
6245 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6246 int last_inst
= tgsi_last_instruction(write_mask
);
6249 for (i
= 0; i
< 4; i
++) {
6250 if (!(write_mask
& (1<<i
)))
6253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6254 alu
.op
= ALU_OP2_SUB_INT
;
6256 alu
.dst
.sel
= ctx
->temp_reg
;
6260 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6261 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6265 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6270 /* dst = (src >= 0 ? src : tmp) */
6271 for (i
= 0; i
< 4; i
++) {
6272 if (!(write_mask
& (1<<i
)))
6275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6276 alu
.op
= ALU_OP3_CNDGE_INT
;
6280 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6282 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6283 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6284 alu
.src
[2].sel
= ctx
->temp_reg
;
6285 alu
.src
[2].chan
= i
;
6289 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6296 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6298 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6299 struct r600_bytecode_alu alu
;
6301 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6302 int last_inst
= tgsi_last_instruction(write_mask
);
6304 /* tmp = (src >= 0 ? src : -1) */
6305 for (i
= 0; i
< 4; i
++) {
6306 if (!(write_mask
& (1<<i
)))
6309 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6310 alu
.op
= ALU_OP3_CNDGE_INT
;
6313 alu
.dst
.sel
= ctx
->temp_reg
;
6317 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6318 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6319 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6328 /* dst = (tmp > 0 ? 1 : tmp) */
6329 for (i
= 0; i
< 4; i
++) {
6330 if (!(write_mask
& (1<<i
)))
6333 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6334 alu
.op
= ALU_OP3_CNDGT_INT
;
6338 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6340 alu
.src
[0].sel
= ctx
->temp_reg
;
6341 alu
.src
[0].chan
= i
;
6343 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6345 alu
.src
[2].sel
= ctx
->temp_reg
;
6346 alu
.src
[2].chan
= i
;
6350 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6359 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6361 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6362 struct r600_bytecode_alu alu
;
6365 /* tmp = (src > 0 ? 1 : src) */
6366 for (i
= 0; i
< 4; i
++) {
6367 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6368 alu
.op
= ALU_OP3_CNDGT
;
6371 alu
.dst
.sel
= ctx
->temp_reg
;
6374 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6375 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6376 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6380 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6385 /* dst = (-tmp > 0 ? -1 : tmp) */
6386 for (i
= 0; i
< 4; i
++) {
6387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6388 alu
.op
= ALU_OP3_CNDGT
;
6390 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6392 alu
.src
[0].sel
= ctx
->temp_reg
;
6393 alu
.src
[0].chan
= i
;
6396 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6399 alu
.src
[2].sel
= ctx
->temp_reg
;
6400 alu
.src
[2].chan
= i
;
6404 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6411 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6413 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6414 struct r600_bytecode_alu alu
;
6417 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6418 int last_inst
= tgsi_last_instruction(write_mask
);
6420 t1
= r600_get_temp(ctx
);
6422 for (i
= 0; i
< 4; i
++) {
6423 if (!(write_mask
& (1<<i
)))
6426 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6427 alu
.op
= ALU_OP2_SETGE_INT
;
6428 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6429 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6430 alu
.src
[1].value
= 32;
6431 alu
.dst
.sel
= ctx
->temp_reg
;
6434 alu
.last
= i
== last_inst
;
6435 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6440 for (i
= 0; i
< 4; i
++) {
6441 if (!(write_mask
& (1<<i
)))
6444 /* create mask tmp */
6445 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6446 alu
.op
= ALU_OP2_BFM_INT
;
6450 alu
.last
= i
== last_inst
;
6452 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6453 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6455 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6460 t2
= r600_get_temp(ctx
);
6462 for (i
= 0; i
< 4; i
++) {
6463 if (!(write_mask
& (1<<i
)))
6466 /* shift insert left */
6467 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6468 alu
.op
= ALU_OP2_LSHL_INT
;
6472 alu
.last
= i
== last_inst
;
6474 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6475 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6477 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6482 for (i
= 0; i
< 4; i
++) {
6483 if (!(write_mask
& (1<<i
)))
6486 /* actual bitfield insert */
6487 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6488 alu
.op
= ALU_OP3_BFI_INT
;
6490 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6493 alu
.last
= i
== last_inst
;
6495 alu
.src
[0].sel
= t1
;
6496 alu
.src
[0].chan
= i
;
6497 alu
.src
[1].sel
= t2
;
6498 alu
.src
[1].chan
= i
;
6499 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6501 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6506 for (i
= 0; i
< 4; i
++) {
6507 if (!(write_mask
& (1<<i
)))
6509 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6510 alu
.op
= ALU_OP3_CNDE_INT
;
6512 alu
.src
[0].sel
= ctx
->temp_reg
;
6513 alu
.src
[0].chan
= i
;
6514 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6516 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6518 alu
.src
[1].sel
= alu
.dst
.sel
;
6519 alu
.src
[1].chan
= i
;
6521 alu
.last
= i
== last_inst
;
6522 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6529 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6531 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6532 struct r600_bytecode_alu alu
;
6535 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6536 int last_inst
= tgsi_last_instruction(write_mask
);
6538 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6539 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6543 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6544 for (i
= 0; i
< 4; i
++) {
6545 if (!(write_mask
& (1<<i
)))
6548 /* t1 = FFBH_INT / FFBH_UINT */
6549 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6550 alu
.op
= ctx
->inst_info
->op
;
6554 alu
.last
= i
== last_inst
;
6556 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6558 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6563 t2
= r600_get_temp(ctx
);
6565 for (i
= 0; i
< 4; i
++) {
6566 if (!(write_mask
& (1<<i
)))
6570 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6571 alu
.op
= ALU_OP2_SUB_INT
;
6575 alu
.last
= i
== last_inst
;
6577 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6578 alu
.src
[0].value
= 31;
6579 alu
.src
[1].sel
= t1
;
6580 alu
.src
[1].chan
= i
;
6582 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6587 for (i
= 0; i
< 4; i
++) {
6588 if (!(write_mask
& (1<<i
)))
6591 /* result = t1 >= 0 ? t2 : t1 */
6592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6593 alu
.op
= ALU_OP3_CNDGE_INT
;
6595 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6598 alu
.last
= i
== last_inst
;
6600 alu
.src
[0].sel
= t1
;
6601 alu
.src
[0].chan
= i
;
6602 alu
.src
[1].sel
= t2
;
6603 alu
.src
[1].chan
= i
;
6604 alu
.src
[2].sel
= t1
;
6605 alu
.src
[2].chan
= i
;
6607 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6615 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6617 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6618 struct r600_bytecode_alu alu
;
6619 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6621 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6623 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6625 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6626 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6627 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6628 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6631 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6634 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6637 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6638 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6640 /* NOTE: currently offset is not perspective correct */
6641 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6642 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6643 int sample_gpr
= -1;
6644 int gradientsH
, gradientsV
;
6645 struct r600_bytecode_tex tex
;
6647 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6648 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6651 gradientsH
= r600_get_temp(ctx
);
6652 gradientsV
= r600_get_temp(ctx
);
6653 for (i
= 0; i
< 2; i
++) {
6654 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6655 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6656 tex
.src_gpr
= interp_gpr
;
6657 tex
.src_sel_x
= interp_base_chan
+ 0;
6658 tex
.src_sel_y
= interp_base_chan
+ 1;
6661 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6666 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6668 tex
.resource_id
= tex
.sampler_id
;
6669 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6674 for (i
= 0; i
< 2; i
++) {
6675 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6676 alu
.op
= ALU_OP3_MULADD
;
6678 alu
.src
[0].sel
= gradientsH
;
6679 alu
.src
[0].chan
= i
;
6680 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6681 alu
.src
[1].sel
= sample_gpr
;
6682 alu
.src
[1].chan
= 2;
6685 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6687 alu
.src
[2].sel
= interp_gpr
;
6688 alu
.src
[2].chan
= interp_base_chan
+ i
;
6689 alu
.dst
.sel
= ctx
->temp_reg
;
6693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6698 for (i
= 0; i
< 2; i
++) {
6699 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6700 alu
.op
= ALU_OP3_MULADD
;
6702 alu
.src
[0].sel
= gradientsV
;
6703 alu
.src
[0].chan
= i
;
6704 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6705 alu
.src
[1].sel
= sample_gpr
;
6706 alu
.src
[1].chan
= 3;
6709 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6711 alu
.src
[2].sel
= ctx
->temp_reg
;
6712 alu
.src
[2].chan
= i
;
6713 alu
.dst
.sel
= ctx
->temp_reg
;
6717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6723 tmp
= r600_get_temp(ctx
);
6724 for (i
= 0; i
< 8; i
++) {
6725 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6726 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6729 if ((i
> 1 && i
< 6)) {
6735 alu
.dst
.chan
= i
% 4;
6737 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6738 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6739 alu
.src
[0].sel
= ctx
->temp_reg
;
6740 alu
.src
[0].chan
= 1 - (i
% 2);
6742 alu
.src
[0].sel
= interp_gpr
;
6743 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6745 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6746 alu
.src
[1].chan
= 0;
6748 alu
.last
= i
% 4 == 3;
6749 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6751 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6756 // INTERP can't swizzle dst
6757 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6758 for (i
= 0; i
<= lasti
; i
++) {
6759 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6763 alu
.op
= ALU_OP1_MOV
;
6764 alu
.src
[0].sel
= tmp
;
6765 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6766 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6768 alu
.last
= i
== lasti
;
6769 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6778 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6780 struct r600_bytecode_alu alu
;
6783 for (i
= 0; i
< 4; i
++) {
6784 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6785 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6786 alu
.op
= ALU_OP0_NOP
;
6789 alu
.op
= ALU_OP1_MOV
;
6790 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6791 alu
.src
[0].sel
= ctx
->temp_reg
;
6792 alu
.src
[0].chan
= i
;
6797 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6804 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6805 unsigned temp
, int chan
,
6806 struct r600_bytecode_alu_src
*bc_src
,
6807 const struct r600_shader_src
*shader_src
)
6809 struct r600_bytecode_alu alu
;
6812 r600_bytecode_src(bc_src
, shader_src
, chan
);
6814 /* op3 operands don't support abs modifier */
6816 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6817 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6818 alu
.op
= ALU_OP1_MOV
;
6820 alu
.dst
.chan
= chan
;
6823 alu
.src
[0] = *bc_src
;
6824 alu
.last
= true; // sufficient?
6825 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6829 memset(bc_src
, 0, sizeof(*bc_src
));
6831 bc_src
->chan
= chan
;
6836 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
6838 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6839 struct r600_bytecode_alu alu
;
6841 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6843 unsigned op
= ctx
->inst_info
->op
;
6845 if (op
== ALU_OP3_MULADD_IEEE
&&
6846 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6847 op
= ALU_OP3_MULADD
;
6849 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6851 if (ctx
->src
[j
].abs
)
6852 temp_regs
[j
] = r600_get_temp(ctx
);
6854 for (i
= 0; i
< lasti
+ 1; i
++) {
6855 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6858 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6860 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6861 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6867 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6877 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6884 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6886 return tgsi_op3_dst(ctx
, -1);
6889 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6891 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6892 struct r600_bytecode_alu alu
;
6894 unsigned op
= ctx
->inst_info
->op
;
6895 if (op
== ALU_OP2_DOT4_IEEE
&&
6896 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6899 for (i
= 0; i
< 4; i
++) {
6900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6902 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6903 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6906 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6908 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6909 /* handle some special cases */
6910 switch (inst
->Instruction
.Opcode
) {
6911 case TGSI_OPCODE_DP2
:
6913 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6914 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6917 case TGSI_OPCODE_DP3
:
6919 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6920 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6929 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6936 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6939 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6940 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6941 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6942 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6943 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6944 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6947 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6950 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6951 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6954 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6956 struct r600_bytecode_vtx vtx
;
6957 struct r600_bytecode_alu alu
;
6958 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6960 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6961 int sampler_index_mode
= inst
->Src
[1].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6963 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6964 if (src_requires_loading
) {
6965 for (i
= 0; i
< 4; i
++) {
6966 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6967 alu
.op
= ALU_OP1_MOV
;
6968 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6969 alu
.dst
.sel
= ctx
->temp_reg
;
6974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6978 src_gpr
= ctx
->temp_reg
;
6981 memset(&vtx
, 0, sizeof(vtx
));
6982 vtx
.op
= FETCH_OP_VFETCH
;
6983 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6984 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6985 vtx
.src_gpr
= src_gpr
;
6986 vtx
.mega_fetch_count
= 16;
6987 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6988 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6989 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6990 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6991 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6992 vtx
.use_const_fields
= 1;
6993 vtx
.buffer_index_mode
= sampler_index_mode
;
6995 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6998 if (ctx
->bc
->chip_class
>= EVERGREEN
)
7001 for (i
= 0; i
< 4; i
++) {
7002 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7003 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7006 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7007 alu
.op
= ALU_OP2_AND_INT
;
7010 alu
.dst
.sel
= vtx
.dst_gpr
;
7013 alu
.src
[0].sel
= vtx
.dst_gpr
;
7014 alu
.src
[0].chan
= i
;
7016 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7017 alu
.src
[1].sel
+= (id
* 2);
7018 alu
.src
[1].chan
= i
% 4;
7019 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7023 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7028 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
7029 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7030 alu
.op
= ALU_OP2_OR_INT
;
7033 alu
.dst
.sel
= vtx
.dst_gpr
;
7036 alu
.src
[0].sel
= vtx
.dst_gpr
;
7037 alu
.src
[0].chan
= 3;
7039 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
7040 alu
.src
[1].chan
= 0;
7041 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7044 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7051 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
, int eg_buffer_base
)
7053 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7055 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
7056 int sampler_index_mode
= inst
->Src
[reg_idx
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7058 if (ctx
->bc
->chip_class
< EVERGREEN
) {
7059 struct r600_bytecode_alu alu
;
7060 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7061 alu
.op
= ALU_OP1_MOV
;
7062 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7063 /* r600 we have them at channel 2 of the second dword */
7064 alu
.src
[0].sel
+= (id
* 2) + 1;
7065 alu
.src
[0].chan
= 1;
7066 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7067 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
7069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7074 struct r600_bytecode_vtx vtx
;
7075 memset(&vtx
, 0, sizeof(vtx
));
7076 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
7077 vtx
.buffer_id
= id
+ eg_buffer_base
;
7078 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7080 vtx
.mega_fetch_count
= 16; /* no idea here really... */
7081 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7082 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7083 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 4 : 7; /* SEL_Y */
7084 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 4 : 7; /* SEL_Z */
7085 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 4 : 7; /* SEL_W */
7086 vtx
.data_format
= FMT_32_32_32_32
;
7087 vtx
.buffer_index_mode
= sampler_index_mode
;
7089 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
7096 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
7098 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7099 struct r600_bytecode_tex tex
;
7100 struct r600_bytecode_alu alu
;
7104 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7105 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7106 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7107 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7109 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7110 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7111 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7113 /* Texture fetch instructions can only use gprs as source.
7114 * Also they cannot negate the source or take the absolute value */
7115 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7116 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7117 read_compressed_msaa
|| txf_add_offsets
;
7119 boolean src_loaded
= FALSE
;
7120 unsigned sampler_src_reg
= 1;
7121 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7122 boolean has_txq_cube_array_z
= false;
7123 unsigned sampler_index_mode
;
7125 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7126 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7127 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7128 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7129 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7130 has_txq_cube_array_z
= true;
7133 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7134 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7135 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7136 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7137 sampler_src_reg
= 2;
7139 /* TGSI moves the sampler to src reg 3 for TXD */
7140 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7141 sampler_src_reg
= 3;
7143 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7145 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7147 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7148 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7149 if (ctx
->bc
->chip_class
< EVERGREEN
)
7150 ctx
->shader
->uses_tex_buffers
= true;
7151 return r600_do_buffer_txq(ctx
, 1, 0, R600_MAX_CONST_BUFFERS
);
7153 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7154 if (ctx
->bc
->chip_class
< EVERGREEN
)
7155 ctx
->shader
->uses_tex_buffers
= true;
7156 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7160 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7162 /* Add perspective divide */
7163 if (ctx
->bc
->chip_class
== CAYMAN
) {
7165 for (i
= 0; i
< 3; i
++) {
7166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7167 alu
.op
= ALU_OP1_RECIP_IEEE
;
7168 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7170 alu
.dst
.sel
= ctx
->temp_reg
;
7176 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7183 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7184 alu
.op
= ALU_OP1_RECIP_IEEE
;
7185 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7187 alu
.dst
.sel
= ctx
->temp_reg
;
7188 alu
.dst
.chan
= out_chan
;
7191 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7196 for (i
= 0; i
< 3; i
++) {
7197 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7198 alu
.op
= ALU_OP2_MUL
;
7199 alu
.src
[0].sel
= ctx
->temp_reg
;
7200 alu
.src
[0].chan
= out_chan
;
7201 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7202 alu
.dst
.sel
= ctx
->temp_reg
;
7205 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7210 alu
.op
= ALU_OP1_MOV
;
7211 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7212 alu
.src
[0].chan
= 0;
7213 alu
.dst
.sel
= ctx
->temp_reg
;
7217 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7221 src_gpr
= ctx
->temp_reg
;
7225 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7226 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7227 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7228 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7229 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7231 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7232 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7234 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7235 for (i
= 0; i
< 4; i
++) {
7236 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7237 alu
.op
= ALU_OP2_CUBE
;
7238 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7239 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7240 alu
.dst
.sel
= ctx
->temp_reg
;
7245 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7250 /* tmp1.z = RCP_e(|tmp1.z|) */
7251 if (ctx
->bc
->chip_class
== CAYMAN
) {
7252 for (i
= 0; i
< 3; i
++) {
7253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7254 alu
.op
= ALU_OP1_RECIP_IEEE
;
7255 alu
.src
[0].sel
= ctx
->temp_reg
;
7256 alu
.src
[0].chan
= 2;
7258 alu
.dst
.sel
= ctx
->temp_reg
;
7264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7270 alu
.op
= ALU_OP1_RECIP_IEEE
;
7271 alu
.src
[0].sel
= ctx
->temp_reg
;
7272 alu
.src
[0].chan
= 2;
7274 alu
.dst
.sel
= ctx
->temp_reg
;
7278 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7283 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7284 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7285 * muladd has no writemask, have to use another temp
7287 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7288 alu
.op
= ALU_OP3_MULADD
;
7291 alu
.src
[0].sel
= ctx
->temp_reg
;
7292 alu
.src
[0].chan
= 0;
7293 alu
.src
[1].sel
= ctx
->temp_reg
;
7294 alu
.src
[1].chan
= 2;
7296 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7297 alu
.src
[2].chan
= 0;
7298 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7300 alu
.dst
.sel
= ctx
->temp_reg
;
7304 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7308 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7309 alu
.op
= ALU_OP3_MULADD
;
7312 alu
.src
[0].sel
= ctx
->temp_reg
;
7313 alu
.src
[0].chan
= 1;
7314 alu
.src
[1].sel
= ctx
->temp_reg
;
7315 alu
.src
[1].chan
= 2;
7317 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7318 alu
.src
[2].chan
= 0;
7319 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7321 alu
.dst
.sel
= ctx
->temp_reg
;
7326 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7329 /* write initial compare value into Z component
7330 - W src 0 for shadow cube
7331 - X src 1 for shadow cube array */
7332 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7333 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7334 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7335 alu
.op
= ALU_OP1_MOV
;
7336 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7337 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7339 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7340 alu
.dst
.sel
= ctx
->temp_reg
;
7344 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7349 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7350 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7351 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7352 int mytmp
= r600_get_temp(ctx
);
7353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7354 alu
.op
= ALU_OP1_MOV
;
7355 alu
.src
[0].sel
= ctx
->temp_reg
;
7356 alu
.src
[0].chan
= 3;
7357 alu
.dst
.sel
= mytmp
;
7361 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7365 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7366 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7367 alu
.op
= ALU_OP3_MULADD
;
7369 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7370 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7371 alu
.src
[1].chan
= 0;
7372 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7373 alu
.src
[2].sel
= mytmp
;
7374 alu
.src
[2].chan
= 0;
7375 alu
.dst
.sel
= ctx
->temp_reg
;
7379 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7382 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7383 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7384 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7385 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7386 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7387 tex
.src_gpr
= r600_get_temp(ctx
);
7392 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7393 tex
.coord_type_x
= 1;
7394 tex
.coord_type_y
= 1;
7395 tex
.coord_type_z
= 1;
7396 tex
.coord_type_w
= 1;
7397 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7398 alu
.op
= ALU_OP1_MOV
;
7399 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7400 alu
.dst
.sel
= tex
.src_gpr
;
7404 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7408 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7415 /* for cube forms of lod and bias we need to route things */
7416 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7417 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7418 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7419 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7420 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7421 alu
.op
= ALU_OP1_MOV
;
7422 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7423 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7424 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7426 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7427 alu
.dst
.sel
= ctx
->temp_reg
;
7431 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7437 src_gpr
= ctx
->temp_reg
;
7440 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7441 int temp_h
= 0, temp_v
= 0;
7444 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7445 if (src_loaded
== TRUE
)
7449 for (i
= start_val
; i
< 3; i
++) {
7450 int treg
= r600_get_temp(ctx
);
7459 for (j
= 0; j
< 4; j
++) {
7460 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7461 alu
.op
= ALU_OP1_MOV
;
7462 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7473 for (i
= 1; i
< 3; i
++) {
7474 /* set gradients h/v */
7475 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7476 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7477 FETCH_OP_SET_GRADIENTS_V
;
7478 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7479 tex
.sampler_index_mode
= sampler_index_mode
;
7480 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7481 tex
.resource_index_mode
= sampler_index_mode
;
7483 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7489 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7490 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7491 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7492 tex
.coord_type_x
= 1;
7493 tex
.coord_type_y
= 1;
7494 tex
.coord_type_z
= 1;
7495 tex
.coord_type_w
= 1;
7497 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7503 if (src_requires_loading
&& !src_loaded
) {
7504 for (i
= 0; i
< 4; i
++) {
7505 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7506 alu
.op
= ALU_OP1_MOV
;
7507 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7508 alu
.dst
.sel
= ctx
->temp_reg
;
7513 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7518 src_gpr
= ctx
->temp_reg
;
7521 /* get offset values */
7522 if (inst
->Texture
.NumOffsets
) {
7523 assert(inst
->Texture
.NumOffsets
== 1);
7525 /* The texture offset feature doesn't work with the TXF instruction
7526 * and must be emulated by adding the offset to the texture coordinates. */
7527 if (txf_add_offsets
) {
7528 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7530 switch (inst
->Texture
.Texture
) {
7531 case TGSI_TEXTURE_3D
:
7532 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7533 alu
.op
= ALU_OP2_ADD_INT
;
7534 alu
.src
[0].sel
= src_gpr
;
7535 alu
.src
[0].chan
= 2;
7536 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7537 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7538 alu
.dst
.sel
= src_gpr
;
7542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7547 case TGSI_TEXTURE_2D
:
7548 case TGSI_TEXTURE_SHADOW2D
:
7549 case TGSI_TEXTURE_RECT
:
7550 case TGSI_TEXTURE_SHADOWRECT
:
7551 case TGSI_TEXTURE_2D_ARRAY
:
7552 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7554 alu
.op
= ALU_OP2_ADD_INT
;
7555 alu
.src
[0].sel
= src_gpr
;
7556 alu
.src
[0].chan
= 1;
7557 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7558 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7559 alu
.dst
.sel
= src_gpr
;
7563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7568 case TGSI_TEXTURE_1D
:
7569 case TGSI_TEXTURE_SHADOW1D
:
7570 case TGSI_TEXTURE_1D_ARRAY
:
7571 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7572 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7573 alu
.op
= ALU_OP2_ADD_INT
;
7574 alu
.src
[0].sel
= src_gpr
;
7575 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7576 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7577 alu
.dst
.sel
= src_gpr
;
7580 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7584 /* texture offsets do not apply to other texture targets */
7587 switch (inst
->Texture
.Texture
) {
7588 case TGSI_TEXTURE_3D
:
7589 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7591 case TGSI_TEXTURE_2D
:
7592 case TGSI_TEXTURE_SHADOW2D
:
7593 case TGSI_TEXTURE_RECT
:
7594 case TGSI_TEXTURE_SHADOWRECT
:
7595 case TGSI_TEXTURE_2D_ARRAY
:
7596 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7597 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7599 case TGSI_TEXTURE_1D
:
7600 case TGSI_TEXTURE_SHADOW1D
:
7601 case TGSI_TEXTURE_1D_ARRAY
:
7602 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7603 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7608 /* Obtain the sample index for reading a compressed MSAA color texture.
7609 * To read the FMASK, we use the ldfptr instruction, which tells us
7610 * where the samples are stored.
7611 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7612 * which is the identity mapping. Each nibble says which physical sample
7613 * should be fetched to get that sample.
7615 * Assume src.z contains the sample index. It should be modified like this:
7616 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7617 * Then fetch the texel with src.
7619 if (read_compressed_msaa
) {
7620 unsigned sample_chan
= 3;
7621 unsigned temp
= r600_get_temp(ctx
);
7624 /* temp.w = ldfptr() */
7625 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7626 tex
.op
= FETCH_OP_LD
;
7627 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7628 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7629 tex
.sampler_index_mode
= sampler_index_mode
;
7630 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7631 tex
.resource_index_mode
= sampler_index_mode
;
7632 tex
.src_gpr
= src_gpr
;
7634 tex
.dst_sel_x
= 7; /* mask out these components */
7637 tex
.dst_sel_w
= 0; /* store X */
7642 tex
.offset_x
= offset_x
;
7643 tex
.offset_y
= offset_y
;
7644 tex
.offset_z
= offset_z
;
7645 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7649 /* temp.x = sample_index*4 */
7650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7651 alu
.op
= ALU_OP2_MULLO_INT
;
7652 alu
.src
[0].sel
= src_gpr
;
7653 alu
.src
[0].chan
= sample_chan
;
7654 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7655 alu
.src
[1].value
= 4;
7659 r
= emit_mul_int_op(ctx
->bc
, &alu
);
7663 /* sample_index = temp.w >> temp.x */
7664 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7665 alu
.op
= ALU_OP2_LSHR_INT
;
7666 alu
.src
[0].sel
= temp
;
7667 alu
.src
[0].chan
= 3;
7668 alu
.src
[1].sel
= temp
;
7669 alu
.src
[1].chan
= 0;
7670 alu
.dst
.sel
= src_gpr
;
7671 alu
.dst
.chan
= sample_chan
;
7674 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7678 /* sample_index & 0xF */
7679 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7680 alu
.op
= ALU_OP2_AND_INT
;
7681 alu
.src
[0].sel
= src_gpr
;
7682 alu
.src
[0].chan
= sample_chan
;
7683 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7684 alu
.src
[1].value
= 0xF;
7685 alu
.dst
.sel
= src_gpr
;
7686 alu
.dst
.chan
= sample_chan
;
7689 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7693 /* visualize the FMASK */
7694 for (i
= 0; i
< 4; i
++) {
7695 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7696 alu
.op
= ALU_OP1_INT_TO_FLT
;
7697 alu
.src
[0].sel
= src_gpr
;
7698 alu
.src
[0].chan
= sample_chan
;
7699 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7703 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7711 /* does this shader want a num layers from TXQ for a cube array? */
7712 if (has_txq_cube_array_z
) {
7713 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7715 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7716 alu
.op
= ALU_OP1_MOV
;
7718 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7719 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7720 /* with eg each dword is number of cubes */
7721 alu
.src
[0].sel
+= id
/ 4;
7722 alu
.src
[0].chan
= id
% 4;
7724 /* r600 we have them at channel 2 of the second dword */
7725 alu
.src
[0].sel
+= (id
* 2) + 1;
7726 alu
.src
[0].chan
= 2;
7728 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7729 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7731 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7734 /* disable writemask from texture instruction */
7735 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7738 opcode
= ctx
->inst_info
->op
;
7739 if (opcode
== FETCH_OP_GATHER4
&&
7740 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7741 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7742 opcode
= FETCH_OP_GATHER4_O
;
7744 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7745 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7746 encoded in the instruction are ignored. */
7747 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7748 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7749 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7750 tex
.sampler_index_mode
= sampler_index_mode
;
7751 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7752 tex
.resource_index_mode
= sampler_index_mode
;
7754 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7755 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7756 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7757 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7765 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7770 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7771 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7772 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7773 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7774 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7775 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7776 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7778 case FETCH_OP_SAMPLE
:
7779 opcode
= FETCH_OP_SAMPLE_C
;
7781 case FETCH_OP_SAMPLE_L
:
7782 opcode
= FETCH_OP_SAMPLE_C_L
;
7784 case FETCH_OP_SAMPLE_LB
:
7785 opcode
= FETCH_OP_SAMPLE_C_LB
;
7787 case FETCH_OP_SAMPLE_G
:
7788 opcode
= FETCH_OP_SAMPLE_C_G
;
7790 /* Texture gather variants */
7791 case FETCH_OP_GATHER4
:
7792 opcode
= FETCH_OP_GATHER4_C
;
7794 case FETCH_OP_GATHER4_O
:
7795 opcode
= FETCH_OP_GATHER4_C_O
;
7800 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7803 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7804 tex
.sampler_index_mode
= sampler_index_mode
;
7805 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7806 tex
.resource_index_mode
= sampler_index_mode
;
7807 tex
.src_gpr
= src_gpr
;
7808 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7810 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7811 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7812 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7815 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7816 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7817 tex
.inst_mod
= texture_component_select
;
7819 if (ctx
->bc
->chip_class
== CAYMAN
) {
7820 /* GATHER4 result order is different from TGSI TG4 */
7821 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7822 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7823 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7824 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7826 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7827 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7828 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7829 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7832 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7833 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7834 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7838 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7845 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7846 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7847 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7848 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7852 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7857 } else if (src_loaded
) {
7863 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7864 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7865 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7866 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7867 tex
.src_rel
= ctx
->src
[0].rel
;
7870 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7871 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7872 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7873 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7877 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7880 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7881 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7882 tex
.coord_type_x
= 1;
7883 tex
.coord_type_y
= 1;
7885 tex
.coord_type_z
= 1;
7886 tex
.coord_type_w
= 1;
7888 tex
.offset_x
= offset_x
;
7889 tex
.offset_y
= offset_y
;
7890 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7891 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7892 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7896 tex
.offset_z
= offset_z
;
7899 /* Put the depth for comparison in W.
7900 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7901 * Some instructions expect the depth in Z. */
7902 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7903 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7904 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7905 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7906 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7907 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7908 tex
.src_sel_w
= tex
.src_sel_z
;
7911 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7912 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7913 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7914 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7915 /* the array index is read from Y */
7916 tex
.coord_type_y
= 0;
7918 /* the array index is read from Z */
7919 tex
.coord_type_z
= 0;
7920 tex
.src_sel_z
= tex
.src_sel_y
;
7922 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7923 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7924 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7925 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7926 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7927 /* the array index is read from Z */
7928 tex
.coord_type_z
= 0;
7930 /* mask unused source components */
7931 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7932 switch (inst
->Texture
.Texture
) {
7933 case TGSI_TEXTURE_2D
:
7934 case TGSI_TEXTURE_RECT
:
7938 case TGSI_TEXTURE_1D_ARRAY
:
7942 case TGSI_TEXTURE_1D
:
7950 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7954 /* add shadow ambient support - gallium doesn't do it yet */
7958 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7959 struct tgsi_full_src_register
*src
)
7963 if (src
->Register
.Indirect
) {
7964 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7965 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7966 return ctx
->shader
->atomics
[i
].hw_idx
;
7969 uint32_t index
= src
->Register
.Index
;
7970 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7971 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
7973 if (index
> ctx
->shader
->atomics
[i
].end
)
7975 if (index
< ctx
->shader
->atomics
[i
].start
)
7977 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7978 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7985 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
7986 int *uav_id_p
, int *uav_index_mode_p
)
7988 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7989 int uav_id
, uav_index_mode
= 0;
7991 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7993 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7995 if (inst
->Src
[0].Register
.Indirect
) {
7997 struct r600_bytecode_alu alu
;
7998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7999 alu
.op
= ALU_OP2_LSHL_INT
;
8000 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
8001 alu
.src
[0].chan
= 0;
8002 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8003 alu
.src
[1].value
= 2;
8004 alu
.dst
.sel
= ctx
->temp_reg
;
8008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8012 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8015 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
8021 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8023 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
8029 *uav_index_mode_p
= uav_index_mode
;
8033 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
8035 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8037 struct r600_bytecode_gds gds
;
8039 int uav_index_mode
= 0;
8040 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8042 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8046 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8047 gds
.op
= FETCH_OP_GDS_READ_RET
;
8048 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8049 gds
.uav_id
= is_cm
? 0 : uav_id
;
8050 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8051 gds
.src_gpr
= ctx
->temp_reg
;
8052 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
8060 gds
.alloc_consume
= !is_cm
;
8061 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8065 ctx
->bc
->cf_last
->vpm
= 1;
8069 /* this fixes up 1D arrays properly */
8070 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
8072 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8074 struct r600_bytecode_alu alu
;
8075 int temp_reg
= r600_get_temp(ctx
);
8077 for (i
= 0; i
< 4; i
++) {
8078 bool def_val
= true, write_zero
= false;
8079 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8080 alu
.op
= ALU_OP1_MOV
;
8081 alu
.dst
.sel
= temp_reg
;
8084 switch (inst
->Memory
.Texture
) {
8085 case TGSI_TEXTURE_BUFFER
:
8086 case TGSI_TEXTURE_1D
:
8087 if (i
== 1 || i
== 2 || i
== 3) {
8091 case TGSI_TEXTURE_1D_ARRAY
:
8092 if (i
== 1 || i
== 3)
8095 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8099 case TGSI_TEXTURE_2D
:
8100 if (i
== 2 || i
== 3)
8110 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8111 alu
.src
[0].value
= 0;
8112 } else if (def_val
) {
8113 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8119 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8123 *idx_gpr
= temp_reg
;
8127 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8130 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8132 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8133 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8134 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8136 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8141 struct r600_bytecode_alu alu
;
8142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8143 alu
.op
= ALU_OP2_LSHR_INT
;
8144 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8145 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8146 alu
.src
[1].value
= 2;
8147 alu
.dst
.sel
= temp_reg
;
8150 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8157 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8159 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8160 /* have to work out the offset into the RAT immediate return buffer */
8161 struct r600_bytecode_vtx vtx
;
8162 struct r600_bytecode_cf
*cf
;
8164 int temp_reg
= r600_get_temp(ctx
);
8165 unsigned rat_index_mode
;
8168 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8169 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8171 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8174 ctx
->bc
->cf_last
->barrier
= 1;
8175 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8176 vtx
.op
= FETCH_OP_VFETCH
;
8177 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8178 vtx
.buffer_index_mode
= rat_index_mode
;
8179 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8180 vtx
.src_gpr
= temp_reg
;
8182 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8183 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8184 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8185 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8186 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8187 vtx
.num_format_all
= 1;
8188 vtx
.format_comp_all
= 1;
8189 vtx
.srf_mode_all
= 0;
8191 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8192 vtx
.data_format
= FMT_32_32_32_32
;
8193 vtx
.use_const_fields
= 0;
8194 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8195 vtx
.data_format
= FMT_32_32_32
;
8196 vtx
.use_const_fields
= 0;
8197 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8198 vtx
.data_format
= FMT_32_32
;
8199 vtx
.use_const_fields
= 0;
8201 vtx
.data_format
= FMT_32
;
8202 vtx
.use_const_fields
= 0;
8205 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8208 cf
= ctx
->bc
->cf_last
;
8213 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8215 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8216 /* have to work out the offset into the RAT immediate return buffer */
8217 struct r600_bytecode_vtx vtx
;
8218 struct r600_bytecode_cf
*cf
;
8221 unsigned format
, num_format
, format_comp
, endian
;
8222 const struct util_format_description
*desc
;
8223 unsigned rat_index_mode
;
8224 unsigned immed_base
;
8226 r
= load_thread_id_gpr(ctx
);
8230 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8232 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8233 r
= load_index_src(ctx
, 1, &idx_gpr
);
8238 egcm_load_index_reg(ctx
->bc
, 1, false);
8240 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8241 cf
= ctx
->bc
->cf_last
;
8243 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8244 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8245 cf
->rat
.index_mode
= rat_index_mode
;
8246 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8247 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8248 cf
->output
.index_gpr
= idx_gpr
;
8249 cf
->output
.comp_mask
= 0xf;
8250 cf
->output
.burst_count
= 1;
8254 cf
->output
.elem_size
= 0;
8256 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8257 cf
= ctx
->bc
->cf_last
;
8260 desc
= util_format_description(inst
->Memory
.Format
);
8261 r600_vertex_data_type(inst
->Memory
.Format
,
8262 &format
, &num_format
, &format_comp
, &endian
);
8263 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8264 vtx
.op
= FETCH_OP_VFETCH
;
8265 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8266 vtx
.buffer_index_mode
= rat_index_mode
;
8267 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8268 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8270 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8271 vtx
.dst_sel_x
= desc
->swizzle
[0];
8272 vtx
.dst_sel_y
= desc
->swizzle
[1];
8273 vtx
.dst_sel_z
= desc
->swizzle
[2];
8274 vtx
.dst_sel_w
= desc
->swizzle
[3];
8275 vtx
.srf_mode_all
= 1;
8276 vtx
.data_format
= format
;
8277 vtx
.num_format_all
= num_format
;
8278 vtx
.format_comp_all
= format_comp
;
8279 vtx
.endian
= endian
;
8281 vtx
.mega_fetch_count
= 3;
8282 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8285 cf
= ctx
->bc
->cf_last
;
8290 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8292 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8293 struct r600_bytecode_alu alu
;
8295 int temp_reg
= r600_get_temp(ctx
);
8297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8298 alu
.op
= ALU_OP1_MOV
;
8299 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8300 alu
.dst
.sel
= temp_reg
;
8303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8307 r
= do_lds_fetch_values(ctx
, temp_reg
,
8308 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8314 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8316 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8317 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8318 return tgsi_load_rat(ctx
);
8319 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8320 return tgsi_load_gds(ctx
);
8321 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8322 return tgsi_load_buffer(ctx
);
8323 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8324 return tgsi_load_lds(ctx
);
8328 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8330 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8331 struct r600_bytecode_cf
*cf
;
8333 unsigned rat_index_mode
;
8335 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8337 r
= load_buffer_coord(ctx
, 0, treg2
);
8341 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8343 egcm_load_index_reg(ctx
->bc
, 1, false);
8345 for (i
= 0; i
<= 3; i
++) {
8346 struct r600_bytecode_alu alu
;
8347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8348 alu
.op
= ALU_OP1_MOV
;
8349 alu
.dst
.sel
= temp_reg
;
8351 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8352 alu
.last
= (i
== 3);
8354 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8359 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8360 for (i
= 0; i
<= lasti
; i
++) {
8361 struct r600_bytecode_alu alu
;
8362 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8365 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8368 V_SQ_ALU_SRC_LITERAL
, i
);
8372 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8373 alu
.op
= ALU_OP1_MOV
;
8374 alu
.dst
.sel
= ctx
->temp_reg
;
8377 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8380 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8384 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8385 cf
= ctx
->bc
->cf_last
;
8387 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8388 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8389 cf
->rat
.index_mode
= rat_index_mode
;
8390 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8391 cf
->output
.gpr
= ctx
->temp_reg
;
8392 cf
->output
.index_gpr
= temp_reg
;
8393 cf
->output
.comp_mask
= 1;
8394 cf
->output
.burst_count
= 1;
8397 cf
->output
.elem_size
= 0;
8402 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8404 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8405 struct r600_bytecode_cf
*cf
;
8406 bool src_requires_loading
= false;
8407 int val_gpr
, idx_gpr
;
8409 unsigned rat_index_mode
;
8411 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8413 r
= load_index_src(ctx
, 0, &idx_gpr
);
8417 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8418 src_requires_loading
= true;
8420 if (src_requires_loading
) {
8421 struct r600_bytecode_alu alu
;
8422 for (i
= 0; i
< 4; i
++) {
8423 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8424 alu
.op
= ALU_OP1_MOV
;
8425 alu
.dst
.sel
= ctx
->temp_reg
;
8428 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8432 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8436 val_gpr
= ctx
->temp_reg
;
8438 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8440 egcm_load_index_reg(ctx
->bc
, 1, false);
8442 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8443 cf
= ctx
->bc
->cf_last
;
8445 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8446 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8447 cf
->rat
.index_mode
= rat_index_mode
;
8448 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8449 cf
->output
.gpr
= val_gpr
;
8450 cf
->output
.index_gpr
= idx_gpr
;
8451 cf
->output
.comp_mask
= 0xf;
8452 cf
->output
.burst_count
= 1;
8455 cf
->output
.elem_size
= 0;
8459 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8461 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8462 struct r600_bytecode_alu alu
;
8464 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8465 int temp_reg
= r600_get_temp(ctx
);
8468 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8469 alu
.op
= ALU_OP1_MOV
;
8470 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8471 alu
.dst
.sel
= temp_reg
;
8474 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8478 lasti
= tgsi_last_instruction(write_mask
);
8479 for (i
= 1; i
<= lasti
; i
++) {
8480 if (!(write_mask
& (1 << i
)))
8482 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8485 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8489 for (i
= 0; i
<= lasti
; i
++) {
8490 if (!(write_mask
& (1 << i
)))
8493 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8494 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8495 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8496 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8498 alu
.src
[0].sel
= temp_reg
;
8499 alu
.src
[0].chan
= i
;
8500 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8501 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8503 alu
.is_lds_idx_op
= true;
8505 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8511 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8512 alu
.op
= LDS_OP2_LDS_WRITE
;
8514 alu
.src
[0].sel
= temp_reg
;
8515 alu
.src
[0].chan
= i
;
8516 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8519 alu
.is_lds_idx_op
= true;
8521 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8528 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8530 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8531 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8532 return tgsi_store_buffer_rat(ctx
);
8533 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8534 return tgsi_store_lds(ctx
);
8536 return tgsi_store_rat(ctx
);
8539 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8541 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8542 /* have to work out the offset into the RAT immediate return buffer */
8543 struct r600_bytecode_alu alu
;
8544 struct r600_bytecode_vtx vtx
;
8545 struct r600_bytecode_cf
*cf
;
8548 unsigned format
, num_format
, format_comp
, endian
;
8549 const struct util_format_description
*desc
;
8550 unsigned rat_index_mode
;
8551 unsigned immed_base
;
8554 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8555 rat_base
= ctx
->shader
->rat_base
;
8557 r
= load_thread_id_gpr(ctx
);
8561 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8562 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8563 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8565 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8568 idx_gpr
= ctx
->temp_reg
;
8570 r
= load_index_src(ctx
, 1, &idx_gpr
);
8575 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8577 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8578 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8579 alu
.op
= ALU_OP1_MOV
;
8580 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8583 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8585 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8589 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8590 alu
.op
= ALU_OP1_MOV
;
8591 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8592 if (ctx
->bc
->chip_class
== CAYMAN
)
8597 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8599 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8603 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8604 alu
.op
= ALU_OP1_MOV
;
8605 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8608 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8610 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8616 egcm_load_index_reg(ctx
->bc
, 1, false);
8617 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8618 cf
= ctx
->bc
->cf_last
;
8620 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
8621 cf
->rat
.inst
= ctx
->inst_info
->op
;
8622 cf
->rat
.index_mode
= rat_index_mode
;
8623 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8624 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8625 cf
->output
.index_gpr
= idx_gpr
;
8626 cf
->output
.comp_mask
= 0xf;
8627 cf
->output
.burst_count
= 1;
8631 cf
->output
.elem_size
= 0;
8632 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8633 cf
= ctx
->bc
->cf_last
;
8637 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8638 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
8639 desc
= util_format_description(inst
->Memory
.Format
);
8640 r600_vertex_data_type(inst
->Memory
.Format
,
8641 &format
, &num_format
, &format_comp
, &endian
);
8642 vtx
.dst_sel_x
= desc
->swizzle
[0];
8650 vtx
.op
= FETCH_OP_VFETCH
;
8651 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8652 vtx
.buffer_index_mode
= rat_index_mode
;
8653 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8654 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8656 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8660 vtx
.use_const_fields
= 0;
8661 vtx
.srf_mode_all
= 1;
8662 vtx
.data_format
= format
;
8663 vtx
.num_format_all
= num_format
;
8664 vtx
.format_comp_all
= format_comp
;
8665 vtx
.endian
= endian
;
8667 vtx
.mega_fetch_count
= 0xf;
8668 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8671 cf
= ctx
->bc
->cf_last
;
8677 static int get_gds_op(int opcode
)
8680 case TGSI_OPCODE_ATOMUADD
:
8681 return FETCH_OP_GDS_ADD_RET
;
8682 case TGSI_OPCODE_ATOMAND
:
8683 return FETCH_OP_GDS_AND_RET
;
8684 case TGSI_OPCODE_ATOMOR
:
8685 return FETCH_OP_GDS_OR_RET
;
8686 case TGSI_OPCODE_ATOMXOR
:
8687 return FETCH_OP_GDS_XOR_RET
;
8688 case TGSI_OPCODE_ATOMUMIN
:
8689 return FETCH_OP_GDS_MIN_UINT_RET
;
8690 case TGSI_OPCODE_ATOMUMAX
:
8691 return FETCH_OP_GDS_MAX_UINT_RET
;
8692 case TGSI_OPCODE_ATOMXCHG
:
8693 return FETCH_OP_GDS_XCHG_RET
;
8694 case TGSI_OPCODE_ATOMCAS
:
8695 return FETCH_OP_GDS_CMP_XCHG_RET
;
8701 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8703 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8704 struct r600_bytecode_gds gds
;
8705 struct r600_bytecode_alu alu
;
8706 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8709 int uav_index_mode
= 0;
8710 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8713 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8717 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8721 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
) {
8722 if (inst
->Src
[3].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8723 int value
= (ctx
->literals
[4 * inst
->Src
[3].Register
.Index
+ inst
->Src
[3].Register
.SwizzleX
]);
8724 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8725 alu
.op
= ALU_OP1_MOV
;
8726 alu
.dst
.sel
= ctx
->temp_reg
;
8727 alu
.dst
.chan
= is_cm
? 2 : 1;
8728 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8729 alu
.src
[0].value
= value
;
8732 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8736 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8737 alu
.op
= ALU_OP1_MOV
;
8738 alu
.dst
.sel
= ctx
->temp_reg
;
8739 alu
.dst
.chan
= is_cm
? 2 : 1;
8740 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8743 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8748 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8749 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8750 int abs_value
= abs(value
);
8751 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8752 gds_op
= FETCH_OP_GDS_SUB_RET
;
8753 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8754 alu
.op
= ALU_OP1_MOV
;
8755 alu
.dst
.sel
= ctx
->temp_reg
;
8756 alu
.dst
.chan
= is_cm
? 1 : 0;
8757 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8758 alu
.src
[0].value
= abs_value
;
8761 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8765 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8766 alu
.op
= ALU_OP1_MOV
;
8767 alu
.dst
.sel
= ctx
->temp_reg
;
8768 alu
.dst
.chan
= is_cm
? 1 : 0;
8769 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8772 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8778 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8780 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8781 gds
.uav_id
= is_cm
? 0 : uav_id
;
8782 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8783 gds
.src_gpr
= ctx
->temp_reg
;
8785 gds
.src_sel_x
= is_cm
? 0 : 4;
8786 gds
.src_sel_y
= is_cm
? 1 : 0;
8787 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
)
8788 gds
.src_sel_z
= is_cm
? 2 : 1;
8795 gds
.alloc_consume
= !is_cm
;
8797 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8800 ctx
->bc
->cf_last
->vpm
= 1;
8804 static int get_lds_op(int opcode
)
8807 case TGSI_OPCODE_ATOMUADD
:
8808 return LDS_OP2_LDS_ADD_RET
;
8809 case TGSI_OPCODE_ATOMAND
:
8810 return LDS_OP2_LDS_AND_RET
;
8811 case TGSI_OPCODE_ATOMOR
:
8812 return LDS_OP2_LDS_OR_RET
;
8813 case TGSI_OPCODE_ATOMXOR
:
8814 return LDS_OP2_LDS_XOR_RET
;
8815 case TGSI_OPCODE_ATOMUMIN
:
8816 return LDS_OP2_LDS_MIN_UINT_RET
;
8817 case TGSI_OPCODE_ATOMUMAX
:
8818 return LDS_OP2_LDS_MAX_UINT_RET
;
8819 case TGSI_OPCODE_ATOMIMIN
:
8820 return LDS_OP2_LDS_MIN_INT_RET
;
8821 case TGSI_OPCODE_ATOMIMAX
:
8822 return LDS_OP2_LDS_MAX_INT_RET
;
8823 case TGSI_OPCODE_ATOMXCHG
:
8824 return LDS_OP2_LDS_XCHG_RET
;
8825 case TGSI_OPCODE_ATOMCAS
:
8826 return LDS_OP3_LDS_CMP_XCHG_RET
;
8832 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
8834 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8835 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
8838 struct r600_bytecode_alu alu
;
8839 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8841 alu
.is_lds_idx_op
= true;
8843 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8844 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
8845 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
8846 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
8848 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
8849 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8853 /* then read from LDS_OQ_A_POP */
8854 memset(&alu
, 0, sizeof(alu
));
8856 alu
.op
= ALU_OP1_MOV
;
8857 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
8858 alu
.src
[0].chan
= 0;
8859 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
8862 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8869 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
8871 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8872 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8873 return tgsi_atomic_op_rat(ctx
);
8874 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8875 return tgsi_atomic_op_gds(ctx
);
8876 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8877 return tgsi_atomic_op_rat(ctx
);
8878 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8879 return tgsi_atomic_op_lds(ctx
);
8883 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
8885 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8886 unsigned sampler_index_mode
;
8887 struct r600_bytecode_tex tex
;
8889 boolean has_txq_cube_array_z
= false;
8891 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
8892 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
8893 if (ctx
->bc
->chip_class
< EVERGREEN
)
8894 ctx
->shader
->uses_tex_buffers
= true;
8895 unsigned eg_buffer_base
= 0;
8896 eg_buffer_base
= R600_IMAGE_REAL_RESOURCE_OFFSET
;
8897 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8898 eg_buffer_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8899 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
, eg_buffer_base
);
8902 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
8903 inst
->Dst
[0].Register
.WriteMask
& 4) {
8904 ctx
->shader
->has_txq_cube_array_z_comp
= true;
8905 has_txq_cube_array_z
= true;
8908 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8909 if (sampler_index_mode
)
8910 egcm_load_index_reg(ctx
->bc
, 1, false);
8913 /* does this shader want a num layers from TXQ for a cube array? */
8914 if (has_txq_cube_array_z
) {
8915 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
8916 struct r600_bytecode_alu alu
;
8918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8919 alu
.op
= ALU_OP1_MOV
;
8921 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8922 /* with eg each dword is either number of cubes */
8923 alu
.src
[0].sel
+= id
/ 4;
8924 alu
.src
[0].chan
= id
% 4;
8925 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8926 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8931 /* disable writemask from texture instruction */
8932 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8934 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8935 tex
.op
= ctx
->inst_info
->op
;
8936 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
8937 tex
.sampler_index_mode
= sampler_index_mode
;
8938 tex
.resource_id
= tex
.sampler_id
;
8939 tex
.resource_index_mode
= sampler_index_mode
;
8944 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8945 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8946 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8947 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8948 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8949 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8956 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
8958 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8959 struct r600_bytecode_alu alu
;
8960 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8961 unsigned i
, temp_regs
[2];
8964 /* optimize if it's just an equal balance */
8965 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
8966 for (i
= 0; i
< lasti
+ 1; i
++) {
8967 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8970 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8971 alu
.op
= ALU_OP2_ADD
;
8972 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8973 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8975 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8988 for (i
= 0; i
< lasti
+ 1; i
++) {
8989 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8992 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8993 alu
.op
= ALU_OP2_ADD
;
8994 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8995 alu
.src
[0].chan
= 0;
8996 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
8997 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
8998 alu
.dst
.sel
= ctx
->temp_reg
;
9004 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9009 /* (1 - src0) * src2 */
9010 for (i
= 0; i
< lasti
+ 1; i
++) {
9011 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9014 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9015 alu
.op
= ALU_OP2_MUL
;
9016 alu
.src
[0].sel
= ctx
->temp_reg
;
9017 alu
.src
[0].chan
= i
;
9018 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9019 alu
.dst
.sel
= ctx
->temp_reg
;
9025 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9030 /* src0 * src1 + (1 - src0) * src2 */
9031 if (ctx
->src
[0].abs
)
9032 temp_regs
[0] = r600_get_temp(ctx
);
9035 if (ctx
->src
[1].abs
)
9036 temp_regs
[1] = r600_get_temp(ctx
);
9040 for (i
= 0; i
< lasti
+ 1; i
++) {
9041 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9044 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9045 alu
.op
= ALU_OP3_MULADD
;
9047 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9050 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
9053 alu
.src
[2].sel
= ctx
->temp_reg
;
9054 alu
.src
[2].chan
= i
;
9056 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9061 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9068 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
9070 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9071 struct r600_bytecode_alu alu
;
9073 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9077 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
9079 ctx
->src
[0].abs
= 0;
9080 ctx
->src
[0].neg
= 0;
9085 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
9087 if (ctx
->src
[j
].abs
)
9088 temp_regs
[j
] = r600_get_temp(ctx
);
9091 for (i
= 0; i
< lasti
+ 1; i
++) {
9092 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9095 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9097 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9100 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
9103 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
9106 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9112 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9119 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9121 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9122 struct r600_bytecode_alu alu
;
9124 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9126 for (i
= 0; i
< lasti
+ 1; i
++) {
9127 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9130 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9131 alu
.op
= ALU_OP3_CNDE_INT
;
9132 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9133 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9134 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9135 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9141 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9148 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9150 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9151 struct r600_bytecode_alu alu
;
9155 /* result.x = 2^floor(src); */
9156 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9157 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9159 alu
.op
= ALU_OP1_FLOOR
;
9160 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9162 alu
.dst
.sel
= ctx
->temp_reg
;
9166 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9170 if (ctx
->bc
->chip_class
== CAYMAN
) {
9171 for (i
= 0; i
< 3; i
++) {
9172 alu
.op
= ALU_OP1_EXP_IEEE
;
9173 alu
.src
[0].sel
= ctx
->temp_reg
;
9174 alu
.src
[0].chan
= 0;
9176 alu
.dst
.sel
= ctx
->temp_reg
;
9178 alu
.dst
.write
= i
== 0;
9180 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9185 alu
.op
= ALU_OP1_EXP_IEEE
;
9186 alu
.src
[0].sel
= ctx
->temp_reg
;
9187 alu
.src
[0].chan
= 0;
9189 alu
.dst
.sel
= ctx
->temp_reg
;
9193 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9199 /* result.y = tmp - floor(tmp); */
9200 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9203 alu
.op
= ALU_OP1_FRACT
;
9204 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9206 alu
.dst
.sel
= ctx
->temp_reg
;
9208 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9217 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9222 /* result.z = RoughApprox2ToX(tmp);*/
9223 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9224 if (ctx
->bc
->chip_class
== CAYMAN
) {
9225 for (i
= 0; i
< 3; i
++) {
9226 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9227 alu
.op
= ALU_OP1_EXP_IEEE
;
9228 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9230 alu
.dst
.sel
= ctx
->temp_reg
;
9237 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9242 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9243 alu
.op
= ALU_OP1_EXP_IEEE
;
9244 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9246 alu
.dst
.sel
= ctx
->temp_reg
;
9252 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9258 /* result.w = 1.0;*/
9259 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9262 alu
.op
= ALU_OP1_MOV
;
9263 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9264 alu
.src
[0].chan
= 0;
9266 alu
.dst
.sel
= ctx
->temp_reg
;
9270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9274 return tgsi_helper_copy(ctx
, inst
);
9277 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9279 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9280 struct r600_bytecode_alu alu
;
9284 /* result.x = floor(log2(|src|)); */
9285 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9286 if (ctx
->bc
->chip_class
== CAYMAN
) {
9287 for (i
= 0; i
< 3; i
++) {
9288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9290 alu
.op
= ALU_OP1_LOG_IEEE
;
9291 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9292 r600_bytecode_src_set_abs(&alu
.src
[0]);
9294 alu
.dst
.sel
= ctx
->temp_reg
;
9300 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9306 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9308 alu
.op
= ALU_OP1_LOG_IEEE
;
9309 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9310 r600_bytecode_src_set_abs(&alu
.src
[0]);
9312 alu
.dst
.sel
= ctx
->temp_reg
;
9316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9321 alu
.op
= ALU_OP1_FLOOR
;
9322 alu
.src
[0].sel
= ctx
->temp_reg
;
9323 alu
.src
[0].chan
= 0;
9325 alu
.dst
.sel
= ctx
->temp_reg
;
9330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9335 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9336 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9338 if (ctx
->bc
->chip_class
== CAYMAN
) {
9339 for (i
= 0; i
< 3; i
++) {
9340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9342 alu
.op
= ALU_OP1_LOG_IEEE
;
9343 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9344 r600_bytecode_src_set_abs(&alu
.src
[0]);
9346 alu
.dst
.sel
= ctx
->temp_reg
;
9353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9358 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9360 alu
.op
= ALU_OP1_LOG_IEEE
;
9361 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9362 r600_bytecode_src_set_abs(&alu
.src
[0]);
9364 alu
.dst
.sel
= ctx
->temp_reg
;
9369 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9376 alu
.op
= ALU_OP1_FLOOR
;
9377 alu
.src
[0].sel
= ctx
->temp_reg
;
9378 alu
.src
[0].chan
= 1;
9380 alu
.dst
.sel
= ctx
->temp_reg
;
9385 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9389 if (ctx
->bc
->chip_class
== CAYMAN
) {
9390 for (i
= 0; i
< 3; i
++) {
9391 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9392 alu
.op
= ALU_OP1_EXP_IEEE
;
9393 alu
.src
[0].sel
= ctx
->temp_reg
;
9394 alu
.src
[0].chan
= 1;
9396 alu
.dst
.sel
= ctx
->temp_reg
;
9403 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9408 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9409 alu
.op
= ALU_OP1_EXP_IEEE
;
9410 alu
.src
[0].sel
= ctx
->temp_reg
;
9411 alu
.src
[0].chan
= 1;
9413 alu
.dst
.sel
= ctx
->temp_reg
;
9418 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9423 if (ctx
->bc
->chip_class
== CAYMAN
) {
9424 for (i
= 0; i
< 3; i
++) {
9425 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9426 alu
.op
= ALU_OP1_RECIP_IEEE
;
9427 alu
.src
[0].sel
= ctx
->temp_reg
;
9428 alu
.src
[0].chan
= 1;
9430 alu
.dst
.sel
= ctx
->temp_reg
;
9437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9442 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9443 alu
.op
= ALU_OP1_RECIP_IEEE
;
9444 alu
.src
[0].sel
= ctx
->temp_reg
;
9445 alu
.src
[0].chan
= 1;
9447 alu
.dst
.sel
= ctx
->temp_reg
;
9452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9457 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9459 alu
.op
= ALU_OP2_MUL
;
9461 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9462 r600_bytecode_src_set_abs(&alu
.src
[0]);
9464 alu
.src
[1].sel
= ctx
->temp_reg
;
9465 alu
.src
[1].chan
= 1;
9467 alu
.dst
.sel
= ctx
->temp_reg
;
9472 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9477 /* result.z = log2(|src|);*/
9478 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9479 if (ctx
->bc
->chip_class
== CAYMAN
) {
9480 for (i
= 0; i
< 3; i
++) {
9481 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9483 alu
.op
= ALU_OP1_LOG_IEEE
;
9484 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9485 r600_bytecode_src_set_abs(&alu
.src
[0]);
9487 alu
.dst
.sel
= ctx
->temp_reg
;
9494 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
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
;
9510 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9516 /* result.w = 1.0; */
9517 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9520 alu
.op
= ALU_OP1_MOV
;
9521 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9522 alu
.src
[0].chan
= 0;
9524 alu
.dst
.sel
= ctx
->temp_reg
;
9529 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9534 return tgsi_helper_copy(ctx
, inst
);
9537 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9539 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9540 struct r600_bytecode_alu alu
;
9542 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9543 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9545 assert(inst
->Dst
[0].Register
.Index
< 3);
9546 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9548 switch (inst
->Instruction
.Opcode
) {
9549 case TGSI_OPCODE_ARL
:
9550 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9552 case TGSI_OPCODE_ARR
:
9553 alu
.op
= ALU_OP1_FLT_TO_INT
;
9555 case TGSI_OPCODE_UARL
:
9556 alu
.op
= ALU_OP1_MOV
;
9563 for (i
= 0; i
<= lasti
; ++i
) {
9564 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9566 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9567 alu
.last
= i
== lasti
;
9571 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9576 if (inst
->Dst
[0].Register
.Index
> 0)
9577 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
9579 ctx
->bc
->ar_loaded
= 0;
9583 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
9585 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9586 struct r600_bytecode_alu alu
;
9588 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9590 switch (inst
->Instruction
.Opcode
) {
9591 case TGSI_OPCODE_ARL
:
9592 memset(&alu
, 0, sizeof(alu
));
9593 alu
.op
= ALU_OP1_FLOOR
;
9594 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9596 for (i
= 0; i
<= lasti
; ++i
) {
9597 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9599 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9600 alu
.last
= i
== lasti
;
9601 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9606 memset(&alu
, 0, sizeof(alu
));
9607 alu
.op
= ALU_OP1_FLT_TO_INT
;
9608 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
9609 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9611 /* FLT_TO_INT is trans-only on r600/r700 */
9613 for (i
= 0; i
<= lasti
; ++i
) {
9615 alu
.src
[0].chan
= i
;
9616 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9620 case TGSI_OPCODE_ARR
:
9621 memset(&alu
, 0, sizeof(alu
));
9622 alu
.op
= ALU_OP1_FLT_TO_INT
;
9623 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9625 /* FLT_TO_INT is trans-only on r600/r700 */
9627 for (i
= 0; i
<= lasti
; ++i
) {
9628 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9630 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9631 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9636 case TGSI_OPCODE_UARL
:
9637 memset(&alu
, 0, sizeof(alu
));
9638 alu
.op
= ALU_OP1_MOV
;
9639 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9641 for (i
= 0; i
<= lasti
; ++i
) {
9642 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9644 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9645 alu
.last
= i
== lasti
;
9646 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9656 ctx
->bc
->ar_loaded
= 0;
9660 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9662 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9663 struct r600_bytecode_alu alu
;
9666 for (i
= 0; i
< 4; i
++) {
9667 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9669 alu
.op
= ALU_OP2_MUL
;
9670 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9672 if (i
== 0 || i
== 3) {
9673 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9675 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9678 if (i
== 0 || i
== 2) {
9679 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9681 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9685 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9692 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
,
9693 struct r600_bytecode_alu_src
*src
)
9695 struct r600_bytecode_alu alu
;
9698 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9700 alu
.execute_mask
= 1;
9701 alu
.update_pred
= 1;
9703 alu
.dst
.sel
= ctx
->temp_reg
;
9708 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9709 alu
.src
[1].chan
= 0;
9713 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9719 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9721 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9725 if (ctx
->bc
->cf_last
) {
9726 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9728 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9733 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9734 ctx
->bc
->force_add_cf
= 1;
9735 } else if (alu_pop
== 2) {
9736 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9737 ctx
->bc
->force_add_cf
= 1;
9744 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9745 ctx
->bc
->cf_last
->pop_count
= pops
;
9746 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9752 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9755 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9759 unsigned entry_size
= stack
->entry_size
;
9761 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9762 elements
+= stack
->push
;
9764 switch (ctx
->bc
->chip_class
) {
9767 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9768 * the stack must be reserved to hold the current active/continue
9770 if (reason
== FC_PUSH_VPM
) {
9776 /* r9xx: any stack operation on empty stack consumes 2 additional
9781 /* FIXME: do the two elements added above cover the cases for the
9785 /* r8xx+: 2 extra elements are not always required, but one extra
9786 * element must be added for each of the following cases:
9787 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9789 * (Currently we don't use ALU_ELSE_AFTER.)
9790 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9791 * PUSH instruction executed.
9793 * NOTE: it seems we also need to reserve additional element in some
9794 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9795 * then STACK_SIZE should be 2 instead of 1 */
9796 if (reason
== FC_PUSH_VPM
) {
9806 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9807 * for all chips, so we use 4 in the final formula, not the real entry_size
9811 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9813 if (entries
> stack
->max_entries
)
9814 stack
->max_entries
= entries
;
9817 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9821 --ctx
->bc
->stack
.push
;
9822 assert(ctx
->bc
->stack
.push
>= 0);
9825 --ctx
->bc
->stack
.push_wqm
;
9826 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9829 --ctx
->bc
->stack
.loop
;
9830 assert(ctx
->bc
->stack
.loop
>= 0);
9838 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
9842 ++ctx
->bc
->stack
.push
;
9845 ++ctx
->bc
->stack
.push_wqm
;
9847 ++ctx
->bc
->stack
.loop
;
9853 callstack_update_max_depth(ctx
, reason
);
9856 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
9858 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
9860 sp
->mid
= realloc((void *)sp
->mid
,
9861 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
9862 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
9866 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
9868 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
9869 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
9870 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
9874 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
9876 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
9886 static int emit_return(struct r600_shader_ctx
*ctx
)
9888 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
9892 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
9895 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
9896 ctx
->bc
->cf_last
->pop_count
= pops
;
9897 /* XXX work out offset */
9901 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
9906 static void emit_testflag(struct r600_shader_ctx
*ctx
)
9911 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
9914 emit_jump_to_offset(ctx
, 1, 4);
9915 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
9916 pops(ctx
, ifidx
+ 1);
9920 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
9924 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9925 ctx
->bc
->cf_last
->pop_count
= 1;
9927 fc_set_mid(ctx
, fc_sp
);
9933 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
,
9934 struct r600_bytecode_alu_src
*src
)
9936 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
9938 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
9939 * LOOP_STARTxxx for nested loops may put the branch stack into a state
9940 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
9941 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
9942 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
9943 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
9944 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9945 alu_type
= CF_OP_ALU
;
9948 emit_logic_pred(ctx
, opcode
, alu_type
, src
);
9950 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
9952 fc_pushlevel(ctx
, FC_IF
);
9954 callstack_push(ctx
, FC_PUSH_VPM
);
9958 static int tgsi_if(struct r600_shader_ctx
*ctx
)
9960 struct r600_bytecode_alu_src alu_src
;
9961 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
9963 return emit_if(ctx
, ALU_OP2_PRED_SETNE
, &alu_src
);
9966 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
9968 struct r600_bytecode_alu_src alu_src
;
9969 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
9970 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
9973 static int tgsi_else(struct r600_shader_ctx
*ctx
)
9975 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
9976 ctx
->bc
->cf_last
->pop_count
= 1;
9978 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
9979 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
9983 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
9986 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
9987 R600_ERR("if/endif unbalanced in shader\n");
9991 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
9992 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9993 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
9995 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9999 callstack_pop(ctx
, FC_PUSH_VPM
);
10003 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
10005 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
10006 * limited to 4096 iterations, like the other LOOP_* instructions. */
10007 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
10009 fc_pushlevel(ctx
, FC_LOOP
);
10011 /* check stack depth */
10012 callstack_push(ctx
, FC_LOOP
);
10016 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
10020 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
10022 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
10023 R600_ERR("loop/endloop in shader code are not paired.\n");
10027 /* fixup loop pointers - from r600isa
10028 LOOP END points to CF after LOOP START,
10029 LOOP START point to CF after LOOP END
10030 BRK/CONT point to LOOP END CF
10032 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
10034 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10036 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
10037 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
10039 /* XXX add LOOPRET support */
10041 callstack_pop(ctx
, FC_LOOP
);
10045 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
10049 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
10051 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
10056 R600_ERR("Break not inside loop/endloop pair\n");
10060 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10062 fc_set_mid(ctx
, fscp
- 1);
10067 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
10069 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10070 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
10073 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10074 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
10076 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10078 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
10079 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10080 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
10085 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
10087 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10088 struct r600_bytecode_alu alu
;
10090 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10093 for (i
= 0; i
< lasti
+ 1; i
++) {
10094 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10097 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10100 alu
.dst
.sel
= ctx
->temp_reg
;
10103 alu
.op
= ALU_OP2_MULLO_UINT
;
10104 for (j
= 0; j
< 2; j
++) {
10105 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10109 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10115 for (i
= 0; i
< lasti
+ 1; i
++) {
10116 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10120 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10122 alu
.op
= ALU_OP2_ADD_INT
;
10124 alu
.src
[0].sel
= ctx
->temp_reg
;
10125 alu
.src
[0].chan
= i
;
10127 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10138 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10140 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10141 struct r600_bytecode_alu alu
;
10143 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10145 /* temp.xy = f32_to_f16(src) */
10146 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10147 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10149 alu
.dst
.sel
= ctx
->temp_reg
;
10151 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10152 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10156 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10158 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10162 /* dst.x = temp.y * 0x10000 + temp.x */
10163 for (i
= 0; i
< lasti
+ 1; i
++) {
10164 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10168 alu
.op
= ALU_OP3_MULADD_UINT24
;
10170 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10171 alu
.last
= i
== lasti
;
10172 alu
.src
[0].sel
= ctx
->temp_reg
;
10173 alu
.src
[0].chan
= 1;
10174 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10175 alu
.src
[1].value
= 0x10000;
10176 alu
.src
[2].sel
= ctx
->temp_reg
;
10177 alu
.src
[2].chan
= 0;
10178 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10186 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10188 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10189 struct r600_bytecode_alu alu
;
10191 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10193 /* temp.x = src.x */
10194 /* note: no need to mask out the high bits */
10195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10196 alu
.op
= ALU_OP1_MOV
;
10198 alu
.dst
.sel
= ctx
->temp_reg
;
10200 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10201 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10205 /* temp.y = src.x >> 16 */
10206 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10207 alu
.op
= ALU_OP2_LSHR_INT
;
10209 alu
.dst
.sel
= ctx
->temp_reg
;
10211 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10212 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10213 alu
.src
[1].value
= 16;
10215 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10219 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10220 for (i
= 0; i
< lasti
+ 1; i
++) {
10221 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10223 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10224 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10225 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10226 alu
.src
[0].sel
= ctx
->temp_reg
;
10227 alu
.src
[0].chan
= i
% 2;
10228 alu
.last
= i
== lasti
;
10229 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10237 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10239 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10240 struct r600_bytecode_alu alu
;
10241 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10245 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10246 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10247 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10248 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10249 dst
= r600_get_temp(ctx
);
10251 r
= tgsi_op3_dst(ctx
, dst
);
10255 for (i
= 0; i
< lasti
+ 1; i
++) {
10256 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10257 alu
.op
= ALU_OP2_SETGE_INT
;
10258 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10259 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10260 alu
.src
[1].value
= 32;
10261 alu
.dst
.sel
= ctx
->temp_reg
;
10266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10271 for (i
= 0; i
< lasti
+ 1; i
++) {
10272 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10273 alu
.op
= ALU_OP3_CNDE_INT
;
10275 alu
.src
[0].sel
= ctx
->temp_reg
;
10276 alu
.src
[0].chan
= i
;
10278 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10280 alu
.src
[1].sel
= dst
;
10282 alu
.src
[1].sel
= alu
.dst
.sel
;
10283 alu
.src
[1].chan
= i
;
10284 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10296 static int tgsi_clock(struct r600_shader_ctx
*ctx
)
10298 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10299 struct r600_bytecode_alu alu
;
10302 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10303 alu
.op
= ALU_OP1_MOV
;
10304 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10305 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_LO
;
10306 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10309 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10310 alu
.op
= ALU_OP1_MOV
;
10311 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10312 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_HI
;
10313 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10319 static int emit_u64add(struct r600_shader_ctx
*ctx
, int op
,
10321 int src0_sel
, int src0_chan
,
10322 int src1_sel
, int src1_chan
)
10324 struct r600_bytecode_alu alu
;
10328 if (op
== ALU_OP2_ADD_INT
)
10329 opc
= ALU_OP2_ADDC_UINT
;
10331 opc
= ALU_OP2_SUBB_UINT
;
10333 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10335 alu
.dst
.sel
= treg
;
10338 alu
.src
[0].sel
= src0_sel
;
10339 alu
.src
[0].chan
= src0_chan
+ 0;
10340 alu
.src
[1].sel
= src1_sel
;
10341 alu
.src
[1].chan
= src1_chan
+ 0;
10342 alu
.src
[1].neg
= 0;
10343 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10347 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10349 alu
.dst
.sel
= treg
;
10352 alu
.src
[0].sel
= src0_sel
;
10353 alu
.src
[0].chan
= src0_chan
+ 1;
10354 alu
.src
[1].sel
= src1_sel
;
10355 alu
.src
[1].chan
= src1_chan
+ 1;
10356 alu
.src
[1].neg
= 0;
10357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10363 alu
.dst
.sel
= treg
;
10367 alu
.src
[0].sel
= src0_sel
;
10368 alu
.src
[0].chan
= src0_chan
+ 0;
10369 alu
.src
[1].sel
= src1_sel
;
10370 alu
.src
[1].chan
= src1_chan
+ 0;
10371 alu
.src
[1].neg
= 0;
10372 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10378 alu
.dst
.sel
= treg
;
10381 alu
.src
[0].sel
= treg
;
10382 alu
.src
[0].chan
= 1;
10383 alu
.src
[1].sel
= treg
;
10384 alu
.src
[1].chan
= 2;
10386 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10392 static int egcm_u64add(struct r600_shader_ctx
*ctx
)
10394 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10395 struct r600_bytecode_alu alu
;
10397 int treg
= ctx
->temp_reg
;
10398 int op
= ALU_OP2_ADD_INT
, opc
= ALU_OP2_ADDC_UINT
;
10400 if (ctx
->src
[1].neg
) {
10401 op
= ALU_OP2_SUB_INT
;
10402 opc
= ALU_OP2_SUBB_UINT
;
10404 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10406 alu
.dst
.sel
= treg
;
10409 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10410 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10411 alu
.src
[1].neg
= 0;
10412 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10418 alu
.dst
.sel
= treg
;
10421 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10422 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10423 alu
.src
[1].neg
= 0;
10424 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10428 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10430 alu
.dst
.sel
= treg
;
10434 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10435 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10436 alu
.src
[1].neg
= 0;
10437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10441 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10443 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10444 alu
.src
[0].sel
= treg
;
10445 alu
.src
[0].chan
= 1;
10446 alu
.src
[1].sel
= treg
;
10447 alu
.src
[1].chan
= 2;
10449 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10452 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10453 alu
.op
= ALU_OP1_MOV
;
10454 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10455 alu
.src
[0].sel
= treg
;
10456 alu
.src
[0].chan
= 0;
10458 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10464 /* result.y = mul_high a, b
10466 result.y += a.x * b.y + a.y * b.x;
10468 static int egcm_u64mul(struct r600_shader_ctx
*ctx
)
10470 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10471 struct r600_bytecode_alu alu
;
10473 int treg
= ctx
->temp_reg
;
10475 /* temp.x = mul_lo a.x, b.x */
10476 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10477 alu
.op
= ALU_OP2_MULLO_UINT
;
10478 alu
.dst
.sel
= treg
;
10481 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10482 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10483 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10487 /* temp.y = mul_hi a.x, b.x */
10488 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10489 alu
.op
= ALU_OP2_MULHI_UINT
;
10490 alu
.dst
.sel
= treg
;
10493 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10494 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10495 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10499 /* temp.z = mul a.x, b.y */
10500 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10501 alu
.op
= ALU_OP2_MULLO_UINT
;
10502 alu
.dst
.sel
= treg
;
10505 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10506 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10507 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10511 /* temp.w = mul a.y, b.x */
10512 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10513 alu
.op
= ALU_OP2_MULLO_UINT
;
10514 alu
.dst
.sel
= treg
;
10517 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10518 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10519 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10523 /* temp.z = temp.z + temp.w */
10524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10525 alu
.op
= ALU_OP2_ADD_INT
;
10526 alu
.dst
.sel
= treg
;
10529 alu
.src
[0].sel
= treg
;
10530 alu
.src
[0].chan
= 2;
10531 alu
.src
[1].sel
= treg
;
10532 alu
.src
[1].chan
= 3;
10534 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10538 /* temp.y = temp.y + temp.z */
10539 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10540 alu
.op
= ALU_OP2_ADD_INT
;
10541 alu
.dst
.sel
= treg
;
10544 alu
.src
[0].sel
= treg
;
10545 alu
.src
[0].chan
= 1;
10546 alu
.src
[1].sel
= treg
;
10547 alu
.src
[1].chan
= 2;
10549 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10553 /* dst.x = temp.x */
10554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10555 alu
.op
= ALU_OP1_MOV
;
10556 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10557 alu
.src
[0].sel
= treg
;
10558 alu
.src
[0].chan
= 0;
10559 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10563 /* dst.y = temp.y */
10564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10565 alu
.op
= ALU_OP1_MOV
;
10566 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10567 alu
.src
[0].sel
= treg
;
10568 alu
.src
[0].chan
= 1;
10570 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10577 static int emit_u64sge(struct r600_shader_ctx
*ctx
,
10579 int src0_sel
, int src0_base_chan
,
10580 int src1_sel
, int src1_base_chan
)
10583 /* for 64-bit sge */
10584 /* result = (src0.y > src1.y) || ((src0.y == src1.y) && src0.x >= src1.x)) */
10585 r
= single_alu_op2(ctx
, ALU_OP2_SETGT_UINT
,
10587 src0_sel
, src0_base_chan
+ 1,
10588 src1_sel
, src1_base_chan
+ 1);
10592 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10594 src0_sel
, src0_base_chan
,
10595 src1_sel
, src1_base_chan
);
10599 r
= single_alu_op2(ctx
, ALU_OP2_SETE_INT
,
10601 src0_sel
, src0_base_chan
+ 1,
10602 src1_sel
, src1_base_chan
+ 1);
10606 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10613 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10622 /* this isn't a complete div it's just enough for qbo shader to work */
10623 static int egcm_u64div(struct r600_shader_ctx
*ctx
)
10625 struct r600_bytecode_alu alu
;
10626 struct r600_bytecode_alu_src alu_num_hi
, alu_num_lo
, alu_denom_hi
, alu_denom_lo
, alu_src
;
10628 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10630 /* make sure we are dividing my a const with 0 in the high bits */
10631 if (ctx
->src
[1].sel
!= V_SQ_ALU_SRC_LITERAL
)
10633 if (ctx
->src
[1].value
[ctx
->src
[1].swizzle
[1]] != 0)
10635 /* make sure we are doing one division */
10636 if (inst
->Dst
[0].Register
.WriteMask
!= 0x3)
10639 /* emit_if uses ctx->temp_reg so we can't */
10640 int treg
= r600_get_temp(ctx
);
10641 int tmp_num
= r600_get_temp(ctx
);
10642 int sub_tmp
= r600_get_temp(ctx
);
10644 /* tmp quot are tmp_num.zw */
10645 r600_bytecode_src(&alu_num_lo
, &ctx
->src
[0], 0);
10646 r600_bytecode_src(&alu_num_hi
, &ctx
->src
[0], 1);
10647 r600_bytecode_src(&alu_denom_lo
, &ctx
->src
[1], 0);
10648 r600_bytecode_src(&alu_denom_hi
, &ctx
->src
[1], 1);
10650 /* MOV tmp_num.xy, numerator */
10651 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10653 alu_num_lo
.sel
, alu_num_lo
.chan
,
10657 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10659 alu_num_hi
.sel
, alu_num_hi
.chan
,
10664 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10666 V_SQ_ALU_SRC_LITERAL
, 0,
10671 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10673 V_SQ_ALU_SRC_LITERAL
, 0,
10678 /* treg 0 is log2_denom */
10679 /* normally this gets the MSB for the denom high value
10680 - however we know this will always be 0 here. */
10681 r
= single_alu_op2(ctx
,
10684 V_SQ_ALU_SRC_LITERAL
, 32,
10689 /* normally check demon hi for 0, but we know it is already */
10690 /* t0.z = num_hi >= denom_lo */
10691 r
= single_alu_op2(ctx
,
10692 ALU_OP2_SETGE_UINT
,
10694 alu_num_hi
.sel
, alu_num_hi
.chan
,
10695 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10699 memset(&alu_src
, 0, sizeof(alu_src
));
10700 alu_src
.sel
= treg
;
10702 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10706 /* for loops in here */
10707 /* get msb t0.x = msb(src[1].x) first */
10708 int msb_lo
= util_last_bit(alu_denom_lo
.value
);
10709 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10711 V_SQ_ALU_SRC_LITERAL
, msb_lo
,
10716 /* unroll the asm here */
10717 for (i
= 0; i
< 31; i
++) {
10718 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10720 V_SQ_ALU_SRC_LITERAL
, i
,
10725 /* we can do this on the CPU */
10726 uint32_t denom_lo_shl
= alu_denom_lo
.value
<< (31 - i
);
10727 /* t0.z = tmp_num.y >= t0.z */
10728 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10731 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
10735 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10742 memset(&alu_src
, 0, sizeof(alu_src
));
10743 alu_src
.sel
= treg
;
10745 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10749 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
10752 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
10756 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10759 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
10763 r
= tgsi_endif(ctx
);
10768 /* log2_denom is always <= 31, so manually peel the last loop
10771 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10774 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10778 memset(&alu_src
, 0, sizeof(alu_src
));
10779 alu_src
.sel
= treg
;
10781 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10785 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
10788 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
10792 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10795 V_SQ_ALU_SRC_LITERAL
, 1U);
10798 r
= tgsi_endif(ctx
);
10802 r
= tgsi_endif(ctx
);
10806 /* onto the second loop to unroll */
10807 for (i
= 0; i
< 31; i
++) {
10808 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
10810 V_SQ_ALU_SRC_LITERAL
, (63 - (31 - i
)),
10815 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
<< (31 - i
);
10816 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10818 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
10823 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10825 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
10830 r
= emit_u64sge(ctx
, sub_tmp
,
10836 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
10843 memset(&alu_src
, 0, sizeof(alu_src
));
10844 alu_src
.sel
= treg
;
10846 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10851 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
10858 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10865 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10872 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10875 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
10879 r
= tgsi_endif(ctx
);
10884 /* log2_denom is always <= 63, so manually peel the last loop
10887 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
;
10888 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10890 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
10895 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
10897 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
10902 r
= emit_u64sge(ctx
, sub_tmp
,
10908 memset(&alu_src
, 0, sizeof(alu_src
));
10909 alu_src
.sel
= sub_tmp
;
10911 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10915 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
10922 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
10925 V_SQ_ALU_SRC_LITERAL
, 1U);
10928 r
= tgsi_endif(ctx
);
10932 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10933 alu
.op
= ALU_OP1_MOV
;
10934 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10935 alu
.src
[0].sel
= tmp_num
;
10936 alu
.src
[0].chan
= 2;
10937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10941 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10942 alu
.op
= ALU_OP1_MOV
;
10943 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10944 alu
.src
[0].sel
= tmp_num
;
10945 alu
.src
[0].chan
= 3;
10947 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10953 static int egcm_u64sne(struct r600_shader_ctx
*ctx
)
10955 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10956 struct r600_bytecode_alu alu
;
10958 int treg
= ctx
->temp_reg
;
10960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10961 alu
.op
= ALU_OP2_SETNE_INT
;
10962 alu
.dst
.sel
= treg
;
10965 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10966 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10967 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10971 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10972 alu
.op
= ALU_OP2_SETNE_INT
;
10973 alu
.dst
.sel
= treg
;
10976 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10977 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10979 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10983 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10984 alu
.op
= ALU_OP2_OR_INT
;
10985 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10986 alu
.src
[0].sel
= treg
;
10987 alu
.src
[0].chan
= 0;
10988 alu
.src
[1].sel
= treg
;
10989 alu
.src
[1].chan
= 1;
10991 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10997 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
10998 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10999 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11000 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11002 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11004 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11005 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11006 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11007 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11008 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11009 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11010 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11011 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11012 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
11013 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11014 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11015 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11016 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11017 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11018 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11019 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11020 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11021 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11022 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11023 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11024 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11025 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11026 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11027 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11028 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11029 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11030 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11031 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11032 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11033 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11034 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11035 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11036 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11037 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11038 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11039 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11040 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11041 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11042 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11043 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11044 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11045 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11046 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11047 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11048 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11049 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11050 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11051 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11052 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11053 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11054 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11055 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11056 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11057 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11058 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11059 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11060 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11061 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11062 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11063 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11064 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11065 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11066 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11067 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11068 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11069 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11070 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11071 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11072 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11073 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11074 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11075 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11076 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11077 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11078 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11079 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11080 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11081 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
11082 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11083 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11084 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11085 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11086 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11087 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
11088 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11089 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11090 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11091 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11092 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11093 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11094 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11095 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11096 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11097 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11098 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11099 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11100 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11101 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11102 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11103 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11104 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11105 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11106 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11107 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11108 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11109 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11110 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11111 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11112 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11113 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11114 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11115 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11116 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11117 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11118 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11119 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
11120 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11121 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11122 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11123 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11124 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11125 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
11126 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11127 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
11128 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11129 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11130 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11131 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11132 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11133 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11134 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11135 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11136 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11137 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11138 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
11139 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11140 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
11141 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11142 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11143 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11144 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11145 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11146 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11147 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11148 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11149 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11150 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11151 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11152 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11153 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11154 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11155 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11156 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11157 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
11158 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11159 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11160 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11161 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11162 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11163 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11164 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11165 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11166 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11167 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11168 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11169 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11170 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11171 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11172 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11173 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11174 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11175 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11176 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11177 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11178 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11179 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11180 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11181 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11182 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
11183 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
11184 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
11185 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
11186 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11187 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
11188 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
11189 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
11190 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
11191 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
11192 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11193 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11194 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11195 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11198 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
11199 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11200 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11201 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11202 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11203 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11204 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11205 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11206 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11207 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11208 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11209 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11210 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11211 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11212 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11213 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11214 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11215 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11216 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11217 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11218 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11219 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11220 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11221 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11222 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11223 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11224 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11225 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11226 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11227 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11228 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11229 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11230 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11231 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11232 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11233 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11234 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11235 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11236 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11237 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11238 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11239 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11240 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11241 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11242 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11243 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11244 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11245 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11246 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11247 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11248 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11249 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11250 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11251 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11252 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11253 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11254 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11255 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11256 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11257 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11258 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11259 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11260 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11261 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11262 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11263 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11264 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11265 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11266 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11267 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11268 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11269 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11270 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11271 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11272 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11273 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11274 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11275 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11276 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11277 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11278 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11279 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11280 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11281 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11282 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11283 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11284 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11285 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11286 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11287 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11288 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11289 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11290 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11291 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11292 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11293 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11294 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11295 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11296 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11297 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11298 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11299 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11300 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11301 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11302 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11303 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11304 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11305 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11306 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11307 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11308 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11309 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11310 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11311 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11312 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11313 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11314 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11315 /* Refer below for TGSI_OPCODE_DFMA */
11316 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
11317 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11318 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11319 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11320 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11321 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11322 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11323 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11324 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
11325 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11326 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11327 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11328 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11329 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11330 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11331 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11332 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11333 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11334 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11335 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11336 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11337 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11338 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11339 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11340 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11341 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11342 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11343 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11344 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11345 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11346 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11347 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11348 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11349 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11350 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11351 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11352 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11353 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11354 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11355 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11356 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11357 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11358 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11359 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11360 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11361 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11362 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11363 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11364 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11365 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11366 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11367 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11368 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11369 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11370 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11371 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11372 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11373 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11374 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11375 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11376 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11377 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11378 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11379 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11380 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11381 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11382 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11383 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11384 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11385 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11386 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11387 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11388 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11389 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11390 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11391 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11392 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11393 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11394 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11395 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11396 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11397 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11398 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11399 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11400 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11401 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11402 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11403 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11404 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11405 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11406 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11407 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11408 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11409 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11410 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11411 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11412 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11413 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11414 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11415 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11416 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11417 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11418 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11419 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11420 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11421 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11424 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
11425 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11426 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11427 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11428 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
11429 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
11430 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11431 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11432 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11433 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11434 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11435 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11436 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11437 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11438 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11439 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11440 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11441 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11442 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11443 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11444 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
11445 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11446 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11447 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11448 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11449 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11450 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11451 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11452 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
11453 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
11454 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
11455 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11456 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11457 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11458 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11459 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11460 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
11461 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11462 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11463 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11464 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11465 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11466 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11467 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11468 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11469 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11470 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11471 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11472 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
11473 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11474 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11475 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11476 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11477 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11478 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11479 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11480 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11481 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11482 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11483 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11484 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11485 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11486 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11487 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11488 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11489 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11490 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11491 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11492 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11493 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11494 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11495 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11496 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11497 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11498 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11499 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11500 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11501 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11502 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11503 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11504 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11505 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11506 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11507 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
11508 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11509 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11510 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11511 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11512 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11513 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11514 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11515 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11516 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11517 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11518 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11519 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11520 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11521 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11522 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11523 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11524 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11525 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11526 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11527 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11528 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11529 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11530 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11531 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11532 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11533 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11534 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11535 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11536 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11537 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11538 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11539 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11540 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11541 /* Refer below for TGSI_OPCODE_DFMA */
11542 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
11543 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11544 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11545 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11546 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11547 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11548 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11549 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11550 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
11551 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
11552 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11553 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11554 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11555 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11556 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11557 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11558 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
11559 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11560 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11561 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11562 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11563 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11564 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11565 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11566 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11567 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11568 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11569 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11570 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11571 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11572 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11573 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11574 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11575 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11576 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11577 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11578 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11579 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11580 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11581 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11582 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11583 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11584 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11585 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11586 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11587 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11588 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11589 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11590 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11591 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11592 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11593 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11594 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11595 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11596 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11597 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11598 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11599 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11600 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11601 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11602 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11603 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
11604 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
11605 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11606 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11607 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11608 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11609 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11610 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11611 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11612 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11613 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11614 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11615 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11616 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11617 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11618 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11619 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11620 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11621 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11622 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11623 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11624 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11625 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11626 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11627 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11628 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11629 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11630 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11631 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11632 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11633 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11634 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11635 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11636 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11637 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11638 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11639 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11640 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11641 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11642 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11643 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11644 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11645 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11646 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11647 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},