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
);
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 sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
212 if (dump
&& !sb_disasm
) {
213 fprintf(stderr
, "--------------------------------------------------------------\n");
214 r600_bytecode_disasm(&shader
->shader
.bc
);
215 fprintf(stderr
, "______________________________________________________________\n");
216 } else if ((dump
&& sb_disasm
) || use_sb
) {
217 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
220 R600_ERR("r600_sb_bytecode_process failed !\n");
225 if (shader
->gs_copy_shader
) {
228 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
229 &shader
->gs_copy_shader
->shader
, dump
, 0);
234 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
238 /* Store the shader in a buffer. */
239 if ((r
= store_shader(ctx
, shader
)))
243 switch (shader
->shader
.processor_type
) {
244 case PIPE_SHADER_TESS_CTRL
:
245 evergreen_update_hs_state(ctx
, shader
);
247 case PIPE_SHADER_TESS_EVAL
:
249 evergreen_update_es_state(ctx
, shader
);
251 evergreen_update_vs_state(ctx
, shader
);
253 case PIPE_SHADER_GEOMETRY
:
254 if (rctx
->b
.chip_class
>= EVERGREEN
) {
255 evergreen_update_gs_state(ctx
, shader
);
256 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
258 r600_update_gs_state(ctx
, shader
);
259 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
262 case PIPE_SHADER_VERTEX
:
263 export_shader
= key
.vs
.as_es
;
264 if (rctx
->b
.chip_class
>= EVERGREEN
) {
266 evergreen_update_ls_state(ctx
, shader
);
267 else if (key
.vs
.as_es
)
268 evergreen_update_es_state(ctx
, shader
);
270 evergreen_update_vs_state(ctx
, shader
);
273 r600_update_es_state(ctx
, shader
);
275 r600_update_vs_state(ctx
, shader
);
278 case PIPE_SHADER_FRAGMENT
:
279 if (rctx
->b
.chip_class
>= EVERGREEN
) {
280 evergreen_update_ps_state(ctx
, shader
);
282 r600_update_ps_state(ctx
, shader
);
285 case PIPE_SHADER_COMPUTE
:
286 evergreen_update_ls_state(ctx
, shader
);
295 r600_pipe_shader_destroy(ctx
, shader
);
299 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
301 r600_resource_reference(&shader
->bo
, NULL
);
302 r600_bytecode_clear(&shader
->shader
.bc
);
303 r600_release_command_buffer(&shader
->command_buffer
);
307 * tgsi -> r600 shader
309 struct r600_shader_tgsi_instruction
;
311 struct r600_shader_src
{
318 boolean kc_rel
; /* true if cache bank is indexed */
327 struct r600_shader_ctx
{
328 struct tgsi_shader_info info
;
329 struct tgsi_array_info
*array_infos
;
330 /* flag for each tgsi temp array if its been spilled or not */
331 bool *spilled_arrays
;
332 struct tgsi_parse_context parse
;
333 const struct tgsi_token
*tokens
;
335 unsigned file_offset
[TGSI_FILE_COUNT
];
337 const struct r600_shader_tgsi_instruction
*inst_info
;
338 struct r600_bytecode
*bc
;
339 struct r600_shader
*shader
;
340 struct r600_shader_src src
[4];
343 uint32_t max_driver_temp_used
;
344 /* needed for evergreen interpolation */
345 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
346 /* evergreen/cayman also store sample mask in face register */
348 /* sample id is .w component stored in fixed point position register */
349 int fixed_pt_position_gpr
;
351 boolean clip_vertex_write
;
353 unsigned edgeflag_output
;
354 int helper_invoc_reg
;
355 int cs_block_size_reg
;
356 int cs_grid_size_reg
;
357 bool cs_block_size_loaded
, cs_grid_size_loaded
;
359 int next_ring_offset
;
360 int gs_out_ring_offset
;
362 struct r600_shader
*gs_for_vs
;
363 int gs_export_gpr_tregs
[4];
364 int gs_rotated_input
[2];
365 const struct pipe_stream_output_info
*gs_stream_output_info
;
366 unsigned enabled_stream_buffers_mask
;
367 unsigned tess_input_info
; /* temp with tess input offsets */
368 unsigned tess_output_info
; /* temp with tess input offsets */
369 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
370 bool thread_id_gpr_loaded
;
373 struct r600_shader_tgsi_instruction
{
375 int (*process
)(struct r600_shader_ctx
*ctx
);
378 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
379 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
380 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
381 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
382 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
383 static int tgsi_else(struct r600_shader_ctx
*ctx
);
384 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
385 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
386 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
387 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
388 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
389 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
390 unsigned int dst_reg
);
391 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
392 const struct r600_shader_src
*shader_src
,
394 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
395 unsigned dst_reg
, unsigned mask
);
397 static int tgsi_last_instruction(unsigned writemask
)
401 for (i
= 0; i
< 4; i
++) {
402 if (writemask
& (1 << i
)) {
409 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
411 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
414 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
415 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
419 if (i
->Instruction
.Label
) {
420 R600_ERR("label unsupported\n");
424 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
425 if (i
->Src
[j
].Register
.Dimension
) {
426 switch (i
->Src
[j
].Register
.File
) {
427 case TGSI_FILE_CONSTANT
:
428 case TGSI_FILE_HW_ATOMIC
:
430 case TGSI_FILE_INPUT
:
431 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
432 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
433 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
435 case TGSI_FILE_OUTPUT
:
436 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
439 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
440 i
->Src
[j
].Register
.File
,
441 i
->Src
[j
].Register
.Dimension
);
446 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
447 if (i
->Dst
[j
].Register
.Dimension
) {
448 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
450 R600_ERR("unsupported dst (dimension)\n");
457 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
459 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
460 interpolate
== TGSI_INTERPOLATE_LINEAR
||
461 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
463 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
467 case TGSI_INTERPOLATE_LOC_CENTER
:
470 case TGSI_INTERPOLATE_LOC_CENTROID
:
473 case TGSI_INTERPOLATE_LOC_SAMPLE
:
478 return is_linear
* 3 + loc
;
484 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
487 int i
= eg_get_interpolator_index(
488 ctx
->shader
->input
[input
].interpolate
,
489 ctx
->shader
->input
[input
].interpolate_location
);
491 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
494 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
497 struct r600_bytecode_alu alu
;
498 int gpr
= 0, base_chan
= 0;
499 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
501 /* work out gpr and base_chan from index */
503 base_chan
= (2 * (ij_index
% 2)) + 1;
505 for (i
= 0; i
< 8; i
++) {
506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
509 alu
.op
= ALU_OP2_INTERP_ZW
;
511 alu
.op
= ALU_OP2_INTERP_XY
;
513 if ((i
> 1) && (i
< 6)) {
514 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
518 alu
.dst
.chan
= i
% 4;
520 alu
.src
[0].sel
= gpr
;
521 alu
.src
[0].chan
= (base_chan
- (i
% 2));
523 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
525 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
528 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
535 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
538 struct r600_bytecode_alu alu
;
540 for (i
= 0; i
< 4; i
++) {
541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
543 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
545 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
550 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
555 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
563 * Special export handling in shaders
565 * shader export ARRAY_BASE for EXPORT_POS:
568 * 62, 63 are clip distance vectors
570 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
571 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
572 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
573 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
574 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
575 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
576 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
577 * exclusive from render target index)
578 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
581 * shader export ARRAY_BASE for EXPORT_PIXEL:
583 * 61 computed Z vector
585 * The use of the values exported in the computed Z vector are controlled
586 * by DB_SHADER_CONTROL:
587 * Z_EXPORT_ENABLE - Z as a float in RED
588 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
589 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
590 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
591 * DB_SOURCE_FORMAT - export control restrictions
596 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
597 static int r600_spi_sid(struct r600_shader_io
* io
)
599 int index
, name
= io
->name
;
601 /* These params are handled differently, they don't need
602 * semantic indices, so we'll use 0 for them.
604 if (name
== TGSI_SEMANTIC_POSITION
||
605 name
== TGSI_SEMANTIC_PSIZE
||
606 name
== TGSI_SEMANTIC_EDGEFLAG
||
607 name
== TGSI_SEMANTIC_FACE
||
608 name
== TGSI_SEMANTIC_SAMPLEMASK
)
611 if (name
== TGSI_SEMANTIC_GENERIC
) {
612 /* For generic params simply use sid from tgsi */
615 /* For non-generic params - pack name and sid into 8 bits */
616 index
= 0x80 | (name
<<3) | (io
->sid
);
619 /* Make sure that all really used indices have nonzero value, so
620 * we can just compare it to 0 later instead of comparing the name
621 * with different values to detect special cases. */
628 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
629 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
631 switch (semantic_name
) {
632 case TGSI_SEMANTIC_POSITION
:
634 case TGSI_SEMANTIC_PSIZE
:
636 case TGSI_SEMANTIC_CLIPDIST
:
639 case TGSI_SEMANTIC_GENERIC
:
641 return 4 + index
- 9;
643 /* same explanation as in the default statement,
644 * the only user hitting this is st/nine.
648 /* patch indices are completely separate and thus start from 0 */
649 case TGSI_SEMANTIC_TESSOUTER
:
651 case TGSI_SEMANTIC_TESSINNER
:
653 case TGSI_SEMANTIC_PATCH
:
657 /* Don't fail here. The result of this function is only used
658 * for LS, TCS, TES, and GS, where legacy GL semantics can't
659 * occur, but this function is called for all vertex shaders
660 * before it's known whether LS will be compiled or not.
666 /* turn input into interpolate on EG */
667 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
671 if (ctx
->shader
->input
[index
].spi_sid
) {
672 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
673 if (ctx
->shader
->input
[index
].interpolate
> 0) {
674 evergreen_interp_assign_ij_index(ctx
, index
);
675 r
= evergreen_interp_alu(ctx
, index
);
677 r
= evergreen_interp_flat(ctx
, index
);
683 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
685 struct r600_bytecode_alu alu
;
687 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
688 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
690 for (i
= 0; i
< 4; i
++) {
691 memset(&alu
, 0, sizeof(alu
));
692 alu
.op
= ALU_OP3_CNDGT
;
695 alu
.dst
.sel
= gpr_front
;
696 alu
.src
[0].sel
= ctx
->face_gpr
;
697 alu
.src
[1].sel
= gpr_front
;
698 alu
.src
[2].sel
= gpr_back
;
705 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
712 /* execute a single slot ALU calculation */
713 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
714 int dst_sel
, int dst_chan
,
715 int src0_sel
, unsigned src0_chan_val
,
716 int src1_sel
, unsigned src1_chan_val
)
718 struct r600_bytecode_alu alu
;
721 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
722 for (i
= 0; i
< 4; i
++) {
723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
725 alu
.src
[0].sel
= src0_sel
;
726 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
727 alu
.src
[0].value
= src0_chan_val
;
729 alu
.src
[0].chan
= src0_chan_val
;
730 alu
.src
[1].sel
= src1_sel
;
731 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
732 alu
.src
[1].value
= src1_chan_val
;
734 alu
.src
[1].chan
= src1_chan_val
;
735 alu
.dst
.sel
= dst_sel
;
737 alu
.dst
.write
= i
== dst_chan
;
739 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
746 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
748 alu
.src
[0].sel
= src0_sel
;
749 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
750 alu
.src
[0].value
= src0_chan_val
;
752 alu
.src
[0].chan
= src0_chan_val
;
753 alu
.src
[1].sel
= src1_sel
;
754 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
755 alu
.src
[1].value
= src1_chan_val
;
757 alu
.src
[1].chan
= src1_chan_val
;
758 alu
.dst
.sel
= dst_sel
;
759 alu
.dst
.chan
= dst_chan
;
762 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
768 /* execute a single slot ALU calculation */
769 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
770 int dst_sel
, int dst_chan
,
771 int src0_sel
, unsigned src0_chan_val
,
772 int src1_sel
, unsigned src1_chan_val
,
773 int src2_sel
, unsigned src2_chan_val
)
775 struct r600_bytecode_alu alu
;
778 /* validate this for other ops */
779 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
|| op
== ALU_OP3_BFE_UINT
);
780 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
782 alu
.src
[0].sel
= src0_sel
;
783 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
784 alu
.src
[0].value
= src0_chan_val
;
786 alu
.src
[0].chan
= src0_chan_val
;
787 alu
.src
[1].sel
= src1_sel
;
788 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
789 alu
.src
[1].value
= src1_chan_val
;
791 alu
.src
[1].chan
= src1_chan_val
;
792 alu
.src
[2].sel
= src2_sel
;
793 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
794 alu
.src
[2].value
= src2_chan_val
;
796 alu
.src
[2].chan
= src2_chan_val
;
797 alu
.dst
.sel
= dst_sel
;
798 alu
.dst
.chan
= dst_chan
;
801 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
807 /* put it in temp_reg.x */
808 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
810 int temp_reg
, bool is_patch_var
)
814 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
816 Dimension - patch0_offset (input_vals.z),
817 Non-dim - patch0_data_offset (input_vals.w)
819 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
821 ctx
->tess_output_info
, 0,
823 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
829 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
831 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
834 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
836 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
839 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
842 i
= ctx
->shader
->noutput
++;
843 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
844 ctx
->shader
->output
[i
].sid
= 0;
845 ctx
->shader
->output
[i
].gpr
= 0;
846 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
847 ctx
->shader
->output
[i
].write_mask
= 0x4;
848 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
853 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
855 struct r600_bytecode_alu alu
;
858 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
859 alu
.op
= ctx
->inst_info
->op
;
862 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
868 static void choose_spill_arrays(struct r600_shader_ctx
*ctx
, int *regno
, unsigned *scratch_space_needed
)
870 // pick largest array and spill it, repeat until the number of temps is under limit or we run out of arrays
871 unsigned n
= ctx
->info
.array_max
[TGSI_FILE_TEMPORARY
];
872 unsigned narrays_left
= n
;
873 bool *spilled
= ctx
->spilled_arrays
; // assumed calloc:ed
875 *scratch_space_needed
= 0;
876 while (*regno
> 124 && narrays_left
) {
878 unsigned largest
= 0;
879 unsigned largest_index
= 0;
881 for (i
= 0; i
< n
; i
++) {
882 unsigned size
= ctx
->array_infos
[i
].range
.Last
- ctx
->array_infos
[i
].range
.First
+ 1;
883 if (!spilled
[i
] && size
> largest
) {
889 spilled
[largest_index
] = true;
891 *scratch_space_needed
+= largest
;
896 if (narrays_left
== 0) {
897 ctx
->info
.indirect_files
&= ~(1 << TGSI_FILE_TEMPORARY
);
901 /* Take spilled temp arrays into account when translating tgsi register
902 * indexes into r600 gprs if spilled is false, or scratch array offset if
904 static int map_tgsi_reg_index_to_r600_gpr(struct r600_shader_ctx
*ctx
, unsigned tgsi_reg_index
, bool *spilled
)
907 unsigned spilled_size
= 0;
909 for (i
= 0; i
< ctx
->info
.array_max
[TGSI_FILE_TEMPORARY
]; i
++) {
910 if (tgsi_reg_index
>= ctx
->array_infos
[i
].range
.First
&& tgsi_reg_index
<= ctx
->array_infos
[i
].range
.Last
) {
911 if (ctx
->spilled_arrays
[i
]) {
912 /* vec4 index into spilled scratch memory */
914 return tgsi_reg_index
- ctx
->array_infos
[i
].range
.First
+ spilled_size
;
917 /* regular GPR array */
919 return tgsi_reg_index
- spilled_size
+ ctx
->file_offset
[TGSI_FILE_TEMPORARY
];
923 if (ctx
->spilled_arrays
[i
]) {
924 spilled_size
+= ctx
->array_infos
[i
].range
.Last
- ctx
->array_infos
[i
].range
.First
+ 1;
928 /* regular GPR index, minus the holes from spilled arrays */
931 return tgsi_reg_index
- spilled_size
+ ctx
->file_offset
[TGSI_FILE_TEMPORARY
];
934 /* look up spill area base offset and array size for a spilled temp array */
935 static void get_spilled_array_base_and_size(struct r600_shader_ctx
*ctx
, unsigned tgsi_reg_index
,
936 unsigned *array_base
, unsigned *array_size
)
941 for (i
= 0; i
< ctx
->info
.array_max
[TGSI_FILE_TEMPORARY
]; i
++) {
942 if (ctx
->spilled_arrays
[i
]) {
943 unsigned size
= ctx
->array_infos
[i
].range
.Last
- ctx
->array_infos
[i
].range
.First
+ 1;
945 if (tgsi_reg_index
>= ctx
->array_infos
[i
].range
.First
&& tgsi_reg_index
<= ctx
->array_infos
[i
].range
.Last
) {
946 *array_base
= offset
;
947 *array_size
= size
- 1; /* hw counts from 1 */
957 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
959 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
960 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
962 switch (d
->Declaration
.File
) {
963 case TGSI_FILE_INPUT
:
964 for (j
= 0; j
< count
; j
++) {
965 i
= ctx
->shader
->ninput
+ j
;
966 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
967 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
968 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
969 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
970 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
971 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
972 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
973 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
974 switch (ctx
->shader
->input
[i
].name
) {
975 case TGSI_SEMANTIC_FACE
:
976 if (ctx
->face_gpr
!= -1)
977 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
979 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
981 case TGSI_SEMANTIC_COLOR
:
984 case TGSI_SEMANTIC_POSITION
:
985 ctx
->fragcoord_input
= i
;
987 case TGSI_SEMANTIC_PRIMID
:
988 /* set this for now */
989 ctx
->shader
->gs_prim_id_input
= true;
990 ctx
->shader
->ps_prim_id_input
= i
;
993 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
994 if ((r
= evergreen_interp_input(ctx
, i
)))
997 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
998 /* FIXME probably skip inputs if they aren't passed in the ring */
999 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
1000 ctx
->next_ring_offset
+= 16;
1001 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
1002 ctx
->shader
->gs_prim_id_input
= true;
1005 ctx
->shader
->ninput
+= count
;
1007 case TGSI_FILE_OUTPUT
:
1008 for (j
= 0; j
< count
; j
++) {
1009 i
= ctx
->shader
->noutput
+ j
;
1010 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
1011 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
1012 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
1013 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
1014 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
1015 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
1016 if (ctx
->type
== PIPE_SHADER_VERTEX
||
1017 ctx
->type
== PIPE_SHADER_GEOMETRY
||
1018 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
1019 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
1020 switch (d
->Semantic
.Name
) {
1021 case TGSI_SEMANTIC_CLIPDIST
:
1023 case TGSI_SEMANTIC_PSIZE
:
1024 ctx
->shader
->vs_out_misc_write
= 1;
1025 ctx
->shader
->vs_out_point_size
= 1;
1027 case TGSI_SEMANTIC_EDGEFLAG
:
1028 ctx
->shader
->vs_out_misc_write
= 1;
1029 ctx
->shader
->vs_out_edgeflag
= 1;
1030 ctx
->edgeflag_output
= i
;
1032 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
1033 ctx
->shader
->vs_out_misc_write
= 1;
1034 ctx
->shader
->vs_out_viewport
= 1;
1036 case TGSI_SEMANTIC_LAYER
:
1037 ctx
->shader
->vs_out_misc_write
= 1;
1038 ctx
->shader
->vs_out_layer
= 1;
1040 case TGSI_SEMANTIC_CLIPVERTEX
:
1041 ctx
->clip_vertex_write
= TRUE
;
1045 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
1046 ctx
->gs_out_ring_offset
+= 16;
1048 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
1049 switch (d
->Semantic
.Name
) {
1050 case TGSI_SEMANTIC_COLOR
:
1051 ctx
->shader
->nr_ps_max_color_exports
++;
1056 ctx
->shader
->noutput
+= count
;
1058 case TGSI_FILE_TEMPORARY
:
1059 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
1060 if (d
->Array
.ArrayID
) {
1062 unsigned idx
= map_tgsi_reg_index_to_r600_gpr(ctx
,
1067 r600_add_gpr_array(ctx
->shader
, idx
,
1068 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
1074 case TGSI_FILE_CONSTANT
:
1075 case TGSI_FILE_SAMPLER
:
1076 case TGSI_FILE_SAMPLER_VIEW
:
1077 case TGSI_FILE_ADDRESS
:
1078 case TGSI_FILE_BUFFER
:
1079 case TGSI_FILE_IMAGE
:
1080 case TGSI_FILE_MEMORY
:
1083 case TGSI_FILE_HW_ATOMIC
:
1084 i
= ctx
->shader
->nhwatomic_ranges
;
1085 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
1086 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
1087 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
1088 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
1089 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
1090 ctx
->shader
->nhwatomic_ranges
++;
1091 ctx
->shader
->nhwatomic
+= count
;
1094 case TGSI_FILE_SYSTEM_VALUE
:
1095 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
1096 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
1097 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
1098 break; /* Already handled from allocate_system_value_inputs */
1099 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
1101 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1103 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1105 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1106 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1107 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1108 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1109 unsigned temp_reg
= r600_get_temp(ctx
);
1111 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1115 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1118 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1122 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
1124 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1128 for (i
= 0; i
< 2; i
++) {
1129 struct r600_bytecode_alu alu
;
1130 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1131 alu
.op
= ALU_OP1_MOV
;
1133 alu
.src
[0].chan
= 0 + i
;
1135 alu
.dst
.chan
= 0 + i
;
1137 alu
.last
= (i
== 1) ? 1 : 0;
1138 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1141 /* ADD r1.z, 1.0f, -r0.x */
1142 struct r600_bytecode_alu alu
;
1143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1144 alu
.op
= ALU_OP2_ADD
;
1145 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1147 alu
.src
[1].chan
= 0;
1153 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1156 /* ADD r1.z, r1.z, -r1.y */
1157 alu
.op
= ALU_OP2_ADD
;
1159 alu
.src
[0].chan
= 2;
1161 alu
.src
[1].chan
= 1;
1167 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1173 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1179 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1181 struct tgsi_parse_context parse
;
1185 unsigned name
, alternate_name
;
1187 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1189 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1194 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1198 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1199 while (!tgsi_parse_end_of_tokens(&parse
)) {
1200 tgsi_parse_token(&parse
);
1202 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1203 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1204 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1205 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1206 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1208 int interpolate
, location
, k
;
1210 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1211 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1212 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1213 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1214 /* Needs sample positions, currently those are always available */
1216 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1219 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1220 k
= eg_get_interpolator_index(interpolate
, location
);
1222 ctx
->eg_interpolators
[k
].enabled
= true;
1224 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1225 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1226 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1227 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1228 if (d
->Semantic
.Name
== inputs
[k
].name
||
1229 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1230 inputs
[k
].enabled
= true;
1237 tgsi_parse_free(&parse
);
1239 if (ctx
->info
.reads_samplemask
&&
1240 (ctx
->info
.uses_linear_sample
|| ctx
->info
.uses_linear_sample
)) {
1241 inputs
[1].enabled
= true;
1244 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1246 /* assign gpr to each interpolator according to priority */
1247 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1248 if (ctx
->eg_interpolators
[i
].enabled
) {
1249 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1253 num_baryc
= (num_baryc
+ 1) >> 1;
1254 gpr_offset
+= num_baryc
;
1257 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1258 boolean enabled
= inputs
[i
].enabled
;
1259 int *reg
= inputs
[i
].reg
;
1260 unsigned name
= inputs
[i
].name
;
1263 int gpr
= gpr_offset
+ num_regs
++;
1264 ctx
->shader
->nsys_inputs
++;
1266 // add to inputs, allocate a gpr
1267 k
= ctx
->shader
->ninput
++;
1268 ctx
->shader
->input
[k
].name
= name
;
1269 ctx
->shader
->input
[k
].sid
= 0;
1270 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1271 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1272 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1276 return gpr_offset
+ num_regs
;
1280 * for evergreen we need to scan the shader to find the number of GPRs we need to
1281 * reserve for interpolation and system values
1283 * we need to know if we are going to emit any sample or centroid inputs
1284 * if perspective and linear are required
1286 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1290 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1293 * Could get this information from the shader info. But right now
1294 * we interpolate all declared inputs, whereas the shader info will
1295 * only contain the bits if the inputs are actually used, so it might
1298 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1300 /* skip position/face/mask/sampleid */
1301 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1302 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1303 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1304 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1307 k
= eg_get_interpolator_index(
1308 ctx
->info
.input_interpolate
[i
],
1309 ctx
->info
.input_interpolate_loc
[i
]);
1311 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1314 /* XXX PULL MODEL and LINE STIPPLE */
1316 return allocate_system_value_inputs(ctx
, 0);
1319 /* sample_id_sel == NULL means fetch for current sample */
1320 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1322 struct r600_bytecode_vtx vtx
;
1325 t1
= r600_get_temp(ctx
);
1327 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1328 vtx
.op
= FETCH_OP_VFETCH
;
1329 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1330 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1331 if (sample_id
== NULL
) {
1332 assert(ctx
->fixed_pt_position_gpr
!= -1);
1334 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1338 struct r600_bytecode_alu alu
;
1340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1341 alu
.op
= ALU_OP1_MOV
;
1342 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1346 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1353 vtx
.mega_fetch_count
= 16;
1359 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1360 vtx
.num_format_all
= 2;
1361 vtx
.format_comp_all
= 1;
1362 vtx
.use_const_fields
= 0;
1364 vtx
.endian
= r600_endian_swap(32);
1365 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1367 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1374 static int eg_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1377 struct r600_bytecode_alu alu
;
1379 /* do a vtx fetch with wqm set on the vtx fetch */
1380 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1381 alu
.op
= ALU_OP1_MOV
;
1382 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1384 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1385 alu
.src
[0].value
= 0xffffffff;
1388 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1392 /* do a vtx fetch in VPM mode */
1393 struct r600_bytecode_vtx vtx
;
1394 memset(&vtx
, 0, sizeof(vtx
));
1395 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
1396 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1397 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1399 vtx
.mega_fetch_count
= 16; /* no idea here really... */
1400 vtx
.dst_gpr
= ctx
->helper_invoc_reg
;
1402 vtx
.dst_sel_y
= 7; /* SEL_Y */
1403 vtx
.dst_sel_z
= 7; /* SEL_Z */
1404 vtx
.dst_sel_w
= 7; /* SEL_W */
1405 vtx
.data_format
= FMT_32
;
1406 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
1408 ctx
->bc
->cf_last
->vpm
= 1;
1412 static int cm_load_helper_invocation(struct r600_shader_ctx
*ctx
)
1415 struct r600_bytecode_alu alu
;
1417 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1418 alu
.op
= ALU_OP1_MOV
;
1419 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1421 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
1422 alu
.src
[0].value
= 0xffffffff;
1425 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1429 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1430 alu
.op
= ALU_OP1_MOV
;
1431 alu
.dst
.sel
= ctx
->helper_invoc_reg
;
1433 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1436 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_VALID_PIXEL_MODE
);
1440 return ctx
->helper_invoc_reg
;
1443 static int load_block_grid_size(struct r600_shader_ctx
*ctx
, bool load_block
)
1445 struct r600_bytecode_vtx vtx
;
1448 if (ctx
->cs_block_size_loaded
)
1449 return ctx
->cs_block_size_reg
;
1450 if (ctx
->cs_grid_size_loaded
)
1451 return ctx
->cs_grid_size_reg
;
1453 t1
= load_block
? ctx
->cs_block_size_reg
: ctx
->cs_grid_size_reg
;
1454 struct r600_bytecode_alu alu
;
1455 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1456 alu
.op
= ALU_OP1_MOV
;
1457 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
1461 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1465 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1466 vtx
.op
= FETCH_OP_VFETCH
;
1467 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1468 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1472 vtx
.mega_fetch_count
= 16;
1478 vtx
.data_format
= FMT_32_32_32_32
;
1479 vtx
.num_format_all
= 1;
1480 vtx
.format_comp_all
= 0;
1481 vtx
.use_const_fields
= 0;
1482 vtx
.offset
= load_block
? 0 : 16; // first element is size of buffer
1483 vtx
.endian
= r600_endian_swap(32);
1484 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1486 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1491 ctx
->cs_block_size_loaded
= true;
1493 ctx
->cs_grid_size_loaded
= true;
1497 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1498 const struct tgsi_full_src_register
*tgsi_src
,
1499 struct r600_shader_src
*r600_src
)
1501 memset(r600_src
, 0, sizeof(*r600_src
));
1502 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1503 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1504 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1505 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1506 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1507 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1509 if (tgsi_src
->Register
.File
== TGSI_FILE_TEMPORARY
) {
1513 idx
= map_tgsi_reg_index_to_r600_gpr(ctx
, tgsi_src
->Register
.Index
, &spilled
);
1516 int reg
= r600_get_temp(ctx
);
1519 r600_src
->sel
= reg
;
1521 if (ctx
->bc
->chip_class
< R700
) {
1522 struct r600_bytecode_output cf
;
1524 memset(&cf
, 0, sizeof(struct r600_bytecode_output
));
1525 cf
.op
= CF_OP_MEM_SCRATCH
;
1535 get_spilled_array_base_and_size(ctx
, tgsi_src
->Register
.Index
,
1536 &cf
.array_base
, &cf
.array_size
);
1538 if (tgsi_src
->Register
.Indirect
) {
1539 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
1540 cf
.index_gpr
= ctx
->bc
->ar_reg
;
1543 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ
;
1544 cf
.array_base
+= idx
;
1548 r
= r600_bytecode_add_output(ctx
->bc
, &cf
);
1551 struct r600_bytecode_vtx vtx
;
1553 if (r600_bytecode_get_need_wait_ack(ctx
->bc
)) {
1554 r600_bytecode_need_wait_ack(ctx
->bc
, false);
1555 r
= r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
1558 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1559 vtx
.op
= FETCH_OP_READ_SCRATCH
;
1561 vtx
.uncached
= 1; // Must bypass cache since prior spill written in same invocation
1563 vtx
.data_format
= FMT_32_32_32_32
;
1564 vtx
.num_format_all
= V_038010_SQ_NUM_FORMAT_INT
;
1565 vtx
.dst_sel_x
= tgsi_src
->Register
.SwizzleX
;
1566 vtx
.dst_sel_y
= tgsi_src
->Register
.SwizzleY
;
1567 vtx
.dst_sel_z
= tgsi_src
->Register
.SwizzleZ
;
1568 vtx
.dst_sel_w
= tgsi_src
->Register
.SwizzleW
;
1570 get_spilled_array_base_and_size(ctx
, tgsi_src
->Register
.Index
,
1571 &vtx
.array_base
, &vtx
.array_size
);
1573 if (tgsi_src
->Register
.Indirect
) {
1575 vtx
.src_gpr
= ctx
->bc
->ar_reg
;
1578 vtx
.array_base
+= idx
;
1582 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1589 if (tgsi_src
->Register
.Indirect
)
1590 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1592 r600_src
->sel
= idx
;
1598 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1600 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1601 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1602 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1604 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1605 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1606 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1609 index
= tgsi_src
->Register
.Index
;
1610 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1611 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1612 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1613 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1614 r600_src
->swizzle
[0] = 2; // Z value
1615 r600_src
->swizzle
[1] = 2;
1616 r600_src
->swizzle
[2] = 2;
1617 r600_src
->swizzle
[3] = 2;
1618 r600_src
->sel
= ctx
->face_gpr
;
1619 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1620 r600_src
->swizzle
[0] = 3; // W value
1621 r600_src
->swizzle
[1] = 3;
1622 r600_src
->swizzle
[2] = 3;
1623 r600_src
->swizzle
[3] = 3;
1624 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1625 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1626 r600_src
->swizzle
[0] = 0;
1627 r600_src
->swizzle
[1] = 1;
1628 r600_src
->swizzle
[2] = 4;
1629 r600_src
->swizzle
[3] = 4;
1630 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1631 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1632 r600_src
->swizzle
[0] = 3;
1633 r600_src
->swizzle
[1] = 3;
1634 r600_src
->swizzle
[2] = 3;
1635 r600_src
->swizzle
[3] = 3;
1637 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1638 r600_src
->swizzle
[0] = 0;
1639 r600_src
->swizzle
[1] = 0;
1640 r600_src
->swizzle
[2] = 0;
1641 r600_src
->swizzle
[3] = 0;
1643 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_THREAD_ID
) {
1645 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_ID
) {
1647 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1648 r600_src
->swizzle
[0] = 3;
1649 r600_src
->swizzle
[1] = 3;
1650 r600_src
->swizzle
[2] = 3;
1651 r600_src
->swizzle
[3] = 3;
1653 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1654 r600_src
->swizzle
[0] = 2;
1655 r600_src
->swizzle
[1] = 2;
1656 r600_src
->swizzle
[2] = 2;
1657 r600_src
->swizzle
[3] = 2;
1659 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1661 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1663 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1665 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1666 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1667 r600_src
->sel
= ctx
->tess_input_info
;
1668 r600_src
->swizzle
[0] = 2;
1669 r600_src
->swizzle
[1] = 2;
1670 r600_src
->swizzle
[2] = 2;
1671 r600_src
->swizzle
[3] = 2;
1673 r600_src
->sel
= ctx
->tess_input_info
;
1674 r600_src
->swizzle
[0] = 3;
1675 r600_src
->swizzle
[1] = 3;
1676 r600_src
->swizzle
[2] = 3;
1677 r600_src
->swizzle
[3] = 3;
1679 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1681 r600_src
->swizzle
[0] = 0;
1682 r600_src
->swizzle
[1] = 0;
1683 r600_src
->swizzle
[2] = 0;
1684 r600_src
->swizzle
[3] = 0;
1685 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1687 r600_src
->swizzle
[0] = 3;
1688 r600_src
->swizzle
[1] = 3;
1689 r600_src
->swizzle
[2] = 3;
1690 r600_src
->swizzle
[3] = 3;
1691 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_GRID_SIZE
) {
1692 r600_src
->sel
= load_block_grid_size(ctx
, false);
1693 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_BLOCK_SIZE
) {
1694 r600_src
->sel
= load_block_grid_size(ctx
, true);
1695 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
1696 r600_src
->sel
= ctx
->helper_invoc_reg
;
1697 r600_src
->swizzle
[0] = 0;
1698 r600_src
->swizzle
[1] = 0;
1699 r600_src
->swizzle
[2] = 0;
1700 r600_src
->swizzle
[3] = 0;
1703 if (tgsi_src
->Register
.Indirect
)
1704 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1705 r600_src
->sel
= tgsi_src
->Register
.Index
;
1706 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1708 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1709 if (tgsi_src
->Register
.Dimension
) {
1710 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1711 if (tgsi_src
->Dimension
.Indirect
) {
1712 r600_src
->kc_rel
= 1;
1718 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1719 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1720 unsigned int dst_reg
)
1722 struct r600_bytecode_vtx vtx
;
1723 unsigned int ar_reg
;
1727 struct r600_bytecode_alu alu
;
1729 memset(&alu
, 0, sizeof(alu
));
1731 alu
.op
= ALU_OP2_ADD_INT
;
1732 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1733 alu
.src
[0].chan
= ar_chan
;
1735 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1736 alu
.src
[1].value
= offset
;
1738 alu
.dst
.sel
= dst_reg
;
1739 alu
.dst
.chan
= ar_chan
;
1743 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1748 ar_reg
= ctx
->bc
->ar_reg
;
1751 memset(&vtx
, 0, sizeof(vtx
));
1752 vtx
.buffer_id
= cb_idx
;
1753 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1754 vtx
.src_gpr
= ar_reg
;
1755 vtx
.src_sel_x
= ar_chan
;
1756 vtx
.mega_fetch_count
= 16;
1757 vtx
.dst_gpr
= dst_reg
;
1758 vtx
.dst_sel_x
= 0; /* SEL_X */
1759 vtx
.dst_sel_y
= 1; /* SEL_Y */
1760 vtx
.dst_sel_z
= 2; /* SEL_Z */
1761 vtx
.dst_sel_w
= 3; /* SEL_W */
1762 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1763 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1764 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1765 vtx
.endian
= r600_endian_swap(32);
1766 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1768 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1774 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1776 struct r600_bytecode_vtx vtx
;
1778 unsigned index
= src
->Register
.Index
;
1779 unsigned vtx_id
= src
->Dimension
.Index
;
1780 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1781 int offset_chan
= vtx_id
% 3;
1784 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1785 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1787 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1790 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1791 t2
= r600_get_temp(ctx
);
1793 if (src
->Dimension
.Indirect
) {
1795 struct r600_bytecode_alu alu
;
1798 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1799 if (src
->DimIndirect
.Index
> 0) {
1800 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1808 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1809 at least this is what fglrx seems to do. */
1810 for (i
= 0; i
< 3; i
++) {
1811 treg
[i
] = r600_get_temp(ctx
);
1813 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1815 for (i
= 0; i
< 3; i
++) {
1816 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1817 alu
.op
= ALU_OP1_MOV
;
1818 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1819 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1820 alu
.dst
.sel
= treg
[i
];
1824 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1828 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1829 alu
.op
= ALU_OP1_MOV
;
1830 alu
.src
[0].sel
= treg
[0];
1835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1842 if (src
->Register
.Indirect
) {
1844 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1846 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1848 /* pull the value from index_reg */
1849 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1852 V_SQ_ALU_SRC_LITERAL
, first
);
1855 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1858 V_SQ_ALU_SRC_LITERAL
, 4,
1859 offset_reg
, offset_chan
);
1864 index
= src
->Register
.Index
- first
;
1867 memset(&vtx
, 0, sizeof(vtx
));
1868 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1869 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1870 vtx
.src_gpr
= offset_reg
;
1871 vtx
.src_sel_x
= offset_chan
;
1872 vtx
.offset
= index
* 16; /*bytes*/
1873 vtx
.mega_fetch_count
= 16;
1874 vtx
.dst_gpr
= dst_reg
;
1875 vtx
.dst_sel_x
= 0; /* SEL_X */
1876 vtx
.dst_sel_y
= 1; /* SEL_Y */
1877 vtx
.dst_sel_z
= 2; /* SEL_Z */
1878 vtx
.dst_sel_w
= 3; /* SEL_W */
1879 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1880 vtx
.use_const_fields
= 1;
1882 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1885 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1891 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1893 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1896 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1897 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1899 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1900 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1901 /* primitive id is in R0.z */
1902 ctx
->src
[i
].sel
= 0;
1903 ctx
->src
[i
].swizzle
[0] = 2;
1906 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1907 int treg
= r600_get_temp(ctx
);
1909 fetch_gs_input(ctx
, src
, treg
);
1910 ctx
->src
[i
].sel
= treg
;
1911 ctx
->src
[i
].rel
= 0;
1918 /* Tessellation shaders pass outputs to the next shader using LDS.
1920 * LS outputs = TCS(HS) inputs
1921 * TCS(HS) outputs = TES(DS) inputs
1923 * The LDS layout is:
1924 * - TCS inputs for patch 0
1925 * - TCS inputs for patch 1
1926 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1928 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1929 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1930 * - TCS outputs for patch 1
1931 * - Per-patch TCS outputs for patch 1
1932 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1933 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1936 * All three shaders VS(LS), TCS, TES share the same LDS space.
1938 /* this will return with the dw address in temp_reg.x */
1939 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1940 const struct tgsi_full_dst_register
*dst
,
1941 const struct tgsi_full_src_register
*src
,
1942 int stride_bytes_reg
, int stride_bytes_chan
)
1944 struct tgsi_full_dst_register reg
;
1945 ubyte
*name
, *index
, *array_first
;
1948 struct tgsi_shader_info
*info
= &ctx
->info
;
1949 /* Set the register description. The address computation is the same
1950 * for sources and destinations. */
1952 reg
.Register
.File
= src
->Register
.File
;
1953 reg
.Register
.Index
= src
->Register
.Index
;
1954 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1955 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1956 reg
.Indirect
= src
->Indirect
;
1957 reg
.Dimension
= src
->Dimension
;
1958 reg
.DimIndirect
= src
->DimIndirect
;
1962 /* If the register is 2-dimensional (e.g. an array of vertices
1963 * in a primitive), calculate the base address of the vertex. */
1964 if (reg
.Register
.Dimension
) {
1966 if (reg
.Dimension
.Indirect
) {
1968 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1970 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1971 /* pull the value from index_reg */
1975 sel
= V_SQ_ALU_SRC_LITERAL
;
1976 chan
= reg
.Dimension
.Index
;
1979 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1981 stride_bytes_reg
, stride_bytes_chan
,
1988 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1989 name
= info
->input_semantic_name
;
1990 index
= info
->input_semantic_index
;
1991 array_first
= info
->input_array_first
;
1992 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1993 name
= info
->output_semantic_name
;
1994 index
= info
->output_semantic_index
;
1995 array_first
= info
->output_array_first
;
2000 if (reg
.Register
.Indirect
) {
2003 /* Add the relative address of the element. */
2004 if (reg
.Indirect
.ArrayID
)
2005 first
= array_first
[reg
.Indirect
.ArrayID
];
2007 first
= reg
.Register
.Index
;
2009 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
2011 /* pull the value from index_reg */
2012 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2014 V_SQ_ALU_SRC_LITERAL
, 16,
2020 param
= r600_get_lds_unique_index(name
[first
],
2024 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
2025 index
[reg
.Register
.Index
]);
2028 /* add to base_addr - passed in temp_reg.x */
2030 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2033 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2041 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
2042 unsigned dst_reg
, unsigned mask
)
2044 struct r600_bytecode_alu alu
;
2047 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
2048 ctx
->bc
->force_add_cf
= 1;
2050 lasti
= tgsi_last_instruction(mask
);
2051 for (i
= 1; i
<= lasti
; i
++) {
2052 if (!(mask
& (1 << i
)))
2055 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2058 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2062 for (i
= 0; i
<= lasti
; i
++) {
2063 if (!(mask
& (1 << i
)))
2066 /* emit an LDS_READ_RET */
2067 memset(&alu
, 0, sizeof(alu
));
2068 alu
.op
= LDS_OP1_LDS_READ_RET
;
2069 alu
.src
[0].sel
= temp_reg
;
2070 alu
.src
[0].chan
= i
;
2071 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
2072 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2074 alu
.is_lds_idx_op
= true;
2076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2080 for (i
= 0; i
<= lasti
; i
++) {
2081 if (!(mask
& (1 << i
)))
2084 /* then read from LDS_OQ_A_POP */
2085 memset(&alu
, 0, sizeof(alu
));
2087 alu
.op
= ALU_OP1_MOV
;
2088 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
2089 alu
.src
[0].chan
= 0;
2090 alu
.dst
.sel
= dst_reg
;
2094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2101 static int fetch_mask(struct tgsi_src_register
*reg
)
2104 mask
|= 1 << reg
->SwizzleX
;
2105 mask
|= 1 << reg
->SwizzleY
;
2106 mask
|= 1 << reg
->SwizzleZ
;
2107 mask
|= 1 << reg
->SwizzleW
;
2111 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
2114 unsigned temp_reg
= r600_get_temp(ctx
);
2116 r
= get_lds_offset0(ctx
, 2, temp_reg
,
2117 src
->Register
.Dimension
? false : true);
2121 /* the base address is now in temp.x */
2122 r
= r600_get_byte_address(ctx
, temp_reg
,
2123 NULL
, src
, ctx
->tess_output_info
, 1);
2127 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2133 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
2136 unsigned temp_reg
= r600_get_temp(ctx
);
2138 /* t.x = ips * r0.y */
2139 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2141 ctx
->tess_input_info
, 0,
2147 /* the base address is now in temp.x */
2148 r
= r600_get_byte_address(ctx
, temp_reg
,
2149 NULL
, src
, ctx
->tess_input_info
, 1);
2153 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2159 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
2162 unsigned temp_reg
= r600_get_temp(ctx
);
2164 r
= get_lds_offset0(ctx
, 1, temp_reg
,
2165 src
->Register
.Dimension
? false : true);
2168 /* the base address is now in temp.x */
2169 r
= r600_get_byte_address(ctx
, temp_reg
,
2171 ctx
->tess_output_info
, 1);
2175 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
2181 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
2183 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2186 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2187 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
2189 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2190 int treg
= r600_get_temp(ctx
);
2191 fetch_tes_input(ctx
, src
, treg
);
2192 ctx
->src
[i
].sel
= treg
;
2193 ctx
->src
[i
].rel
= 0;
2195 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
2196 int treg
= r600_get_temp(ctx
);
2197 fetch_tcs_input(ctx
, src
, treg
);
2198 ctx
->src
[i
].sel
= treg
;
2199 ctx
->src
[i
].rel
= 0;
2201 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
2202 int treg
= r600_get_temp(ctx
);
2203 fetch_tcs_output(ctx
, src
, treg
);
2204 ctx
->src
[i
].sel
= treg
;
2205 ctx
->src
[i
].rel
= 0;
2211 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
2213 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2214 struct r600_bytecode_alu alu
;
2215 int i
, j
, k
, nconst
, r
;
2217 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2218 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
2221 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
2223 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2224 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
2228 if (ctx
->src
[i
].rel
) {
2229 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
2230 int treg
= r600_get_temp(ctx
);
2231 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
2234 ctx
->src
[i
].kc_bank
= 0;
2235 ctx
->src
[i
].kc_rel
= 0;
2236 ctx
->src
[i
].sel
= treg
;
2237 ctx
->src
[i
].rel
= 0;
2240 int treg
= r600_get_temp(ctx
);
2241 for (k
= 0; k
< 4; k
++) {
2242 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2243 alu
.op
= ALU_OP1_MOV
;
2244 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2245 alu
.src
[0].chan
= k
;
2246 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
2247 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
2248 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
2254 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2258 ctx
->src
[i
].sel
= treg
;
2266 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
2267 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
2269 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2270 struct r600_bytecode_alu alu
;
2271 int i
, j
, k
, nliteral
, r
;
2273 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2274 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2278 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
2279 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
2280 int treg
= r600_get_temp(ctx
);
2281 for (k
= 0; k
< 4; k
++) {
2282 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2283 alu
.op
= ALU_OP1_MOV
;
2284 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
2285 alu
.src
[0].chan
= k
;
2286 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2292 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2296 ctx
->src
[i
].sel
= treg
;
2303 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2305 int i
, r
, count
= ctx
->shader
->ninput
;
2307 for (i
= 0; i
< count
; i
++) {
2308 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2309 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2317 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2318 int stream
, unsigned *stream_item_size UNUSED
)
2320 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2321 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2325 /* Sanity checking. */
2326 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2327 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2331 for (i
= 0; i
< so
->num_outputs
; i
++) {
2332 if (so
->output
[i
].output_buffer
>= 4) {
2333 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2334 so
->output
[i
].output_buffer
);
2340 /* Initialize locations where the outputs are stored. */
2341 for (i
= 0; i
< so
->num_outputs
; i
++) {
2343 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2344 start_comp
[i
] = so
->output
[i
].start_component
;
2345 /* Lower outputs with dst_offset < start_component.
2347 * We can only output 4D vectors with a write mask, e.g. we can
2348 * only output the W component at offset 3, etc. If we want
2349 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2350 * to move it to X and output X. */
2351 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2352 unsigned tmp
= r600_get_temp(ctx
);
2354 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2355 struct r600_bytecode_alu alu
;
2356 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2357 alu
.op
= ALU_OP1_MOV
;
2358 alu
.src
[0].sel
= so_gpr
[i
];
2359 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2364 if (j
== so
->output
[i
].num_components
- 1)
2366 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2375 /* Write outputs to buffers. */
2376 for (i
= 0; i
< so
->num_outputs
; i
++) {
2377 struct r600_bytecode_output output
;
2379 if (stream
!= -1 && stream
!= so
->output
[i
].stream
)
2382 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2383 output
.gpr
= so_gpr
[i
];
2384 output
.elem_size
= so
->output
[i
].num_components
- 1;
2385 if (output
.elem_size
== 2)
2386 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2387 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2388 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2389 output
.burst_count
= 1;
2390 /* array_size is an upper limit for the burst_count
2391 * with MEM_STREAM instructions */
2392 output
.array_size
= 0xFFF;
2393 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2395 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2396 switch (so
->output
[i
].output_buffer
) {
2398 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2401 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2404 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2407 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2410 output
.op
+= so
->output
[i
].stream
* 4;
2411 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2412 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2414 switch (so
->output
[i
].output_buffer
) {
2416 output
.op
= CF_OP_MEM_STREAM0
;
2419 output
.op
= CF_OP_MEM_STREAM1
;
2422 output
.op
= CF_OP_MEM_STREAM2
;
2425 output
.op
= CF_OP_MEM_STREAM3
;
2428 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2430 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2439 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2441 struct r600_bytecode_alu alu
;
2444 if (!ctx
->shader
->vs_out_edgeflag
)
2447 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2449 /* clamp(x, 0, 1) */
2450 memset(&alu
, 0, sizeof(alu
));
2451 alu
.op
= ALU_OP1_MOV
;
2452 alu
.src
[0].sel
= reg
;
2457 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2459 memset(&alu
, 0, sizeof(alu
));
2460 alu
.op
= ALU_OP1_FLT_TO_INT
;
2461 alu
.src
[0].sel
= reg
;
2465 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2468 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2469 struct r600_pipe_shader
*gs
,
2470 struct pipe_stream_output_info
*so
)
2472 struct r600_shader_ctx ctx
= {};
2473 struct r600_shader
*gs_shader
= &gs
->shader
;
2474 struct r600_pipe_shader
*cshader
;
2475 unsigned ocnt
= gs_shader
->noutput
;
2476 struct r600_bytecode_alu alu
;
2477 struct r600_bytecode_vtx vtx
;
2478 struct r600_bytecode_output output
;
2479 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2480 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2481 int next_clip_pos
= 61, next_param
= 0;
2484 bool only_ring_0
= true;
2485 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2489 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2490 sizeof(struct r600_shader_io
));
2492 cshader
->shader
.noutput
= ocnt
;
2494 ctx
.shader
= &cshader
->shader
;
2495 ctx
.bc
= &ctx
.shader
->bc
;
2496 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2498 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2499 rctx
->screen
->has_compressed_msaa_texturing
);
2501 ctx
.bc
->isa
= rctx
->isa
;
2504 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2506 /* R0.x = R0.x & 0x3fffffff */
2507 memset(&alu
, 0, sizeof(alu
));
2508 alu
.op
= ALU_OP2_AND_INT
;
2509 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2510 alu
.src
[1].value
= 0x3fffffff;
2512 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2514 /* R0.y = R0.x >> 30 */
2515 memset(&alu
, 0, sizeof(alu
));
2516 alu
.op
= ALU_OP2_LSHR_INT
;
2517 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2518 alu
.src
[1].value
= 0x1e;
2522 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2524 /* fetch vertex data from GSVS ring */
2525 for (i
= 0; i
< ocnt
; ++i
) {
2526 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2529 out
->ring_offset
= i
* 16;
2531 memset(&vtx
, 0, sizeof(vtx
));
2532 vtx
.op
= FETCH_OP_VFETCH
;
2533 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2534 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2535 vtx
.mega_fetch_count
= 16;
2536 vtx
.offset
= out
->ring_offset
;
2537 vtx
.dst_gpr
= out
->gpr
;
2543 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2544 vtx
.use_const_fields
= 1;
2546 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2549 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2551 ctx
.temp_reg
= i
+ 1;
2552 for (ring
= 3; ring
>= 0; --ring
) {
2553 bool enabled
= false;
2554 for (i
= 0; i
< so
->num_outputs
; i
++) {
2555 if (so
->output
[i
].stream
== ring
) {
2558 only_ring_0
= false;
2562 if (ring
!= 0 && !enabled
) {
2563 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2568 // Patch up jump label
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;
2578 /* PRED_SETE_INT __, R0.y, ring */
2579 memset(&alu
, 0, sizeof(alu
));
2580 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2581 alu
.src
[0].chan
= 1;
2582 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2583 alu
.src
[1].value
= ring
;
2584 alu
.execute_mask
= 1;
2585 alu
.update_pred
= 1;
2587 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2589 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2590 cf_jump
= ctx
.bc
->cf_last
;
2593 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2594 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2597 /* bc adds nops - copy it */
2598 if (ctx
.bc
->chip_class
== R600
) {
2599 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2600 alu
.op
= ALU_OP0_NOP
;
2602 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2604 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2607 /* export vertex data */
2608 /* XXX factor out common code with r600_shader_from_tgsi ? */
2609 for (i
= 0; i
< ocnt
; ++i
) {
2610 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2611 bool instream0
= true;
2612 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2615 for (j
= 0; j
< so
->num_outputs
; j
++) {
2616 if (so
->output
[j
].register_index
== i
) {
2617 if (so
->output
[j
].stream
== 0)
2619 if (so
->output
[j
].stream
> 0)
2625 memset(&output
, 0, sizeof(output
));
2626 output
.gpr
= out
->gpr
;
2627 output
.elem_size
= 3;
2628 output
.swizzle_x
= 0;
2629 output
.swizzle_y
= 1;
2630 output
.swizzle_z
= 2;
2631 output
.swizzle_w
= 3;
2632 output
.burst_count
= 1;
2633 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2634 output
.op
= CF_OP_EXPORT
;
2635 switch (out
->name
) {
2636 case TGSI_SEMANTIC_POSITION
:
2637 output
.array_base
= 60;
2638 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2641 case TGSI_SEMANTIC_PSIZE
:
2642 output
.array_base
= 61;
2643 if (next_clip_pos
== 61)
2645 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2646 output
.swizzle_y
= 7;
2647 output
.swizzle_z
= 7;
2648 output
.swizzle_w
= 7;
2649 ctx
.shader
->vs_out_misc_write
= 1;
2650 ctx
.shader
->vs_out_point_size
= 1;
2652 case TGSI_SEMANTIC_LAYER
:
2654 /* duplicate it as PARAM to pass to the pixel shader */
2655 output
.array_base
= next_param
++;
2656 r600_bytecode_add_output(ctx
.bc
, &output
);
2657 last_exp_param
= ctx
.bc
->cf_last
;
2659 output
.array_base
= 61;
2660 if (next_clip_pos
== 61)
2662 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2663 output
.swizzle_x
= 7;
2664 output
.swizzle_y
= 7;
2665 output
.swizzle_z
= 0;
2666 output
.swizzle_w
= 7;
2667 ctx
.shader
->vs_out_misc_write
= 1;
2668 ctx
.shader
->vs_out_layer
= 1;
2670 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2672 /* duplicate it as PARAM to pass to the pixel shader */
2673 output
.array_base
= next_param
++;
2674 r600_bytecode_add_output(ctx
.bc
, &output
);
2675 last_exp_param
= ctx
.bc
->cf_last
;
2677 output
.array_base
= 61;
2678 if (next_clip_pos
== 61)
2680 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2681 ctx
.shader
->vs_out_misc_write
= 1;
2682 ctx
.shader
->vs_out_viewport
= 1;
2683 output
.swizzle_x
= 7;
2684 output
.swizzle_y
= 7;
2685 output
.swizzle_z
= 7;
2686 output
.swizzle_w
= 0;
2688 case TGSI_SEMANTIC_CLIPDIST
:
2689 /* spi_sid is 0 for clipdistance outputs that were generated
2690 * for clipvertex - we don't need to pass them to PS */
2691 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2692 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2693 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2695 /* duplicate it as PARAM to pass to the pixel shader */
2696 output
.array_base
= next_param
++;
2697 r600_bytecode_add_output(ctx
.bc
, &output
);
2698 last_exp_param
= ctx
.bc
->cf_last
;
2700 output
.array_base
= next_clip_pos
++;
2701 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2703 case TGSI_SEMANTIC_FOG
:
2704 output
.swizzle_y
= 4; /* 0 */
2705 output
.swizzle_z
= 4; /* 0 */
2706 output
.swizzle_w
= 5; /* 1 */
2709 output
.array_base
= next_param
++;
2712 r600_bytecode_add_output(ctx
.bc
, &output
);
2713 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2714 last_exp_param
= ctx
.bc
->cf_last
;
2716 last_exp_pos
= ctx
.bc
->cf_last
;
2719 if (!last_exp_pos
) {
2720 memset(&output
, 0, sizeof(output
));
2722 output
.elem_size
= 3;
2723 output
.swizzle_x
= 7;
2724 output
.swizzle_y
= 7;
2725 output
.swizzle_z
= 7;
2726 output
.swizzle_w
= 7;
2727 output
.burst_count
= 1;
2729 output
.op
= CF_OP_EXPORT
;
2730 output
.array_base
= 60;
2731 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2732 r600_bytecode_add_output(ctx
.bc
, &output
);
2733 last_exp_pos
= ctx
.bc
->cf_last
;
2736 if (!last_exp_param
) {
2737 memset(&output
, 0, sizeof(output
));
2739 output
.elem_size
= 3;
2740 output
.swizzle_x
= 7;
2741 output
.swizzle_y
= 7;
2742 output
.swizzle_z
= 7;
2743 output
.swizzle_w
= 7;
2744 output
.burst_count
= 1;
2746 output
.op
= CF_OP_EXPORT
;
2747 output
.array_base
= next_param
++;
2748 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2749 r600_bytecode_add_output(ctx
.bc
, &output
);
2750 last_exp_param
= ctx
.bc
->cf_last
;
2753 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2754 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2756 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2757 cf_pop
= ctx
.bc
->cf_last
;
2759 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2760 cf_jump
->pop_count
= 1;
2761 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2762 cf_pop
->pop_count
= 1;
2764 if (ctx
.bc
->chip_class
== CAYMAN
)
2765 cm_bytecode_add_cf_end(ctx
.bc
);
2767 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2768 ctx
.bc
->cf_last
->end_of_program
= 1;
2771 gs
->gs_copy_shader
= cshader
;
2772 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2776 return r600_bytecode_build(ctx
.bc
);
2779 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2782 struct r600_bytecode_alu alu
;
2785 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2786 alu
.op
= ALU_OP2_ADD_INT
;
2787 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2788 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2789 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2790 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2793 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2800 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2802 struct r600_bytecode_output output
;
2805 int effective_stream
= stream
== -1 ? 0 : stream
;
2808 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2809 if (ctx
->gs_for_vs
) {
2810 /* for ES we need to lookup corresponding ring offset expected by GS
2811 * (map this output to GS input by name and sid) */
2812 /* FIXME precompute offsets */
2814 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2815 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2816 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2817 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2818 ring_offset
= in
->ring_offset
;
2821 if (ring_offset
== -1)
2824 ring_offset
= idx
* 16;
2828 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2830 /* next_ring_offset after parsing input decls contains total size of
2831 * single vertex data, gs_next_vertex - current vertex index */
2833 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2835 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2836 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2837 output
.elem_size
= 3;
2838 output
.comp_mask
= 0xF;
2839 output
.burst_count
= 1;
2842 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2844 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2849 output
.op
= CF_OP_MEM_RING
; break;
2851 output
.op
= CF_OP_MEM_RING1
; break;
2853 output
.op
= CF_OP_MEM_RING2
; break;
2855 output
.op
= CF_OP_MEM_RING3
; break;
2859 output
.array_base
= ring_offset
>> 2; /* in dwords */
2860 output
.array_size
= 0xfff;
2861 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2863 output
.array_base
= ring_offset
>> 2; /* in dwords */
2864 r600_bytecode_add_output(ctx
->bc
, &output
);
2867 ++ctx
->gs_next_vertex
;
2872 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2875 struct r600_bytecode_vtx vtx
;
2876 int temp_val
= ctx
->temp_reg
;
2877 /* need to store the TCS output somewhere */
2878 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2880 V_SQ_ALU_SRC_LITERAL
, 0,
2885 /* used by VS/TCS */
2886 if (ctx
->tess_input_info
) {
2887 /* fetch tcs input values into resv space */
2888 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2889 vtx
.op
= FETCH_OP_VFETCH
;
2890 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2891 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2892 vtx
.mega_fetch_count
= 16;
2893 vtx
.data_format
= FMT_32_32_32_32
;
2894 vtx
.num_format_all
= 2;
2895 vtx
.format_comp_all
= 1;
2896 vtx
.use_const_fields
= 0;
2897 vtx
.endian
= r600_endian_swap(32);
2898 vtx
.srf_mode_all
= 1;
2900 vtx
.dst_gpr
= ctx
->tess_input_info
;
2905 vtx
.src_gpr
= temp_val
;
2908 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2913 /* used by TCS/TES */
2914 if (ctx
->tess_output_info
) {
2915 /* fetch tcs output values into resv space */
2916 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2917 vtx
.op
= FETCH_OP_VFETCH
;
2918 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2919 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2920 vtx
.mega_fetch_count
= 16;
2921 vtx
.data_format
= FMT_32_32_32_32
;
2922 vtx
.num_format_all
= 2;
2923 vtx
.format_comp_all
= 1;
2924 vtx
.use_const_fields
= 0;
2925 vtx
.endian
= r600_endian_swap(32);
2926 vtx
.srf_mode_all
= 1;
2928 vtx
.dst_gpr
= ctx
->tess_output_info
;
2933 vtx
.src_gpr
= temp_val
;
2936 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2943 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2949 /* fetch tcs input values into input_vals */
2950 ctx
->tess_input_info
= r600_get_temp(ctx
);
2951 ctx
->tess_output_info
= 0;
2952 r
= r600_fetch_tess_io_info(ctx
);
2956 temp_reg
= r600_get_temp(ctx
);
2957 /* dst reg contains LDS address stride * idx */
2958 /* MUL vertexID, vertex_dw_stride */
2959 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2961 ctx
->tess_input_info
, 1,
2962 0, 1); /* rel id in r0.y? */
2966 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2967 struct r600_bytecode_alu alu
;
2968 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2971 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2974 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2979 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2981 temp_reg
, param
? 1 : 0,
2982 V_SQ_ALU_SRC_LITERAL
, 8);
2987 for (j
= 0; j
< 2; j
++) {
2988 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2990 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2991 alu
.src
[0].sel
= temp_reg
;
2992 alu
.src
[0].chan
= chan
;
2993 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2994 alu
.src
[1].chan
= j
* 2;
2995 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2996 alu
.src
[2].chan
= (j
* 2) + 1;
3000 alu
.is_lds_idx_op
= true;
3001 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3009 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
3011 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3012 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
3014 int temp_reg
= r600_get_temp(ctx
);
3015 struct r600_bytecode_alu alu
;
3016 unsigned write_mask
= dst
->Register
.WriteMask
;
3018 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
3021 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
3025 /* the base address is now in temp.x */
3026 r
= r600_get_byte_address(ctx
, temp_reg
,
3027 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
3032 lasti
= tgsi_last_instruction(write_mask
);
3033 for (i
= 1; i
<= lasti
; i
++) {
3035 if (!(write_mask
& (1 << i
)))
3037 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3040 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3045 for (i
= 0; i
<= lasti
; i
++) {
3046 if (!(write_mask
& (1 << i
)))
3049 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
3050 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
3051 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3052 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
3053 alu
.src
[0].sel
= temp_reg
;
3054 alu
.src
[0].chan
= i
;
3056 alu
.src
[1].sel
= dst
->Register
.Index
;
3057 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
3058 alu
.src
[1].chan
= i
;
3060 alu
.src
[2].sel
= dst
->Register
.Index
;
3061 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
3062 alu
.src
[2].chan
= i
+ 1;
3066 alu
.is_lds_idx_op
= true;
3067 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3074 alu
.op
= LDS_OP2_LDS_WRITE
;
3075 alu
.src
[0].sel
= temp_reg
;
3076 alu
.src
[0].chan
= i
;
3078 alu
.src
[1].sel
= dst
->Register
.Index
;
3079 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
3080 alu
.src
[1].chan
= i
;
3082 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
3085 alu
.is_lds_idx_op
= true;
3086 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3093 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
3094 int output_idx
, int nc
)
3097 unsigned temp_reg
= r600_get_temp(ctx
);
3098 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
3099 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
3102 param
= r600_get_lds_unique_index(name
, 0);
3103 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
3108 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3111 V_SQ_ALU_SRC_LITERAL
, param
* 16);
3116 do_lds_fetch_values(ctx
, temp_reg
, dreg
, ((1u << nc
) - 1));
3120 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
3122 int stride
, outer_comps
, inner_comps
;
3123 int tessinner_idx
= -1, tessouter_idx
= -1;
3126 int temp_reg
= r600_get_temp(ctx
);
3127 int treg
[3] = {-1, -1, -1};
3128 struct r600_bytecode_alu alu
;
3129 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
3131 /* only execute factor emission for invocation 0 */
3132 /* PRED_SETE_INT __, R0.x, 0 */
3133 memset(&alu
, 0, sizeof(alu
));
3134 alu
.op
= ALU_OP2_PRED_SETE_INT
;
3135 alu
.src
[0].chan
= 2;
3136 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3137 alu
.execute_mask
= 1;
3138 alu
.update_pred
= 1;
3140 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
3142 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
3143 cf_jump
= ctx
->bc
->cf_last
;
3145 treg
[0] = r600_get_temp(ctx
);
3146 switch (ctx
->shader
->tcs_prim_mode
) {
3147 case PIPE_PRIM_LINES
:
3148 stride
= 8; /* 2 dwords, 1 vec2 store */
3152 case PIPE_PRIM_TRIANGLES
:
3153 stride
= 16; /* 4 dwords, 1 vec4 store */
3156 treg
[1] = r600_get_temp(ctx
);
3158 case PIPE_PRIM_QUADS
:
3159 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
3162 treg
[1] = r600_get_temp(ctx
);
3163 treg
[2] = r600_get_temp(ctx
);
3170 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
3171 /* TF_WRITE takes index in R.x, value in R.y */
3172 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
3173 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
3175 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
3179 if (tessouter_idx
== -1)
3182 if (tessinner_idx
== -1 && inner_comps
)
3185 if (tessouter_idx
!= -1) {
3186 r
= r600_tess_factor_read(ctx
, tessouter_idx
, outer_comps
);
3191 if (tessinner_idx
!= -1) {
3192 r
= r600_tess_factor_read(ctx
, tessinner_idx
, inner_comps
);
3197 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
3198 /* r.x = relpatchid(r0.y) * tf_stride */
3200 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
3201 /* add incoming r0.w to it: t.x = t.x + r0.w */
3202 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3205 V_SQ_ALU_SRC_LITERAL
, stride
,
3210 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3211 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
3212 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
3214 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
3217 else if (out_comp
== 0)
3221 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
3222 treg
[i
/ 2], (2 * (i
% 2)),
3224 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
3227 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
3228 treg
[i
/ 2], 1 + (2 * (i
%2)),
3229 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
3234 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
3235 struct r600_bytecode_gds gds
;
3237 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
3238 gds
.src_gpr
= treg
[i
/ 2];
3239 gds
.src_sel_x
= 2 * (i
% 2);
3240 gds
.src_sel_y
= 1 + (2 * (i
% 2));
3246 gds
.op
= FETCH_OP_TF_WRITE
;
3247 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
3252 // Patch up jump label
3253 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
3254 cf_pop
= ctx
->bc
->cf_last
;
3256 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
3257 cf_jump
->pop_count
= 1;
3258 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
3259 cf_pop
->pop_count
= 1;
3265 * We have to work out the thread ID for load and atomic
3266 * operations, which store the returned value to an index
3267 * in an intermediate buffer.
3268 * The index is calculated by taking the thread id,
3269 * calculated from the MBCNT instructions.
3270 * Then the shader engine ID is multiplied by 256,
3271 * and the wave id is added.
3272 * Then the result is multipled by 64 and thread id is
3275 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
3277 struct r600_bytecode_alu alu
;
3280 if (ctx
->thread_id_gpr_loaded
)
3283 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3284 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
3285 alu
.dst
.sel
= ctx
->temp_reg
;
3287 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3288 alu
.src
[0].value
= 0xffffffff;
3290 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3294 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3295 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3296 alu
.dst
.sel
= ctx
->temp_reg
;
3298 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3299 alu
.src
[0].value
= 0xffffffff;
3301 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3306 alu
.op
= ALU_OP3_MULADD_UINT24
;
3307 alu
.dst
.sel
= ctx
->temp_reg
;
3309 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3310 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3311 alu
.src
[1].value
= 256;
3312 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3316 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3320 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3321 ctx
->thread_id_gpr
, 1,
3323 V_SQ_ALU_SRC_LITERAL
, 0x40,
3327 ctx
->thread_id_gpr_loaded
= true;
3331 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3332 struct r600_pipe_shader
*pipeshader
,
3333 union r600_shader_key key
)
3335 struct r600_screen
*rscreen
= rctx
->screen
;
3336 struct r600_shader
*shader
= &pipeshader
->shader
;
3337 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3338 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3339 struct tgsi_full_immediate
*immediate
;
3340 struct r600_shader_ctx ctx
;
3341 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3342 unsigned output_done
, noutput
;
3346 int next_param_base
= 0, next_clip_base
;
3347 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3349 bool ring_outputs
= false;
3350 bool lds_outputs
= false;
3351 bool lds_inputs
= false;
3352 bool pos_emitted
= false;
3354 ctx
.bc
= &shader
->bc
;
3355 ctx
.shader
= shader
;
3357 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3358 rscreen
->has_compressed_msaa_texturing
);
3359 ctx
.tokens
= tokens
;
3360 tgsi_scan_shader(tokens
, &ctx
.info
);
3361 shader
->indirect_files
= ctx
.info
.indirect_files
;
3363 int narrays
= ctx
.info
.array_max
[TGSI_FILE_TEMPORARY
];
3364 ctx
.array_infos
= calloc(narrays
, sizeof(*ctx
.array_infos
));
3365 ctx
.spilled_arrays
= calloc(narrays
, sizeof(bool));
3366 tgsi_scan_arrays(tokens
, TGSI_FILE_TEMPORARY
, narrays
, ctx
.array_infos
);
3368 shader
->uses_helper_invocation
= false;
3369 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3370 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3371 shader
->nsys_inputs
= 0;
3373 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3374 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3375 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3376 tgsi_parse_init(&ctx
.parse
, tokens
);
3377 ctx
.type
= ctx
.info
.processor
;
3378 shader
->processor_type
= ctx
.type
;
3379 ctx
.bc
->type
= shader
->processor_type
;
3382 case PIPE_SHADER_VERTEX
:
3383 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3384 shader
->vs_as_es
= key
.vs
.as_es
;
3385 shader
->vs_as_ls
= key
.vs
.as_ls
;
3386 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3387 if (shader
->vs_as_es
)
3388 ring_outputs
= true;
3389 if (shader
->vs_as_ls
)
3392 case PIPE_SHADER_GEOMETRY
:
3393 ring_outputs
= true;
3394 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3395 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3397 case PIPE_SHADER_TESS_CTRL
:
3398 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3399 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3403 case PIPE_SHADER_TESS_EVAL
:
3404 shader
->tes_as_es
= key
.tes
.as_es
;
3405 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3407 if (shader
->tes_as_es
)
3408 ring_outputs
= true;
3410 case PIPE_SHADER_FRAGMENT
:
3411 shader
->two_side
= key
.ps
.color_two_side
;
3412 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3413 shader
->rat_base
= key
.ps
.nr_cbufs
;
3414 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3416 case PIPE_SHADER_COMPUTE
:
3417 shader
->rat_base
= 0;
3418 shader
->image_size_const_offset
= ctx
.info
.file_count
[TGSI_FILE_SAMPLER
];
3424 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3425 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3427 ctx
.gs_for_vs
= NULL
;
3430 ctx
.next_ring_offset
= 0;
3431 ctx
.gs_out_ring_offset
= 0;
3432 ctx
.gs_next_vertex
= 0;
3433 ctx
.gs_stream_output_info
= &so
;
3436 ctx
.fixed_pt_position_gpr
= -1;
3437 ctx
.fragcoord_input
= -1;
3438 ctx
.colors_used
= 0;
3439 ctx
.clip_vertex_write
= 0;
3440 ctx
.thread_id_gpr_loaded
= false;
3442 ctx
.helper_invoc_reg
= -1;
3443 ctx
.cs_block_size_reg
= -1;
3444 ctx
.cs_grid_size_reg
= -1;
3445 ctx
.cs_block_size_loaded
= false;
3446 ctx
.cs_grid_size_loaded
= false;
3448 shader
->nr_ps_color_exports
= 0;
3449 shader
->nr_ps_max_color_exports
= 0;
3452 /* register allocations */
3453 /* Values [0,127] correspond to GPR[0..127].
3454 * Values [128,159] correspond to constant buffer bank 0
3455 * Values [160,191] correspond to constant buffer bank 1
3456 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3457 * Values [256,287] correspond to constant buffer bank 2 (EG)
3458 * Values [288,319] correspond to constant buffer bank 3 (EG)
3459 * Other special values are shown in the list below.
3460 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3461 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3462 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3463 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3464 * 248 SQ_ALU_SRC_0: special constant 0.0.
3465 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3466 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3467 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3468 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3469 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3470 * 254 SQ_ALU_SRC_PV: previous vector result.
3471 * 255 SQ_ALU_SRC_PS: previous scalar result.
3473 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3474 ctx
.file_offset
[i
] = 0;
3477 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3479 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3480 if (ctx
.info
.num_inputs
)
3481 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3483 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3484 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3485 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3487 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3489 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3490 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_HELPER_INVOCATION
) {
3491 ctx
.helper_invoc_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3492 shader
->uses_helper_invocation
= true;
3496 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3497 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3498 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3500 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3501 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3502 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3503 bool add_tesscoord
= false, add_tess_inout
= false;
3504 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3505 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3506 /* if we have tesscoord save one reg */
3507 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3508 add_tesscoord
= true;
3509 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3510 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3511 add_tess_inout
= true;
3513 if (add_tesscoord
|| add_tess_inout
)
3514 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3516 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3518 if (ctx
.type
== PIPE_SHADER_COMPUTE
) {
3519 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3520 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3521 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_GRID_SIZE
)
3522 ctx
.cs_grid_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3523 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_BLOCK_SIZE
)
3524 ctx
.cs_block_size_reg
= ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3528 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3529 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3530 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3531 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3532 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3534 /* Outside the GPR range. This will be translated to one of the
3535 * kcache banks later. */
3536 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3537 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3539 pipeshader
->scratch_space_needed
= 0;
3540 int regno
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3541 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
];
3543 choose_spill_arrays(&ctx
, ®no
, &pipeshader
->scratch_space_needed
);
3544 shader
->indirect_files
= ctx
.info
.indirect_files
;
3546 shader
->needs_scratch_space
= pipeshader
->scratch_space_needed
!= 0;
3548 ctx
.bc
->ar_reg
= ++regno
;
3549 ctx
.bc
->index_reg
[0] = ++regno
;
3550 ctx
.bc
->index_reg
[1] = ++regno
;
3552 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3553 ctx
.tess_input_info
= ++regno
;
3554 ctx
.tess_output_info
= ++regno
;
3555 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3556 ctx
.tess_input_info
= 0;
3557 ctx
.tess_output_info
= ++regno
;
3558 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3559 ctx
.gs_export_gpr_tregs
[0] = ++regno
;
3560 ctx
.gs_export_gpr_tregs
[1] = ++regno
;
3561 ctx
.gs_export_gpr_tregs
[2] = ++regno
;
3562 ctx
.gs_export_gpr_tregs
[3] = ++regno
;
3563 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3564 ctx
.gs_rotated_input
[0] = ++regno
;
3565 ctx
.gs_rotated_input
[1] = ++regno
;
3567 ctx
.gs_rotated_input
[0] = 0;
3568 ctx
.gs_rotated_input
[1] = 1;
3572 if (shader
->uses_images
) {
3573 ctx
.thread_id_gpr
= ++regno
;
3574 ctx
.thread_id_gpr_loaded
= false;
3576 ctx
.temp_reg
= ++regno
;
3578 shader
->max_arrays
= 0;
3579 shader
->num_arrays
= 0;
3580 if (indirect_gprs
) {
3582 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3583 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3584 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3585 ctx
.file_offset
[TGSI_FILE_INPUT
],
3588 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3589 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3590 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3591 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3597 ctx
.literals
= NULL
;
3598 ctx
.max_driver_temp_used
= 0;
3600 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3601 ctx
.info
.colors_written
== 1;
3602 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3603 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3605 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3606 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3607 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3608 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3609 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3610 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3611 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3614 if (shader
->vs_as_gs_a
)
3615 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3617 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3618 r600_fetch_tess_io_info(&ctx
);
3620 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3621 tgsi_parse_token(&ctx
.parse
);
3622 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3623 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3624 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3625 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3626 if(ctx
.literals
== NULL
) {
3630 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3631 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3632 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3633 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3636 case TGSI_TOKEN_TYPE_DECLARATION
:
3637 r
= tgsi_declaration(&ctx
);
3641 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3642 case TGSI_TOKEN_TYPE_PROPERTY
:
3645 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3651 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3652 shader
->ring_item_sizes
[1] = 0;
3653 shader
->ring_item_sizes
[2] = 0;
3654 shader
->ring_item_sizes
[3] = 0;
3656 /* Process two side if needed */
3657 if (shader
->two_side
&& ctx
.colors_used
) {
3658 int i
, count
= ctx
.shader
->ninput
;
3659 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3661 /* additional inputs will be allocated right after the existing inputs,
3662 * we won't need them after the color selection, so we don't need to
3663 * reserve these gprs for the rest of the shader code and to adjust
3664 * output offsets etc. */
3665 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3666 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3668 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3669 if (ctx
.face_gpr
== -1) {
3670 i
= ctx
.shader
->ninput
++;
3671 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3672 ctx
.shader
->input
[i
].spi_sid
= 0;
3673 ctx
.shader
->input
[i
].gpr
= gpr
++;
3674 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3677 for (i
= 0; i
< count
; i
++) {
3678 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3679 int ni
= ctx
.shader
->ninput
++;
3680 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3681 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3682 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3683 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3684 // TGSI to LLVM needs to know the lds position of inputs.
3685 // Non LLVM path computes it later (in process_twoside_color)
3686 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3687 ctx
.shader
->input
[i
].back_color_input
= ni
;
3688 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3689 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3696 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3697 shader
->nr_ps_max_color_exports
= 8;
3699 if (ctx
.shader
->uses_helper_invocation
) {
3700 if (ctx
.bc
->chip_class
== CAYMAN
)
3701 r
= cm_load_helper_invocation(&ctx
);
3703 r
= eg_load_helper_invocation(&ctx
);
3709 * XXX this relies on fixed_pt_position_gpr only being present when
3710 * this shader should be executed per sample. Should be the case for now...
3712 if (ctx
.fixed_pt_position_gpr
!= -1 && ctx
.info
.reads_samplemask
) {
3714 * Fix up sample mask. The hw always gives us coverage mask for
3715 * the pixel. However, for per-sample shading, we need the
3716 * coverage for the shader invocation only.
3717 * Also, with disabled msaa, only the first bit should be set
3718 * (luckily the same fixup works for both problems).
3719 * For now, we can only do it if we know this shader is always
3720 * executed per sample (due to usage of bits in the shader
3721 * forcing per-sample execution).
3722 * If the fb is not multisampled, we'd do unnecessary work but
3723 * it should still be correct.
3724 * It will however do nothing for sample shading according
3725 * to MinSampleShading.
3727 struct r600_bytecode_alu alu
;
3728 int tmp
= r600_get_temp(&ctx
);
3729 assert(ctx
.face_gpr
!= -1);
3730 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3732 alu
.op
= ALU_OP2_LSHL_INT
;
3733 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3734 alu
.src
[0].value
= 0x1;
3735 alu
.src
[1].sel
= ctx
.fixed_pt_position_gpr
;
3736 alu
.src
[1].chan
= 3;
3741 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3744 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3745 alu
.op
= ALU_OP2_AND_INT
;
3746 alu
.src
[0].sel
= tmp
;
3747 alu
.src
[1].sel
= ctx
.face_gpr
;
3748 alu
.src
[1].chan
= 2;
3749 alu
.dst
.sel
= ctx
.face_gpr
;
3753 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3757 if (ctx
.fragcoord_input
>= 0) {
3758 if (ctx
.bc
->chip_class
== CAYMAN
) {
3759 for (j
= 0 ; j
< 4; j
++) {
3760 struct r600_bytecode_alu alu
;
3761 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3762 alu
.op
= ALU_OP1_RECIP_IEEE
;
3763 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3764 alu
.src
[0].chan
= 3;
3766 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3768 alu
.dst
.write
= (j
== 3);
3770 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3774 struct r600_bytecode_alu alu
;
3775 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3776 alu
.op
= ALU_OP1_RECIP_IEEE
;
3777 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3778 alu
.src
[0].chan
= 3;
3780 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3784 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3789 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3790 struct r600_bytecode_alu alu
;
3793 /* GS thread with no output workaround - emit a cut at start of GS */
3794 if (ctx
.bc
->chip_class
== R600
)
3795 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3797 for (j
= 0; j
< 4; j
++) {
3798 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3799 alu
.op
= ALU_OP1_MOV
;
3800 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3801 alu
.src
[0].value
= 0;
3802 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3805 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3810 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3811 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3812 ctx
.gs_rotated_input
[0], 2,
3814 V_SQ_ALU_SRC_LITERAL
, 1);
3818 for (i
= 0; i
< 6; i
++) {
3819 int rotated
= (i
+ 4) % 6;
3820 int offset_reg
= i
/ 3;
3821 int offset_chan
= i
% 3;
3822 int rotated_offset_reg
= rotated
/ 3;
3823 int rotated_offset_chan
= rotated
% 3;
3825 if (offset_reg
== 0 && offset_chan
== 2)
3827 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3828 rotated_offset_chan
= 3;
3830 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3831 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3832 ctx
.gs_rotated_input
[0], 2,
3833 offset_reg
, offset_chan
,
3834 rotated_offset_reg
, rotated_offset_chan
);
3841 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3842 r600_fetch_tess_io_info(&ctx
);
3844 if (shader
->two_side
&& ctx
.colors_used
) {
3845 if ((r
= process_twoside_color_inputs(&ctx
)))
3849 tgsi_parse_init(&ctx
.parse
, tokens
);
3850 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3851 tgsi_parse_token(&ctx
.parse
);
3852 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3853 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3854 r
= tgsi_is_supported(&ctx
);
3857 ctx
.max_driver_temp_used
= 0;
3858 /* reserve first tmp for everyone */
3859 r600_get_temp(&ctx
);
3861 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3862 if ((r
= tgsi_split_constant(&ctx
)))
3864 if ((r
= tgsi_split_literal_constant(&ctx
)))
3866 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3867 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3869 } else if (lds_inputs
) {
3870 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3873 if (ctx
.bc
->chip_class
== CAYMAN
)
3874 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3875 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3876 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3878 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3879 r
= ctx
.inst_info
->process(&ctx
);
3883 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3884 r
= r600_store_tcs_output(&ctx
);
3894 /* Reset the temporary register counter. */
3895 ctx
.max_driver_temp_used
= 0;
3897 noutput
= shader
->noutput
;
3899 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3900 unsigned clipdist_temp
[2];
3902 clipdist_temp
[0] = r600_get_temp(&ctx
);
3903 clipdist_temp
[1] = r600_get_temp(&ctx
);
3905 /* need to convert a clipvertex write into clipdistance writes and not export
3906 the clip vertex anymore */
3908 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3909 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3910 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3912 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3913 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3916 /* reset spi_sid for clipvertex output to avoid confusing spi */
3917 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3919 shader
->clip_dist_write
= 0xFF;
3920 shader
->cc_dist_mask
= 0xFF;
3922 for (i
= 0; i
< 8; i
++) {
3926 for (j
= 0; j
< 4; j
++) {
3927 struct r600_bytecode_alu alu
;
3928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3929 alu
.op
= ALU_OP2_DOT4
;
3930 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3931 alu
.src
[0].chan
= j
;
3933 alu
.src
[1].sel
= 512 + i
;
3934 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3935 alu
.src
[1].chan
= j
;
3937 alu
.dst
.sel
= clipdist_temp
[oreg
];
3939 alu
.dst
.write
= (j
== ochan
);
3942 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3949 /* Add stream outputs. */
3950 if (so
.num_outputs
) {
3952 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3954 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3957 emit_streamout(&ctx
, &so
, -1, NULL
);
3959 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3960 convert_edgeflag_to_int(&ctx
);
3962 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3963 r600_emit_tess_factor(&ctx
);
3966 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3967 if (ctx
.shader
->noutput
)
3968 emit_lds_vs_writes(&ctx
);
3970 } else if (ring_outputs
) {
3971 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3972 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3973 ctx
.gs_export_gpr_tregs
[1] = -1;
3974 ctx
.gs_export_gpr_tregs
[2] = -1;
3975 ctx
.gs_export_gpr_tregs
[3] = -1;
3977 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3981 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3983 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3984 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3985 output
[j
].gpr
= shader
->output
[i
].gpr
;
3986 output
[j
].elem_size
= 3;
3987 output
[j
].swizzle_x
= 0;
3988 output
[j
].swizzle_y
= 1;
3989 output
[j
].swizzle_z
= 2;
3990 output
[j
].swizzle_w
= 3;
3991 output
[j
].burst_count
= 1;
3992 output
[j
].type
= 0xffffffff;
3993 output
[j
].op
= CF_OP_EXPORT
;
3995 case PIPE_SHADER_VERTEX
:
3996 case PIPE_SHADER_TESS_EVAL
:
3997 switch (shader
->output
[i
].name
) {
3998 case TGSI_SEMANTIC_POSITION
:
3999 output
[j
].array_base
= 60;
4000 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4004 case TGSI_SEMANTIC_PSIZE
:
4005 output
[j
].array_base
= 61;
4006 output
[j
].swizzle_y
= 7;
4007 output
[j
].swizzle_z
= 7;
4008 output
[j
].swizzle_w
= 7;
4009 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4012 case TGSI_SEMANTIC_EDGEFLAG
:
4013 output
[j
].array_base
= 61;
4014 output
[j
].swizzle_x
= 7;
4015 output
[j
].swizzle_y
= 0;
4016 output
[j
].swizzle_z
= 7;
4017 output
[j
].swizzle_w
= 7;
4018 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4021 case TGSI_SEMANTIC_LAYER
:
4022 /* spi_sid is 0 for outputs that are
4023 * not consumed by PS */
4024 if (shader
->output
[i
].spi_sid
) {
4025 output
[j
].array_base
= next_param_base
++;
4026 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4028 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
4030 output
[j
].array_base
= 61;
4031 output
[j
].swizzle_x
= 7;
4032 output
[j
].swizzle_y
= 7;
4033 output
[j
].swizzle_z
= 0;
4034 output
[j
].swizzle_w
= 7;
4035 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4038 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
4039 /* spi_sid is 0 for outputs that are
4040 * not consumed by PS */
4041 if (shader
->output
[i
].spi_sid
) {
4042 output
[j
].array_base
= next_param_base
++;
4043 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4045 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
4047 output
[j
].array_base
= 61;
4048 output
[j
].swizzle_x
= 7;
4049 output
[j
].swizzle_y
= 7;
4050 output
[j
].swizzle_z
= 7;
4051 output
[j
].swizzle_w
= 0;
4052 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4055 case TGSI_SEMANTIC_CLIPVERTEX
:
4058 case TGSI_SEMANTIC_CLIPDIST
:
4059 output
[j
].array_base
= next_clip_base
++;
4060 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4062 /* spi_sid is 0 for clipdistance outputs that were generated
4063 * for clipvertex - we don't need to pass them to PS */
4064 if (shader
->output
[i
].spi_sid
) {
4066 /* duplicate it as PARAM to pass to the pixel shader */
4067 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
4068 output
[j
].array_base
= next_param_base
++;
4069 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4072 case TGSI_SEMANTIC_FOG
:
4073 output
[j
].swizzle_y
= 4; /* 0 */
4074 output
[j
].swizzle_z
= 4; /* 0 */
4075 output
[j
].swizzle_w
= 5; /* 1 */
4077 case TGSI_SEMANTIC_PRIMID
:
4078 output
[j
].swizzle_x
= 2;
4079 output
[j
].swizzle_y
= 4; /* 0 */
4080 output
[j
].swizzle_z
= 4; /* 0 */
4081 output
[j
].swizzle_w
= 4; /* 0 */
4086 case PIPE_SHADER_FRAGMENT
:
4087 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
4088 /* never export more colors than the number of CBs */
4089 if (shader
->output
[i
].sid
>= max_color_exports
) {
4094 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
4095 output
[j
].array_base
= shader
->output
[i
].sid
;
4096 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4097 shader
->nr_ps_color_exports
++;
4098 shader
->ps_color_export_mask
|= (0xf << (shader
->output
[i
].sid
* 4));
4100 /* If the i-th target format is set, all previous target formats must
4101 * be non-zero to avoid hangs. - from radeonsi, seems to apply to eg as well.
4103 if (shader
->output
[i
].sid
> 0)
4104 for (unsigned x
= 0; x
< shader
->output
[i
].sid
; x
++)
4105 shader
->ps_color_export_mask
|= (1 << (x
*4));
4107 if (shader
->output
[i
].sid
> shader
->ps_export_highest
)
4108 shader
->ps_export_highest
= shader
->output
[i
].sid
;
4109 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
4110 for (k
= 1; k
< max_color_exports
; k
++) {
4112 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4113 output
[j
].gpr
= shader
->output
[i
].gpr
;
4114 output
[j
].elem_size
= 3;
4115 output
[j
].swizzle_x
= 0;
4116 output
[j
].swizzle_y
= 1;
4117 output
[j
].swizzle_z
= 2;
4118 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
4119 output
[j
].burst_count
= 1;
4120 output
[j
].array_base
= k
;
4121 output
[j
].op
= CF_OP_EXPORT
;
4122 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4123 shader
->nr_ps_color_exports
++;
4124 shader
->ps_color_export_mask
|= (0xf << (j
* 4));
4127 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
4128 output
[j
].array_base
= 61;
4129 output
[j
].swizzle_x
= 2;
4130 output
[j
].swizzle_y
= 7;
4131 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
4132 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4133 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
4134 output
[j
].array_base
= 61;
4135 output
[j
].swizzle_x
= 7;
4136 output
[j
].swizzle_y
= 1;
4137 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
4138 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4139 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
4140 output
[j
].array_base
= 61;
4141 output
[j
].swizzle_x
= 7;
4142 output
[j
].swizzle_y
= 7;
4143 output
[j
].swizzle_z
= 0;
4144 output
[j
].swizzle_w
= 7;
4145 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4147 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
4152 case PIPE_SHADER_TESS_CTRL
:
4155 R600_ERR("unsupported processor type %d\n", ctx
.type
);
4160 if (output
[j
].type
== 0xffffffff) {
4161 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4162 output
[j
].array_base
= next_param_base
++;
4166 /* add fake position export */
4167 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
4168 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4170 output
[j
].elem_size
= 3;
4171 output
[j
].swizzle_x
= 7;
4172 output
[j
].swizzle_y
= 7;
4173 output
[j
].swizzle_z
= 7;
4174 output
[j
].swizzle_w
= 7;
4175 output
[j
].burst_count
= 1;
4176 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
4177 output
[j
].array_base
= 60;
4178 output
[j
].op
= CF_OP_EXPORT
;
4182 /* add fake param output for vertex shader if no param is exported */
4183 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
4184 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4186 output
[j
].elem_size
= 3;
4187 output
[j
].swizzle_x
= 7;
4188 output
[j
].swizzle_y
= 7;
4189 output
[j
].swizzle_z
= 7;
4190 output
[j
].swizzle_w
= 7;
4191 output
[j
].burst_count
= 1;
4192 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
4193 output
[j
].array_base
= 0;
4194 output
[j
].op
= CF_OP_EXPORT
;
4198 /* add fake pixel export */
4199 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
4200 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
4202 output
[j
].elem_size
= 3;
4203 output
[j
].swizzle_x
= 7;
4204 output
[j
].swizzle_y
= 7;
4205 output
[j
].swizzle_z
= 7;
4206 output
[j
].swizzle_w
= 7;
4207 output
[j
].burst_count
= 1;
4208 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
4209 output
[j
].array_base
= 0;
4210 output
[j
].op
= CF_OP_EXPORT
;
4212 shader
->nr_ps_color_exports
++;
4213 shader
->ps_color_export_mask
= 0xf;
4218 /* set export done on last export of each type */
4219 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
4220 if (!(output_done
& (1 << output
[k
].type
))) {
4221 output_done
|= (1 << output
[k
].type
);
4222 output
[k
].op
= CF_OP_EXPORT_DONE
;
4225 /* add output to bytecode */
4226 for (i
= 0; i
< noutput
; i
++) {
4227 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
4233 /* add program end */
4234 if (ctx
.bc
->chip_class
== CAYMAN
)
4235 cm_bytecode_add_cf_end(ctx
.bc
);
4237 const struct cf_op_info
*last
= NULL
;
4239 if (ctx
.bc
->cf_last
)
4240 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
4242 /* alu clause instructions don't have EOP bit, so add NOP */
4243 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
4244 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
4246 ctx
.bc
->cf_last
->end_of_program
= 1;
4249 /* check GPR limit - we have 124 = 128 - 4
4250 * (4 are reserved as alu clause temporary registers) */
4251 if (ctx
.bc
->ngpr
> 124) {
4252 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
4257 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
4258 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
4262 free(ctx
.spilled_arrays
);
4263 free(ctx
.array_infos
);
4265 tgsi_parse_free(&ctx
.parse
);
4268 free(ctx
.spilled_arrays
);
4269 free(ctx
.array_infos
);
4271 tgsi_parse_free(&ctx
.parse
);
4275 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
4277 const unsigned tgsi_opcode
=
4278 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
4279 R600_ERR("%s tgsi opcode unsupported\n",
4280 tgsi_get_opcode_name(tgsi_opcode
));
4284 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
4289 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
4290 const struct r600_shader_src
*shader_src
,
4293 bc_src
->sel
= shader_src
->sel
;
4294 bc_src
->chan
= shader_src
->swizzle
[chan
];
4295 bc_src
->neg
= shader_src
->neg
;
4296 bc_src
->abs
= shader_src
->abs
;
4297 bc_src
->rel
= shader_src
->rel
;
4298 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
4299 bc_src
->kc_bank
= shader_src
->kc_bank
;
4300 bc_src
->kc_rel
= shader_src
->kc_rel
;
4303 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
4309 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
4311 bc_src
->neg
= !bc_src
->neg
;
4314 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
4315 const struct tgsi_full_dst_register
*tgsi_dst
,
4317 struct r600_bytecode_alu_dst
*r600_dst
)
4319 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4321 if (tgsi_dst
->Register
.File
== TGSI_FILE_TEMPORARY
) {
4325 idx
= map_tgsi_reg_index_to_r600_gpr(ctx
, tgsi_dst
->Register
.Index
, &spilled
);
4328 struct r600_bytecode_output cf
;
4329 int reg
= r600_get_temp(ctx
);
4332 r600_dst
->sel
= reg
;
4333 r600_dst
->chan
= swizzle
;
4334 r600_dst
->write
= 1;
4335 if (inst
->Instruction
.Saturate
) {
4336 r600_dst
->clamp
= 1;
4339 // needs to be added after op using tgsi_dst
4340 memset(&cf
, 0, sizeof(struct r600_bytecode_output
));
4341 cf
.op
= CF_OP_MEM_SCRATCH
;
4344 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
4346 cf
.comp_mask
= inst
->Dst
[0].Register
.WriteMask
;
4353 get_spilled_array_base_and_size(ctx
, tgsi_dst
->Register
.Index
,
4354 &cf
.array_base
, &cf
.array_size
);
4356 if (tgsi_dst
->Register
.Indirect
) {
4357 if (ctx
->bc
->chip_class
< R700
)
4358 cf
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
4360 cf
.type
= 3; // V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND_ACK;
4361 cf
.index_gpr
= ctx
->bc
->ar_reg
;
4364 cf
.array_base
+= idx
;
4368 r
= r600_bytecode_add_pending_output(ctx
->bc
, &cf
);
4372 if (ctx
->bc
->chip_class
>= R700
)
4373 r600_bytecode_need_wait_ack(ctx
->bc
, true);
4378 r600_dst
->sel
= idx
;
4382 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
4383 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
4385 r600_dst
->chan
= swizzle
;
4386 r600_dst
->write
= 1;
4387 if (inst
->Instruction
.Saturate
) {
4388 r600_dst
->clamp
= 1;
4390 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
4391 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
4395 if (tgsi_dst
->Register
.Indirect
)
4396 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
4400 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
4402 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4403 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4404 struct r600_bytecode_alu alu
;
4405 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4407 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
4410 switch (write_mask
) {
4412 if (swizzle_x
== 2) {
4419 if (swizzle_x
== 2) {
4428 if (swizzle_x
== 0) {
4435 if (swizzle_x
== 0) {
4446 lasti
= tgsi_last_instruction(write_mask
);
4447 for (i
= 0; i
<= lasti
; i
++) {
4449 if (!(write_mask
& (1 << i
)))
4452 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4455 if (use_tmp
|| dest_temp
) {
4456 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
4460 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4462 if (i
== 1 || i
== 3)
4465 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4467 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4468 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4469 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4471 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4472 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4475 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4476 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4479 /* handle some special cases */
4480 if (i
== 1 || i
== 3) {
4481 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4482 case TGSI_OPCODE_DABS
:
4483 r600_bytecode_src_set_abs(&alu
.src
[0]);
4492 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4498 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4500 lasti
= tgsi_last_instruction(write_mask
);
4501 /* move result from temp to dst */
4502 for (i
= 0; i
<= lasti
; i
++) {
4503 if (!(write_mask
& (1 << i
)))
4506 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4507 alu
.op
= ALU_OP1_MOV
;
4510 alu
.dst
.sel
= dest_temp
;
4514 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4515 alu
.src
[0].sel
= ctx
->temp_reg
;
4516 alu
.src
[0].chan
= use_tmp
- 1;
4517 alu
.last
= (i
== lasti
);
4519 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4527 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4529 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4530 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4531 /* confirm writemasking */
4532 if ((write_mask
& 0x3) != 0x3 &&
4533 (write_mask
& 0xc) != 0xc) {
4534 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4537 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4540 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4542 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4545 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4547 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4550 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4552 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4553 struct r600_bytecode_alu alu
;
4556 int tmp
= r600_get_temp(ctx
);
4558 for (i
= 0; i
< lasti
+ 1; i
++) {
4560 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4561 alu
.op
= ctx
->inst_info
->op
;
4562 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4563 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4566 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4567 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4576 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4583 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4585 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4586 struct r600_bytecode_alu alu
;
4587 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4588 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4589 /* use temp register if trans_only and more than one dst component */
4590 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4591 unsigned op
= ctx
->inst_info
->op
;
4593 if (op
== ALU_OP2_MUL_IEEE
&&
4594 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4597 for (i
= 0; i
<= lasti
; i
++) {
4598 if (!(write_mask
& (1 << i
)))
4601 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4603 alu
.dst
.sel
= ctx
->temp_reg
;
4607 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4611 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4612 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4615 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4616 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4618 if (i
== lasti
|| trans_only
) {
4621 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4627 /* move result from temp to dst */
4628 for (i
= 0; i
<= lasti
; i
++) {
4629 if (!(write_mask
& (1 << i
)))
4632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4633 alu
.op
= ALU_OP1_MOV
;
4634 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4635 alu
.src
[0].sel
= ctx
->temp_reg
;
4636 alu
.src
[0].chan
= i
;
4637 alu
.last
= (i
== lasti
);
4639 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4647 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4649 return tgsi_op2_s(ctx
, 0, 0);
4652 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4654 return tgsi_op2_s(ctx
, 1, 0);
4657 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4659 return tgsi_op2_s(ctx
, 0, 1);
4662 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4664 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4665 struct r600_bytecode_alu alu
;
4667 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4669 for (i
= 0; i
< lasti
+ 1; i
++) {
4671 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4673 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4674 alu
.op
= ctx
->inst_info
->op
;
4676 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4678 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4680 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4685 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4693 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4695 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4696 struct r600_bytecode_alu alu
;
4698 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4700 for (i
= 0; i
< lasti
+ 1; i
++) {
4702 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4704 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4705 alu
.op
= ALU_OP1_MOV
;
4707 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4709 if (i
== 1 || i
== 3)
4710 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4711 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4716 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4724 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4726 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4727 struct r600_bytecode_alu alu
;
4728 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4731 for (i
= 0; i
<= 3; i
++) {
4732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4733 alu
.op
= ctx
->inst_info
->op
;
4735 alu
.dst
.sel
= ctx
->temp_reg
;
4738 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4739 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4745 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4750 /* Replicate significand result across channels. */
4751 for (i
= 0; i
<= 3; i
++) {
4752 if (!(write_mask
& (1 << i
)))
4755 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4756 alu
.op
= ALU_OP1_MOV
;
4757 alu
.src
[0].chan
= (i
& 1) + 2;
4758 alu
.src
[0].sel
= ctx
->temp_reg
;
4760 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4763 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4768 for (i
= 0; i
<= 3; i
++) {
4769 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4770 /* MOV third channels to writemask dst1 */
4771 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4772 alu
.op
= ALU_OP1_MOV
;
4773 alu
.src
[0].chan
= 1;
4774 alu
.src
[0].sel
= ctx
->temp_reg
;
4776 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4778 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4788 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4790 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4791 struct r600_bytecode_alu alu
;
4793 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4794 int temp_reg
= r600_get_temp(ctx
);
4796 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4797 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4799 for (c
= 0; c
< 2; c
++) {
4801 if (write_mask
& (0x3 << dchan
)) {
4802 /* split into 24-bit int and 8-bit int */
4803 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4804 alu
.op
= ALU_OP2_AND_INT
;
4805 alu
.dst
.sel
= temp_reg
;
4806 alu
.dst
.chan
= dchan
;
4807 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4808 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4809 alu
.src
[1].value
= 0xffffff00;
4811 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4815 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4816 alu
.op
= ALU_OP2_AND_INT
;
4817 alu
.dst
.sel
= temp_reg
;
4818 alu
.dst
.chan
= dchan
+ 1;
4819 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], c
);
4820 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4821 alu
.src
[1].value
= 0xff;
4824 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4830 for (c
= 0; c
< 2; c
++) {
4832 if (write_mask
& (0x3 << dchan
)) {
4833 for (i
= dchan
; i
<= dchan
+ 1; i
++) {
4834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4835 alu
.op
= i
== dchan
? ctx
->inst_info
->op
: ALU_OP1_UINT_TO_FLT
;
4837 alu
.src
[0].sel
= temp_reg
;
4838 alu
.src
[0].chan
= i
;
4839 alu
.dst
.sel
= temp_reg
;
4842 if (ctx
->bc
->chip_class
== CAYMAN
)
4843 alu
.last
= i
== dchan
+ 1;
4845 alu
.last
= 1; /* trans only ops on evergreen */
4847 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4854 for (c
= 0; c
< 2; c
++) {
4856 if (write_mask
& (0x3 << dchan
)) {
4857 for (i
= 0; i
< 4; i
++) {
4858 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4859 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4861 alu
.src
[0].chan
= dchan
+ (i
/ 2);
4862 if (i
== 0 || i
== 2)
4863 alu
.src
[0].sel
= temp_reg
;
4865 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4866 alu
.src
[0].value
= 0x0;
4868 alu
.dst
.sel
= ctx
->temp_reg
;
4873 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4878 for (i
= 0; i
<= 1; i
++) {
4879 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4880 alu
.op
= ALU_OP2_ADD_64
;
4882 alu
.src
[0].chan
= fp64_switch(i
);
4883 alu
.src
[0].sel
= ctx
->temp_reg
;
4885 alu
.src
[1].chan
= fp64_switch(i
+ 2);
4886 alu
.src
[1].sel
= ctx
->temp_reg
;
4887 tgsi_dst(ctx
, &inst
->Dst
[0], dchan
+ i
, &alu
.dst
);
4890 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4900 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4902 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4903 struct r600_bytecode_alu alu
;
4905 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4906 int treg
= r600_get_temp(ctx
);
4907 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4908 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4910 /* do a 64->32 into a temp register */
4911 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4915 for (i
= 0; i
<= lasti
; i
++) {
4916 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4919 alu
.op
= ctx
->inst_info
->op
;
4921 alu
.src
[0].chan
= i
;
4922 alu
.src
[0].sel
= treg
;
4923 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4924 alu
.last
= (i
== lasti
);
4926 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4934 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4937 struct r600_shader_src
*src
,
4940 struct r600_bytecode_alu alu
;
4941 const int last_slot
= 3;
4944 /* these have to write the result to X/Y by the looks of it */
4945 for (int i
= 0 ; i
< last_slot
; i
++) {
4946 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4949 r600_bytecode_src(&alu
.src
[0], src
, 1);
4950 r600_bytecode_src(&alu
.src
[1], src
, 0);
4953 r600_bytecode_src_set_abs(&alu
.src
[1]);
4955 alu
.dst
.sel
= dst_reg
;
4957 alu
.dst
.write
= (i
== 0 || i
== 1);
4959 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4961 r
= r600_bytecode_add_alu(bc
, &alu
);
4969 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4971 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4973 struct r600_bytecode_alu alu
;
4974 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4975 int t1
= ctx
->temp_reg
;
4977 /* should only be one src regs */
4978 assert(inst
->Instruction
.NumSrcRegs
== 1);
4980 /* only support one double at a time */
4981 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4982 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4984 r
= cayman_emit_unary_double_raw(
4985 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4987 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4988 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4992 for (i
= 0 ; i
<= lasti
; i
++) {
4993 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4996 alu
.op
= ALU_OP1_MOV
;
4997 alu
.src
[0].sel
= t1
;
4998 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4999 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5003 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5010 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
5012 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;
5017 for (i
= 0 ; i
< last_slot
; i
++) {
5018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5019 alu
.op
= ctx
->inst_info
->op
;
5020 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5021 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
5023 /* RSQ should take the absolute value of src */
5024 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
5025 r600_bytecode_src_set_abs(&alu
.src
[j
]);
5028 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5029 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5031 if (i
== last_slot
- 1)
5033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5040 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
5042 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5044 struct r600_bytecode_alu alu
;
5045 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5046 int t1
= ctx
->temp_reg
;
5048 for (k
= 0; k
<= lasti
; k
++) {
5049 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
5052 for (i
= 0 ; i
< 4; i
++) {
5053 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5054 alu
.op
= ctx
->inst_info
->op
;
5055 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5056 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
5060 alu
.dst
.write
= (i
== k
);
5063 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5069 for (i
= 0 ; i
<= lasti
; i
++) {
5070 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5072 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5073 alu
.op
= ALU_OP1_MOV
;
5074 alu
.src
[0].sel
= t1
;
5075 alu
.src
[0].chan
= i
;
5076 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5080 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5089 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
5091 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5093 struct r600_bytecode_alu alu
;
5094 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5095 int t1
= ctx
->temp_reg
;
5097 /* t1 would get overwritten below if we actually tried to
5098 * multiply two pairs of doubles at a time. */
5099 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
5100 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
5102 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
5104 for (i
= 0; i
< 4; i
++) {
5105 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5106 alu
.op
= ctx
->inst_info
->op
;
5107 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
5108 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
5115 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5120 for (i
= 0; i
<= lasti
; i
++) {
5121 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5123 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5124 alu
.op
= ALU_OP1_MOV
;
5125 alu
.src
[0].sel
= t1
;
5126 alu
.src
[0].chan
= i
;
5127 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5131 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5140 * Emit RECIP_64 + MUL_64 to implement division.
5142 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
5144 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5146 struct r600_bytecode_alu alu
;
5147 int t1
= ctx
->temp_reg
;
5150 /* Only support one double at a time. This is the same constraint as
5151 * in DMUL lowering. */
5152 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
5153 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
5155 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
5157 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
5161 for (int i
= 0; i
< 4; i
++) {
5162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5163 alu
.op
= ALU_OP2_MUL_64
;
5165 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
5167 alu
.src
[1].sel
= t1
;
5168 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
5175 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5180 for (int i
= 0; i
< 2; i
++) {
5181 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5182 alu
.op
= ALU_OP1_MOV
;
5183 alu
.src
[0].sel
= t1
;
5184 alu
.src
[0].chan
= i
;
5185 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
5189 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5197 * r600 - trunc to -PI..PI range
5198 * r700 - normalize by dividing by 2PI
5201 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
5204 struct r600_bytecode_alu alu
;
5206 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5207 alu
.op
= ALU_OP3_MULADD
;
5211 alu
.dst
.sel
= ctx
->temp_reg
;
5214 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5216 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5217 alu
.src
[1].chan
= 0;
5218 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
5219 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
5220 alu
.src
[2].chan
= 0;
5222 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5226 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5227 alu
.op
= ALU_OP1_FRACT
;
5230 alu
.dst
.sel
= ctx
->temp_reg
;
5233 alu
.src
[0].sel
= ctx
->temp_reg
;
5234 alu
.src
[0].chan
= 0;
5236 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5240 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5241 alu
.op
= ALU_OP3_MULADD
;
5245 alu
.dst
.sel
= ctx
->temp_reg
;
5248 alu
.src
[0].sel
= ctx
->temp_reg
;
5249 alu
.src
[0].chan
= 0;
5251 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5252 alu
.src
[1].chan
= 0;
5253 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
5254 alu
.src
[2].chan
= 0;
5256 if (ctx
->bc
->chip_class
== R600
) {
5257 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
5258 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
5260 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5261 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
5266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5272 static int cayman_trig(struct r600_shader_ctx
*ctx
)
5274 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5275 struct r600_bytecode_alu alu
;
5276 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5279 r
= tgsi_setup_trig(ctx
);
5284 for (i
= 0; i
< last_slot
; i
++) {
5285 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5286 alu
.op
= ctx
->inst_info
->op
;
5289 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5290 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5292 alu
.src
[0].sel
= ctx
->temp_reg
;
5293 alu
.src
[0].chan
= 0;
5294 if (i
== last_slot
- 1)
5296 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5303 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
5305 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5306 struct r600_bytecode_alu alu
;
5308 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
5310 r
= tgsi_setup_trig(ctx
);
5314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5315 alu
.op
= ctx
->inst_info
->op
;
5317 alu
.dst
.sel
= ctx
->temp_reg
;
5320 alu
.src
[0].sel
= ctx
->temp_reg
;
5321 alu
.src
[0].chan
= 0;
5323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5327 /* replicate result */
5328 for (i
= 0; i
< lasti
+ 1; i
++) {
5329 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
5332 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5333 alu
.op
= ALU_OP1_MOV
;
5335 alu
.src
[0].sel
= ctx
->temp_reg
;
5336 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5339 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5346 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
5348 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5349 struct r600_bytecode_alu alu
;
5352 for (i
= 0; i
< 4; i
++) {
5353 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5354 alu
.op
= ctx
->inst_info
->op
;
5358 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5360 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
5361 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
5364 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5369 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5374 /* kill must be last in ALU */
5375 ctx
->bc
->force_add_cf
= 1;
5376 ctx
->shader
->uses_kill
= TRUE
;
5380 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
5382 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5383 struct r600_bytecode_alu alu
;
5386 /* tmp.x = max(src.y, 0.0) */
5387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5388 alu
.op
= ALU_OP2_MAX
;
5389 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
5390 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5391 alu
.src
[1].chan
= 1;
5393 alu
.dst
.sel
= ctx
->temp_reg
;
5398 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5402 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
5408 if (ctx
->bc
->chip_class
== CAYMAN
) {
5409 for (i
= 0; i
< 3; i
++) {
5410 /* tmp.z = log(tmp.x) */
5411 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5412 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5413 alu
.src
[0].sel
= ctx
->temp_reg
;
5414 alu
.src
[0].chan
= 0;
5415 alu
.dst
.sel
= ctx
->temp_reg
;
5423 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5428 /* tmp.z = log(tmp.x) */
5429 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5430 alu
.op
= ALU_OP1_LOG_CLAMPED
;
5431 alu
.src
[0].sel
= ctx
->temp_reg
;
5432 alu
.src
[0].chan
= 0;
5433 alu
.dst
.sel
= ctx
->temp_reg
;
5437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5442 chan
= alu
.dst
.chan
;
5445 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
5446 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5447 alu
.op
= ALU_OP3_MUL_LIT
;
5448 alu
.src
[0].sel
= sel
;
5449 alu
.src
[0].chan
= chan
;
5450 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
5451 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
5452 alu
.dst
.sel
= ctx
->temp_reg
;
5457 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5461 if (ctx
->bc
->chip_class
== CAYMAN
) {
5462 for (i
= 0; i
< 3; i
++) {
5463 /* dst.z = exp(tmp.x) */
5464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5465 alu
.op
= ALU_OP1_EXP_IEEE
;
5466 alu
.src
[0].sel
= ctx
->temp_reg
;
5467 alu
.src
[0].chan
= 0;
5468 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5474 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5479 /* dst.z = exp(tmp.x) */
5480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5481 alu
.op
= ALU_OP1_EXP_IEEE
;
5482 alu
.src
[0].sel
= ctx
->temp_reg
;
5483 alu
.src
[0].chan
= 0;
5484 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
5486 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5494 alu
.op
= ALU_OP1_MOV
;
5495 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
5496 alu
.src
[0].chan
= 0;
5497 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
5498 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
5499 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5503 /* dst.y = max(src.x, 0.0) */
5504 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5505 alu
.op
= ALU_OP2_MAX
;
5506 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5507 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
5508 alu
.src
[1].chan
= 0;
5509 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
5510 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
5511 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5516 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5517 alu
.op
= ALU_OP1_MOV
;
5518 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
5519 alu
.src
[0].chan
= 0;
5520 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
5521 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
5523 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5530 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5532 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5533 struct r600_bytecode_alu alu
;
5536 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5538 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5540 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5541 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5542 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5544 alu
.dst
.sel
= ctx
->temp_reg
;
5547 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5550 /* replicate result */
5551 return tgsi_helper_tempx_replicate(ctx
);
5554 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5556 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5557 struct r600_bytecode_alu alu
;
5560 for (i
= 0; i
< 4; i
++) {
5561 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5562 alu
.src
[0].sel
= ctx
->temp_reg
;
5563 alu
.op
= ALU_OP1_MOV
;
5565 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5566 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5569 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5576 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5578 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5579 struct r600_bytecode_alu alu
;
5582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5583 alu
.op
= ctx
->inst_info
->op
;
5584 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5585 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5587 alu
.dst
.sel
= ctx
->temp_reg
;
5590 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5593 /* replicate result */
5594 return tgsi_helper_tempx_replicate(ctx
);
5597 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5599 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5601 struct r600_bytecode_alu alu
;
5602 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5604 for (i
= 0; i
< 3; i
++) {
5605 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5606 alu
.op
= ALU_OP1_LOG_IEEE
;
5607 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5608 alu
.dst
.sel
= ctx
->temp_reg
;
5613 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5619 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5620 alu
.op
= ALU_OP2_MUL
;
5621 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5622 alu
.src
[1].sel
= ctx
->temp_reg
;
5623 alu
.dst
.sel
= ctx
->temp_reg
;
5626 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5630 for (i
= 0; i
< last_slot
; i
++) {
5631 /* POW(a,b) = EXP2(b * LOG2(a))*/
5632 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5633 alu
.op
= ALU_OP1_EXP_IEEE
;
5634 alu
.src
[0].sel
= ctx
->temp_reg
;
5636 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5637 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5638 if (i
== last_slot
- 1)
5640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5647 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5649 struct r600_bytecode_alu alu
;
5653 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5654 alu
.op
= ALU_OP1_LOG_IEEE
;
5655 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5656 alu
.dst
.sel
= ctx
->temp_reg
;
5659 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5663 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5664 alu
.op
= ALU_OP2_MUL
;
5665 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5666 alu
.src
[1].sel
= ctx
->temp_reg
;
5667 alu
.dst
.sel
= ctx
->temp_reg
;
5670 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5673 /* POW(a,b) = EXP2(b * LOG2(a))*/
5674 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5675 alu
.op
= ALU_OP1_EXP_IEEE
;
5676 alu
.src
[0].sel
= ctx
->temp_reg
;
5677 alu
.dst
.sel
= ctx
->temp_reg
;
5680 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5683 return tgsi_helper_tempx_replicate(ctx
);
5686 static int emit_mul_int_op(struct r600_bytecode
*bc
,
5687 struct r600_bytecode_alu
*alu_src
)
5689 struct r600_bytecode_alu alu
;
5692 if (bc
->chip_class
== CAYMAN
) {
5693 for (i
= 0; i
< 4; i
++) {
5695 alu
.dst
.write
= (i
== alu_src
->dst
.chan
);
5696 alu
.last
= (i
== 3);
5698 r
= r600_bytecode_add_alu(bc
, &alu
);
5704 r
= r600_bytecode_add_alu(bc
, &alu
);
5711 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5713 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5714 struct r600_bytecode_alu alu
;
5716 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5717 int tmp0
= ctx
->temp_reg
;
5718 int tmp1
= r600_get_temp(ctx
);
5719 int tmp2
= r600_get_temp(ctx
);
5720 int tmp3
= r600_get_temp(ctx
);
5723 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5725 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5726 * 2. tmp0.z = lo (tmp0.x * src2)
5727 * 3. tmp0.w = -tmp0.z
5728 * 4. tmp0.y = hi (tmp0.x * src2)
5729 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5730 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5731 * 7. tmp1.x = tmp0.x - tmp0.w
5732 * 8. tmp1.y = tmp0.x + tmp0.w
5733 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5734 * 10. tmp0.z = hi(tmp0.x * src1) = q
5735 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5737 * 12. tmp0.w = src1 - tmp0.y = r
5738 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5739 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5743 * 15. tmp1.z = tmp0.z + 1 = q + 1
5744 * 16. tmp1.w = tmp0.z - 1 = q - 1
5748 * 15. tmp1.z = tmp0.w - src2 = r - src2
5749 * 16. tmp1.w = tmp0.w + src2 = r + src2
5753 * 17. tmp1.x = tmp1.x & tmp1.y
5755 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5756 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5758 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5759 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5763 * Same as unsigned, using abs values of the operands,
5764 * and fixing the sign of the result in the end.
5767 for (i
= 0; i
< 4; i
++) {
5768 if (!(write_mask
& (1<<i
)))
5773 /* tmp2.x = -src0 */
5774 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5775 alu
.op
= ALU_OP2_SUB_INT
;
5781 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5783 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5786 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5789 /* tmp2.y = -src1 */
5790 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5791 alu
.op
= ALU_OP2_SUB_INT
;
5797 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5799 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5802 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5805 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5806 /* it will be a sign of the quotient */
5809 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5810 alu
.op
= ALU_OP2_XOR_INT
;
5816 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5817 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5820 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5824 /* tmp2.x = |src0| */
5825 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5826 alu
.op
= ALU_OP3_CNDGE_INT
;
5833 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5834 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5835 alu
.src
[2].sel
= tmp2
;
5836 alu
.src
[2].chan
= 0;
5839 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5842 /* tmp2.y = |src1| */
5843 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5844 alu
.op
= ALU_OP3_CNDGE_INT
;
5851 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5852 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5853 alu
.src
[2].sel
= tmp2
;
5854 alu
.src
[2].chan
= 1;
5857 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5862 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5863 if (ctx
->bc
->chip_class
== CAYMAN
) {
5864 /* tmp3.x = u2f(src2) */
5865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5866 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5873 alu
.src
[0].sel
= tmp2
;
5874 alu
.src
[0].chan
= 1;
5876 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5880 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5883 /* tmp0.x = recip(tmp3.x) */
5884 for (j
= 0 ; j
< 3; j
++) {
5885 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5886 alu
.op
= ALU_OP1_RECIP_IEEE
;
5890 alu
.dst
.write
= (j
== 0);
5892 alu
.src
[0].sel
= tmp3
;
5893 alu
.src
[0].chan
= 0;
5897 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5901 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5902 alu
.op
= ALU_OP2_MUL
;
5904 alu
.src
[0].sel
= tmp0
;
5905 alu
.src
[0].chan
= 0;
5907 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5908 alu
.src
[1].value
= 0x4f800000;
5913 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5917 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5918 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5924 alu
.src
[0].sel
= tmp3
;
5925 alu
.src
[0].chan
= 0;
5928 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5932 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5933 alu
.op
= ALU_OP1_RECIP_UINT
;
5940 alu
.src
[0].sel
= tmp2
;
5941 alu
.src
[0].chan
= 1;
5943 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5947 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5951 /* 2. tmp0.z = lo (tmp0.x * src2) */
5952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5953 alu
.op
= ALU_OP2_MULLO_UINT
;
5959 alu
.src
[0].sel
= tmp0
;
5960 alu
.src
[0].chan
= 0;
5962 alu
.src
[1].sel
= tmp2
;
5963 alu
.src
[1].chan
= 1;
5965 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5968 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
5971 /* 3. tmp0.w = -tmp0.z */
5972 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5973 alu
.op
= ALU_OP2_SUB_INT
;
5979 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5980 alu
.src
[1].sel
= tmp0
;
5981 alu
.src
[1].chan
= 2;
5984 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5987 /* 4. tmp0.y = hi (tmp0.x * src2) */
5988 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5989 alu
.op
= ALU_OP2_MULHI_UINT
;
5995 alu
.src
[0].sel
= tmp0
;
5996 alu
.src
[0].chan
= 0;
5999 alu
.src
[1].sel
= tmp2
;
6000 alu
.src
[1].chan
= 1;
6002 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6005 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6008 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
6009 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6010 alu
.op
= ALU_OP3_CNDE_INT
;
6017 alu
.src
[0].sel
= tmp0
;
6018 alu
.src
[0].chan
= 1;
6019 alu
.src
[1].sel
= tmp0
;
6020 alu
.src
[1].chan
= 3;
6021 alu
.src
[2].sel
= tmp0
;
6022 alu
.src
[2].chan
= 2;
6025 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6028 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
6029 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6030 alu
.op
= ALU_OP2_MULHI_UINT
;
6036 alu
.src
[0].sel
= tmp0
;
6037 alu
.src
[0].chan
= 2;
6039 alu
.src
[1].sel
= tmp0
;
6040 alu
.src
[1].chan
= 0;
6042 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6045 /* 7. tmp1.x = tmp0.x - tmp0.w */
6046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6047 alu
.op
= ALU_OP2_SUB_INT
;
6053 alu
.src
[0].sel
= tmp0
;
6054 alu
.src
[0].chan
= 0;
6055 alu
.src
[1].sel
= tmp0
;
6056 alu
.src
[1].chan
= 3;
6059 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6062 /* 8. tmp1.y = tmp0.x + tmp0.w */
6063 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6064 alu
.op
= ALU_OP2_ADD_INT
;
6070 alu
.src
[0].sel
= tmp0
;
6071 alu
.src
[0].chan
= 0;
6072 alu
.src
[1].sel
= tmp0
;
6073 alu
.src
[1].chan
= 3;
6076 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6079 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
6080 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6081 alu
.op
= ALU_OP3_CNDE_INT
;
6088 alu
.src
[0].sel
= tmp0
;
6089 alu
.src
[0].chan
= 1;
6090 alu
.src
[1].sel
= tmp1
;
6091 alu
.src
[1].chan
= 1;
6092 alu
.src
[2].sel
= tmp1
;
6093 alu
.src
[2].chan
= 0;
6096 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6099 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
6100 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6101 alu
.op
= ALU_OP2_MULHI_UINT
;
6107 alu
.src
[0].sel
= tmp0
;
6108 alu
.src
[0].chan
= 0;
6111 alu
.src
[1].sel
= tmp2
;
6112 alu
.src
[1].chan
= 0;
6114 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6117 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6120 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
6121 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6122 alu
.op
= ALU_OP2_MULLO_UINT
;
6129 alu
.src
[0].sel
= tmp2
;
6130 alu
.src
[0].chan
= 1;
6132 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6135 alu
.src
[1].sel
= tmp0
;
6136 alu
.src
[1].chan
= 2;
6138 if ((r
= emit_mul_int_op(ctx
->bc
, &alu
)))
6141 /* 12. tmp0.w = src1 - tmp0.y = r */
6142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6143 alu
.op
= ALU_OP2_SUB_INT
;
6150 alu
.src
[0].sel
= tmp2
;
6151 alu
.src
[0].chan
= 0;
6153 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6156 alu
.src
[1].sel
= tmp0
;
6157 alu
.src
[1].chan
= 1;
6160 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6163 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
6164 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6165 alu
.op
= ALU_OP2_SETGE_UINT
;
6171 alu
.src
[0].sel
= tmp0
;
6172 alu
.src
[0].chan
= 3;
6174 alu
.src
[1].sel
= tmp2
;
6175 alu
.src
[1].chan
= 1;
6177 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6181 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6184 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
6185 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6186 alu
.op
= ALU_OP2_SETGE_UINT
;
6193 alu
.src
[0].sel
= tmp2
;
6194 alu
.src
[0].chan
= 0;
6196 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6199 alu
.src
[1].sel
= tmp0
;
6200 alu
.src
[1].chan
= 1;
6203 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6206 if (mod
) { /* UMOD */
6208 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
6209 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6210 alu
.op
= ALU_OP2_SUB_INT
;
6216 alu
.src
[0].sel
= tmp0
;
6217 alu
.src
[0].chan
= 3;
6220 alu
.src
[1].sel
= tmp2
;
6221 alu
.src
[1].chan
= 1;
6223 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6227 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6230 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
6231 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6232 alu
.op
= ALU_OP2_ADD_INT
;
6238 alu
.src
[0].sel
= tmp0
;
6239 alu
.src
[0].chan
= 3;
6241 alu
.src
[1].sel
= tmp2
;
6242 alu
.src
[1].chan
= 1;
6244 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
6248 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6253 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
6254 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6255 alu
.op
= ALU_OP2_ADD_INT
;
6261 alu
.src
[0].sel
= tmp0
;
6262 alu
.src
[0].chan
= 2;
6263 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6266 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6269 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
6270 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6271 alu
.op
= ALU_OP2_ADD_INT
;
6277 alu
.src
[0].sel
= tmp0
;
6278 alu
.src
[0].chan
= 2;
6279 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
6282 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6287 /* 17. tmp1.x = tmp1.x & tmp1.y */
6288 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6289 alu
.op
= ALU_OP2_AND_INT
;
6295 alu
.src
[0].sel
= tmp1
;
6296 alu
.src
[0].chan
= 0;
6297 alu
.src
[1].sel
= tmp1
;
6298 alu
.src
[1].chan
= 1;
6301 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6304 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
6305 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
6306 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6307 alu
.op
= ALU_OP3_CNDE_INT
;
6314 alu
.src
[0].sel
= tmp1
;
6315 alu
.src
[0].chan
= 0;
6316 alu
.src
[1].sel
= tmp0
;
6317 alu
.src
[1].chan
= mod
? 3 : 2;
6318 alu
.src
[2].sel
= tmp1
;
6319 alu
.src
[2].chan
= 2;
6322 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6325 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
6326 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6327 alu
.op
= ALU_OP3_CNDE_INT
;
6335 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6338 alu
.src
[0].sel
= tmp1
;
6339 alu
.src
[0].chan
= 1;
6340 alu
.src
[1].sel
= tmp1
;
6341 alu
.src
[1].chan
= 3;
6342 alu
.src
[2].sel
= tmp0
;
6343 alu
.src
[2].chan
= 2;
6346 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6351 /* fix the sign of the result */
6355 /* tmp0.x = -tmp0.z */
6356 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6357 alu
.op
= ALU_OP2_SUB_INT
;
6363 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6364 alu
.src
[1].sel
= tmp0
;
6365 alu
.src
[1].chan
= 2;
6368 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6371 /* sign of the remainder is the same as the sign of src0 */
6372 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
6373 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6374 alu
.op
= ALU_OP3_CNDGE_INT
;
6377 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6379 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6380 alu
.src
[1].sel
= tmp0
;
6381 alu
.src
[1].chan
= 2;
6382 alu
.src
[2].sel
= tmp0
;
6383 alu
.src
[2].chan
= 0;
6386 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6391 /* tmp0.x = -tmp0.z */
6392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6393 alu
.op
= ALU_OP2_SUB_INT
;
6399 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6400 alu
.src
[1].sel
= tmp0
;
6401 alu
.src
[1].chan
= 2;
6404 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6407 /* fix the quotient sign (same as the sign of src0*src1) */
6408 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
6409 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6410 alu
.op
= ALU_OP3_CNDGE_INT
;
6413 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6415 alu
.src
[0].sel
= tmp2
;
6416 alu
.src
[0].chan
= 2;
6417 alu
.src
[1].sel
= tmp0
;
6418 alu
.src
[1].chan
= 2;
6419 alu
.src
[2].sel
= tmp0
;
6420 alu
.src
[2].chan
= 0;
6423 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
6431 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6433 return tgsi_divmod(ctx
, 0, 0);
6436 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6438 return tgsi_divmod(ctx
, 1, 0);
6441 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6443 return tgsi_divmod(ctx
, 0, 1);
6446 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6448 return tgsi_divmod(ctx
, 1, 1);
6452 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6454 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6455 struct r600_bytecode_alu alu
;
6457 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6458 int last_inst
= tgsi_last_instruction(write_mask
);
6460 for (i
= 0; i
< 4; i
++) {
6461 if (!(write_mask
& (1<<i
)))
6464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6465 alu
.op
= ALU_OP1_TRUNC
;
6467 alu
.dst
.sel
= ctx
->temp_reg
;
6471 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6474 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6479 for (i
= 0; i
< 4; i
++) {
6480 if (!(write_mask
& (1<<i
)))
6483 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6484 alu
.op
= ctx
->inst_info
->op
;
6486 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6488 alu
.src
[0].sel
= ctx
->temp_reg
;
6489 alu
.src
[0].chan
= i
;
6491 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6493 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6501 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6503 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6504 struct r600_bytecode_alu alu
;
6506 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6507 int last_inst
= tgsi_last_instruction(write_mask
);
6510 for (i
= 0; i
< 4; i
++) {
6511 if (!(write_mask
& (1<<i
)))
6514 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6515 alu
.op
= ALU_OP2_SUB_INT
;
6517 alu
.dst
.sel
= ctx
->temp_reg
;
6521 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6522 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6526 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6531 /* dst = (src >= 0 ? src : tmp) */
6532 for (i
= 0; i
< 4; i
++) {
6533 if (!(write_mask
& (1<<i
)))
6536 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6537 alu
.op
= ALU_OP3_CNDGE_INT
;
6541 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6543 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6544 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6545 alu
.src
[2].sel
= ctx
->temp_reg
;
6546 alu
.src
[2].chan
= i
;
6550 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6557 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6559 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6560 struct r600_bytecode_alu alu
;
6562 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6563 int last_inst
= tgsi_last_instruction(write_mask
);
6565 /* tmp = (src >= 0 ? src : -1) */
6566 for (i
= 0; i
< 4; i
++) {
6567 if (!(write_mask
& (1<<i
)))
6570 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6571 alu
.op
= ALU_OP3_CNDGE_INT
;
6574 alu
.dst
.sel
= ctx
->temp_reg
;
6578 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6579 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6580 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6584 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6589 /* dst = (tmp > 0 ? 1 : tmp) */
6590 for (i
= 0; i
< 4; i
++) {
6591 if (!(write_mask
& (1<<i
)))
6594 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6595 alu
.op
= ALU_OP3_CNDGT_INT
;
6599 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6601 alu
.src
[0].sel
= ctx
->temp_reg
;
6602 alu
.src
[0].chan
= i
;
6604 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6606 alu
.src
[2].sel
= ctx
->temp_reg
;
6607 alu
.src
[2].chan
= i
;
6611 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6620 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6622 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6623 struct r600_bytecode_alu alu
;
6626 /* tmp = (src > 0 ? 1 : src) */
6627 for (i
= 0; i
< 4; i
++) {
6628 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6629 alu
.op
= ALU_OP3_CNDGT
;
6632 alu
.dst
.sel
= ctx
->temp_reg
;
6635 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6636 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6637 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6641 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6646 /* dst = (-tmp > 0 ? -1 : tmp) */
6647 for (i
= 0; i
< 4; i
++) {
6648 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6649 alu
.op
= ALU_OP3_CNDGT
;
6651 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6653 alu
.src
[0].sel
= ctx
->temp_reg
;
6654 alu
.src
[0].chan
= i
;
6657 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6660 alu
.src
[2].sel
= ctx
->temp_reg
;
6661 alu
.src
[2].chan
= i
;
6665 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6672 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6674 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6675 struct r600_bytecode_alu alu
;
6678 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6679 int last_inst
= tgsi_last_instruction(write_mask
);
6681 t1
= r600_get_temp(ctx
);
6683 for (i
= 0; i
< 4; i
++) {
6684 if (!(write_mask
& (1<<i
)))
6687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6688 alu
.op
= ALU_OP2_SETGE_INT
;
6689 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6690 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6691 alu
.src
[1].value
= 32;
6692 alu
.dst
.sel
= ctx
->temp_reg
;
6695 alu
.last
= i
== last_inst
;
6696 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6701 for (i
= 0; i
< 4; i
++) {
6702 if (!(write_mask
& (1<<i
)))
6705 /* create mask tmp */
6706 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6707 alu
.op
= ALU_OP2_BFM_INT
;
6711 alu
.last
= i
== last_inst
;
6713 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6714 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6716 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6721 t2
= r600_get_temp(ctx
);
6723 for (i
= 0; i
< 4; i
++) {
6724 if (!(write_mask
& (1<<i
)))
6727 /* shift insert left */
6728 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6729 alu
.op
= ALU_OP2_LSHL_INT
;
6733 alu
.last
= i
== last_inst
;
6735 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6736 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6738 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6743 for (i
= 0; i
< 4; i
++) {
6744 if (!(write_mask
& (1<<i
)))
6747 /* actual bitfield insert */
6748 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6749 alu
.op
= ALU_OP3_BFI_INT
;
6751 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6754 alu
.last
= i
== last_inst
;
6756 alu
.src
[0].sel
= t1
;
6757 alu
.src
[0].chan
= i
;
6758 alu
.src
[1].sel
= t2
;
6759 alu
.src
[1].chan
= i
;
6760 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6762 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6767 for (i
= 0; i
< 4; i
++) {
6768 if (!(write_mask
& (1<<i
)))
6770 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6771 alu
.op
= ALU_OP3_CNDE_INT
;
6773 alu
.src
[0].sel
= ctx
->temp_reg
;
6774 alu
.src
[0].chan
= i
;
6775 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6777 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6779 alu
.src
[1].sel
= alu
.dst
.sel
;
6780 alu
.src
[1].chan
= i
;
6782 alu
.last
= i
== last_inst
;
6783 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6790 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6792 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6793 struct r600_bytecode_alu alu
;
6796 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6797 int last_inst
= tgsi_last_instruction(write_mask
);
6799 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6800 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6804 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6805 for (i
= 0; i
< 4; i
++) {
6806 if (!(write_mask
& (1<<i
)))
6809 /* t1 = FFBH_INT / FFBH_UINT */
6810 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6811 alu
.op
= ctx
->inst_info
->op
;
6815 alu
.last
= i
== last_inst
;
6817 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6819 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6824 t2
= r600_get_temp(ctx
);
6826 for (i
= 0; i
< 4; i
++) {
6827 if (!(write_mask
& (1<<i
)))
6831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6832 alu
.op
= ALU_OP2_SUB_INT
;
6836 alu
.last
= i
== last_inst
;
6838 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6839 alu
.src
[0].value
= 31;
6840 alu
.src
[1].sel
= t1
;
6841 alu
.src
[1].chan
= i
;
6843 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6848 for (i
= 0; i
< 4; i
++) {
6849 if (!(write_mask
& (1<<i
)))
6852 /* result = t1 >= 0 ? t2 : t1 */
6853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6854 alu
.op
= ALU_OP3_CNDGE_INT
;
6856 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6859 alu
.last
= i
== last_inst
;
6861 alu
.src
[0].sel
= t1
;
6862 alu
.src
[0].chan
= i
;
6863 alu
.src
[1].sel
= t2
;
6864 alu
.src
[1].chan
= i
;
6865 alu
.src
[2].sel
= t1
;
6866 alu
.src
[2].chan
= i
;
6868 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6876 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6878 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6879 struct r600_bytecode_alu alu
;
6880 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6882 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6884 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6886 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6887 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6888 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6889 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6892 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6895 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6898 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6899 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6901 /* NOTE: currently offset is not perspective correct */
6902 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6903 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6904 int sample_gpr
= -1;
6905 int gradientsH
, gradientsV
;
6906 struct r600_bytecode_tex tex
;
6908 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6909 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6912 gradientsH
= r600_get_temp(ctx
);
6913 gradientsV
= r600_get_temp(ctx
);
6914 for (i
= 0; i
< 2; i
++) {
6915 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6916 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6917 tex
.src_gpr
= interp_gpr
;
6918 tex
.src_sel_x
= interp_base_chan
+ 0;
6919 tex
.src_sel_y
= interp_base_chan
+ 1;
6922 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6927 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6929 tex
.resource_id
= tex
.sampler_id
;
6930 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6935 for (i
= 0; i
< 2; i
++) {
6936 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6937 alu
.op
= ALU_OP3_MULADD
;
6939 alu
.src
[0].sel
= gradientsH
;
6940 alu
.src
[0].chan
= i
;
6941 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6942 alu
.src
[1].sel
= sample_gpr
;
6943 alu
.src
[1].chan
= 2;
6946 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6948 alu
.src
[2].sel
= interp_gpr
;
6949 alu
.src
[2].chan
= interp_base_chan
+ i
;
6950 alu
.dst
.sel
= ctx
->temp_reg
;
6954 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6959 for (i
= 0; i
< 2; i
++) {
6960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6961 alu
.op
= ALU_OP3_MULADD
;
6963 alu
.src
[0].sel
= gradientsV
;
6964 alu
.src
[0].chan
= i
;
6965 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6966 alu
.src
[1].sel
= sample_gpr
;
6967 alu
.src
[1].chan
= 3;
6970 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6972 alu
.src
[2].sel
= ctx
->temp_reg
;
6973 alu
.src
[2].chan
= i
;
6974 alu
.dst
.sel
= ctx
->temp_reg
;
6978 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6984 tmp
= r600_get_temp(ctx
);
6985 for (i
= 0; i
< 8; i
++) {
6986 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6987 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6990 if ((i
> 1 && i
< 6)) {
6996 alu
.dst
.chan
= i
% 4;
6998 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6999 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
7000 alu
.src
[0].sel
= ctx
->temp_reg
;
7001 alu
.src
[0].chan
= 1 - (i
% 2);
7003 alu
.src
[0].sel
= interp_gpr
;
7004 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
7006 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
7007 alu
.src
[1].chan
= 0;
7009 alu
.last
= i
% 4 == 3;
7010 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
7012 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7017 // INTERP can't swizzle dst
7018 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7019 for (i
= 0; i
<= lasti
; i
++) {
7020 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7023 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7024 alu
.op
= ALU_OP1_MOV
;
7025 alu
.src
[0].sel
= tmp
;
7026 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
7027 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7029 alu
.last
= i
== lasti
;
7030 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7039 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
7041 struct r600_bytecode_alu alu
;
7044 for (i
= 0; i
< 4; i
++) {
7045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7046 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
7047 alu
.op
= ALU_OP0_NOP
;
7050 alu
.op
= ALU_OP1_MOV
;
7051 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7052 alu
.src
[0].sel
= ctx
->temp_reg
;
7053 alu
.src
[0].chan
= i
;
7058 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7065 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
7066 unsigned temp
, int chan
,
7067 struct r600_bytecode_alu_src
*bc_src
,
7068 const struct r600_shader_src
*shader_src
)
7070 struct r600_bytecode_alu alu
;
7073 r600_bytecode_src(bc_src
, shader_src
, chan
);
7075 /* op3 operands don't support abs modifier */
7077 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
7078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7079 alu
.op
= ALU_OP1_MOV
;
7081 alu
.dst
.chan
= chan
;
7084 alu
.src
[0] = *bc_src
;
7085 alu
.last
= true; // sufficient?
7086 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7090 memset(bc_src
, 0, sizeof(*bc_src
));
7092 bc_src
->chan
= chan
;
7097 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
7099 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7100 struct r600_bytecode_alu alu
;
7102 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7104 unsigned op
= ctx
->inst_info
->op
;
7106 if (op
== ALU_OP3_MULADD_IEEE
&&
7107 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
7108 op
= ALU_OP3_MULADD
;
7110 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7112 if (ctx
->src
[j
].abs
)
7113 temp_regs
[j
] = r600_get_temp(ctx
);
7115 for (i
= 0; i
< lasti
+ 1; i
++) {
7116 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7119 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7121 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7122 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
7128 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7138 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7145 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
7147 return tgsi_op3_dst(ctx
, -1);
7150 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
7152 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7153 struct r600_bytecode_alu alu
;
7155 unsigned op
= ctx
->inst_info
->op
;
7156 if (op
== ALU_OP2_DOT4_IEEE
&&
7157 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
7160 for (i
= 0; i
< 4; i
++) {
7161 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7163 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7164 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
7167 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7169 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
7170 /* handle some special cases */
7171 switch (inst
->Instruction
.Opcode
) {
7172 case TGSI_OPCODE_DP2
:
7174 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7175 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
7178 case TGSI_OPCODE_DP3
:
7180 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7181 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
7190 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7197 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
7200 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7201 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
7202 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
7203 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
7204 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
7205 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
7208 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
7211 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7212 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
7215 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
7217 struct r600_bytecode_vtx vtx
;
7218 struct r600_bytecode_alu alu
;
7219 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7221 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
7222 int sampler_index_mode
= inst
->Src
[1].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7224 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7225 if (src_requires_loading
) {
7226 for (i
= 0; i
< 4; i
++) {
7227 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7228 alu
.op
= ALU_OP1_MOV
;
7229 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7230 alu
.dst
.sel
= ctx
->temp_reg
;
7235 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7239 src_gpr
= ctx
->temp_reg
;
7242 memset(&vtx
, 0, sizeof(vtx
));
7243 vtx
.op
= FETCH_OP_VFETCH
;
7244 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
7245 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7246 vtx
.src_gpr
= src_gpr
;
7247 vtx
.mega_fetch_count
= 16;
7248 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7249 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7250 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
7251 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
7252 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
7253 vtx
.use_const_fields
= 1;
7254 vtx
.buffer_index_mode
= sampler_index_mode
;
7256 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
7259 if (ctx
->bc
->chip_class
>= EVERGREEN
)
7262 for (i
= 0; i
< 4; i
++) {
7263 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7264 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7267 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7268 alu
.op
= ALU_OP2_AND_INT
;
7271 alu
.dst
.sel
= vtx
.dst_gpr
;
7274 alu
.src
[0].sel
= vtx
.dst_gpr
;
7275 alu
.src
[0].chan
= i
;
7277 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7278 alu
.src
[1].sel
+= (id
* 2);
7279 alu
.src
[1].chan
= i
% 4;
7280 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7289 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
7290 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7291 alu
.op
= ALU_OP2_OR_INT
;
7294 alu
.dst
.sel
= vtx
.dst_gpr
;
7297 alu
.src
[0].sel
= vtx
.dst_gpr
;
7298 alu
.src
[0].chan
= 3;
7300 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
7301 alu
.src
[1].chan
= 0;
7302 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7312 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
, int eg_buffer_base
)
7314 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7316 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
7317 int sampler_index_mode
= inst
->Src
[reg_idx
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7319 if (ctx
->bc
->chip_class
< EVERGREEN
) {
7320 struct r600_bytecode_alu alu
;
7321 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7322 alu
.op
= ALU_OP1_MOV
;
7323 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7324 /* r600 we have them at channel 2 of the second dword */
7325 alu
.src
[0].sel
+= (id
* 2) + 1;
7326 alu
.src
[0].chan
= 1;
7327 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7328 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
7330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7335 struct r600_bytecode_vtx vtx
;
7336 memset(&vtx
, 0, sizeof(vtx
));
7337 vtx
.op
= FETCH_OP_GET_BUFFER_RESINFO
;
7338 vtx
.buffer_id
= id
+ eg_buffer_base
;
7339 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
7341 vtx
.mega_fetch_count
= 16; /* no idea here really... */
7342 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7343 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
7344 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 4 : 7; /* SEL_Y */
7345 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 4 : 7; /* SEL_Z */
7346 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 4 : 7; /* SEL_W */
7347 vtx
.data_format
= FMT_32_32_32_32
;
7348 vtx
.buffer_index_mode
= sampler_index_mode
;
7350 if ((r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
)))
7357 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
7359 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7360 struct r600_bytecode_tex tex
;
7361 struct r600_bytecode_alu alu
;
7365 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
7366 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7367 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
7368 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
7370 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
7371 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
7372 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
7374 /* Texture fetch instructions can only use gprs as source.
7375 * Also they cannot negate the source or take the absolute value */
7376 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
7377 tgsi_tex_src_requires_loading(ctx
, 0)) ||
7378 read_compressed_msaa
|| txf_add_offsets
;
7380 boolean src_loaded
= FALSE
;
7381 unsigned sampler_src_reg
= 1;
7382 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
7383 boolean has_txq_cube_array_z
= false;
7384 unsigned sampler_index_mode
;
7386 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
7387 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7388 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
7389 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
7390 ctx
->shader
->has_txq_cube_array_z_comp
= true;
7391 has_txq_cube_array_z
= true;
7394 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
7395 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7396 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
7397 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
7398 sampler_src_reg
= 2;
7400 /* TGSI moves the sampler to src reg 3 for TXD */
7401 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
7402 sampler_src_reg
= 3;
7404 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7406 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
7408 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
7409 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
7410 if (ctx
->bc
->chip_class
< EVERGREEN
)
7411 ctx
->shader
->uses_tex_buffers
= true;
7412 return r600_do_buffer_txq(ctx
, 1, 0, R600_MAX_CONST_BUFFERS
);
7414 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
7415 if (ctx
->bc
->chip_class
< EVERGREEN
)
7416 ctx
->shader
->uses_tex_buffers
= true;
7417 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
7421 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
7423 /* Add perspective divide */
7424 if (ctx
->bc
->chip_class
== CAYMAN
) {
7426 for (i
= 0; i
< 3; i
++) {
7427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7428 alu
.op
= ALU_OP1_RECIP_IEEE
;
7429 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7431 alu
.dst
.sel
= ctx
->temp_reg
;
7437 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7444 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7445 alu
.op
= ALU_OP1_RECIP_IEEE
;
7446 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7448 alu
.dst
.sel
= ctx
->temp_reg
;
7449 alu
.dst
.chan
= out_chan
;
7452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7457 for (i
= 0; i
< 3; i
++) {
7458 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7459 alu
.op
= ALU_OP2_MUL
;
7460 alu
.src
[0].sel
= ctx
->temp_reg
;
7461 alu
.src
[0].chan
= out_chan
;
7462 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7463 alu
.dst
.sel
= ctx
->temp_reg
;
7466 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7470 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7471 alu
.op
= ALU_OP1_MOV
;
7472 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7473 alu
.src
[0].chan
= 0;
7474 alu
.dst
.sel
= ctx
->temp_reg
;
7478 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7482 src_gpr
= ctx
->temp_reg
;
7486 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7487 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7488 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7489 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7490 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7492 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7493 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7495 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7496 for (i
= 0; i
< 4; i
++) {
7497 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7498 alu
.op
= ALU_OP2_CUBE
;
7499 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7500 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7501 alu
.dst
.sel
= ctx
->temp_reg
;
7506 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7511 /* tmp1.z = RCP_e(|tmp1.z|) */
7512 if (ctx
->bc
->chip_class
== CAYMAN
) {
7513 for (i
= 0; i
< 3; i
++) {
7514 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7515 alu
.op
= ALU_OP1_RECIP_IEEE
;
7516 alu
.src
[0].sel
= ctx
->temp_reg
;
7517 alu
.src
[0].chan
= 2;
7519 alu
.dst
.sel
= ctx
->temp_reg
;
7525 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7530 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7531 alu
.op
= ALU_OP1_RECIP_IEEE
;
7532 alu
.src
[0].sel
= ctx
->temp_reg
;
7533 alu
.src
[0].chan
= 2;
7535 alu
.dst
.sel
= ctx
->temp_reg
;
7539 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7544 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7545 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7546 * muladd has no writemask, have to use another temp
7548 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7549 alu
.op
= ALU_OP3_MULADD
;
7552 alu
.src
[0].sel
= ctx
->temp_reg
;
7553 alu
.src
[0].chan
= 0;
7554 alu
.src
[1].sel
= ctx
->temp_reg
;
7555 alu
.src
[1].chan
= 2;
7557 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7558 alu
.src
[2].chan
= 0;
7559 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7561 alu
.dst
.sel
= ctx
->temp_reg
;
7565 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7570 alu
.op
= ALU_OP3_MULADD
;
7573 alu
.src
[0].sel
= ctx
->temp_reg
;
7574 alu
.src
[0].chan
= 1;
7575 alu
.src
[1].sel
= ctx
->temp_reg
;
7576 alu
.src
[1].chan
= 2;
7578 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7579 alu
.src
[2].chan
= 0;
7580 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7582 alu
.dst
.sel
= ctx
->temp_reg
;
7587 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7590 /* write initial compare value into Z component
7591 - W src 0 for shadow cube
7592 - X src 1 for shadow cube array */
7593 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7594 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7595 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7596 alu
.op
= ALU_OP1_MOV
;
7597 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7598 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7600 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7601 alu
.dst
.sel
= ctx
->temp_reg
;
7605 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7610 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7611 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7612 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7613 int mytmp
= r600_get_temp(ctx
);
7614 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7615 alu
.op
= ALU_OP1_MOV
;
7616 alu
.src
[0].sel
= ctx
->temp_reg
;
7617 alu
.src
[0].chan
= 3;
7618 alu
.dst
.sel
= mytmp
;
7622 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7626 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7627 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7628 alu
.op
= ALU_OP3_MULADD
;
7630 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7631 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7632 alu
.src
[1].chan
= 0;
7633 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7634 alu
.src
[2].sel
= mytmp
;
7635 alu
.src
[2].chan
= 0;
7636 alu
.dst
.sel
= ctx
->temp_reg
;
7640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7643 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7644 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7645 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7646 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7647 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7648 tex
.src_gpr
= r600_get_temp(ctx
);
7653 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7654 tex
.coord_type_x
= 1;
7655 tex
.coord_type_y
= 1;
7656 tex
.coord_type_z
= 1;
7657 tex
.coord_type_w
= 1;
7658 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7659 alu
.op
= ALU_OP1_MOV
;
7660 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7661 alu
.dst
.sel
= tex
.src_gpr
;
7665 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7669 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7676 /* for cube forms of lod and bias we need to route things */
7677 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7678 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7679 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7680 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7681 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7682 alu
.op
= ALU_OP1_MOV
;
7683 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7684 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7685 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7687 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7688 alu
.dst
.sel
= ctx
->temp_reg
;
7692 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7698 src_gpr
= ctx
->temp_reg
;
7701 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7702 int temp_h
= 0, temp_v
= 0;
7705 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7706 if (src_loaded
== TRUE
)
7710 for (i
= start_val
; i
< 3; i
++) {
7711 int treg
= r600_get_temp(ctx
);
7720 for (j
= 0; j
< 4; j
++) {
7721 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7722 alu
.op
= ALU_OP1_MOV
;
7723 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7734 for (i
= 1; i
< 3; i
++) {
7735 /* set gradients h/v */
7736 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7737 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7738 FETCH_OP_SET_GRADIENTS_V
;
7739 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7740 tex
.sampler_index_mode
= sampler_index_mode
;
7741 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7742 tex
.resource_index_mode
= sampler_index_mode
;
7744 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7750 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7751 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7752 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7753 tex
.coord_type_x
= 1;
7754 tex
.coord_type_y
= 1;
7755 tex
.coord_type_z
= 1;
7756 tex
.coord_type_w
= 1;
7758 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7764 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7765 /* Gather4 should follow the same rules as bilinear filtering, but the hardware
7766 * incorrectly forces nearest filtering if the texture format is integer.
7767 * The only effect it has on Gather4, which always returns 4 texels for
7768 * bilinear filtering, is that the final coordinates are off by 0.5 of
7771 * The workaround is to subtract 0.5 from the unnormalized coordinates,
7772 * or (0.5 / size) from the normalized coordinates.
7774 if (inst
->Texture
.ReturnType
== TGSI_RETURN_TYPE_SINT
||
7775 inst
->Texture
.ReturnType
== TGSI_RETURN_TYPE_UINT
) {
7776 int treg
= r600_get_temp(ctx
);
7778 /* mov array and comparison oordinate to temp_reg if needed */
7779 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7780 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7781 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
) && !src_loaded
) {
7782 int end
= inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
? 3 : 2;
7783 for (i
= 2; i
<= end
; i
++) {
7784 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7785 alu
.op
= ALU_OP1_MOV
;
7786 alu
.dst
.sel
= ctx
->temp_reg
;
7789 alu
.last
= (i
== end
);
7790 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7791 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7797 if (inst
->Texture
.Texture
== TGSI_TEXTURE_RECT
||
7798 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
) {
7799 for (i
= 0; i
< 2; i
++) {
7800 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7801 alu
.op
= ALU_OP2_ADD
;
7802 alu
.dst
.sel
= ctx
->temp_reg
;
7807 alu
.src
[0].sel
= ctx
->temp_reg
;
7808 alu
.src
[0].chan
= i
;
7810 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7811 alu
.src
[1].sel
= V_SQ_ALU_SRC_0_5
;
7813 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7819 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7820 tex
.op
= FETCH_OP_GET_TEXTURE_RESINFO
;
7821 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7822 tex
.sampler_index_mode
= sampler_index_mode
;
7823 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7824 tex
.resource_index_mode
= sampler_index_mode
;
7834 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7838 /* coord.xy = -0.5 * (1.0/int_to_flt(size)) + coord.xy */
7839 if (ctx
->bc
->chip_class
== CAYMAN
) {
7841 for (i
= 0; i
< 2; i
++) {
7842 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7843 alu
.op
= ALU_OP1_INT_TO_FLT
;
7847 alu
.src
[0].sel
= treg
;
7848 alu
.src
[0].chan
= i
;
7849 alu
.last
= (i
== 1) ? 1 : 0;
7850 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7854 for (j
= 0; j
< 2; j
++) {
7855 for (i
= 0; i
< 3; i
++) {
7856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7857 alu
.op
= ALU_OP1_RECIP_IEEE
;
7858 alu
.src
[0].sel
= treg
;
7859 alu
.src
[0].chan
= j
;
7866 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7872 for (i
= 0; i
< 2; i
++) {
7873 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7874 alu
.op
= ALU_OP1_INT_TO_FLT
;
7878 alu
.src
[0].sel
= treg
;
7879 alu
.src
[0].chan
= i
;
7881 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7885 for (i
= 0; i
< 2; i
++) {
7886 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7887 alu
.op
= ALU_OP1_RECIP_IEEE
;
7888 alu
.src
[0].sel
= treg
;
7889 alu
.src
[0].chan
= i
;
7894 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7899 for (i
= 0; i
< 2; i
++) {
7900 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7901 alu
.op
= ALU_OP3_MULADD
;
7903 alu
.dst
.sel
= ctx
->temp_reg
;
7907 alu
.src
[0].sel
= treg
;
7908 alu
.src
[0].chan
= i
;
7909 alu
.src
[1].sel
= V_SQ_ALU_SRC_0_5
;
7912 alu
.src
[2].sel
= ctx
->temp_reg
;
7913 alu
.src
[2].chan
= i
;
7915 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
7916 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7922 src_gpr
= ctx
->temp_reg
;
7926 if (src_requires_loading
&& !src_loaded
) {
7927 for (i
= 0; i
< 4; i
++) {
7928 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7929 alu
.op
= ALU_OP1_MOV
;
7930 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7931 alu
.dst
.sel
= ctx
->temp_reg
;
7936 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7941 src_gpr
= ctx
->temp_reg
;
7944 /* get offset values */
7945 if (inst
->Texture
.NumOffsets
) {
7946 assert(inst
->Texture
.NumOffsets
== 1);
7948 /* The texture offset feature doesn't work with the TXF instruction
7949 * and must be emulated by adding the offset to the texture coordinates. */
7950 if (txf_add_offsets
) {
7951 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7953 switch (inst
->Texture
.Texture
) {
7954 case TGSI_TEXTURE_3D
:
7955 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7956 alu
.op
= ALU_OP2_ADD_INT
;
7957 alu
.src
[0].sel
= src_gpr
;
7958 alu
.src
[0].chan
= 2;
7959 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7960 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7961 alu
.dst
.sel
= src_gpr
;
7965 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7970 case TGSI_TEXTURE_2D
:
7971 case TGSI_TEXTURE_SHADOW2D
:
7972 case TGSI_TEXTURE_RECT
:
7973 case TGSI_TEXTURE_SHADOWRECT
:
7974 case TGSI_TEXTURE_2D_ARRAY
:
7975 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7976 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7977 alu
.op
= ALU_OP2_ADD_INT
;
7978 alu
.src
[0].sel
= src_gpr
;
7979 alu
.src
[0].chan
= 1;
7980 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7981 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7982 alu
.dst
.sel
= src_gpr
;
7986 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7991 case TGSI_TEXTURE_1D
:
7992 case TGSI_TEXTURE_SHADOW1D
:
7993 case TGSI_TEXTURE_1D_ARRAY
:
7994 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7996 alu
.op
= ALU_OP2_ADD_INT
;
7997 alu
.src
[0].sel
= src_gpr
;
7998 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7999 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
8000 alu
.dst
.sel
= src_gpr
;
8003 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8007 /* texture offsets do not apply to other texture targets */
8010 switch (inst
->Texture
.Texture
) {
8011 case TGSI_TEXTURE_3D
:
8012 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
8014 case TGSI_TEXTURE_2D
:
8015 case TGSI_TEXTURE_SHADOW2D
:
8016 case TGSI_TEXTURE_RECT
:
8017 case TGSI_TEXTURE_SHADOWRECT
:
8018 case TGSI_TEXTURE_2D_ARRAY
:
8019 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
8020 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
8022 case TGSI_TEXTURE_1D
:
8023 case TGSI_TEXTURE_SHADOW1D
:
8024 case TGSI_TEXTURE_1D_ARRAY
:
8025 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
8026 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
8031 /* Obtain the sample index for reading a compressed MSAA color texture.
8032 * To read the FMASK, we use the ldfptr instruction, which tells us
8033 * where the samples are stored.
8034 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
8035 * which is the identity mapping. Each nibble says which physical sample
8036 * should be fetched to get that sample.
8038 * Assume src.z contains the sample index. It should be modified like this:
8039 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
8040 * Then fetch the texel with src.
8042 if (read_compressed_msaa
) {
8043 unsigned sample_chan
= 3;
8044 unsigned temp
= r600_get_temp(ctx
);
8047 /* temp.w = ldfptr() */
8048 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8049 tex
.op
= FETCH_OP_LD
;
8050 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
8051 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8052 tex
.sampler_index_mode
= sampler_index_mode
;
8053 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
8054 tex
.resource_index_mode
= sampler_index_mode
;
8055 tex
.src_gpr
= src_gpr
;
8057 tex
.dst_sel_x
= 7; /* mask out these components */
8060 tex
.dst_sel_w
= 0; /* store X */
8065 tex
.offset_x
= offset_x
;
8066 tex
.offset_y
= offset_y
;
8067 tex
.offset_z
= offset_z
;
8068 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8072 /* temp.x = sample_index*4 */
8073 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8074 alu
.op
= ALU_OP2_MULLO_INT
;
8075 alu
.src
[0].sel
= src_gpr
;
8076 alu
.src
[0].chan
= sample_chan
;
8077 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8078 alu
.src
[1].value
= 4;
8082 r
= emit_mul_int_op(ctx
->bc
, &alu
);
8086 /* sample_index = temp.w >> temp.x */
8087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8088 alu
.op
= ALU_OP2_LSHR_INT
;
8089 alu
.src
[0].sel
= temp
;
8090 alu
.src
[0].chan
= 3;
8091 alu
.src
[1].sel
= temp
;
8092 alu
.src
[1].chan
= 0;
8093 alu
.dst
.sel
= src_gpr
;
8094 alu
.dst
.chan
= sample_chan
;
8097 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8101 /* sample_index & 0xF */
8102 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8103 alu
.op
= ALU_OP2_AND_INT
;
8104 alu
.src
[0].sel
= src_gpr
;
8105 alu
.src
[0].chan
= sample_chan
;
8106 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8107 alu
.src
[1].value
= 0xF;
8108 alu
.dst
.sel
= src_gpr
;
8109 alu
.dst
.chan
= sample_chan
;
8112 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8116 /* visualize the FMASK */
8117 for (i
= 0; i
< 4; i
++) {
8118 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8119 alu
.op
= ALU_OP1_INT_TO_FLT
;
8120 alu
.src
[0].sel
= src_gpr
;
8121 alu
.src
[0].chan
= sample_chan
;
8122 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8126 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8134 /* does this shader want a num layers from TXQ for a cube array? */
8135 if (has_txq_cube_array_z
) {
8136 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8138 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8139 alu
.op
= ALU_OP1_MOV
;
8141 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8142 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
8143 /* with eg each dword is number of cubes */
8144 alu
.src
[0].sel
+= id
/ 4;
8145 alu
.src
[0].chan
= id
% 4;
8147 /* r600 we have them at channel 2 of the second dword */
8148 alu
.src
[0].sel
+= (id
* 2) + 1;
8149 alu
.src
[0].chan
= 2;
8151 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8152 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8154 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8157 /* disable writemask from texture instruction */
8158 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8161 opcode
= ctx
->inst_info
->op
;
8162 if (opcode
== FETCH_OP_GATHER4
&&
8163 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
8164 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
8165 opcode
= FETCH_OP_GATHER4_O
;
8167 /* GATHER4_O/GATHER4_C_O use offset values loaded by
8168 SET_TEXTURE_OFFSETS instruction. The immediate offset values
8169 encoded in the instruction are ignored. */
8170 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8171 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
8172 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8173 tex
.sampler_index_mode
= sampler_index_mode
;
8174 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
8175 tex
.resource_index_mode
= sampler_index_mode
;
8177 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
8178 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
8179 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
8180 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
8188 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8193 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
8194 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
8195 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
8196 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
8197 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
8198 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
8199 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
8201 case FETCH_OP_SAMPLE
:
8202 opcode
= FETCH_OP_SAMPLE_C
;
8204 case FETCH_OP_SAMPLE_L
:
8205 opcode
= FETCH_OP_SAMPLE_C_L
;
8207 case FETCH_OP_SAMPLE_LB
:
8208 opcode
= FETCH_OP_SAMPLE_C_LB
;
8210 case FETCH_OP_SAMPLE_G
:
8211 opcode
= FETCH_OP_SAMPLE_C_G
;
8213 /* Texture gather variants */
8214 case FETCH_OP_GATHER4
:
8215 opcode
= FETCH_OP_GATHER4_C
;
8217 case FETCH_OP_GATHER4_O
:
8218 opcode
= FETCH_OP_GATHER4_C_O
;
8223 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8226 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
8227 tex
.sampler_index_mode
= sampler_index_mode
;
8228 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
8229 tex
.resource_index_mode
= sampler_index_mode
;
8230 tex
.src_gpr
= src_gpr
;
8231 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8233 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
8234 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
8235 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
8238 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
8239 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
8240 tex
.inst_mod
= texture_component_select
;
8242 if (ctx
->bc
->chip_class
== CAYMAN
) {
8243 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8244 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8245 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8246 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8248 /* GATHER4 result order is different from TGSI TG4 */
8249 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 1 : 7;
8250 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 2 : 7;
8251 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 0 : 7;
8252 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8255 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
8256 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8257 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8261 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
8268 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8269 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8270 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8271 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8275 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
8280 } else if (src_loaded
) {
8286 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
8287 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
8288 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
8289 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
8290 tex
.src_rel
= ctx
->src
[0].rel
;
8293 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
8294 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
8295 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
8296 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
8300 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
8303 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
8304 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
8305 tex
.coord_type_x
= 1;
8306 tex
.coord_type_y
= 1;
8308 tex
.coord_type_z
= 1;
8309 tex
.coord_type_w
= 1;
8311 tex
.offset_x
= offset_x
;
8312 tex
.offset_y
= offset_y
;
8313 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
8314 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8315 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
8319 tex
.offset_z
= offset_z
;
8322 /* Put the depth for comparison in W.
8323 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
8324 * Some instructions expect the depth in Z. */
8325 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
8326 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
8327 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
8328 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
8329 opcode
!= FETCH_OP_SAMPLE_C_L
&&
8330 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
8331 tex
.src_sel_w
= tex
.src_sel_z
;
8334 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
8335 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
8336 if (opcode
== FETCH_OP_SAMPLE_C_L
||
8337 opcode
== FETCH_OP_SAMPLE_C_LB
) {
8338 /* the array index is read from Y */
8339 tex
.coord_type_y
= 0;
8341 /* the array index is read from Z */
8342 tex
.coord_type_z
= 0;
8343 tex
.src_sel_z
= tex
.src_sel_y
;
8345 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
8346 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
8347 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
8348 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
8349 (ctx
->bc
->chip_class
>= EVERGREEN
)))
8350 /* the array index is read from Z */
8351 tex
.coord_type_z
= 0;
8353 /* mask unused source components */
8354 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
8355 switch (inst
->Texture
.Texture
) {
8356 case TGSI_TEXTURE_2D
:
8357 case TGSI_TEXTURE_RECT
:
8361 case TGSI_TEXTURE_1D_ARRAY
:
8365 case TGSI_TEXTURE_1D
:
8373 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8377 /* add shadow ambient support - gallium doesn't do it yet */
8381 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
8382 struct tgsi_full_src_register
*src
)
8386 if (src
->Register
.Indirect
) {
8387 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
8388 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
8389 return ctx
->shader
->atomics
[i
].hw_idx
;
8392 uint32_t index
= src
->Register
.Index
;
8393 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
8394 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
8396 if (index
> ctx
->shader
->atomics
[i
].end
)
8398 if (index
< ctx
->shader
->atomics
[i
].start
)
8400 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
8401 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
8408 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
8409 int *uav_id_p
, int *uav_index_mode_p
)
8411 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8412 int uav_id
, uav_index_mode
= 0;
8414 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8416 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
8418 if (inst
->Src
[0].Register
.Indirect
) {
8420 struct r600_bytecode_alu alu
;
8421 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8422 alu
.op
= ALU_OP2_LSHL_INT
;
8423 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
8424 alu
.src
[0].chan
= 0;
8425 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8426 alu
.src
[1].value
= 2;
8427 alu
.dst
.sel
= ctx
->temp_reg
;
8431 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8435 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8438 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
8444 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8446 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
8452 *uav_index_mode_p
= uav_index_mode
;
8456 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
8458 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8460 struct r600_bytecode_gds gds
;
8462 int uav_index_mode
= 0;
8463 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8465 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8469 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8470 gds
.op
= FETCH_OP_GDS_READ_RET
;
8471 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8472 gds
.uav_id
= is_cm
? 0 : uav_id
;
8473 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8474 gds
.src_gpr
= ctx
->temp_reg
;
8475 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
8483 gds
.alloc_consume
= !is_cm
;
8484 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8488 ctx
->bc
->cf_last
->vpm
= 1;
8492 /* this fixes up 1D arrays properly */
8493 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
8495 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8497 struct r600_bytecode_alu alu
;
8498 int temp_reg
= r600_get_temp(ctx
);
8500 for (i
= 0; i
< 4; i
++) {
8501 bool def_val
= true, write_zero
= false;
8502 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8503 alu
.op
= ALU_OP1_MOV
;
8504 alu
.dst
.sel
= temp_reg
;
8507 switch (inst
->Memory
.Texture
) {
8508 case TGSI_TEXTURE_BUFFER
:
8509 case TGSI_TEXTURE_1D
:
8510 if (i
== 1 || i
== 2 || i
== 3) {
8514 case TGSI_TEXTURE_1D_ARRAY
:
8515 if (i
== 1 || i
== 3)
8518 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
8522 case TGSI_TEXTURE_2D
:
8523 if (i
== 2 || i
== 3)
8533 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8534 alu
.src
[0].value
= 0;
8535 } else if (def_val
) {
8536 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
8542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8546 *idx_gpr
= temp_reg
;
8550 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
8553 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8555 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8556 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
8557 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
8559 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
8564 struct r600_bytecode_alu alu
;
8565 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8566 alu
.op
= ALU_OP2_LSHR_INT
;
8567 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
8568 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
8569 alu
.src
[1].value
= 2;
8570 alu
.dst
.sel
= temp_reg
;
8573 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8580 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
8582 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8583 /* have to work out the offset into the RAT immediate return buffer */
8584 struct r600_bytecode_vtx vtx
;
8585 struct r600_bytecode_cf
*cf
;
8587 int temp_reg
= r600_get_temp(ctx
);
8588 unsigned rat_index_mode
;
8591 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8592 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8594 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8597 ctx
->bc
->cf_last
->barrier
= 1;
8598 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8599 vtx
.op
= FETCH_OP_VFETCH
;
8600 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8601 vtx
.buffer_index_mode
= rat_index_mode
;
8602 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8603 vtx
.src_gpr
= temp_reg
;
8605 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8606 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8607 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8608 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8609 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8610 vtx
.num_format_all
= 1;
8611 vtx
.format_comp_all
= 1;
8612 vtx
.srf_mode_all
= 0;
8614 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8615 vtx
.data_format
= FMT_32_32_32_32
;
8616 vtx
.use_const_fields
= 0;
8617 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8618 vtx
.data_format
= FMT_32_32_32
;
8619 vtx
.use_const_fields
= 0;
8620 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8621 vtx
.data_format
= FMT_32_32
;
8622 vtx
.use_const_fields
= 0;
8624 vtx
.data_format
= FMT_32
;
8625 vtx
.use_const_fields
= 0;
8628 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8631 cf
= ctx
->bc
->cf_last
;
8636 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8638 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8639 /* have to work out the offset into the RAT immediate return buffer */
8640 struct r600_bytecode_vtx vtx
;
8641 struct r600_bytecode_cf
*cf
;
8644 unsigned format
, num_format
, format_comp
, endian
;
8645 const struct util_format_description
*desc
;
8646 unsigned rat_index_mode
;
8647 unsigned immed_base
;
8649 r
= load_thread_id_gpr(ctx
);
8653 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8655 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8656 r
= load_index_src(ctx
, 1, &idx_gpr
);
8661 egcm_load_index_reg(ctx
->bc
, 1, false);
8663 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8664 cf
= ctx
->bc
->cf_last
;
8666 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8667 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8668 cf
->rat
.index_mode
= rat_index_mode
;
8669 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8670 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8671 cf
->output
.index_gpr
= idx_gpr
;
8672 cf
->output
.comp_mask
= 0xf;
8673 cf
->output
.burst_count
= 1;
8677 cf
->output
.elem_size
= 0;
8679 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8680 cf
= ctx
->bc
->cf_last
;
8683 desc
= util_format_description(inst
->Memory
.Format
);
8684 r600_vertex_data_type(inst
->Memory
.Format
,
8685 &format
, &num_format
, &format_comp
, &endian
);
8686 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8687 vtx
.op
= FETCH_OP_VFETCH
;
8688 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8689 vtx
.buffer_index_mode
= rat_index_mode
;
8690 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8691 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8693 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8694 vtx
.dst_sel_x
= desc
->swizzle
[0];
8695 vtx
.dst_sel_y
= desc
->swizzle
[1];
8696 vtx
.dst_sel_z
= desc
->swizzle
[2];
8697 vtx
.dst_sel_w
= desc
->swizzle
[3];
8698 vtx
.srf_mode_all
= 1;
8699 vtx
.data_format
= format
;
8700 vtx
.num_format_all
= num_format
;
8701 vtx
.format_comp_all
= format_comp
;
8702 vtx
.endian
= endian
;
8704 vtx
.mega_fetch_count
= 3;
8705 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8708 cf
= ctx
->bc
->cf_last
;
8713 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8715 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8716 struct r600_bytecode_alu alu
;
8718 int temp_reg
= r600_get_temp(ctx
);
8720 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8721 alu
.op
= ALU_OP1_MOV
;
8722 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8723 alu
.dst
.sel
= temp_reg
;
8726 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8730 r
= do_lds_fetch_values(ctx
, temp_reg
,
8731 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8737 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8739 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8740 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8741 return tgsi_load_rat(ctx
);
8742 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8743 return tgsi_load_gds(ctx
);
8744 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8745 return tgsi_load_buffer(ctx
);
8746 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8747 return tgsi_load_lds(ctx
);
8751 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8753 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8754 struct r600_bytecode_cf
*cf
;
8756 unsigned rat_index_mode
;
8758 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8760 r
= load_buffer_coord(ctx
, 0, treg2
);
8764 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8766 egcm_load_index_reg(ctx
->bc
, 1, false);
8768 for (i
= 0; i
<= 3; i
++) {
8769 struct r600_bytecode_alu alu
;
8770 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8771 alu
.op
= ALU_OP1_MOV
;
8772 alu
.dst
.sel
= temp_reg
;
8774 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8775 alu
.last
= (i
== 3);
8777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8782 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8783 for (i
= 0; i
<= lasti
; i
++) {
8784 struct r600_bytecode_alu alu
;
8785 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8788 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8791 V_SQ_ALU_SRC_LITERAL
, i
);
8795 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8796 alu
.op
= ALU_OP1_MOV
;
8797 alu
.dst
.sel
= ctx
->temp_reg
;
8800 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8803 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8807 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8808 cf
= ctx
->bc
->cf_last
;
8810 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8811 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8812 cf
->rat
.index_mode
= rat_index_mode
;
8813 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8814 cf
->output
.gpr
= ctx
->temp_reg
;
8815 cf
->output
.index_gpr
= temp_reg
;
8816 cf
->output
.comp_mask
= 1;
8817 cf
->output
.burst_count
= 1;
8820 cf
->output
.elem_size
= 0;
8825 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8827 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8828 struct r600_bytecode_cf
*cf
;
8829 bool src_requires_loading
= false;
8830 int val_gpr
, idx_gpr
;
8832 unsigned rat_index_mode
;
8834 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8836 r
= load_index_src(ctx
, 0, &idx_gpr
);
8840 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8841 src_requires_loading
= true;
8843 if (src_requires_loading
) {
8844 struct r600_bytecode_alu alu
;
8845 for (i
= 0; i
< 4; i
++) {
8846 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8847 alu
.op
= ALU_OP1_MOV
;
8848 alu
.dst
.sel
= ctx
->temp_reg
;
8851 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8855 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8859 val_gpr
= ctx
->temp_reg
;
8861 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8863 egcm_load_index_reg(ctx
->bc
, 1, false);
8865 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8866 cf
= ctx
->bc
->cf_last
;
8868 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8869 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8870 cf
->rat
.index_mode
= rat_index_mode
;
8871 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8872 cf
->output
.gpr
= val_gpr
;
8873 cf
->output
.index_gpr
= idx_gpr
;
8874 cf
->output
.comp_mask
= 0xf;
8875 cf
->output
.burst_count
= 1;
8878 cf
->output
.elem_size
= 0;
8882 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8884 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8885 struct r600_bytecode_alu alu
;
8887 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8888 int temp_reg
= r600_get_temp(ctx
);
8891 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8892 alu
.op
= ALU_OP1_MOV
;
8893 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8894 alu
.dst
.sel
= temp_reg
;
8897 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8901 lasti
= tgsi_last_instruction(write_mask
);
8902 for (i
= 1; i
<= lasti
; i
++) {
8903 if (!(write_mask
& (1 << i
)))
8905 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8908 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8912 for (i
= 0; i
<= lasti
; i
++) {
8913 if (!(write_mask
& (1 << i
)))
8916 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8917 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8918 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8919 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8921 alu
.src
[0].sel
= temp_reg
;
8922 alu
.src
[0].chan
= i
;
8923 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8924 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8926 alu
.is_lds_idx_op
= true;
8928 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8934 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8935 alu
.op
= LDS_OP2_LDS_WRITE
;
8937 alu
.src
[0].sel
= temp_reg
;
8938 alu
.src
[0].chan
= i
;
8939 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8942 alu
.is_lds_idx_op
= true;
8944 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8951 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8953 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8954 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8955 return tgsi_store_buffer_rat(ctx
);
8956 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8957 return tgsi_store_lds(ctx
);
8959 return tgsi_store_rat(ctx
);
8962 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8964 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8965 /* have to work out the offset into the RAT immediate return buffer */
8966 struct r600_bytecode_alu alu
;
8967 struct r600_bytecode_vtx vtx
;
8968 struct r600_bytecode_cf
*cf
;
8971 unsigned format
, num_format
, format_comp
, endian
;
8972 const struct util_format_description
*desc
;
8973 unsigned rat_index_mode
;
8974 unsigned immed_base
;
8977 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8978 rat_base
= ctx
->shader
->rat_base
;
8980 r
= load_thread_id_gpr(ctx
);
8984 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8985 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8986 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8988 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8991 idx_gpr
= ctx
->temp_reg
;
8993 r
= load_index_src(ctx
, 1, &idx_gpr
);
8998 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
9000 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
9001 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9002 alu
.op
= ALU_OP1_MOV
;
9003 alu
.dst
.sel
= ctx
->thread_id_gpr
;
9006 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
9008 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9013 alu
.op
= ALU_OP1_MOV
;
9014 alu
.dst
.sel
= ctx
->thread_id_gpr
;
9015 if (ctx
->bc
->chip_class
== CAYMAN
)
9020 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
9022 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9026 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9027 alu
.op
= ALU_OP1_MOV
;
9028 alu
.dst
.sel
= ctx
->thread_id_gpr
;
9031 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
9033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9039 egcm_load_index_reg(ctx
->bc
, 1, false);
9040 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
9041 cf
= ctx
->bc
->cf_last
;
9043 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
9044 cf
->rat
.inst
= ctx
->inst_info
->op
;
9045 cf
->rat
.index_mode
= rat_index_mode
;
9046 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
9047 cf
->output
.gpr
= ctx
->thread_id_gpr
;
9048 cf
->output
.index_gpr
= idx_gpr
;
9049 cf
->output
.comp_mask
= 0xf;
9050 cf
->output
.burst_count
= 1;
9054 cf
->output
.elem_size
= 0;
9055 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
9056 cf
= ctx
->bc
->cf_last
;
9060 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
9061 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
9062 desc
= util_format_description(inst
->Memory
.Format
);
9063 r600_vertex_data_type(inst
->Memory
.Format
,
9064 &format
, &num_format
, &format_comp
, &endian
);
9065 vtx
.dst_sel_x
= desc
->swizzle
[0];
9073 vtx
.op
= FETCH_OP_VFETCH
;
9074 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
9075 vtx
.buffer_index_mode
= rat_index_mode
;
9076 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
9077 vtx
.src_gpr
= ctx
->thread_id_gpr
;
9079 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9083 vtx
.use_const_fields
= 0;
9084 vtx
.srf_mode_all
= 1;
9085 vtx
.data_format
= format
;
9086 vtx
.num_format_all
= num_format
;
9087 vtx
.format_comp_all
= format_comp
;
9088 vtx
.endian
= endian
;
9090 vtx
.mega_fetch_count
= 0xf;
9091 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
9094 cf
= ctx
->bc
->cf_last
;
9100 static int get_gds_op(int opcode
)
9103 case TGSI_OPCODE_ATOMUADD
:
9104 return FETCH_OP_GDS_ADD_RET
;
9105 case TGSI_OPCODE_ATOMAND
:
9106 return FETCH_OP_GDS_AND_RET
;
9107 case TGSI_OPCODE_ATOMOR
:
9108 return FETCH_OP_GDS_OR_RET
;
9109 case TGSI_OPCODE_ATOMXOR
:
9110 return FETCH_OP_GDS_XOR_RET
;
9111 case TGSI_OPCODE_ATOMUMIN
:
9112 return FETCH_OP_GDS_MIN_UINT_RET
;
9113 case TGSI_OPCODE_ATOMUMAX
:
9114 return FETCH_OP_GDS_MAX_UINT_RET
;
9115 case TGSI_OPCODE_ATOMXCHG
:
9116 return FETCH_OP_GDS_XCHG_RET
;
9117 case TGSI_OPCODE_ATOMCAS
:
9118 return FETCH_OP_GDS_CMP_XCHG_RET
;
9124 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
9126 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9127 struct r600_bytecode_gds gds
;
9128 struct r600_bytecode_alu alu
;
9129 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
9132 int uav_index_mode
= 0;
9133 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
9136 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
9140 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
9144 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
) {
9145 if (inst
->Src
[3].Register
.File
== TGSI_FILE_IMMEDIATE
) {
9146 int value
= (ctx
->literals
[4 * inst
->Src
[3].Register
.Index
+ inst
->Src
[3].Register
.SwizzleX
]);
9147 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9148 alu
.op
= ALU_OP1_MOV
;
9149 alu
.dst
.sel
= ctx
->temp_reg
;
9150 alu
.dst
.chan
= is_cm
? 2 : 1;
9151 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
9152 alu
.src
[0].value
= value
;
9155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9159 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9160 alu
.op
= ALU_OP1_MOV
;
9161 alu
.dst
.sel
= ctx
->temp_reg
;
9162 alu
.dst
.chan
= is_cm
? 2 : 1;
9163 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
9166 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9171 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
9172 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
9173 int abs_value
= abs(value
);
9174 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
9175 gds_op
= FETCH_OP_GDS_SUB_RET
;
9176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9177 alu
.op
= ALU_OP1_MOV
;
9178 alu
.dst
.sel
= ctx
->temp_reg
;
9179 alu
.dst
.chan
= is_cm
? 1 : 0;
9180 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
9181 alu
.src
[0].value
= abs_value
;
9184 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9188 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9189 alu
.op
= ALU_OP1_MOV
;
9190 alu
.dst
.sel
= ctx
->temp_reg
;
9191 alu
.dst
.chan
= is_cm
? 1 : 0;
9192 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
9195 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9201 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
9203 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9204 gds
.uav_id
= is_cm
? 0 : uav_id
;
9205 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
9206 gds
.src_gpr
= ctx
->temp_reg
;
9208 gds
.src_sel_x
= is_cm
? 0 : 4;
9209 gds
.src_sel_y
= is_cm
? 1 : 0;
9210 if (gds_op
== FETCH_OP_GDS_CMP_XCHG_RET
)
9211 gds
.src_sel_z
= is_cm
? 2 : 1;
9218 gds
.alloc_consume
= !is_cm
;
9220 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
9223 ctx
->bc
->cf_last
->vpm
= 1;
9227 static int get_lds_op(int opcode
)
9230 case TGSI_OPCODE_ATOMUADD
:
9231 return LDS_OP2_LDS_ADD_RET
;
9232 case TGSI_OPCODE_ATOMAND
:
9233 return LDS_OP2_LDS_AND_RET
;
9234 case TGSI_OPCODE_ATOMOR
:
9235 return LDS_OP2_LDS_OR_RET
;
9236 case TGSI_OPCODE_ATOMXOR
:
9237 return LDS_OP2_LDS_XOR_RET
;
9238 case TGSI_OPCODE_ATOMUMIN
:
9239 return LDS_OP2_LDS_MIN_UINT_RET
;
9240 case TGSI_OPCODE_ATOMUMAX
:
9241 return LDS_OP2_LDS_MAX_UINT_RET
;
9242 case TGSI_OPCODE_ATOMIMIN
:
9243 return LDS_OP2_LDS_MIN_INT_RET
;
9244 case TGSI_OPCODE_ATOMIMAX
:
9245 return LDS_OP2_LDS_MAX_INT_RET
;
9246 case TGSI_OPCODE_ATOMXCHG
:
9247 return LDS_OP2_LDS_XCHG_RET
;
9248 case TGSI_OPCODE_ATOMCAS
:
9249 return LDS_OP3_LDS_CMP_XCHG_RET
;
9255 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
9257 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9258 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
9261 struct r600_bytecode_alu alu
;
9262 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9264 alu
.is_lds_idx_op
= true;
9266 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
9267 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
9268 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
9269 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
9271 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
9272 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9276 /* then read from LDS_OQ_A_POP */
9277 memset(&alu
, 0, sizeof(alu
));
9279 alu
.op
= ALU_OP1_MOV
;
9280 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
9281 alu
.src
[0].chan
= 0;
9282 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
9285 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9292 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
9294 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9295 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
9296 return tgsi_atomic_op_rat(ctx
);
9297 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
9298 return tgsi_atomic_op_gds(ctx
);
9299 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
9300 return tgsi_atomic_op_rat(ctx
);
9301 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
9302 return tgsi_atomic_op_lds(ctx
);
9306 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
9308 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9309 unsigned sampler_index_mode
;
9310 struct r600_bytecode_tex tex
;
9312 boolean has_txq_cube_array_z
= false;
9314 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
9315 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
9316 if (ctx
->bc
->chip_class
< EVERGREEN
)
9317 ctx
->shader
->uses_tex_buffers
= true;
9318 unsigned eg_buffer_base
= 0;
9319 eg_buffer_base
= R600_IMAGE_REAL_RESOURCE_OFFSET
;
9320 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
9321 eg_buffer_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
9322 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
, eg_buffer_base
);
9325 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
9326 inst
->Dst
[0].Register
.WriteMask
& 4) {
9327 ctx
->shader
->has_txq_cube_array_z_comp
= true;
9328 has_txq_cube_array_z
= true;
9331 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
9332 if (sampler_index_mode
)
9333 egcm_load_index_reg(ctx
->bc
, 1, false);
9336 /* does this shader want a num layers from TXQ for a cube array? */
9337 if (has_txq_cube_array_z
) {
9338 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
9339 struct r600_bytecode_alu alu
;
9341 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9342 alu
.op
= ALU_OP1_MOV
;
9344 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
9345 /* with eg each dword is either number of cubes */
9346 alu
.src
[0].sel
+= id
/ 4;
9347 alu
.src
[0].chan
= id
% 4;
9348 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
9349 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
9351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9354 /* disable writemask from texture instruction */
9355 inst
->Dst
[0].Register
.WriteMask
&= ~4;
9357 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
9358 tex
.op
= ctx
->inst_info
->op
;
9359 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
9360 tex
.sampler_index_mode
= sampler_index_mode
;
9361 tex
.resource_id
= tex
.sampler_id
;
9362 tex
.resource_index_mode
= sampler_index_mode
;
9367 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
9368 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
9369 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
9370 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
9371 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
9372 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
9379 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
9381 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9382 struct r600_bytecode_alu alu
;
9383 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9384 unsigned i
, temp_regs
[2];
9387 /* optimize if it's just an equal balance */
9388 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
9389 for (i
= 0; i
< lasti
+ 1; i
++) {
9390 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9393 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9394 alu
.op
= ALU_OP2_ADD
;
9395 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
9396 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9398 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9403 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9411 for (i
= 0; i
< lasti
+ 1; i
++) {
9412 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9415 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9416 alu
.op
= ALU_OP2_ADD
;
9417 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9418 alu
.src
[0].chan
= 0;
9419 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
9420 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
9421 alu
.dst
.sel
= ctx
->temp_reg
;
9427 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9432 /* (1 - src0) * src2 */
9433 for (i
= 0; i
< lasti
+ 1; i
++) {
9434 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9437 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9438 alu
.op
= ALU_OP2_MUL
;
9439 alu
.src
[0].sel
= ctx
->temp_reg
;
9440 alu
.src
[0].chan
= i
;
9441 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9442 alu
.dst
.sel
= ctx
->temp_reg
;
9448 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9453 /* src0 * src1 + (1 - src0) * src2 */
9454 if (ctx
->src
[0].abs
)
9455 temp_regs
[0] = r600_get_temp(ctx
);
9458 if (ctx
->src
[1].abs
)
9459 temp_regs
[1] = r600_get_temp(ctx
);
9463 for (i
= 0; i
< lasti
+ 1; i
++) {
9464 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9467 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9468 alu
.op
= ALU_OP3_MULADD
;
9470 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9473 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
9476 alu
.src
[2].sel
= ctx
->temp_reg
;
9477 alu
.src
[2].chan
= i
;
9479 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9484 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9491 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
9493 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9494 struct r600_bytecode_alu alu
;
9496 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9500 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
9502 ctx
->src
[0].abs
= 0;
9503 ctx
->src
[0].neg
= 0;
9508 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
9510 if (ctx
->src
[j
].abs
)
9511 temp_regs
[j
] = r600_get_temp(ctx
);
9514 for (i
= 0; i
< lasti
+ 1; i
++) {
9515 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9518 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9520 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
9523 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
9526 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
9529 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9535 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9542 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
9544 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9545 struct r600_bytecode_alu alu
;
9547 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9549 for (i
= 0; i
< lasti
+ 1; i
++) {
9550 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9554 alu
.op
= ALU_OP3_CNDE_INT
;
9555 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9556 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9557 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
9558 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9564 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9571 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
9573 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9574 struct r600_bytecode_alu alu
;
9578 /* result.x = 2^floor(src); */
9579 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9580 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9582 alu
.op
= ALU_OP1_FLOOR
;
9583 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9585 alu
.dst
.sel
= ctx
->temp_reg
;
9589 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9593 if (ctx
->bc
->chip_class
== CAYMAN
) {
9594 for (i
= 0; i
< 3; i
++) {
9595 alu
.op
= ALU_OP1_EXP_IEEE
;
9596 alu
.src
[0].sel
= ctx
->temp_reg
;
9597 alu
.src
[0].chan
= 0;
9599 alu
.dst
.sel
= ctx
->temp_reg
;
9601 alu
.dst
.write
= i
== 0;
9603 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9608 alu
.op
= ALU_OP1_EXP_IEEE
;
9609 alu
.src
[0].sel
= ctx
->temp_reg
;
9610 alu
.src
[0].chan
= 0;
9612 alu
.dst
.sel
= ctx
->temp_reg
;
9616 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9622 /* result.y = tmp - floor(tmp); */
9623 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9624 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9626 alu
.op
= ALU_OP1_FRACT
;
9627 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9629 alu
.dst
.sel
= ctx
->temp_reg
;
9631 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9640 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9645 /* result.z = RoughApprox2ToX(tmp);*/
9646 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9647 if (ctx
->bc
->chip_class
== CAYMAN
) {
9648 for (i
= 0; i
< 3; i
++) {
9649 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9650 alu
.op
= ALU_OP1_EXP_IEEE
;
9651 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9653 alu
.dst
.sel
= ctx
->temp_reg
;
9660 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9665 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9666 alu
.op
= ALU_OP1_EXP_IEEE
;
9667 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9669 alu
.dst
.sel
= ctx
->temp_reg
;
9675 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9681 /* result.w = 1.0;*/
9682 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9685 alu
.op
= ALU_OP1_MOV
;
9686 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9687 alu
.src
[0].chan
= 0;
9689 alu
.dst
.sel
= ctx
->temp_reg
;
9693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9697 return tgsi_helper_copy(ctx
, inst
);
9700 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9702 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9703 struct r600_bytecode_alu alu
;
9707 /* result.x = floor(log2(|src|)); */
9708 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9709 if (ctx
->bc
->chip_class
== CAYMAN
) {
9710 for (i
= 0; i
< 3; i
++) {
9711 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9713 alu
.op
= ALU_OP1_LOG_IEEE
;
9714 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9715 r600_bytecode_src_set_abs(&alu
.src
[0]);
9717 alu
.dst
.sel
= ctx
->temp_reg
;
9723 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9729 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9731 alu
.op
= ALU_OP1_LOG_IEEE
;
9732 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9733 r600_bytecode_src_set_abs(&alu
.src
[0]);
9735 alu
.dst
.sel
= ctx
->temp_reg
;
9739 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9744 alu
.op
= ALU_OP1_FLOOR
;
9745 alu
.src
[0].sel
= ctx
->temp_reg
;
9746 alu
.src
[0].chan
= 0;
9748 alu
.dst
.sel
= ctx
->temp_reg
;
9753 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9758 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9759 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9761 if (ctx
->bc
->chip_class
== CAYMAN
) {
9762 for (i
= 0; i
< 3; i
++) {
9763 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9765 alu
.op
= ALU_OP1_LOG_IEEE
;
9766 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9767 r600_bytecode_src_set_abs(&alu
.src
[0]);
9769 alu
.dst
.sel
= ctx
->temp_reg
;
9776 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9781 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9783 alu
.op
= ALU_OP1_LOG_IEEE
;
9784 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9785 r600_bytecode_src_set_abs(&alu
.src
[0]);
9787 alu
.dst
.sel
= ctx
->temp_reg
;
9792 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9797 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9799 alu
.op
= ALU_OP1_FLOOR
;
9800 alu
.src
[0].sel
= ctx
->temp_reg
;
9801 alu
.src
[0].chan
= 1;
9803 alu
.dst
.sel
= ctx
->temp_reg
;
9808 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9812 if (ctx
->bc
->chip_class
== CAYMAN
) {
9813 for (i
= 0; i
< 3; i
++) {
9814 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9815 alu
.op
= ALU_OP1_EXP_IEEE
;
9816 alu
.src
[0].sel
= ctx
->temp_reg
;
9817 alu
.src
[0].chan
= 1;
9819 alu
.dst
.sel
= ctx
->temp_reg
;
9826 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9831 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9832 alu
.op
= ALU_OP1_EXP_IEEE
;
9833 alu
.src
[0].sel
= ctx
->temp_reg
;
9834 alu
.src
[0].chan
= 1;
9836 alu
.dst
.sel
= ctx
->temp_reg
;
9841 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9846 if (ctx
->bc
->chip_class
== CAYMAN
) {
9847 for (i
= 0; i
< 3; i
++) {
9848 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9849 alu
.op
= ALU_OP1_RECIP_IEEE
;
9850 alu
.src
[0].sel
= ctx
->temp_reg
;
9851 alu
.src
[0].chan
= 1;
9853 alu
.dst
.sel
= ctx
->temp_reg
;
9860 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9866 alu
.op
= ALU_OP1_RECIP_IEEE
;
9867 alu
.src
[0].sel
= ctx
->temp_reg
;
9868 alu
.src
[0].chan
= 1;
9870 alu
.dst
.sel
= ctx
->temp_reg
;
9875 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9880 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9882 alu
.op
= ALU_OP2_MUL
;
9884 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9885 r600_bytecode_src_set_abs(&alu
.src
[0]);
9887 alu
.src
[1].sel
= ctx
->temp_reg
;
9888 alu
.src
[1].chan
= 1;
9890 alu
.dst
.sel
= ctx
->temp_reg
;
9895 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9900 /* result.z = log2(|src|);*/
9901 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9902 if (ctx
->bc
->chip_class
== CAYMAN
) {
9903 for (i
= 0; i
< 3; i
++) {
9904 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9906 alu
.op
= ALU_OP1_LOG_IEEE
;
9907 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9908 r600_bytecode_src_set_abs(&alu
.src
[0]);
9910 alu
.dst
.sel
= ctx
->temp_reg
;
9917 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9922 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9924 alu
.op
= ALU_OP1_LOG_IEEE
;
9925 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9926 r600_bytecode_src_set_abs(&alu
.src
[0]);
9928 alu
.dst
.sel
= ctx
->temp_reg
;
9933 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9939 /* result.w = 1.0; */
9940 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9941 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9943 alu
.op
= ALU_OP1_MOV
;
9944 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9945 alu
.src
[0].chan
= 0;
9947 alu
.dst
.sel
= ctx
->temp_reg
;
9952 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9957 return tgsi_helper_copy(ctx
, inst
);
9960 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9962 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9963 struct r600_bytecode_alu alu
;
9965 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9966 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9968 assert(inst
->Dst
[0].Register
.Index
< 3);
9969 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9971 switch (inst
->Instruction
.Opcode
) {
9972 case TGSI_OPCODE_ARL
:
9973 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9975 case TGSI_OPCODE_ARR
:
9976 alu
.op
= ALU_OP1_FLT_TO_INT
;
9978 case TGSI_OPCODE_UARL
:
9979 alu
.op
= ALU_OP1_MOV
;
9986 for (i
= 0; i
<= lasti
; ++i
) {
9987 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9989 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9990 alu
.last
= i
== lasti
;
9994 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9999 if (inst
->Dst
[0].Register
.Index
> 0)
10000 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
10002 ctx
->bc
->ar_loaded
= 0;
10006 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
10008 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10009 struct r600_bytecode_alu alu
;
10011 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10013 switch (inst
->Instruction
.Opcode
) {
10014 case TGSI_OPCODE_ARL
:
10015 memset(&alu
, 0, sizeof(alu
));
10016 alu
.op
= ALU_OP1_FLOOR
;
10017 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10019 for (i
= 0; i
<= lasti
; ++i
) {
10020 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
10022 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10023 alu
.last
= i
== lasti
;
10024 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10029 memset(&alu
, 0, sizeof(alu
));
10030 alu
.op
= ALU_OP1_FLT_TO_INT
;
10031 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
10032 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10034 /* FLT_TO_INT is trans-only on r600/r700 */
10036 for (i
= 0; i
<= lasti
; ++i
) {
10038 alu
.src
[0].chan
= i
;
10039 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10043 case TGSI_OPCODE_ARR
:
10044 memset(&alu
, 0, sizeof(alu
));
10045 alu
.op
= ALU_OP1_FLT_TO_INT
;
10046 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10048 /* FLT_TO_INT is trans-only on r600/r700 */
10050 for (i
= 0; i
<= lasti
; ++i
) {
10051 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
10053 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10054 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10059 case TGSI_OPCODE_UARL
:
10060 memset(&alu
, 0, sizeof(alu
));
10061 alu
.op
= ALU_OP1_MOV
;
10062 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
10064 for (i
= 0; i
<= lasti
; ++i
) {
10065 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
10067 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10068 alu
.last
= i
== lasti
;
10069 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
10079 ctx
->bc
->ar_loaded
= 0;
10083 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
10085 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10086 struct r600_bytecode_alu alu
;
10089 for (i
= 0; i
< 4; i
++) {
10090 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10092 alu
.op
= ALU_OP2_MUL
;
10093 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10095 if (i
== 0 || i
== 3) {
10096 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
10098 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
10101 if (i
== 0 || i
== 2) {
10102 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
10104 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
10108 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10115 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
,
10116 struct r600_bytecode_alu_src
*src
)
10118 struct r600_bytecode_alu alu
;
10121 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10123 alu
.execute_mask
= 1;
10124 alu
.update_pred
= 1;
10126 alu
.dst
.sel
= ctx
->temp_reg
;
10131 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
10132 alu
.src
[1].chan
= 0;
10136 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
10142 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
10144 unsigned force_pop
= ctx
->bc
->force_add_cf
;
10148 if (ctx
->bc
->cf_last
) {
10149 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
10151 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
10155 if (alu_pop
== 1) {
10156 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
10157 ctx
->bc
->force_add_cf
= 1;
10158 } else if (alu_pop
== 2) {
10159 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
10160 ctx
->bc
->force_add_cf
= 1;
10167 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
10168 ctx
->bc
->cf_last
->pop_count
= pops
;
10169 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10175 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
10178 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
10182 unsigned entry_size
= stack
->entry_size
;
10184 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
10185 elements
+= stack
->push
;
10187 switch (ctx
->bc
->chip_class
) {
10190 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
10191 * the stack must be reserved to hold the current active/continue
10193 if (reason
== FC_PUSH_VPM
) {
10199 /* r9xx: any stack operation on empty stack consumes 2 additional
10204 /* FIXME: do the two elements added above cover the cases for the
10208 /* r8xx+: 2 extra elements are not always required, but one extra
10209 * element must be added for each of the following cases:
10210 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
10212 * (Currently we don't use ALU_ELSE_AFTER.)
10213 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
10214 * PUSH instruction executed.
10216 * NOTE: it seems we also need to reserve additional element in some
10217 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
10218 * then STACK_SIZE should be 2 instead of 1 */
10219 if (reason
== FC_PUSH_VPM
) {
10229 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
10230 * for all chips, so we use 4 in the final formula, not the real entry_size
10234 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
10236 if (entries
> stack
->max_entries
)
10237 stack
->max_entries
= entries
;
10240 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
10244 --ctx
->bc
->stack
.push
;
10245 assert(ctx
->bc
->stack
.push
>= 0);
10248 --ctx
->bc
->stack
.push_wqm
;
10249 assert(ctx
->bc
->stack
.push_wqm
>= 0);
10252 --ctx
->bc
->stack
.loop
;
10253 assert(ctx
->bc
->stack
.loop
>= 0);
10261 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
10265 ++ctx
->bc
->stack
.push
;
10268 ++ctx
->bc
->stack
.push_wqm
;
10270 ++ctx
->bc
->stack
.loop
;
10276 callstack_update_max_depth(ctx
, reason
);
10279 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
10281 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
10283 sp
->mid
= realloc((void *)sp
->mid
,
10284 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
10285 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
10289 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
10291 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
10292 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
10293 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
10297 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
10299 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
10309 static int emit_return(struct r600_shader_ctx
*ctx
)
10311 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
10315 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
10318 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
10319 ctx
->bc
->cf_last
->pop_count
= pops
;
10320 /* XXX work out offset */
10324 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
10329 static void emit_testflag(struct r600_shader_ctx
*ctx
)
10334 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
10336 emit_testflag(ctx
);
10337 emit_jump_to_offset(ctx
, 1, 4);
10338 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
10339 pops(ctx
, ifidx
+ 1);
10343 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
10345 emit_testflag(ctx
);
10347 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10348 ctx
->bc
->cf_last
->pop_count
= 1;
10350 fc_set_mid(ctx
, fc_sp
);
10356 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
,
10357 struct r600_bytecode_alu_src
*src
)
10359 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
10361 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
10362 * LOOP_STARTxxx for nested loops may put the branch stack into a state
10363 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
10364 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
10365 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
10366 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
10367 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10368 alu_type
= CF_OP_ALU
;
10371 emit_logic_pred(ctx
, opcode
, alu_type
, src
);
10373 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
10375 fc_pushlevel(ctx
, FC_IF
);
10377 callstack_push(ctx
, FC_PUSH_VPM
);
10381 static int tgsi_if(struct r600_shader_ctx
*ctx
)
10383 struct r600_bytecode_alu_src alu_src
;
10384 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
10386 return emit_if(ctx
, ALU_OP2_PRED_SETNE
, &alu_src
);
10389 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
10391 struct r600_bytecode_alu_src alu_src
;
10392 r600_bytecode_src(&alu_src
, &ctx
->src
[0], 0);
10393 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
10396 static int tgsi_else(struct r600_shader_ctx
*ctx
)
10398 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
10399 ctx
->bc
->cf_last
->pop_count
= 1;
10401 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
10402 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
10406 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
10409 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
10410 R600_ERR("if/endif unbalanced in shader\n");
10414 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
10415 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10416 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
10418 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10422 callstack_pop(ctx
, FC_PUSH_VPM
);
10426 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
10428 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
10429 * limited to 4096 iterations, like the other LOOP_* instructions. */
10430 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
10432 fc_pushlevel(ctx
, FC_LOOP
);
10434 /* check stack depth */
10435 callstack_push(ctx
, FC_LOOP
);
10439 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
10443 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
10445 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
10446 R600_ERR("loop/endloop in shader code are not paired.\n");
10450 /* fixup loop pointers - from r600isa
10451 LOOP END points to CF after LOOP START,
10452 LOOP START point to CF after LOOP END
10453 BRK/CONT point to LOOP END CF
10455 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
10457 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
10459 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
10460 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
10462 /* XXX add LOOPRET support */
10464 callstack_pop(ctx
, FC_LOOP
);
10468 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
10472 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
10474 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
10479 R600_ERR("Break not inside loop/endloop pair\n");
10483 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10485 fc_set_mid(ctx
, fscp
- 1);
10490 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
10492 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10493 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
10496 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10497 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
10499 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
10501 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
10502 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
10503 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
10508 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
10510 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10511 struct r600_bytecode_alu alu
;
10513 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10516 for (i
= 0; i
< lasti
+ 1; i
++) {
10517 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10523 alu
.dst
.sel
= ctx
->temp_reg
;
10526 alu
.op
= ALU_OP2_MULLO_UINT
;
10527 for (j
= 0; j
< 2; j
++) {
10528 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
10532 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10538 for (i
= 0; i
< lasti
+ 1; i
++) {
10539 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10543 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10545 alu
.op
= ALU_OP2_ADD_INT
;
10547 alu
.src
[0].sel
= ctx
->temp_reg
;
10548 alu
.src
[0].chan
= i
;
10550 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
10554 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10561 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
10563 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10564 struct r600_bytecode_alu alu
;
10566 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10568 /* temp.xy = f32_to_f16(src) */
10569 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10570 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
10572 alu
.dst
.sel
= ctx
->temp_reg
;
10574 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10575 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10579 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10581 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10585 /* dst.x = temp.y * 0x10000 + temp.x */
10586 for (i
= 0; i
< lasti
+ 1; i
++) {
10587 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10590 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10591 alu
.op
= ALU_OP3_MULADD_UINT24
;
10593 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10594 alu
.last
= i
== lasti
;
10595 alu
.src
[0].sel
= ctx
->temp_reg
;
10596 alu
.src
[0].chan
= 1;
10597 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10598 alu
.src
[1].value
= 0x10000;
10599 alu
.src
[2].sel
= ctx
->temp_reg
;
10600 alu
.src
[2].chan
= 0;
10601 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10609 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
10611 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10612 struct r600_bytecode_alu alu
;
10614 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10616 /* temp.x = src.x */
10617 /* note: no need to mask out the high bits */
10618 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10619 alu
.op
= ALU_OP1_MOV
;
10621 alu
.dst
.sel
= ctx
->temp_reg
;
10623 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10624 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10628 /* temp.y = src.x >> 16 */
10629 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10630 alu
.op
= ALU_OP2_LSHR_INT
;
10632 alu
.dst
.sel
= ctx
->temp_reg
;
10634 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10635 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10636 alu
.src
[1].value
= 16;
10638 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10642 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10643 for (i
= 0; i
< lasti
+ 1; i
++) {
10644 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10646 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10647 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10648 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10649 alu
.src
[0].sel
= ctx
->temp_reg
;
10650 alu
.src
[0].chan
= i
% 2;
10651 alu
.last
= i
== lasti
;
10652 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10660 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10662 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10663 struct r600_bytecode_alu alu
;
10664 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10668 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10669 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10670 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10671 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10672 dst
= r600_get_temp(ctx
);
10674 r
= tgsi_op3_dst(ctx
, dst
);
10678 for (i
= 0; i
< lasti
+ 1; i
++) {
10679 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10680 alu
.op
= ALU_OP2_SETGE_INT
;
10681 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10682 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10683 alu
.src
[1].value
= 32;
10684 alu
.dst
.sel
= ctx
->temp_reg
;
10689 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10694 for (i
= 0; i
< lasti
+ 1; i
++) {
10695 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10696 alu
.op
= ALU_OP3_CNDE_INT
;
10698 alu
.src
[0].sel
= ctx
->temp_reg
;
10699 alu
.src
[0].chan
= i
;
10701 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10703 alu
.src
[1].sel
= dst
;
10705 alu
.src
[1].sel
= alu
.dst
.sel
;
10706 alu
.src
[1].chan
= i
;
10707 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10711 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10719 static int tgsi_clock(struct r600_shader_ctx
*ctx
)
10721 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10722 struct r600_bytecode_alu alu
;
10725 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10726 alu
.op
= ALU_OP1_MOV
;
10727 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10728 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_LO
;
10729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10733 alu
.op
= ALU_OP1_MOV
;
10734 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10735 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_TIME_HI
;
10736 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10742 static int emit_u64add(struct r600_shader_ctx
*ctx
, int op
,
10744 int src0_sel
, int src0_chan
,
10745 int src1_sel
, int src1_chan
)
10747 struct r600_bytecode_alu alu
;
10751 if (op
== ALU_OP2_ADD_INT
)
10752 opc
= ALU_OP2_ADDC_UINT
;
10754 opc
= ALU_OP2_SUBB_UINT
;
10756 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10758 alu
.dst
.sel
= treg
;
10761 alu
.src
[0].sel
= src0_sel
;
10762 alu
.src
[0].chan
= src0_chan
+ 0;
10763 alu
.src
[1].sel
= src1_sel
;
10764 alu
.src
[1].chan
= src1_chan
+ 0;
10765 alu
.src
[1].neg
= 0;
10766 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10770 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10772 alu
.dst
.sel
= treg
;
10775 alu
.src
[0].sel
= src0_sel
;
10776 alu
.src
[0].chan
= src0_chan
+ 1;
10777 alu
.src
[1].sel
= src1_sel
;
10778 alu
.src
[1].chan
= src1_chan
+ 1;
10779 alu
.src
[1].neg
= 0;
10780 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10784 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10786 alu
.dst
.sel
= treg
;
10790 alu
.src
[0].sel
= src0_sel
;
10791 alu
.src
[0].chan
= src0_chan
+ 0;
10792 alu
.src
[1].sel
= src1_sel
;
10793 alu
.src
[1].chan
= src1_chan
+ 0;
10794 alu
.src
[1].neg
= 0;
10795 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10801 alu
.dst
.sel
= treg
;
10804 alu
.src
[0].sel
= treg
;
10805 alu
.src
[0].chan
= 1;
10806 alu
.src
[1].sel
= treg
;
10807 alu
.src
[1].chan
= 2;
10809 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10815 static int egcm_u64add(struct r600_shader_ctx
*ctx
)
10817 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10818 struct r600_bytecode_alu alu
;
10820 int treg
= ctx
->temp_reg
;
10821 int op
= ALU_OP2_ADD_INT
, opc
= ALU_OP2_ADDC_UINT
;
10823 if (ctx
->src
[1].neg
) {
10824 op
= ALU_OP2_SUB_INT
;
10825 opc
= ALU_OP2_SUBB_UINT
;
10827 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10829 alu
.dst
.sel
= treg
;
10832 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10833 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10834 alu
.src
[1].neg
= 0;
10835 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10839 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10841 alu
.dst
.sel
= treg
;
10844 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10845 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10846 alu
.src
[1].neg
= 0;
10847 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10851 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10853 alu
.dst
.sel
= treg
;
10857 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10858 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10859 alu
.src
[1].neg
= 0;
10860 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10864 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10866 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10867 alu
.src
[0].sel
= treg
;
10868 alu
.src
[0].chan
= 1;
10869 alu
.src
[1].sel
= treg
;
10870 alu
.src
[1].chan
= 2;
10872 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10875 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10876 alu
.op
= ALU_OP1_MOV
;
10877 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10878 alu
.src
[0].sel
= treg
;
10879 alu
.src
[0].chan
= 0;
10881 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10887 /* result.y = mul_high a, b
10889 result.y += a.x * b.y + a.y * b.x;
10891 static int egcm_u64mul(struct r600_shader_ctx
*ctx
)
10893 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10894 struct r600_bytecode_alu alu
;
10896 int treg
= ctx
->temp_reg
;
10898 /* temp.x = mul_lo a.x, b.x */
10899 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10900 alu
.op
= ALU_OP2_MULLO_UINT
;
10901 alu
.dst
.sel
= treg
;
10904 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10905 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10906 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10910 /* temp.y = mul_hi a.x, b.x */
10911 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10912 alu
.op
= ALU_OP2_MULHI_UINT
;
10913 alu
.dst
.sel
= treg
;
10916 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10917 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10918 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10922 /* temp.z = mul a.x, b.y */
10923 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10924 alu
.op
= ALU_OP2_MULLO_UINT
;
10925 alu
.dst
.sel
= treg
;
10928 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10929 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
10930 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10934 /* temp.w = mul a.y, b.x */
10935 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10936 alu
.op
= ALU_OP2_MULLO_UINT
;
10937 alu
.dst
.sel
= treg
;
10940 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
10941 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
10942 r
= emit_mul_int_op(ctx
->bc
, &alu
);
10946 /* temp.z = temp.z + temp.w */
10947 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10948 alu
.op
= ALU_OP2_ADD_INT
;
10949 alu
.dst
.sel
= treg
;
10952 alu
.src
[0].sel
= treg
;
10953 alu
.src
[0].chan
= 2;
10954 alu
.src
[1].sel
= treg
;
10955 alu
.src
[1].chan
= 3;
10957 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10961 /* temp.y = temp.y + temp.z */
10962 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10963 alu
.op
= ALU_OP2_ADD_INT
;
10964 alu
.dst
.sel
= treg
;
10967 alu
.src
[0].sel
= treg
;
10968 alu
.src
[0].chan
= 1;
10969 alu
.src
[1].sel
= treg
;
10970 alu
.src
[1].chan
= 2;
10972 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10976 /* dst.x = temp.x */
10977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10978 alu
.op
= ALU_OP1_MOV
;
10979 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
10980 alu
.src
[0].sel
= treg
;
10981 alu
.src
[0].chan
= 0;
10982 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10986 /* dst.y = temp.y */
10987 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10988 alu
.op
= ALU_OP1_MOV
;
10989 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
10990 alu
.src
[0].sel
= treg
;
10991 alu
.src
[0].chan
= 1;
10993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11000 static int emit_u64sge(struct r600_shader_ctx
*ctx
,
11002 int src0_sel
, int src0_base_chan
,
11003 int src1_sel
, int src1_base_chan
)
11006 /* for 64-bit sge */
11007 /* result = (src0.y > src1.y) || ((src0.y == src1.y) && src0.x >= src1.x)) */
11008 r
= single_alu_op2(ctx
, ALU_OP2_SETGT_UINT
,
11010 src0_sel
, src0_base_chan
+ 1,
11011 src1_sel
, src1_base_chan
+ 1);
11015 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11017 src0_sel
, src0_base_chan
,
11018 src1_sel
, src1_base_chan
);
11022 r
= single_alu_op2(ctx
, ALU_OP2_SETE_INT
,
11024 src0_sel
, src0_base_chan
+ 1,
11025 src1_sel
, src1_base_chan
+ 1);
11029 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11036 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11045 /* this isn't a complete div it's just enough for qbo shader to work */
11046 static int egcm_u64div(struct r600_shader_ctx
*ctx
)
11048 struct r600_bytecode_alu alu
;
11049 struct r600_bytecode_alu_src alu_num_hi
, alu_num_lo
, alu_denom_hi
, alu_denom_lo
, alu_src
;
11051 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
11053 /* make sure we are dividing my a const with 0 in the high bits */
11054 if (ctx
->src
[1].sel
!= V_SQ_ALU_SRC_LITERAL
)
11056 if (ctx
->src
[1].value
[ctx
->src
[1].swizzle
[1]] != 0)
11058 /* make sure we are doing one division */
11059 if (inst
->Dst
[0].Register
.WriteMask
!= 0x3)
11062 /* emit_if uses ctx->temp_reg so we can't */
11063 int treg
= r600_get_temp(ctx
);
11064 int tmp_num
= r600_get_temp(ctx
);
11065 int sub_tmp
= r600_get_temp(ctx
);
11067 /* tmp quot are tmp_num.zw */
11068 r600_bytecode_src(&alu_num_lo
, &ctx
->src
[0], 0);
11069 r600_bytecode_src(&alu_num_hi
, &ctx
->src
[0], 1);
11070 r600_bytecode_src(&alu_denom_lo
, &ctx
->src
[1], 0);
11071 r600_bytecode_src(&alu_denom_hi
, &ctx
->src
[1], 1);
11073 /* MOV tmp_num.xy, numerator */
11074 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11076 alu_num_lo
.sel
, alu_num_lo
.chan
,
11080 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11082 alu_num_hi
.sel
, alu_num_hi
.chan
,
11087 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11089 V_SQ_ALU_SRC_LITERAL
, 0,
11094 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11096 V_SQ_ALU_SRC_LITERAL
, 0,
11101 /* treg 0 is log2_denom */
11102 /* normally this gets the MSB for the denom high value
11103 - however we know this will always be 0 here. */
11104 r
= single_alu_op2(ctx
,
11107 V_SQ_ALU_SRC_LITERAL
, 32,
11112 /* normally check demon hi for 0, but we know it is already */
11113 /* t0.z = num_hi >= denom_lo */
11114 r
= single_alu_op2(ctx
,
11115 ALU_OP2_SETGE_UINT
,
11117 alu_num_hi
.sel
, alu_num_hi
.chan
,
11118 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
11122 memset(&alu_src
, 0, sizeof(alu_src
));
11123 alu_src
.sel
= treg
;
11125 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11129 /* for loops in here */
11130 /* get msb t0.x = msb(src[1].x) first */
11131 int msb_lo
= util_last_bit(alu_denom_lo
.value
);
11132 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11134 V_SQ_ALU_SRC_LITERAL
, msb_lo
,
11139 /* unroll the asm here */
11140 for (i
= 0; i
< 31; i
++) {
11141 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11143 V_SQ_ALU_SRC_LITERAL
, i
,
11148 /* we can do this on the CPU */
11149 uint32_t denom_lo_shl
= alu_denom_lo
.value
<< (31 - i
);
11150 /* t0.z = tmp_num.y >= t0.z */
11151 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11154 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
11158 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11165 memset(&alu_src
, 0, sizeof(alu_src
));
11166 alu_src
.sel
= treg
;
11168 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11172 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
11175 V_SQ_ALU_SRC_LITERAL
, denom_lo_shl
);
11179 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11182 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
11186 r
= tgsi_endif(ctx
);
11191 /* log2_denom is always <= 31, so manually peel the last loop
11194 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11197 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
11201 memset(&alu_src
, 0, sizeof(alu_src
));
11202 alu_src
.sel
= treg
;
11204 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11208 r
= single_alu_op2(ctx
, ALU_OP2_SUB_INT
,
11211 V_SQ_ALU_SRC_LITERAL
, alu_denom_lo
.value
);
11215 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11218 V_SQ_ALU_SRC_LITERAL
, 1U);
11221 r
= tgsi_endif(ctx
);
11225 r
= tgsi_endif(ctx
);
11229 /* onto the second loop to unroll */
11230 for (i
= 0; i
< 31; i
++) {
11231 r
= single_alu_op2(ctx
, ALU_OP2_SETGE_UINT
,
11233 V_SQ_ALU_SRC_LITERAL
, (63 - (31 - i
)),
11238 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
<< (31 - i
);
11239 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11241 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
11246 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11248 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
11253 r
= emit_u64sge(ctx
, sub_tmp
,
11259 r
= single_alu_op2(ctx
, ALU_OP2_AND_INT
,
11266 memset(&alu_src
, 0, sizeof(alu_src
));
11267 alu_src
.sel
= treg
;
11269 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11274 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
11281 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11288 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11295 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11298 V_SQ_ALU_SRC_LITERAL
, 1U << (31 - i
));
11302 r
= tgsi_endif(ctx
);
11307 /* log2_denom is always <= 63, so manually peel the last loop
11310 uint64_t denom_shl
= (uint64_t)alu_denom_lo
.value
;
11311 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11313 V_SQ_ALU_SRC_LITERAL
, (denom_shl
& 0xffffffff),
11318 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
11320 V_SQ_ALU_SRC_LITERAL
, (denom_shl
>> 32),
11325 r
= emit_u64sge(ctx
, sub_tmp
,
11331 memset(&alu_src
, 0, sizeof(alu_src
));
11332 alu_src
.sel
= sub_tmp
;
11334 r
= emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
, &alu_src
);
11338 r
= emit_u64add(ctx
, ALU_OP2_SUB_INT
,
11345 r
= single_alu_op2(ctx
, ALU_OP2_OR_INT
,
11348 V_SQ_ALU_SRC_LITERAL
, 1U);
11351 r
= tgsi_endif(ctx
);
11355 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11356 alu
.op
= ALU_OP1_MOV
;
11357 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11358 alu
.src
[0].sel
= tmp_num
;
11359 alu
.src
[0].chan
= 2;
11360 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11364 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11365 alu
.op
= ALU_OP1_MOV
;
11366 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
11367 alu
.src
[0].sel
= tmp_num
;
11368 alu
.src
[0].chan
= 3;
11370 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11376 static int egcm_u64sne(struct r600_shader_ctx
*ctx
)
11378 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
11379 struct r600_bytecode_alu alu
;
11381 int treg
= ctx
->temp_reg
;
11383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11384 alu
.op
= ALU_OP2_SETNE_INT
;
11385 alu
.dst
.sel
= treg
;
11388 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
11389 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
11390 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11394 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11395 alu
.op
= ALU_OP2_SETNE_INT
;
11396 alu
.dst
.sel
= treg
;
11399 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
11400 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
11402 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11406 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
11407 alu
.op
= ALU_OP2_OR_INT
;
11408 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
11409 alu
.src
[0].sel
= treg
;
11410 alu
.src
[0].chan
= 0;
11411 alu
.src
[1].sel
= treg
;
11412 alu
.src
[1].chan
= 1;
11414 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
11420 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
11421 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11422 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11423 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11425 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11427 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11428 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11429 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11430 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11431 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11432 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11433 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11434 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11435 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
11436 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11437 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11438 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11439 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11440 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11441 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11442 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11443 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11444 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11445 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11446 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11447 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11448 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11449 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11450 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11451 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11452 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11453 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11454 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11455 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11456 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11457 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11458 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11459 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11460 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11461 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11462 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11463 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11464 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11465 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11466 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11467 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11468 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11469 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11470 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11471 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11472 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11473 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11474 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11475 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11476 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11477 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11478 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11479 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11480 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11481 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11482 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11483 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11484 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
11485 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11486 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11487 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11488 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11489 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11490 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11491 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11492 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11493 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11494 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11495 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11496 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11497 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11498 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11499 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11500 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11501 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11502 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11503 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11504 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
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_trans
},
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_trans
},
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
] = { ALU_OP0_NOP
, tgsi_unsupported
},
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_NOP
, tgsi_unsupported
},
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 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11542 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
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_trans
},
11549 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11550 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
11551 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
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_UINT
, tgsi_op2_trans
},
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_trans
},
11562 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11563 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
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_r600_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_unsupported
},
11585 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
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_NOP
, tgsi_unsupported
},
11590 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11591 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11592 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11593 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11594 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11595 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11596 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11597 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11598 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11599 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
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
, tgsi_op2_trans
},
11604 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11605 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
11606 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
11607 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
11608 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
11609 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11610 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
11611 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
11612 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
11613 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
11614 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
11615 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11616 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11617 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11618 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11621 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
11622 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11623 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11624 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11625 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
11626 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
11627 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11628 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11629 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11630 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11631 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11632 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11633 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11634 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11635 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11636 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11637 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11638 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11639 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11640 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11641 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
11642 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11643 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11644 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11645 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11646 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11647 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11648 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11649 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
11650 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
11651 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
11652 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11653 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11654 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11655 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11656 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11657 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
11658 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11659 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11660 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11661 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11662 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11663 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11664 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11665 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11666 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11667 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11668 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11669 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
11670 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11671 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11672 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11673 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11674 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11675 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11676 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11677 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11678 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11679 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11680 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11681 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11682 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11683 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11684 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11685 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11686 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11687 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11688 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11689 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11690 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11691 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11692 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11693 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11694 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11695 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11696 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11697 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11698 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11699 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11700 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11701 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11702 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11703 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11704 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
11705 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11706 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11707 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11708 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11709 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11710 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11711 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11712 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11713 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11714 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11715 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11716 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11717 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11718 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11719 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11720 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11721 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11722 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11723 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11724 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11725 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11726 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11727 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11728 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11729 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11730 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11731 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11732 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11733 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11734 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11735 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11736 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11737 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11738 /* Refer below for TGSI_OPCODE_DFMA */
11739 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
11740 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11741 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11742 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11743 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11744 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11745 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11746 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11747 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
11748 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
11749 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11750 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11751 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11752 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11753 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11754 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11755 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
11756 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11757 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11758 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11759 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11760 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11761 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11762 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11763 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11764 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11765 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11766 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11767 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11768 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11769 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11770 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11771 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11772 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11773 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
11774 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
11775 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
11776 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
11777 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
11778 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
11779 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
11780 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
11781 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
11782 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
11783 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
11784 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
11785 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
11786 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11787 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
11788 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
11789 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
11790 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
11791 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
11792 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
11793 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
11794 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
11795 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
11796 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
11797 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11798 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11799 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11800 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
11801 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
11802 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
11803 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
11804 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
11805 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
11806 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
11807 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
11808 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
11809 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
11810 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
11811 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
11812 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11813 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11814 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
11815 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
11816 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
11817 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
11818 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
11819 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
11820 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
11821 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
11822 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
11823 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
11824 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
11825 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
11826 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
11827 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
11828 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
11829 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
11830 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11831 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
11832 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
11833 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
11834 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
11835 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
11836 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
11837 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
11838 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
11839 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
11840 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
11841 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
11842 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
11843 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
11844 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11847 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
11848 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11849 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
11850 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
11851 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
11852 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
11853 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
11854 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
11855 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
11856 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
11857 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11858 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11859 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
11860 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
11861 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
11862 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
11863 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
11864 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
11865 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
11866 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
11867 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
11868 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
11869 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
11870 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
11871 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
11872 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
11873 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
11874 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
11875 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
11876 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
11877 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
11878 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
11879 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
11880 [TGSI_OPCODE_CLOCK
] = { ALU_OP0_NOP
, tgsi_clock
},
11881 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
11882 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
11883 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
11884 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11885 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11886 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
11887 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
11888 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11889 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11890 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11891 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
11892 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
11893 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
11894 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
11895 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
11896 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
11897 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
11898 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
11899 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11900 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
11901 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
11902 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
11903 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11904 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11905 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11906 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
11907 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
11908 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
11909 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
11910 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11911 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11912 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
11913 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
11914 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
11915 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
11916 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
11917 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11918 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
11919 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
11920 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
11921 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
11922 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
11923 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
11924 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
11925 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
11926 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
11927 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
11928 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
11929 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
11930 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
11931 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
11932 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
11933 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
11934 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
11935 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
11936 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
11937 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
11938 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
11939 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
11940 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
11941 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11942 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
11943 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
11944 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
11945 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
11946 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11947 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
11948 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11949 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
11950 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
11951 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
11952 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
11953 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11954 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
11955 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
11956 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
11957 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
11958 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
11959 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
11960 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
11961 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
11962 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
11963 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
11964 /* Refer below for TGSI_OPCODE_DFMA */
11965 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
11966 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
11967 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
11968 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
11969 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
11970 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
11971 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
11972 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
11973 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
11974 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
11975 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
11976 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
11977 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
11978 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
11979 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
11980 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
11981 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
11982 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
11983 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
11984 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
11985 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
11986 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
11987 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11988 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11989 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11990 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
11991 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
11992 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
11993 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
11994 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
11995 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
11996 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
11997 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
11998 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
11999 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
12000 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
12001 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
12002 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
12003 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
12004 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
12005 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
12006 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
12007 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
12008 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
12009 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
12010 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
12011 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
12012 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
12013 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
12014 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
12015 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
12016 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
12017 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
12018 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
12019 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
12020 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
12021 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
12022 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
12023 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
12024 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
12025 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
12026 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
12027 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
12028 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
12029 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
12030 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
12031 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
12032 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
12033 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
12034 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
12035 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
12036 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
12037 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
12038 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
12039 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
12040 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
12041 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
12042 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
12043 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
12044 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
12045 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
12046 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
12047 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
12048 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
12049 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
12050 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
12051 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
12052 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
12053 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
12054 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
12055 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
12056 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
12057 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
12058 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
12059 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
12060 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
12061 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
12062 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
12063 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
12064 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
12065 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
12066 [TGSI_OPCODE_U64SNE
] = { ALU_OP0_NOP
, egcm_u64sne
},
12067 [TGSI_OPCODE_U64ADD
] = { ALU_OP0_NOP
, egcm_u64add
},
12068 [TGSI_OPCODE_U64MUL
] = { ALU_OP0_NOP
, egcm_u64mul
},
12069 [TGSI_OPCODE_U64DIV
] = { ALU_OP0_NOP
, egcm_u64div
},
12070 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},