2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "r600_formats.h"
25 #include "r600_opcodes.h"
26 #include "r600_shader.h"
29 #include "sb/sb_public.h"
31 #include "pipe/p_shader_tokens.h"
32 #include "tgsi/tgsi_info.h"
33 #include "tgsi/tgsi_parse.h"
34 #include "tgsi/tgsi_scan.h"
35 #include "tgsi/tgsi_dump.h"
36 #include "util/u_bitcast.h"
37 #include "util/u_memory.h"
38 #include "util/u_math.h"
43 Why CAYMAN got loops for lots of instructions is explained here.
45 -These 8xx t-slot only ops are implemented in all vector slots.
46 MUL_LIT, FLT_TO_UINT, INT_TO_FLT, UINT_TO_FLT
47 These 8xx t-slot only opcodes become vector ops, with all four
48 slots expecting the arguments on sources a and b. Result is
49 broadcast to all channels.
50 MULLO_INT, MULHI_INT, MULLO_UINT, MULHI_UINT, MUL_64
51 These 8xx t-slot only opcodes become vector ops in the z, y, and
53 EXP_IEEE, LOG_IEEE/CLAMPED, RECIP_IEEE/CLAMPED/FF/INT/UINT/_64/CLAMPED_64
54 RECIPSQRT_IEEE/CLAMPED/FF/_64/CLAMPED_64
57 The w slot may have an independent co-issued operation, or if the
58 result is required to be in the w slot, the opcode above may be
59 issued in the w slot as well.
60 The compiler must issue the source argument to slots z, y, and x
63 /* Contents of r0 on entry to various shaders
69 GS - r0.xyw, r1.xyz = per-vertex offsets
75 .w = tess factor base.
77 TES - .x = TessCoord.x
79 - .z = RelPatchID (??)
82 PS - face_gpr.z = SampleMask
85 #define R600_SHADER_BUFFER_INFO_SEL (512 + R600_BUFFER_INFO_OFFSET / 16)
86 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
87 struct r600_pipe_shader
*pipeshader
,
88 union r600_shader_key key
);
90 static void r600_add_gpr_array(struct r600_shader
*ps
, int start_gpr
,
91 int size
, unsigned comp_mask
) {
96 if (ps
->num_arrays
== ps
->max_arrays
) {
98 ps
->arrays
= realloc(ps
->arrays
, ps
->max_arrays
*
99 sizeof(struct r600_shader_array
));
102 int n
= ps
->num_arrays
;
105 ps
->arrays
[n
].comp_mask
= comp_mask
;
106 ps
->arrays
[n
].gpr_start
= start_gpr
;
107 ps
->arrays
[n
].gpr_count
= size
;
110 static void r600_dump_streamout(struct pipe_stream_output_info
*so
)
114 fprintf(stderr
, "STREAMOUT\n");
115 for (i
= 0; i
< so
->num_outputs
; i
++) {
116 unsigned mask
= ((1 << so
->output
[i
].num_components
) - 1) <<
117 so
->output
[i
].start_component
;
118 fprintf(stderr
, " %i: MEM_STREAM%d_BUF%i[%i..%i] <- OUT[%i].%s%s%s%s%s\n",
120 so
->output
[i
].stream
,
121 so
->output
[i
].output_buffer
,
122 so
->output
[i
].dst_offset
, so
->output
[i
].dst_offset
+ so
->output
[i
].num_components
- 1,
123 so
->output
[i
].register_index
,
128 so
->output
[i
].dst_offset
< so
->output
[i
].start_component
? " (will lower)" : "");
132 static int store_shader(struct pipe_context
*ctx
,
133 struct r600_pipe_shader
*shader
)
135 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
138 if (shader
->bo
== NULL
) {
139 shader
->bo
= (struct r600_resource
*)
140 pipe_buffer_create(ctx
->screen
, 0, PIPE_USAGE_IMMUTABLE
, shader
->shader
.bc
.ndw
* 4);
141 if (shader
->bo
== NULL
) {
144 ptr
= r600_buffer_map_sync_with_rings(&rctx
->b
, shader
->bo
, PIPE_TRANSFER_WRITE
);
145 if (R600_BIG_ENDIAN
) {
146 for (i
= 0; i
< shader
->shader
.bc
.ndw
; ++i
) {
147 ptr
[i
] = util_cpu_to_le32(shader
->shader
.bc
.bytecode
[i
]);
150 memcpy(ptr
, shader
->shader
.bc
.bytecode
, shader
->shader
.bc
.ndw
* sizeof(*ptr
));
152 rctx
->b
.ws
->buffer_unmap(shader
->bo
->buf
);
158 int r600_pipe_shader_create(struct pipe_context
*ctx
,
159 struct r600_pipe_shader
*shader
,
160 union r600_shader_key key
)
162 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
163 struct r600_pipe_shader_selector
*sel
= shader
->selector
;
165 bool dump
= r600_can_dump_shader(&rctx
->screen
->b
,
166 tgsi_get_processor_type(sel
->tokens
));
167 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
168 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
169 unsigned export_shader
;
171 shader
->shader
.bc
.isa
= rctx
->isa
;
174 fprintf(stderr
, "--------------------------------------------------------------\n");
175 tgsi_dump(sel
->tokens
, 0);
177 if (sel
->so
.num_outputs
) {
178 r600_dump_streamout(&sel
->so
);
181 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
183 R600_ERR("translation from TGSI failed !\n");
186 if (shader
->shader
.processor_type
== PIPE_SHADER_VERTEX
) {
187 /* only disable for vertex shaders in tess paths */
191 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_CTRL
);
192 use_sb
&= (shader
->shader
.processor_type
!= PIPE_SHADER_TESS_EVAL
);
194 /* disable SB for shaders using doubles */
195 use_sb
&= !shader
->shader
.uses_doubles
;
197 use_sb
&= !shader
->shader
.uses_atomics
;
198 use_sb
&= !shader
->shader
.uses_images
;
200 /* Check if the bytecode has already been built. */
201 if (!shader
->shader
.bc
.bytecode
) {
202 r
= r600_bytecode_build(&shader
->shader
.bc
);
204 R600_ERR("building bytecode failed !\n");
209 if (dump
&& !sb_disasm
) {
210 fprintf(stderr
, "--------------------------------------------------------------\n");
211 r600_bytecode_disasm(&shader
->shader
.bc
);
212 fprintf(stderr
, "______________________________________________________________\n");
213 } else if ((dump
&& sb_disasm
) || use_sb
) {
214 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
217 R600_ERR("r600_sb_bytecode_process failed !\n");
222 if (shader
->gs_copy_shader
) {
225 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
226 &shader
->gs_copy_shader
->shader
, dump
, 0);
231 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
235 /* Store the shader in a buffer. */
236 if ((r
= store_shader(ctx
, shader
)))
240 switch (shader
->shader
.processor_type
) {
241 case PIPE_SHADER_TESS_CTRL
:
242 evergreen_update_hs_state(ctx
, shader
);
244 case PIPE_SHADER_TESS_EVAL
:
246 evergreen_update_es_state(ctx
, shader
);
248 evergreen_update_vs_state(ctx
, shader
);
250 case PIPE_SHADER_GEOMETRY
:
251 if (rctx
->b
.chip_class
>= EVERGREEN
) {
252 evergreen_update_gs_state(ctx
, shader
);
253 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
255 r600_update_gs_state(ctx
, shader
);
256 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
259 case PIPE_SHADER_VERTEX
:
260 export_shader
= key
.vs
.as_es
;
261 if (rctx
->b
.chip_class
>= EVERGREEN
) {
263 evergreen_update_ls_state(ctx
, shader
);
264 else if (key
.vs
.as_es
)
265 evergreen_update_es_state(ctx
, shader
);
267 evergreen_update_vs_state(ctx
, shader
);
270 r600_update_es_state(ctx
, shader
);
272 r600_update_vs_state(ctx
, shader
);
275 case PIPE_SHADER_FRAGMENT
:
276 if (rctx
->b
.chip_class
>= EVERGREEN
) {
277 evergreen_update_ps_state(ctx
, shader
);
279 r600_update_ps_state(ctx
, shader
);
289 r600_pipe_shader_destroy(ctx
, shader
);
293 void r600_pipe_shader_destroy(struct pipe_context
*ctx UNUSED
, struct r600_pipe_shader
*shader
)
295 r600_resource_reference(&shader
->bo
, NULL
);
296 r600_bytecode_clear(&shader
->shader
.bc
);
297 r600_release_command_buffer(&shader
->command_buffer
);
301 * tgsi -> r600 shader
303 struct r600_shader_tgsi_instruction
;
305 struct r600_shader_src
{
312 boolean kc_rel
; /* true if cache bank is indexed */
321 struct r600_shader_ctx
{
322 struct tgsi_shader_info info
;
323 struct tgsi_parse_context parse
;
324 const struct tgsi_token
*tokens
;
326 unsigned file_offset
[TGSI_FILE_COUNT
];
328 const struct r600_shader_tgsi_instruction
*inst_info
;
329 struct r600_bytecode
*bc
;
330 struct r600_shader
*shader
;
331 struct r600_shader_src src
[4];
334 uint32_t max_driver_temp_used
;
335 /* needed for evergreen interpolation */
336 struct eg_interp eg_interpolators
[6]; // indexed by Persp/Linear * 3 + sample/center/centroid
337 /* evergreen/cayman also store sample mask in face register */
339 /* sample id is .w component stored in fixed point position register */
340 int fixed_pt_position_gpr
;
342 boolean clip_vertex_write
;
344 unsigned edgeflag_output
;
347 int next_ring_offset
;
348 int gs_out_ring_offset
;
350 struct r600_shader
*gs_for_vs
;
351 int gs_export_gpr_tregs
[4];
352 int gs_rotated_input
[2];
353 const struct pipe_stream_output_info
*gs_stream_output_info
;
354 unsigned enabled_stream_buffers_mask
;
355 unsigned tess_input_info
; /* temp with tess input offsets */
356 unsigned tess_output_info
; /* temp with tess input offsets */
357 unsigned thread_id_gpr
; /* temp with thread id calculated for images */
358 bool thread_id_gpr_loaded
;
361 struct r600_shader_tgsi_instruction
{
363 int (*process
)(struct r600_shader_ctx
*ctx
);
366 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
367 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
368 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
369 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
370 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
371 static int tgsi_else(struct r600_shader_ctx
*ctx
);
372 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
373 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
374 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
375 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
376 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
377 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
378 unsigned int dst_reg
);
379 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
380 const struct r600_shader_src
*shader_src
,
382 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
383 unsigned dst_reg
, unsigned mask
);
385 static int tgsi_last_instruction(unsigned writemask
)
389 for (i
= 0; i
< 4; i
++) {
390 if (writemask
& (1 << i
)) {
397 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
399 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
402 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
403 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
407 if (i
->Instruction
.Label
) {
408 R600_ERR("label unsupported\n");
412 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
413 if (i
->Src
[j
].Register
.Dimension
) {
414 switch (i
->Src
[j
].Register
.File
) {
415 case TGSI_FILE_CONSTANT
:
416 case TGSI_FILE_HW_ATOMIC
:
418 case TGSI_FILE_INPUT
:
419 if (ctx
->type
== PIPE_SHADER_GEOMETRY
||
420 ctx
->type
== PIPE_SHADER_TESS_CTRL
||
421 ctx
->type
== PIPE_SHADER_TESS_EVAL
)
423 case TGSI_FILE_OUTPUT
:
424 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
427 R600_ERR("unsupported src %d (file %d, dimension %d)\n", j
,
428 i
->Src
[j
].Register
.File
,
429 i
->Src
[j
].Register
.Dimension
);
434 for (j
= 0; j
< i
->Instruction
.NumDstRegs
; j
++) {
435 if (i
->Dst
[j
].Register
.Dimension
) {
436 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
)
438 R600_ERR("unsupported dst (dimension)\n");
445 int eg_get_interpolator_index(unsigned interpolate
, unsigned location
)
447 if (interpolate
== TGSI_INTERPOLATE_COLOR
||
448 interpolate
== TGSI_INTERPOLATE_LINEAR
||
449 interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
451 int is_linear
= interpolate
== TGSI_INTERPOLATE_LINEAR
;
455 case TGSI_INTERPOLATE_LOC_CENTER
:
458 case TGSI_INTERPOLATE_LOC_CENTROID
:
461 case TGSI_INTERPOLATE_LOC_SAMPLE
:
466 return is_linear
* 3 + loc
;
472 static void evergreen_interp_assign_ij_index(struct r600_shader_ctx
*ctx
,
475 int i
= eg_get_interpolator_index(
476 ctx
->shader
->input
[input
].interpolate
,
477 ctx
->shader
->input
[input
].interpolate_location
);
479 ctx
->shader
->input
[input
].ij_index
= ctx
->eg_interpolators
[i
].ij_index
;
482 static int evergreen_interp_alu(struct r600_shader_ctx
*ctx
, int input
)
485 struct r600_bytecode_alu alu
;
486 int gpr
= 0, base_chan
= 0;
487 int ij_index
= ctx
->shader
->input
[input
].ij_index
;
489 /* work out gpr and base_chan from index */
491 base_chan
= (2 * (ij_index
% 2)) + 1;
493 for (i
= 0; i
< 8; i
++) {
494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
497 alu
.op
= ALU_OP2_INTERP_ZW
;
499 alu
.op
= ALU_OP2_INTERP_XY
;
501 if ((i
> 1) && (i
< 6)) {
502 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
506 alu
.dst
.chan
= i
% 4;
508 alu
.src
[0].sel
= gpr
;
509 alu
.src
[0].chan
= (base_chan
- (i
% 2));
511 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
513 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
516 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
523 static int evergreen_interp_flat(struct r600_shader_ctx
*ctx
, int input
)
526 struct r600_bytecode_alu alu
;
528 for (i
= 0; i
< 4; i
++) {
529 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
531 alu
.op
= ALU_OP1_INTERP_LOAD_P0
;
533 alu
.dst
.sel
= ctx
->shader
->input
[input
].gpr
;
538 alu
.src
[0].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
543 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
551 * Special export handling in shaders
553 * shader export ARRAY_BASE for EXPORT_POS:
556 * 62, 63 are clip distance vectors
558 * The use of the values exported in 61-63 are controlled by PA_CL_VS_OUT_CNTL:
559 * VS_OUT_MISC_VEC_ENA - enables the use of all fields in export 61
560 * USE_VTX_POINT_SIZE - point size in the X channel of export 61
561 * USE_VTX_EDGE_FLAG - edge flag in the Y channel of export 61
562 * USE_VTX_RENDER_TARGET_INDX - render target index in the Z channel of export 61
563 * USE_VTX_VIEWPORT_INDX - viewport index in the W channel of export 61
564 * USE_VTX_KILL_FLAG - kill flag in the Z channel of export 61 (mutually
565 * exclusive from render target index)
566 * VS_OUT_CCDIST0_VEC_ENA/VS_OUT_CCDIST1_VEC_ENA - enable clip distance vectors
569 * shader export ARRAY_BASE for EXPORT_PIXEL:
571 * 61 computed Z vector
573 * The use of the values exported in the computed Z vector are controlled
574 * by DB_SHADER_CONTROL:
575 * Z_EXPORT_ENABLE - Z as a float in RED
576 * STENCIL_REF_EXPORT_ENABLE - stencil ref as int in GREEN
577 * COVERAGE_TO_MASK_ENABLE - alpha to mask in ALPHA
578 * MASK_EXPORT_ENABLE - pixel sample mask in BLUE
579 * DB_SOURCE_FORMAT - export control restrictions
584 /* Map name/sid pair from tgsi to the 8-bit semantic index for SPI setup */
585 static int r600_spi_sid(struct r600_shader_io
* io
)
587 int index
, name
= io
->name
;
589 /* These params are handled differently, they don't need
590 * semantic indices, so we'll use 0 for them.
592 if (name
== TGSI_SEMANTIC_POSITION
||
593 name
== TGSI_SEMANTIC_PSIZE
||
594 name
== TGSI_SEMANTIC_EDGEFLAG
||
595 name
== TGSI_SEMANTIC_FACE
||
596 name
== TGSI_SEMANTIC_SAMPLEMASK
)
599 if (name
== TGSI_SEMANTIC_GENERIC
) {
600 /* For generic params simply use sid from tgsi */
603 /* For non-generic params - pack name and sid into 8 bits */
604 index
= 0x80 | (name
<<3) | (io
->sid
);
607 /* Make sure that all really used indices have nonzero value, so
608 * we can just compare it to 0 later instead of comparing the name
609 * with different values to detect special cases. */
616 /* we need this to get a common lds index for vs/tcs/tes input/outputs */
617 int r600_get_lds_unique_index(unsigned semantic_name
, unsigned index
)
619 switch (semantic_name
) {
620 case TGSI_SEMANTIC_POSITION
:
622 case TGSI_SEMANTIC_PSIZE
:
624 case TGSI_SEMANTIC_CLIPDIST
:
627 case TGSI_SEMANTIC_GENERIC
:
629 return 4 + index
- 9;
631 /* same explanation as in the default statement,
632 * the only user hitting this is st/nine.
636 /* patch indices are completely separate and thus start from 0 */
637 case TGSI_SEMANTIC_TESSOUTER
:
639 case TGSI_SEMANTIC_TESSINNER
:
641 case TGSI_SEMANTIC_PATCH
:
645 /* Don't fail here. The result of this function is only used
646 * for LS, TCS, TES, and GS, where legacy GL semantics can't
647 * occur, but this function is called for all vertex shaders
648 * before it's known whether LS will be compiled or not.
654 /* turn input into interpolate on EG */
655 static int evergreen_interp_input(struct r600_shader_ctx
*ctx
, int index
)
659 if (ctx
->shader
->input
[index
].spi_sid
) {
660 ctx
->shader
->input
[index
].lds_pos
= ctx
->shader
->nlds
++;
661 if (ctx
->shader
->input
[index
].interpolate
> 0) {
662 evergreen_interp_assign_ij_index(ctx
, index
);
663 r
= evergreen_interp_alu(ctx
, index
);
665 r
= evergreen_interp_flat(ctx
, index
);
671 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
673 struct r600_bytecode_alu alu
;
675 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
676 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
678 for (i
= 0; i
< 4; i
++) {
679 memset(&alu
, 0, sizeof(alu
));
680 alu
.op
= ALU_OP3_CNDGT
;
683 alu
.dst
.sel
= gpr_front
;
684 alu
.src
[0].sel
= ctx
->face_gpr
;
685 alu
.src
[1].sel
= gpr_front
;
686 alu
.src
[2].sel
= gpr_back
;
693 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
700 /* execute a single slot ALU calculation */
701 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
702 int dst_sel
, int dst_chan
,
703 int src0_sel
, unsigned src0_chan_val
,
704 int src1_sel
, unsigned src1_chan_val
)
706 struct r600_bytecode_alu alu
;
709 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
710 for (i
= 0; i
< 4; i
++) {
711 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
713 alu
.src
[0].sel
= src0_sel
;
714 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
715 alu
.src
[0].value
= src0_chan_val
;
717 alu
.src
[0].chan
= src0_chan_val
;
718 alu
.src
[1].sel
= src1_sel
;
719 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
720 alu
.src
[1].value
= src1_chan_val
;
722 alu
.src
[1].chan
= src1_chan_val
;
723 alu
.dst
.sel
= dst_sel
;
725 alu
.dst
.write
= i
== dst_chan
;
727 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
734 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
736 alu
.src
[0].sel
= src0_sel
;
737 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
738 alu
.src
[0].value
= src0_chan_val
;
740 alu
.src
[0].chan
= src0_chan_val
;
741 alu
.src
[1].sel
= src1_sel
;
742 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
743 alu
.src
[1].value
= src1_chan_val
;
745 alu
.src
[1].chan
= src1_chan_val
;
746 alu
.dst
.sel
= dst_sel
;
747 alu
.dst
.chan
= dst_chan
;
750 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
756 /* execute a single slot ALU calculation */
757 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
758 int dst_sel
, int dst_chan
,
759 int src0_sel
, unsigned src0_chan_val
,
760 int src1_sel
, unsigned src1_chan_val
,
761 int src2_sel
, unsigned src2_chan_val
)
763 struct r600_bytecode_alu alu
;
766 /* validate this for other ops */
767 assert(op
== ALU_OP3_MULADD_UINT24
|| op
== ALU_OP3_CNDE_INT
);
768 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
770 alu
.src
[0].sel
= src0_sel
;
771 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
772 alu
.src
[0].value
= src0_chan_val
;
774 alu
.src
[0].chan
= src0_chan_val
;
775 alu
.src
[1].sel
= src1_sel
;
776 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
777 alu
.src
[1].value
= src1_chan_val
;
779 alu
.src
[1].chan
= src1_chan_val
;
780 alu
.src
[2].sel
= src2_sel
;
781 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
782 alu
.src
[2].value
= src2_chan_val
;
784 alu
.src
[2].chan
= src2_chan_val
;
785 alu
.dst
.sel
= dst_sel
;
786 alu
.dst
.chan
= dst_chan
;
789 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
795 /* put it in temp_reg.x */
796 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
798 int temp_reg
, bool is_patch_var
)
802 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
804 Dimension - patch0_offset (input_vals.z),
805 Non-dim - patch0_data_offset (input_vals.w)
807 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
809 ctx
->tess_output_info
, 0,
811 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
817 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
819 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
822 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
824 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
827 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
830 i
= ctx
->shader
->noutput
++;
831 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
832 ctx
->shader
->output
[i
].sid
= 0;
833 ctx
->shader
->output
[i
].gpr
= 0;
834 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
835 ctx
->shader
->output
[i
].write_mask
= 0x4;
836 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
841 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
843 struct r600_bytecode_alu alu
;
846 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
847 alu
.op
= ctx
->inst_info
->op
;
850 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
856 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
858 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
859 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
861 switch (d
->Declaration
.File
) {
862 case TGSI_FILE_INPUT
:
863 for (j
= 0; j
< count
; j
++) {
864 i
= ctx
->shader
->ninput
+ j
;
865 assert(i
< ARRAY_SIZE(ctx
->shader
->input
));
866 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
867 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
868 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
869 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
870 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
871 if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
872 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
873 switch (ctx
->shader
->input
[i
].name
) {
874 case TGSI_SEMANTIC_FACE
:
875 if (ctx
->face_gpr
!= -1)
876 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
878 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
880 case TGSI_SEMANTIC_COLOR
:
883 case TGSI_SEMANTIC_POSITION
:
884 ctx
->fragcoord_input
= i
;
886 case TGSI_SEMANTIC_PRIMID
:
887 /* set this for now */
888 ctx
->shader
->gs_prim_id_input
= true;
889 ctx
->shader
->ps_prim_id_input
= i
;
892 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
893 if ((r
= evergreen_interp_input(ctx
, i
)))
896 } else if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
897 /* FIXME probably skip inputs if they aren't passed in the ring */
898 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
899 ctx
->next_ring_offset
+= 16;
900 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
901 ctx
->shader
->gs_prim_id_input
= true;
904 ctx
->shader
->ninput
+= count
;
906 case TGSI_FILE_OUTPUT
:
907 for (j
= 0; j
< count
; j
++) {
908 i
= ctx
->shader
->noutput
+ j
;
909 assert(i
< ARRAY_SIZE(ctx
->shader
->output
));
910 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
911 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
912 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
913 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
914 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
915 if (ctx
->type
== PIPE_SHADER_VERTEX
||
916 ctx
->type
== PIPE_SHADER_GEOMETRY
||
917 ctx
->type
== PIPE_SHADER_TESS_EVAL
) {
918 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
919 switch (d
->Semantic
.Name
) {
920 case TGSI_SEMANTIC_CLIPDIST
:
922 case TGSI_SEMANTIC_PSIZE
:
923 ctx
->shader
->vs_out_misc_write
= 1;
924 ctx
->shader
->vs_out_point_size
= 1;
926 case TGSI_SEMANTIC_EDGEFLAG
:
927 ctx
->shader
->vs_out_misc_write
= 1;
928 ctx
->shader
->vs_out_edgeflag
= 1;
929 ctx
->edgeflag_output
= i
;
931 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
932 ctx
->shader
->vs_out_misc_write
= 1;
933 ctx
->shader
->vs_out_viewport
= 1;
935 case TGSI_SEMANTIC_LAYER
:
936 ctx
->shader
->vs_out_misc_write
= 1;
937 ctx
->shader
->vs_out_layer
= 1;
939 case TGSI_SEMANTIC_CLIPVERTEX
:
940 ctx
->clip_vertex_write
= TRUE
;
944 if (ctx
->type
== PIPE_SHADER_GEOMETRY
) {
945 ctx
->gs_out_ring_offset
+= 16;
947 } else if (ctx
->type
== PIPE_SHADER_FRAGMENT
) {
948 switch (d
->Semantic
.Name
) {
949 case TGSI_SEMANTIC_COLOR
:
950 ctx
->shader
->nr_ps_max_color_exports
++;
955 ctx
->shader
->noutput
+= count
;
957 case TGSI_FILE_TEMPORARY
:
958 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
959 if (d
->Array
.ArrayID
) {
960 r600_add_gpr_array(ctx
->shader
,
961 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
963 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
968 case TGSI_FILE_CONSTANT
:
969 case TGSI_FILE_SAMPLER
:
970 case TGSI_FILE_SAMPLER_VIEW
:
971 case TGSI_FILE_ADDRESS
:
972 case TGSI_FILE_BUFFER
:
973 case TGSI_FILE_IMAGE
:
974 case TGSI_FILE_MEMORY
:
977 case TGSI_FILE_HW_ATOMIC
:
978 i
= ctx
->shader
->nhwatomic_ranges
;
979 ctx
->shader
->atomics
[i
].start
= d
->Range
.First
;
980 ctx
->shader
->atomics
[i
].end
= d
->Range
.Last
;
981 ctx
->shader
->atomics
[i
].hw_idx
= ctx
->shader
->atomic_base
+ ctx
->shader
->nhwatomic
;
982 ctx
->shader
->atomics
[i
].array_id
= d
->Array
.ArrayID
;
983 ctx
->shader
->atomics
[i
].buffer_id
= d
->Dim
.Index2D
;
984 ctx
->shader
->nhwatomic_ranges
++;
985 ctx
->shader
->nhwatomic
+= count
;
988 case TGSI_FILE_SYSTEM_VALUE
:
989 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
990 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
991 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
992 break; /* Already handled from allocate_system_value_inputs */
993 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
994 if (!ctx
->native_integers
) {
995 struct r600_bytecode_alu alu
;
996 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
998 alu
.op
= ALU_OP1_INT_TO_FLT
;
1000 alu
.src
[0].chan
= 3;
1007 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1011 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1013 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1015 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1016 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1017 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1018 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1019 unsigned temp_reg
= r600_get_temp(ctx
);
1021 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1025 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1028 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1032 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
1034 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1038 for (i
= 0; i
< 2; i
++) {
1039 struct r600_bytecode_alu alu
;
1040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1041 alu
.op
= ALU_OP1_MOV
;
1043 alu
.src
[0].chan
= 0 + i
;
1045 alu
.dst
.chan
= 0 + i
;
1047 alu
.last
= (i
== 1) ? 1 : 0;
1048 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1051 /* ADD r1.z, 1.0f, -r0.x */
1052 struct r600_bytecode_alu alu
;
1053 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1054 alu
.op
= ALU_OP2_ADD
;
1055 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1057 alu
.src
[1].chan
= 0;
1063 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1066 /* ADD r1.z, r1.z, -r1.y */
1067 alu
.op
= ALU_OP2_ADD
;
1069 alu
.src
[0].chan
= 2;
1071 alu
.src
[1].chan
= 1;
1077 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1083 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1089 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1091 struct tgsi_parse_context parse
;
1095 unsigned name
, alternate_name
;
1097 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1099 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1104 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1108 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1109 while (!tgsi_parse_end_of_tokens(&parse
)) {
1110 tgsi_parse_token(&parse
);
1112 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1113 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1114 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1115 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1116 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1118 int interpolate
, location
, k
;
1120 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1121 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1122 inputs
[1].enabled
= true; /* needs SAMPLEID */
1123 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1124 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1125 /* Needs sample positions, currently those are always available */
1127 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1130 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1131 k
= eg_get_interpolator_index(interpolate
, location
);
1133 ctx
->eg_interpolators
[k
].enabled
= true;
1135 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1136 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1137 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1138 for (k
= 0; k
< ARRAY_SIZE(inputs
); k
++) {
1139 if (d
->Semantic
.Name
== inputs
[k
].name
||
1140 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1141 inputs
[k
].enabled
= true;
1148 tgsi_parse_free(&parse
);
1150 for (i
= 0; i
< ARRAY_SIZE(inputs
); i
++) {
1151 boolean enabled
= inputs
[i
].enabled
;
1152 int *reg
= inputs
[i
].reg
;
1153 unsigned name
= inputs
[i
].name
;
1156 int gpr
= gpr_offset
+ num_regs
++;
1157 ctx
->shader
->nsys_inputs
++;
1159 // add to inputs, allocate a gpr
1160 k
= ctx
->shader
->ninput
++;
1161 ctx
->shader
->input
[k
].name
= name
;
1162 ctx
->shader
->input
[k
].sid
= 0;
1163 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1164 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1165 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1169 return gpr_offset
+ num_regs
;
1173 * for evergreen we need to scan the shader to find the number of GPRs we need to
1174 * reserve for interpolation and system values
1176 * we need to know if we are going to emit
1177 * any sample or centroid inputs
1178 * if perspective and linear are required
1180 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1184 struct tgsi_parse_context parse
;
1186 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1188 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1190 /* skip position/face/mask/sampleid */
1191 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1192 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1193 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1194 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1197 k
= eg_get_interpolator_index(
1198 ctx
->info
.input_interpolate
[i
],
1199 ctx
->info
.input_interpolate_loc
[i
]);
1201 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1204 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1208 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1209 while (!tgsi_parse_end_of_tokens(&parse
)) {
1210 tgsi_parse_token(&parse
);
1212 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1213 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1214 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1215 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1216 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1218 int interpolate
, location
, k
;
1220 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1221 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1222 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1223 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1225 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1228 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1229 k
= eg_get_interpolator_index(interpolate
, location
);
1231 ctx
->eg_interpolators
[k
].enabled
= true;
1236 tgsi_parse_free(&parse
);
1238 /* assign gpr to each interpolator according to priority */
1240 for (i
= 0; i
< ARRAY_SIZE(ctx
->eg_interpolators
); i
++) {
1241 if (ctx
->eg_interpolators
[i
].enabled
) {
1242 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1247 /* XXX PULL MODEL and LINE STIPPLE */
1249 num_baryc
= (num_baryc
+ 1) >> 1;
1250 return allocate_system_value_inputs(ctx
, num_baryc
);
1253 /* sample_id_sel == NULL means fetch for current sample */
1254 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1256 struct r600_bytecode_vtx vtx
;
1259 assert(ctx
->fixed_pt_position_gpr
!= -1);
1261 t1
= r600_get_temp(ctx
);
1263 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1264 vtx
.op
= FETCH_OP_VFETCH
;
1265 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1266 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1267 if (sample_id
== NULL
) {
1268 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1272 struct r600_bytecode_alu alu
;
1274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1275 alu
.op
= ALU_OP1_MOV
;
1276 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1280 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1287 vtx
.mega_fetch_count
= 16;
1293 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1294 vtx
.num_format_all
= 2;
1295 vtx
.format_comp_all
= 1;
1296 vtx
.use_const_fields
= 0;
1297 vtx
.offset
= 1; // first element is size of buffer
1298 vtx
.endian
= r600_endian_swap(32);
1299 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1301 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1308 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1309 const struct tgsi_full_src_register
*tgsi_src
,
1310 struct r600_shader_src
*r600_src
)
1312 memset(r600_src
, 0, sizeof(*r600_src
));
1313 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1314 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1315 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1316 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1317 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1318 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1320 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1322 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1323 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1324 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1326 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1327 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1328 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1331 index
= tgsi_src
->Register
.Index
;
1332 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1333 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1334 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1335 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1336 r600_src
->swizzle
[0] = 2; // Z value
1337 r600_src
->swizzle
[1] = 2;
1338 r600_src
->swizzle
[2] = 2;
1339 r600_src
->swizzle
[3] = 2;
1340 r600_src
->sel
= ctx
->face_gpr
;
1341 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1342 r600_src
->swizzle
[0] = 3; // W value
1343 r600_src
->swizzle
[1] = 3;
1344 r600_src
->swizzle
[2] = 3;
1345 r600_src
->swizzle
[3] = 3;
1346 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1347 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1348 r600_src
->swizzle
[0] = 0;
1349 r600_src
->swizzle
[1] = 1;
1350 r600_src
->swizzle
[2] = 4;
1351 r600_src
->swizzle
[3] = 4;
1352 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1353 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1354 r600_src
->swizzle
[0] = 3;
1355 r600_src
->swizzle
[1] = 3;
1356 r600_src
->swizzle
[2] = 3;
1357 r600_src
->swizzle
[3] = 3;
1359 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1360 r600_src
->swizzle
[0] = 0;
1361 r600_src
->swizzle
[1] = 0;
1362 r600_src
->swizzle
[2] = 0;
1363 r600_src
->swizzle
[3] = 0;
1365 } else if (ctx
->type
!= PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1366 r600_src
->swizzle
[0] = 3;
1367 r600_src
->swizzle
[1] = 3;
1368 r600_src
->swizzle
[2] = 3;
1369 r600_src
->swizzle
[3] = 3;
1371 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1372 r600_src
->swizzle
[0] = 2;
1373 r600_src
->swizzle
[1] = 2;
1374 r600_src
->swizzle
[2] = 2;
1375 r600_src
->swizzle
[3] = 2;
1377 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1379 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1381 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1383 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1384 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
1385 r600_src
->sel
= ctx
->tess_input_info
;
1386 r600_src
->swizzle
[0] = 2;
1387 r600_src
->swizzle
[1] = 2;
1388 r600_src
->swizzle
[2] = 2;
1389 r600_src
->swizzle
[3] = 2;
1391 r600_src
->sel
= ctx
->tess_input_info
;
1392 r600_src
->swizzle
[0] = 3;
1393 r600_src
->swizzle
[1] = 3;
1394 r600_src
->swizzle
[2] = 3;
1395 r600_src
->swizzle
[3] = 3;
1397 } else if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1399 r600_src
->swizzle
[0] = 0;
1400 r600_src
->swizzle
[1] = 0;
1401 r600_src
->swizzle
[2] = 0;
1402 r600_src
->swizzle
[3] = 0;
1403 } else if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1405 r600_src
->swizzle
[0] = 3;
1406 r600_src
->swizzle
[1] = 3;
1407 r600_src
->swizzle
[2] = 3;
1408 r600_src
->swizzle
[3] = 3;
1411 if (tgsi_src
->Register
.Indirect
)
1412 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1413 r600_src
->sel
= tgsi_src
->Register
.Index
;
1414 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1416 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1417 if (tgsi_src
->Register
.Dimension
) {
1418 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1419 if (tgsi_src
->Dimension
.Indirect
) {
1420 r600_src
->kc_rel
= 1;
1426 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1427 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1428 unsigned int dst_reg
)
1430 struct r600_bytecode_vtx vtx
;
1431 unsigned int ar_reg
;
1435 struct r600_bytecode_alu alu
;
1437 memset(&alu
, 0, sizeof(alu
));
1439 alu
.op
= ALU_OP2_ADD_INT
;
1440 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1441 alu
.src
[0].chan
= ar_chan
;
1443 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1444 alu
.src
[1].value
= offset
;
1446 alu
.dst
.sel
= dst_reg
;
1447 alu
.dst
.chan
= ar_chan
;
1451 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1456 ar_reg
= ctx
->bc
->ar_reg
;
1459 memset(&vtx
, 0, sizeof(vtx
));
1460 vtx
.buffer_id
= cb_idx
;
1461 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1462 vtx
.src_gpr
= ar_reg
;
1463 vtx
.src_sel_x
= ar_chan
;
1464 vtx
.mega_fetch_count
= 16;
1465 vtx
.dst_gpr
= dst_reg
;
1466 vtx
.dst_sel_x
= 0; /* SEL_X */
1467 vtx
.dst_sel_y
= 1; /* SEL_Y */
1468 vtx
.dst_sel_z
= 2; /* SEL_Z */
1469 vtx
.dst_sel_w
= 3; /* SEL_W */
1470 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1471 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1472 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1473 vtx
.endian
= r600_endian_swap(32);
1474 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1476 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1482 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1484 struct r600_bytecode_vtx vtx
;
1486 unsigned index
= src
->Register
.Index
;
1487 unsigned vtx_id
= src
->Dimension
.Index
;
1488 int offset_reg
= ctx
->gs_rotated_input
[vtx_id
/ 3];
1489 int offset_chan
= vtx_id
% 3;
1492 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1493 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1495 if (offset_reg
== ctx
->gs_rotated_input
[0] && offset_chan
== 2)
1498 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1499 t2
= r600_get_temp(ctx
);
1501 if (src
->Dimension
.Indirect
) {
1503 struct r600_bytecode_alu alu
;
1506 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1507 if (src
->DimIndirect
.Index
> 0) {
1508 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1516 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1517 at least this is what fglrx seems to do. */
1518 for (i
= 0; i
< 3; i
++) {
1519 treg
[i
] = r600_get_temp(ctx
);
1521 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1523 for (i
= 0; i
< 3; i
++) {
1524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1525 alu
.op
= ALU_OP1_MOV
;
1526 alu
.src
[0].sel
= ctx
->gs_rotated_input
[0];
1527 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1528 alu
.dst
.sel
= treg
[i
];
1532 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1536 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1537 alu
.op
= ALU_OP1_MOV
;
1538 alu
.src
[0].sel
= treg
[0];
1543 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1550 if (src
->Register
.Indirect
) {
1552 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1554 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1556 /* pull the value from index_reg */
1557 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1560 V_SQ_ALU_SRC_LITERAL
, first
);
1563 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1566 V_SQ_ALU_SRC_LITERAL
, 4,
1567 offset_reg
, offset_chan
);
1572 index
= src
->Register
.Index
- first
;
1575 memset(&vtx
, 0, sizeof(vtx
));
1576 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1577 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1578 vtx
.src_gpr
= offset_reg
;
1579 vtx
.src_sel_x
= offset_chan
;
1580 vtx
.offset
= index
* 16; /*bytes*/
1581 vtx
.mega_fetch_count
= 16;
1582 vtx
.dst_gpr
= dst_reg
;
1583 vtx
.dst_sel_x
= 0; /* SEL_X */
1584 vtx
.dst_sel_y
= 1; /* SEL_Y */
1585 vtx
.dst_sel_z
= 2; /* SEL_Z */
1586 vtx
.dst_sel_w
= 3; /* SEL_W */
1587 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1588 vtx
.use_const_fields
= 1;
1590 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1593 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1599 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1601 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1604 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1605 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1607 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1608 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1609 /* primitive id is in R0.z */
1610 ctx
->src
[i
].sel
= 0;
1611 ctx
->src
[i
].swizzle
[0] = 2;
1614 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1615 int treg
= r600_get_temp(ctx
);
1617 fetch_gs_input(ctx
, src
, treg
);
1618 ctx
->src
[i
].sel
= treg
;
1619 ctx
->src
[i
].rel
= 0;
1626 /* Tessellation shaders pass outputs to the next shader using LDS.
1628 * LS outputs = TCS(HS) inputs
1629 * TCS(HS) outputs = TES(DS) inputs
1631 * The LDS layout is:
1632 * - TCS inputs for patch 0
1633 * - TCS inputs for patch 1
1634 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1636 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1637 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1638 * - TCS outputs for patch 1
1639 * - Per-patch TCS outputs for patch 1
1640 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1641 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1644 * All three shaders VS(LS), TCS, TES share the same LDS space.
1646 /* this will return with the dw address in temp_reg.x */
1647 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1648 const struct tgsi_full_dst_register
*dst
,
1649 const struct tgsi_full_src_register
*src
,
1650 int stride_bytes_reg
, int stride_bytes_chan
)
1652 struct tgsi_full_dst_register reg
;
1653 ubyte
*name
, *index
, *array_first
;
1656 struct tgsi_shader_info
*info
= &ctx
->info
;
1657 /* Set the register description. The address computation is the same
1658 * for sources and destinations. */
1660 reg
.Register
.File
= src
->Register
.File
;
1661 reg
.Register
.Index
= src
->Register
.Index
;
1662 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1663 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1664 reg
.Indirect
= src
->Indirect
;
1665 reg
.Dimension
= src
->Dimension
;
1666 reg
.DimIndirect
= src
->DimIndirect
;
1670 /* If the register is 2-dimensional (e.g. an array of vertices
1671 * in a primitive), calculate the base address of the vertex. */
1672 if (reg
.Register
.Dimension
) {
1674 if (reg
.Dimension
.Indirect
) {
1676 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1678 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1679 /* pull the value from index_reg */
1683 sel
= V_SQ_ALU_SRC_LITERAL
;
1684 chan
= reg
.Dimension
.Index
;
1687 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1689 stride_bytes_reg
, stride_bytes_chan
,
1696 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1697 name
= info
->input_semantic_name
;
1698 index
= info
->input_semantic_index
;
1699 array_first
= info
->input_array_first
;
1700 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1701 name
= info
->output_semantic_name
;
1702 index
= info
->output_semantic_index
;
1703 array_first
= info
->output_array_first
;
1708 if (reg
.Register
.Indirect
) {
1711 /* Add the relative address of the element. */
1712 if (reg
.Indirect
.ArrayID
)
1713 first
= array_first
[reg
.Indirect
.ArrayID
];
1715 first
= reg
.Register
.Index
;
1717 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1719 /* pull the value from index_reg */
1720 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1722 V_SQ_ALU_SRC_LITERAL
, 16,
1728 param
= r600_get_lds_unique_index(name
[first
],
1732 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1733 index
[reg
.Register
.Index
]);
1736 /* add to base_addr - passed in temp_reg.x */
1738 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1741 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1749 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1750 unsigned dst_reg
, unsigned mask
)
1752 struct r600_bytecode_alu alu
;
1755 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1756 ctx
->bc
->force_add_cf
= 1;
1758 lasti
= tgsi_last_instruction(mask
);
1759 for (i
= 1; i
<= lasti
; i
++) {
1760 if (!(mask
& (1 << i
)))
1763 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1766 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1770 for (i
= 0; i
<= lasti
; i
++) {
1771 if (!(mask
& (1 << i
)))
1774 /* emit an LDS_READ_RET */
1775 memset(&alu
, 0, sizeof(alu
));
1776 alu
.op
= LDS_OP1_LDS_READ_RET
;
1777 alu
.src
[0].sel
= temp_reg
;
1778 alu
.src
[0].chan
= i
;
1779 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1780 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1782 alu
.is_lds_idx_op
= true;
1784 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1788 for (i
= 0; i
<= lasti
; i
++) {
1789 if (!(mask
& (1 << i
)))
1792 /* then read from LDS_OQ_A_POP */
1793 memset(&alu
, 0, sizeof(alu
));
1795 alu
.op
= ALU_OP1_MOV
;
1796 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1797 alu
.src
[0].chan
= 0;
1798 alu
.dst
.sel
= dst_reg
;
1802 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1809 static int fetch_mask(struct tgsi_src_register
*reg
)
1812 mask
|= 1 << reg
->SwizzleX
;
1813 mask
|= 1 << reg
->SwizzleY
;
1814 mask
|= 1 << reg
->SwizzleZ
;
1815 mask
|= 1 << reg
->SwizzleW
;
1819 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1822 unsigned temp_reg
= r600_get_temp(ctx
);
1824 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1825 src
->Register
.Dimension
? false : true);
1829 /* the base address is now in temp.x */
1830 r
= r600_get_byte_address(ctx
, temp_reg
,
1831 NULL
, src
, ctx
->tess_output_info
, 1);
1835 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1841 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1844 unsigned temp_reg
= r600_get_temp(ctx
);
1846 /* t.x = ips * r0.y */
1847 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1849 ctx
->tess_input_info
, 0,
1855 /* the base address is now in temp.x */
1856 r
= r600_get_byte_address(ctx
, temp_reg
,
1857 NULL
, src
, ctx
->tess_input_info
, 1);
1861 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1867 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1870 unsigned temp_reg
= r600_get_temp(ctx
);
1872 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1873 src
->Register
.Dimension
? false : true);
1876 /* the base address is now in temp.x */
1877 r
= r600_get_byte_address(ctx
, temp_reg
,
1879 ctx
->tess_output_info
, 1);
1883 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
, fetch_mask(&src
->Register
));
1889 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1891 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1894 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1895 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1897 if (ctx
->type
== PIPE_SHADER_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1898 int treg
= r600_get_temp(ctx
);
1899 fetch_tes_input(ctx
, src
, treg
);
1900 ctx
->src
[i
].sel
= treg
;
1901 ctx
->src
[i
].rel
= 0;
1903 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1904 int treg
= r600_get_temp(ctx
);
1905 fetch_tcs_input(ctx
, src
, treg
);
1906 ctx
->src
[i
].sel
= treg
;
1907 ctx
->src
[i
].rel
= 0;
1909 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1910 int treg
= r600_get_temp(ctx
);
1911 fetch_tcs_output(ctx
, src
, treg
);
1912 ctx
->src
[i
].sel
= treg
;
1913 ctx
->src
[i
].rel
= 0;
1919 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1921 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1922 struct r600_bytecode_alu alu
;
1923 int i
, j
, k
, nconst
, r
;
1925 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1926 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1929 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1931 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1932 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1936 if (ctx
->src
[i
].rel
) {
1937 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1938 int treg
= r600_get_temp(ctx
);
1939 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1942 ctx
->src
[i
].kc_bank
= 0;
1943 ctx
->src
[i
].kc_rel
= 0;
1944 ctx
->src
[i
].sel
= treg
;
1945 ctx
->src
[i
].rel
= 0;
1948 int treg
= r600_get_temp(ctx
);
1949 for (k
= 0; k
< 4; k
++) {
1950 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1951 alu
.op
= ALU_OP1_MOV
;
1952 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1953 alu
.src
[0].chan
= k
;
1954 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1955 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1956 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1966 ctx
->src
[i
].sel
= treg
;
1974 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1975 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1977 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1978 struct r600_bytecode_alu alu
;
1979 int i
, j
, k
, nliteral
, r
;
1981 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1982 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1986 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1987 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1988 int treg
= r600_get_temp(ctx
);
1989 for (k
= 0; k
< 4; k
++) {
1990 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1991 alu
.op
= ALU_OP1_MOV
;
1992 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1993 alu
.src
[0].chan
= k
;
1994 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
2000 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2004 ctx
->src
[i
].sel
= treg
;
2011 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
2013 int i
, r
, count
= ctx
->shader
->ninput
;
2015 for (i
= 0; i
< count
; i
++) {
2016 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
2017 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
2025 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
2026 int stream
, unsigned *stream_item_size UNUSED
)
2028 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
2029 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
2033 /* Sanity checking. */
2034 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
2035 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2039 for (i
= 0; i
< so
->num_outputs
; i
++) {
2040 if (so
->output
[i
].output_buffer
>= 4) {
2041 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2042 so
->output
[i
].output_buffer
);
2048 /* Initialize locations where the outputs are stored. */
2049 for (i
= 0; i
< so
->num_outputs
; i
++) {
2051 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2052 start_comp
[i
] = so
->output
[i
].start_component
;
2053 /* Lower outputs with dst_offset < start_component.
2055 * We can only output 4D vectors with a write mask, e.g. we can
2056 * only output the W component at offset 3, etc. If we want
2057 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2058 * to move it to X and output X. */
2059 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2060 unsigned tmp
= r600_get_temp(ctx
);
2062 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2063 struct r600_bytecode_alu alu
;
2064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2065 alu
.op
= ALU_OP1_MOV
;
2066 alu
.src
[0].sel
= so_gpr
[i
];
2067 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2072 if (j
== so
->output
[i
].num_components
- 1)
2074 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2083 /* Write outputs to buffers. */
2084 for (i
= 0; i
< so
->num_outputs
; i
++) {
2085 struct r600_bytecode_output output
;
2087 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2090 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2091 output
.gpr
= so_gpr
[i
];
2092 output
.elem_size
= so
->output
[i
].num_components
- 1;
2093 if (output
.elem_size
== 2)
2094 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2095 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2096 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2097 output
.burst_count
= 1;
2098 /* array_size is an upper limit for the burst_count
2099 * with MEM_STREAM instructions */
2100 output
.array_size
= 0xFFF;
2101 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2103 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2104 switch (so
->output
[i
].output_buffer
) {
2106 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2109 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2112 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2115 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2118 output
.op
+= so
->output
[i
].stream
* 4;
2119 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2120 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2122 switch (so
->output
[i
].output_buffer
) {
2124 output
.op
= CF_OP_MEM_STREAM0
;
2127 output
.op
= CF_OP_MEM_STREAM1
;
2130 output
.op
= CF_OP_MEM_STREAM2
;
2133 output
.op
= CF_OP_MEM_STREAM3
;
2136 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2138 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2147 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2149 struct r600_bytecode_alu alu
;
2152 if (!ctx
->shader
->vs_out_edgeflag
)
2155 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2157 /* clamp(x, 0, 1) */
2158 memset(&alu
, 0, sizeof(alu
));
2159 alu
.op
= ALU_OP1_MOV
;
2160 alu
.src
[0].sel
= reg
;
2165 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2167 memset(&alu
, 0, sizeof(alu
));
2168 alu
.op
= ALU_OP1_FLT_TO_INT
;
2169 alu
.src
[0].sel
= reg
;
2173 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2176 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2177 struct r600_pipe_shader
*gs
,
2178 struct pipe_stream_output_info
*so
)
2180 struct r600_shader_ctx ctx
= {};
2181 struct r600_shader
*gs_shader
= &gs
->shader
;
2182 struct r600_pipe_shader
*cshader
;
2183 unsigned ocnt
= gs_shader
->noutput
;
2184 struct r600_bytecode_alu alu
;
2185 struct r600_bytecode_vtx vtx
;
2186 struct r600_bytecode_output output
;
2187 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2188 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2189 int next_clip_pos
= 61, next_param
= 0;
2192 bool only_ring_0
= true;
2193 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2197 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2198 sizeof(struct r600_shader_io
));
2200 cshader
->shader
.noutput
= ocnt
;
2202 ctx
.shader
= &cshader
->shader
;
2203 ctx
.bc
= &ctx
.shader
->bc
;
2204 ctx
.type
= ctx
.bc
->type
= PIPE_SHADER_VERTEX
;
2206 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2207 rctx
->screen
->has_compressed_msaa_texturing
);
2209 ctx
.bc
->isa
= rctx
->isa
;
2212 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2214 /* R0.x = R0.x & 0x3fffffff */
2215 memset(&alu
, 0, sizeof(alu
));
2216 alu
.op
= ALU_OP2_AND_INT
;
2217 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2218 alu
.src
[1].value
= 0x3fffffff;
2220 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2222 /* R0.y = R0.x >> 30 */
2223 memset(&alu
, 0, sizeof(alu
));
2224 alu
.op
= ALU_OP2_LSHR_INT
;
2225 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2226 alu
.src
[1].value
= 0x1e;
2230 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2232 /* fetch vertex data from GSVS ring */
2233 for (i
= 0; i
< ocnt
; ++i
) {
2234 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2237 out
->ring_offset
= i
* 16;
2239 memset(&vtx
, 0, sizeof(vtx
));
2240 vtx
.op
= FETCH_OP_VFETCH
;
2241 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2242 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2243 vtx
.mega_fetch_count
= 16;
2244 vtx
.offset
= out
->ring_offset
;
2245 vtx
.dst_gpr
= out
->gpr
;
2251 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2252 vtx
.use_const_fields
= 1;
2254 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2257 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2259 ctx
.temp_reg
= i
+ 1;
2260 for (ring
= 3; ring
>= 0; --ring
) {
2261 bool enabled
= false;
2262 for (i
= 0; i
< so
->num_outputs
; i
++) {
2263 if (so
->output
[i
].stream
== ring
) {
2266 only_ring_0
= false;
2270 if (ring
!= 0 && !enabled
) {
2271 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2276 // Patch up jump label
2277 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2278 cf_pop
= ctx
.bc
->cf_last
;
2280 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2281 cf_jump
->pop_count
= 1;
2282 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2283 cf_pop
->pop_count
= 1;
2286 /* PRED_SETE_INT __, R0.y, ring */
2287 memset(&alu
, 0, sizeof(alu
));
2288 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2289 alu
.src
[0].chan
= 1;
2290 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2291 alu
.src
[1].value
= ring
;
2292 alu
.execute_mask
= 1;
2293 alu
.update_pred
= 1;
2295 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2297 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2298 cf_jump
= ctx
.bc
->cf_last
;
2301 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2302 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2305 /* bc adds nops - copy it */
2306 if (ctx
.bc
->chip_class
== R600
) {
2307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2308 alu
.op
= ALU_OP0_NOP
;
2310 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2312 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2315 /* export vertex data */
2316 /* XXX factor out common code with r600_shader_from_tgsi ? */
2317 for (i
= 0; i
< ocnt
; ++i
) {
2318 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2319 bool instream0
= true;
2320 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2323 for (j
= 0; j
< so
->num_outputs
; j
++) {
2324 if (so
->output
[j
].register_index
== i
) {
2325 if (so
->output
[j
].stream
== 0)
2327 if (so
->output
[j
].stream
> 0)
2333 memset(&output
, 0, sizeof(output
));
2334 output
.gpr
= out
->gpr
;
2335 output
.elem_size
= 3;
2336 output
.swizzle_x
= 0;
2337 output
.swizzle_y
= 1;
2338 output
.swizzle_z
= 2;
2339 output
.swizzle_w
= 3;
2340 output
.burst_count
= 1;
2341 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2342 output
.op
= CF_OP_EXPORT
;
2343 switch (out
->name
) {
2344 case TGSI_SEMANTIC_POSITION
:
2345 output
.array_base
= 60;
2346 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2349 case TGSI_SEMANTIC_PSIZE
:
2350 output
.array_base
= 61;
2351 if (next_clip_pos
== 61)
2353 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2354 output
.swizzle_y
= 7;
2355 output
.swizzle_z
= 7;
2356 output
.swizzle_w
= 7;
2357 ctx
.shader
->vs_out_misc_write
= 1;
2358 ctx
.shader
->vs_out_point_size
= 1;
2360 case TGSI_SEMANTIC_LAYER
:
2362 /* duplicate it as PARAM to pass to the pixel shader */
2363 output
.array_base
= next_param
++;
2364 r600_bytecode_add_output(ctx
.bc
, &output
);
2365 last_exp_param
= ctx
.bc
->cf_last
;
2367 output
.array_base
= 61;
2368 if (next_clip_pos
== 61)
2370 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2371 output
.swizzle_x
= 7;
2372 output
.swizzle_y
= 7;
2373 output
.swizzle_z
= 0;
2374 output
.swizzle_w
= 7;
2375 ctx
.shader
->vs_out_misc_write
= 1;
2376 ctx
.shader
->vs_out_layer
= 1;
2378 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2380 /* duplicate it as PARAM to pass to the pixel shader */
2381 output
.array_base
= next_param
++;
2382 r600_bytecode_add_output(ctx
.bc
, &output
);
2383 last_exp_param
= ctx
.bc
->cf_last
;
2385 output
.array_base
= 61;
2386 if (next_clip_pos
== 61)
2388 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2389 ctx
.shader
->vs_out_misc_write
= 1;
2390 ctx
.shader
->vs_out_viewport
= 1;
2391 output
.swizzle_x
= 7;
2392 output
.swizzle_y
= 7;
2393 output
.swizzle_z
= 7;
2394 output
.swizzle_w
= 0;
2396 case TGSI_SEMANTIC_CLIPDIST
:
2397 /* spi_sid is 0 for clipdistance outputs that were generated
2398 * for clipvertex - we don't need to pass them to PS */
2399 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2400 ctx
.shader
->cull_dist_write
= gs
->shader
.cull_dist_write
;
2401 ctx
.shader
->cc_dist_mask
= gs
->shader
.cc_dist_mask
;
2403 /* duplicate it as PARAM to pass to the pixel shader */
2404 output
.array_base
= next_param
++;
2405 r600_bytecode_add_output(ctx
.bc
, &output
);
2406 last_exp_param
= ctx
.bc
->cf_last
;
2408 output
.array_base
= next_clip_pos
++;
2409 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2411 case TGSI_SEMANTIC_FOG
:
2412 output
.swizzle_y
= 4; /* 0 */
2413 output
.swizzle_z
= 4; /* 0 */
2414 output
.swizzle_w
= 5; /* 1 */
2417 output
.array_base
= next_param
++;
2420 r600_bytecode_add_output(ctx
.bc
, &output
);
2421 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2422 last_exp_param
= ctx
.bc
->cf_last
;
2424 last_exp_pos
= ctx
.bc
->cf_last
;
2427 if (!last_exp_pos
) {
2428 memset(&output
, 0, sizeof(output
));
2430 output
.elem_size
= 3;
2431 output
.swizzle_x
= 7;
2432 output
.swizzle_y
= 7;
2433 output
.swizzle_z
= 7;
2434 output
.swizzle_w
= 7;
2435 output
.burst_count
= 1;
2437 output
.op
= CF_OP_EXPORT
;
2438 output
.array_base
= 60;
2439 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2440 r600_bytecode_add_output(ctx
.bc
, &output
);
2441 last_exp_pos
= ctx
.bc
->cf_last
;
2444 if (!last_exp_param
) {
2445 memset(&output
, 0, sizeof(output
));
2447 output
.elem_size
= 3;
2448 output
.swizzle_x
= 7;
2449 output
.swizzle_y
= 7;
2450 output
.swizzle_z
= 7;
2451 output
.swizzle_w
= 7;
2452 output
.burst_count
= 1;
2454 output
.op
= CF_OP_EXPORT
;
2455 output
.array_base
= next_param
++;
2456 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2457 r600_bytecode_add_output(ctx
.bc
, &output
);
2458 last_exp_param
= ctx
.bc
->cf_last
;
2461 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2462 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2464 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2465 cf_pop
= ctx
.bc
->cf_last
;
2467 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2468 cf_jump
->pop_count
= 1;
2469 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2470 cf_pop
->pop_count
= 1;
2472 if (ctx
.bc
->chip_class
== CAYMAN
)
2473 cm_bytecode_add_cf_end(ctx
.bc
);
2475 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2476 ctx
.bc
->cf_last
->end_of_program
= 1;
2479 gs
->gs_copy_shader
= cshader
;
2480 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2484 return r600_bytecode_build(ctx
.bc
);
2487 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2490 struct r600_bytecode_alu alu
;
2493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2494 alu
.op
= ALU_OP2_ADD_INT
;
2495 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2496 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2497 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2498 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2501 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2508 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so UNUSED
, int stream
, bool ind
)
2510 struct r600_bytecode_output output
;
2513 int effective_stream
= stream
== -1 ? 0 : stream
;
2516 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2517 if (ctx
->gs_for_vs
) {
2518 /* for ES we need to lookup corresponding ring offset expected by GS
2519 * (map this output to GS input by name and sid) */
2520 /* FIXME precompute offsets */
2522 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2523 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2524 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2525 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2526 ring_offset
= in
->ring_offset
;
2529 if (ring_offset
== -1)
2532 ring_offset
= idx
* 16;
2536 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2538 /* next_ring_offset after parsing input decls contains total size of
2539 * single vertex data, gs_next_vertex - current vertex index */
2541 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2543 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2544 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2545 output
.elem_size
= 3;
2546 output
.comp_mask
= 0xF;
2547 output
.burst_count
= 1;
2550 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2552 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2557 output
.op
= CF_OP_MEM_RING
; break;
2559 output
.op
= CF_OP_MEM_RING1
; break;
2561 output
.op
= CF_OP_MEM_RING2
; break;
2563 output
.op
= CF_OP_MEM_RING3
; break;
2567 output
.array_base
= ring_offset
>> 2; /* in dwords */
2568 output
.array_size
= 0xfff;
2569 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2571 output
.array_base
= ring_offset
>> 2; /* in dwords */
2572 r600_bytecode_add_output(ctx
->bc
, &output
);
2575 ++ctx
->gs_next_vertex
;
2580 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2583 struct r600_bytecode_vtx vtx
;
2584 int temp_val
= ctx
->temp_reg
;
2585 /* need to store the TCS output somewhere */
2586 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2588 V_SQ_ALU_SRC_LITERAL
, 0,
2593 /* used by VS/TCS */
2594 if (ctx
->tess_input_info
) {
2595 /* fetch tcs input values into resv space */
2596 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2597 vtx
.op
= FETCH_OP_VFETCH
;
2598 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2599 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2600 vtx
.mega_fetch_count
= 16;
2601 vtx
.data_format
= FMT_32_32_32_32
;
2602 vtx
.num_format_all
= 2;
2603 vtx
.format_comp_all
= 1;
2604 vtx
.use_const_fields
= 0;
2605 vtx
.endian
= r600_endian_swap(32);
2606 vtx
.srf_mode_all
= 1;
2608 vtx
.dst_gpr
= ctx
->tess_input_info
;
2613 vtx
.src_gpr
= temp_val
;
2616 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2621 /* used by TCS/TES */
2622 if (ctx
->tess_output_info
) {
2623 /* fetch tcs output values into resv space */
2624 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2625 vtx
.op
= FETCH_OP_VFETCH
;
2626 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2627 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2628 vtx
.mega_fetch_count
= 16;
2629 vtx
.data_format
= FMT_32_32_32_32
;
2630 vtx
.num_format_all
= 2;
2631 vtx
.format_comp_all
= 1;
2632 vtx
.use_const_fields
= 0;
2633 vtx
.endian
= r600_endian_swap(32);
2634 vtx
.srf_mode_all
= 1;
2636 vtx
.dst_gpr
= ctx
->tess_output_info
;
2641 vtx
.src_gpr
= temp_val
;
2644 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2651 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2657 /* fetch tcs input values into input_vals */
2658 ctx
->tess_input_info
= r600_get_temp(ctx
);
2659 ctx
->tess_output_info
= 0;
2660 r
= r600_fetch_tess_io_info(ctx
);
2664 temp_reg
= r600_get_temp(ctx
);
2665 /* dst reg contains LDS address stride * idx */
2666 /* MUL vertexID, vertex_dw_stride */
2667 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2669 ctx
->tess_input_info
, 1,
2670 0, 1); /* rel id in r0.y? */
2674 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2675 struct r600_bytecode_alu alu
;
2676 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2679 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2682 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2687 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2689 temp_reg
, param
? 1 : 0,
2690 V_SQ_ALU_SRC_LITERAL
, 8);
2695 for (j
= 0; j
< 2; j
++) {
2696 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2697 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2698 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2699 alu
.src
[0].sel
= temp_reg
;
2700 alu
.src
[0].chan
= chan
;
2701 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2702 alu
.src
[1].chan
= j
* 2;
2703 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2704 alu
.src
[2].chan
= (j
* 2) + 1;
2708 alu
.is_lds_idx_op
= true;
2709 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2717 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2719 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2720 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2722 int temp_reg
= r600_get_temp(ctx
);
2723 struct r600_bytecode_alu alu
;
2724 unsigned write_mask
= dst
->Register
.WriteMask
;
2726 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2729 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2733 /* the base address is now in temp.x */
2734 r
= r600_get_byte_address(ctx
, temp_reg
,
2735 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2740 lasti
= tgsi_last_instruction(write_mask
);
2741 for (i
= 1; i
<= lasti
; i
++) {
2743 if (!(write_mask
& (1 << i
)))
2745 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2748 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2753 for (i
= 0; i
<= lasti
; i
++) {
2754 if (!(write_mask
& (1 << i
)))
2757 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2758 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2759 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2760 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2761 alu
.src
[0].sel
= temp_reg
;
2762 alu
.src
[0].chan
= i
;
2764 alu
.src
[1].sel
= dst
->Register
.Index
;
2765 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2766 alu
.src
[1].chan
= i
;
2768 alu
.src
[2].sel
= dst
->Register
.Index
;
2769 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2770 alu
.src
[2].chan
= i
+ 1;
2774 alu
.is_lds_idx_op
= true;
2775 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2781 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2782 alu
.op
= LDS_OP2_LDS_WRITE
;
2783 alu
.src
[0].sel
= temp_reg
;
2784 alu
.src
[0].chan
= i
;
2786 alu
.src
[1].sel
= dst
->Register
.Index
;
2787 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2788 alu
.src
[1].chan
= i
;
2790 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2793 alu
.is_lds_idx_op
= true;
2794 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2801 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2805 unsigned temp_reg
= r600_get_temp(ctx
);
2806 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2807 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2810 param
= r600_get_lds_unique_index(name
, 0);
2811 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2815 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2818 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2822 do_lds_fetch_values(ctx
, temp_reg
, dreg
, 0xf);
2826 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2828 int stride
, outer_comps
, inner_comps
;
2829 int tessinner_idx
= -1, tessouter_idx
= -1;
2832 int temp_reg
= r600_get_temp(ctx
);
2833 int treg
[3] = {-1, -1, -1};
2834 struct r600_bytecode_alu alu
;
2835 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2837 /* only execute factor emission for invocation 0 */
2838 /* PRED_SETE_INT __, R0.x, 0 */
2839 memset(&alu
, 0, sizeof(alu
));
2840 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2841 alu
.src
[0].chan
= 2;
2842 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2843 alu
.execute_mask
= 1;
2844 alu
.update_pred
= 1;
2846 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2848 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2849 cf_jump
= ctx
->bc
->cf_last
;
2851 treg
[0] = r600_get_temp(ctx
);
2852 switch (ctx
->shader
->tcs_prim_mode
) {
2853 case PIPE_PRIM_LINES
:
2854 stride
= 8; /* 2 dwords, 1 vec2 store */
2858 case PIPE_PRIM_TRIANGLES
:
2859 stride
= 16; /* 4 dwords, 1 vec4 store */
2862 treg
[1] = r600_get_temp(ctx
);
2864 case PIPE_PRIM_QUADS
:
2865 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2868 treg
[1] = r600_get_temp(ctx
);
2869 treg
[2] = r600_get_temp(ctx
);
2876 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2877 /* TF_WRITE takes index in R.x, value in R.y */
2878 for (j
= 0; j
< ctx
->shader
->noutput
; j
++) {
2879 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSINNER
)
2881 if (ctx
->shader
->output
[j
].name
== TGSI_SEMANTIC_TESSOUTER
)
2885 if (tessouter_idx
== -1)
2888 if (tessinner_idx
== -1 && inner_comps
)
2891 if (tessouter_idx
!= -1) {
2892 r
= r600_tess_factor_read(ctx
, tessouter_idx
);
2897 if (tessinner_idx
!= -1) {
2898 r
= r600_tess_factor_read(ctx
, tessinner_idx
);
2903 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2904 /* r.x = relpatchid(r0.y) * tf_stride */
2906 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2907 /* add incoming r0.w to it: t.x = t.x + r0.w */
2908 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2911 V_SQ_ALU_SRC_LITERAL
, stride
,
2916 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2917 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2918 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2920 if (ctx
->shader
->tcs_prim_mode
== PIPE_PRIM_LINES
) {
2923 else if (out_comp
== 0)
2927 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2928 treg
[i
/ 2], (2 * (i
% 2)),
2930 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2933 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2934 treg
[i
/ 2], 1 + (2 * (i
%2)),
2935 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
2940 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2941 struct r600_bytecode_gds gds
;
2943 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
2944 gds
.src_gpr
= treg
[i
/ 2];
2945 gds
.src_sel_x
= 2 * (i
% 2);
2946 gds
.src_sel_y
= 1 + (2 * (i
% 2));
2952 gds
.op
= FETCH_OP_TF_WRITE
;
2953 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
2958 // Patch up jump label
2959 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
2960 cf_pop
= ctx
->bc
->cf_last
;
2962 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2963 cf_jump
->pop_count
= 1;
2964 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2965 cf_pop
->pop_count
= 1;
2971 * We have to work out the thread ID for load and atomic
2972 * operations, which store the returned value to an index
2973 * in an intermediate buffer.
2974 * The index is calculated by taking the thread id,
2975 * calculated from the MBCNT instructions.
2976 * Then the shader engine ID is multiplied by 256,
2977 * and the wave id is added.
2978 * Then the result is multipled by 64 and thread id is
2981 static int load_thread_id_gpr(struct r600_shader_ctx
*ctx
)
2983 struct r600_bytecode_alu alu
;
2986 if (ctx
->thread_id_gpr_loaded
)
2989 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2990 alu
.op
= ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT
;
2991 alu
.dst
.sel
= ctx
->temp_reg
;
2993 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
2994 alu
.src
[0].value
= 0xffffffff;
2996 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3000 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3001 alu
.op
= ALU_OP1_MBCNT_32HI_INT
;
3002 alu
.dst
.sel
= ctx
->temp_reg
;
3004 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3005 alu
.src
[0].value
= 0xffffffff;
3007 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3011 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3012 alu
.op
= ALU_OP3_MULADD_UINT24
;
3013 alu
.dst
.sel
= ctx
->temp_reg
;
3015 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_SE_ID
;
3016 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
3017 alu
.src
[1].value
= 256;
3018 alu
.src
[2].sel
= EG_V_SQ_ALU_SRC_HW_WAVE_ID
;
3022 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3026 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
3027 ctx
->thread_id_gpr
, 1,
3029 V_SQ_ALU_SRC_LITERAL
, 0x40,
3033 ctx
->thread_id_gpr_loaded
= true;
3037 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
3038 struct r600_pipe_shader
*pipeshader
,
3039 union r600_shader_key key
)
3041 struct r600_screen
*rscreen
= rctx
->screen
;
3042 struct r600_shader
*shader
= &pipeshader
->shader
;
3043 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
3044 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
3045 struct tgsi_full_immediate
*immediate
;
3046 struct r600_shader_ctx ctx
;
3047 struct r600_bytecode_output output
[ARRAY_SIZE(shader
->output
)];
3048 unsigned output_done
, noutput
;
3052 int next_param_base
= 0, next_clip_base
;
3053 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
3055 bool ring_outputs
= false;
3056 bool lds_outputs
= false;
3057 bool lds_inputs
= false;
3058 bool pos_emitted
= false;
3060 ctx
.bc
= &shader
->bc
;
3061 ctx
.shader
= shader
;
3062 ctx
.native_integers
= true;
3064 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
3065 rscreen
->has_compressed_msaa_texturing
);
3066 ctx
.tokens
= tokens
;
3067 tgsi_scan_shader(tokens
, &ctx
.info
);
3068 shader
->indirect_files
= ctx
.info
.indirect_files
;
3070 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
3071 shader
->uses_atomics
= ctx
.info
.file_mask
[TGSI_FILE_HW_ATOMIC
];
3072 shader
->nsys_inputs
= 0;
3074 shader
->uses_images
= ctx
.info
.file_count
[TGSI_FILE_IMAGE
] > 0 ||
3075 ctx
.info
.file_count
[TGSI_FILE_BUFFER
] > 0;
3076 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
3077 tgsi_parse_init(&ctx
.parse
, tokens
);
3078 ctx
.type
= ctx
.info
.processor
;
3079 shader
->processor_type
= ctx
.type
;
3080 ctx
.bc
->type
= shader
->processor_type
;
3083 case PIPE_SHADER_VERTEX
:
3084 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
3085 shader
->vs_as_es
= key
.vs
.as_es
;
3086 shader
->vs_as_ls
= key
.vs
.as_ls
;
3087 shader
->atomic_base
= key
.vs
.first_atomic_counter
;
3088 if (shader
->vs_as_es
)
3089 ring_outputs
= true;
3090 if (shader
->vs_as_ls
)
3093 case PIPE_SHADER_GEOMETRY
:
3094 ring_outputs
= true;
3095 shader
->atomic_base
= key
.gs
.first_atomic_counter
;
3096 shader
->gs_tri_strip_adj_fix
= key
.gs
.tri_strip_adj_fix
;
3098 case PIPE_SHADER_TESS_CTRL
:
3099 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
3100 shader
->atomic_base
= key
.tcs
.first_atomic_counter
;
3104 case PIPE_SHADER_TESS_EVAL
:
3105 shader
->tes_as_es
= key
.tes
.as_es
;
3106 shader
->atomic_base
= key
.tes
.first_atomic_counter
;
3108 if (shader
->tes_as_es
)
3109 ring_outputs
= true;
3111 case PIPE_SHADER_FRAGMENT
:
3112 shader
->two_side
= key
.ps
.color_two_side
;
3113 shader
->atomic_base
= key
.ps
.first_atomic_counter
;
3114 shader
->rat_base
= key
.ps
.nr_cbufs
;
3115 shader
->image_size_const_offset
= key
.ps
.image_size_const_offset
;
3121 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3122 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3124 ctx
.gs_for_vs
= NULL
;
3127 ctx
.next_ring_offset
= 0;
3128 ctx
.gs_out_ring_offset
= 0;
3129 ctx
.gs_next_vertex
= 0;
3130 ctx
.gs_stream_output_info
= &so
;
3133 ctx
.fixed_pt_position_gpr
= -1;
3134 ctx
.fragcoord_input
= -1;
3135 ctx
.colors_used
= 0;
3136 ctx
.clip_vertex_write
= 0;
3137 ctx
.thread_id_gpr_loaded
= false;
3139 shader
->nr_ps_color_exports
= 0;
3140 shader
->nr_ps_max_color_exports
= 0;
3143 /* register allocations */
3144 /* Values [0,127] correspond to GPR[0..127].
3145 * Values [128,159] correspond to constant buffer bank 0
3146 * Values [160,191] correspond to constant buffer bank 1
3147 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3148 * Values [256,287] correspond to constant buffer bank 2 (EG)
3149 * Values [288,319] correspond to constant buffer bank 3 (EG)
3150 * Other special values are shown in the list below.
3151 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3152 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3153 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3154 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3155 * 248 SQ_ALU_SRC_0: special constant 0.0.
3156 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3157 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3158 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3159 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3160 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3161 * 254 SQ_ALU_SRC_PV: previous vector result.
3162 * 255 SQ_ALU_SRC_PS: previous scalar result.
3164 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3165 ctx
.file_offset
[i
] = 0;
3168 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3170 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3171 if (ctx
.info
.num_inputs
)
3172 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3174 if (ctx
.type
== PIPE_SHADER_FRAGMENT
) {
3175 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3176 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3178 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3180 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3181 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3182 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3184 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3185 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3186 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3187 bool add_tesscoord
= false, add_tess_inout
= false;
3188 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3189 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3190 /* if we have tesscoord save one reg */
3191 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3192 add_tesscoord
= true;
3193 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3194 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3195 add_tess_inout
= true;
3197 if (add_tesscoord
|| add_tess_inout
)
3198 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3200 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3203 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3204 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3205 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3206 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3207 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3209 /* Outside the GPR range. This will be translated to one of the
3210 * kcache banks later. */
3211 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3213 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3214 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3215 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3216 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3217 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3219 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3220 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3221 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3222 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3223 } else if (ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3224 ctx
.tess_input_info
= 0;
3225 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3226 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3227 } else if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3228 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3229 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3230 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3231 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3232 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3233 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3234 ctx
.gs_rotated_input
[0] = ctx
.bc
->ar_reg
+ 7;
3235 ctx
.gs_rotated_input
[1] = ctx
.bc
->ar_reg
+ 8;
3238 ctx
.gs_rotated_input
[0] = 0;
3239 ctx
.gs_rotated_input
[1] = 1;
3242 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3245 if (shader
->uses_images
) {
3246 ctx
.thread_id_gpr
= ctx
.temp_reg
++;
3247 ctx
.thread_id_gpr_loaded
= false;
3250 shader
->max_arrays
= 0;
3251 shader
->num_arrays
= 0;
3252 if (indirect_gprs
) {
3254 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3255 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3256 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3257 ctx
.file_offset
[TGSI_FILE_INPUT
],
3260 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3261 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3262 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3263 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3269 ctx
.literals
= NULL
;
3271 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3272 ctx
.info
.colors_written
== 1;
3273 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3274 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3276 if (ctx
.type
== PIPE_SHADER_VERTEX
||
3277 ctx
.type
== PIPE_SHADER_GEOMETRY
||
3278 ctx
.type
== PIPE_SHADER_TESS_EVAL
) {
3279 shader
->cc_dist_mask
= (1 << (ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
] +
3280 ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
])) - 1;
3281 shader
->clip_dist_write
= (1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
]) - 1;
3282 shader
->cull_dist_write
= ((1 << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CULLDIST_ENABLED
]) - 1) << ctx
.info
.properties
[TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
];
3285 if (shader
->vs_as_gs_a
)
3286 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3288 if (ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3289 r600_fetch_tess_io_info(&ctx
);
3291 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3292 tgsi_parse_token(&ctx
.parse
);
3293 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3294 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3295 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3296 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3297 if(ctx
.literals
== NULL
) {
3301 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3302 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3303 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3304 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3307 case TGSI_TOKEN_TYPE_DECLARATION
:
3308 r
= tgsi_declaration(&ctx
);
3312 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3313 case TGSI_TOKEN_TYPE_PROPERTY
:
3316 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3322 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3323 shader
->ring_item_sizes
[1] = 0;
3324 shader
->ring_item_sizes
[2] = 0;
3325 shader
->ring_item_sizes
[3] = 0;
3327 /* Process two side if needed */
3328 if (shader
->two_side
&& ctx
.colors_used
) {
3329 int i
, count
= ctx
.shader
->ninput
;
3330 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3332 /* additional inputs will be allocated right after the existing inputs,
3333 * we won't need them after the color selection, so we don't need to
3334 * reserve these gprs for the rest of the shader code and to adjust
3335 * output offsets etc. */
3336 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3337 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3339 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3340 if (ctx
.face_gpr
== -1) {
3341 i
= ctx
.shader
->ninput
++;
3342 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3343 ctx
.shader
->input
[i
].spi_sid
= 0;
3344 ctx
.shader
->input
[i
].gpr
= gpr
++;
3345 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3348 for (i
= 0; i
< count
; i
++) {
3349 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3350 int ni
= ctx
.shader
->ninput
++;
3351 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3352 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3353 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3354 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3355 // TGSI to LLVM needs to know the lds position of inputs.
3356 // Non LLVM path computes it later (in process_twoside_color)
3357 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3358 ctx
.shader
->input
[i
].back_color_input
= ni
;
3359 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3360 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3367 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3368 shader
->nr_ps_max_color_exports
= 8;
3370 if (ctx
.fragcoord_input
>= 0) {
3371 if (ctx
.bc
->chip_class
== CAYMAN
) {
3372 for (j
= 0 ; j
< 4; j
++) {
3373 struct r600_bytecode_alu alu
;
3374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3375 alu
.op
= ALU_OP1_RECIP_IEEE
;
3376 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3377 alu
.src
[0].chan
= 3;
3379 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3381 alu
.dst
.write
= (j
== 3);
3383 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3387 struct r600_bytecode_alu alu
;
3388 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3389 alu
.op
= ALU_OP1_RECIP_IEEE
;
3390 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3391 alu
.src
[0].chan
= 3;
3393 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3397 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3402 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3403 struct r600_bytecode_alu alu
;
3406 /* GS thread with no output workaround - emit a cut at start of GS */
3407 if (ctx
.bc
->chip_class
== R600
)
3408 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3410 for (j
= 0; j
< 4; j
++) {
3411 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3412 alu
.op
= ALU_OP1_MOV
;
3413 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3414 alu
.src
[0].value
= 0;
3415 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3418 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3423 if (ctx
.shader
->gs_tri_strip_adj_fix
) {
3424 r
= single_alu_op2(&ctx
, ALU_OP2_AND_INT
,
3425 ctx
.gs_rotated_input
[0], 2,
3427 V_SQ_ALU_SRC_LITERAL
, 1);
3431 for (i
= 0; i
< 6; i
++) {
3432 int rotated
= (i
+ 4) % 6;
3433 int offset_reg
= i
/ 3;
3434 int offset_chan
= i
% 3;
3435 int rotated_offset_reg
= rotated
/ 3;
3436 int rotated_offset_chan
= rotated
% 3;
3438 if (offset_reg
== 0 && offset_chan
== 2)
3440 if (rotated_offset_reg
== 0 && rotated_offset_chan
== 2)
3441 rotated_offset_chan
= 3;
3443 r
= single_alu_op3(&ctx
, ALU_OP3_CNDE_INT
,
3444 ctx
.gs_rotated_input
[offset_reg
], offset_chan
,
3445 ctx
.gs_rotated_input
[0], 2,
3446 offset_reg
, offset_chan
,
3447 rotated_offset_reg
, rotated_offset_chan
);
3454 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3455 r600_fetch_tess_io_info(&ctx
);
3457 if (shader
->two_side
&& ctx
.colors_used
) {
3458 if ((r
= process_twoside_color_inputs(&ctx
)))
3462 tgsi_parse_init(&ctx
.parse
, tokens
);
3463 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3464 tgsi_parse_token(&ctx
.parse
);
3465 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3466 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3467 r
= tgsi_is_supported(&ctx
);
3470 ctx
.max_driver_temp_used
= 0;
3471 /* reserve first tmp for everyone */
3472 r600_get_temp(&ctx
);
3474 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3475 if ((r
= tgsi_split_constant(&ctx
)))
3477 if ((r
= tgsi_split_literal_constant(&ctx
)))
3479 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3480 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3482 } else if (lds_inputs
) {
3483 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3486 if (ctx
.bc
->chip_class
== CAYMAN
)
3487 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3488 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3489 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3491 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3492 r
= ctx
.inst_info
->process(&ctx
);
3496 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
) {
3497 r
= r600_store_tcs_output(&ctx
);
3507 /* Reset the temporary register counter. */
3508 ctx
.max_driver_temp_used
= 0;
3510 noutput
= shader
->noutput
;
3512 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3513 unsigned clipdist_temp
[2];
3515 clipdist_temp
[0] = r600_get_temp(&ctx
);
3516 clipdist_temp
[1] = r600_get_temp(&ctx
);
3518 /* need to convert a clipvertex write into clipdistance writes and not export
3519 the clip vertex anymore */
3521 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3522 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3523 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3525 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3526 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3529 /* reset spi_sid for clipvertex output to avoid confusing spi */
3530 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3532 shader
->clip_dist_write
= 0xFF;
3533 shader
->cc_dist_mask
= 0xFF;
3535 for (i
= 0; i
< 8; i
++) {
3539 for (j
= 0; j
< 4; j
++) {
3540 struct r600_bytecode_alu alu
;
3541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3542 alu
.op
= ALU_OP2_DOT4
;
3543 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3544 alu
.src
[0].chan
= j
;
3546 alu
.src
[1].sel
= 512 + i
;
3547 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3548 alu
.src
[1].chan
= j
;
3550 alu
.dst
.sel
= clipdist_temp
[oreg
];
3552 alu
.dst
.write
= (j
== ochan
);
3555 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3562 /* Add stream outputs. */
3563 if (so
.num_outputs
) {
3565 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== PIPE_SHADER_VERTEX
)
3567 if (!ring_outputs
&& ctx
.type
== PIPE_SHADER_TESS_EVAL
)
3570 emit_streamout(&ctx
, &so
, -1, NULL
);
3572 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3573 convert_edgeflag_to_int(&ctx
);
3575 if (ctx
.type
== PIPE_SHADER_TESS_CTRL
)
3576 r600_emit_tess_factor(&ctx
);
3579 if (ctx
.type
== PIPE_SHADER_VERTEX
) {
3580 if (ctx
.shader
->noutput
)
3581 emit_lds_vs_writes(&ctx
);
3583 } else if (ring_outputs
) {
3584 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3585 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3586 ctx
.gs_export_gpr_tregs
[1] = -1;
3587 ctx
.gs_export_gpr_tregs
[2] = -1;
3588 ctx
.gs_export_gpr_tregs
[3] = -1;
3590 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3594 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3596 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3597 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3598 output
[j
].gpr
= shader
->output
[i
].gpr
;
3599 output
[j
].elem_size
= 3;
3600 output
[j
].swizzle_x
= 0;
3601 output
[j
].swizzle_y
= 1;
3602 output
[j
].swizzle_z
= 2;
3603 output
[j
].swizzle_w
= 3;
3604 output
[j
].burst_count
= 1;
3605 output
[j
].type
= 0xffffffff;
3606 output
[j
].op
= CF_OP_EXPORT
;
3608 case PIPE_SHADER_VERTEX
:
3609 case PIPE_SHADER_TESS_EVAL
:
3610 switch (shader
->output
[i
].name
) {
3611 case TGSI_SEMANTIC_POSITION
:
3612 output
[j
].array_base
= 60;
3613 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3617 case TGSI_SEMANTIC_PSIZE
:
3618 output
[j
].array_base
= 61;
3619 output
[j
].swizzle_y
= 7;
3620 output
[j
].swizzle_z
= 7;
3621 output
[j
].swizzle_w
= 7;
3622 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3625 case TGSI_SEMANTIC_EDGEFLAG
:
3626 output
[j
].array_base
= 61;
3627 output
[j
].swizzle_x
= 7;
3628 output
[j
].swizzle_y
= 0;
3629 output
[j
].swizzle_z
= 7;
3630 output
[j
].swizzle_w
= 7;
3631 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3634 case TGSI_SEMANTIC_LAYER
:
3635 /* spi_sid is 0 for outputs that are
3636 * not consumed by PS */
3637 if (shader
->output
[i
].spi_sid
) {
3638 output
[j
].array_base
= next_param_base
++;
3639 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3641 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3643 output
[j
].array_base
= 61;
3644 output
[j
].swizzle_x
= 7;
3645 output
[j
].swizzle_y
= 7;
3646 output
[j
].swizzle_z
= 0;
3647 output
[j
].swizzle_w
= 7;
3648 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3651 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3652 /* spi_sid is 0 for outputs that are
3653 * not consumed by PS */
3654 if (shader
->output
[i
].spi_sid
) {
3655 output
[j
].array_base
= next_param_base
++;
3656 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3658 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3660 output
[j
].array_base
= 61;
3661 output
[j
].swizzle_x
= 7;
3662 output
[j
].swizzle_y
= 7;
3663 output
[j
].swizzle_z
= 7;
3664 output
[j
].swizzle_w
= 0;
3665 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3668 case TGSI_SEMANTIC_CLIPVERTEX
:
3671 case TGSI_SEMANTIC_CLIPDIST
:
3672 output
[j
].array_base
= next_clip_base
++;
3673 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3675 /* spi_sid is 0 for clipdistance outputs that were generated
3676 * for clipvertex - we don't need to pass them to PS */
3677 if (shader
->output
[i
].spi_sid
) {
3679 /* duplicate it as PARAM to pass to the pixel shader */
3680 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3681 output
[j
].array_base
= next_param_base
++;
3682 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3685 case TGSI_SEMANTIC_FOG
:
3686 output
[j
].swizzle_y
= 4; /* 0 */
3687 output
[j
].swizzle_z
= 4; /* 0 */
3688 output
[j
].swizzle_w
= 5; /* 1 */
3690 case TGSI_SEMANTIC_PRIMID
:
3691 output
[j
].swizzle_x
= 2;
3692 output
[j
].swizzle_y
= 4; /* 0 */
3693 output
[j
].swizzle_z
= 4; /* 0 */
3694 output
[j
].swizzle_w
= 4; /* 0 */
3699 case PIPE_SHADER_FRAGMENT
:
3700 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3701 /* never export more colors than the number of CBs */
3702 if (shader
->output
[i
].sid
>= max_color_exports
) {
3707 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3708 output
[j
].array_base
= shader
->output
[i
].sid
;
3709 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3710 shader
->nr_ps_color_exports
++;
3711 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3712 for (k
= 1; k
< max_color_exports
; k
++) {
3714 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3715 output
[j
].gpr
= shader
->output
[i
].gpr
;
3716 output
[j
].elem_size
= 3;
3717 output
[j
].swizzle_x
= 0;
3718 output
[j
].swizzle_y
= 1;
3719 output
[j
].swizzle_z
= 2;
3720 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3721 output
[j
].burst_count
= 1;
3722 output
[j
].array_base
= k
;
3723 output
[j
].op
= CF_OP_EXPORT
;
3724 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3725 shader
->nr_ps_color_exports
++;
3728 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3729 output
[j
].array_base
= 61;
3730 output
[j
].swizzle_x
= 2;
3731 output
[j
].swizzle_y
= 7;
3732 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3733 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3734 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3735 output
[j
].array_base
= 61;
3736 output
[j
].swizzle_x
= 7;
3737 output
[j
].swizzle_y
= 1;
3738 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3739 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3740 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3741 output
[j
].array_base
= 61;
3742 output
[j
].swizzle_x
= 7;
3743 output
[j
].swizzle_y
= 7;
3744 output
[j
].swizzle_z
= 0;
3745 output
[j
].swizzle_w
= 7;
3746 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3748 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3753 case PIPE_SHADER_TESS_CTRL
:
3756 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3761 if (output
[j
].type
== 0xffffffff) {
3762 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3763 output
[j
].array_base
= next_param_base
++;
3767 /* add fake position export */
3768 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && pos_emitted
== false) {
3769 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3771 output
[j
].elem_size
= 3;
3772 output
[j
].swizzle_x
= 7;
3773 output
[j
].swizzle_y
= 7;
3774 output
[j
].swizzle_z
= 7;
3775 output
[j
].swizzle_w
= 7;
3776 output
[j
].burst_count
= 1;
3777 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3778 output
[j
].array_base
= 60;
3779 output
[j
].op
= CF_OP_EXPORT
;
3783 /* add fake param output for vertex shader if no param is exported */
3784 if ((ctx
.type
== PIPE_SHADER_VERTEX
|| ctx
.type
== PIPE_SHADER_TESS_EVAL
) && next_param_base
== 0) {
3785 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3787 output
[j
].elem_size
= 3;
3788 output
[j
].swizzle_x
= 7;
3789 output
[j
].swizzle_y
= 7;
3790 output
[j
].swizzle_z
= 7;
3791 output
[j
].swizzle_w
= 7;
3792 output
[j
].burst_count
= 1;
3793 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3794 output
[j
].array_base
= 0;
3795 output
[j
].op
= CF_OP_EXPORT
;
3799 /* add fake pixel export */
3800 if (ctx
.type
== PIPE_SHADER_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3801 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3803 output
[j
].elem_size
= 3;
3804 output
[j
].swizzle_x
= 7;
3805 output
[j
].swizzle_y
= 7;
3806 output
[j
].swizzle_z
= 7;
3807 output
[j
].swizzle_w
= 7;
3808 output
[j
].burst_count
= 1;
3809 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3810 output
[j
].array_base
= 0;
3811 output
[j
].op
= CF_OP_EXPORT
;
3813 shader
->nr_ps_color_exports
++;
3818 /* set export done on last export of each type */
3819 for (k
= noutput
- 1, output_done
= 0; k
>= 0; k
--) {
3820 if (!(output_done
& (1 << output
[k
].type
))) {
3821 output_done
|= (1 << output
[k
].type
);
3822 output
[k
].op
= CF_OP_EXPORT_DONE
;
3825 /* add output to bytecode */
3826 for (i
= 0; i
< noutput
; i
++) {
3827 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3833 /* add program end */
3834 if (ctx
.bc
->chip_class
== CAYMAN
)
3835 cm_bytecode_add_cf_end(ctx
.bc
);
3837 const struct cf_op_info
*last
= NULL
;
3839 if (ctx
.bc
->cf_last
)
3840 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3842 /* alu clause instructions don't have EOP bit, so add NOP */
3843 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
)
3844 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3846 ctx
.bc
->cf_last
->end_of_program
= 1;
3849 /* check GPR limit - we have 124 = 128 - 4
3850 * (4 are reserved as alu clause temporary registers) */
3851 if (ctx
.bc
->ngpr
> 124) {
3852 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3857 if (ctx
.type
== PIPE_SHADER_GEOMETRY
) {
3858 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3863 tgsi_parse_free(&ctx
.parse
);
3867 tgsi_parse_free(&ctx
.parse
);
3871 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3873 const unsigned tgsi_opcode
=
3874 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3875 R600_ERR("%s tgsi opcode unsupported\n",
3876 tgsi_get_opcode_name(tgsi_opcode
));
3880 static int tgsi_end(struct r600_shader_ctx
*ctx UNUSED
)
3885 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3886 const struct r600_shader_src
*shader_src
,
3889 bc_src
->sel
= shader_src
->sel
;
3890 bc_src
->chan
= shader_src
->swizzle
[chan
];
3891 bc_src
->neg
= shader_src
->neg
;
3892 bc_src
->abs
= shader_src
->abs
;
3893 bc_src
->rel
= shader_src
->rel
;
3894 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3895 bc_src
->kc_bank
= shader_src
->kc_bank
;
3896 bc_src
->kc_rel
= shader_src
->kc_rel
;
3899 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3905 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3907 bc_src
->neg
= !bc_src
->neg
;
3910 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3911 const struct tgsi_full_dst_register
*tgsi_dst
,
3913 struct r600_bytecode_alu_dst
*r600_dst
)
3915 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3917 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
3918 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
3919 r600_dst
->chan
= swizzle
;
3920 r600_dst
->write
= 1;
3921 if (inst
->Instruction
.Saturate
) {
3922 r600_dst
->clamp
= 1;
3924 if (ctx
->type
== PIPE_SHADER_TESS_CTRL
) {
3925 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
3929 if (tgsi_dst
->Register
.Indirect
)
3930 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
3934 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
, int dest_temp
, int op_override
)
3936 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3937 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3938 struct r600_bytecode_alu alu
;
3939 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3941 int swizzle_x
= inst
->Src
[0].Register
.SwizzleX
;
3944 switch (write_mask
) {
3946 if (swizzle_x
== 2) {
3953 if (swizzle_x
== 2) {
3962 if (swizzle_x
== 0) {
3969 if (swizzle_x
== 0) {
3980 lasti
= tgsi_last_instruction(write_mask
);
3981 for (i
= 0; i
<= lasti
; i
++) {
3983 if (!(write_mask
& (1 << i
)))
3986 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3989 if (use_tmp
|| dest_temp
) {
3990 alu
.dst
.sel
= use_tmp
? ctx
->temp_reg
: dest_temp
;
3994 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3996 if (i
== 1 || i
== 3)
3999 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4001 alu
.op
= op_override
? op_override
: ctx
->inst_info
->op
;
4002 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
4003 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4005 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4006 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4009 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
4010 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
4013 /* handle some special cases */
4014 if (i
== 1 || i
== 3) {
4015 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
4016 case TGSI_OPCODE_DABS
:
4017 r600_bytecode_src_set_abs(&alu
.src
[0]);
4026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4032 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4034 lasti
= tgsi_last_instruction(write_mask
);
4035 /* move result from temp to dst */
4036 for (i
= 0; i
<= lasti
; i
++) {
4037 if (!(write_mask
& (1 << i
)))
4040 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4041 alu
.op
= ALU_OP1_MOV
;
4044 alu
.dst
.sel
= dest_temp
;
4048 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4049 alu
.src
[0].sel
= ctx
->temp_reg
;
4050 alu
.src
[0].chan
= use_tmp
- 1;
4051 alu
.last
= (i
== lasti
);
4053 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4061 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
4063 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4064 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4065 /* confirm writemasking */
4066 if ((write_mask
& 0x3) != 0x3 &&
4067 (write_mask
& 0xc) != 0xc) {
4068 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
4071 return tgsi_op2_64_params(ctx
, false, false, 0, 0);
4074 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
4076 return tgsi_op2_64_params(ctx
, true, false, 0, 0);
4079 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
4081 return tgsi_op2_64_params(ctx
, true, true, 0, 0);
4084 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
4086 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4087 struct r600_bytecode_alu alu
;
4090 int tmp
= r600_get_temp(ctx
);
4092 for (i
= 0; i
< lasti
+ 1; i
++) {
4094 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4095 alu
.op
= ctx
->inst_info
->op
;
4096 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4097 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
4100 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
4101 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4110 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4117 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
4119 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4120 struct r600_bytecode_alu alu
;
4121 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4122 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
4123 /* use temp register if trans_only and more than one dst component */
4124 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
4125 unsigned op
= ctx
->inst_info
->op
;
4127 if (op
== ALU_OP2_MUL_IEEE
&&
4128 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
4131 for (i
= 0; i
<= lasti
; i
++) {
4132 if (!(write_mask
& (1 << i
)))
4135 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4137 alu
.dst
.sel
= ctx
->temp_reg
;
4141 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4145 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4146 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4149 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4150 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4152 if (i
== lasti
|| trans_only
) {
4155 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4161 /* move result from temp to dst */
4162 for (i
= 0; i
<= lasti
; i
++) {
4163 if (!(write_mask
& (1 << i
)))
4166 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4167 alu
.op
= ALU_OP1_MOV
;
4168 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4169 alu
.src
[0].sel
= ctx
->temp_reg
;
4170 alu
.src
[0].chan
= i
;
4171 alu
.last
= (i
== lasti
);
4173 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4181 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4183 return tgsi_op2_s(ctx
, 0, 0);
4186 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4188 return tgsi_op2_s(ctx
, 1, 0);
4191 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4193 return tgsi_op2_s(ctx
, 0, 1);
4196 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4198 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4199 struct r600_bytecode_alu alu
;
4201 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4203 for (i
= 0; i
< lasti
+ 1; i
++) {
4205 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4207 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4208 alu
.op
= ctx
->inst_info
->op
;
4210 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4212 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4214 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4219 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4227 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4229 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4230 struct r600_bytecode_alu alu
;
4232 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4234 for (i
= 0; i
< lasti
+ 1; i
++) {
4236 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4238 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4239 alu
.op
= ALU_OP1_MOV
;
4241 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4243 if (i
== 1 || i
== 3)
4244 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4245 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4250 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4258 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4260 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4261 struct r600_bytecode_alu alu
;
4262 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4265 for (i
= 0; i
<= 3; i
++) {
4266 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4267 alu
.op
= ctx
->inst_info
->op
;
4269 alu
.dst
.sel
= ctx
->temp_reg
;
4272 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4273 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4279 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4284 /* Replicate significand result across channels. */
4285 for (i
= 0; i
<= 3; i
++) {
4286 if (!(write_mask
& (1 << i
)))
4289 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4290 alu
.op
= ALU_OP1_MOV
;
4291 alu
.src
[0].chan
= (i
& 1) + 2;
4292 alu
.src
[0].sel
= ctx
->temp_reg
;
4294 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4297 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4302 for (i
= 0; i
<= 3; i
++) {
4303 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4304 /* MOV third channels to writemask dst1 */
4305 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4306 alu
.op
= ALU_OP1_MOV
;
4307 alu
.src
[0].chan
= 1;
4308 alu
.src
[0].sel
= ctx
->temp_reg
;
4310 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4312 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4322 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4324 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4325 struct r600_bytecode_alu alu
;
4327 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4329 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4330 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4332 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4333 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4334 alu
.op
= ctx
->inst_info
->op
;
4336 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4337 alu
.dst
.sel
= ctx
->temp_reg
;
4342 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4347 for (i
= 0; i
<= lasti
; i
++) {
4348 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4349 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4351 alu
.src
[0].chan
= i
/2;
4353 alu
.src
[0].sel
= ctx
->temp_reg
;
4355 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4356 alu
.src
[0].value
= 0x0;
4358 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4359 alu
.last
= i
== lasti
;
4361 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4369 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4371 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4372 struct r600_bytecode_alu alu
;
4374 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4375 int treg
= r600_get_temp(ctx
);
4376 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4377 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4379 /* do a 64->32 into a temp register */
4380 r
= tgsi_op2_64_params(ctx
, true, false, treg
, ALU_OP1_FLT64_TO_FLT32
);
4384 for (i
= 0; i
<= lasti
; i
++) {
4385 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4387 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4388 alu
.op
= ctx
->inst_info
->op
;
4390 alu
.src
[0].chan
= i
;
4391 alu
.src
[0].sel
= treg
;
4392 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4393 alu
.last
= (i
== lasti
);
4395 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4403 static int cayman_emit_unary_double_raw(struct r600_bytecode
*bc
,
4406 struct r600_shader_src
*src
,
4409 struct r600_bytecode_alu alu
;
4410 const int last_slot
= 3;
4413 /* these have to write the result to X/Y by the looks of it */
4414 for (int i
= 0 ; i
< last_slot
; i
++) {
4415 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4418 r600_bytecode_src(&alu
.src
[0], src
, 1);
4419 r600_bytecode_src(&alu
.src
[1], src
, 0);
4422 r600_bytecode_src_set_abs(&alu
.src
[1]);
4424 alu
.dst
.sel
= dst_reg
;
4426 alu
.dst
.write
= (i
== 0 || i
== 1);
4428 if (bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4430 r
= r600_bytecode_add_alu(bc
, &alu
);
4438 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4440 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4442 struct r600_bytecode_alu alu
;
4443 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4444 int t1
= ctx
->temp_reg
;
4446 /* should only be one src regs */
4447 assert(inst
->Instruction
.NumSrcRegs
== 1);
4449 /* only support one double at a time */
4450 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4451 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4453 r
= cayman_emit_unary_double_raw(
4454 ctx
->bc
, ctx
->inst_info
->op
, t1
,
4456 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4457 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
);
4461 for (i
= 0 ; i
<= lasti
; i
++) {
4462 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4464 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4465 alu
.op
= ALU_OP1_MOV
;
4466 alu
.src
[0].sel
= t1
;
4467 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4468 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4472 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4479 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4481 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4483 struct r600_bytecode_alu alu
;
4484 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4486 for (i
= 0 ; i
< last_slot
; i
++) {
4487 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4488 alu
.op
= ctx
->inst_info
->op
;
4489 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4490 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4492 /* RSQ should take the absolute value of src */
4493 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4494 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4497 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4498 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4500 if (i
== last_slot
- 1)
4502 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4509 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4511 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4513 struct r600_bytecode_alu alu
;
4514 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4515 int t1
= ctx
->temp_reg
;
4517 for (k
= 0; k
<= lasti
; k
++) {
4518 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4521 for (i
= 0 ; i
< 4; i
++) {
4522 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4523 alu
.op
= ctx
->inst_info
->op
;
4524 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4525 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4529 alu
.dst
.write
= (i
== k
);
4532 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4538 for (i
= 0 ; i
<= lasti
; i
++) {
4539 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4541 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4542 alu
.op
= ALU_OP1_MOV
;
4543 alu
.src
[0].sel
= t1
;
4544 alu
.src
[0].chan
= i
;
4545 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4549 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4558 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4560 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4562 struct r600_bytecode_alu alu
;
4563 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4564 int t1
= ctx
->temp_reg
;
4566 /* t1 would get overwritten below if we actually tried to
4567 * multiply two pairs of doubles at a time. */
4568 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4569 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4571 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4573 for (i
= 0; i
< 4; i
++) {
4574 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4575 alu
.op
= ctx
->inst_info
->op
;
4576 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4577 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));
4584 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4589 for (i
= 0; i
<= lasti
; i
++) {
4590 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4592 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4593 alu
.op
= ALU_OP1_MOV
;
4594 alu
.src
[0].sel
= t1
;
4595 alu
.src
[0].chan
= i
;
4596 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4600 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4609 * Emit RECIP_64 + MUL_64 to implement division.
4611 static int cayman_ddiv_instr(struct r600_shader_ctx
*ctx
)
4613 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4615 struct r600_bytecode_alu alu
;
4616 int t1
= ctx
->temp_reg
;
4619 /* Only support one double at a time. This is the same constraint as
4620 * in DMUL lowering. */
4621 assert(inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
||
4622 inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_ZW
);
4624 k
= inst
->Dst
[0].Register
.WriteMask
== TGSI_WRITEMASK_XY
? 0 : 1;
4626 r
= cayman_emit_unary_double_raw(ctx
->bc
, ALU_OP2_RECIP_64
, t1
, &ctx
->src
[1], false);
4630 for (int i
= 0; i
< 4; i
++) {
4631 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4632 alu
.op
= ALU_OP2_MUL_64
;
4634 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], k
* 2 + ((i
== 3) ? 0 : 1));
4636 alu
.src
[1].sel
= t1
;
4637 alu
.src
[1].chan
= (i
== 3) ? 0 : 1;
4644 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4649 for (int i
= 0; i
< 2; i
++) {
4650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4651 alu
.op
= ALU_OP1_MOV
;
4652 alu
.src
[0].sel
= t1
;
4653 alu
.src
[0].chan
= i
;
4654 tgsi_dst(ctx
, &inst
->Dst
[0], k
* 2 + i
, &alu
.dst
);
4658 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4666 * r600 - trunc to -PI..PI range
4667 * r700 - normalize by dividing by 2PI
4670 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4673 struct r600_bytecode_alu alu
;
4675 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4676 alu
.op
= ALU_OP3_MULADD
;
4680 alu
.dst
.sel
= ctx
->temp_reg
;
4683 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4685 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4686 alu
.src
[1].chan
= 0;
4687 alu
.src
[1].value
= u_bitcast_f2u(0.5f
* M_1_PI
);
4688 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4689 alu
.src
[2].chan
= 0;
4691 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4695 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4696 alu
.op
= ALU_OP1_FRACT
;
4699 alu
.dst
.sel
= ctx
->temp_reg
;
4702 alu
.src
[0].sel
= ctx
->temp_reg
;
4703 alu
.src
[0].chan
= 0;
4705 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4709 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4710 alu
.op
= ALU_OP3_MULADD
;
4714 alu
.dst
.sel
= ctx
->temp_reg
;
4717 alu
.src
[0].sel
= ctx
->temp_reg
;
4718 alu
.src
[0].chan
= 0;
4720 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4721 alu
.src
[1].chan
= 0;
4722 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4723 alu
.src
[2].chan
= 0;
4725 if (ctx
->bc
->chip_class
== R600
) {
4726 alu
.src
[1].value
= u_bitcast_f2u(2.0f
* M_PI
);
4727 alu
.src
[2].value
= u_bitcast_f2u(-M_PI
);
4729 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4730 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4735 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4741 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4743 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4744 struct r600_bytecode_alu alu
;
4745 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4748 r
= tgsi_setup_trig(ctx
);
4753 for (i
= 0; i
< last_slot
; i
++) {
4754 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4755 alu
.op
= ctx
->inst_info
->op
;
4758 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4759 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4761 alu
.src
[0].sel
= ctx
->temp_reg
;
4762 alu
.src
[0].chan
= 0;
4763 if (i
== last_slot
- 1)
4765 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4772 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4774 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4775 struct r600_bytecode_alu alu
;
4777 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4779 r
= tgsi_setup_trig(ctx
);
4783 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4784 alu
.op
= ctx
->inst_info
->op
;
4786 alu
.dst
.sel
= ctx
->temp_reg
;
4789 alu
.src
[0].sel
= ctx
->temp_reg
;
4790 alu
.src
[0].chan
= 0;
4792 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4796 /* replicate result */
4797 for (i
= 0; i
< lasti
+ 1; i
++) {
4798 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4801 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4802 alu
.op
= ALU_OP1_MOV
;
4804 alu
.src
[0].sel
= ctx
->temp_reg
;
4805 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4808 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4815 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4817 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4818 struct r600_bytecode_alu alu
;
4821 for (i
= 0; i
< 4; i
++) {
4822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4823 alu
.op
= ctx
->inst_info
->op
;
4827 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4829 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4830 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4833 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4838 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4843 /* kill must be last in ALU */
4844 ctx
->bc
->force_add_cf
= 1;
4845 ctx
->shader
->uses_kill
= TRUE
;
4849 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4851 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4852 struct r600_bytecode_alu alu
;
4855 /* tmp.x = max(src.y, 0.0) */
4856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4857 alu
.op
= ALU_OP2_MAX
;
4858 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4859 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4860 alu
.src
[1].chan
= 1;
4862 alu
.dst
.sel
= ctx
->temp_reg
;
4867 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4871 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4877 if (ctx
->bc
->chip_class
== CAYMAN
) {
4878 for (i
= 0; i
< 3; i
++) {
4879 /* tmp.z = log(tmp.x) */
4880 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4881 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4882 alu
.src
[0].sel
= ctx
->temp_reg
;
4883 alu
.src
[0].chan
= 0;
4884 alu
.dst
.sel
= ctx
->temp_reg
;
4892 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4897 /* tmp.z = log(tmp.x) */
4898 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4899 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4900 alu
.src
[0].sel
= ctx
->temp_reg
;
4901 alu
.src
[0].chan
= 0;
4902 alu
.dst
.sel
= ctx
->temp_reg
;
4906 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4911 chan
= alu
.dst
.chan
;
4914 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
4915 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4916 alu
.op
= ALU_OP3_MUL_LIT
;
4917 alu
.src
[0].sel
= sel
;
4918 alu
.src
[0].chan
= chan
;
4919 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
4920 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
4921 alu
.dst
.sel
= ctx
->temp_reg
;
4926 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4930 if (ctx
->bc
->chip_class
== CAYMAN
) {
4931 for (i
= 0; i
< 3; i
++) {
4932 /* dst.z = exp(tmp.x) */
4933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4934 alu
.op
= ALU_OP1_EXP_IEEE
;
4935 alu
.src
[0].sel
= ctx
->temp_reg
;
4936 alu
.src
[0].chan
= 0;
4937 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4943 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4948 /* dst.z = exp(tmp.x) */
4949 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4950 alu
.op
= ALU_OP1_EXP_IEEE
;
4951 alu
.src
[0].sel
= ctx
->temp_reg
;
4952 alu
.src
[0].chan
= 0;
4953 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4955 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4962 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4963 alu
.op
= ALU_OP1_MOV
;
4964 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
4965 alu
.src
[0].chan
= 0;
4966 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4967 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
4968 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4972 /* dst.y = max(src.x, 0.0) */
4973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4974 alu
.op
= ALU_OP2_MAX
;
4975 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4976 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4977 alu
.src
[1].chan
= 0;
4978 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
4979 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
4980 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4985 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4986 alu
.op
= ALU_OP1_MOV
;
4987 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4988 alu
.src
[0].chan
= 0;
4989 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
4990 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
4992 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4999 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
5001 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5002 struct r600_bytecode_alu alu
;
5005 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5007 alu
.op
= ALU_OP1_RECIPSQRT_IEEE
;
5009 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5010 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5011 r600_bytecode_src_set_abs(&alu
.src
[i
]);
5013 alu
.dst
.sel
= ctx
->temp_reg
;
5016 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5019 /* replicate result */
5020 return tgsi_helper_tempx_replicate(ctx
);
5023 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
5025 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5026 struct r600_bytecode_alu alu
;
5029 for (i
= 0; i
< 4; i
++) {
5030 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5031 alu
.src
[0].sel
= ctx
->temp_reg
;
5032 alu
.op
= ALU_OP1_MOV
;
5034 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5035 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5045 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
5047 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5048 struct r600_bytecode_alu alu
;
5051 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5052 alu
.op
= ctx
->inst_info
->op
;
5053 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
5054 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
5056 alu
.dst
.sel
= ctx
->temp_reg
;
5059 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5062 /* replicate result */
5063 return tgsi_helper_tempx_replicate(ctx
);
5066 static int cayman_pow(struct r600_shader_ctx
*ctx
)
5068 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5070 struct r600_bytecode_alu alu
;
5071 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
5073 for (i
= 0; i
< 3; i
++) {
5074 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5075 alu
.op
= ALU_OP1_LOG_IEEE
;
5076 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5077 alu
.dst
.sel
= ctx
->temp_reg
;
5082 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5088 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5089 alu
.op
= ALU_OP2_MUL
;
5090 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5091 alu
.src
[1].sel
= ctx
->temp_reg
;
5092 alu
.dst
.sel
= ctx
->temp_reg
;
5095 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5099 for (i
= 0; i
< last_slot
; i
++) {
5100 /* POW(a,b) = EXP2(b * LOG2(a))*/
5101 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5102 alu
.op
= ALU_OP1_EXP_IEEE
;
5103 alu
.src
[0].sel
= ctx
->temp_reg
;
5105 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5106 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5107 if (i
== last_slot
- 1)
5109 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5116 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5118 struct r600_bytecode_alu alu
;
5122 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5123 alu
.op
= ALU_OP1_LOG_IEEE
;
5124 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5125 alu
.dst
.sel
= ctx
->temp_reg
;
5128 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5132 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5133 alu
.op
= ALU_OP2_MUL
;
5134 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5135 alu
.src
[1].sel
= ctx
->temp_reg
;
5136 alu
.dst
.sel
= ctx
->temp_reg
;
5139 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5142 /* POW(a,b) = EXP2(b * LOG2(a))*/
5143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5144 alu
.op
= ALU_OP1_EXP_IEEE
;
5145 alu
.src
[0].sel
= ctx
->temp_reg
;
5146 alu
.dst
.sel
= ctx
->temp_reg
;
5149 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5152 return tgsi_helper_tempx_replicate(ctx
);
5155 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5157 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5158 struct r600_bytecode_alu alu
;
5160 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5161 int tmp0
= ctx
->temp_reg
;
5162 int tmp1
= r600_get_temp(ctx
);
5163 int tmp2
= r600_get_temp(ctx
);
5164 int tmp3
= r600_get_temp(ctx
);
5167 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5169 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5170 * 2. tmp0.z = lo (tmp0.x * src2)
5171 * 3. tmp0.w = -tmp0.z
5172 * 4. tmp0.y = hi (tmp0.x * src2)
5173 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5174 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5175 * 7. tmp1.x = tmp0.x - tmp0.w
5176 * 8. tmp1.y = tmp0.x + tmp0.w
5177 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5178 * 10. tmp0.z = hi(tmp0.x * src1) = q
5179 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5181 * 12. tmp0.w = src1 - tmp0.y = r
5182 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5183 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5187 * 15. tmp1.z = tmp0.z + 1 = q + 1
5188 * 16. tmp1.w = tmp0.z - 1 = q - 1
5192 * 15. tmp1.z = tmp0.w - src2 = r - src2
5193 * 16. tmp1.w = tmp0.w + src2 = r + src2
5197 * 17. tmp1.x = tmp1.x & tmp1.y
5199 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5200 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5202 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5203 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5207 * Same as unsigned, using abs values of the operands,
5208 * and fixing the sign of the result in the end.
5211 for (i
= 0; i
< 4; i
++) {
5212 if (!(write_mask
& (1<<i
)))
5217 /* tmp2.x = -src0 */
5218 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5219 alu
.op
= ALU_OP2_SUB_INT
;
5225 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5227 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5230 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5233 /* tmp2.y = -src1 */
5234 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5235 alu
.op
= ALU_OP2_SUB_INT
;
5241 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5243 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5246 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5249 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5250 /* it will be a sign of the quotient */
5253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5254 alu
.op
= ALU_OP2_XOR_INT
;
5260 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5261 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5264 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5268 /* tmp2.x = |src0| */
5269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5270 alu
.op
= ALU_OP3_CNDGE_INT
;
5277 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5278 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5279 alu
.src
[2].sel
= tmp2
;
5280 alu
.src
[2].chan
= 0;
5283 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5286 /* tmp2.y = |src1| */
5287 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5288 alu
.op
= ALU_OP3_CNDGE_INT
;
5295 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5296 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5297 alu
.src
[2].sel
= tmp2
;
5298 alu
.src
[2].chan
= 1;
5301 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5306 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5307 if (ctx
->bc
->chip_class
== CAYMAN
) {
5308 /* tmp3.x = u2f(src2) */
5309 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5310 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5317 alu
.src
[0].sel
= tmp2
;
5318 alu
.src
[0].chan
= 1;
5320 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5324 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5327 /* tmp0.x = recip(tmp3.x) */
5328 for (j
= 0 ; j
< 3; j
++) {
5329 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5330 alu
.op
= ALU_OP1_RECIP_IEEE
;
5334 alu
.dst
.write
= (j
== 0);
5336 alu
.src
[0].sel
= tmp3
;
5337 alu
.src
[0].chan
= 0;
5341 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5345 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5346 alu
.op
= ALU_OP2_MUL
;
5348 alu
.src
[0].sel
= tmp0
;
5349 alu
.src
[0].chan
= 0;
5351 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5352 alu
.src
[1].value
= 0x4f800000;
5357 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5361 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5362 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5368 alu
.src
[0].sel
= tmp3
;
5369 alu
.src
[0].chan
= 0;
5372 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5377 alu
.op
= ALU_OP1_RECIP_UINT
;
5384 alu
.src
[0].sel
= tmp2
;
5385 alu
.src
[0].chan
= 1;
5387 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5391 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5395 /* 2. tmp0.z = lo (tmp0.x * src2) */
5396 if (ctx
->bc
->chip_class
== CAYMAN
) {
5397 for (j
= 0 ; j
< 4; j
++) {
5398 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5399 alu
.op
= ALU_OP2_MULLO_UINT
;
5403 alu
.dst
.write
= (j
== 2);
5405 alu
.src
[0].sel
= tmp0
;
5406 alu
.src
[0].chan
= 0;
5408 alu
.src
[1].sel
= tmp2
;
5409 alu
.src
[1].chan
= 1;
5411 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5414 alu
.last
= (j
== 3);
5415 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5419 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5420 alu
.op
= ALU_OP2_MULLO_UINT
;
5426 alu
.src
[0].sel
= tmp0
;
5427 alu
.src
[0].chan
= 0;
5429 alu
.src
[1].sel
= tmp2
;
5430 alu
.src
[1].chan
= 1;
5432 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5436 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5440 /* 3. tmp0.w = -tmp0.z */
5441 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5442 alu
.op
= ALU_OP2_SUB_INT
;
5448 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5449 alu
.src
[1].sel
= tmp0
;
5450 alu
.src
[1].chan
= 2;
5453 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5456 /* 4. tmp0.y = hi (tmp0.x * src2) */
5457 if (ctx
->bc
->chip_class
== CAYMAN
) {
5458 for (j
= 0 ; j
< 4; j
++) {
5459 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5460 alu
.op
= ALU_OP2_MULHI_UINT
;
5464 alu
.dst
.write
= (j
== 1);
5466 alu
.src
[0].sel
= tmp0
;
5467 alu
.src
[0].chan
= 0;
5470 alu
.src
[1].sel
= tmp2
;
5471 alu
.src
[1].chan
= 1;
5473 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5475 alu
.last
= (j
== 3);
5476 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5480 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5481 alu
.op
= ALU_OP2_MULHI_UINT
;
5487 alu
.src
[0].sel
= tmp0
;
5488 alu
.src
[0].chan
= 0;
5491 alu
.src
[1].sel
= tmp2
;
5492 alu
.src
[1].chan
= 1;
5494 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5498 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5502 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5503 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5504 alu
.op
= ALU_OP3_CNDE_INT
;
5511 alu
.src
[0].sel
= tmp0
;
5512 alu
.src
[0].chan
= 1;
5513 alu
.src
[1].sel
= tmp0
;
5514 alu
.src
[1].chan
= 3;
5515 alu
.src
[2].sel
= tmp0
;
5516 alu
.src
[2].chan
= 2;
5519 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5522 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5523 if (ctx
->bc
->chip_class
== CAYMAN
) {
5524 for (j
= 0 ; j
< 4; j
++) {
5525 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5526 alu
.op
= ALU_OP2_MULHI_UINT
;
5530 alu
.dst
.write
= (j
== 3);
5532 alu
.src
[0].sel
= tmp0
;
5533 alu
.src
[0].chan
= 2;
5535 alu
.src
[1].sel
= tmp0
;
5536 alu
.src
[1].chan
= 0;
5538 alu
.last
= (j
== 3);
5539 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5543 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5544 alu
.op
= ALU_OP2_MULHI_UINT
;
5550 alu
.src
[0].sel
= tmp0
;
5551 alu
.src
[0].chan
= 2;
5553 alu
.src
[1].sel
= tmp0
;
5554 alu
.src
[1].chan
= 0;
5557 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5561 /* 7. tmp1.x = tmp0.x - tmp0.w */
5562 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5563 alu
.op
= ALU_OP2_SUB_INT
;
5569 alu
.src
[0].sel
= tmp0
;
5570 alu
.src
[0].chan
= 0;
5571 alu
.src
[1].sel
= tmp0
;
5572 alu
.src
[1].chan
= 3;
5575 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5578 /* 8. tmp1.y = tmp0.x + tmp0.w */
5579 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5580 alu
.op
= ALU_OP2_ADD_INT
;
5586 alu
.src
[0].sel
= tmp0
;
5587 alu
.src
[0].chan
= 0;
5588 alu
.src
[1].sel
= tmp0
;
5589 alu
.src
[1].chan
= 3;
5592 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5595 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5596 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5597 alu
.op
= ALU_OP3_CNDE_INT
;
5604 alu
.src
[0].sel
= tmp0
;
5605 alu
.src
[0].chan
= 1;
5606 alu
.src
[1].sel
= tmp1
;
5607 alu
.src
[1].chan
= 1;
5608 alu
.src
[2].sel
= tmp1
;
5609 alu
.src
[2].chan
= 0;
5612 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5615 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5616 if (ctx
->bc
->chip_class
== CAYMAN
) {
5617 for (j
= 0 ; j
< 4; j
++) {
5618 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5619 alu
.op
= ALU_OP2_MULHI_UINT
;
5623 alu
.dst
.write
= (j
== 2);
5625 alu
.src
[0].sel
= tmp0
;
5626 alu
.src
[0].chan
= 0;
5629 alu
.src
[1].sel
= tmp2
;
5630 alu
.src
[1].chan
= 0;
5632 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5635 alu
.last
= (j
== 3);
5636 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5640 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5641 alu
.op
= ALU_OP2_MULHI_UINT
;
5647 alu
.src
[0].sel
= tmp0
;
5648 alu
.src
[0].chan
= 0;
5651 alu
.src
[1].sel
= tmp2
;
5652 alu
.src
[1].chan
= 0;
5654 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5658 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5662 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5663 if (ctx
->bc
->chip_class
== CAYMAN
) {
5664 for (j
= 0 ; j
< 4; j
++) {
5665 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5666 alu
.op
= ALU_OP2_MULLO_UINT
;
5670 alu
.dst
.write
= (j
== 1);
5673 alu
.src
[0].sel
= tmp2
;
5674 alu
.src
[0].chan
= 1;
5676 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5679 alu
.src
[1].sel
= tmp0
;
5680 alu
.src
[1].chan
= 2;
5682 alu
.last
= (j
== 3);
5683 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5688 alu
.op
= ALU_OP2_MULLO_UINT
;
5695 alu
.src
[0].sel
= tmp2
;
5696 alu
.src
[0].chan
= 1;
5698 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5701 alu
.src
[1].sel
= tmp0
;
5702 alu
.src
[1].chan
= 2;
5705 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5709 /* 12. tmp0.w = src1 - tmp0.y = r */
5710 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5711 alu
.op
= ALU_OP2_SUB_INT
;
5718 alu
.src
[0].sel
= tmp2
;
5719 alu
.src
[0].chan
= 0;
5721 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5724 alu
.src
[1].sel
= tmp0
;
5725 alu
.src
[1].chan
= 1;
5728 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5731 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5732 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5733 alu
.op
= ALU_OP2_SETGE_UINT
;
5739 alu
.src
[0].sel
= tmp0
;
5740 alu
.src
[0].chan
= 3;
5742 alu
.src
[1].sel
= tmp2
;
5743 alu
.src
[1].chan
= 1;
5745 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5749 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5752 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5753 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5754 alu
.op
= ALU_OP2_SETGE_UINT
;
5761 alu
.src
[0].sel
= tmp2
;
5762 alu
.src
[0].chan
= 0;
5764 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5767 alu
.src
[1].sel
= tmp0
;
5768 alu
.src
[1].chan
= 1;
5771 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5774 if (mod
) { /* UMOD */
5776 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5777 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5778 alu
.op
= ALU_OP2_SUB_INT
;
5784 alu
.src
[0].sel
= tmp0
;
5785 alu
.src
[0].chan
= 3;
5788 alu
.src
[1].sel
= tmp2
;
5789 alu
.src
[1].chan
= 1;
5791 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5795 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5798 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5800 alu
.op
= ALU_OP2_ADD_INT
;
5806 alu
.src
[0].sel
= tmp0
;
5807 alu
.src
[0].chan
= 3;
5809 alu
.src
[1].sel
= tmp2
;
5810 alu
.src
[1].chan
= 1;
5812 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5816 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5821 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5822 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5823 alu
.op
= ALU_OP2_ADD_INT
;
5829 alu
.src
[0].sel
= tmp0
;
5830 alu
.src
[0].chan
= 2;
5831 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5834 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5837 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5838 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5839 alu
.op
= ALU_OP2_ADD_INT
;
5845 alu
.src
[0].sel
= tmp0
;
5846 alu
.src
[0].chan
= 2;
5847 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5850 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5855 /* 17. tmp1.x = tmp1.x & tmp1.y */
5856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5857 alu
.op
= ALU_OP2_AND_INT
;
5863 alu
.src
[0].sel
= tmp1
;
5864 alu
.src
[0].chan
= 0;
5865 alu
.src
[1].sel
= tmp1
;
5866 alu
.src
[1].chan
= 1;
5869 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5872 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5873 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5874 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5875 alu
.op
= ALU_OP3_CNDE_INT
;
5882 alu
.src
[0].sel
= tmp1
;
5883 alu
.src
[0].chan
= 0;
5884 alu
.src
[1].sel
= tmp0
;
5885 alu
.src
[1].chan
= mod
? 3 : 2;
5886 alu
.src
[2].sel
= tmp1
;
5887 alu
.src
[2].chan
= 2;
5890 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5893 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5894 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5895 alu
.op
= ALU_OP3_CNDE_INT
;
5903 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5906 alu
.src
[0].sel
= tmp1
;
5907 alu
.src
[0].chan
= 1;
5908 alu
.src
[1].sel
= tmp1
;
5909 alu
.src
[1].chan
= 3;
5910 alu
.src
[2].sel
= tmp0
;
5911 alu
.src
[2].chan
= 2;
5914 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5919 /* fix the sign of the result */
5923 /* tmp0.x = -tmp0.z */
5924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5925 alu
.op
= ALU_OP2_SUB_INT
;
5931 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5932 alu
.src
[1].sel
= tmp0
;
5933 alu
.src
[1].chan
= 2;
5936 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5939 /* sign of the remainder is the same as the sign of src0 */
5940 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
5941 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5942 alu
.op
= ALU_OP3_CNDGE_INT
;
5945 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5947 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5948 alu
.src
[1].sel
= tmp0
;
5949 alu
.src
[1].chan
= 2;
5950 alu
.src
[2].sel
= tmp0
;
5951 alu
.src
[2].chan
= 0;
5954 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5959 /* tmp0.x = -tmp0.z */
5960 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5961 alu
.op
= ALU_OP2_SUB_INT
;
5967 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5968 alu
.src
[1].sel
= tmp0
;
5969 alu
.src
[1].chan
= 2;
5972 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5975 /* fix the quotient sign (same as the sign of src0*src1) */
5976 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
5977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5978 alu
.op
= ALU_OP3_CNDGE_INT
;
5981 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5983 alu
.src
[0].sel
= tmp2
;
5984 alu
.src
[0].chan
= 2;
5985 alu
.src
[1].sel
= tmp0
;
5986 alu
.src
[1].chan
= 2;
5987 alu
.src
[2].sel
= tmp0
;
5988 alu
.src
[2].chan
= 0;
5991 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5999 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
6001 return tgsi_divmod(ctx
, 0, 0);
6004 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
6006 return tgsi_divmod(ctx
, 1, 0);
6009 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
6011 return tgsi_divmod(ctx
, 0, 1);
6014 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
6016 return tgsi_divmod(ctx
, 1, 1);
6020 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
6022 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6023 struct r600_bytecode_alu alu
;
6025 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6026 int last_inst
= tgsi_last_instruction(write_mask
);
6028 for (i
= 0; i
< 4; i
++) {
6029 if (!(write_mask
& (1<<i
)))
6032 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6033 alu
.op
= ALU_OP1_TRUNC
;
6035 alu
.dst
.sel
= ctx
->temp_reg
;
6039 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6042 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6047 for (i
= 0; i
< 4; i
++) {
6048 if (!(write_mask
& (1<<i
)))
6051 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6052 alu
.op
= ctx
->inst_info
->op
;
6054 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6056 alu
.src
[0].sel
= ctx
->temp_reg
;
6057 alu
.src
[0].chan
= i
;
6059 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
6061 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6069 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
6071 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6072 struct r600_bytecode_alu alu
;
6074 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6075 int last_inst
= tgsi_last_instruction(write_mask
);
6078 for (i
= 0; i
< 4; i
++) {
6079 if (!(write_mask
& (1<<i
)))
6082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6083 alu
.op
= ALU_OP2_SUB_INT
;
6085 alu
.dst
.sel
= ctx
->temp_reg
;
6089 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6090 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6099 /* dst = (src >= 0 ? src : tmp) */
6100 for (i
= 0; i
< 4; i
++) {
6101 if (!(write_mask
& (1<<i
)))
6104 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6105 alu
.op
= ALU_OP3_CNDGE_INT
;
6109 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6111 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6112 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6113 alu
.src
[2].sel
= ctx
->temp_reg
;
6114 alu
.src
[2].chan
= i
;
6118 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6125 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6127 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6128 struct r600_bytecode_alu alu
;
6130 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6131 int last_inst
= tgsi_last_instruction(write_mask
);
6133 /* tmp = (src >= 0 ? src : -1) */
6134 for (i
= 0; i
< 4; i
++) {
6135 if (!(write_mask
& (1<<i
)))
6138 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6139 alu
.op
= ALU_OP3_CNDGE_INT
;
6142 alu
.dst
.sel
= ctx
->temp_reg
;
6146 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6147 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6148 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6152 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6157 /* dst = (tmp > 0 ? 1 : tmp) */
6158 for (i
= 0; i
< 4; i
++) {
6159 if (!(write_mask
& (1<<i
)))
6162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6163 alu
.op
= ALU_OP3_CNDGT_INT
;
6167 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6169 alu
.src
[0].sel
= ctx
->temp_reg
;
6170 alu
.src
[0].chan
= i
;
6172 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6174 alu
.src
[2].sel
= ctx
->temp_reg
;
6175 alu
.src
[2].chan
= i
;
6179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6188 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6190 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6191 struct r600_bytecode_alu alu
;
6194 /* tmp = (src > 0 ? 1 : src) */
6195 for (i
= 0; i
< 4; i
++) {
6196 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6197 alu
.op
= ALU_OP3_CNDGT
;
6200 alu
.dst
.sel
= ctx
->temp_reg
;
6203 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6204 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6205 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6209 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6214 /* dst = (-tmp > 0 ? -1 : tmp) */
6215 for (i
= 0; i
< 4; i
++) {
6216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6217 alu
.op
= ALU_OP3_CNDGT
;
6219 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6221 alu
.src
[0].sel
= ctx
->temp_reg
;
6222 alu
.src
[0].chan
= i
;
6225 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6228 alu
.src
[2].sel
= ctx
->temp_reg
;
6229 alu
.src
[2].chan
= i
;
6233 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6240 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6242 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6243 struct r600_bytecode_alu alu
;
6246 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6247 int last_inst
= tgsi_last_instruction(write_mask
);
6249 t1
= r600_get_temp(ctx
);
6251 for (i
= 0; i
< 4; i
++) {
6252 if (!(write_mask
& (1<<i
)))
6255 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6256 alu
.op
= ALU_OP2_SETGE_INT
;
6257 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6258 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
6259 alu
.src
[1].value
= 32;
6260 alu
.dst
.sel
= ctx
->temp_reg
;
6263 alu
.last
= i
== last_inst
;
6264 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6269 for (i
= 0; i
< 4; i
++) {
6270 if (!(write_mask
& (1<<i
)))
6273 /* create mask tmp */
6274 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6275 alu
.op
= ALU_OP2_BFM_INT
;
6279 alu
.last
= i
== last_inst
;
6281 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6282 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6284 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6289 t2
= r600_get_temp(ctx
);
6291 for (i
= 0; i
< 4; i
++) {
6292 if (!(write_mask
& (1<<i
)))
6295 /* shift insert left */
6296 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6297 alu
.op
= ALU_OP2_LSHL_INT
;
6301 alu
.last
= i
== last_inst
;
6303 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6304 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6306 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6311 for (i
= 0; i
< 4; i
++) {
6312 if (!(write_mask
& (1<<i
)))
6315 /* actual bitfield insert */
6316 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6317 alu
.op
= ALU_OP3_BFI_INT
;
6319 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6322 alu
.last
= i
== last_inst
;
6324 alu
.src
[0].sel
= t1
;
6325 alu
.src
[0].chan
= i
;
6326 alu
.src
[1].sel
= t2
;
6327 alu
.src
[1].chan
= i
;
6328 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6330 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6335 for (i
= 0; i
< 4; i
++) {
6336 if (!(write_mask
& (1<<i
)))
6338 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6339 alu
.op
= ALU_OP3_CNDE_INT
;
6341 alu
.src
[0].sel
= ctx
->temp_reg
;
6342 alu
.src
[0].chan
= i
;
6343 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
6345 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6347 alu
.src
[1].sel
= alu
.dst
.sel
;
6348 alu
.src
[1].chan
= i
;
6350 alu
.last
= i
== last_inst
;
6351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6358 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6360 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6361 struct r600_bytecode_alu alu
;
6364 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6365 int last_inst
= tgsi_last_instruction(write_mask
);
6367 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6368 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6372 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6373 for (i
= 0; i
< 4; i
++) {
6374 if (!(write_mask
& (1<<i
)))
6377 /* t1 = FFBH_INT / FFBH_UINT */
6378 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6379 alu
.op
= ctx
->inst_info
->op
;
6383 alu
.last
= i
== last_inst
;
6385 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6387 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6392 t2
= r600_get_temp(ctx
);
6394 for (i
= 0; i
< 4; i
++) {
6395 if (!(write_mask
& (1<<i
)))
6399 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6400 alu
.op
= ALU_OP2_SUB_INT
;
6404 alu
.last
= i
== last_inst
;
6406 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6407 alu
.src
[0].value
= 31;
6408 alu
.src
[1].sel
= t1
;
6409 alu
.src
[1].chan
= i
;
6411 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6416 for (i
= 0; i
< 4; i
++) {
6417 if (!(write_mask
& (1<<i
)))
6420 /* result = t1 >= 0 ? t2 : t1 */
6421 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6422 alu
.op
= ALU_OP3_CNDGE_INT
;
6424 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6427 alu
.last
= i
== last_inst
;
6429 alu
.src
[0].sel
= t1
;
6430 alu
.src
[0].chan
= i
;
6431 alu
.src
[1].sel
= t2
;
6432 alu
.src
[1].chan
= i
;
6433 alu
.src
[2].sel
= t1
;
6434 alu
.src
[2].chan
= i
;
6436 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6444 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6446 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6447 struct r600_bytecode_alu alu
;
6448 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6450 const int input
= inst
->Src
[0].Register
.Index
+ ctx
->shader
->nsys_inputs
;
6452 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6454 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6455 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6456 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6457 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6460 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6463 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6466 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6467 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6469 /* NOTE: currently offset is not perspective correct */
6470 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6471 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6472 int sample_gpr
= -1;
6473 int gradientsH
, gradientsV
;
6474 struct r600_bytecode_tex tex
;
6476 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6477 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6480 gradientsH
= r600_get_temp(ctx
);
6481 gradientsV
= r600_get_temp(ctx
);
6482 for (i
= 0; i
< 2; i
++) {
6483 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6484 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6485 tex
.src_gpr
= interp_gpr
;
6486 tex
.src_sel_x
= interp_base_chan
+ 0;
6487 tex
.src_sel_y
= interp_base_chan
+ 1;
6490 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6495 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6497 tex
.resource_id
= tex
.sampler_id
;
6498 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6503 for (i
= 0; i
< 2; i
++) {
6504 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6505 alu
.op
= ALU_OP3_MULADD
;
6507 alu
.src
[0].sel
= gradientsH
;
6508 alu
.src
[0].chan
= i
;
6509 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6510 alu
.src
[1].sel
= sample_gpr
;
6511 alu
.src
[1].chan
= 2;
6514 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6516 alu
.src
[2].sel
= interp_gpr
;
6517 alu
.src
[2].chan
= interp_base_chan
+ i
;
6518 alu
.dst
.sel
= ctx
->temp_reg
;
6522 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6527 for (i
= 0; i
< 2; i
++) {
6528 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6529 alu
.op
= ALU_OP3_MULADD
;
6531 alu
.src
[0].sel
= gradientsV
;
6532 alu
.src
[0].chan
= i
;
6533 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6534 alu
.src
[1].sel
= sample_gpr
;
6535 alu
.src
[1].chan
= 3;
6538 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6540 alu
.src
[2].sel
= ctx
->temp_reg
;
6541 alu
.src
[2].chan
= i
;
6542 alu
.dst
.sel
= ctx
->temp_reg
;
6546 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6552 tmp
= r600_get_temp(ctx
);
6553 for (i
= 0; i
< 8; i
++) {
6554 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6555 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6558 if ((i
> 1 && i
< 6)) {
6564 alu
.dst
.chan
= i
% 4;
6566 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6567 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6568 alu
.src
[0].sel
= ctx
->temp_reg
;
6569 alu
.src
[0].chan
= 1 - (i
% 2);
6571 alu
.src
[0].sel
= interp_gpr
;
6572 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6574 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6575 alu
.src
[1].chan
= 0;
6577 alu
.last
= i
% 4 == 3;
6578 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6580 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6585 // INTERP can't swizzle dst
6586 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6587 for (i
= 0; i
<= lasti
; i
++) {
6588 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6591 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6592 alu
.op
= ALU_OP1_MOV
;
6593 alu
.src
[0].sel
= tmp
;
6594 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6595 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6597 alu
.last
= i
== lasti
;
6598 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6607 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6609 struct r600_bytecode_alu alu
;
6612 for (i
= 0; i
< 4; i
++) {
6613 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6614 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6615 alu
.op
= ALU_OP0_NOP
;
6618 alu
.op
= ALU_OP1_MOV
;
6619 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6620 alu
.src
[0].sel
= ctx
->temp_reg
;
6621 alu
.src
[0].chan
= i
;
6626 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6633 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6634 unsigned temp
, int chan
,
6635 struct r600_bytecode_alu_src
*bc_src
,
6636 const struct r600_shader_src
*shader_src
)
6638 struct r600_bytecode_alu alu
;
6641 r600_bytecode_src(bc_src
, shader_src
, chan
);
6643 /* op3 operands don't support abs modifier */
6645 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6646 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6647 alu
.op
= ALU_OP1_MOV
;
6649 alu
.dst
.chan
= chan
;
6652 alu
.src
[0] = *bc_src
;
6653 alu
.last
= true; // sufficient?
6654 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6658 memset(bc_src
, 0, sizeof(*bc_src
));
6660 bc_src
->chan
= chan
;
6665 static int tgsi_op3_dst(struct r600_shader_ctx
*ctx
, int dst
)
6667 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6668 struct r600_bytecode_alu alu
;
6670 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6672 unsigned op
= ctx
->inst_info
->op
;
6674 if (op
== ALU_OP3_MULADD_IEEE
&&
6675 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6676 op
= ALU_OP3_MULADD
;
6678 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6680 if (ctx
->src
[j
].abs
)
6681 temp_regs
[j
] = r600_get_temp(ctx
);
6683 for (i
= 0; i
< lasti
+ 1; i
++) {
6684 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6687 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6689 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6690 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6696 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6706 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6713 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6715 return tgsi_op3_dst(ctx
, -1);
6718 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6720 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6721 struct r600_bytecode_alu alu
;
6723 unsigned op
= ctx
->inst_info
->op
;
6724 if (op
== ALU_OP2_DOT4_IEEE
&&
6725 ctx
->info
.properties
[TGSI_PROPERTY_MUL_ZERO_WINS
])
6728 for (i
= 0; i
< 4; i
++) {
6729 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6731 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6732 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6735 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6737 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6738 /* handle some special cases */
6739 switch (inst
->Instruction
.Opcode
) {
6740 case TGSI_OPCODE_DP2
:
6742 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6743 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6746 case TGSI_OPCODE_DP3
:
6748 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6749 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6758 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6765 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6768 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6769 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6770 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6771 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6772 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6773 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== PIPE_SHADER_GEOMETRY
);
6776 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6779 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6780 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6783 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6785 struct r600_bytecode_vtx vtx
;
6786 struct r600_bytecode_alu alu
;
6787 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6789 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6791 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6792 if (src_requires_loading
) {
6793 for (i
= 0; i
< 4; i
++) {
6794 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6795 alu
.op
= ALU_OP1_MOV
;
6796 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6797 alu
.dst
.sel
= ctx
->temp_reg
;
6802 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6806 src_gpr
= ctx
->temp_reg
;
6809 memset(&vtx
, 0, sizeof(vtx
));
6810 vtx
.op
= FETCH_OP_VFETCH
;
6811 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6812 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6813 vtx
.src_gpr
= src_gpr
;
6814 vtx
.mega_fetch_count
= 16;
6815 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6816 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6817 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6818 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6819 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6820 vtx
.use_const_fields
= 1;
6822 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6825 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6828 for (i
= 0; i
< 4; i
++) {
6829 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6830 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6833 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6834 alu
.op
= ALU_OP2_AND_INT
;
6837 alu
.dst
.sel
= vtx
.dst_gpr
;
6840 alu
.src
[0].sel
= vtx
.dst_gpr
;
6841 alu
.src
[0].chan
= i
;
6843 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6844 alu
.src
[1].sel
+= (id
* 2);
6845 alu
.src
[1].chan
= i
% 4;
6846 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6850 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6855 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6856 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6857 alu
.op
= ALU_OP2_OR_INT
;
6860 alu
.dst
.sel
= vtx
.dst_gpr
;
6863 alu
.src
[0].sel
= vtx
.dst_gpr
;
6864 alu
.src
[0].chan
= 3;
6866 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6867 alu
.src
[1].chan
= 0;
6868 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6871 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6878 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
, int reg_idx
, int offset
)
6880 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6881 struct r600_bytecode_alu alu
;
6883 int id
= tgsi_tex_get_src_gpr(ctx
, reg_idx
) + offset
;
6885 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6886 alu
.op
= ALU_OP1_MOV
;
6887 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6888 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6889 /* channel 0 or 2 of each word */
6890 alu
.src
[0].sel
+= (id
/ 2);
6891 alu
.src
[0].chan
= (id
% 2) * 2;
6893 /* r600 we have them at channel 2 of the second dword */
6894 alu
.src
[0].sel
+= (id
* 2) + 1;
6895 alu
.src
[0].chan
= 1;
6897 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6898 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6906 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6908 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6909 struct r600_bytecode_tex tex
;
6910 struct r600_bytecode_alu alu
;
6914 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
6915 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6916 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
6917 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
6919 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
6920 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6921 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
6923 /* Texture fetch instructions can only use gprs as source.
6924 * Also they cannot negate the source or take the absolute value */
6925 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
6926 tgsi_tex_src_requires_loading(ctx
, 0)) ||
6927 read_compressed_msaa
|| txf_add_offsets
;
6929 boolean src_loaded
= FALSE
;
6930 unsigned sampler_src_reg
= 1;
6931 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
6932 boolean has_txq_cube_array_z
= false;
6933 unsigned sampler_index_mode
;
6935 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
6936 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6937 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
6938 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
6939 ctx
->shader
->has_txq_cube_array_z_comp
= true;
6940 has_txq_cube_array_z
= true;
6943 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
6944 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6945 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
6946 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
6947 sampler_src_reg
= 2;
6949 /* TGSI moves the sampler to src reg 3 for TXD */
6950 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
6951 sampler_src_reg
= 3;
6953 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6955 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6957 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
6958 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
6959 ctx
->shader
->uses_tex_buffers
= true;
6960 return r600_do_buffer_txq(ctx
, 1, 0);
6962 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
6963 if (ctx
->bc
->chip_class
< EVERGREEN
)
6964 ctx
->shader
->uses_tex_buffers
= true;
6965 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
6969 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
6971 /* Add perspective divide */
6972 if (ctx
->bc
->chip_class
== CAYMAN
) {
6974 for (i
= 0; i
< 3; i
++) {
6975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6976 alu
.op
= ALU_OP1_RECIP_IEEE
;
6977 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6979 alu
.dst
.sel
= ctx
->temp_reg
;
6985 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6992 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6993 alu
.op
= ALU_OP1_RECIP_IEEE
;
6994 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6996 alu
.dst
.sel
= ctx
->temp_reg
;
6997 alu
.dst
.chan
= out_chan
;
7000 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7005 for (i
= 0; i
< 3; i
++) {
7006 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7007 alu
.op
= ALU_OP2_MUL
;
7008 alu
.src
[0].sel
= ctx
->temp_reg
;
7009 alu
.src
[0].chan
= out_chan
;
7010 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7011 alu
.dst
.sel
= ctx
->temp_reg
;
7014 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7019 alu
.op
= ALU_OP1_MOV
;
7020 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7021 alu
.src
[0].chan
= 0;
7022 alu
.dst
.sel
= ctx
->temp_reg
;
7026 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7030 src_gpr
= ctx
->temp_reg
;
7034 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7035 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7036 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7037 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7038 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
) {
7040 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
7041 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
7043 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
7044 for (i
= 0; i
< 4; i
++) {
7045 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7046 alu
.op
= ALU_OP2_CUBE
;
7047 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7048 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
7049 alu
.dst
.sel
= ctx
->temp_reg
;
7054 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7059 /* tmp1.z = RCP_e(|tmp1.z|) */
7060 if (ctx
->bc
->chip_class
== CAYMAN
) {
7061 for (i
= 0; i
< 3; i
++) {
7062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7063 alu
.op
= ALU_OP1_RECIP_IEEE
;
7064 alu
.src
[0].sel
= ctx
->temp_reg
;
7065 alu
.src
[0].chan
= 2;
7067 alu
.dst
.sel
= ctx
->temp_reg
;
7073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7079 alu
.op
= ALU_OP1_RECIP_IEEE
;
7080 alu
.src
[0].sel
= ctx
->temp_reg
;
7081 alu
.src
[0].chan
= 2;
7083 alu
.dst
.sel
= ctx
->temp_reg
;
7087 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7092 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
7093 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
7094 * muladd has no writemask, have to use another temp
7096 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7097 alu
.op
= ALU_OP3_MULADD
;
7100 alu
.src
[0].sel
= ctx
->temp_reg
;
7101 alu
.src
[0].chan
= 0;
7102 alu
.src
[1].sel
= ctx
->temp_reg
;
7103 alu
.src
[1].chan
= 2;
7105 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7106 alu
.src
[2].chan
= 0;
7107 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7109 alu
.dst
.sel
= ctx
->temp_reg
;
7113 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7117 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7118 alu
.op
= ALU_OP3_MULADD
;
7121 alu
.src
[0].sel
= ctx
->temp_reg
;
7122 alu
.src
[0].chan
= 1;
7123 alu
.src
[1].sel
= ctx
->temp_reg
;
7124 alu
.src
[1].chan
= 2;
7126 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7127 alu
.src
[2].chan
= 0;
7128 alu
.src
[2].value
= u_bitcast_f2u(1.5f
);
7130 alu
.dst
.sel
= ctx
->temp_reg
;
7135 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7138 /* write initial compare value into Z component
7139 - W src 0 for shadow cube
7140 - X src 1 for shadow cube array */
7141 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7142 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7143 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7144 alu
.op
= ALU_OP1_MOV
;
7145 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7146 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7148 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7149 alu
.dst
.sel
= ctx
->temp_reg
;
7153 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7158 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7159 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7160 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7161 int mytmp
= r600_get_temp(ctx
);
7162 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7163 alu
.op
= ALU_OP1_MOV
;
7164 alu
.src
[0].sel
= ctx
->temp_reg
;
7165 alu
.src
[0].chan
= 3;
7166 alu
.dst
.sel
= mytmp
;
7170 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7174 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7175 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7176 alu
.op
= ALU_OP3_MULADD
;
7178 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7179 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7180 alu
.src
[1].chan
= 0;
7181 alu
.src
[1].value
= u_bitcast_f2u(8.0f
);
7182 alu
.src
[2].sel
= mytmp
;
7183 alu
.src
[2].chan
= 0;
7184 alu
.dst
.sel
= ctx
->temp_reg
;
7188 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7191 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7192 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7193 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7194 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7195 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7196 tex
.src_gpr
= r600_get_temp(ctx
);
7201 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7202 tex
.coord_type_x
= 1;
7203 tex
.coord_type_y
= 1;
7204 tex
.coord_type_z
= 1;
7205 tex
.coord_type_w
= 1;
7206 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7207 alu
.op
= ALU_OP1_MOV
;
7208 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7209 alu
.dst
.sel
= tex
.src_gpr
;
7213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7217 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7224 /* for cube forms of lod and bias we need to route things */
7225 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7226 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7227 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7228 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7229 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7230 alu
.op
= ALU_OP1_MOV
;
7231 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7232 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7233 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7235 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7236 alu
.dst
.sel
= ctx
->temp_reg
;
7240 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7246 src_gpr
= ctx
->temp_reg
;
7249 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7250 int temp_h
= 0, temp_v
= 0;
7253 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7254 if (src_loaded
== TRUE
)
7258 for (i
= start_val
; i
< 3; i
++) {
7259 int treg
= r600_get_temp(ctx
);
7268 for (j
= 0; j
< 4; j
++) {
7269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7270 alu
.op
= ALU_OP1_MOV
;
7271 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7277 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7282 for (i
= 1; i
< 3; i
++) {
7283 /* set gradients h/v */
7284 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7285 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7286 FETCH_OP_SET_GRADIENTS_V
;
7287 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7288 tex
.sampler_index_mode
= sampler_index_mode
;
7289 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7290 tex
.resource_index_mode
= sampler_index_mode
;
7292 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7298 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7299 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7300 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7301 tex
.coord_type_x
= 1;
7302 tex
.coord_type_y
= 1;
7303 tex
.coord_type_z
= 1;
7304 tex
.coord_type_w
= 1;
7306 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7312 if (src_requires_loading
&& !src_loaded
) {
7313 for (i
= 0; i
< 4; i
++) {
7314 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7315 alu
.op
= ALU_OP1_MOV
;
7316 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7317 alu
.dst
.sel
= ctx
->temp_reg
;
7322 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7327 src_gpr
= ctx
->temp_reg
;
7330 /* get offset values */
7331 if (inst
->Texture
.NumOffsets
) {
7332 assert(inst
->Texture
.NumOffsets
== 1);
7334 /* The texture offset feature doesn't work with the TXF instruction
7335 * and must be emulated by adding the offset to the texture coordinates. */
7336 if (txf_add_offsets
) {
7337 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7339 switch (inst
->Texture
.Texture
) {
7340 case TGSI_TEXTURE_3D
:
7341 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7342 alu
.op
= ALU_OP2_ADD_INT
;
7343 alu
.src
[0].sel
= src_gpr
;
7344 alu
.src
[0].chan
= 2;
7345 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7346 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7347 alu
.dst
.sel
= src_gpr
;
7351 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7356 case TGSI_TEXTURE_2D
:
7357 case TGSI_TEXTURE_SHADOW2D
:
7358 case TGSI_TEXTURE_RECT
:
7359 case TGSI_TEXTURE_SHADOWRECT
:
7360 case TGSI_TEXTURE_2D_ARRAY
:
7361 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7362 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7363 alu
.op
= ALU_OP2_ADD_INT
;
7364 alu
.src
[0].sel
= src_gpr
;
7365 alu
.src
[0].chan
= 1;
7366 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7367 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7368 alu
.dst
.sel
= src_gpr
;
7372 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7377 case TGSI_TEXTURE_1D
:
7378 case TGSI_TEXTURE_SHADOW1D
:
7379 case TGSI_TEXTURE_1D_ARRAY
:
7380 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7381 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7382 alu
.op
= ALU_OP2_ADD_INT
;
7383 alu
.src
[0].sel
= src_gpr
;
7384 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7385 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7386 alu
.dst
.sel
= src_gpr
;
7389 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7393 /* texture offsets do not apply to other texture targets */
7396 switch (inst
->Texture
.Texture
) {
7397 case TGSI_TEXTURE_3D
:
7398 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7400 case TGSI_TEXTURE_2D
:
7401 case TGSI_TEXTURE_SHADOW2D
:
7402 case TGSI_TEXTURE_RECT
:
7403 case TGSI_TEXTURE_SHADOWRECT
:
7404 case TGSI_TEXTURE_2D_ARRAY
:
7405 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7406 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7408 case TGSI_TEXTURE_1D
:
7409 case TGSI_TEXTURE_SHADOW1D
:
7410 case TGSI_TEXTURE_1D_ARRAY
:
7411 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7412 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7417 /* Obtain the sample index for reading a compressed MSAA color texture.
7418 * To read the FMASK, we use the ldfptr instruction, which tells us
7419 * where the samples are stored.
7420 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7421 * which is the identity mapping. Each nibble says which physical sample
7422 * should be fetched to get that sample.
7424 * Assume src.z contains the sample index. It should be modified like this:
7425 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7426 * Then fetch the texel with src.
7428 if (read_compressed_msaa
) {
7429 unsigned sample_chan
= 3;
7430 unsigned temp
= r600_get_temp(ctx
);
7433 /* temp.w = ldfptr() */
7434 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7435 tex
.op
= FETCH_OP_LD
;
7436 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7437 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7438 tex
.sampler_index_mode
= sampler_index_mode
;
7439 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7440 tex
.resource_index_mode
= sampler_index_mode
;
7441 tex
.src_gpr
= src_gpr
;
7443 tex
.dst_sel_x
= 7; /* mask out these components */
7446 tex
.dst_sel_w
= 0; /* store X */
7451 tex
.offset_x
= offset_x
;
7452 tex
.offset_y
= offset_y
;
7453 tex
.offset_z
= offset_z
;
7454 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7458 /* temp.x = sample_index*4 */
7459 if (ctx
->bc
->chip_class
== CAYMAN
) {
7460 for (i
= 0 ; i
< 4; i
++) {
7461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7462 alu
.op
= ALU_OP2_MULLO_INT
;
7463 alu
.src
[0].sel
= src_gpr
;
7464 alu
.src
[0].chan
= sample_chan
;
7465 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7466 alu
.src
[1].value
= 4;
7469 alu
.dst
.write
= i
== 0;
7472 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7477 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7478 alu
.op
= ALU_OP2_MULLO_INT
;
7479 alu
.src
[0].sel
= src_gpr
;
7480 alu
.src
[0].chan
= sample_chan
;
7481 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7482 alu
.src
[1].value
= 4;
7487 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7492 /* sample_index = temp.w >> temp.x */
7493 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7494 alu
.op
= ALU_OP2_LSHR_INT
;
7495 alu
.src
[0].sel
= temp
;
7496 alu
.src
[0].chan
= 3;
7497 alu
.src
[1].sel
= temp
;
7498 alu
.src
[1].chan
= 0;
7499 alu
.dst
.sel
= src_gpr
;
7500 alu
.dst
.chan
= sample_chan
;
7503 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7507 /* sample_index & 0xF */
7508 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7509 alu
.op
= ALU_OP2_AND_INT
;
7510 alu
.src
[0].sel
= src_gpr
;
7511 alu
.src
[0].chan
= sample_chan
;
7512 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7513 alu
.src
[1].value
= 0xF;
7514 alu
.dst
.sel
= src_gpr
;
7515 alu
.dst
.chan
= sample_chan
;
7518 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7522 /* visualize the FMASK */
7523 for (i
= 0; i
< 4; i
++) {
7524 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7525 alu
.op
= ALU_OP1_INT_TO_FLT
;
7526 alu
.src
[0].sel
= src_gpr
;
7527 alu
.src
[0].chan
= sample_chan
;
7528 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7532 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7540 /* does this shader want a num layers from TXQ for a cube array? */
7541 if (has_txq_cube_array_z
) {
7542 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7544 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7545 alu
.op
= ALU_OP1_MOV
;
7547 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7548 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7549 /* channel 1 or 3 of each word */
7550 alu
.src
[0].sel
+= (id
/ 2);
7551 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
7553 /* r600 we have them at channel 2 of the second dword */
7554 alu
.src
[0].sel
+= (id
* 2) + 1;
7555 alu
.src
[0].chan
= 2;
7557 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7558 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7560 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7563 /* disable writemask from texture instruction */
7564 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7567 opcode
= ctx
->inst_info
->op
;
7568 if (opcode
== FETCH_OP_GATHER4
&&
7569 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7570 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7571 opcode
= FETCH_OP_GATHER4_O
;
7573 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7574 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7575 encoded in the instruction are ignored. */
7576 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7577 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7578 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7579 tex
.sampler_index_mode
= sampler_index_mode
;
7580 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7581 tex
.resource_index_mode
= sampler_index_mode
;
7583 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7584 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7585 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7586 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7594 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7599 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7600 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7601 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7602 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7603 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7604 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7605 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7607 case FETCH_OP_SAMPLE
:
7608 opcode
= FETCH_OP_SAMPLE_C
;
7610 case FETCH_OP_SAMPLE_L
:
7611 opcode
= FETCH_OP_SAMPLE_C_L
;
7613 case FETCH_OP_SAMPLE_LB
:
7614 opcode
= FETCH_OP_SAMPLE_C_LB
;
7616 case FETCH_OP_SAMPLE_G
:
7617 opcode
= FETCH_OP_SAMPLE_C_G
;
7619 /* Texture gather variants */
7620 case FETCH_OP_GATHER4
:
7621 opcode
= FETCH_OP_GATHER4_C
;
7623 case FETCH_OP_GATHER4_O
:
7624 opcode
= FETCH_OP_GATHER4_C_O
;
7629 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7632 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7633 tex
.sampler_index_mode
= sampler_index_mode
;
7634 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7635 tex
.resource_index_mode
= sampler_index_mode
;
7636 tex
.src_gpr
= src_gpr
;
7637 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7639 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7640 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7641 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7644 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7645 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7646 tex
.inst_mod
= texture_component_select
;
7648 if (ctx
->bc
->chip_class
== CAYMAN
) {
7649 /* GATHER4 result order is different from TGSI TG4 */
7650 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7651 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7652 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7653 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7655 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7656 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7657 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7658 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7661 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7662 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7663 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7667 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7674 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7675 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7676 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7677 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7681 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7686 } else if (src_loaded
) {
7692 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7693 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7694 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7695 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7696 tex
.src_rel
= ctx
->src
[0].rel
;
7699 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7700 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7701 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7702 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7706 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7709 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7710 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7711 tex
.coord_type_x
= 1;
7712 tex
.coord_type_y
= 1;
7714 tex
.coord_type_z
= 1;
7715 tex
.coord_type_w
= 1;
7717 tex
.offset_x
= offset_x
;
7718 tex
.offset_y
= offset_y
;
7719 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7720 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7721 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7725 tex
.offset_z
= offset_z
;
7728 /* Put the depth for comparison in W.
7729 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7730 * Some instructions expect the depth in Z. */
7731 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7732 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7733 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7734 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7735 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7736 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7737 tex
.src_sel_w
= tex
.src_sel_z
;
7740 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7741 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7742 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7743 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7744 /* the array index is read from Y */
7745 tex
.coord_type_y
= 0;
7747 /* the array index is read from Z */
7748 tex
.coord_type_z
= 0;
7749 tex
.src_sel_z
= tex
.src_sel_y
;
7751 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7752 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7753 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7754 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7755 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7756 /* the array index is read from Z */
7757 tex
.coord_type_z
= 0;
7759 /* mask unused source components */
7760 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7761 switch (inst
->Texture
.Texture
) {
7762 case TGSI_TEXTURE_2D
:
7763 case TGSI_TEXTURE_RECT
:
7767 case TGSI_TEXTURE_1D_ARRAY
:
7771 case TGSI_TEXTURE_1D
:
7779 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7783 /* add shadow ambient support - gallium doesn't do it yet */
7787 static int find_hw_atomic_counter(struct r600_shader_ctx
*ctx
,
7788 struct tgsi_full_src_register
*src
)
7792 if (src
->Register
.Indirect
) {
7793 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7794 if (src
->Indirect
.ArrayID
== ctx
->shader
->atomics
[i
].array_id
)
7795 return ctx
->shader
->atomics
[i
].hw_idx
;
7798 uint32_t index
= src
->Register
.Index
;
7799 for (i
= 0; i
< ctx
->shader
->nhwatomic_ranges
; i
++) {
7800 if (ctx
->shader
->atomics
[i
].buffer_id
!= (unsigned)src
->Dimension
.Index
)
7802 if (index
> ctx
->shader
->atomics
[i
].end
)
7804 if (index
< ctx
->shader
->atomics
[i
].start
)
7806 uint32_t offset
= (index
- ctx
->shader
->atomics
[i
].start
);
7807 return ctx
->shader
->atomics
[i
].hw_idx
+ offset
;
7814 static int tgsi_set_gds_temp(struct r600_shader_ctx
*ctx
,
7815 int *uav_id_p
, int *uav_index_mode_p
)
7817 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7818 int uav_id
, uav_index_mode
;
7820 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7822 uav_id
= find_hw_atomic_counter(ctx
, &inst
->Src
[0]);
7824 if (inst
->Src
[0].Register
.Indirect
) {
7826 struct r600_bytecode_alu alu
;
7827 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7828 alu
.op
= ALU_OP2_LSHL_INT
;
7829 alu
.src
[0].sel
= get_address_file_reg(ctx
, inst
->Src
[0].Indirect
.Index
);
7830 alu
.src
[0].chan
= 0;
7831 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7832 alu
.src
[1].value
= 2;
7833 alu
.dst
.sel
= ctx
->temp_reg
;
7837 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7841 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
7844 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4);
7850 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
7852 V_SQ_ALU_SRC_LITERAL
, uav_id
* 4,
7858 *uav_index_mode_p
= uav_index_mode
;
7862 static int tgsi_load_gds(struct r600_shader_ctx
*ctx
)
7864 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7866 struct r600_bytecode_gds gds
;
7868 int uav_index_mode
= 0;
7869 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
7871 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
7875 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
7876 gds
.op
= FETCH_OP_GDS_READ_RET
;
7877 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7878 gds
.uav_id
= is_cm
? 0 : uav_id
;
7879 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
7880 gds
.src_gpr
= ctx
->temp_reg
;
7881 gds
.src_sel_x
= (is_cm
) ? 0 : 4;
7889 gds
.alloc_consume
= !is_cm
;
7890 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
7894 ctx
->bc
->cf_last
->vpm
= 1;
7898 /* this fixes up 1D arrays properly */
7899 static int load_index_src(struct r600_shader_ctx
*ctx
, int src_index
, int *idx_gpr
)
7901 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7903 struct r600_bytecode_alu alu
;
7904 int temp_reg
= r600_get_temp(ctx
);
7906 for (i
= 0; i
< 4; i
++) {
7907 bool def_val
= true, write_zero
= false;
7908 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7909 alu
.op
= ALU_OP1_MOV
;
7910 alu
.dst
.sel
= temp_reg
;
7913 switch (inst
->Memory
.Texture
) {
7914 case TGSI_TEXTURE_BUFFER
:
7915 case TGSI_TEXTURE_1D
:
7916 if (i
== 1 || i
== 2 || i
== 3) {
7920 case TGSI_TEXTURE_1D_ARRAY
:
7921 if (i
== 1 || i
== 3)
7924 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], 1);
7928 case TGSI_TEXTURE_2D
:
7929 if (i
== 2 || i
== 3)
7939 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
7940 alu
.src
[0].value
= 0;
7941 } else if (def_val
) {
7942 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_index
], i
);
7948 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7952 *idx_gpr
= temp_reg
;
7956 static int load_buffer_coord(struct r600_shader_ctx
*ctx
, int src_idx
,
7959 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7961 if (inst
->Src
[src_idx
].Register
.File
== TGSI_FILE_IMMEDIATE
) {
7962 int value
= (ctx
->literals
[4 * inst
->Src
[src_idx
].Register
.Index
+ inst
->Src
[src_idx
].Register
.SwizzleX
]);
7963 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
7965 V_SQ_ALU_SRC_LITERAL
, value
>> 2,
7970 struct r600_bytecode_alu alu
;
7971 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7972 alu
.op
= ALU_OP2_LSHR_INT
;
7973 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[src_idx
], 0);
7974 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7975 alu
.src
[1].value
= 2;
7976 alu
.dst
.sel
= temp_reg
;
7979 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7986 static int tgsi_load_buffer(struct r600_shader_ctx
*ctx
)
7988 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7989 /* have to work out the offset into the RAT immediate return buffer */
7990 struct r600_bytecode_vtx vtx
;
7991 struct r600_bytecode_cf
*cf
;
7993 int temp_reg
= r600_get_temp(ctx
);
7994 unsigned rat_index_mode
;
7997 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
7998 base
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8000 r
= load_buffer_coord(ctx
, 1, temp_reg
);
8003 ctx
->bc
->cf_last
->barrier
= 1;
8004 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8005 vtx
.op
= FETCH_OP_VFETCH
;
8006 vtx
.buffer_id
= inst
->Src
[0].Register
.Index
+ base
;
8007 vtx
.buffer_index_mode
= rat_index_mode
;
8008 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8009 vtx
.src_gpr
= temp_reg
;
8011 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8012 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
8013 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
8014 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
8015 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
8016 vtx
.num_format_all
= 1;
8017 vtx
.format_comp_all
= 1;
8018 vtx
.srf_mode_all
= 0;
8020 if (inst
->Dst
[0].Register
.WriteMask
& 8) {
8021 vtx
.data_format
= FMT_32_32_32_32
;
8022 vtx
.use_const_fields
= 0;
8023 } else if (inst
->Dst
[0].Register
.WriteMask
& 4) {
8024 vtx
.data_format
= FMT_32_32_32
;
8025 vtx
.use_const_fields
= 0;
8026 } else if (inst
->Dst
[0].Register
.WriteMask
& 2) {
8027 vtx
.data_format
= FMT_32_32
;
8028 vtx
.use_const_fields
= 0;
8030 vtx
.data_format
= FMT_32
;
8031 vtx
.use_const_fields
= 0;
8034 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8037 cf
= ctx
->bc
->cf_last
;
8042 static int tgsi_load_rat(struct r600_shader_ctx
*ctx
)
8044 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8045 /* have to work out the offset into the RAT immediate return buffer */
8046 struct r600_bytecode_vtx vtx
;
8047 struct r600_bytecode_cf
*cf
;
8050 unsigned format
, num_format
, format_comp
, endian
;
8051 const struct util_format_description
*desc
;
8052 unsigned rat_index_mode
;
8053 unsigned immed_base
;
8055 r
= load_thread_id_gpr(ctx
);
8059 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8061 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8062 r
= load_index_src(ctx
, 1, &idx_gpr
);
8067 egcm_load_index_reg(ctx
->bc
, 1, false);
8069 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8070 cf
= ctx
->bc
->cf_last
;
8072 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Src
[0].Register
.Index
;
8073 cf
->rat
.inst
= V_RAT_INST_NOP_RTN
;
8074 cf
->rat
.index_mode
= rat_index_mode
;
8075 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8076 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8077 cf
->output
.index_gpr
= idx_gpr
;
8078 cf
->output
.comp_mask
= 0xf;
8079 cf
->output
.burst_count
= 1;
8083 cf
->output
.elem_size
= 0;
8085 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8086 cf
= ctx
->bc
->cf_last
;
8089 desc
= util_format_description(inst
->Memory
.Format
);
8090 r600_vertex_data_type(inst
->Memory
.Format
,
8091 &format
, &num_format
, &format_comp
, &endian
);
8092 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8093 vtx
.op
= FETCH_OP_VFETCH
;
8094 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8095 vtx
.buffer_index_mode
= rat_index_mode
;
8096 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8097 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8099 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8100 vtx
.dst_sel_x
= desc
->swizzle
[0];
8101 vtx
.dst_sel_y
= desc
->swizzle
[1];
8102 vtx
.dst_sel_z
= desc
->swizzle
[2];
8103 vtx
.dst_sel_w
= desc
->swizzle
[3];
8104 vtx
.srf_mode_all
= 1;
8105 vtx
.data_format
= format
;
8106 vtx
.num_format_all
= num_format
;
8107 vtx
.format_comp_all
= format_comp
;
8108 vtx
.endian
= endian
;
8110 vtx
.mega_fetch_count
= 3;
8111 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8114 cf
= ctx
->bc
->cf_last
;
8119 static int tgsi_load_lds(struct r600_shader_ctx
*ctx
)
8121 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8122 struct r600_bytecode_alu alu
;
8124 int temp_reg
= r600_get_temp(ctx
);
8126 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8127 alu
.op
= ALU_OP1_MOV
;
8128 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8129 alu
.dst
.sel
= temp_reg
;
8132 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8136 r
= do_lds_fetch_values(ctx
, temp_reg
,
8137 ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
, inst
->Dst
[0].Register
.WriteMask
);
8143 static int tgsi_load(struct r600_shader_ctx
*ctx
)
8145 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8146 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8147 return tgsi_load_rat(ctx
);
8148 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8149 return tgsi_load_gds(ctx
);
8150 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8151 return tgsi_load_buffer(ctx
);
8152 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8153 return tgsi_load_lds(ctx
);
8157 static int tgsi_store_buffer_rat(struct r600_shader_ctx
*ctx
)
8159 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8160 struct r600_bytecode_cf
*cf
;
8162 unsigned rat_index_mode
;
8164 int temp_reg
= r600_get_temp(ctx
), treg2
= r600_get_temp(ctx
);
8166 r
= load_buffer_coord(ctx
, 0, treg2
);
8170 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8172 egcm_load_index_reg(ctx
->bc
, 1, false);
8174 for (i
= 0; i
<= 3; i
++) {
8175 struct r600_bytecode_alu alu
;
8176 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8177 alu
.op
= ALU_OP1_MOV
;
8178 alu
.dst
.sel
= temp_reg
;
8180 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
8181 alu
.last
= (i
== 3);
8183 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8188 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8189 for (i
= 0; i
<= lasti
; i
++) {
8190 struct r600_bytecode_alu alu
;
8191 if (!((1 << i
) & inst
->Dst
[0].Register
.WriteMask
))
8194 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8197 V_SQ_ALU_SRC_LITERAL
, i
);
8201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8202 alu
.op
= ALU_OP1_MOV
;
8203 alu
.dst
.sel
= ctx
->temp_reg
;
8206 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8209 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8213 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8214 cf
= ctx
->bc
->cf_last
;
8216 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
+ ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8217 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8218 cf
->rat
.index_mode
= rat_index_mode
;
8219 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8220 cf
->output
.gpr
= ctx
->temp_reg
;
8221 cf
->output
.index_gpr
= temp_reg
;
8222 cf
->output
.comp_mask
= 1;
8223 cf
->output
.burst_count
= 1;
8226 cf
->output
.elem_size
= 0;
8231 static int tgsi_store_rat(struct r600_shader_ctx
*ctx
)
8233 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8234 struct r600_bytecode_cf
*cf
;
8235 bool src_requires_loading
= false;
8236 int val_gpr
, idx_gpr
;
8238 unsigned rat_index_mode
;
8240 rat_index_mode
= inst
->Dst
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8242 r
= load_index_src(ctx
, 0, &idx_gpr
);
8246 if (inst
->Src
[1].Register
.File
!= TGSI_FILE_TEMPORARY
)
8247 src_requires_loading
= true;
8249 if (src_requires_loading
) {
8250 struct r600_bytecode_alu alu
;
8251 for (i
= 0; i
< 4; i
++) {
8252 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8253 alu
.op
= ALU_OP1_MOV
;
8254 alu
.dst
.sel
= ctx
->temp_reg
;
8257 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8261 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8265 val_gpr
= ctx
->temp_reg
;
8267 val_gpr
= tgsi_tex_get_src_gpr(ctx
, 1);
8269 egcm_load_index_reg(ctx
->bc
, 1, false);
8271 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8272 cf
= ctx
->bc
->cf_last
;
8274 cf
->rat
.id
= ctx
->shader
->rat_base
+ inst
->Dst
[0].Register
.Index
;
8275 cf
->rat
.inst
= V_RAT_INST_STORE_TYPED
;
8276 cf
->rat
.index_mode
= rat_index_mode
;
8277 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
8278 cf
->output
.gpr
= val_gpr
;
8279 cf
->output
.index_gpr
= idx_gpr
;
8280 cf
->output
.comp_mask
= 0xf;
8281 cf
->output
.burst_count
= 1;
8284 cf
->output
.elem_size
= 0;
8288 static int tgsi_store_lds(struct r600_shader_ctx
*ctx
)
8290 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8291 struct r600_bytecode_alu alu
;
8293 int write_mask
= inst
->Dst
[0].Register
.WriteMask
;
8294 int temp_reg
= r600_get_temp(ctx
);
8297 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8298 alu
.op
= ALU_OP1_MOV
;
8299 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8300 alu
.dst
.sel
= temp_reg
;
8303 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8307 lasti
= tgsi_last_instruction(write_mask
);
8308 for (i
= 1; i
<= lasti
; i
++) {
8309 if (!(write_mask
& (1 << i
)))
8311 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
8314 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
8318 for (i
= 0; i
<= lasti
; i
++) {
8319 if (!(write_mask
& (1 << i
)))
8322 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
8323 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
8324 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8325 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
8327 alu
.src
[0].sel
= temp_reg
;
8328 alu
.src
[0].chan
= i
;
8329 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8330 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
+ 1);
8332 alu
.is_lds_idx_op
= true;
8334 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8341 alu
.op
= LDS_OP2_LDS_WRITE
;
8343 alu
.src
[0].sel
= temp_reg
;
8344 alu
.src
[0].chan
= i
;
8345 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8348 alu
.is_lds_idx_op
= true;
8350 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8357 static int tgsi_store(struct r600_shader_ctx
*ctx
)
8359 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8360 if (inst
->Dst
[0].Register
.File
== TGSI_FILE_BUFFER
)
8361 return tgsi_store_buffer_rat(ctx
);
8362 else if (inst
->Dst
[0].Register
.File
== TGSI_FILE_MEMORY
)
8363 return tgsi_store_lds(ctx
);
8365 return tgsi_store_rat(ctx
);
8368 static int tgsi_atomic_op_rat(struct r600_shader_ctx
*ctx
)
8370 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8371 /* have to work out the offset into the RAT immediate return buffer */
8372 struct r600_bytecode_alu alu
;
8373 struct r600_bytecode_vtx vtx
;
8374 struct r600_bytecode_cf
*cf
;
8377 unsigned format
, num_format
, format_comp
, endian
;
8378 const struct util_format_description
*desc
;
8379 unsigned rat_index_mode
;
8380 unsigned immed_base
;
8383 immed_base
= R600_IMAGE_IMMED_RESOURCE_OFFSET
;
8384 rat_base
= ctx
->shader
->rat_base
;
8386 r
= load_thread_id_gpr(ctx
);
8390 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
) {
8391 immed_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8392 rat_base
+= ctx
->info
.file_count
[TGSI_FILE_IMAGE
];
8394 r
= load_buffer_coord(ctx
, 1, ctx
->temp_reg
);
8397 idx_gpr
= ctx
->temp_reg
;
8399 r
= load_index_src(ctx
, 1, &idx_gpr
);
8404 rat_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8406 if (ctx
->inst_info
->op
== V_RAT_INST_CMPXCHG_INT_RTN
) {
8407 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8408 alu
.op
= ALU_OP1_MOV
;
8409 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8412 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], 0);
8414 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8418 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8419 alu
.op
= ALU_OP1_MOV
;
8420 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8421 if (ctx
->bc
->chip_class
== CAYMAN
)
8426 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8428 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8432 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8433 alu
.op
= ALU_OP1_MOV
;
8434 alu
.dst
.sel
= ctx
->thread_id_gpr
;
8437 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8439 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8445 egcm_load_index_reg(ctx
->bc
, 1, false);
8446 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_MEM_RAT
);
8447 cf
= ctx
->bc
->cf_last
;
8449 cf
->rat
.id
= rat_base
+ inst
->Src
[0].Register
.Index
;
8450 cf
->rat
.inst
= ctx
->inst_info
->op
;
8451 cf
->rat
.index_mode
= rat_index_mode
;
8452 cf
->output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_READ_IND
;
8453 cf
->output
.gpr
= ctx
->thread_id_gpr
;
8454 cf
->output
.index_gpr
= idx_gpr
;
8455 cf
->output
.comp_mask
= 0xf;
8456 cf
->output
.burst_count
= 1;
8460 cf
->output
.elem_size
= 0;
8461 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_WAIT_ACK
);
8462 cf
= ctx
->bc
->cf_last
;
8466 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
8467 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
) {
8468 desc
= util_format_description(inst
->Memory
.Format
);
8469 r600_vertex_data_type(inst
->Memory
.Format
,
8470 &format
, &num_format
, &format_comp
, &endian
);
8471 vtx
.dst_sel_x
= desc
->swizzle
[0];
8479 vtx
.op
= FETCH_OP_VFETCH
;
8480 vtx
.buffer_id
= immed_base
+ inst
->Src
[0].Register
.Index
;
8481 vtx
.buffer_index_mode
= rat_index_mode
;
8482 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
8483 vtx
.src_gpr
= ctx
->thread_id_gpr
;
8485 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8489 vtx
.use_const_fields
= 0;
8490 vtx
.srf_mode_all
= 1;
8491 vtx
.data_format
= format
;
8492 vtx
.num_format_all
= num_format
;
8493 vtx
.format_comp_all
= format_comp
;
8494 vtx
.endian
= endian
;
8496 vtx
.mega_fetch_count
= 0xf;
8497 r
= r600_bytecode_add_vtx_tc(ctx
->bc
, &vtx
);
8500 cf
= ctx
->bc
->cf_last
;
8506 static int get_gds_op(int opcode
)
8509 case TGSI_OPCODE_ATOMUADD
:
8510 return FETCH_OP_GDS_ADD_RET
;
8511 case TGSI_OPCODE_ATOMAND
:
8512 return FETCH_OP_GDS_AND_RET
;
8513 case TGSI_OPCODE_ATOMOR
:
8514 return FETCH_OP_GDS_OR_RET
;
8515 case TGSI_OPCODE_ATOMXOR
:
8516 return FETCH_OP_GDS_XOR_RET
;
8517 case TGSI_OPCODE_ATOMUMIN
:
8518 return FETCH_OP_GDS_MIN_UINT_RET
;
8519 case TGSI_OPCODE_ATOMUMAX
:
8520 return FETCH_OP_GDS_MAX_UINT_RET
;
8521 case TGSI_OPCODE_ATOMXCHG
:
8522 return FETCH_OP_GDS_XCHG_RET
;
8523 case TGSI_OPCODE_ATOMCAS
:
8524 return FETCH_OP_GDS_CMP_XCHG_RET
;
8530 static int tgsi_atomic_op_gds(struct r600_shader_ctx
*ctx
)
8532 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8533 struct r600_bytecode_gds gds
;
8534 struct r600_bytecode_alu alu
;
8535 int gds_op
= get_gds_op(inst
->Instruction
.Opcode
);
8538 int uav_index_mode
= 0;
8539 bool is_cm
= (ctx
->bc
->chip_class
== CAYMAN
);
8542 fprintf(stderr
, "unknown GDS op for opcode %d\n", inst
->Instruction
.Opcode
);
8546 r
= tgsi_set_gds_temp(ctx
, &uav_id
, &uav_index_mode
);
8550 if (inst
->Src
[2].Register
.File
== TGSI_FILE_IMMEDIATE
) {
8551 int value
= (ctx
->literals
[4 * inst
->Src
[2].Register
.Index
+ inst
->Src
[2].Register
.SwizzleX
]);
8552 int abs_value
= abs(value
);
8553 if (abs_value
!= value
&& gds_op
== FETCH_OP_GDS_ADD_RET
)
8554 gds_op
= FETCH_OP_GDS_SUB_RET
;
8555 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8556 alu
.op
= ALU_OP1_MOV
;
8557 alu
.dst
.sel
= ctx
->temp_reg
;
8558 alu
.dst
.chan
= is_cm
? 1 : 0;
8559 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
8560 alu
.src
[0].value
= abs_value
;
8563 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8567 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8568 alu
.op
= ALU_OP1_MOV
;
8569 alu
.dst
.sel
= ctx
->temp_reg
;
8570 alu
.dst
.chan
= is_cm
? 1 : 0;
8571 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], 0);
8574 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8580 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
8582 gds
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8583 gds
.uav_id
= is_cm
? 0 : uav_id
;
8584 gds
.uav_index_mode
= is_cm
? 0 : uav_index_mode
;
8585 gds
.src_gpr
= ctx
->temp_reg
;
8587 gds
.src_sel_x
= is_cm
? 0 : 4;
8588 gds
.src_sel_y
= is_cm
? 1 : 0;
8594 gds
.alloc_consume
= !is_cm
;
8596 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
8599 ctx
->bc
->cf_last
->vpm
= 1;
8603 static int get_lds_op(int opcode
)
8606 case TGSI_OPCODE_ATOMUADD
:
8607 return LDS_OP2_LDS_ADD_RET
;
8608 case TGSI_OPCODE_ATOMAND
:
8609 return LDS_OP2_LDS_AND_RET
;
8610 case TGSI_OPCODE_ATOMOR
:
8611 return LDS_OP2_LDS_OR_RET
;
8612 case TGSI_OPCODE_ATOMXOR
:
8613 return LDS_OP2_LDS_XOR_RET
;
8614 case TGSI_OPCODE_ATOMUMIN
:
8615 return LDS_OP2_LDS_MIN_UINT_RET
;
8616 case TGSI_OPCODE_ATOMUMAX
:
8617 return LDS_OP2_LDS_MAX_UINT_RET
;
8618 case TGSI_OPCODE_ATOMIMIN
:
8619 return LDS_OP2_LDS_MIN_INT_RET
;
8620 case TGSI_OPCODE_ATOMIMAX
:
8621 return LDS_OP2_LDS_MAX_INT_RET
;
8622 case TGSI_OPCODE_ATOMXCHG
:
8623 return LDS_OP2_LDS_XCHG_RET
;
8624 case TGSI_OPCODE_ATOMCAS
:
8625 return LDS_OP3_LDS_CMP_XCHG_RET
;
8631 static int tgsi_atomic_op_lds(struct r600_shader_ctx
*ctx
)
8633 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8634 int lds_op
= get_lds_op(inst
->Instruction
.Opcode
);
8637 struct r600_bytecode_alu alu
;
8638 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8640 alu
.is_lds_idx_op
= true;
8642 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
8643 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], 0);
8644 if (lds_op
== LDS_OP3_LDS_CMP_XCHG_RET
)
8645 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[3], 0);
8647 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
8648 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8652 /* then read from LDS_OQ_A_POP */
8653 memset(&alu
, 0, sizeof(alu
));
8655 alu
.op
= ALU_OP1_MOV
;
8656 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
8657 alu
.src
[0].chan
= 0;
8658 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
8661 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8668 static int tgsi_atomic_op(struct r600_shader_ctx
*ctx
)
8670 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8671 if (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
)
8672 return tgsi_atomic_op_rat(ctx
);
8673 if (inst
->Src
[0].Register
.File
== TGSI_FILE_HW_ATOMIC
)
8674 return tgsi_atomic_op_gds(ctx
);
8675 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
)
8676 return tgsi_atomic_op_rat(ctx
);
8677 if (inst
->Src
[0].Register
.File
== TGSI_FILE_MEMORY
)
8678 return tgsi_atomic_op_lds(ctx
);
8682 static int tgsi_resq(struct r600_shader_ctx
*ctx
)
8684 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8685 unsigned sampler_index_mode
;
8686 struct r600_bytecode_tex tex
;
8688 boolean has_txq_cube_array_z
= false;
8690 if (inst
->Src
[0].Register
.File
== TGSI_FILE_BUFFER
||
8691 (inst
->Src
[0].Register
.File
== TGSI_FILE_IMAGE
&& inst
->Memory
.Texture
== TGSI_TEXTURE_BUFFER
)) {
8692 ctx
->shader
->uses_tex_buffers
= true;
8693 return r600_do_buffer_txq(ctx
, 0, ctx
->shader
->image_size_const_offset
);
8696 if (inst
->Memory
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
&&
8697 inst
->Dst
[0].Register
.WriteMask
& 4) {
8698 ctx
->shader
->has_txq_cube_array_z_comp
= true;
8699 has_txq_cube_array_z
= true;
8702 sampler_index_mode
= inst
->Src
[0].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
8703 if (sampler_index_mode
)
8704 egcm_load_index_reg(ctx
->bc
, 1, false);
8707 /* does this shader want a num layers from TXQ for a cube array? */
8708 if (has_txq_cube_array_z
) {
8709 int id
= tgsi_tex_get_src_gpr(ctx
, 0) + ctx
->shader
->image_size_const_offset
;
8710 struct r600_bytecode_alu alu
;
8712 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8713 alu
.op
= ALU_OP1_MOV
;
8715 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
8716 /* channel 1 or 3 of each word */
8717 alu
.src
[0].sel
+= (id
/ 2);
8718 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
8719 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
8720 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
8722 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8725 /* disable writemask from texture instruction */
8726 inst
->Dst
[0].Register
.WriteMask
&= ~4;
8728 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
8729 tex
.op
= ctx
->inst_info
->op
;
8730 tex
.sampler_id
= R600_IMAGE_REAL_RESOURCE_OFFSET
+ inst
->Src
[0].Register
.Index
;
8731 tex
.sampler_index_mode
= sampler_index_mode
;
8732 tex
.resource_id
= tex
.sampler_id
;
8733 tex
.resource_index_mode
= sampler_index_mode
;
8738 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
8739 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
8740 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
8741 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
8742 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
8743 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
8750 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
8752 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8753 struct r600_bytecode_alu alu
;
8754 unsigned lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8755 unsigned i
, temp_regs
[2];
8758 /* optimize if it's just an equal balance */
8759 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
8760 for (i
= 0; i
< lasti
+ 1; i
++) {
8761 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8764 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8765 alu
.op
= ALU_OP2_ADD
;
8766 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
8767 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8769 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8774 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8782 for (i
= 0; i
< lasti
+ 1; i
++) {
8783 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8786 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8787 alu
.op
= ALU_OP2_ADD
;
8788 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8789 alu
.src
[0].chan
= 0;
8790 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
8791 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
8792 alu
.dst
.sel
= ctx
->temp_reg
;
8798 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8803 /* (1 - src0) * src2 */
8804 for (i
= 0; i
< lasti
+ 1; i
++) {
8805 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8808 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8809 alu
.op
= ALU_OP2_MUL
;
8810 alu
.src
[0].sel
= ctx
->temp_reg
;
8811 alu
.src
[0].chan
= i
;
8812 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8813 alu
.dst
.sel
= ctx
->temp_reg
;
8819 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8824 /* src0 * src1 + (1 - src0) * src2 */
8825 if (ctx
->src
[0].abs
)
8826 temp_regs
[0] = r600_get_temp(ctx
);
8829 if (ctx
->src
[1].abs
)
8830 temp_regs
[1] = r600_get_temp(ctx
);
8834 for (i
= 0; i
< lasti
+ 1; i
++) {
8835 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8838 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8839 alu
.op
= ALU_OP3_MULADD
;
8841 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8844 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
8847 alu
.src
[2].sel
= ctx
->temp_reg
;
8848 alu
.src
[2].chan
= i
;
8850 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8855 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8862 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
8864 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8865 struct r600_bytecode_alu alu
;
8867 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8871 if (ctx
->src
[0].abs
&& ctx
->src
[0].neg
) {
8873 ctx
->src
[0].abs
= 0;
8874 ctx
->src
[0].neg
= 0;
8879 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
8881 if (ctx
->src
[j
].abs
)
8882 temp_regs
[j
] = r600_get_temp(ctx
);
8885 for (i
= 0; i
< lasti
+ 1; i
++) {
8886 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8891 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
8894 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
8897 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
8900 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8906 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8913 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
8915 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8916 struct r600_bytecode_alu alu
;
8918 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8920 for (i
= 0; i
< lasti
+ 1; i
++) {
8921 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8924 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8925 alu
.op
= ALU_OP3_CNDE_INT
;
8926 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8927 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8928 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
8929 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8935 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8942 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
8944 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8945 struct r600_bytecode_alu alu
;
8949 /* result.x = 2^floor(src); */
8950 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8951 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8953 alu
.op
= ALU_OP1_FLOOR
;
8954 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8956 alu
.dst
.sel
= ctx
->temp_reg
;
8960 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8964 if (ctx
->bc
->chip_class
== CAYMAN
) {
8965 for (i
= 0; i
< 3; i
++) {
8966 alu
.op
= ALU_OP1_EXP_IEEE
;
8967 alu
.src
[0].sel
= ctx
->temp_reg
;
8968 alu
.src
[0].chan
= 0;
8970 alu
.dst
.sel
= ctx
->temp_reg
;
8972 alu
.dst
.write
= i
== 0;
8974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8979 alu
.op
= ALU_OP1_EXP_IEEE
;
8980 alu
.src
[0].sel
= ctx
->temp_reg
;
8981 alu
.src
[0].chan
= 0;
8983 alu
.dst
.sel
= ctx
->temp_reg
;
8987 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8993 /* result.y = tmp - floor(tmp); */
8994 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8995 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8997 alu
.op
= ALU_OP1_FRACT
;
8998 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9000 alu
.dst
.sel
= ctx
->temp_reg
;
9002 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9011 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9016 /* result.z = RoughApprox2ToX(tmp);*/
9017 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
9018 if (ctx
->bc
->chip_class
== CAYMAN
) {
9019 for (i
= 0; i
< 3; i
++) {
9020 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9021 alu
.op
= ALU_OP1_EXP_IEEE
;
9022 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9024 alu
.dst
.sel
= ctx
->temp_reg
;
9031 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9037 alu
.op
= ALU_OP1_EXP_IEEE
;
9038 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9040 alu
.dst
.sel
= ctx
->temp_reg
;
9046 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9052 /* result.w = 1.0;*/
9053 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
9054 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9056 alu
.op
= ALU_OP1_MOV
;
9057 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9058 alu
.src
[0].chan
= 0;
9060 alu
.dst
.sel
= ctx
->temp_reg
;
9064 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9068 return tgsi_helper_copy(ctx
, inst
);
9071 static int tgsi_log(struct r600_shader_ctx
*ctx
)
9073 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9074 struct r600_bytecode_alu alu
;
9078 /* result.x = floor(log2(|src|)); */
9079 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
9080 if (ctx
->bc
->chip_class
== CAYMAN
) {
9081 for (i
= 0; i
< 3; i
++) {
9082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9084 alu
.op
= ALU_OP1_LOG_IEEE
;
9085 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9086 r600_bytecode_src_set_abs(&alu
.src
[0]);
9088 alu
.dst
.sel
= ctx
->temp_reg
;
9094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9100 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9102 alu
.op
= ALU_OP1_LOG_IEEE
;
9103 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9104 r600_bytecode_src_set_abs(&alu
.src
[0]);
9106 alu
.dst
.sel
= ctx
->temp_reg
;
9110 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9115 alu
.op
= ALU_OP1_FLOOR
;
9116 alu
.src
[0].sel
= ctx
->temp_reg
;
9117 alu
.src
[0].chan
= 0;
9119 alu
.dst
.sel
= ctx
->temp_reg
;
9124 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9129 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
9130 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
9132 if (ctx
->bc
->chip_class
== CAYMAN
) {
9133 for (i
= 0; i
< 3; i
++) {
9134 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9136 alu
.op
= ALU_OP1_LOG_IEEE
;
9137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9138 r600_bytecode_src_set_abs(&alu
.src
[0]);
9140 alu
.dst
.sel
= ctx
->temp_reg
;
9147 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9152 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9154 alu
.op
= ALU_OP1_LOG_IEEE
;
9155 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9156 r600_bytecode_src_set_abs(&alu
.src
[0]);
9158 alu
.dst
.sel
= ctx
->temp_reg
;
9163 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9168 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9170 alu
.op
= ALU_OP1_FLOOR
;
9171 alu
.src
[0].sel
= ctx
->temp_reg
;
9172 alu
.src
[0].chan
= 1;
9174 alu
.dst
.sel
= ctx
->temp_reg
;
9179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9183 if (ctx
->bc
->chip_class
== CAYMAN
) {
9184 for (i
= 0; i
< 3; i
++) {
9185 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9186 alu
.op
= ALU_OP1_EXP_IEEE
;
9187 alu
.src
[0].sel
= ctx
->temp_reg
;
9188 alu
.src
[0].chan
= 1;
9190 alu
.dst
.sel
= ctx
->temp_reg
;
9197 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9203 alu
.op
= ALU_OP1_EXP_IEEE
;
9204 alu
.src
[0].sel
= ctx
->temp_reg
;
9205 alu
.src
[0].chan
= 1;
9207 alu
.dst
.sel
= ctx
->temp_reg
;
9212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9217 if (ctx
->bc
->chip_class
== CAYMAN
) {
9218 for (i
= 0; i
< 3; i
++) {
9219 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9220 alu
.op
= ALU_OP1_RECIP_IEEE
;
9221 alu
.src
[0].sel
= ctx
->temp_reg
;
9222 alu
.src
[0].chan
= 1;
9224 alu
.dst
.sel
= ctx
->temp_reg
;
9231 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9236 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9237 alu
.op
= ALU_OP1_RECIP_IEEE
;
9238 alu
.src
[0].sel
= ctx
->temp_reg
;
9239 alu
.src
[0].chan
= 1;
9241 alu
.dst
.sel
= ctx
->temp_reg
;
9246 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9251 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9253 alu
.op
= ALU_OP2_MUL
;
9255 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9256 r600_bytecode_src_set_abs(&alu
.src
[0]);
9258 alu
.src
[1].sel
= ctx
->temp_reg
;
9259 alu
.src
[1].chan
= 1;
9261 alu
.dst
.sel
= ctx
->temp_reg
;
9266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9271 /* result.z = log2(|src|);*/
9272 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
9273 if (ctx
->bc
->chip_class
== CAYMAN
) {
9274 for (i
= 0; i
< 3; i
++) {
9275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9277 alu
.op
= ALU_OP1_LOG_IEEE
;
9278 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9279 r600_bytecode_src_set_abs(&alu
.src
[0]);
9281 alu
.dst
.sel
= ctx
->temp_reg
;
9288 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9293 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9295 alu
.op
= ALU_OP1_LOG_IEEE
;
9296 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9297 r600_bytecode_src_set_abs(&alu
.src
[0]);
9299 alu
.dst
.sel
= ctx
->temp_reg
;
9304 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9310 /* result.w = 1.0; */
9311 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
9312 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9314 alu
.op
= ALU_OP1_MOV
;
9315 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9316 alu
.src
[0].chan
= 0;
9318 alu
.dst
.sel
= ctx
->temp_reg
;
9323 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9328 return tgsi_helper_copy(ctx
, inst
);
9331 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
9333 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9334 struct r600_bytecode_alu alu
;
9336 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9337 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
9339 assert(inst
->Dst
[0].Register
.Index
< 3);
9340 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9342 switch (inst
->Instruction
.Opcode
) {
9343 case TGSI_OPCODE_ARL
:
9344 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
9346 case TGSI_OPCODE_ARR
:
9347 alu
.op
= ALU_OP1_FLT_TO_INT
;
9349 case TGSI_OPCODE_UARL
:
9350 alu
.op
= ALU_OP1_MOV
;
9357 for (i
= 0; i
<= lasti
; ++i
) {
9358 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9360 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9361 alu
.last
= i
== lasti
;
9365 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9370 if (inst
->Dst
[0].Register
.Index
> 0)
9371 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
9373 ctx
->bc
->ar_loaded
= 0;
9377 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
9379 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9380 struct r600_bytecode_alu alu
;
9382 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9384 switch (inst
->Instruction
.Opcode
) {
9385 case TGSI_OPCODE_ARL
:
9386 memset(&alu
, 0, sizeof(alu
));
9387 alu
.op
= ALU_OP1_FLOOR
;
9388 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9390 for (i
= 0; i
<= lasti
; ++i
) {
9391 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9393 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9394 alu
.last
= i
== lasti
;
9395 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9400 memset(&alu
, 0, sizeof(alu
));
9401 alu
.op
= ALU_OP1_FLT_TO_INT
;
9402 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
9403 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9405 /* FLT_TO_INT is trans-only on r600/r700 */
9407 for (i
= 0; i
<= lasti
; ++i
) {
9409 alu
.src
[0].chan
= i
;
9410 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9414 case TGSI_OPCODE_ARR
:
9415 memset(&alu
, 0, sizeof(alu
));
9416 alu
.op
= ALU_OP1_FLT_TO_INT
;
9417 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9419 /* FLT_TO_INT is trans-only on r600/r700 */
9421 for (i
= 0; i
<= lasti
; ++i
) {
9422 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9424 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9425 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9430 case TGSI_OPCODE_UARL
:
9431 memset(&alu
, 0, sizeof(alu
));
9432 alu
.op
= ALU_OP1_MOV
;
9433 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
9435 for (i
= 0; i
<= lasti
; ++i
) {
9436 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
9438 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9439 alu
.last
= i
== lasti
;
9440 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
9450 ctx
->bc
->ar_loaded
= 0;
9454 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
9456 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9457 struct r600_bytecode_alu alu
;
9460 for (i
= 0; i
< 4; i
++) {
9461 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9463 alu
.op
= ALU_OP2_MUL
;
9464 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9466 if (i
== 0 || i
== 3) {
9467 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
9469 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
9472 if (i
== 0 || i
== 2) {
9473 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
9475 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
9479 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9486 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
9488 struct r600_bytecode_alu alu
;
9491 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9493 alu
.execute_mask
= 1;
9494 alu
.update_pred
= 1;
9496 alu
.dst
.sel
= ctx
->temp_reg
;
9500 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9501 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
9502 alu
.src
[1].chan
= 0;
9506 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
9512 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
9514 unsigned force_pop
= ctx
->bc
->force_add_cf
;
9518 if (ctx
->bc
->cf_last
) {
9519 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
9521 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
9526 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
9527 ctx
->bc
->force_add_cf
= 1;
9528 } else if (alu_pop
== 2) {
9529 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
9530 ctx
->bc
->force_add_cf
= 1;
9537 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
9538 ctx
->bc
->cf_last
->pop_count
= pops
;
9539 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9545 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
9548 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
9552 unsigned entry_size
= stack
->entry_size
;
9554 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
9555 elements
+= stack
->push
;
9557 switch (ctx
->bc
->chip_class
) {
9560 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
9561 * the stack must be reserved to hold the current active/continue
9563 if (reason
== FC_PUSH_VPM
) {
9569 /* r9xx: any stack operation on empty stack consumes 2 additional
9574 /* FIXME: do the two elements added above cover the cases for the
9578 /* r8xx+: 2 extra elements are not always required, but one extra
9579 * element must be added for each of the following cases:
9580 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
9582 * (Currently we don't use ALU_ELSE_AFTER.)
9583 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
9584 * PUSH instruction executed.
9586 * NOTE: it seems we also need to reserve additional element in some
9587 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
9588 * then STACK_SIZE should be 2 instead of 1 */
9589 if (reason
== FC_PUSH_VPM
) {
9599 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
9600 * for all chips, so we use 4 in the final formula, not the real entry_size
9604 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
9606 if (entries
> stack
->max_entries
)
9607 stack
->max_entries
= entries
;
9610 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
9614 --ctx
->bc
->stack
.push
;
9615 assert(ctx
->bc
->stack
.push
>= 0);
9618 --ctx
->bc
->stack
.push_wqm
;
9619 assert(ctx
->bc
->stack
.push_wqm
>= 0);
9622 --ctx
->bc
->stack
.loop
;
9623 assert(ctx
->bc
->stack
.loop
>= 0);
9631 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
9635 ++ctx
->bc
->stack
.push
;
9638 ++ctx
->bc
->stack
.push_wqm
;
9640 ++ctx
->bc
->stack
.loop
;
9646 callstack_update_max_depth(ctx
, reason
);
9649 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
9651 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
9653 sp
->mid
= realloc((void *)sp
->mid
,
9654 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
9655 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
9659 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
9661 assert(ctx
->bc
->fc_sp
< ARRAY_SIZE(ctx
->bc
->fc_stack
));
9662 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
9663 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
9667 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
9669 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1];
9679 static int emit_return(struct r600_shader_ctx
*ctx
)
9681 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
9685 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
9688 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
9689 ctx
->bc
->cf_last
->pop_count
= pops
;
9690 /* XXX work out offset */
9694 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
9699 static void emit_testflag(struct r600_shader_ctx
*ctx
)
9704 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
9707 emit_jump_to_offset(ctx
, 1, 4);
9708 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
9709 pops(ctx
, ifidx
+ 1);
9713 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
9717 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9718 ctx
->bc
->cf_last
->pop_count
= 1;
9720 fc_set_mid(ctx
, fc_sp
);
9726 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
9728 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
9730 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
9731 * LOOP_STARTxxx for nested loops may put the branch stack into a state
9732 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
9733 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
9734 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
9735 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
9736 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9737 alu_type
= CF_OP_ALU
;
9740 emit_logic_pred(ctx
, opcode
, alu_type
);
9742 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
9744 fc_pushlevel(ctx
, FC_IF
);
9746 callstack_push(ctx
, FC_PUSH_VPM
);
9750 static int tgsi_if(struct r600_shader_ctx
*ctx
)
9752 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
9755 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
9757 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
9760 static int tgsi_else(struct r600_shader_ctx
*ctx
)
9762 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
9763 ctx
->bc
->cf_last
->pop_count
= 1;
9765 fc_set_mid(ctx
, ctx
->bc
->fc_sp
- 1);
9766 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
9770 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
9773 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_IF
) {
9774 R600_ERR("if/endif unbalanced in shader\n");
9778 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
== NULL
) {
9779 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9780 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->pop_count
= 1;
9782 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9786 callstack_pop(ctx
, FC_PUSH_VPM
);
9790 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
9792 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
9793 * limited to 4096 iterations, like the other LOOP_* instructions. */
9794 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
9796 fc_pushlevel(ctx
, FC_LOOP
);
9798 /* check stack depth */
9799 callstack_push(ctx
, FC_LOOP
);
9803 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
9807 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
9809 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].type
!= FC_LOOP
) {
9810 R600_ERR("loop/endloop in shader code are not paired.\n");
9814 /* fixup loop pointers - from r600isa
9815 LOOP END points to CF after LOOP START,
9816 LOOP START point to CF after LOOP END
9817 BRK/CONT point to LOOP END CF
9819 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->id
+ 2;
9821 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
9823 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].num_mid
; i
++) {
9824 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
- 1].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
9826 /* XXX add LOOPRET support */
9828 callstack_pop(ctx
, FC_LOOP
);
9832 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
9836 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
9838 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
- 1].type
)
9843 R600_ERR("Break not inside loop/endloop pair\n");
9847 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9849 fc_set_mid(ctx
, fscp
- 1);
9854 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
9856 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9857 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
9860 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9861 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
9863 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
9865 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
9866 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
9867 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
9872 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
9874 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9875 struct r600_bytecode_alu alu
;
9877 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9880 for (i
= 0; i
< lasti
+ 1; i
++) {
9881 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9884 if (ctx
->bc
->chip_class
== CAYMAN
) {
9885 for (j
= 0 ; j
< 4; j
++) {
9886 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9888 alu
.op
= ALU_OP2_MULLO_UINT
;
9889 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
9890 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
9893 alu
.dst
.sel
= ctx
->temp_reg
;
9894 alu
.dst
.write
= (j
== i
);
9897 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9902 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9905 alu
.dst
.sel
= ctx
->temp_reg
;
9908 alu
.op
= ALU_OP2_MULLO_UINT
;
9909 for (j
= 0; j
< 2; j
++) {
9910 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
9914 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9921 for (i
= 0; i
< lasti
+ 1; i
++) {
9922 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9926 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9928 alu
.op
= ALU_OP2_ADD_INT
;
9930 alu
.src
[0].sel
= ctx
->temp_reg
;
9931 alu
.src
[0].chan
= i
;
9933 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
9937 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9944 static int tgsi_pk2h(struct r600_shader_ctx
*ctx
)
9946 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9947 struct r600_bytecode_alu alu
;
9949 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9951 /* temp.xy = f32_to_f16(src) */
9952 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9953 alu
.op
= ALU_OP1_FLT32_TO_FLT16
;
9955 alu
.dst
.sel
= ctx
->temp_reg
;
9957 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
9958 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9962 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
9964 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9968 /* dst.x = temp.y * 0x10000 + temp.x */
9969 for (i
= 0; i
< lasti
+ 1; i
++) {
9970 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
9973 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
9974 alu
.op
= ALU_OP3_MULADD_UINT24
;
9976 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
9977 alu
.last
= i
== lasti
;
9978 alu
.src
[0].sel
= ctx
->temp_reg
;
9979 alu
.src
[0].chan
= 1;
9980 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
9981 alu
.src
[1].value
= 0x10000;
9982 alu
.src
[2].sel
= ctx
->temp_reg
;
9983 alu
.src
[2].chan
= 0;
9984 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
9992 static int tgsi_up2h(struct r600_shader_ctx
*ctx
)
9994 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
9995 struct r600_bytecode_alu alu
;
9997 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
9999 /* temp.x = src.x */
10000 /* note: no need to mask out the high bits */
10001 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10002 alu
.op
= ALU_OP1_MOV
;
10004 alu
.dst
.sel
= ctx
->temp_reg
;
10006 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10007 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10011 /* temp.y = src.x >> 16 */
10012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10013 alu
.op
= ALU_OP2_LSHR_INT
;
10015 alu
.dst
.sel
= ctx
->temp_reg
;
10017 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
10018 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10019 alu
.src
[1].value
= 16;
10021 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10025 /* dst.wz = dst.xy = f16_to_f32(temp.xy) */
10026 for (i
= 0; i
< lasti
+ 1; i
++) {
10027 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
10029 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10030 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10031 alu
.op
= ALU_OP1_FLT16_TO_FLT32
;
10032 alu
.src
[0].sel
= ctx
->temp_reg
;
10033 alu
.src
[0].chan
= i
% 2;
10034 alu
.last
= i
== lasti
;
10035 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10043 static int tgsi_bfe(struct r600_shader_ctx
*ctx
)
10045 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
10046 struct r600_bytecode_alu alu
;
10047 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
10051 if ((inst
->Src
[0].Register
.File
== inst
->Dst
[0].Register
.File
&&
10052 inst
->Src
[0].Register
.Index
== inst
->Dst
[0].Register
.Index
) ||
10053 (inst
->Src
[2].Register
.File
== inst
->Dst
[0].Register
.File
&&
10054 inst
->Src
[2].Register
.Index
== inst
->Dst
[0].Register
.Index
))
10055 dst
= r600_get_temp(ctx
);
10057 r
= tgsi_op3_dst(ctx
, dst
);
10061 for (i
= 0; i
< lasti
+ 1; i
++) {
10062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10063 alu
.op
= ALU_OP2_SETGE_INT
;
10064 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[2], i
);
10065 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
10066 alu
.src
[1].value
= 32;
10067 alu
.dst
.sel
= ctx
->temp_reg
;
10072 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10077 for (i
= 0; i
< lasti
+ 1; i
++) {
10078 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
10079 alu
.op
= ALU_OP3_CNDE_INT
;
10081 alu
.src
[0].sel
= ctx
->temp_reg
;
10082 alu
.src
[0].chan
= i
;
10084 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
10086 alu
.src
[1].sel
= dst
;
10088 alu
.src
[1].sel
= alu
.dst
.sel
;
10089 alu
.src
[1].chan
= i
;
10090 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
10094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
10102 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
10103 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10104 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10105 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10107 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10109 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10110 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10111 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10112 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10113 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10114 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10115 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10116 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10117 /* MIN_DX10 returns non-nan result if one src is NaN, MIN returns NaN */
10118 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10119 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10120 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10121 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10122 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10123 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10124 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10125 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10126 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10127 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10128 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10129 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10130 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10131 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10132 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10133 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
10134 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
10135 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
10136 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10137 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10138 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10139 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10140 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10141 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
10142 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10143 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10144 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10145 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10146 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10147 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10148 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10149 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10150 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10151 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10152 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10153 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
10154 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10155 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10156 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10157 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10158 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10159 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10160 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10161 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10162 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10163 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10164 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10165 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10166 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
10167 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10168 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10169 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10170 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10171 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10172 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10173 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10174 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10175 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10176 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10177 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10178 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10179 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10180 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10181 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10182 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10183 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10184 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10185 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10186 [81] = { ALU_OP0_NOP
, tgsi_unsupported
},
10187 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10188 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10189 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
10190 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10191 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10192 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
10193 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10194 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10195 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10196 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10197 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10198 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10199 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10200 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10201 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10202 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10203 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10204 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10205 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10206 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10207 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10208 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10209 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10210 [TGSI_OPCODE_RESQ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10211 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10212 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10213 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10214 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10215 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10216 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10217 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10218 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10219 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10220 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10221 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10222 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10223 [TGSI_OPCODE_DFMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10224 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
10225 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10226 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10227 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10228 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10229 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10230 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
10231 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10232 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
10233 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
10234 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10235 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10236 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10237 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10238 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10239 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10240 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
10241 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10242 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10243 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
10244 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10245 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
10246 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10247 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10248 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10249 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10250 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10251 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10252 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10253 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10254 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10255 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10256 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10257 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10258 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10259 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10260 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10261 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10262 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
10263 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10264 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10265 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10266 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10267 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10268 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10269 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10270 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10271 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10272 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10273 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10274 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10275 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10276 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10277 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10278 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10279 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10280 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10281 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10282 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10283 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10284 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10285 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10286 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10287 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
10288 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
10289 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
10290 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
10291 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10292 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
10293 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
10294 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
10295 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
10296 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
10297 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10298 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10299 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10300 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10303 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
10304 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10305 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10306 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10307 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
10308 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
10309 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10310 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10311 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10312 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10313 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10314 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10315 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10316 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10317 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10318 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10319 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10320 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10321 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10322 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10323 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
10324 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10325 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10326 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10327 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10328 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10329 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10330 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10331 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
10332 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
10333 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
10334 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10335 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10336 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10337 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10338 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10339 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
10340 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10341 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10342 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10343 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10344 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10345 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10346 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10347 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10348 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10349 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10350 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10351 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
10352 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10353 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10354 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10355 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10356 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10357 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10358 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10359 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10360 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10361 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10362 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10363 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10364 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10365 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10366 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10367 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10368 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10369 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10370 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10371 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10372 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10373 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10374 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10375 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10376 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10377 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10378 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10379 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10380 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10381 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10382 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10383 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10384 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10385 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10386 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
10387 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10388 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10389 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10390 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10391 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10392 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10393 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10394 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10395 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10396 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10397 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10398 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10399 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10400 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10401 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10402 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10403 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10404 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10405 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10406 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10407 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10408 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10409 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10410 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10411 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10412 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10413 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10414 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10415 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10416 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10417 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10418 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10419 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10420 /* Refer below for TGSI_OPCODE_DFMA */
10421 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
10422 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10423 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10424 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10425 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10426 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10427 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10428 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10429 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
10430 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
10431 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10432 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10433 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10434 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10435 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10436 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10437 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
10438 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10439 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10440 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10441 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10442 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10443 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10444 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10445 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10446 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10447 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10448 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10449 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10450 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10451 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10452 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10453 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10454 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10455 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10456 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10457 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10458 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10459 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10460 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10461 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10462 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10463 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10464 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10465 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10466 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10467 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10468 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10469 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10470 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10471 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10472 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10473 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10474 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10475 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10476 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10477 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10478 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10479 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10480 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10481 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10482 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
10483 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
10484 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10485 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10486 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10487 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10488 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10489 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10490 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10491 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10492 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10493 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10494 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10495 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10496 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10497 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10498 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10499 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10500 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10501 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10502 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10503 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10504 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10505 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10506 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10507 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10508 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10509 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10510 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10511 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10512 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10513 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10514 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10515 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10516 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10517 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10518 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10519 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10520 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10521 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10522 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10525 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
10526 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10527 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
10528 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
10529 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
10530 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
10531 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
10532 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
10533 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL_IEEE
, tgsi_op2
},
10534 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
10535 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10536 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10537 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
10538 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN_DX10
, tgsi_op2
},
10539 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX_DX10
, tgsi_op2
},
10540 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
10541 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
10542 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD_IEEE
, tgsi_op3
},
10543 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
10544 [TGSI_OPCODE_FMA
] = { ALU_OP3_FMA
, tgsi_op3
},
10545 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
10546 [21] = { ALU_OP0_NOP
, tgsi_unsupported
},
10547 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
10548 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
10549 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
10550 [25] = { ALU_OP0_NOP
, tgsi_unsupported
},
10551 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
10552 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
10553 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
10554 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
10555 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
10556 [31] = { ALU_OP0_NOP
, tgsi_unsupported
},
10557 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
10558 [33] = { ALU_OP0_NOP
, tgsi_unsupported
},
10559 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
10560 [35] = { ALU_OP0_NOP
, tgsi_unsupported
},
10561 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
10562 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10563 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10564 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
10565 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_pk2h
},
10566 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10567 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10568 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10569 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
10570 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
10571 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
10572 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
10573 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
10574 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
10575 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
10576 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
10577 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10578 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
10579 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10580 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_up2h
},
10581 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10582 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10583 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10584 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
10585 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
10586 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
10587 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
10588 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10589 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10590 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
10591 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
10592 [67] = { ALU_OP0_NOP
, tgsi_unsupported
},
10593 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10594 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
10595 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10596 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4_IEEE
, tgsi_dp
},
10597 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10598 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
10599 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
10600 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
10601 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
10602 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
10603 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
10604 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
10605 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
10606 [82] = { ALU_OP0_NOP
, tgsi_unsupported
},
10607 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
10608 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
10609 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
10610 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
10611 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
10612 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
10613 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
10614 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
10615 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
10616 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
10617 [93] = { ALU_OP0_NOP
, tgsi_unsupported
},
10618 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
10619 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10620 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
10621 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
10622 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
10623 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
10624 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10625 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
10626 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10627 [103] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
10628 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
10629 [TGSI_OPCODE_RESQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_resq
},
10630 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
10631 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10632 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
10633 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
10634 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
10635 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
10636 [TGSI_OPCODE_MEMBAR
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10637 [113] = { ALU_OP0_NOP
, tgsi_unsupported
},
10638 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
10639 [115] = { ALU_OP0_NOP
, tgsi_unsupported
},
10640 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
10641 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
10642 /* Refer below for TGSI_OPCODE_DFMA */
10643 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
10644 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
10645 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
10646 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
10647 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
10648 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
10649 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
10650 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
10651 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
10652 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
10653 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
10654 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
10655 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
10656 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
10657 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
10658 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
10659 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
10660 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
10661 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
10662 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
10663 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
10664 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
10665 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10666 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10667 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10668 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
10669 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
10670 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
10671 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
10672 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
10673 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
10674 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
10675 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
10676 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
10677 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
10678 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
10679 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
10680 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
10681 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
10682 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
10683 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
10684 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
10685 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_load
},
10686 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_store
},
10687 [163] = { ALU_OP0_NOP
, tgsi_unsupported
},
10688 [164] = { ALU_OP0_NOP
, tgsi_unsupported
},
10689 [165] = { ALU_OP0_NOP
, tgsi_unsupported
},
10690 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
10691 [TGSI_OPCODE_ATOMUADD
] = { V_RAT_INST_ADD_RTN
, tgsi_atomic_op
},
10692 [TGSI_OPCODE_ATOMXCHG
] = { V_RAT_INST_XCHG_RTN
, tgsi_atomic_op
},
10693 [TGSI_OPCODE_ATOMCAS
] = { V_RAT_INST_CMPXCHG_INT_RTN
, tgsi_atomic_op
},
10694 [TGSI_OPCODE_ATOMAND
] = { V_RAT_INST_AND_RTN
, tgsi_atomic_op
},
10695 [TGSI_OPCODE_ATOMOR
] = { V_RAT_INST_OR_RTN
, tgsi_atomic_op
},
10696 [TGSI_OPCODE_ATOMXOR
] = { V_RAT_INST_XOR_RTN
, tgsi_atomic_op
},
10697 [TGSI_OPCODE_ATOMUMIN
] = { V_RAT_INST_MIN_UINT_RTN
, tgsi_atomic_op
},
10698 [TGSI_OPCODE_ATOMUMAX
] = { V_RAT_INST_MAX_UINT_RTN
, tgsi_atomic_op
},
10699 [TGSI_OPCODE_ATOMIMIN
] = { V_RAT_INST_MIN_INT_RTN
, tgsi_atomic_op
},
10700 [TGSI_OPCODE_ATOMIMAX
] = { V_RAT_INST_MAX_INT_RTN
, tgsi_atomic_op
},
10701 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
10702 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
10703 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
10704 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
10705 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
10706 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
10707 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
10708 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_bfe
},
10709 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_bfe
},
10710 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
10711 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
10712 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
10713 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
10714 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
10715 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
10716 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10717 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10718 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
10719 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
10720 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
10721 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
10722 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
10723 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
10724 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
10725 [TGSI_OPCODE_DDIV
] = { 0, cayman_ddiv_instr
},
10726 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
10727 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
10728 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
10729 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
10730 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
10731 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
10732 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
10733 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
10734 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10735 [TGSI_OPCODE_DFMA
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
10736 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
10737 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
10738 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
10739 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
10740 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
10741 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
10742 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
10743 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
10744 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},