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_llvm.h"
25 #include "r600_formats.h"
26 #include "r600_opcodes.h"
27 #include "r600_shader.h"
30 #include "sb/sb_public.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "tgsi/tgsi_info.h"
34 #include "tgsi/tgsi_parse.h"
35 #include "tgsi/tgsi_scan.h"
36 #include "tgsi/tgsi_dump.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
, PIPE_BIND_CUSTOM
, 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
, sel
->tokens
);
166 unsigned use_sb
= !(rctx
->screen
->b
.debug_flags
& DBG_NO_SB
);
167 unsigned sb_disasm
= use_sb
|| (rctx
->screen
->b
.debug_flags
& DBG_SB_DISASM
);
168 unsigned export_shader
;
170 shader
->shader
.bc
.isa
= rctx
->isa
;
173 fprintf(stderr
, "--------------------------------------------------------------\n");
174 tgsi_dump(sel
->tokens
, 0);
176 if (sel
->so
.num_outputs
) {
177 r600_dump_streamout(&sel
->so
);
180 r
= r600_shader_from_tgsi(rctx
, shader
, key
);
182 R600_ERR("translation from TGSI failed !\n");
185 if (shader
->shader
.processor_type
== TGSI_PROCESSOR_VERTEX
) {
186 /* only disable for vertex shaders in tess paths */
190 use_sb
&= (shader
->shader
.processor_type
!= TGSI_PROCESSOR_TESS_CTRL
);
191 use_sb
&= (shader
->shader
.processor_type
!= TGSI_PROCESSOR_TESS_EVAL
);
193 /* disable SB for shaders using doubles */
194 use_sb
&= !shader
->shader
.uses_doubles
;
196 /* Check if the bytecode has already been built. When using the llvm
197 * backend, r600_shader_from_tgsi() will take care of building the
200 if (!shader
->shader
.bc
.bytecode
) {
201 r
= r600_bytecode_build(&shader
->shader
.bc
);
203 R600_ERR("building bytecode failed !\n");
208 if (dump
&& !sb_disasm
) {
209 fprintf(stderr
, "--------------------------------------------------------------\n");
210 r600_bytecode_disasm(&shader
->shader
.bc
);
211 fprintf(stderr
, "______________________________________________________________\n");
212 } else if ((dump
&& sb_disasm
) || use_sb
) {
213 r
= r600_sb_bytecode_process(rctx
, &shader
->shader
.bc
, &shader
->shader
,
216 R600_ERR("r600_sb_bytecode_process failed !\n");
221 if (shader
->gs_copy_shader
) {
224 r
= r600_sb_bytecode_process(rctx
, &shader
->gs_copy_shader
->shader
.bc
,
225 &shader
->gs_copy_shader
->shader
, dump
, 0);
230 if ((r
= store_shader(ctx
, shader
->gs_copy_shader
)))
234 /* Store the shader in a buffer. */
235 if ((r
= store_shader(ctx
, shader
)))
239 switch (shader
->shader
.processor_type
) {
240 case TGSI_PROCESSOR_TESS_CTRL
:
241 evergreen_update_hs_state(ctx
, shader
);
243 case TGSI_PROCESSOR_TESS_EVAL
:
245 evergreen_update_es_state(ctx
, shader
);
247 evergreen_update_vs_state(ctx
, shader
);
249 case TGSI_PROCESSOR_GEOMETRY
:
250 if (rctx
->b
.chip_class
>= EVERGREEN
) {
251 evergreen_update_gs_state(ctx
, shader
);
252 evergreen_update_vs_state(ctx
, shader
->gs_copy_shader
);
254 r600_update_gs_state(ctx
, shader
);
255 r600_update_vs_state(ctx
, shader
->gs_copy_shader
);
258 case TGSI_PROCESSOR_VERTEX
:
259 export_shader
= key
.vs
.as_es
;
260 if (rctx
->b
.chip_class
>= EVERGREEN
) {
262 evergreen_update_ls_state(ctx
, shader
);
263 else if (key
.vs
.as_es
)
264 evergreen_update_es_state(ctx
, shader
);
266 evergreen_update_vs_state(ctx
, shader
);
269 r600_update_es_state(ctx
, shader
);
271 r600_update_vs_state(ctx
, shader
);
274 case TGSI_PROCESSOR_FRAGMENT
:
275 if (rctx
->b
.chip_class
>= EVERGREEN
) {
276 evergreen_update_ps_state(ctx
, shader
);
278 r600_update_ps_state(ctx
, shader
);
288 r600_pipe_shader_destroy(ctx
, shader
);
292 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
294 pipe_resource_reference((struct pipe_resource
**)&shader
->bo
, NULL
);
295 r600_bytecode_clear(&shader
->shader
.bc
);
296 r600_release_command_buffer(&shader
->command_buffer
);
300 * tgsi -> r600 shader
302 struct r600_shader_tgsi_instruction
;
304 struct r600_shader_src
{
311 boolean kc_rel
; /* true if cache bank is indexed */
320 struct r600_shader_ctx
{
321 struct tgsi_shader_info info
;
322 struct tgsi_parse_context parse
;
323 const struct tgsi_token
*tokens
;
325 unsigned file_offset
[TGSI_FILE_COUNT
];
327 const struct r600_shader_tgsi_instruction
*inst_info
;
328 struct r600_bytecode
*bc
;
329 struct r600_shader
*shader
;
330 struct r600_shader_src src
[4];
333 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 const struct pipe_stream_output_info
*gs_stream_output_info
;
353 unsigned enabled_stream_buffers_mask
;
354 unsigned tess_input_info
; /* temp with tess input offsets */
355 unsigned tess_output_info
; /* temp with tess input offsets */
358 struct r600_shader_tgsi_instruction
{
360 int (*process
)(struct r600_shader_ctx
*ctx
);
363 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
);
364 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[], eg_shader_tgsi_instruction
[], cm_shader_tgsi_instruction
[];
365 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
);
366 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
);
367 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
);
368 static int tgsi_else(struct r600_shader_ctx
*ctx
);
369 static int tgsi_endif(struct r600_shader_ctx
*ctx
);
370 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
);
371 static int tgsi_endloop(struct r600_shader_ctx
*ctx
);
372 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
);
373 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
374 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
375 unsigned int dst_reg
);
376 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
377 const struct r600_shader_src
*shader_src
,
379 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
382 static int tgsi_last_instruction(unsigned writemask
)
386 for (i
= 0; i
< 4; i
++) {
387 if (writemask
& (1 << i
)) {
394 static int tgsi_is_supported(struct r600_shader_ctx
*ctx
)
396 struct tgsi_full_instruction
*i
= &ctx
->parse
.FullToken
.FullInstruction
;
399 if (i
->Instruction
.NumDstRegs
> 1 && i
->Instruction
.Opcode
!= TGSI_OPCODE_DFRACEXP
) {
400 R600_ERR("too many dst (%d)\n", i
->Instruction
.NumDstRegs
);
403 if (i
->Instruction
.Predicate
) {
404 R600_ERR("predicate unsupported\n");
408 if (i
->Instruction
.Label
) {
409 R600_ERR("label unsupported\n");
413 for (j
= 0; j
< i
->Instruction
.NumSrcRegs
; j
++) {
414 if (i
->Src
[j
].Register
.Dimension
) {
415 switch (i
->Src
[j
].Register
.File
) {
416 case TGSI_FILE_CONSTANT
:
418 case TGSI_FILE_INPUT
:
419 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
||
420 ctx
->type
== TGSI_PROCESSOR_TESS_CTRL
||
421 ctx
->type
== TGSI_PROCESSOR_TESS_EVAL
)
423 case TGSI_FILE_OUTPUT
:
424 if (ctx
->type
== TGSI_PROCESSOR_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
== TGSI_PROCESSOR_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
);
664 r
= evergreen_interp_alu(ctx
, index
);
667 r
= evergreen_interp_flat(ctx
, index
);
673 static int select_twoside_color(struct r600_shader_ctx
*ctx
, int front
, int back
)
675 struct r600_bytecode_alu alu
;
677 int gpr_front
= ctx
->shader
->input
[front
].gpr
;
678 int gpr_back
= ctx
->shader
->input
[back
].gpr
;
680 for (i
= 0; i
< 4; i
++) {
681 memset(&alu
, 0, sizeof(alu
));
682 alu
.op
= ALU_OP3_CNDGT
;
685 alu
.dst
.sel
= gpr_front
;
686 alu
.src
[0].sel
= ctx
->face_gpr
;
687 alu
.src
[1].sel
= gpr_front
;
688 alu
.src
[2].sel
= gpr_back
;
695 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
702 /* execute a single slot ALU calculation */
703 static int single_alu_op2(struct r600_shader_ctx
*ctx
, int op
,
704 int dst_sel
, int dst_chan
,
705 int src0_sel
, unsigned src0_chan_val
,
706 int src1_sel
, unsigned src1_chan_val
)
708 struct r600_bytecode_alu alu
;
711 if (ctx
->bc
->chip_class
== CAYMAN
&& op
== ALU_OP2_MULLO_INT
) {
712 for (i
= 0; i
< 4; i
++) {
713 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
715 alu
.src
[0].sel
= src0_sel
;
716 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
717 alu
.src
[0].value
= src0_chan_val
;
719 alu
.src
[0].chan
= src0_chan_val
;
720 alu
.src
[1].sel
= src1_sel
;
721 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
722 alu
.src
[1].value
= src1_chan_val
;
724 alu
.src
[1].chan
= src1_chan_val
;
725 alu
.dst
.sel
= dst_sel
;
727 alu
.dst
.write
= i
== dst_chan
;
729 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
736 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
738 alu
.src
[0].sel
= src0_sel
;
739 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
740 alu
.src
[0].value
= src0_chan_val
;
742 alu
.src
[0].chan
= src0_chan_val
;
743 alu
.src
[1].sel
= src1_sel
;
744 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
745 alu
.src
[1].value
= src1_chan_val
;
747 alu
.src
[1].chan
= src1_chan_val
;
748 alu
.dst
.sel
= dst_sel
;
749 alu
.dst
.chan
= dst_chan
;
752 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
758 /* execute a single slot ALU calculation */
759 static int single_alu_op3(struct r600_shader_ctx
*ctx
, int op
,
760 int dst_sel
, int dst_chan
,
761 int src0_sel
, unsigned src0_chan_val
,
762 int src1_sel
, unsigned src1_chan_val
,
763 int src2_sel
, unsigned src2_chan_val
)
765 struct r600_bytecode_alu alu
;
768 /* validate this for other ops */
769 assert(op
== ALU_OP3_MULADD_UINT24
);
770 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
772 alu
.src
[0].sel
= src0_sel
;
773 if (src0_sel
== V_SQ_ALU_SRC_LITERAL
)
774 alu
.src
[0].value
= src0_chan_val
;
776 alu
.src
[0].chan
= src0_chan_val
;
777 alu
.src
[1].sel
= src1_sel
;
778 if (src1_sel
== V_SQ_ALU_SRC_LITERAL
)
779 alu
.src
[1].value
= src1_chan_val
;
781 alu
.src
[1].chan
= src1_chan_val
;
782 alu
.src
[2].sel
= src2_sel
;
783 if (src2_sel
== V_SQ_ALU_SRC_LITERAL
)
784 alu
.src
[2].value
= src2_chan_val
;
786 alu
.src
[2].chan
= src2_chan_val
;
787 alu
.dst
.sel
= dst_sel
;
788 alu
.dst
.chan
= dst_chan
;
791 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
797 /* put it in temp_reg.x */
798 static int get_lds_offset0(struct r600_shader_ctx
*ctx
,
800 int temp_reg
, bool is_patch_var
)
804 /* MUL temp.x, patch_stride (input_vals.x), rel_patch_id (r0.y (tcs)) */
806 Dimension - patch0_offset (input_vals.z),
807 Non-dim - patch0_data_offset (input_vals.w)
809 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
811 ctx
->tess_output_info
, 0,
813 ctx
->tess_output_info
, is_patch_var
? 3 : 2);
819 static inline int get_address_file_reg(struct r600_shader_ctx
*ctx
, int index
)
821 return index
> 0 ? ctx
->bc
->index_reg
[index
- 1] : ctx
->bc
->ar_reg
;
824 static int r600_get_temp(struct r600_shader_ctx
*ctx
)
826 return ctx
->temp_reg
+ ctx
->max_driver_temp_used
++;
829 static int vs_add_primid_output(struct r600_shader_ctx
*ctx
, int prim_id_sid
)
832 i
= ctx
->shader
->noutput
++;
833 ctx
->shader
->output
[i
].name
= TGSI_SEMANTIC_PRIMID
;
834 ctx
->shader
->output
[i
].sid
= 0;
835 ctx
->shader
->output
[i
].gpr
= 0;
836 ctx
->shader
->output
[i
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
837 ctx
->shader
->output
[i
].write_mask
= 0x4;
838 ctx
->shader
->output
[i
].spi_sid
= prim_id_sid
;
843 static int tgsi_barrier(struct r600_shader_ctx
*ctx
)
845 struct r600_bytecode_alu alu
;
848 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
849 alu
.op
= ctx
->inst_info
->op
;
852 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
858 static int tgsi_declaration(struct r600_shader_ctx
*ctx
)
860 struct tgsi_full_declaration
*d
= &ctx
->parse
.FullToken
.FullDeclaration
;
861 int r
, i
, j
, count
= d
->Range
.Last
- d
->Range
.First
+ 1;
863 switch (d
->Declaration
.File
) {
864 case TGSI_FILE_INPUT
:
865 for (j
= 0; j
< count
; j
++) {
866 i
= ctx
->shader
->ninput
+ j
;
867 assert(i
< Elements(ctx
->shader
->input
));
868 ctx
->shader
->input
[i
].name
= d
->Semantic
.Name
;
869 ctx
->shader
->input
[i
].sid
= d
->Semantic
.Index
+ j
;
870 ctx
->shader
->input
[i
].interpolate
= d
->Interp
.Interpolate
;
871 ctx
->shader
->input
[i
].interpolate_location
= d
->Interp
.Location
;
872 ctx
->shader
->input
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_INPUT
] + d
->Range
.First
+ j
;
873 if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
874 ctx
->shader
->input
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->input
[i
]);
875 switch (ctx
->shader
->input
[i
].name
) {
876 case TGSI_SEMANTIC_FACE
:
877 if (ctx
->face_gpr
!= -1)
878 ctx
->shader
->input
[i
].gpr
= ctx
->face_gpr
; /* already allocated by allocate_system_value_inputs */
880 ctx
->face_gpr
= ctx
->shader
->input
[i
].gpr
;
882 case TGSI_SEMANTIC_COLOR
:
885 case TGSI_SEMANTIC_POSITION
:
886 ctx
->fragcoord_input
= i
;
888 case TGSI_SEMANTIC_PRIMID
:
889 /* set this for now */
890 ctx
->shader
->gs_prim_id_input
= true;
891 ctx
->shader
->ps_prim_id_input
= i
;
894 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
895 if ((r
= evergreen_interp_input(ctx
, i
)))
898 } else if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
899 /* FIXME probably skip inputs if they aren't passed in the ring */
900 ctx
->shader
->input
[i
].ring_offset
= ctx
->next_ring_offset
;
901 ctx
->next_ring_offset
+= 16;
902 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_PRIMID
)
903 ctx
->shader
->gs_prim_id_input
= true;
906 ctx
->shader
->ninput
+= count
;
908 case TGSI_FILE_OUTPUT
:
909 for (j
= 0; j
< count
; j
++) {
910 i
= ctx
->shader
->noutput
+ j
;
911 assert(i
< Elements(ctx
->shader
->output
));
912 ctx
->shader
->output
[i
].name
= d
->Semantic
.Name
;
913 ctx
->shader
->output
[i
].sid
= d
->Semantic
.Index
+ j
;
914 ctx
->shader
->output
[i
].gpr
= ctx
->file_offset
[TGSI_FILE_OUTPUT
] + d
->Range
.First
+ j
;
915 ctx
->shader
->output
[i
].interpolate
= d
->Interp
.Interpolate
;
916 ctx
->shader
->output
[i
].write_mask
= d
->Declaration
.UsageMask
;
917 if (ctx
->type
== TGSI_PROCESSOR_VERTEX
||
918 ctx
->type
== TGSI_PROCESSOR_GEOMETRY
||
919 ctx
->type
== TGSI_PROCESSOR_TESS_EVAL
) {
920 ctx
->shader
->output
[i
].spi_sid
= r600_spi_sid(&ctx
->shader
->output
[i
]);
921 switch (d
->Semantic
.Name
) {
922 case TGSI_SEMANTIC_CLIPDIST
:
923 ctx
->shader
->clip_dist_write
|= d
->Declaration
.UsageMask
<<
924 ((d
->Semantic
.Index
+ j
) << 2);
926 case TGSI_SEMANTIC_PSIZE
:
927 ctx
->shader
->vs_out_misc_write
= 1;
928 ctx
->shader
->vs_out_point_size
= 1;
930 case TGSI_SEMANTIC_EDGEFLAG
:
931 ctx
->shader
->vs_out_misc_write
= 1;
932 ctx
->shader
->vs_out_edgeflag
= 1;
933 ctx
->edgeflag_output
= i
;
935 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
936 ctx
->shader
->vs_out_misc_write
= 1;
937 ctx
->shader
->vs_out_viewport
= 1;
939 case TGSI_SEMANTIC_LAYER
:
940 ctx
->shader
->vs_out_misc_write
= 1;
941 ctx
->shader
->vs_out_layer
= 1;
943 case TGSI_SEMANTIC_CLIPVERTEX
:
944 ctx
->clip_vertex_write
= TRUE
;
948 if (ctx
->type
== TGSI_PROCESSOR_GEOMETRY
) {
949 ctx
->gs_out_ring_offset
+= 16;
951 } else if (ctx
->type
== TGSI_PROCESSOR_FRAGMENT
) {
952 switch (d
->Semantic
.Name
) {
953 case TGSI_SEMANTIC_COLOR
:
954 ctx
->shader
->nr_ps_max_color_exports
++;
959 ctx
->shader
->noutput
+= count
;
961 case TGSI_FILE_TEMPORARY
:
962 if (ctx
->info
.indirect_files
& (1 << TGSI_FILE_TEMPORARY
)) {
963 if (d
->Array
.ArrayID
) {
964 r600_add_gpr_array(ctx
->shader
,
965 ctx
->file_offset
[TGSI_FILE_TEMPORARY
] +
967 d
->Range
.Last
- d
->Range
.First
+ 1, 0x0F);
972 case TGSI_FILE_CONSTANT
:
973 case TGSI_FILE_SAMPLER
:
974 case TGSI_FILE_SAMPLER_VIEW
:
975 case TGSI_FILE_ADDRESS
:
978 case TGSI_FILE_SYSTEM_VALUE
:
979 if (d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEMASK
||
980 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEID
||
981 d
->Semantic
.Name
== TGSI_SEMANTIC_SAMPLEPOS
) {
982 break; /* Already handled from allocate_system_value_inputs */
983 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INSTANCEID
) {
984 if (!ctx
->native_integers
) {
985 struct r600_bytecode_alu alu
;
986 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
988 alu
.op
= ALU_OP1_INT_TO_FLT
;
997 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1001 } else if (d
->Semantic
.Name
== TGSI_SEMANTIC_VERTEXID
)
1003 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_INVOCATIONID
)
1005 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
||
1006 d
->Semantic
.Name
== TGSI_SEMANTIC_TESSOUTER
) {
1007 int param
= r600_get_lds_unique_index(d
->Semantic
.Name
, 0);
1008 int dreg
= d
->Semantic
.Name
== TGSI_SEMANTIC_TESSINNER
? 3 : 2;
1009 unsigned temp_reg
= r600_get_temp(ctx
);
1011 r
= get_lds_offset0(ctx
, 2, temp_reg
, true);
1015 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1018 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1022 do_lds_fetch_values(ctx
, temp_reg
, dreg
);
1024 else if (d
->Semantic
.Name
== TGSI_SEMANTIC_TESSCOORD
) {
1028 for (i
= 0; i
< 2; i
++) {
1029 struct r600_bytecode_alu alu
;
1030 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1031 alu
.op
= ALU_OP1_MOV
;
1033 alu
.src
[0].chan
= 0 + i
;
1035 alu
.dst
.chan
= 0 + i
;
1037 alu
.last
= (i
== 1) ? 1 : 0;
1038 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1041 /* ADD r1.z, 1.0f, -r0.x */
1042 struct r600_bytecode_alu alu
;
1043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1044 alu
.op
= ALU_OP2_ADD
;
1045 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
1047 alu
.src
[1].chan
= 0;
1053 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1056 /* ADD r1.z, r1.z, -r1.y */
1057 alu
.op
= ALU_OP2_ADD
;
1059 alu
.src
[0].chan
= 2;
1061 alu
.src
[1].chan
= 1;
1067 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1073 R600_ERR("unsupported file %d declaration\n", d
->Declaration
.File
);
1079 static int allocate_system_value_inputs(struct r600_shader_ctx
*ctx
, int gpr_offset
)
1081 struct tgsi_parse_context parse
;
1085 unsigned name
, alternate_name
;
1087 { false, &ctx
->face_gpr
, TGSI_SEMANTIC_SAMPLEMASK
, ~0u }, /* lives in Front Face GPR.z */
1089 { false, &ctx
->fixed_pt_position_gpr
, TGSI_SEMANTIC_SAMPLEID
, TGSI_SEMANTIC_SAMPLEPOS
} /* SAMPLEID is in Fixed Point Position GPR.w */
1091 int i
, k
, num_regs
= 0;
1093 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1097 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1098 while (!tgsi_parse_end_of_tokens(&parse
)) {
1099 tgsi_parse_token(&parse
);
1101 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1102 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1103 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1104 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1105 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1107 int interpolate
, location
, k
;
1109 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1110 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1111 inputs
[1].enabled
= true; /* needs SAMPLEID */
1112 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1113 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1114 /* Needs sample positions, currently those are always available */
1116 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1119 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1120 k
= eg_get_interpolator_index(interpolate
, location
);
1121 ctx
->eg_interpolators
[k
].enabled
= true;
1123 } else if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_DECLARATION
) {
1124 struct tgsi_full_declaration
*d
= &parse
.FullToken
.FullDeclaration
;
1125 if (d
->Declaration
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1126 for (k
= 0; k
< Elements(inputs
); k
++) {
1127 if (d
->Semantic
.Name
== inputs
[k
].name
||
1128 d
->Semantic
.Name
== inputs
[k
].alternate_name
) {
1129 inputs
[k
].enabled
= true;
1136 tgsi_parse_free(&parse
);
1138 for (i
= 0; i
< Elements(inputs
); i
++) {
1139 boolean enabled
= inputs
[i
].enabled
;
1140 int *reg
= inputs
[i
].reg
;
1141 unsigned name
= inputs
[i
].name
;
1144 int gpr
= gpr_offset
+ num_regs
++;
1146 // add to inputs, allocate a gpr
1147 k
= ctx
->shader
->ninput
++;
1148 ctx
->shader
->input
[k
].name
= name
;
1149 ctx
->shader
->input
[k
].sid
= 0;
1150 ctx
->shader
->input
[k
].interpolate
= TGSI_INTERPOLATE_CONSTANT
;
1151 ctx
->shader
->input
[k
].interpolate_location
= TGSI_INTERPOLATE_LOC_CENTER
;
1152 *reg
= ctx
->shader
->input
[k
].gpr
= gpr
;
1156 return gpr_offset
+ num_regs
;
1160 * for evergreen we need to scan the shader to find the number of GPRs we need to
1161 * reserve for interpolation and system values
1163 * we need to know if we are going to emit
1164 * any sample or centroid inputs
1165 * if perspective and linear are required
1167 static int evergreen_gpr_count(struct r600_shader_ctx
*ctx
)
1171 struct tgsi_parse_context parse
;
1173 memset(&ctx
->eg_interpolators
, 0, sizeof(ctx
->eg_interpolators
));
1175 for (i
= 0; i
< ctx
->info
.num_inputs
; i
++) {
1177 /* skip position/face/mask/sampleid */
1178 if (ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
||
1179 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
||
1180 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEMASK
||
1181 ctx
->info
.input_semantic_name
[i
] == TGSI_SEMANTIC_SAMPLEID
)
1184 k
= eg_get_interpolator_index(
1185 ctx
->info
.input_interpolate
[i
],
1186 ctx
->info
.input_interpolate_loc
[i
]);
1188 ctx
->eg_interpolators
[k
].enabled
= TRUE
;
1191 if (tgsi_parse_init(&parse
, ctx
->tokens
) != TGSI_PARSE_OK
) {
1195 /* need to scan shader for system values and interpolateAtSample/Offset/Centroid */
1196 while (!tgsi_parse_end_of_tokens(&parse
)) {
1197 tgsi_parse_token(&parse
);
1199 if (parse
.FullToken
.Token
.Type
== TGSI_TOKEN_TYPE_INSTRUCTION
) {
1200 const struct tgsi_full_instruction
*inst
= &parse
.FullToken
.FullInstruction
;
1201 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
||
1202 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
1203 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_CENTROID
)
1205 int interpolate
, location
, k
;
1207 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
1208 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1209 } else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
) {
1210 location
= TGSI_INTERPOLATE_LOC_CENTER
;
1212 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
1215 interpolate
= ctx
->info
.input_interpolate
[inst
->Src
[0].Register
.Index
];
1216 k
= eg_get_interpolator_index(interpolate
, location
);
1217 ctx
->eg_interpolators
[k
].enabled
= true;
1222 tgsi_parse_free(&parse
);
1224 /* assign gpr to each interpolator according to priority */
1226 for (i
= 0; i
< Elements(ctx
->eg_interpolators
); i
++) {
1227 if (ctx
->eg_interpolators
[i
].enabled
) {
1228 ctx
->eg_interpolators
[i
].ij_index
= num_baryc
;
1233 /* XXX PULL MODEL and LINE STIPPLE */
1235 num_baryc
= (num_baryc
+ 1) >> 1;
1236 return allocate_system_value_inputs(ctx
, num_baryc
);
1239 /* sample_id_sel == NULL means fetch for current sample */
1240 static int load_sample_position(struct r600_shader_ctx
*ctx
, struct r600_shader_src
*sample_id
, int chan_sel
)
1242 struct r600_bytecode_vtx vtx
;
1245 assert(ctx
->fixed_pt_position_gpr
!= -1);
1247 t1
= r600_get_temp(ctx
);
1249 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
1250 vtx
.op
= FETCH_OP_VFETCH
;
1251 vtx
.buffer_id
= R600_BUFFER_INFO_CONST_BUFFER
;
1252 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1253 if (sample_id
== NULL
) {
1254 vtx
.src_gpr
= ctx
->fixed_pt_position_gpr
; // SAMPLEID is in .w;
1258 struct r600_bytecode_alu alu
;
1260 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1261 alu
.op
= ALU_OP1_MOV
;
1262 r600_bytecode_src(&alu
.src
[0], sample_id
, chan_sel
);
1266 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1273 vtx
.mega_fetch_count
= 16;
1279 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1280 vtx
.num_format_all
= 2;
1281 vtx
.format_comp_all
= 1;
1282 vtx
.use_const_fields
= 0;
1283 vtx
.offset
= 1; // first element is size of buffer
1284 vtx
.endian
= r600_endian_swap(32);
1285 vtx
.srf_mode_all
= 1; /* SRF_MODE_NO_ZERO */
1287 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
1294 static void tgsi_src(struct r600_shader_ctx
*ctx
,
1295 const struct tgsi_full_src_register
*tgsi_src
,
1296 struct r600_shader_src
*r600_src
)
1298 memset(r600_src
, 0, sizeof(*r600_src
));
1299 r600_src
->swizzle
[0] = tgsi_src
->Register
.SwizzleX
;
1300 r600_src
->swizzle
[1] = tgsi_src
->Register
.SwizzleY
;
1301 r600_src
->swizzle
[2] = tgsi_src
->Register
.SwizzleZ
;
1302 r600_src
->swizzle
[3] = tgsi_src
->Register
.SwizzleW
;
1303 r600_src
->neg
= tgsi_src
->Register
.Negate
;
1304 r600_src
->abs
= tgsi_src
->Register
.Absolute
;
1306 if (tgsi_src
->Register
.File
== TGSI_FILE_IMMEDIATE
) {
1308 if ((tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleY
) &&
1309 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleZ
) &&
1310 (tgsi_src
->Register
.SwizzleX
== tgsi_src
->Register
.SwizzleW
)) {
1312 index
= tgsi_src
->Register
.Index
* 4 + tgsi_src
->Register
.SwizzleX
;
1313 r600_bytecode_special_constants(ctx
->literals
[index
], &r600_src
->sel
, &r600_src
->neg
, r600_src
->abs
);
1314 if (r600_src
->sel
!= V_SQ_ALU_SRC_LITERAL
)
1317 index
= tgsi_src
->Register
.Index
;
1318 r600_src
->sel
= V_SQ_ALU_SRC_LITERAL
;
1319 memcpy(r600_src
->value
, ctx
->literals
+ index
* 4, sizeof(r600_src
->value
));
1320 } else if (tgsi_src
->Register
.File
== TGSI_FILE_SYSTEM_VALUE
) {
1321 if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEMASK
) {
1322 r600_src
->swizzle
[0] = 2; // Z value
1323 r600_src
->swizzle
[1] = 2;
1324 r600_src
->swizzle
[2] = 2;
1325 r600_src
->swizzle
[3] = 2;
1326 r600_src
->sel
= ctx
->face_gpr
;
1327 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEID
) {
1328 r600_src
->swizzle
[0] = 3; // W value
1329 r600_src
->swizzle
[1] = 3;
1330 r600_src
->swizzle
[2] = 3;
1331 r600_src
->swizzle
[3] = 3;
1332 r600_src
->sel
= ctx
->fixed_pt_position_gpr
;
1333 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_SAMPLEPOS
) {
1334 r600_src
->swizzle
[0] = 0;
1335 r600_src
->swizzle
[1] = 1;
1336 r600_src
->swizzle
[2] = 4;
1337 r600_src
->swizzle
[3] = 4;
1338 r600_src
->sel
= load_sample_position(ctx
, NULL
, -1);
1339 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INSTANCEID
) {
1340 r600_src
->swizzle
[0] = 3;
1341 r600_src
->swizzle
[1] = 3;
1342 r600_src
->swizzle
[2] = 3;
1343 r600_src
->swizzle
[3] = 3;
1345 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTEXID
) {
1346 r600_src
->swizzle
[0] = 0;
1347 r600_src
->swizzle
[1] = 0;
1348 r600_src
->swizzle
[2] = 0;
1349 r600_src
->swizzle
[3] = 0;
1351 } else if (ctx
->type
!= TGSI_PROCESSOR_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1352 r600_src
->swizzle
[0] = 3;
1353 r600_src
->swizzle
[1] = 3;
1354 r600_src
->swizzle
[2] = 3;
1355 r600_src
->swizzle
[3] = 3;
1357 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_INVOCATIONID
) {
1358 r600_src
->swizzle
[0] = 2;
1359 r600_src
->swizzle
[1] = 2;
1360 r600_src
->swizzle
[2] = 2;
1361 r600_src
->swizzle
[3] = 2;
1363 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSCOORD
) {
1365 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSINNER
) {
1367 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_TESSOUTER
) {
1369 } else if (ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_VERTICESIN
) {
1370 if (ctx
->type
== TGSI_PROCESSOR_TESS_CTRL
) {
1371 r600_src
->sel
= ctx
->tess_input_info
;
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 r600_src
->sel
= ctx
->tess_input_info
;
1378 r600_src
->swizzle
[0] = 3;
1379 r600_src
->swizzle
[1] = 3;
1380 r600_src
->swizzle
[2] = 3;
1381 r600_src
->swizzle
[3] = 3;
1383 } else if (ctx
->type
== TGSI_PROCESSOR_TESS_CTRL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1385 r600_src
->swizzle
[0] = 0;
1386 r600_src
->swizzle
[1] = 0;
1387 r600_src
->swizzle
[2] = 0;
1388 r600_src
->swizzle
[3] = 0;
1389 } else if (ctx
->type
== TGSI_PROCESSOR_TESS_EVAL
&& ctx
->info
.system_value_semantic_name
[tgsi_src
->Register
.Index
] == TGSI_SEMANTIC_PRIMID
) {
1391 r600_src
->swizzle
[0] = 3;
1392 r600_src
->swizzle
[1] = 3;
1393 r600_src
->swizzle
[2] = 3;
1394 r600_src
->swizzle
[3] = 3;
1397 if (tgsi_src
->Register
.Indirect
)
1398 r600_src
->rel
= V_SQ_REL_RELATIVE
;
1399 r600_src
->sel
= tgsi_src
->Register
.Index
;
1400 r600_src
->sel
+= ctx
->file_offset
[tgsi_src
->Register
.File
];
1402 if (tgsi_src
->Register
.File
== TGSI_FILE_CONSTANT
) {
1403 if (tgsi_src
->Register
.Dimension
) {
1404 r600_src
->kc_bank
= tgsi_src
->Dimension
.Index
;
1405 if (tgsi_src
->Dimension
.Indirect
) {
1406 r600_src
->kc_rel
= 1;
1412 static int tgsi_fetch_rel_const(struct r600_shader_ctx
*ctx
,
1413 unsigned int cb_idx
, unsigned cb_rel
, unsigned int offset
, unsigned ar_chan
,
1414 unsigned int dst_reg
)
1416 struct r600_bytecode_vtx vtx
;
1417 unsigned int ar_reg
;
1421 struct r600_bytecode_alu alu
;
1423 memset(&alu
, 0, sizeof(alu
));
1425 alu
.op
= ALU_OP2_ADD_INT
;
1426 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
1427 alu
.src
[0].chan
= ar_chan
;
1429 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
1430 alu
.src
[1].value
= offset
;
1432 alu
.dst
.sel
= dst_reg
;
1433 alu
.dst
.chan
= ar_chan
;
1437 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
1442 ar_reg
= ctx
->bc
->ar_reg
;
1445 memset(&vtx
, 0, sizeof(vtx
));
1446 vtx
.buffer_id
= cb_idx
;
1447 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1448 vtx
.src_gpr
= ar_reg
;
1449 vtx
.src_sel_x
= ar_chan
;
1450 vtx
.mega_fetch_count
= 16;
1451 vtx
.dst_gpr
= dst_reg
;
1452 vtx
.dst_sel_x
= 0; /* SEL_X */
1453 vtx
.dst_sel_y
= 1; /* SEL_Y */
1454 vtx
.dst_sel_z
= 2; /* SEL_Z */
1455 vtx
.dst_sel_w
= 3; /* SEL_W */
1456 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1457 vtx
.num_format_all
= 2; /* NUM_FORMAT_SCALED */
1458 vtx
.format_comp_all
= 1; /* FORMAT_COMP_SIGNED */
1459 vtx
.endian
= r600_endian_swap(32);
1460 vtx
.buffer_index_mode
= cb_rel
; // cb_rel ? V_SQ_CF_INDEX_0 : V_SQ_CF_INDEX_NONE;
1462 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1468 static int fetch_gs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1470 struct r600_bytecode_vtx vtx
;
1472 unsigned index
= src
->Register
.Index
;
1473 unsigned vtx_id
= src
->Dimension
.Index
;
1474 int offset_reg
= vtx_id
/ 3;
1475 int offset_chan
= vtx_id
% 3;
1478 /* offsets of per-vertex data in ESGS ring are passed to GS in R0.x, R0.y,
1479 * R0.w, R1.x, R1.y, R1.z (it seems R0.z is used for PrimitiveID) */
1481 if (offset_reg
== 0 && offset_chan
== 2)
1484 if (src
->Dimension
.Indirect
|| src
->Register
.Indirect
)
1485 t2
= r600_get_temp(ctx
);
1487 if (src
->Dimension
.Indirect
) {
1489 struct r600_bytecode_alu alu
;
1492 addr_reg
= get_address_file_reg(ctx
, src
->DimIndirect
.Index
);
1493 if (src
->DimIndirect
.Index
> 0) {
1494 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
1502 we have to put the R0.x/y/w into Rt.x Rt+1.x Rt+2.x then index reg from Rt.
1503 at least this is what fglrx seems to do. */
1504 for (i
= 0; i
< 3; i
++) {
1505 treg
[i
] = r600_get_temp(ctx
);
1507 r600_add_gpr_array(ctx
->shader
, treg
[0], 3, 0x0F);
1509 for (i
= 0; i
< 3; i
++) {
1510 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1511 alu
.op
= ALU_OP1_MOV
;
1513 alu
.src
[0].chan
= i
== 2 ? 3 : i
;
1514 alu
.dst
.sel
= treg
[i
];
1518 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1522 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1523 alu
.op
= ALU_OP1_MOV
;
1524 alu
.src
[0].sel
= treg
[0];
1529 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1536 if (src
->Register
.Indirect
) {
1538 unsigned first
= ctx
->info
.input_array_first
[src
->Indirect
.ArrayID
];
1540 addr_reg
= get_address_file_reg(ctx
, src
->Indirect
.Index
);
1542 /* pull the value from index_reg */
1543 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1546 V_SQ_ALU_SRC_LITERAL
, first
);
1549 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1552 V_SQ_ALU_SRC_LITERAL
, 4,
1553 offset_reg
, offset_chan
);
1558 index
= src
->Register
.Index
- first
;
1561 memset(&vtx
, 0, sizeof(vtx
));
1562 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
1563 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
1564 vtx
.src_gpr
= offset_reg
;
1565 vtx
.src_sel_x
= offset_chan
;
1566 vtx
.offset
= index
* 16; /*bytes*/
1567 vtx
.mega_fetch_count
= 16;
1568 vtx
.dst_gpr
= dst_reg
;
1569 vtx
.dst_sel_x
= 0; /* SEL_X */
1570 vtx
.dst_sel_y
= 1; /* SEL_Y */
1571 vtx
.dst_sel_z
= 2; /* SEL_Z */
1572 vtx
.dst_sel_w
= 3; /* SEL_W */
1573 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
1574 vtx
.use_const_fields
= 1;
1576 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
1579 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
1585 static int tgsi_split_gs_inputs(struct r600_shader_ctx
*ctx
)
1587 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1590 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1591 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1593 if (src
->Register
.File
== TGSI_FILE_INPUT
) {
1594 if (ctx
->shader
->input
[src
->Register
.Index
].name
== TGSI_SEMANTIC_PRIMID
) {
1595 /* primitive id is in R0.z */
1596 ctx
->src
[i
].sel
= 0;
1597 ctx
->src
[i
].swizzle
[0] = 2;
1600 if (src
->Register
.File
== TGSI_FILE_INPUT
&& src
->Register
.Dimension
) {
1601 int treg
= r600_get_temp(ctx
);
1603 fetch_gs_input(ctx
, src
, treg
);
1604 ctx
->src
[i
].sel
= treg
;
1605 ctx
->src
[i
].rel
= 0;
1612 /* Tessellation shaders pass outputs to the next shader using LDS.
1614 * LS outputs = TCS(HS) inputs
1615 * TCS(HS) outputs = TES(DS) inputs
1617 * The LDS layout is:
1618 * - TCS inputs for patch 0
1619 * - TCS inputs for patch 1
1620 * - TCS inputs for patch 2 = get_tcs_in_current_patch_offset (if RelPatchID==2)
1622 * - TCS outputs for patch 0 = get_tcs_out_patch0_offset
1623 * - Per-patch TCS outputs for patch 0 = get_tcs_out_patch0_patch_data_offset
1624 * - TCS outputs for patch 1
1625 * - Per-patch TCS outputs for patch 1
1626 * - TCS outputs for patch 2 = get_tcs_out_current_patch_offset (if RelPatchID==2)
1627 * - Per-patch TCS outputs for patch 2 = get_tcs_out_current_patch_data_offset (if RelPatchID==2)
1630 * All three shaders VS(LS), TCS, TES share the same LDS space.
1632 /* this will return with the dw address in temp_reg.x */
1633 static int r600_get_byte_address(struct r600_shader_ctx
*ctx
, int temp_reg
,
1634 const struct tgsi_full_dst_register
*dst
,
1635 const struct tgsi_full_src_register
*src
,
1636 int stride_bytes_reg
, int stride_bytes_chan
)
1638 struct tgsi_full_dst_register reg
;
1639 ubyte
*name
, *index
, *array_first
;
1642 struct tgsi_shader_info
*info
= &ctx
->info
;
1643 /* Set the register description. The address computation is the same
1644 * for sources and destinations. */
1646 reg
.Register
.File
= src
->Register
.File
;
1647 reg
.Register
.Index
= src
->Register
.Index
;
1648 reg
.Register
.Indirect
= src
->Register
.Indirect
;
1649 reg
.Register
.Dimension
= src
->Register
.Dimension
;
1650 reg
.Indirect
= src
->Indirect
;
1651 reg
.Dimension
= src
->Dimension
;
1652 reg
.DimIndirect
= src
->DimIndirect
;
1656 /* If the register is 2-dimensional (e.g. an array of vertices
1657 * in a primitive), calculate the base address of the vertex. */
1658 if (reg
.Register
.Dimension
) {
1660 if (reg
.Dimension
.Indirect
) {
1662 assert (reg
.DimIndirect
.File
== TGSI_FILE_ADDRESS
);
1664 addr_reg
= get_address_file_reg(ctx
, reg
.DimIndirect
.Index
);
1665 /* pull the value from index_reg */
1669 sel
= V_SQ_ALU_SRC_LITERAL
;
1670 chan
= reg
.Dimension
.Index
;
1673 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1675 stride_bytes_reg
, stride_bytes_chan
,
1682 if (reg
.Register
.File
== TGSI_FILE_INPUT
) {
1683 name
= info
->input_semantic_name
;
1684 index
= info
->input_semantic_index
;
1685 array_first
= info
->input_array_first
;
1686 } else if (reg
.Register
.File
== TGSI_FILE_OUTPUT
) {
1687 name
= info
->output_semantic_name
;
1688 index
= info
->output_semantic_index
;
1689 array_first
= info
->output_array_first
;
1694 if (reg
.Register
.Indirect
) {
1697 /* Add the relative address of the element. */
1698 if (reg
.Indirect
.ArrayID
)
1699 first
= array_first
[reg
.Indirect
.ArrayID
];
1701 first
= reg
.Register
.Index
;
1703 addr_reg
= get_address_file_reg(ctx
, reg
.Indirect
.Index
);
1705 /* pull the value from index_reg */
1706 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
1708 V_SQ_ALU_SRC_LITERAL
, 16,
1714 param
= r600_get_lds_unique_index(name
[first
],
1718 param
= r600_get_lds_unique_index(name
[reg
.Register
.Index
],
1719 index
[reg
.Register
.Index
]);
1722 /* add to base_addr - passed in temp_reg.x */
1724 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1727 V_SQ_ALU_SRC_LITERAL
, param
* 16);
1735 static int do_lds_fetch_values(struct r600_shader_ctx
*ctx
, unsigned temp_reg
,
1738 struct r600_bytecode_alu alu
;
1741 if ((ctx
->bc
->cf_last
->ndw
>>1) >= 0x60)
1742 ctx
->bc
->force_add_cf
= 1;
1743 for (i
= 1; i
< 4; i
++) {
1744 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
1747 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
1751 for (i
= 0; i
< 4; i
++) {
1752 /* emit an LDS_READ_RET */
1753 memset(&alu
, 0, sizeof(alu
));
1754 alu
.op
= LDS_OP1_LDS_READ_RET
;
1755 alu
.src
[0].sel
= temp_reg
;
1756 alu
.src
[0].chan
= i
;
1757 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
1758 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
1760 alu
.is_lds_idx_op
= true;
1762 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1766 for (i
= 0; i
< 4; i
++) {
1767 /* then read from LDS_OQ_A_POP */
1768 memset(&alu
, 0, sizeof(alu
));
1770 alu
.op
= ALU_OP1_MOV
;
1771 alu
.src
[0].sel
= EG_V_SQ_ALU_SRC_LDS_OQ_A_POP
;
1772 alu
.src
[0].chan
= 0;
1773 alu
.dst
.sel
= dst_reg
;
1777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1784 static int fetch_tes_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1787 unsigned temp_reg
= r600_get_temp(ctx
);
1789 r
= get_lds_offset0(ctx
, 2, temp_reg
,
1790 src
->Register
.Dimension
? false : true);
1794 /* the base address is now in temp.x */
1795 r
= r600_get_byte_address(ctx
, temp_reg
,
1796 NULL
, src
, ctx
->tess_output_info
, 1);
1800 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1806 static int fetch_tcs_input(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1809 unsigned temp_reg
= r600_get_temp(ctx
);
1811 /* t.x = ips * r0.y */
1812 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
1814 ctx
->tess_input_info
, 0,
1820 /* the base address is now in temp.x */
1821 r
= r600_get_byte_address(ctx
, temp_reg
,
1822 NULL
, src
, ctx
->tess_input_info
, 1);
1826 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1832 static int fetch_tcs_output(struct r600_shader_ctx
*ctx
, struct tgsi_full_src_register
*src
, unsigned int dst_reg
)
1835 unsigned temp_reg
= r600_get_temp(ctx
);
1837 r
= get_lds_offset0(ctx
, 1, temp_reg
,
1838 src
->Register
.Dimension
? false : true);
1841 /* the base address is now in temp.x */
1842 r
= r600_get_byte_address(ctx
, temp_reg
,
1844 ctx
->tess_output_info
, 1);
1848 r
= do_lds_fetch_values(ctx
, temp_reg
, dst_reg
);
1854 static int tgsi_split_lds_inputs(struct r600_shader_ctx
*ctx
)
1856 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1859 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1860 struct tgsi_full_src_register
*src
= &inst
->Src
[i
];
1862 if (ctx
->type
== TGSI_PROCESSOR_TESS_EVAL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1863 int treg
= r600_get_temp(ctx
);
1864 fetch_tes_input(ctx
, src
, treg
);
1865 ctx
->src
[i
].sel
= treg
;
1866 ctx
->src
[i
].rel
= 0;
1868 if (ctx
->type
== TGSI_PROCESSOR_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_INPUT
) {
1869 int treg
= r600_get_temp(ctx
);
1870 fetch_tcs_input(ctx
, src
, treg
);
1871 ctx
->src
[i
].sel
= treg
;
1872 ctx
->src
[i
].rel
= 0;
1874 if (ctx
->type
== TGSI_PROCESSOR_TESS_CTRL
&& src
->Register
.File
== TGSI_FILE_OUTPUT
) {
1875 int treg
= r600_get_temp(ctx
);
1876 fetch_tcs_output(ctx
, src
, treg
);
1877 ctx
->src
[i
].sel
= treg
;
1878 ctx
->src
[i
].rel
= 0;
1884 static int tgsi_split_constant(struct r600_shader_ctx
*ctx
)
1886 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1887 struct r600_bytecode_alu alu
;
1888 int i
, j
, k
, nconst
, r
;
1890 for (i
= 0, nconst
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1891 if (inst
->Src
[i
].Register
.File
== TGSI_FILE_CONSTANT
) {
1894 tgsi_src(ctx
, &inst
->Src
[i
], &ctx
->src
[i
]);
1896 for (i
= 0, j
= nconst
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1897 if (inst
->Src
[i
].Register
.File
!= TGSI_FILE_CONSTANT
) {
1901 if (ctx
->src
[i
].rel
) {
1902 int chan
= inst
->Src
[i
].Indirect
.Swizzle
;
1903 int treg
= r600_get_temp(ctx
);
1904 if ((r
= tgsi_fetch_rel_const(ctx
, ctx
->src
[i
].kc_bank
, ctx
->src
[i
].kc_rel
, ctx
->src
[i
].sel
- 512, chan
, treg
)))
1907 ctx
->src
[i
].kc_bank
= 0;
1908 ctx
->src
[i
].kc_rel
= 0;
1909 ctx
->src
[i
].sel
= treg
;
1910 ctx
->src
[i
].rel
= 0;
1913 int treg
= r600_get_temp(ctx
);
1914 for (k
= 0; k
< 4; k
++) {
1915 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1916 alu
.op
= ALU_OP1_MOV
;
1917 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1918 alu
.src
[0].chan
= k
;
1919 alu
.src
[0].rel
= ctx
->src
[i
].rel
;
1920 alu
.src
[0].kc_bank
= ctx
->src
[i
].kc_bank
;
1921 alu
.src
[0].kc_rel
= ctx
->src
[i
].kc_rel
;
1927 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1931 ctx
->src
[i
].sel
= treg
;
1939 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
1940 static int tgsi_split_literal_constant(struct r600_shader_ctx
*ctx
)
1942 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
1943 struct r600_bytecode_alu alu
;
1944 int i
, j
, k
, nliteral
, r
;
1946 for (i
= 0, nliteral
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1947 if (ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1951 for (i
= 0, j
= nliteral
- 1; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
1952 if (j
> 0 && ctx
->src
[i
].sel
== V_SQ_ALU_SRC_LITERAL
) {
1953 int treg
= r600_get_temp(ctx
);
1954 for (k
= 0; k
< 4; k
++) {
1955 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
1956 alu
.op
= ALU_OP1_MOV
;
1957 alu
.src
[0].sel
= ctx
->src
[i
].sel
;
1958 alu
.src
[0].chan
= k
;
1959 alu
.src
[0].value
= ctx
->src
[i
].value
[k
];
1965 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
1969 ctx
->src
[i
].sel
= treg
;
1976 static int process_twoside_color_inputs(struct r600_shader_ctx
*ctx
)
1978 int i
, r
, count
= ctx
->shader
->ninput
;
1980 for (i
= 0; i
< count
; i
++) {
1981 if (ctx
->shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1982 r
= select_twoside_color(ctx
, i
, ctx
->shader
->input
[i
].back_color_input
);
1990 static int emit_streamout(struct r600_shader_ctx
*ctx
, struct pipe_stream_output_info
*so
,
1991 int stream
, unsigned *stream_item_size
)
1993 unsigned so_gpr
[PIPE_MAX_SHADER_OUTPUTS
];
1994 unsigned start_comp
[PIPE_MAX_SHADER_OUTPUTS
];
1997 /* Sanity checking. */
1998 if (so
->num_outputs
> PIPE_MAX_SO_OUTPUTS
) {
1999 R600_ERR("Too many stream outputs: %d\n", so
->num_outputs
);
2003 for (i
= 0; i
< so
->num_outputs
; i
++) {
2004 if (so
->output
[i
].output_buffer
>= 4) {
2005 R600_ERR("Exceeded the max number of stream output buffers, got: %d\n",
2006 so
->output
[i
].output_buffer
);
2012 /* Initialize locations where the outputs are stored. */
2013 for (i
= 0; i
< so
->num_outputs
; i
++) {
2015 so_gpr
[i
] = ctx
->shader
->output
[so
->output
[i
].register_index
].gpr
;
2016 start_comp
[i
] = so
->output
[i
].start_component
;
2017 /* Lower outputs with dst_offset < start_component.
2019 * We can only output 4D vectors with a write mask, e.g. we can
2020 * only output the W component at offset 3, etc. If we want
2021 * to store Y, Z, or W at buffer offset 0, we need to use MOV
2022 * to move it to X and output X. */
2023 if (so
->output
[i
].dst_offset
< so
->output
[i
].start_component
) {
2024 unsigned tmp
= r600_get_temp(ctx
);
2026 for (j
= 0; j
< so
->output
[i
].num_components
; j
++) {
2027 struct r600_bytecode_alu alu
;
2028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2029 alu
.op
= ALU_OP1_MOV
;
2030 alu
.src
[0].sel
= so_gpr
[i
];
2031 alu
.src
[0].chan
= so
->output
[i
].start_component
+ j
;
2036 if (j
== so
->output
[i
].num_components
- 1)
2038 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2047 /* Write outputs to buffers. */
2048 for (i
= 0; i
< so
->num_outputs
; i
++) {
2049 struct r600_bytecode_output output
;
2051 if (stream
!= -1 && stream
!= so
->output
[i
].output_buffer
)
2054 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2055 output
.gpr
= so_gpr
[i
];
2056 output
.elem_size
= so
->output
[i
].num_components
- 1;
2057 if (output
.elem_size
== 2)
2058 output
.elem_size
= 3; // 3 not supported, write 4 with junk at end
2059 output
.array_base
= so
->output
[i
].dst_offset
- start_comp
[i
];
2060 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2061 output
.burst_count
= 1;
2062 /* array_size is an upper limit for the burst_count
2063 * with MEM_STREAM instructions */
2064 output
.array_size
= 0xFFF;
2065 output
.comp_mask
= ((1 << so
->output
[i
].num_components
) - 1) << start_comp
[i
];
2067 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
2068 switch (so
->output
[i
].output_buffer
) {
2070 output
.op
= CF_OP_MEM_STREAM0_BUF0
;
2073 output
.op
= CF_OP_MEM_STREAM0_BUF1
;
2076 output
.op
= CF_OP_MEM_STREAM0_BUF2
;
2079 output
.op
= CF_OP_MEM_STREAM0_BUF3
;
2082 output
.op
+= so
->output
[i
].stream
* 4;
2083 assert(output
.op
>= CF_OP_MEM_STREAM0_BUF0
&& output
.op
<= CF_OP_MEM_STREAM3_BUF3
);
2084 ctx
->enabled_stream_buffers_mask
|= (1 << so
->output
[i
].output_buffer
) << so
->output
[i
].stream
* 4;
2086 switch (so
->output
[i
].output_buffer
) {
2088 output
.op
= CF_OP_MEM_STREAM0
;
2091 output
.op
= CF_OP_MEM_STREAM1
;
2094 output
.op
= CF_OP_MEM_STREAM2
;
2097 output
.op
= CF_OP_MEM_STREAM3
;
2100 ctx
->enabled_stream_buffers_mask
|= 1 << so
->output
[i
].output_buffer
;
2102 r
= r600_bytecode_add_output(ctx
->bc
, &output
);
2111 static void convert_edgeflag_to_int(struct r600_shader_ctx
*ctx
)
2113 struct r600_bytecode_alu alu
;
2116 if (!ctx
->shader
->vs_out_edgeflag
)
2119 reg
= ctx
->shader
->output
[ctx
->edgeflag_output
].gpr
;
2121 /* clamp(x, 0, 1) */
2122 memset(&alu
, 0, sizeof(alu
));
2123 alu
.op
= ALU_OP1_MOV
;
2124 alu
.src
[0].sel
= reg
;
2129 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2131 memset(&alu
, 0, sizeof(alu
));
2132 alu
.op
= ALU_OP1_FLT_TO_INT
;
2133 alu
.src
[0].sel
= reg
;
2137 r600_bytecode_add_alu(ctx
->bc
, &alu
);
2140 static int generate_gs_copy_shader(struct r600_context
*rctx
,
2141 struct r600_pipe_shader
*gs
,
2142 struct pipe_stream_output_info
*so
)
2144 struct r600_shader_ctx ctx
= {};
2145 struct r600_shader
*gs_shader
= &gs
->shader
;
2146 struct r600_pipe_shader
*cshader
;
2147 int ocnt
= gs_shader
->noutput
;
2148 struct r600_bytecode_alu alu
;
2149 struct r600_bytecode_vtx vtx
;
2150 struct r600_bytecode_output output
;
2151 struct r600_bytecode_cf
*cf_jump
, *cf_pop
,
2152 *last_exp_pos
= NULL
, *last_exp_param
= NULL
;
2153 int i
, j
, next_clip_pos
= 61, next_param
= 0;
2155 bool only_ring_0
= true;
2156 cshader
= calloc(1, sizeof(struct r600_pipe_shader
));
2160 memcpy(cshader
->shader
.output
, gs_shader
->output
, ocnt
*
2161 sizeof(struct r600_shader_io
));
2163 cshader
->shader
.noutput
= ocnt
;
2165 ctx
.shader
= &cshader
->shader
;
2166 ctx
.bc
= &ctx
.shader
->bc
;
2167 ctx
.type
= ctx
.bc
->type
= TGSI_PROCESSOR_VERTEX
;
2169 r600_bytecode_init(ctx
.bc
, rctx
->b
.chip_class
, rctx
->b
.family
,
2170 rctx
->screen
->has_compressed_msaa_texturing
);
2172 ctx
.bc
->isa
= rctx
->isa
;
2175 memset(cshader
->shader
.ring_item_sizes
, 0, sizeof(cshader
->shader
.ring_item_sizes
));
2177 /* R0.x = R0.x & 0x3fffffff */
2178 memset(&alu
, 0, sizeof(alu
));
2179 alu
.op
= ALU_OP2_AND_INT
;
2180 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2181 alu
.src
[1].value
= 0x3fffffff;
2183 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2185 /* R0.y = R0.x >> 30 */
2186 memset(&alu
, 0, sizeof(alu
));
2187 alu
.op
= ALU_OP2_LSHR_INT
;
2188 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2189 alu
.src
[1].value
= 0x1e;
2193 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2195 /* fetch vertex data from GSVS ring */
2196 for (i
= 0; i
< ocnt
; ++i
) {
2197 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2200 out
->ring_offset
= i
* 16;
2202 memset(&vtx
, 0, sizeof(vtx
));
2203 vtx
.op
= FETCH_OP_VFETCH
;
2204 vtx
.buffer_id
= R600_GS_RING_CONST_BUFFER
;
2205 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2206 vtx
.mega_fetch_count
= 16;
2207 vtx
.offset
= out
->ring_offset
;
2208 vtx
.dst_gpr
= out
->gpr
;
2214 if (rctx
->b
.chip_class
>= EVERGREEN
) {
2215 vtx
.use_const_fields
= 1;
2217 vtx
.data_format
= FMT_32_32_32_32_FLOAT
;
2220 r600_bytecode_add_vtx(ctx
.bc
, &vtx
);
2222 ctx
.temp_reg
= i
+ 1;
2223 for (ring
= 3; ring
>= 0; --ring
) {
2224 bool enabled
= false;
2225 for (i
= 0; i
< so
->num_outputs
; i
++) {
2226 if (so
->output
[i
].stream
== ring
) {
2229 only_ring_0
= false;
2233 if (ring
!= 0 && !enabled
) {
2234 cshader
->shader
.ring_item_sizes
[ring
] = 0;
2239 // Patch up jump label
2240 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2241 cf_pop
= ctx
.bc
->cf_last
;
2243 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2244 cf_jump
->pop_count
= 1;
2245 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2246 cf_pop
->pop_count
= 1;
2249 /* PRED_SETE_INT __, R0.y, ring */
2250 memset(&alu
, 0, sizeof(alu
));
2251 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2252 alu
.src
[0].chan
= 1;
2253 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2254 alu
.src
[1].value
= ring
;
2255 alu
.execute_mask
= 1;
2256 alu
.update_pred
= 1;
2258 r600_bytecode_add_alu_type(ctx
.bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2260 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_JUMP
);
2261 cf_jump
= ctx
.bc
->cf_last
;
2264 emit_streamout(&ctx
, so
, only_ring_0
? -1 : ring
, &cshader
->shader
.ring_item_sizes
[ring
]);
2265 cshader
->shader
.ring_item_sizes
[ring
] = ocnt
* 16;
2268 /* bc adds nops - copy it */
2269 if (ctx
.bc
->chip_class
== R600
) {
2270 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2271 alu
.op
= ALU_OP0_NOP
;
2273 r600_bytecode_add_alu(ctx
.bc
, &alu
);
2275 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2278 /* export vertex data */
2279 /* XXX factor out common code with r600_shader_from_tgsi ? */
2280 for (i
= 0; i
< ocnt
; ++i
) {
2281 struct r600_shader_io
*out
= &ctx
.shader
->output
[i
];
2282 bool instream0
= true;
2283 if (out
->name
== TGSI_SEMANTIC_CLIPVERTEX
)
2286 for (j
= 0; j
< so
->num_outputs
; j
++) {
2287 if (so
->output
[j
].register_index
== i
) {
2288 if (so
->output
[j
].stream
== 0)
2290 if (so
->output
[j
].stream
> 0)
2296 memset(&output
, 0, sizeof(output
));
2297 output
.gpr
= out
->gpr
;
2298 output
.elem_size
= 3;
2299 output
.swizzle_x
= 0;
2300 output
.swizzle_y
= 1;
2301 output
.swizzle_z
= 2;
2302 output
.swizzle_w
= 3;
2303 output
.burst_count
= 1;
2304 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2305 output
.op
= CF_OP_EXPORT
;
2306 switch (out
->name
) {
2307 case TGSI_SEMANTIC_POSITION
:
2308 output
.array_base
= 60;
2309 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2312 case TGSI_SEMANTIC_PSIZE
:
2313 output
.array_base
= 61;
2314 if (next_clip_pos
== 61)
2316 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2317 output
.swizzle_y
= 7;
2318 output
.swizzle_z
= 7;
2319 output
.swizzle_w
= 7;
2320 ctx
.shader
->vs_out_misc_write
= 1;
2321 ctx
.shader
->vs_out_point_size
= 1;
2323 case TGSI_SEMANTIC_LAYER
:
2325 /* duplicate it as PARAM to pass to the pixel shader */
2326 output
.array_base
= next_param
++;
2327 r600_bytecode_add_output(ctx
.bc
, &output
);
2328 last_exp_param
= ctx
.bc
->cf_last
;
2330 output
.array_base
= 61;
2331 if (next_clip_pos
== 61)
2333 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2334 output
.swizzle_x
= 7;
2335 output
.swizzle_y
= 7;
2336 output
.swizzle_z
= 0;
2337 output
.swizzle_w
= 7;
2338 ctx
.shader
->vs_out_misc_write
= 1;
2339 ctx
.shader
->vs_out_layer
= 1;
2341 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
2343 /* duplicate it as PARAM to pass to the pixel shader */
2344 output
.array_base
= next_param
++;
2345 r600_bytecode_add_output(ctx
.bc
, &output
);
2346 last_exp_param
= ctx
.bc
->cf_last
;
2348 output
.array_base
= 61;
2349 if (next_clip_pos
== 61)
2351 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2352 ctx
.shader
->vs_out_misc_write
= 1;
2353 ctx
.shader
->vs_out_viewport
= 1;
2354 output
.swizzle_x
= 7;
2355 output
.swizzle_y
= 7;
2356 output
.swizzle_z
= 7;
2357 output
.swizzle_w
= 0;
2359 case TGSI_SEMANTIC_CLIPDIST
:
2360 /* spi_sid is 0 for clipdistance outputs that were generated
2361 * for clipvertex - we don't need to pass them to PS */
2362 ctx
.shader
->clip_dist_write
= gs
->shader
.clip_dist_write
;
2364 /* duplicate it as PARAM to pass to the pixel shader */
2365 output
.array_base
= next_param
++;
2366 r600_bytecode_add_output(ctx
.bc
, &output
);
2367 last_exp_param
= ctx
.bc
->cf_last
;
2369 output
.array_base
= next_clip_pos
++;
2370 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2372 case TGSI_SEMANTIC_FOG
:
2373 output
.swizzle_y
= 4; /* 0 */
2374 output
.swizzle_z
= 4; /* 0 */
2375 output
.swizzle_w
= 5; /* 1 */
2378 output
.array_base
= next_param
++;
2381 r600_bytecode_add_output(ctx
.bc
, &output
);
2382 if (output
.type
== V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
)
2383 last_exp_param
= ctx
.bc
->cf_last
;
2385 last_exp_pos
= ctx
.bc
->cf_last
;
2388 if (!last_exp_pos
) {
2389 memset(&output
, 0, sizeof(output
));
2391 output
.elem_size
= 3;
2392 output
.swizzle_x
= 7;
2393 output
.swizzle_y
= 7;
2394 output
.swizzle_z
= 7;
2395 output
.swizzle_w
= 7;
2396 output
.burst_count
= 1;
2398 output
.op
= CF_OP_EXPORT
;
2399 output
.array_base
= 60;
2400 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
2401 r600_bytecode_add_output(ctx
.bc
, &output
);
2402 last_exp_pos
= ctx
.bc
->cf_last
;
2405 if (!last_exp_param
) {
2406 memset(&output
, 0, sizeof(output
));
2408 output
.elem_size
= 3;
2409 output
.swizzle_x
= 7;
2410 output
.swizzle_y
= 7;
2411 output
.swizzle_z
= 7;
2412 output
.swizzle_w
= 7;
2413 output
.burst_count
= 1;
2415 output
.op
= CF_OP_EXPORT
;
2416 output
.array_base
= next_param
++;
2417 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
2418 r600_bytecode_add_output(ctx
.bc
, &output
);
2419 last_exp_param
= ctx
.bc
->cf_last
;
2422 last_exp_pos
->op
= CF_OP_EXPORT_DONE
;
2423 last_exp_param
->op
= CF_OP_EXPORT_DONE
;
2425 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_POP
);
2426 cf_pop
= ctx
.bc
->cf_last
;
2428 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2429 cf_jump
->pop_count
= 1;
2430 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2431 cf_pop
->pop_count
= 1;
2433 if (ctx
.bc
->chip_class
== CAYMAN
)
2434 cm_bytecode_add_cf_end(ctx
.bc
);
2436 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
2437 ctx
.bc
->cf_last
->end_of_program
= 1;
2440 gs
->gs_copy_shader
= cshader
;
2441 cshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
2445 return r600_bytecode_build(ctx
.bc
);
2448 static int emit_inc_ring_offset(struct r600_shader_ctx
*ctx
, int idx
, bool ind
)
2451 struct r600_bytecode_alu alu
;
2454 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2455 alu
.op
= ALU_OP2_ADD_INT
;
2456 alu
.src
[0].sel
= ctx
->gs_export_gpr_tregs
[idx
];
2457 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2458 alu
.src
[1].value
= ctx
->gs_out_ring_offset
>> 4;
2459 alu
.dst
.sel
= ctx
->gs_export_gpr_tregs
[idx
];
2462 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2469 static int emit_gs_ring_writes(struct r600_shader_ctx
*ctx
, const struct pipe_stream_output_info
*so
, int stream
, bool ind
)
2471 struct r600_bytecode_output output
;
2472 int i
, k
, ring_offset
;
2473 int effective_stream
= stream
== -1 ? 0 : stream
;
2476 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2477 if (ctx
->gs_for_vs
) {
2478 /* for ES we need to lookup corresponding ring offset expected by GS
2479 * (map this output to GS input by name and sid) */
2480 /* FIXME precompute offsets */
2482 for(k
= 0; k
< ctx
->gs_for_vs
->ninput
; ++k
) {
2483 struct r600_shader_io
*in
= &ctx
->gs_for_vs
->input
[k
];
2484 struct r600_shader_io
*out
= &ctx
->shader
->output
[i
];
2485 if (in
->name
== out
->name
&& in
->sid
== out
->sid
)
2486 ring_offset
= in
->ring_offset
;
2489 if (ring_offset
== -1)
2492 ring_offset
= idx
* 16;
2496 if (stream
> 0 && ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
2498 /* next_ring_offset after parsing input decls contains total size of
2499 * single vertex data, gs_next_vertex - current vertex index */
2501 ring_offset
+= ctx
->gs_out_ring_offset
* ctx
->gs_next_vertex
;
2503 memset(&output
, 0, sizeof(struct r600_bytecode_output
));
2504 output
.gpr
= ctx
->shader
->output
[i
].gpr
;
2505 output
.elem_size
= 3;
2506 output
.comp_mask
= 0xF;
2507 output
.burst_count
= 1;
2510 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND
;
2512 output
.type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE
;
2517 output
.op
= CF_OP_MEM_RING
; break;
2519 output
.op
= CF_OP_MEM_RING1
; break;
2521 output
.op
= CF_OP_MEM_RING2
; break;
2523 output
.op
= CF_OP_MEM_RING3
; break;
2527 output
.array_base
= ring_offset
>> 2; /* in dwords */
2528 output
.array_size
= 0xfff;
2529 output
.index_gpr
= ctx
->gs_export_gpr_tregs
[effective_stream
];
2531 output
.array_base
= ring_offset
>> 2; /* in dwords */
2532 r600_bytecode_add_output(ctx
->bc
, &output
);
2535 ++ctx
->gs_next_vertex
;
2540 static int r600_fetch_tess_io_info(struct r600_shader_ctx
*ctx
)
2543 struct r600_bytecode_vtx vtx
;
2544 int temp_val
= ctx
->temp_reg
;
2545 /* need to store the TCS output somewhere */
2546 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2548 V_SQ_ALU_SRC_LITERAL
, 0,
2553 /* used by VS/TCS */
2554 if (ctx
->tess_input_info
) {
2555 /* fetch tcs input values into resv space */
2556 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2557 vtx
.op
= FETCH_OP_VFETCH
;
2558 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2559 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2560 vtx
.mega_fetch_count
= 16;
2561 vtx
.data_format
= FMT_32_32_32_32
;
2562 vtx
.num_format_all
= 2;
2563 vtx
.format_comp_all
= 1;
2564 vtx
.use_const_fields
= 0;
2565 vtx
.endian
= r600_endian_swap(32);
2566 vtx
.srf_mode_all
= 1;
2568 vtx
.dst_gpr
= ctx
->tess_input_info
;
2573 vtx
.src_gpr
= temp_val
;
2576 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2581 /* used by TCS/TES */
2582 if (ctx
->tess_output_info
) {
2583 /* fetch tcs output values into resv space */
2584 memset(&vtx
, 0, sizeof(struct r600_bytecode_vtx
));
2585 vtx
.op
= FETCH_OP_VFETCH
;
2586 vtx
.buffer_id
= R600_LDS_INFO_CONST_BUFFER
;
2587 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
2588 vtx
.mega_fetch_count
= 16;
2589 vtx
.data_format
= FMT_32_32_32_32
;
2590 vtx
.num_format_all
= 2;
2591 vtx
.format_comp_all
= 1;
2592 vtx
.use_const_fields
= 0;
2593 vtx
.endian
= r600_endian_swap(32);
2594 vtx
.srf_mode_all
= 1;
2596 vtx
.dst_gpr
= ctx
->tess_output_info
;
2601 vtx
.src_gpr
= temp_val
;
2604 r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
);
2611 static int emit_lds_vs_writes(struct r600_shader_ctx
*ctx
)
2616 /* fetch tcs input values into input_vals */
2617 ctx
->tess_input_info
= r600_get_temp(ctx
);
2618 ctx
->tess_output_info
= 0;
2619 r
= r600_fetch_tess_io_info(ctx
);
2623 temp_reg
= r600_get_temp(ctx
);
2624 /* dst reg contains LDS address stride * idx */
2625 /* MUL vertexID, vertex_dw_stride */
2626 r
= single_alu_op2(ctx
, ALU_OP2_MUL_UINT24
,
2628 ctx
->tess_input_info
, 1,
2629 0, 1); /* rel id in r0.y? */
2633 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2634 struct r600_bytecode_alu alu
;
2635 int param
= r600_get_lds_unique_index(ctx
->shader
->output
[i
].name
, ctx
->shader
->output
[i
].sid
);
2638 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2641 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2646 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2648 temp_reg
, param
? 1 : 0,
2649 V_SQ_ALU_SRC_LITERAL
, 8);
2654 for (j
= 0; j
< 2; j
++) {
2655 int chan
= (j
== 1) ? 2 : (param
? 1 : 0);
2656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2657 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2658 alu
.src
[0].sel
= temp_reg
;
2659 alu
.src
[0].chan
= chan
;
2660 alu
.src
[1].sel
= ctx
->shader
->output
[i
].gpr
;
2661 alu
.src
[1].chan
= j
* 2;
2662 alu
.src
[2].sel
= ctx
->shader
->output
[i
].gpr
;
2663 alu
.src
[2].chan
= (j
* 2) + 1;
2667 alu
.is_lds_idx_op
= true;
2668 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2676 static int r600_store_tcs_output(struct r600_shader_ctx
*ctx
)
2678 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
2679 const struct tgsi_full_dst_register
*dst
= &inst
->Dst
[0];
2681 int temp_reg
= r600_get_temp(ctx
);
2682 struct r600_bytecode_alu alu
;
2683 unsigned write_mask
= dst
->Register
.WriteMask
;
2685 if (inst
->Dst
[0].Register
.File
!= TGSI_FILE_OUTPUT
)
2688 r
= get_lds_offset0(ctx
, 1, temp_reg
, dst
->Register
.Dimension
? false : true);
2692 /* the base address is now in temp.x */
2693 r
= r600_get_byte_address(ctx
, temp_reg
,
2694 &inst
->Dst
[0], NULL
, ctx
->tess_output_info
, 1);
2699 lasti
= tgsi_last_instruction(write_mask
);
2700 for (i
= 1; i
<= lasti
; i
++) {
2702 if (!(write_mask
& (1 << i
)))
2704 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2707 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2712 for (i
= 0; i
<= lasti
; i
++) {
2713 if (!(write_mask
& (1 << i
)))
2716 if ((i
== 0 && ((write_mask
& 3) == 3)) ||
2717 (i
== 2 && ((write_mask
& 0xc) == 0xc))) {
2718 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2719 alu
.op
= LDS_OP3_LDS_WRITE_REL
;
2720 alu
.src
[0].sel
= temp_reg
;
2721 alu
.src
[0].chan
= i
;
2723 alu
.src
[1].sel
= dst
->Register
.Index
;
2724 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2725 alu
.src
[1].chan
= i
;
2727 alu
.src
[2].sel
= dst
->Register
.Index
;
2728 alu
.src
[2].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2729 alu
.src
[2].chan
= i
+ 1;
2733 alu
.is_lds_idx_op
= true;
2734 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2740 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
2741 alu
.op
= LDS_OP2_LDS_WRITE
;
2742 alu
.src
[0].sel
= temp_reg
;
2743 alu
.src
[0].chan
= i
;
2745 alu
.src
[1].sel
= dst
->Register
.Index
;
2746 alu
.src
[1].sel
+= ctx
->file_offset
[dst
->Register
.File
];
2747 alu
.src
[1].chan
= i
;
2749 alu
.src
[2].sel
= V_SQ_ALU_SRC_0
;
2752 alu
.is_lds_idx_op
= true;
2753 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
2760 static int r600_tess_factor_read(struct r600_shader_ctx
*ctx
,
2764 unsigned temp_reg
= r600_get_temp(ctx
);
2765 unsigned name
= ctx
->shader
->output
[output_idx
].name
;
2766 int dreg
= ctx
->shader
->output
[output_idx
].gpr
;
2769 param
= r600_get_lds_unique_index(name
, 0);
2770 r
= get_lds_offset0(ctx
, 1, temp_reg
, true);
2774 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2777 V_SQ_ALU_SRC_LITERAL
, param
* 16);
2781 do_lds_fetch_values(ctx
, temp_reg
, dreg
);
2785 static int r600_emit_tess_factor(struct r600_shader_ctx
*ctx
)
2788 int stride
, outer_comps
, inner_comps
;
2789 int tessinner_idx
= -1, tessouter_idx
= -1;
2791 int temp_reg
= r600_get_temp(ctx
);
2792 int treg
[3] = {-1, -1, -1};
2793 struct r600_bytecode_alu alu
;
2794 struct r600_bytecode_cf
*cf_jump
, *cf_pop
;
2796 /* only execute factor emission for invocation 0 */
2797 /* PRED_SETE_INT __, R0.x, 0 */
2798 memset(&alu
, 0, sizeof(alu
));
2799 alu
.op
= ALU_OP2_PRED_SETE_INT
;
2800 alu
.src
[0].chan
= 2;
2801 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
2802 alu
.execute_mask
= 1;
2803 alu
.update_pred
= 1;
2805 r600_bytecode_add_alu_type(ctx
->bc
, &alu
, CF_OP_ALU_PUSH_BEFORE
);
2807 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
2808 cf_jump
= ctx
->bc
->cf_last
;
2810 treg
[0] = r600_get_temp(ctx
);
2811 switch (ctx
->shader
->tcs_prim_mode
) {
2812 case PIPE_PRIM_LINES
:
2813 stride
= 8; /* 2 dwords, 1 vec2 store */
2817 case PIPE_PRIM_TRIANGLES
:
2818 stride
= 16; /* 4 dwords, 1 vec4 store */
2821 treg
[1] = r600_get_temp(ctx
);
2823 case PIPE_PRIM_QUADS
:
2824 stride
= 24; /* 6 dwords, 2 stores (vec4 + vec2) */
2827 treg
[1] = r600_get_temp(ctx
);
2828 treg
[2] = r600_get_temp(ctx
);
2835 /* R0 is InvocationID, RelPatchID, PatchID, tf_base */
2836 /* TF_WRITE takes index in R.x, value in R.y */
2837 for (i
= 0; i
< ctx
->shader
->noutput
; i
++) {
2838 if (ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_TESSINNER
)
2840 if (ctx
->shader
->output
[i
].name
== TGSI_SEMANTIC_TESSOUTER
)
2844 if (tessouter_idx
== -1)
2847 if (tessinner_idx
== -1 && inner_comps
)
2850 if (tessouter_idx
!= -1) {
2851 r
= r600_tess_factor_read(ctx
, tessouter_idx
);
2856 if (tessinner_idx
!= -1) {
2857 r
= r600_tess_factor_read(ctx
, tessinner_idx
);
2862 /* r.x = tf_base(r0.w) + relpatchid(r0.y) * tf_stride */
2863 /* r.x = relpatchid(r0.y) * tf_stride */
2865 /* multiply incoming r0.y * stride - t.x = r0.y * stride */
2866 /* add incoming r0.w to it: t.x = t.x + r0.w */
2867 r
= single_alu_op3(ctx
, ALU_OP3_MULADD_UINT24
,
2870 V_SQ_ALU_SRC_LITERAL
, stride
,
2875 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2876 int out_idx
= i
>= outer_comps
? tessinner_idx
: tessouter_idx
;
2877 int out_comp
= i
>= outer_comps
? i
- outer_comps
: i
;
2879 r
= single_alu_op2(ctx
, ALU_OP2_ADD_INT
,
2880 treg
[i
/ 2], (2 * (i
% 2)),
2882 V_SQ_ALU_SRC_LITERAL
, 4 * i
);
2885 r
= single_alu_op2(ctx
, ALU_OP1_MOV
,
2886 treg
[i
/ 2], 1 + (2 * (i
%2)),
2887 ctx
->shader
->output
[out_idx
].gpr
, out_comp
,
2892 for (i
= 0; i
< outer_comps
+ inner_comps
; i
++) {
2893 struct r600_bytecode_gds gds
;
2895 memset(&gds
, 0, sizeof(struct r600_bytecode_gds
));
2896 gds
.src_gpr
= treg
[i
/ 2];
2897 gds
.src_sel_x
= 2 * (i
% 2);
2898 gds
.src_sel_y
= 1 + (2 * (i
% 2));
2904 gds
.op
= FETCH_OP_TF_WRITE
;
2905 r
= r600_bytecode_add_gds(ctx
->bc
, &gds
);
2910 // Patch up jump label
2911 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
2912 cf_pop
= ctx
->bc
->cf_last
;
2914 cf_jump
->cf_addr
= cf_pop
->id
+ 2;
2915 cf_jump
->pop_count
= 1;
2916 cf_pop
->cf_addr
= cf_pop
->id
+ 2;
2917 cf_pop
->pop_count
= 1;
2922 static int r600_shader_from_tgsi(struct r600_context
*rctx
,
2923 struct r600_pipe_shader
*pipeshader
,
2924 union r600_shader_key key
)
2926 struct r600_screen
*rscreen
= rctx
->screen
;
2927 struct r600_shader
*shader
= &pipeshader
->shader
;
2928 struct tgsi_token
*tokens
= pipeshader
->selector
->tokens
;
2929 struct pipe_stream_output_info so
= pipeshader
->selector
->so
;
2930 struct tgsi_full_immediate
*immediate
;
2931 struct r600_shader_ctx ctx
;
2932 struct r600_bytecode_output output
[32];
2933 unsigned output_done
, noutput
;
2936 int next_param_base
= 0, next_clip_base
;
2937 int max_color_exports
= MAX2(key
.ps
.nr_cbufs
, 1);
2938 /* Declarations used by llvm code */
2939 bool use_llvm
= false;
2941 bool ring_outputs
= false;
2942 bool lds_outputs
= false;
2943 bool lds_inputs
= false;
2944 bool pos_emitted
= false;
2946 #ifdef R600_USE_LLVM
2947 use_llvm
= rscreen
->b
.debug_flags
& DBG_LLVM
;
2949 ctx
.bc
= &shader
->bc
;
2950 ctx
.shader
= shader
;
2951 ctx
.native_integers
= true;
2954 r600_bytecode_init(ctx
.bc
, rscreen
->b
.chip_class
, rscreen
->b
.family
,
2955 rscreen
->has_compressed_msaa_texturing
);
2956 ctx
.tokens
= tokens
;
2957 tgsi_scan_shader(tokens
, &ctx
.info
);
2958 shader
->indirect_files
= ctx
.info
.indirect_files
;
2960 shader
->uses_doubles
= ctx
.info
.uses_doubles
;
2962 indirect_gprs
= ctx
.info
.indirect_files
& ~((1 << TGSI_FILE_CONSTANT
) | (1 << TGSI_FILE_SAMPLER
));
2963 tgsi_parse_init(&ctx
.parse
, tokens
);
2964 ctx
.type
= ctx
.info
.processor
;
2965 shader
->processor_type
= ctx
.type
;
2966 ctx
.bc
->type
= shader
->processor_type
;
2969 case TGSI_PROCESSOR_VERTEX
:
2970 shader
->vs_as_gs_a
= key
.vs
.as_gs_a
;
2971 shader
->vs_as_es
= key
.vs
.as_es
;
2972 shader
->vs_as_ls
= key
.vs
.as_ls
;
2973 if (shader
->vs_as_es
)
2974 ring_outputs
= true;
2975 if (shader
->vs_as_ls
)
2978 case TGSI_PROCESSOR_GEOMETRY
:
2979 ring_outputs
= true;
2981 case TGSI_PROCESSOR_TESS_CTRL
:
2982 shader
->tcs_prim_mode
= key
.tcs
.prim_mode
;
2986 case TGSI_PROCESSOR_TESS_EVAL
:
2987 shader
->tes_as_es
= key
.tes
.as_es
;
2989 if (shader
->tes_as_es
)
2990 ring_outputs
= true;
2992 case TGSI_PROCESSOR_FRAGMENT
:
2993 shader
->two_side
= key
.ps
.color_two_side
;
2999 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3000 ctx
.gs_for_vs
= &rctx
->gs_shader
->current
->shader
;
3002 ctx
.gs_for_vs
= NULL
;
3005 ctx
.next_ring_offset
= 0;
3006 ctx
.gs_out_ring_offset
= 0;
3007 ctx
.gs_next_vertex
= 0;
3008 ctx
.gs_stream_output_info
= &so
;
3011 ctx
.fixed_pt_position_gpr
= -1;
3012 ctx
.fragcoord_input
= -1;
3013 ctx
.colors_used
= 0;
3014 ctx
.clip_vertex_write
= 0;
3016 shader
->nr_ps_color_exports
= 0;
3017 shader
->nr_ps_max_color_exports
= 0;
3020 /* register allocations */
3021 /* Values [0,127] correspond to GPR[0..127].
3022 * Values [128,159] correspond to constant buffer bank 0
3023 * Values [160,191] correspond to constant buffer bank 1
3024 * Values [256,511] correspond to cfile constants c[0..255]. (Gone on EG)
3025 * Values [256,287] correspond to constant buffer bank 2 (EG)
3026 * Values [288,319] correspond to constant buffer bank 3 (EG)
3027 * Other special values are shown in the list below.
3028 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
3029 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
3030 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
3031 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
3032 * 248 SQ_ALU_SRC_0: special constant 0.0.
3033 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
3034 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
3035 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
3036 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
3037 * 253 SQ_ALU_SRC_LITERAL: literal constant.
3038 * 254 SQ_ALU_SRC_PV: previous vector result.
3039 * 255 SQ_ALU_SRC_PS: previous scalar result.
3041 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
3042 ctx
.file_offset
[i
] = 0;
3045 #ifdef R600_USE_LLVM
3046 if (use_llvm
&& ctx
.info
.indirect_files
&& (ctx
.info
.indirect_files
& (1 << TGSI_FILE_CONSTANT
)) != ctx
.info
.indirect_files
) {
3047 fprintf(stderr
, "Warning: R600 LLVM backend does not support "
3048 "indirect adressing. Falling back to TGSI "
3053 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
3054 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3056 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CALL_FS
);
3059 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
) {
3060 if (ctx
.bc
->chip_class
>= EVERGREEN
)
3061 ctx
.file_offset
[TGSI_FILE_INPUT
] = evergreen_gpr_count(&ctx
);
3063 ctx
.file_offset
[TGSI_FILE_INPUT
] = allocate_system_value_inputs(&ctx
, ctx
.file_offset
[TGSI_FILE_INPUT
]);
3065 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
3066 /* FIXME 1 would be enough in some cases (3 or less input vertices) */
3067 ctx
.file_offset
[TGSI_FILE_INPUT
] = 2;
3069 if (ctx
.type
== TGSI_PROCESSOR_TESS_CTRL
)
3070 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3071 if (ctx
.type
== TGSI_PROCESSOR_TESS_EVAL
) {
3072 bool add_tesscoord
= false, add_tess_inout
= false;
3073 ctx
.file_offset
[TGSI_FILE_INPUT
] = 1;
3074 for (i
= 0; i
< PIPE_MAX_SHADER_INPUTS
; i
++) {
3075 /* if we have tesscoord save one reg */
3076 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSCOORD
)
3077 add_tesscoord
= true;
3078 if (ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSINNER
||
3079 ctx
.info
.system_value_semantic_name
[i
] == TGSI_SEMANTIC_TESSOUTER
)
3080 add_tess_inout
= true;
3082 if (add_tesscoord
|| add_tess_inout
)
3083 ctx
.file_offset
[TGSI_FILE_INPUT
]++;
3085 ctx
.file_offset
[TGSI_FILE_INPUT
]+=2;
3087 ctx
.use_llvm
= use_llvm
;
3090 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3091 ctx
.file_offset
[TGSI_FILE_INPUT
];
3093 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3094 ctx
.file_offset
[TGSI_FILE_INPUT
] +
3095 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3097 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] = ctx
.file_offset
[TGSI_FILE_OUTPUT
] +
3098 ctx
.info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
3100 /* Outside the GPR range. This will be translated to one of the
3101 * kcache banks later. */
3102 ctx
.file_offset
[TGSI_FILE_CONSTANT
] = 512;
3104 ctx
.file_offset
[TGSI_FILE_IMMEDIATE
] = V_SQ_ALU_SRC_LITERAL
;
3105 ctx
.bc
->ar_reg
= ctx
.file_offset
[TGSI_FILE_TEMPORARY
] +
3106 ctx
.info
.file_max
[TGSI_FILE_TEMPORARY
] + 1;
3107 ctx
.bc
->index_reg
[0] = ctx
.bc
->ar_reg
+ 1;
3108 ctx
.bc
->index_reg
[1] = ctx
.bc
->ar_reg
+ 2;
3110 if (ctx
.type
== TGSI_PROCESSOR_TESS_CTRL
) {
3111 ctx
.tess_input_info
= ctx
.bc
->ar_reg
+ 3;
3112 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 4;
3113 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 5;
3114 } else if (ctx
.type
== TGSI_PROCESSOR_TESS_EVAL
) {
3115 ctx
.tess_input_info
= 0;
3116 ctx
.tess_output_info
= ctx
.bc
->ar_reg
+ 3;
3117 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 4;
3118 } else if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
3119 ctx
.gs_export_gpr_tregs
[0] = ctx
.bc
->ar_reg
+ 3;
3120 ctx
.gs_export_gpr_tregs
[1] = ctx
.bc
->ar_reg
+ 4;
3121 ctx
.gs_export_gpr_tregs
[2] = ctx
.bc
->ar_reg
+ 5;
3122 ctx
.gs_export_gpr_tregs
[3] = ctx
.bc
->ar_reg
+ 6;
3123 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 7;
3125 ctx
.temp_reg
= ctx
.bc
->ar_reg
+ 3;
3128 shader
->max_arrays
= 0;
3129 shader
->num_arrays
= 0;
3130 if (indirect_gprs
) {
3132 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_INPUT
)) {
3133 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_INPUT
],
3134 ctx
.file_offset
[TGSI_FILE_OUTPUT
] -
3135 ctx
.file_offset
[TGSI_FILE_INPUT
],
3138 if (ctx
.info
.indirect_files
& (1 << TGSI_FILE_OUTPUT
)) {
3139 r600_add_gpr_array(shader
, ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3140 ctx
.file_offset
[TGSI_FILE_TEMPORARY
] -
3141 ctx
.file_offset
[TGSI_FILE_OUTPUT
],
3147 ctx
.literals
= NULL
;
3149 shader
->fs_write_all
= ctx
.info
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
] &&
3150 ctx
.info
.colors_written
== 1;
3151 shader
->vs_position_window_space
= ctx
.info
.properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
3152 shader
->ps_conservative_z
= (uint8_t)ctx
.info
.properties
[TGSI_PROPERTY_FS_DEPTH_LAYOUT
];
3154 if (shader
->vs_as_gs_a
)
3155 vs_add_primid_output(&ctx
, key
.vs
.prim_id_out
);
3157 if (ctx
.type
== TGSI_PROCESSOR_TESS_EVAL
)
3158 r600_fetch_tess_io_info(&ctx
);
3160 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3161 tgsi_parse_token(&ctx
.parse
);
3162 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3163 case TGSI_TOKEN_TYPE_IMMEDIATE
:
3164 immediate
= &ctx
.parse
.FullToken
.FullImmediate
;
3165 ctx
.literals
= realloc(ctx
.literals
, (ctx
.nliterals
+ 1) * 16);
3166 if(ctx
.literals
== NULL
) {
3170 ctx
.literals
[ctx
.nliterals
* 4 + 0] = immediate
->u
[0].Uint
;
3171 ctx
.literals
[ctx
.nliterals
* 4 + 1] = immediate
->u
[1].Uint
;
3172 ctx
.literals
[ctx
.nliterals
* 4 + 2] = immediate
->u
[2].Uint
;
3173 ctx
.literals
[ctx
.nliterals
* 4 + 3] = immediate
->u
[3].Uint
;
3176 case TGSI_TOKEN_TYPE_DECLARATION
:
3177 r
= tgsi_declaration(&ctx
);
3181 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3182 case TGSI_TOKEN_TYPE_PROPERTY
:
3185 R600_ERR("unsupported token type %d\n", ctx
.parse
.FullToken
.Token
.Type
);
3191 shader
->ring_item_sizes
[0] = ctx
.next_ring_offset
;
3192 shader
->ring_item_sizes
[1] = 0;
3193 shader
->ring_item_sizes
[2] = 0;
3194 shader
->ring_item_sizes
[3] = 0;
3196 /* Process two side if needed */
3197 if (shader
->two_side
&& ctx
.colors_used
) {
3198 int i
, count
= ctx
.shader
->ninput
;
3199 unsigned next_lds_loc
= ctx
.shader
->nlds
;
3201 /* additional inputs will be allocated right after the existing inputs,
3202 * we won't need them after the color selection, so we don't need to
3203 * reserve these gprs for the rest of the shader code and to adjust
3204 * output offsets etc. */
3205 int gpr
= ctx
.file_offset
[TGSI_FILE_INPUT
] +
3206 ctx
.info
.file_max
[TGSI_FILE_INPUT
] + 1;
3208 /* if two sided and neither face or sample mask is used by shader, ensure face_gpr is emitted */
3209 if (ctx
.face_gpr
== -1) {
3210 i
= ctx
.shader
->ninput
++;
3211 ctx
.shader
->input
[i
].name
= TGSI_SEMANTIC_FACE
;
3212 ctx
.shader
->input
[i
].spi_sid
= 0;
3213 ctx
.shader
->input
[i
].gpr
= gpr
++;
3214 ctx
.face_gpr
= ctx
.shader
->input
[i
].gpr
;
3217 for (i
= 0; i
< count
; i
++) {
3218 if (ctx
.shader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3219 int ni
= ctx
.shader
->ninput
++;
3220 memcpy(&ctx
.shader
->input
[ni
],&ctx
.shader
->input
[i
], sizeof(struct r600_shader_io
));
3221 ctx
.shader
->input
[ni
].name
= TGSI_SEMANTIC_BCOLOR
;
3222 ctx
.shader
->input
[ni
].spi_sid
= r600_spi_sid(&ctx
.shader
->input
[ni
]);
3223 ctx
.shader
->input
[ni
].gpr
= gpr
++;
3224 // TGSI to LLVM needs to know the lds position of inputs.
3225 // Non LLVM path computes it later (in process_twoside_color)
3226 ctx
.shader
->input
[ni
].lds_pos
= next_lds_loc
++;
3227 ctx
.shader
->input
[i
].back_color_input
= ni
;
3228 if (ctx
.bc
->chip_class
>= EVERGREEN
) {
3229 if ((r
= evergreen_interp_input(&ctx
, ni
)))
3236 /* LLVM backend setup */
3237 #ifdef R600_USE_LLVM
3239 struct radeon_llvm_context radeon_llvm_ctx
;
3241 bool dump
= r600_can_dump_shader(&rscreen
->b
, tokens
);
3242 boolean use_kill
= false;
3244 memset(&radeon_llvm_ctx
, 0, sizeof(radeon_llvm_ctx
));
3245 radeon_llvm_ctx
.type
= ctx
.type
;
3246 radeon_llvm_ctx
.two_side
= shader
->two_side
;
3247 radeon_llvm_ctx
.face_gpr
= ctx
.face_gpr
;
3248 radeon_llvm_ctx
.inputs_count
= ctx
.shader
->ninput
+ 1;
3249 radeon_llvm_ctx
.r600_inputs
= ctx
.shader
->input
;
3250 radeon_llvm_ctx
.r600_outputs
= ctx
.shader
->output
;
3251 radeon_llvm_ctx
.color_buffer_count
= max_color_exports
;
3252 radeon_llvm_ctx
.chip_class
= ctx
.bc
->chip_class
;
3253 radeon_llvm_ctx
.fs_color_all
= shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
);
3254 radeon_llvm_ctx
.stream_outputs
= &so
;
3255 radeon_llvm_ctx
.alpha_to_one
= key
.ps
.alpha_to_one
;
3256 radeon_llvm_ctx
.has_compressed_msaa_texturing
=
3257 ctx
.bc
->has_compressed_msaa_texturing
;
3258 mod
= r600_tgsi_llvm(&radeon_llvm_ctx
, tokens
);
3259 ctx
.shader
->has_txq_cube_array_z_comp
= radeon_llvm_ctx
.has_txq_cube_array_z_comp
;
3260 ctx
.shader
->uses_tex_buffers
= radeon_llvm_ctx
.uses_tex_buffers
;
3262 if (r600_llvm_compile(mod
, rscreen
->b
.family
, ctx
.bc
, &use_kill
,
3263 dump
, &rctx
->b
.debug
)) {
3264 radeon_llvm_dispose(&radeon_llvm_ctx
);
3266 fprintf(stderr
, "R600 LLVM backend failed to compile "
3267 "shader. Falling back to TGSI\n");
3269 ctx
.file_offset
[TGSI_FILE_OUTPUT
] =
3270 ctx
.file_offset
[TGSI_FILE_INPUT
];
3273 ctx
.shader
->uses_kill
= use_kill
;
3274 radeon_llvm_dispose(&radeon_llvm_ctx
);
3277 /* End of LLVM backend setup */
3279 if (shader
->fs_write_all
&& rscreen
->b
.chip_class
>= EVERGREEN
)
3280 shader
->nr_ps_max_color_exports
= 8;
3283 if (ctx
.fragcoord_input
>= 0) {
3284 if (ctx
.bc
->chip_class
== CAYMAN
) {
3285 for (j
= 0 ; j
< 4; j
++) {
3286 struct r600_bytecode_alu alu
;
3287 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3288 alu
.op
= ALU_OP1_RECIP_IEEE
;
3289 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3290 alu
.src
[0].chan
= 3;
3292 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3294 alu
.dst
.write
= (j
== 3);
3296 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3300 struct r600_bytecode_alu alu
;
3301 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3302 alu
.op
= ALU_OP1_RECIP_IEEE
;
3303 alu
.src
[0].sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3304 alu
.src
[0].chan
= 3;
3306 alu
.dst
.sel
= shader
->input
[ctx
.fragcoord_input
].gpr
;
3310 if ((r
= r600_bytecode_add_alu(ctx
.bc
, &alu
)))
3315 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
3316 struct r600_bytecode_alu alu
;
3319 /* GS thread with no output workaround - emit a cut at start of GS */
3320 if (ctx
.bc
->chip_class
== R600
)
3321 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_CUT_VERTEX
);
3323 for (j
= 0; j
< 4; j
++) {
3324 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3325 alu
.op
= ALU_OP1_MOV
;
3326 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
3327 alu
.src
[0].value
= 0;
3328 alu
.dst
.sel
= ctx
.gs_export_gpr_tregs
[j
];
3331 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3337 if (ctx
.type
== TGSI_PROCESSOR_TESS_CTRL
)
3338 r600_fetch_tess_io_info(&ctx
);
3340 if (shader
->two_side
&& ctx
.colors_used
) {
3341 if ((r
= process_twoside_color_inputs(&ctx
)))
3345 tgsi_parse_init(&ctx
.parse
, tokens
);
3346 while (!tgsi_parse_end_of_tokens(&ctx
.parse
)) {
3347 tgsi_parse_token(&ctx
.parse
);
3348 switch (ctx
.parse
.FullToken
.Token
.Type
) {
3349 case TGSI_TOKEN_TYPE_INSTRUCTION
:
3350 r
= tgsi_is_supported(&ctx
);
3353 ctx
.max_driver_temp_used
= 0;
3354 /* reserve first tmp for everyone */
3355 r600_get_temp(&ctx
);
3357 opcode
= ctx
.parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3358 if ((r
= tgsi_split_constant(&ctx
)))
3360 if ((r
= tgsi_split_literal_constant(&ctx
)))
3362 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
3363 if ((r
= tgsi_split_gs_inputs(&ctx
)))
3365 } else if (lds_inputs
) {
3366 if ((r
= tgsi_split_lds_inputs(&ctx
)))
3369 if (ctx
.bc
->chip_class
== CAYMAN
)
3370 ctx
.inst_info
= &cm_shader_tgsi_instruction
[opcode
];
3371 else if (ctx
.bc
->chip_class
>= EVERGREEN
)
3372 ctx
.inst_info
= &eg_shader_tgsi_instruction
[opcode
];
3374 ctx
.inst_info
= &r600_shader_tgsi_instruction
[opcode
];
3375 r
= ctx
.inst_info
->process(&ctx
);
3379 if (ctx
.type
== TGSI_PROCESSOR_TESS_CTRL
) {
3380 r
= r600_store_tcs_output(&ctx
);
3391 /* Reset the temporary register counter. */
3392 ctx
.max_driver_temp_used
= 0;
3394 noutput
= shader
->noutput
;
3396 if (!ring_outputs
&& ctx
.clip_vertex_write
) {
3397 unsigned clipdist_temp
[2];
3399 clipdist_temp
[0] = r600_get_temp(&ctx
);
3400 clipdist_temp
[1] = r600_get_temp(&ctx
);
3402 /* need to convert a clipvertex write into clipdistance writes and not export
3403 the clip vertex anymore */
3405 memset(&shader
->output
[noutput
], 0, 2*sizeof(struct r600_shader_io
));
3406 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3407 shader
->output
[noutput
].gpr
= clipdist_temp
[0];
3409 shader
->output
[noutput
].name
= TGSI_SEMANTIC_CLIPDIST
;
3410 shader
->output
[noutput
].gpr
= clipdist_temp
[1];
3413 /* reset spi_sid for clipvertex output to avoid confusing spi */
3414 shader
->output
[ctx
.cv_output
].spi_sid
= 0;
3416 shader
->clip_dist_write
= 0xFF;
3418 for (i
= 0; i
< 8; i
++) {
3422 for (j
= 0; j
< 4; j
++) {
3423 struct r600_bytecode_alu alu
;
3424 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3425 alu
.op
= ALU_OP2_DOT4
;
3426 alu
.src
[0].sel
= shader
->output
[ctx
.cv_output
].gpr
;
3427 alu
.src
[0].chan
= j
;
3429 alu
.src
[1].sel
= 512 + i
;
3430 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
3431 alu
.src
[1].chan
= j
;
3433 alu
.dst
.sel
= clipdist_temp
[oreg
];
3435 alu
.dst
.write
= (j
== ochan
);
3439 r
= r600_bytecode_add_alu(ctx
.bc
, &alu
);
3446 /* Add stream outputs. */
3447 if (!use_llvm
&& so
.num_outputs
) {
3449 if (!lds_outputs
&& !ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_VERTEX
)
3451 if (!ring_outputs
&& ctx
.type
== TGSI_PROCESSOR_TESS_EVAL
)
3454 emit_streamout(&ctx
, &so
, -1, NULL
);
3456 pipeshader
->enabled_stream_buffers_mask
= ctx
.enabled_stream_buffers_mask
;
3457 convert_edgeflag_to_int(&ctx
);
3459 if (ctx
.type
== TGSI_PROCESSOR_TESS_CTRL
)
3460 r600_emit_tess_factor(&ctx
);
3463 if (ctx
.type
== TGSI_PROCESSOR_VERTEX
) {
3464 if (ctx
.shader
->noutput
)
3465 emit_lds_vs_writes(&ctx
);
3467 } else if (ring_outputs
) {
3468 if (shader
->vs_as_es
|| shader
->tes_as_es
) {
3469 ctx
.gs_export_gpr_tregs
[0] = r600_get_temp(&ctx
);
3470 ctx
.gs_export_gpr_tregs
[1] = -1;
3471 ctx
.gs_export_gpr_tregs
[2] = -1;
3472 ctx
.gs_export_gpr_tregs
[3] = -1;
3474 emit_gs_ring_writes(&ctx
, &so
, -1, FALSE
);
3478 next_clip_base
= shader
->vs_out_misc_write
? 62 : 61;
3480 for (i
= 0, j
= 0; i
< noutput
; i
++, j
++) {
3481 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3482 output
[j
].gpr
= shader
->output
[i
].gpr
;
3483 output
[j
].elem_size
= 3;
3484 output
[j
].swizzle_x
= 0;
3485 output
[j
].swizzle_y
= 1;
3486 output
[j
].swizzle_z
= 2;
3487 output
[j
].swizzle_w
= 3;
3488 output
[j
].burst_count
= 1;
3489 output
[j
].type
= -1;
3490 output
[j
].op
= CF_OP_EXPORT
;
3492 case TGSI_PROCESSOR_VERTEX
:
3493 case TGSI_PROCESSOR_TESS_EVAL
:
3494 switch (shader
->output
[i
].name
) {
3495 case TGSI_SEMANTIC_POSITION
:
3496 output
[j
].array_base
= 60;
3497 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3501 case TGSI_SEMANTIC_PSIZE
:
3502 output
[j
].array_base
= 61;
3503 output
[j
].swizzle_y
= 7;
3504 output
[j
].swizzle_z
= 7;
3505 output
[j
].swizzle_w
= 7;
3506 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3509 case TGSI_SEMANTIC_EDGEFLAG
:
3510 output
[j
].array_base
= 61;
3511 output
[j
].swizzle_x
= 7;
3512 output
[j
].swizzle_y
= 0;
3513 output
[j
].swizzle_z
= 7;
3514 output
[j
].swizzle_w
= 7;
3515 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3518 case TGSI_SEMANTIC_LAYER
:
3519 /* spi_sid is 0 for outputs that are
3520 * not consumed by PS */
3521 if (shader
->output
[i
].spi_sid
) {
3522 output
[j
].array_base
= next_param_base
++;
3523 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3525 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3527 output
[j
].array_base
= 61;
3528 output
[j
].swizzle_x
= 7;
3529 output
[j
].swizzle_y
= 7;
3530 output
[j
].swizzle_z
= 0;
3531 output
[j
].swizzle_w
= 7;
3532 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3535 case TGSI_SEMANTIC_VIEWPORT_INDEX
:
3536 /* spi_sid is 0 for outputs that are
3537 * not consumed by PS */
3538 if (shader
->output
[i
].spi_sid
) {
3539 output
[j
].array_base
= next_param_base
++;
3540 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3542 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3544 output
[j
].array_base
= 61;
3545 output
[j
].swizzle_x
= 7;
3546 output
[j
].swizzle_y
= 7;
3547 output
[j
].swizzle_z
= 7;
3548 output
[j
].swizzle_w
= 0;
3549 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3552 case TGSI_SEMANTIC_CLIPVERTEX
:
3555 case TGSI_SEMANTIC_CLIPDIST
:
3556 output
[j
].array_base
= next_clip_base
++;
3557 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3559 /* spi_sid is 0 for clipdistance outputs that were generated
3560 * for clipvertex - we don't need to pass them to PS */
3561 if (shader
->output
[i
].spi_sid
) {
3563 /* duplicate it as PARAM to pass to the pixel shader */
3564 memcpy(&output
[j
], &output
[j
-1], sizeof(struct r600_bytecode_output
));
3565 output
[j
].array_base
= next_param_base
++;
3566 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3569 case TGSI_SEMANTIC_FOG
:
3570 output
[j
].swizzle_y
= 4; /* 0 */
3571 output
[j
].swizzle_z
= 4; /* 0 */
3572 output
[j
].swizzle_w
= 5; /* 1 */
3574 case TGSI_SEMANTIC_PRIMID
:
3575 output
[j
].swizzle_x
= 2;
3576 output
[j
].swizzle_y
= 4; /* 0 */
3577 output
[j
].swizzle_z
= 4; /* 0 */
3578 output
[j
].swizzle_w
= 4; /* 0 */
3583 case TGSI_PROCESSOR_FRAGMENT
:
3584 if (shader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
3585 /* never export more colors than the number of CBs */
3586 if (shader
->output
[i
].sid
>= max_color_exports
) {
3591 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3592 output
[j
].array_base
= shader
->output
[i
].sid
;
3593 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3594 shader
->nr_ps_color_exports
++;
3595 if (shader
->fs_write_all
&& (rscreen
->b
.chip_class
>= EVERGREEN
)) {
3596 for (k
= 1; k
< max_color_exports
; k
++) {
3598 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3599 output
[j
].gpr
= shader
->output
[i
].gpr
;
3600 output
[j
].elem_size
= 3;
3601 output
[j
].swizzle_x
= 0;
3602 output
[j
].swizzle_y
= 1;
3603 output
[j
].swizzle_z
= 2;
3604 output
[j
].swizzle_w
= key
.ps
.alpha_to_one
? 5 : 3;
3605 output
[j
].burst_count
= 1;
3606 output
[j
].array_base
= k
;
3607 output
[j
].op
= CF_OP_EXPORT
;
3608 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3609 shader
->nr_ps_color_exports
++;
3612 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
) {
3613 output
[j
].array_base
= 61;
3614 output
[j
].swizzle_x
= 2;
3615 output
[j
].swizzle_y
= 7;
3616 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3617 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3618 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
) {
3619 output
[j
].array_base
= 61;
3620 output
[j
].swizzle_x
= 7;
3621 output
[j
].swizzle_y
= 1;
3622 output
[j
].swizzle_z
= output
[j
].swizzle_w
= 7;
3623 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3624 } else if (shader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3625 output
[j
].array_base
= 61;
3626 output
[j
].swizzle_x
= 7;
3627 output
[j
].swizzle_y
= 7;
3628 output
[j
].swizzle_z
= 0;
3629 output
[j
].swizzle_w
= 7;
3630 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3632 R600_ERR("unsupported fragment output name %d\n", shader
->output
[i
].name
);
3637 case TGSI_PROCESSOR_TESS_CTRL
:
3640 R600_ERR("unsupported processor type %d\n", ctx
.type
);
3645 if (output
[j
].type
==-1) {
3646 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3647 output
[j
].array_base
= next_param_base
++;
3651 /* add fake position export */
3652 if ((ctx
.type
== TGSI_PROCESSOR_VERTEX
|| ctx
.type
== TGSI_PROCESSOR_TESS_EVAL
) && pos_emitted
== false) {
3653 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3655 output
[j
].elem_size
= 3;
3656 output
[j
].swizzle_x
= 7;
3657 output
[j
].swizzle_y
= 7;
3658 output
[j
].swizzle_z
= 7;
3659 output
[j
].swizzle_w
= 7;
3660 output
[j
].burst_count
= 1;
3661 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS
;
3662 output
[j
].array_base
= 60;
3663 output
[j
].op
= CF_OP_EXPORT
;
3667 /* add fake param output for vertex shader if no param is exported */
3668 if ((ctx
.type
== TGSI_PROCESSOR_VERTEX
|| ctx
.type
== TGSI_PROCESSOR_TESS_EVAL
) && next_param_base
== 0) {
3669 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3671 output
[j
].elem_size
= 3;
3672 output
[j
].swizzle_x
= 7;
3673 output
[j
].swizzle_y
= 7;
3674 output
[j
].swizzle_z
= 7;
3675 output
[j
].swizzle_w
= 7;
3676 output
[j
].burst_count
= 1;
3677 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM
;
3678 output
[j
].array_base
= 0;
3679 output
[j
].op
= CF_OP_EXPORT
;
3683 /* add fake pixel export */
3684 if (ctx
.type
== TGSI_PROCESSOR_FRAGMENT
&& shader
->nr_ps_color_exports
== 0) {
3685 memset(&output
[j
], 0, sizeof(struct r600_bytecode_output
));
3687 output
[j
].elem_size
= 3;
3688 output
[j
].swizzle_x
= 7;
3689 output
[j
].swizzle_y
= 7;
3690 output
[j
].swizzle_z
= 7;
3691 output
[j
].swizzle_w
= 7;
3692 output
[j
].burst_count
= 1;
3693 output
[j
].type
= V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL
;
3694 output
[j
].array_base
= 0;
3695 output
[j
].op
= CF_OP_EXPORT
;
3697 shader
->nr_ps_color_exports
++;
3702 /* set export done on last export of each type */
3703 for (i
= noutput
- 1, output_done
= 0; i
>= 0; i
--) {
3704 if (!(output_done
& (1 << output
[i
].type
))) {
3705 output_done
|= (1 << output
[i
].type
);
3706 output
[i
].op
= CF_OP_EXPORT_DONE
;
3709 /* add output to bytecode */
3711 for (i
= 0; i
< noutput
; i
++) {
3712 r
= r600_bytecode_add_output(ctx
.bc
, &output
[i
]);
3719 /* add program end */
3721 if (ctx
.bc
->chip_class
== CAYMAN
)
3722 cm_bytecode_add_cf_end(ctx
.bc
);
3724 const struct cf_op_info
*last
= NULL
;
3726 if (ctx
.bc
->cf_last
)
3727 last
= r600_isa_cf(ctx
.bc
->cf_last
->op
);
3729 /* alu clause instructions don't have EOP bit, so add NOP */
3730 if (!last
|| last
->flags
& CF_ALU
|| ctx
.bc
->cf_last
->op
== CF_OP_LOOP_END
|| ctx
.bc
->cf_last
->op
== CF_OP_CALL_FS
|| ctx
.bc
->cf_last
->op
== CF_OP_POP
|| ctx
.bc
->cf_last
->op
== CF_OP_GDS
)
3731 r600_bytecode_add_cfinst(ctx
.bc
, CF_OP_NOP
);
3733 ctx
.bc
->cf_last
->end_of_program
= 1;
3737 /* check GPR limit - we have 124 = 128 - 4
3738 * (4 are reserved as alu clause temporary registers) */
3739 if (ctx
.bc
->ngpr
> 124) {
3740 R600_ERR("GPR limit exceeded - shader requires %d registers\n", ctx
.bc
->ngpr
);
3745 if (ctx
.type
== TGSI_PROCESSOR_GEOMETRY
) {
3746 if ((r
= generate_gs_copy_shader(rctx
, pipeshader
, &so
)))
3751 tgsi_parse_free(&ctx
.parse
);
3755 tgsi_parse_free(&ctx
.parse
);
3759 static int tgsi_unsupported(struct r600_shader_ctx
*ctx
)
3761 const unsigned tgsi_opcode
=
3762 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
;
3763 R600_ERR("%s tgsi opcode unsupported\n",
3764 tgsi_get_opcode_name(tgsi_opcode
));
3768 static int tgsi_end(struct r600_shader_ctx
*ctx
)
3773 static void r600_bytecode_src(struct r600_bytecode_alu_src
*bc_src
,
3774 const struct r600_shader_src
*shader_src
,
3777 bc_src
->sel
= shader_src
->sel
;
3778 bc_src
->chan
= shader_src
->swizzle
[chan
];
3779 bc_src
->neg
= shader_src
->neg
;
3780 bc_src
->abs
= shader_src
->abs
;
3781 bc_src
->rel
= shader_src
->rel
;
3782 bc_src
->value
= shader_src
->value
[bc_src
->chan
];
3783 bc_src
->kc_bank
= shader_src
->kc_bank
;
3784 bc_src
->kc_rel
= shader_src
->kc_rel
;
3787 static void r600_bytecode_src_set_abs(struct r600_bytecode_alu_src
*bc_src
)
3793 static void r600_bytecode_src_toggle_neg(struct r600_bytecode_alu_src
*bc_src
)
3795 bc_src
->neg
= !bc_src
->neg
;
3798 static void tgsi_dst(struct r600_shader_ctx
*ctx
,
3799 const struct tgsi_full_dst_register
*tgsi_dst
,
3801 struct r600_bytecode_alu_dst
*r600_dst
)
3803 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3805 r600_dst
->sel
= tgsi_dst
->Register
.Index
;
3806 r600_dst
->sel
+= ctx
->file_offset
[tgsi_dst
->Register
.File
];
3807 r600_dst
->chan
= swizzle
;
3808 r600_dst
->write
= 1;
3809 if (inst
->Instruction
.Saturate
) {
3810 r600_dst
->clamp
= 1;
3812 if (ctx
->type
== TGSI_PROCESSOR_TESS_CTRL
) {
3813 if (tgsi_dst
->Register
.File
== TGSI_FILE_OUTPUT
) {
3817 if (tgsi_dst
->Register
.Indirect
)
3818 r600_dst
->rel
= V_SQ_REL_RELATIVE
;
3822 static int tgsi_op2_64_params(struct r600_shader_ctx
*ctx
, bool singledest
, bool swap
)
3824 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3825 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3826 struct r600_bytecode_alu alu
;
3827 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3831 switch (write_mask
) {
3849 lasti
= tgsi_last_instruction(write_mask
);
3850 for (i
= 0; i
<= lasti
; i
++) {
3852 if (!(write_mask
& (1 << i
)))
3855 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3858 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3860 alu
.dst
.sel
= ctx
->temp_reg
;
3864 if (i
== 1 || i
== 3)
3867 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3869 alu
.op
= ctx
->inst_info
->op
;
3870 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DABS
) {
3871 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
3873 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3874 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
3877 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], fp64_switch(i
));
3878 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], fp64_switch(i
));
3881 /* handle some special cases */
3882 if (i
== 1 || i
== 3) {
3883 switch (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
) {
3884 case TGSI_OPCODE_SUB
:
3885 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
3887 case TGSI_OPCODE_DABS
:
3888 r600_bytecode_src_set_abs(&alu
.src
[0]);
3897 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3903 write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3905 /* move result from temp to dst */
3906 for (i
= 0; i
<= lasti
; i
++) {
3907 if (!(write_mask
& (1 << i
)))
3910 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3911 alu
.op
= ALU_OP1_MOV
;
3912 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3913 alu
.src
[0].sel
= ctx
->temp_reg
;
3914 alu
.src
[0].chan
= use_tmp
- 1;
3915 alu
.last
= (i
== lasti
);
3917 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3925 static int tgsi_op2_64(struct r600_shader_ctx
*ctx
)
3927 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3928 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3929 /* confirm writemasking */
3930 if ((write_mask
& 0x3) != 0x3 &&
3931 (write_mask
& 0xc) != 0xc) {
3932 fprintf(stderr
, "illegal writemask for 64-bit: 0x%x\n", write_mask
);
3935 return tgsi_op2_64_params(ctx
, false, false);
3938 static int tgsi_op2_64_single_dest(struct r600_shader_ctx
*ctx
)
3940 return tgsi_op2_64_params(ctx
, true, false);
3943 static int tgsi_op2_64_single_dest_s(struct r600_shader_ctx
*ctx
)
3945 return tgsi_op2_64_params(ctx
, true, true);
3948 static int tgsi_op3_64(struct r600_shader_ctx
*ctx
)
3950 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3951 struct r600_bytecode_alu alu
;
3954 int tmp
= r600_get_temp(ctx
);
3956 for (i
= 0; i
< lasti
+ 1; i
++) {
3958 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3959 alu
.op
= ctx
->inst_info
->op
;
3960 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
3961 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
== 3 ? 0 : 1);
3964 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
))
3965 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
3974 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
3981 static int tgsi_op2_s(struct r600_shader_ctx
*ctx
, int swap
, int trans_only
)
3983 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
3984 struct r600_bytecode_alu alu
;
3985 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
3986 int i
, j
, r
, lasti
= tgsi_last_instruction(write_mask
);
3987 /* use temp register if trans_only and more than one dst component */
3988 int use_tmp
= trans_only
&& (write_mask
^ (1 << lasti
));
3990 for (i
= 0; i
<= lasti
; i
++) {
3991 if (!(write_mask
& (1 << i
)))
3994 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
3996 alu
.dst
.sel
= ctx
->temp_reg
;
4000 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4002 alu
.op
= ctx
->inst_info
->op
;
4004 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4005 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
4008 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
4009 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4011 /* handle some special cases */
4012 switch (inst
->Instruction
.Opcode
) {
4013 case TGSI_OPCODE_SUB
:
4014 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
4016 case TGSI_OPCODE_ABS
:
4017 r600_bytecode_src_set_abs(&alu
.src
[0]);
4022 if (i
== lasti
|| trans_only
) {
4025 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4031 /* move result from temp to dst */
4032 for (i
= 0; i
<= lasti
; i
++) {
4033 if (!(write_mask
& (1 << i
)))
4036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4037 alu
.op
= ALU_OP1_MOV
;
4038 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4039 alu
.src
[0].sel
= ctx
->temp_reg
;
4040 alu
.src
[0].chan
= i
;
4041 alu
.last
= (i
== lasti
);
4043 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4051 static int tgsi_op2(struct r600_shader_ctx
*ctx
)
4053 return tgsi_op2_s(ctx
, 0, 0);
4056 static int tgsi_op2_swap(struct r600_shader_ctx
*ctx
)
4058 return tgsi_op2_s(ctx
, 1, 0);
4061 static int tgsi_op2_trans(struct r600_shader_ctx
*ctx
)
4063 return tgsi_op2_s(ctx
, 0, 1);
4066 static int tgsi_ineg(struct r600_shader_ctx
*ctx
)
4068 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4069 struct r600_bytecode_alu alu
;
4071 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4073 for (i
= 0; i
< lasti
+ 1; i
++) {
4075 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4077 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4078 alu
.op
= ctx
->inst_info
->op
;
4080 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4082 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4084 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4089 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4097 static int tgsi_dneg(struct r600_shader_ctx
*ctx
)
4099 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4100 struct r600_bytecode_alu alu
;
4102 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4104 for (i
= 0; i
< lasti
+ 1; i
++) {
4106 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4108 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4109 alu
.op
= ALU_OP1_MOV
;
4111 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4113 if (i
== 1 || i
== 3)
4114 r600_bytecode_src_toggle_neg(&alu
.src
[0]);
4115 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4120 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4128 static int tgsi_dfracexp(struct r600_shader_ctx
*ctx
)
4130 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4131 struct r600_bytecode_alu alu
;
4132 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
4134 int firsti
= write_mask
== 0xc ? 2 : 0;
4136 for (i
= 0; i
<= 3; i
++) {
4137 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4138 alu
.op
= ctx
->inst_info
->op
;
4140 alu
.dst
.sel
= ctx
->temp_reg
;
4143 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4144 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], fp64_switch(i
));
4150 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4155 /* MOV first two channels to writemask dst0 */
4156 for (i
= 0; i
<= 1; i
++) {
4157 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4158 alu
.op
= ALU_OP1_MOV
;
4159 alu
.src
[0].chan
= i
+ 2;
4160 alu
.src
[0].sel
= ctx
->temp_reg
;
4162 tgsi_dst(ctx
, &inst
->Dst
[0], firsti
+ i
, &alu
.dst
);
4163 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> (firsti
+ i
)) & 1;
4165 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4170 for (i
= 0; i
<= 3; i
++) {
4171 if (inst
->Dst
[1].Register
.WriteMask
& (1 << i
)) {
4172 /* MOV third channels to writemask dst1 */
4173 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4174 alu
.op
= ALU_OP1_MOV
;
4175 alu
.src
[0].chan
= 1;
4176 alu
.src
[0].sel
= ctx
->temp_reg
;
4178 tgsi_dst(ctx
, &inst
->Dst
[1], i
, &alu
.dst
);
4180 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4190 static int egcm_int_to_double(struct r600_shader_ctx
*ctx
)
4192 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4193 struct r600_bytecode_alu alu
;
4195 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4197 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_I2D
||
4198 inst
->Instruction
.Opcode
== TGSI_OPCODE_U2D
);
4200 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4202 alu
.op
= ctx
->inst_info
->op
;
4204 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
4205 alu
.dst
.sel
= ctx
->temp_reg
;
4210 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4215 for (i
= 0; i
<= lasti
; i
++) {
4216 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4217 alu
.op
= ALU_OP1_FLT32_TO_FLT64
;
4219 alu
.src
[0].chan
= i
/2;
4221 alu
.src
[0].sel
= ctx
->temp_reg
;
4223 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
4224 alu
.src
[0].value
= 0x0;
4226 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4227 alu
.last
= i
== lasti
;
4229 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4237 static int egcm_double_to_int(struct r600_shader_ctx
*ctx
)
4239 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4240 struct r600_bytecode_alu alu
;
4242 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4244 assert(inst
->Instruction
.Opcode
== TGSI_OPCODE_D2I
||
4245 inst
->Instruction
.Opcode
== TGSI_OPCODE_D2U
);
4247 for (i
= 0; i
<= lasti
; i
++) {
4248 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4249 alu
.op
= ALU_OP1_FLT64_TO_FLT32
;
4251 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], fp64_switch(i
));
4253 alu
.dst
.sel
= ctx
->temp_reg
;
4254 alu
.dst
.write
= i
%2 == 0;
4255 alu
.last
= i
== lasti
;
4257 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4262 for (i
= 0; i
<= (lasti
+1)/2; i
++) {
4263 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4264 alu
.op
= ctx
->inst_info
->op
;
4266 alu
.src
[0].chan
= i
*2;
4267 alu
.src
[0].sel
= ctx
->temp_reg
;
4268 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4271 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4279 static int cayman_emit_double_instr(struct r600_shader_ctx
*ctx
)
4281 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4283 struct r600_bytecode_alu alu
;
4285 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4286 int t1
= ctx
->temp_reg
;
4288 /* these have to write the result to X/Y by the looks of it */
4289 for (i
= 0 ; i
< last_slot
; i
++) {
4290 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4291 alu
.op
= ctx
->inst_info
->op
;
4293 /* should only be one src regs */
4294 assert (inst
->Instruction
.NumSrcRegs
== 1);
4296 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4297 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 0);
4299 /* RSQ should take the absolute value of src */
4300 if (ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DRSQ
||
4301 ctx
->parse
.FullToken
.FullInstruction
.Instruction
.Opcode
== TGSI_OPCODE_DSQRT
) {
4302 r600_bytecode_src_set_abs(&alu
.src
[1]);
4306 alu
.dst
.write
= (i
== 0 || i
== 1);
4308 if (ctx
->bc
->chip_class
!= CAYMAN
|| i
== last_slot
- 1)
4310 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4315 for (i
= 0 ; i
<= lasti
; i
++) {
4316 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4318 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4319 alu
.op
= ALU_OP1_MOV
;
4320 alu
.src
[0].sel
= t1
;
4321 alu
.src
[0].chan
= (i
== 0 || i
== 2) ? 0 : 1;
4322 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4326 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4333 static int cayman_emit_float_instr(struct r600_shader_ctx
*ctx
)
4335 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4337 struct r600_bytecode_alu alu
;
4338 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4340 for (i
= 0 ; i
< last_slot
; i
++) {
4341 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4342 alu
.op
= ctx
->inst_info
->op
;
4343 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4344 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], 0);
4346 /* RSQ should take the absolute value of src */
4347 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_RSQ
) {
4348 r600_bytecode_src_set_abs(&alu
.src
[j
]);
4351 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4352 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4354 if (i
== last_slot
- 1)
4356 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4363 static int cayman_mul_int_instr(struct r600_shader_ctx
*ctx
)
4365 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4367 struct r600_bytecode_alu alu
;
4368 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4369 int t1
= ctx
->temp_reg
;
4371 for (k
= 0; k
<= lasti
; k
++) {
4372 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << k
)))
4375 for (i
= 0 ; i
< 4; i
++) {
4376 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4377 alu
.op
= ctx
->inst_info
->op
;
4378 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4379 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
);
4383 alu
.dst
.write
= (i
== k
);
4386 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4392 for (i
= 0 ; i
<= lasti
; i
++) {
4393 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4395 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4396 alu
.op
= ALU_OP1_MOV
;
4397 alu
.src
[0].sel
= t1
;
4398 alu
.src
[0].chan
= i
;
4399 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4403 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4412 static int cayman_mul_double_instr(struct r600_shader_ctx
*ctx
)
4414 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4416 struct r600_bytecode_alu alu
;
4417 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4418 int t1
= ctx
->temp_reg
;
4420 for (k
= 0; k
< 2; k
++) {
4421 if (!(inst
->Dst
[0].Register
.WriteMask
& (0x3 << (k
* 2))))
4424 for (i
= 0; i
< 4; i
++) {
4425 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4426 alu
.op
= ctx
->inst_info
->op
;
4427 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
4428 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], k
* 2 + ((i
== 3) ? 0 : 1));;
4435 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4441 for (i
= 0; i
<= lasti
; i
++) {
4442 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4444 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4445 alu
.op
= ALU_OP1_MOV
;
4446 alu
.src
[0].sel
= t1
;
4447 alu
.src
[0].chan
= i
;
4448 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4452 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4461 * r600 - trunc to -PI..PI range
4462 * r700 - normalize by dividing by 2PI
4465 static int tgsi_setup_trig(struct r600_shader_ctx
*ctx
)
4467 static float half_inv_pi
= 1.0 /(3.1415926535 * 2);
4468 static float double_pi
= 3.1415926535 * 2;
4469 static float neg_pi
= -3.1415926535;
4472 struct r600_bytecode_alu alu
;
4474 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4475 alu
.op
= ALU_OP3_MULADD
;
4479 alu
.dst
.sel
= ctx
->temp_reg
;
4482 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4484 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4485 alu
.src
[1].chan
= 0;
4486 alu
.src
[1].value
= *(uint32_t *)&half_inv_pi
;
4487 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4488 alu
.src
[2].chan
= 0;
4490 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4494 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4495 alu
.op
= ALU_OP1_FRACT
;
4498 alu
.dst
.sel
= ctx
->temp_reg
;
4501 alu
.src
[0].sel
= ctx
->temp_reg
;
4502 alu
.src
[0].chan
= 0;
4504 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4508 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4509 alu
.op
= ALU_OP3_MULADD
;
4513 alu
.dst
.sel
= ctx
->temp_reg
;
4516 alu
.src
[0].sel
= ctx
->temp_reg
;
4517 alu
.src
[0].chan
= 0;
4519 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
4520 alu
.src
[1].chan
= 0;
4521 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
4522 alu
.src
[2].chan
= 0;
4524 if (ctx
->bc
->chip_class
== R600
) {
4525 alu
.src
[1].value
= *(uint32_t *)&double_pi
;
4526 alu
.src
[2].value
= *(uint32_t *)&neg_pi
;
4528 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4529 alu
.src
[2].sel
= V_SQ_ALU_SRC_0_5
;
4534 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4540 static int cayman_trig(struct r600_shader_ctx
*ctx
)
4542 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4543 struct r600_bytecode_alu alu
;
4544 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4547 r
= tgsi_setup_trig(ctx
);
4552 for (i
= 0; i
< last_slot
; i
++) {
4553 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4554 alu
.op
= ctx
->inst_info
->op
;
4557 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4558 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4560 alu
.src
[0].sel
= ctx
->temp_reg
;
4561 alu
.src
[0].chan
= 0;
4562 if (i
== last_slot
- 1)
4564 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4571 static int tgsi_trig(struct r600_shader_ctx
*ctx
)
4573 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4574 struct r600_bytecode_alu alu
;
4576 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
4578 r
= tgsi_setup_trig(ctx
);
4582 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4583 alu
.op
= ctx
->inst_info
->op
;
4585 alu
.dst
.sel
= ctx
->temp_reg
;
4588 alu
.src
[0].sel
= ctx
->temp_reg
;
4589 alu
.src
[0].chan
= 0;
4591 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4595 /* replicate result */
4596 for (i
= 0; i
< lasti
+ 1; i
++) {
4597 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
4600 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4601 alu
.op
= ALU_OP1_MOV
;
4603 alu
.src
[0].sel
= ctx
->temp_reg
;
4604 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4607 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4614 static int tgsi_scs(struct r600_shader_ctx
*ctx
)
4616 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4617 struct r600_bytecode_alu alu
;
4620 /* We'll only need the trig stuff if we are going to write to the
4621 * X or Y components of the destination vector.
4623 if (likely(inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_XY
)) {
4624 r
= tgsi_setup_trig(ctx
);
4630 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_X
) {
4631 if (ctx
->bc
->chip_class
== CAYMAN
) {
4632 for (i
= 0 ; i
< 3; i
++) {
4633 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4634 alu
.op
= ALU_OP1_COS
;
4635 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4641 alu
.src
[0].sel
= ctx
->temp_reg
;
4642 alu
.src
[0].chan
= 0;
4645 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4650 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4651 alu
.op
= ALU_OP1_COS
;
4652 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4654 alu
.src
[0].sel
= ctx
->temp_reg
;
4655 alu
.src
[0].chan
= 0;
4657 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4664 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Y
) {
4665 if (ctx
->bc
->chip_class
== CAYMAN
) {
4666 for (i
= 0 ; i
< 3; i
++) {
4667 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4668 alu
.op
= ALU_OP1_SIN
;
4669 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4674 alu
.src
[0].sel
= ctx
->temp_reg
;
4675 alu
.src
[0].chan
= 0;
4678 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4684 alu
.op
= ALU_OP1_SIN
;
4685 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
4687 alu
.src
[0].sel
= ctx
->temp_reg
;
4688 alu
.src
[0].chan
= 0;
4690 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4697 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_Z
) {
4698 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4700 alu
.op
= ALU_OP1_MOV
;
4702 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4704 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4705 alu
.src
[0].chan
= 0;
4709 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4715 if (inst
->Dst
[0].Register
.WriteMask
& TGSI_WRITEMASK_W
) {
4716 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4718 alu
.op
= ALU_OP1_MOV
;
4720 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
4722 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4723 alu
.src
[0].chan
= 0;
4727 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4735 static int tgsi_kill(struct r600_shader_ctx
*ctx
)
4737 const struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4738 struct r600_bytecode_alu alu
;
4741 for (i
= 0; i
< 4; i
++) {
4742 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4743 alu
.op
= ctx
->inst_info
->op
;
4747 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
4749 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_KILL
) {
4750 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
4753 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
4758 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4763 /* kill must be last in ALU */
4764 ctx
->bc
->force_add_cf
= 1;
4765 ctx
->shader
->uses_kill
= TRUE
;
4769 static int tgsi_lit(struct r600_shader_ctx
*ctx
)
4771 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4772 struct r600_bytecode_alu alu
;
4775 /* tmp.x = max(src.y, 0.0) */
4776 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4777 alu
.op
= ALU_OP2_MAX
;
4778 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 1);
4779 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4780 alu
.src
[1].chan
= 1;
4782 alu
.dst
.sel
= ctx
->temp_reg
;
4787 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4791 if (inst
->Dst
[0].Register
.WriteMask
& (1 << 2))
4797 if (ctx
->bc
->chip_class
== CAYMAN
) {
4798 for (i
= 0; i
< 3; i
++) {
4799 /* tmp.z = log(tmp.x) */
4800 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4801 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4802 alu
.src
[0].sel
= ctx
->temp_reg
;
4803 alu
.src
[0].chan
= 0;
4804 alu
.dst
.sel
= ctx
->temp_reg
;
4812 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4817 /* tmp.z = log(tmp.x) */
4818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4819 alu
.op
= ALU_OP1_LOG_CLAMPED
;
4820 alu
.src
[0].sel
= ctx
->temp_reg
;
4821 alu
.src
[0].chan
= 0;
4822 alu
.dst
.sel
= ctx
->temp_reg
;
4826 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4831 chan
= alu
.dst
.chan
;
4834 /* tmp.x = amd MUL_LIT(tmp.z, src.w, src.x ) */
4835 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4836 alu
.op
= ALU_OP3_MUL_LIT
;
4837 alu
.src
[0].sel
= sel
;
4838 alu
.src
[0].chan
= chan
;
4839 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], 3);
4840 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], 0);
4841 alu
.dst
.sel
= ctx
->temp_reg
;
4846 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4850 if (ctx
->bc
->chip_class
== CAYMAN
) {
4851 for (i
= 0; i
< 3; i
++) {
4852 /* dst.z = exp(tmp.x) */
4853 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4854 alu
.op
= ALU_OP1_EXP_IEEE
;
4855 alu
.src
[0].sel
= ctx
->temp_reg
;
4856 alu
.src
[0].chan
= 0;
4857 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4863 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4868 /* dst.z = exp(tmp.x) */
4869 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4870 alu
.op
= ALU_OP1_EXP_IEEE
;
4871 alu
.src
[0].sel
= ctx
->temp_reg
;
4872 alu
.src
[0].chan
= 0;
4873 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
4875 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4882 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4883 alu
.op
= ALU_OP1_MOV
;
4884 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
; /*1.0*/
4885 alu
.src
[0].chan
= 0;
4886 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
4887 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 0) & 1;
4888 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4892 /* dst.y = max(src.x, 0.0) */
4893 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4894 alu
.op
= ALU_OP2_MAX
;
4895 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
4896 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
; /*0.0*/
4897 alu
.src
[1].chan
= 0;
4898 tgsi_dst(ctx
, &inst
->Dst
[0], 1, &alu
.dst
);
4899 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 1) & 1;
4900 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4905 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4906 alu
.op
= ALU_OP1_MOV
;
4907 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
4908 alu
.src
[0].chan
= 0;
4909 tgsi_dst(ctx
, &inst
->Dst
[0], 3, &alu
.dst
);
4910 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> 3) & 1;
4912 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4919 static int tgsi_rsq(struct r600_shader_ctx
*ctx
)
4921 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4922 struct r600_bytecode_alu alu
;
4925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4928 * For state trackers other than OpenGL, we'll want to use
4929 * _RECIPSQRT_IEEE instead.
4931 alu
.op
= ALU_OP1_RECIPSQRT_CLAMPED
;
4933 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4934 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4935 r600_bytecode_src_set_abs(&alu
.src
[i
]);
4937 alu
.dst
.sel
= ctx
->temp_reg
;
4940 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4943 /* replicate result */
4944 return tgsi_helper_tempx_replicate(ctx
);
4947 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx
*ctx
)
4949 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4950 struct r600_bytecode_alu alu
;
4953 for (i
= 0; i
< 4; i
++) {
4954 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4955 alu
.src
[0].sel
= ctx
->temp_reg
;
4956 alu
.op
= ALU_OP1_MOV
;
4958 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
4959 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
4962 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4969 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx
*ctx
)
4971 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4972 struct r600_bytecode_alu alu
;
4975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4976 alu
.op
= ctx
->inst_info
->op
;
4977 for (i
= 0; i
< inst
->Instruction
.NumSrcRegs
; i
++) {
4978 r600_bytecode_src(&alu
.src
[i
], &ctx
->src
[i
], 0);
4980 alu
.dst
.sel
= ctx
->temp_reg
;
4983 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
4986 /* replicate result */
4987 return tgsi_helper_tempx_replicate(ctx
);
4990 static int cayman_pow(struct r600_shader_ctx
*ctx
)
4992 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
4994 struct r600_bytecode_alu alu
;
4995 int last_slot
= (inst
->Dst
[0].Register
.WriteMask
& 0x8) ? 4 : 3;
4997 for (i
= 0; i
< 3; i
++) {
4998 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
4999 alu
.op
= ALU_OP1_LOG_IEEE
;
5000 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5001 alu
.dst
.sel
= ctx
->temp_reg
;
5006 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5012 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5013 alu
.op
= ALU_OP2_MUL
;
5014 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5015 alu
.src
[1].sel
= ctx
->temp_reg
;
5016 alu
.dst
.sel
= ctx
->temp_reg
;
5019 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5023 for (i
= 0; i
< last_slot
; i
++) {
5024 /* POW(a,b) = EXP2(b * LOG2(a))*/
5025 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5026 alu
.op
= ALU_OP1_EXP_IEEE
;
5027 alu
.src
[0].sel
= ctx
->temp_reg
;
5029 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5030 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
5031 if (i
== last_slot
- 1)
5033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5040 static int tgsi_pow(struct r600_shader_ctx
*ctx
)
5042 struct r600_bytecode_alu alu
;
5046 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5047 alu
.op
= ALU_OP1_LOG_IEEE
;
5048 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
5049 alu
.dst
.sel
= ctx
->temp_reg
;
5052 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5056 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5057 alu
.op
= ALU_OP2_MUL
;
5058 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
5059 alu
.src
[1].sel
= ctx
->temp_reg
;
5060 alu
.dst
.sel
= ctx
->temp_reg
;
5063 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5066 /* POW(a,b) = EXP2(b * LOG2(a))*/
5067 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5068 alu
.op
= ALU_OP1_EXP_IEEE
;
5069 alu
.src
[0].sel
= ctx
->temp_reg
;
5070 alu
.dst
.sel
= ctx
->temp_reg
;
5073 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5076 return tgsi_helper_tempx_replicate(ctx
);
5079 static int tgsi_divmod(struct r600_shader_ctx
*ctx
, int mod
, int signed_op
)
5081 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5082 struct r600_bytecode_alu alu
;
5084 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5085 int tmp0
= ctx
->temp_reg
;
5086 int tmp1
= r600_get_temp(ctx
);
5087 int tmp2
= r600_get_temp(ctx
);
5088 int tmp3
= r600_get_temp(ctx
);
5091 * we need to represent src1 as src2*q + r, where q - quotient, r - remainder
5093 * 1. tmp0.x = rcp (src2) = 2^32/src2 + e, where e is rounding error
5094 * 2. tmp0.z = lo (tmp0.x * src2)
5095 * 3. tmp0.w = -tmp0.z
5096 * 4. tmp0.y = hi (tmp0.x * src2)
5097 * 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src2))
5098 * 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error
5099 * 7. tmp1.x = tmp0.x - tmp0.w
5100 * 8. tmp1.y = tmp0.x + tmp0.w
5101 * 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x)
5102 * 10. tmp0.z = hi(tmp0.x * src1) = q
5103 * 11. tmp0.y = lo (tmp0.z * src2) = src2*q = src1 - r
5105 * 12. tmp0.w = src1 - tmp0.y = r
5106 * 13. tmp1.x = tmp0.w >= src2 = r >= src2 (uint comparison)
5107 * 14. tmp1.y = src1 >= tmp0.y = r >= 0 (uint comparison)
5111 * 15. tmp1.z = tmp0.z + 1 = q + 1
5112 * 16. tmp1.w = tmp0.z - 1 = q - 1
5116 * 15. tmp1.z = tmp0.w - src2 = r - src2
5117 * 16. tmp1.w = tmp0.w + src2 = r + src2
5121 * 17. tmp1.x = tmp1.x & tmp1.y
5123 * DIV: 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z
5124 * MOD: 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z
5126 * 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z
5127 * 20. dst = src2==0 ? MAX_UINT : tmp0.z
5131 * Same as unsigned, using abs values of the operands,
5132 * and fixing the sign of the result in the end.
5135 for (i
= 0; i
< 4; i
++) {
5136 if (!(write_mask
& (1<<i
)))
5141 /* tmp2.x = -src0 */
5142 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5143 alu
.op
= ALU_OP2_SUB_INT
;
5149 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5151 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5154 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5157 /* tmp2.y = -src1 */
5158 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5159 alu
.op
= ALU_OP2_SUB_INT
;
5165 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5167 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5170 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5173 /* tmp2.z sign bit is set if src0 and src2 signs are different */
5174 /* it will be a sign of the quotient */
5177 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5178 alu
.op
= ALU_OP2_XOR_INT
;
5184 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5185 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5188 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5192 /* tmp2.x = |src0| */
5193 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5194 alu
.op
= ALU_OP3_CNDGE_INT
;
5201 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5202 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5203 alu
.src
[2].sel
= tmp2
;
5204 alu
.src
[2].chan
= 0;
5207 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5210 /* tmp2.y = |src1| */
5211 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5212 alu
.op
= ALU_OP3_CNDGE_INT
;
5219 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5220 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5221 alu
.src
[2].sel
= tmp2
;
5222 alu
.src
[2].chan
= 1;
5225 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5230 /* 1. tmp0.x = rcp_u (src2) = 2^32/src2 + e, where e is rounding error */
5231 if (ctx
->bc
->chip_class
== CAYMAN
) {
5232 /* tmp3.x = u2f(src2) */
5233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5234 alu
.op
= ALU_OP1_UINT_TO_FLT
;
5241 alu
.src
[0].sel
= tmp2
;
5242 alu
.src
[0].chan
= 1;
5244 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5248 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5251 /* tmp0.x = recip(tmp3.x) */
5252 for (j
= 0 ; j
< 3; j
++) {
5253 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5254 alu
.op
= ALU_OP1_RECIP_IEEE
;
5258 alu
.dst
.write
= (j
== 0);
5260 alu
.src
[0].sel
= tmp3
;
5261 alu
.src
[0].chan
= 0;
5265 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5269 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5270 alu
.op
= ALU_OP2_MUL
;
5272 alu
.src
[0].sel
= tmp0
;
5273 alu
.src
[0].chan
= 0;
5275 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
5276 alu
.src
[1].value
= 0x4f800000;
5281 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5285 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5286 alu
.op
= ALU_OP1_FLT_TO_UINT
;
5292 alu
.src
[0].sel
= tmp3
;
5293 alu
.src
[0].chan
= 0;
5296 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5300 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5301 alu
.op
= ALU_OP1_RECIP_UINT
;
5308 alu
.src
[0].sel
= tmp2
;
5309 alu
.src
[0].chan
= 1;
5311 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5315 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5319 /* 2. tmp0.z = lo (tmp0.x * src2) */
5320 if (ctx
->bc
->chip_class
== CAYMAN
) {
5321 for (j
= 0 ; j
< 4; j
++) {
5322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5323 alu
.op
= ALU_OP2_MULLO_UINT
;
5327 alu
.dst
.write
= (j
== 2);
5329 alu
.src
[0].sel
= tmp0
;
5330 alu
.src
[0].chan
= 0;
5332 alu
.src
[1].sel
= tmp2
;
5333 alu
.src
[1].chan
= 1;
5335 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5338 alu
.last
= (j
== 3);
5339 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5343 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5344 alu
.op
= ALU_OP2_MULLO_UINT
;
5350 alu
.src
[0].sel
= tmp0
;
5351 alu
.src
[0].chan
= 0;
5353 alu
.src
[1].sel
= tmp2
;
5354 alu
.src
[1].chan
= 1;
5356 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5360 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5364 /* 3. tmp0.w = -tmp0.z */
5365 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5366 alu
.op
= ALU_OP2_SUB_INT
;
5372 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5373 alu
.src
[1].sel
= tmp0
;
5374 alu
.src
[1].chan
= 2;
5377 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5380 /* 4. tmp0.y = hi (tmp0.x * src2) */
5381 if (ctx
->bc
->chip_class
== CAYMAN
) {
5382 for (j
= 0 ; j
< 4; j
++) {
5383 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5384 alu
.op
= ALU_OP2_MULHI_UINT
;
5388 alu
.dst
.write
= (j
== 1);
5390 alu
.src
[0].sel
= tmp0
;
5391 alu
.src
[0].chan
= 0;
5394 alu
.src
[1].sel
= tmp2
;
5395 alu
.src
[1].chan
= 1;
5397 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5399 alu
.last
= (j
== 3);
5400 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5404 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5405 alu
.op
= ALU_OP2_MULHI_UINT
;
5411 alu
.src
[0].sel
= tmp0
;
5412 alu
.src
[0].chan
= 0;
5415 alu
.src
[1].sel
= tmp2
;
5416 alu
.src
[1].chan
= 1;
5418 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5422 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5426 /* 5. tmp0.z = (tmp0.y == 0 ? tmp0.w : tmp0.z) = abs(lo(rcp*src)) */
5427 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5428 alu
.op
= ALU_OP3_CNDE_INT
;
5435 alu
.src
[0].sel
= tmp0
;
5436 alu
.src
[0].chan
= 1;
5437 alu
.src
[1].sel
= tmp0
;
5438 alu
.src
[1].chan
= 3;
5439 alu
.src
[2].sel
= tmp0
;
5440 alu
.src
[2].chan
= 2;
5443 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5446 /* 6. tmp0.w = hi (tmp0.z * tmp0.x) = e, rounding error */
5447 if (ctx
->bc
->chip_class
== CAYMAN
) {
5448 for (j
= 0 ; j
< 4; j
++) {
5449 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5450 alu
.op
= ALU_OP2_MULHI_UINT
;
5454 alu
.dst
.write
= (j
== 3);
5456 alu
.src
[0].sel
= tmp0
;
5457 alu
.src
[0].chan
= 2;
5459 alu
.src
[1].sel
= tmp0
;
5460 alu
.src
[1].chan
= 0;
5462 alu
.last
= (j
== 3);
5463 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5467 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5468 alu
.op
= ALU_OP2_MULHI_UINT
;
5474 alu
.src
[0].sel
= tmp0
;
5475 alu
.src
[0].chan
= 2;
5477 alu
.src
[1].sel
= tmp0
;
5478 alu
.src
[1].chan
= 0;
5481 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5485 /* 7. tmp1.x = tmp0.x - tmp0.w */
5486 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5487 alu
.op
= ALU_OP2_SUB_INT
;
5493 alu
.src
[0].sel
= tmp0
;
5494 alu
.src
[0].chan
= 0;
5495 alu
.src
[1].sel
= tmp0
;
5496 alu
.src
[1].chan
= 3;
5499 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5502 /* 8. tmp1.y = tmp0.x + tmp0.w */
5503 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5504 alu
.op
= ALU_OP2_ADD_INT
;
5510 alu
.src
[0].sel
= tmp0
;
5511 alu
.src
[0].chan
= 0;
5512 alu
.src
[1].sel
= tmp0
;
5513 alu
.src
[1].chan
= 3;
5516 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5519 /* 9. tmp0.x = (tmp0.y == 0 ? tmp1.y : tmp1.x) */
5520 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5521 alu
.op
= ALU_OP3_CNDE_INT
;
5528 alu
.src
[0].sel
= tmp0
;
5529 alu
.src
[0].chan
= 1;
5530 alu
.src
[1].sel
= tmp1
;
5531 alu
.src
[1].chan
= 1;
5532 alu
.src
[2].sel
= tmp1
;
5533 alu
.src
[2].chan
= 0;
5536 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5539 /* 10. tmp0.z = hi(tmp0.x * src1) = q */
5540 if (ctx
->bc
->chip_class
== CAYMAN
) {
5541 for (j
= 0 ; j
< 4; j
++) {
5542 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5543 alu
.op
= ALU_OP2_MULHI_UINT
;
5547 alu
.dst
.write
= (j
== 2);
5549 alu
.src
[0].sel
= tmp0
;
5550 alu
.src
[0].chan
= 0;
5553 alu
.src
[1].sel
= tmp2
;
5554 alu
.src
[1].chan
= 0;
5556 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5559 alu
.last
= (j
== 3);
5560 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5564 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5565 alu
.op
= ALU_OP2_MULHI_UINT
;
5571 alu
.src
[0].sel
= tmp0
;
5572 alu
.src
[0].chan
= 0;
5575 alu
.src
[1].sel
= tmp2
;
5576 alu
.src
[1].chan
= 0;
5578 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
5582 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5586 /* 11. tmp0.y = lo (src2 * tmp0.z) = src2*q = src1 - r */
5587 if (ctx
->bc
->chip_class
== CAYMAN
) {
5588 for (j
= 0 ; j
< 4; j
++) {
5589 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5590 alu
.op
= ALU_OP2_MULLO_UINT
;
5594 alu
.dst
.write
= (j
== 1);
5597 alu
.src
[0].sel
= tmp2
;
5598 alu
.src
[0].chan
= 1;
5600 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5603 alu
.src
[1].sel
= tmp0
;
5604 alu
.src
[1].chan
= 2;
5606 alu
.last
= (j
== 3);
5607 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5611 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5612 alu
.op
= ALU_OP2_MULLO_UINT
;
5619 alu
.src
[0].sel
= tmp2
;
5620 alu
.src
[0].chan
= 1;
5622 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
5625 alu
.src
[1].sel
= tmp0
;
5626 alu
.src
[1].chan
= 2;
5629 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5633 /* 12. tmp0.w = src1 - tmp0.y = r */
5634 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5635 alu
.op
= ALU_OP2_SUB_INT
;
5642 alu
.src
[0].sel
= tmp2
;
5643 alu
.src
[0].chan
= 0;
5645 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5648 alu
.src
[1].sel
= tmp0
;
5649 alu
.src
[1].chan
= 1;
5652 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5655 /* 13. tmp1.x = tmp0.w >= src2 = r >= src2 */
5656 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5657 alu
.op
= ALU_OP2_SETGE_UINT
;
5663 alu
.src
[0].sel
= tmp0
;
5664 alu
.src
[0].chan
= 3;
5666 alu
.src
[1].sel
= tmp2
;
5667 alu
.src
[1].chan
= 1;
5669 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5673 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5676 /* 14. tmp1.y = src1 >= tmp0.y = r >= 0 */
5677 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5678 alu
.op
= ALU_OP2_SETGE_UINT
;
5685 alu
.src
[0].sel
= tmp2
;
5686 alu
.src
[0].chan
= 0;
5688 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5691 alu
.src
[1].sel
= tmp0
;
5692 alu
.src
[1].chan
= 1;
5695 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5698 if (mod
) { /* UMOD */
5700 /* 15. tmp1.z = tmp0.w - src2 = r - src2 */
5701 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5702 alu
.op
= ALU_OP2_SUB_INT
;
5708 alu
.src
[0].sel
= tmp0
;
5709 alu
.src
[0].chan
= 3;
5712 alu
.src
[1].sel
= tmp2
;
5713 alu
.src
[1].chan
= 1;
5715 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5719 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5722 /* 16. tmp1.w = tmp0.w + src2 = r + src2 */
5723 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5724 alu
.op
= ALU_OP2_ADD_INT
;
5730 alu
.src
[0].sel
= tmp0
;
5731 alu
.src
[0].chan
= 3;
5733 alu
.src
[1].sel
= tmp2
;
5734 alu
.src
[1].chan
= 1;
5736 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
5740 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5745 /* 15. tmp1.z = tmp0.z + 1 = q + 1 DIV */
5746 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5747 alu
.op
= ALU_OP2_ADD_INT
;
5753 alu
.src
[0].sel
= tmp0
;
5754 alu
.src
[0].chan
= 2;
5755 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
5758 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5761 /* 16. tmp1.w = tmp0.z - 1 = q - 1 */
5762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5763 alu
.op
= ALU_OP2_ADD_INT
;
5769 alu
.src
[0].sel
= tmp0
;
5770 alu
.src
[0].chan
= 2;
5771 alu
.src
[1].sel
= V_SQ_ALU_SRC_M_1_INT
;
5774 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5779 /* 17. tmp1.x = tmp1.x & tmp1.y */
5780 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5781 alu
.op
= ALU_OP2_AND_INT
;
5787 alu
.src
[0].sel
= tmp1
;
5788 alu
.src
[0].chan
= 0;
5789 alu
.src
[1].sel
= tmp1
;
5790 alu
.src
[1].chan
= 1;
5793 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5796 /* 18. tmp0.z = tmp1.x==0 ? tmp0.z : tmp1.z DIV */
5797 /* 18. tmp0.z = tmp1.x==0 ? tmp0.w : tmp1.z MOD */
5798 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5799 alu
.op
= ALU_OP3_CNDE_INT
;
5806 alu
.src
[0].sel
= tmp1
;
5807 alu
.src
[0].chan
= 0;
5808 alu
.src
[1].sel
= tmp0
;
5809 alu
.src
[1].chan
= mod
? 3 : 2;
5810 alu
.src
[2].sel
= tmp1
;
5811 alu
.src
[2].chan
= 2;
5814 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5817 /* 19. tmp0.z = tmp1.y==0 ? tmp1.w : tmp0.z */
5818 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5819 alu
.op
= ALU_OP3_CNDE_INT
;
5827 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5830 alu
.src
[0].sel
= tmp1
;
5831 alu
.src
[0].chan
= 1;
5832 alu
.src
[1].sel
= tmp1
;
5833 alu
.src
[1].chan
= 3;
5834 alu
.src
[2].sel
= tmp0
;
5835 alu
.src
[2].chan
= 2;
5838 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5843 /* fix the sign of the result */
5847 /* tmp0.x = -tmp0.z */
5848 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5849 alu
.op
= ALU_OP2_SUB_INT
;
5855 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5856 alu
.src
[1].sel
= tmp0
;
5857 alu
.src
[1].chan
= 2;
5860 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5863 /* sign of the remainder is the same as the sign of src0 */
5864 /* tmp0.x = src0>=0 ? tmp0.z : tmp0.x */
5865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5866 alu
.op
= ALU_OP3_CNDGE_INT
;
5869 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5871 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5872 alu
.src
[1].sel
= tmp0
;
5873 alu
.src
[1].chan
= 2;
5874 alu
.src
[2].sel
= tmp0
;
5875 alu
.src
[2].chan
= 0;
5878 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5883 /* tmp0.x = -tmp0.z */
5884 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5885 alu
.op
= ALU_OP2_SUB_INT
;
5891 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
5892 alu
.src
[1].sel
= tmp0
;
5893 alu
.src
[1].chan
= 2;
5896 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5899 /* fix the quotient sign (same as the sign of src0*src1) */
5900 /* tmp0.x = tmp2.z>=0 ? tmp0.z : tmp0.x */
5901 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5902 alu
.op
= ALU_OP3_CNDGE_INT
;
5905 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5907 alu
.src
[0].sel
= tmp2
;
5908 alu
.src
[0].chan
= 2;
5909 alu
.src
[1].sel
= tmp0
;
5910 alu
.src
[1].chan
= 2;
5911 alu
.src
[2].sel
= tmp0
;
5912 alu
.src
[2].chan
= 0;
5915 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
5923 static int tgsi_udiv(struct r600_shader_ctx
*ctx
)
5925 return tgsi_divmod(ctx
, 0, 0);
5928 static int tgsi_umod(struct r600_shader_ctx
*ctx
)
5930 return tgsi_divmod(ctx
, 1, 0);
5933 static int tgsi_idiv(struct r600_shader_ctx
*ctx
)
5935 return tgsi_divmod(ctx
, 0, 1);
5938 static int tgsi_imod(struct r600_shader_ctx
*ctx
)
5940 return tgsi_divmod(ctx
, 1, 1);
5944 static int tgsi_f2i(struct r600_shader_ctx
*ctx
)
5946 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5947 struct r600_bytecode_alu alu
;
5949 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5950 int last_inst
= tgsi_last_instruction(write_mask
);
5952 for (i
= 0; i
< 4; i
++) {
5953 if (!(write_mask
& (1<<i
)))
5956 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5957 alu
.op
= ALU_OP1_TRUNC
;
5959 alu
.dst
.sel
= ctx
->temp_reg
;
5963 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
5966 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5971 for (i
= 0; i
< 4; i
++) {
5972 if (!(write_mask
& (1<<i
)))
5975 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
5976 alu
.op
= ctx
->inst_info
->op
;
5978 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
5980 alu
.src
[0].sel
= ctx
->temp_reg
;
5981 alu
.src
[0].chan
= i
;
5983 if (i
== last_inst
|| alu
.op
== ALU_OP1_FLT_TO_UINT
)
5985 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
5993 static int tgsi_iabs(struct r600_shader_ctx
*ctx
)
5995 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
5996 struct r600_bytecode_alu alu
;
5998 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
5999 int last_inst
= tgsi_last_instruction(write_mask
);
6002 for (i
= 0; i
< 4; i
++) {
6003 if (!(write_mask
& (1<<i
)))
6006 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6007 alu
.op
= ALU_OP2_SUB_INT
;
6009 alu
.dst
.sel
= ctx
->temp_reg
;
6013 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6014 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
6018 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6023 /* dst = (src >= 0 ? src : tmp) */
6024 for (i
= 0; i
< 4; i
++) {
6025 if (!(write_mask
& (1<<i
)))
6028 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6029 alu
.op
= ALU_OP3_CNDGE_INT
;
6033 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6035 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6036 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6037 alu
.src
[2].sel
= ctx
->temp_reg
;
6038 alu
.src
[2].chan
= i
;
6042 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6049 static int tgsi_issg(struct r600_shader_ctx
*ctx
)
6051 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6052 struct r600_bytecode_alu alu
;
6054 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6055 int last_inst
= tgsi_last_instruction(write_mask
);
6057 /* tmp = (src >= 0 ? src : -1) */
6058 for (i
= 0; i
< 4; i
++) {
6059 if (!(write_mask
& (1<<i
)))
6062 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6063 alu
.op
= ALU_OP3_CNDGE_INT
;
6066 alu
.dst
.sel
= ctx
->temp_reg
;
6070 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6071 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6072 alu
.src
[2].sel
= V_SQ_ALU_SRC_M_1_INT
;
6076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6081 /* dst = (tmp > 0 ? 1 : tmp) */
6082 for (i
= 0; i
< 4; i
++) {
6083 if (!(write_mask
& (1<<i
)))
6086 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6087 alu
.op
= ALU_OP3_CNDGT_INT
;
6091 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6093 alu
.src
[0].sel
= ctx
->temp_reg
;
6094 alu
.src
[0].chan
= i
;
6096 alu
.src
[1].sel
= V_SQ_ALU_SRC_1_INT
;
6098 alu
.src
[2].sel
= ctx
->temp_reg
;
6099 alu
.src
[2].chan
= i
;
6103 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6112 static int tgsi_ssg(struct r600_shader_ctx
*ctx
)
6114 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6115 struct r600_bytecode_alu alu
;
6118 /* tmp = (src > 0 ? 1 : src) */
6119 for (i
= 0; i
< 4; i
++) {
6120 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6121 alu
.op
= ALU_OP3_CNDGT
;
6124 alu
.dst
.sel
= ctx
->temp_reg
;
6127 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6128 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6129 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6133 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6138 /* dst = (-tmp > 0 ? -1 : tmp) */
6139 for (i
= 0; i
< 4; i
++) {
6140 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6141 alu
.op
= ALU_OP3_CNDGT
;
6143 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6145 alu
.src
[0].sel
= ctx
->temp_reg
;
6146 alu
.src
[0].chan
= i
;
6149 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
6152 alu
.src
[2].sel
= ctx
->temp_reg
;
6153 alu
.src
[2].chan
= i
;
6157 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6164 static int tgsi_bfi(struct r600_shader_ctx
*ctx
)
6166 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6167 struct r600_bytecode_alu alu
;
6170 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6171 int last_inst
= tgsi_last_instruction(write_mask
);
6175 for (i
= 0; i
< 4; i
++) {
6176 if (!(write_mask
& (1<<i
)))
6179 /* create mask tmp */
6180 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6181 alu
.op
= ALU_OP2_BFM_INT
;
6185 alu
.last
= i
== last_inst
;
6187 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[3], i
);
6188 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6190 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6195 t2
= r600_get_temp(ctx
);
6197 for (i
= 0; i
< 4; i
++) {
6198 if (!(write_mask
& (1<<i
)))
6201 /* shift insert left */
6202 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6203 alu
.op
= ALU_OP2_LSHL_INT
;
6207 alu
.last
= i
== last_inst
;
6209 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
6210 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
6212 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6217 for (i
= 0; i
< 4; i
++) {
6218 if (!(write_mask
& (1<<i
)))
6221 /* actual bitfield insert */
6222 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6223 alu
.op
= ALU_OP3_BFI_INT
;
6225 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6228 alu
.last
= i
== last_inst
;
6230 alu
.src
[0].sel
= t1
;
6231 alu
.src
[0].chan
= i
;
6232 alu
.src
[1].sel
= t2
;
6233 alu
.src
[1].chan
= i
;
6234 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[0], i
);
6236 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6244 static int tgsi_msb(struct r600_shader_ctx
*ctx
)
6246 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6247 struct r600_bytecode_alu alu
;
6250 unsigned write_mask
= inst
->Dst
[0].Register
.WriteMask
;
6251 int last_inst
= tgsi_last_instruction(write_mask
);
6253 assert(ctx
->inst_info
->op
== ALU_OP1_FFBH_INT
||
6254 ctx
->inst_info
->op
== ALU_OP1_FFBH_UINT
);
6258 /* bit position is indexed from lsb by TGSI, and from msb by the hardware */
6259 for (i
= 0; i
< 4; i
++) {
6260 if (!(write_mask
& (1<<i
)))
6263 /* t1 = FFBH_INT / FFBH_UINT */
6264 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6265 alu
.op
= ctx
->inst_info
->op
;
6269 alu
.last
= i
== last_inst
;
6271 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6273 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6278 t2
= r600_get_temp(ctx
);
6280 for (i
= 0; i
< 4; i
++) {
6281 if (!(write_mask
& (1<<i
)))
6285 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6286 alu
.op
= ALU_OP2_SUB_INT
;
6290 alu
.last
= i
== last_inst
;
6292 alu
.src
[0].sel
= V_SQ_ALU_SRC_LITERAL
;
6293 alu
.src
[0].value
= 31;
6294 alu
.src
[1].sel
= t1
;
6295 alu
.src
[1].chan
= i
;
6297 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6302 for (i
= 0; i
< 4; i
++) {
6303 if (!(write_mask
& (1<<i
)))
6306 /* result = t1 >= 0 ? t2 : t1 */
6307 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6308 alu
.op
= ALU_OP3_CNDGE_INT
;
6310 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6313 alu
.last
= i
== last_inst
;
6315 alu
.src
[0].sel
= t1
;
6316 alu
.src
[0].chan
= i
;
6317 alu
.src
[1].sel
= t2
;
6318 alu
.src
[1].chan
= i
;
6319 alu
.src
[2].sel
= t1
;
6320 alu
.src
[2].chan
= i
;
6322 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6330 static int tgsi_interp_egcm(struct r600_shader_ctx
*ctx
)
6332 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6333 struct r600_bytecode_alu alu
;
6334 int r
, i
= 0, k
, interp_gpr
, interp_base_chan
, tmp
, lasti
;
6338 assert(inst
->Src
[0].Register
.File
== TGSI_FILE_INPUT
);
6340 input
= inst
->Src
[0].Register
.Index
;
6342 /* Interpolators have been marked for use already by allocate_system_value_inputs */
6343 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6344 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6345 location
= TGSI_INTERPOLATE_LOC_CENTER
; /* sample offset will be added explicitly */
6348 location
= TGSI_INTERPOLATE_LOC_CENTROID
;
6351 k
= eg_get_interpolator_index(ctx
->shader
->input
[input
].interpolate
, location
);
6354 interp_gpr
= ctx
->eg_interpolators
[k
].ij_index
/ 2;
6355 interp_base_chan
= 2 * (ctx
->eg_interpolators
[k
].ij_index
% 2);
6357 /* NOTE: currently offset is not perspective correct */
6358 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6359 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6360 int sample_gpr
= -1;
6361 int gradientsH
, gradientsV
;
6362 struct r600_bytecode_tex tex
;
6364 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6365 sample_gpr
= load_sample_position(ctx
, &ctx
->src
[1], ctx
->src
[1].swizzle
[0]);
6368 gradientsH
= r600_get_temp(ctx
);
6369 gradientsV
= r600_get_temp(ctx
);
6370 for (i
= 0; i
< 2; i
++) {
6371 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
6372 tex
.op
= i
== 0 ? FETCH_OP_GET_GRADIENTS_H
: FETCH_OP_GET_GRADIENTS_V
;
6373 tex
.src_gpr
= interp_gpr
;
6374 tex
.src_sel_x
= interp_base_chan
+ 0;
6375 tex
.src_sel_y
= interp_base_chan
+ 1;
6378 tex
.dst_gpr
= i
== 0 ? gradientsH
: gradientsV
;
6383 tex
.inst_mod
= 1; // Use per pixel gradient calculation
6385 tex
.resource_id
= tex
.sampler_id
;
6386 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
6391 for (i
= 0; i
< 2; i
++) {
6392 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6393 alu
.op
= ALU_OP3_MULADD
;
6395 alu
.src
[0].sel
= gradientsH
;
6396 alu
.src
[0].chan
= i
;
6397 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6398 alu
.src
[1].sel
= sample_gpr
;
6399 alu
.src
[1].chan
= 2;
6402 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 0);
6404 alu
.src
[2].sel
= interp_gpr
;
6405 alu
.src
[2].chan
= interp_base_chan
+ i
;
6406 alu
.dst
.sel
= ctx
->temp_reg
;
6410 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6415 for (i
= 0; i
< 2; i
++) {
6416 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6417 alu
.op
= ALU_OP3_MULADD
;
6419 alu
.src
[0].sel
= gradientsV
;
6420 alu
.src
[0].chan
= i
;
6421 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6422 alu
.src
[1].sel
= sample_gpr
;
6423 alu
.src
[1].chan
= 3;
6426 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], 1);
6428 alu
.src
[2].sel
= ctx
->temp_reg
;
6429 alu
.src
[2].chan
= i
;
6430 alu
.dst
.sel
= ctx
->temp_reg
;
6434 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6440 tmp
= r600_get_temp(ctx
);
6441 for (i
= 0; i
< 8; i
++) {
6442 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6443 alu
.op
= i
< 4 ? ALU_OP2_INTERP_ZW
: ALU_OP2_INTERP_XY
;
6446 if ((i
> 1 && i
< 6)) {
6452 alu
.dst
.chan
= i
% 4;
6454 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_OFFSET
||
6455 inst
->Instruction
.Opcode
== TGSI_OPCODE_INTERP_SAMPLE
) {
6456 alu
.src
[0].sel
= ctx
->temp_reg
;
6457 alu
.src
[0].chan
= 1 - (i
% 2);
6459 alu
.src
[0].sel
= interp_gpr
;
6460 alu
.src
[0].chan
= interp_base_chan
+ 1 - (i
% 2);
6462 alu
.src
[1].sel
= V_SQ_ALU_SRC_PARAM_BASE
+ ctx
->shader
->input
[input
].lds_pos
;
6463 alu
.src
[1].chan
= 0;
6465 alu
.last
= i
% 4 == 3;
6466 alu
.bank_swizzle_force
= SQ_ALU_VEC_210
;
6468 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6473 // INTERP can't swizzle dst
6474 lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6475 for (i
= 0; i
<= lasti
; i
++) {
6476 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6479 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6480 alu
.op
= ALU_OP1_MOV
;
6481 alu
.src
[0].sel
= tmp
;
6482 alu
.src
[0].chan
= ctx
->src
[0].swizzle
[i
];
6483 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6485 alu
.last
= i
== lasti
;
6486 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6495 static int tgsi_helper_copy(struct r600_shader_ctx
*ctx
, struct tgsi_full_instruction
*inst
)
6497 struct r600_bytecode_alu alu
;
6500 for (i
= 0; i
< 4; i
++) {
6501 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6502 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
))) {
6503 alu
.op
= ALU_OP0_NOP
;
6506 alu
.op
= ALU_OP1_MOV
;
6507 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6508 alu
.src
[0].sel
= ctx
->temp_reg
;
6509 alu
.src
[0].chan
= i
;
6514 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6521 static int tgsi_make_src_for_op3(struct r600_shader_ctx
*ctx
,
6522 unsigned temp
, int chan
,
6523 struct r600_bytecode_alu_src
*bc_src
,
6524 const struct r600_shader_src
*shader_src
)
6526 struct r600_bytecode_alu alu
;
6529 r600_bytecode_src(bc_src
, shader_src
, chan
);
6531 /* op3 operands don't support abs modifier */
6533 assert(temp
!=0); /* we actually need the extra register, make sure it is allocated. */
6534 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6535 alu
.op
= ALU_OP1_MOV
;
6537 alu
.dst
.chan
= chan
;
6540 alu
.src
[0] = *bc_src
;
6541 alu
.last
= true; // sufficient?
6542 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6546 memset(bc_src
, 0, sizeof(*bc_src
));
6548 bc_src
->chan
= chan
;
6553 static int tgsi_op3(struct r600_shader_ctx
*ctx
)
6555 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6556 struct r600_bytecode_alu alu
;
6558 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6561 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6563 if (ctx
->src
[j
].abs
)
6564 temp_regs
[j
] = r600_get_temp(ctx
);
6566 for (i
= 0; i
< lasti
+ 1; i
++) {
6567 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6570 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6571 alu
.op
= ctx
->inst_info
->op
;
6572 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6573 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[j
], i
, &alu
.src
[j
], &ctx
->src
[j
]);
6578 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6585 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6592 static int tgsi_dp(struct r600_shader_ctx
*ctx
)
6594 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6595 struct r600_bytecode_alu alu
;
6598 for (i
= 0; i
< 4; i
++) {
6599 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6600 alu
.op
= ctx
->inst_info
->op
;
6601 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
6602 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
6605 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
6607 alu
.dst
.write
= (inst
->Dst
[0].Register
.WriteMask
>> i
) & 1;
6608 /* handle some special cases */
6609 switch (inst
->Instruction
.Opcode
) {
6610 case TGSI_OPCODE_DP2
:
6612 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6613 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6616 case TGSI_OPCODE_DP3
:
6618 alu
.src
[0].sel
= alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
6619 alu
.src
[0].chan
= alu
.src
[1].chan
= 0;
6622 case TGSI_OPCODE_DPH
:
6624 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6625 alu
.src
[0].chan
= 0;
6635 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6642 static inline boolean
tgsi_tex_src_requires_loading(struct r600_shader_ctx
*ctx
,
6645 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6646 return (inst
->Src
[index
].Register
.File
!= TGSI_FILE_TEMPORARY
&&
6647 inst
->Src
[index
].Register
.File
!= TGSI_FILE_INPUT
&&
6648 inst
->Src
[index
].Register
.File
!= TGSI_FILE_OUTPUT
) ||
6649 ctx
->src
[index
].neg
|| ctx
->src
[index
].abs
||
6650 (inst
->Src
[index
].Register
.File
== TGSI_FILE_INPUT
&& ctx
->type
== TGSI_PROCESSOR_GEOMETRY
);
6653 static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx
*ctx
,
6656 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6657 return ctx
->file_offset
[inst
->Src
[index
].Register
.File
] + inst
->Src
[index
].Register
.Index
;
6660 static int do_vtx_fetch_inst(struct r600_shader_ctx
*ctx
, boolean src_requires_loading
)
6662 struct r600_bytecode_vtx vtx
;
6663 struct r600_bytecode_alu alu
;
6664 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6666 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6668 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6669 if (src_requires_loading
) {
6670 for (i
= 0; i
< 4; i
++) {
6671 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6672 alu
.op
= ALU_OP1_MOV
;
6673 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
6674 alu
.dst
.sel
= ctx
->temp_reg
;
6679 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6683 src_gpr
= ctx
->temp_reg
;
6686 memset(&vtx
, 0, sizeof(vtx
));
6687 vtx
.op
= FETCH_OP_VFETCH
;
6688 vtx
.buffer_id
= id
+ R600_MAX_CONST_BUFFERS
;
6689 vtx
.fetch_type
= SQ_VTX_FETCH_NO_INDEX_OFFSET
;
6690 vtx
.src_gpr
= src_gpr
;
6691 vtx
.mega_fetch_count
= 16;
6692 vtx
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
6693 vtx
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7; /* SEL_X */
6694 vtx
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7; /* SEL_Y */
6695 vtx
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7; /* SEL_Z */
6696 vtx
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7; /* SEL_W */
6697 vtx
.use_const_fields
= 1;
6699 if ((r
= r600_bytecode_add_vtx(ctx
->bc
, &vtx
)))
6702 if (ctx
->bc
->chip_class
>= EVERGREEN
)
6705 for (i
= 0; i
< 4; i
++) {
6706 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
6707 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
6710 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6711 alu
.op
= ALU_OP2_AND_INT
;
6714 alu
.dst
.sel
= vtx
.dst_gpr
;
6717 alu
.src
[0].sel
= vtx
.dst_gpr
;
6718 alu
.src
[0].chan
= i
;
6720 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6721 alu
.src
[1].sel
+= (id
* 2);
6722 alu
.src
[1].chan
= i
% 4;
6723 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6727 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6732 if (inst
->Dst
[0].Register
.WriteMask
& 3) {
6733 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6734 alu
.op
= ALU_OP2_OR_INT
;
6737 alu
.dst
.sel
= vtx
.dst_gpr
;
6740 alu
.src
[0].sel
= vtx
.dst_gpr
;
6741 alu
.src
[0].chan
= 3;
6743 alu
.src
[1].sel
= R600_SHADER_BUFFER_INFO_SEL
+ (id
* 2) + 1;
6744 alu
.src
[1].chan
= 0;
6745 alu
.src
[1].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6748 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6755 static int r600_do_buffer_txq(struct r600_shader_ctx
*ctx
)
6757 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6758 struct r600_bytecode_alu alu
;
6760 int id
= tgsi_tex_get_src_gpr(ctx
, 1);
6762 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6763 alu
.op
= ALU_OP1_MOV
;
6764 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
6765 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
6766 /* channel 0 or 2 of each word */
6767 alu
.src
[0].sel
+= (id
/ 2);
6768 alu
.src
[0].chan
= (id
% 2) * 2;
6770 /* r600 we have them at channel 2 of the second dword */
6771 alu
.src
[0].sel
+= (id
* 2) + 1;
6772 alu
.src
[0].chan
= 1;
6774 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
6775 tgsi_dst(ctx
, &inst
->Dst
[0], 0, &alu
.dst
);
6777 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6783 static int tgsi_tex(struct r600_shader_ctx
*ctx
)
6785 static float one_point_five
= 1.5f
;
6786 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
6787 struct r600_bytecode_tex tex
;
6788 struct r600_bytecode_alu alu
;
6792 bool read_compressed_msaa
= ctx
->bc
->has_compressed_msaa_texturing
&&
6793 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6794 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_MSAA
||
6795 inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY_MSAA
);
6797 bool txf_add_offsets
= inst
->Texture
.NumOffsets
&&
6798 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
&&
6799 inst
->Texture
.Texture
!= TGSI_TEXTURE_BUFFER
;
6801 /* Texture fetch instructions can only use gprs as source.
6802 * Also they cannot negate the source or take the absolute value */
6803 const boolean src_requires_loading
= (inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
&&
6804 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQS
&&
6805 tgsi_tex_src_requires_loading(ctx
, 0)) ||
6806 read_compressed_msaa
|| txf_add_offsets
;
6808 boolean src_loaded
= FALSE
;
6809 unsigned sampler_src_reg
= inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
? 0 : 1;
6810 int8_t offset_x
= 0, offset_y
= 0, offset_z
= 0;
6811 boolean has_txq_cube_array_z
= false;
6812 unsigned sampler_index_mode
;
6814 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
&&
6815 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6816 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)))
6817 if (inst
->Dst
[0].Register
.WriteMask
& 4) {
6818 ctx
->shader
->has_txq_cube_array_z_comp
= true;
6819 has_txq_cube_array_z
= true;
6822 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TEX2
||
6823 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
6824 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
||
6825 inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
)
6826 sampler_src_reg
= 2;
6828 /* TGSI moves the sampler to src reg 3 for TXD */
6829 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
)
6830 sampler_src_reg
= 3;
6832 sampler_index_mode
= inst
->Src
[sampler_src_reg
].Indirect
.Index
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
6834 src_gpr
= tgsi_tex_get_src_gpr(ctx
, 0);
6836 if (inst
->Texture
.Texture
== TGSI_TEXTURE_BUFFER
) {
6837 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ
) {
6838 ctx
->shader
->uses_tex_buffers
= true;
6839 return r600_do_buffer_txq(ctx
);
6841 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXF
) {
6842 if (ctx
->bc
->chip_class
< EVERGREEN
)
6843 ctx
->shader
->uses_tex_buffers
= true;
6844 return do_vtx_fetch_inst(ctx
, src_requires_loading
);
6848 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXP
) {
6850 /* Add perspective divide */
6851 if (ctx
->bc
->chip_class
== CAYMAN
) {
6853 for (i
= 0; i
< 3; i
++) {
6854 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6855 alu
.op
= ALU_OP1_RECIP_IEEE
;
6856 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6858 alu
.dst
.sel
= ctx
->temp_reg
;
6864 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6871 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6872 alu
.op
= ALU_OP1_RECIP_IEEE
;
6873 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
6875 alu
.dst
.sel
= ctx
->temp_reg
;
6876 alu
.dst
.chan
= out_chan
;
6879 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6884 for (i
= 0; i
< 3; i
++) {
6885 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6886 alu
.op
= ALU_OP2_MUL
;
6887 alu
.src
[0].sel
= ctx
->temp_reg
;
6888 alu
.src
[0].chan
= out_chan
;
6889 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
6890 alu
.dst
.sel
= ctx
->temp_reg
;
6893 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6897 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6898 alu
.op
= ALU_OP1_MOV
;
6899 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
6900 alu
.src
[0].chan
= 0;
6901 alu
.dst
.sel
= ctx
->temp_reg
;
6905 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6909 src_gpr
= ctx
->temp_reg
;
6913 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
6914 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
6915 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
6916 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
6917 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ
&&
6918 inst
->Instruction
.Opcode
!= TGSI_OPCODE_TXQ_LZ
) {
6920 static const unsigned src0_swizzle
[] = {2, 2, 0, 1};
6921 static const unsigned src1_swizzle
[] = {1, 0, 2, 2};
6923 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
6924 for (i
= 0; i
< 4; i
++) {
6925 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6926 alu
.op
= ALU_OP2_CUBE
;
6927 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
6928 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], src1_swizzle
[i
]);
6929 alu
.dst
.sel
= ctx
->temp_reg
;
6934 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6939 /* tmp1.z = RCP_e(|tmp1.z|) */
6940 if (ctx
->bc
->chip_class
== CAYMAN
) {
6941 for (i
= 0; i
< 3; i
++) {
6942 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6943 alu
.op
= ALU_OP1_RECIP_IEEE
;
6944 alu
.src
[0].sel
= ctx
->temp_reg
;
6945 alu
.src
[0].chan
= 2;
6947 alu
.dst
.sel
= ctx
->temp_reg
;
6953 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6958 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6959 alu
.op
= ALU_OP1_RECIP_IEEE
;
6960 alu
.src
[0].sel
= ctx
->temp_reg
;
6961 alu
.src
[0].chan
= 2;
6963 alu
.dst
.sel
= ctx
->temp_reg
;
6967 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6972 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
6973 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
6974 * muladd has no writemask, have to use another temp
6976 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6977 alu
.op
= ALU_OP3_MULADD
;
6980 alu
.src
[0].sel
= ctx
->temp_reg
;
6981 alu
.src
[0].chan
= 0;
6982 alu
.src
[1].sel
= ctx
->temp_reg
;
6983 alu
.src
[1].chan
= 2;
6985 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
6986 alu
.src
[2].chan
= 0;
6987 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
6989 alu
.dst
.sel
= ctx
->temp_reg
;
6993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
6997 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
6998 alu
.op
= ALU_OP3_MULADD
;
7001 alu
.src
[0].sel
= ctx
->temp_reg
;
7002 alu
.src
[0].chan
= 1;
7003 alu
.src
[1].sel
= ctx
->temp_reg
;
7004 alu
.src
[1].chan
= 2;
7006 alu
.src
[2].sel
= V_SQ_ALU_SRC_LITERAL
;
7007 alu
.src
[2].chan
= 0;
7008 alu
.src
[2].value
= *(uint32_t *)&one_point_five
;
7010 alu
.dst
.sel
= ctx
->temp_reg
;
7015 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7018 /* write initial compare value into Z component
7019 - W src 0 for shadow cube
7020 - X src 1 for shadow cube array */
7021 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7022 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7023 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7024 alu
.op
= ALU_OP1_MOV
;
7025 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
)
7026 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7028 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7029 alu
.dst
.sel
= ctx
->temp_reg
;
7033 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7038 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7039 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7040 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7041 int mytmp
= r600_get_temp(ctx
);
7042 static const float eight
= 8.0f
;
7043 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7044 alu
.op
= ALU_OP1_MOV
;
7045 alu
.src
[0].sel
= ctx
->temp_reg
;
7046 alu
.src
[0].chan
= 3;
7047 alu
.dst
.sel
= mytmp
;
7051 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7055 /* have to multiply original layer by 8 and add to face id (temp.w) in Z */
7056 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7057 alu
.op
= ALU_OP3_MULADD
;
7059 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7060 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7061 alu
.src
[1].chan
= 0;
7062 alu
.src
[1].value
= *(uint32_t *)&eight
;
7063 alu
.src
[2].sel
= mytmp
;
7064 alu
.src
[2].chan
= 0;
7065 alu
.dst
.sel
= ctx
->temp_reg
;
7069 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7072 } else if (ctx
->bc
->chip_class
< EVERGREEN
) {
7073 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7074 tex
.op
= FETCH_OP_SET_CUBEMAP_INDEX
;
7075 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7076 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7077 tex
.src_gpr
= r600_get_temp(ctx
);
7082 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7083 tex
.coord_type_x
= 1;
7084 tex
.coord_type_y
= 1;
7085 tex
.coord_type_z
= 1;
7086 tex
.coord_type_w
= 1;
7087 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7088 alu
.op
= ALU_OP1_MOV
;
7089 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7090 alu
.dst
.sel
= tex
.src_gpr
;
7094 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7098 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7105 /* for cube forms of lod and bias we need to route things */
7106 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB
||
7107 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL
||
7108 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7109 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
) {
7110 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7111 alu
.op
= ALU_OP1_MOV
;
7112 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXB2
||
7113 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXL2
)
7114 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], 0);
7116 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 3);
7117 alu
.dst
.sel
= ctx
->temp_reg
;
7121 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7127 src_gpr
= ctx
->temp_reg
;
7130 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXD
) {
7131 int temp_h
= 0, temp_v
= 0;
7134 /* if we've already loaded the src (i.e. CUBE don't reload it). */
7135 if (src_loaded
== TRUE
)
7139 for (i
= start_val
; i
< 3; i
++) {
7140 int treg
= r600_get_temp(ctx
);
7149 for (j
= 0; j
< 4; j
++) {
7150 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7151 alu
.op
= ALU_OP1_MOV
;
7152 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[i
], j
);
7158 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7163 for (i
= 1; i
< 3; i
++) {
7164 /* set gradients h/v */
7165 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7166 tex
.op
= (i
== 1) ? FETCH_OP_SET_GRADIENTS_H
:
7167 FETCH_OP_SET_GRADIENTS_V
;
7168 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7169 tex
.sampler_index_mode
= sampler_index_mode
;
7170 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7171 tex
.resource_index_mode
= sampler_index_mode
;
7173 tex
.src_gpr
= (i
== 1) ? temp_h
: temp_v
;
7179 tex
.dst_gpr
= r600_get_temp(ctx
); /* just to avoid confusing the asm scheduler */
7180 tex
.dst_sel_x
= tex
.dst_sel_y
= tex
.dst_sel_z
= tex
.dst_sel_w
= 7;
7181 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
) {
7182 tex
.coord_type_x
= 1;
7183 tex
.coord_type_y
= 1;
7184 tex
.coord_type_z
= 1;
7185 tex
.coord_type_w
= 1;
7187 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7193 if (src_requires_loading
&& !src_loaded
) {
7194 for (i
= 0; i
< 4; i
++) {
7195 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7196 alu
.op
= ALU_OP1_MOV
;
7197 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7198 alu
.dst
.sel
= ctx
->temp_reg
;
7203 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7208 src_gpr
= ctx
->temp_reg
;
7211 /* get offset values */
7212 if (inst
->Texture
.NumOffsets
) {
7213 assert(inst
->Texture
.NumOffsets
== 1);
7215 /* The texture offset feature doesn't work with the TXF instruction
7216 * and must be emulated by adding the offset to the texture coordinates. */
7217 if (txf_add_offsets
) {
7218 const struct tgsi_texture_offset
*off
= inst
->TexOffsets
;
7220 switch (inst
->Texture
.Texture
) {
7221 case TGSI_TEXTURE_3D
:
7222 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7223 alu
.op
= ALU_OP2_ADD_INT
;
7224 alu
.src
[0].sel
= src_gpr
;
7225 alu
.src
[0].chan
= 2;
7226 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7227 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleZ
];
7228 alu
.dst
.sel
= src_gpr
;
7232 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7237 case TGSI_TEXTURE_2D
:
7238 case TGSI_TEXTURE_SHADOW2D
:
7239 case TGSI_TEXTURE_RECT
:
7240 case TGSI_TEXTURE_SHADOWRECT
:
7241 case TGSI_TEXTURE_2D_ARRAY
:
7242 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7243 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7244 alu
.op
= ALU_OP2_ADD_INT
;
7245 alu
.src
[0].sel
= src_gpr
;
7246 alu
.src
[0].chan
= 1;
7247 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7248 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleY
];
7249 alu
.dst
.sel
= src_gpr
;
7253 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7258 case TGSI_TEXTURE_1D
:
7259 case TGSI_TEXTURE_SHADOW1D
:
7260 case TGSI_TEXTURE_1D_ARRAY
:
7261 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7262 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7263 alu
.op
= ALU_OP2_ADD_INT
;
7264 alu
.src
[0].sel
= src_gpr
;
7265 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7266 alu
.src
[1].value
= ctx
->literals
[4 * off
[0].Index
+ off
[0].SwizzleX
];
7267 alu
.dst
.sel
= src_gpr
;
7270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7274 /* texture offsets do not apply to other texture targets */
7277 switch (inst
->Texture
.Texture
) {
7278 case TGSI_TEXTURE_3D
:
7279 offset_z
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleZ
] << 1;
7281 case TGSI_TEXTURE_2D
:
7282 case TGSI_TEXTURE_SHADOW2D
:
7283 case TGSI_TEXTURE_RECT
:
7284 case TGSI_TEXTURE_SHADOWRECT
:
7285 case TGSI_TEXTURE_2D_ARRAY
:
7286 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
7287 offset_y
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleY
] << 1;
7289 case TGSI_TEXTURE_1D
:
7290 case TGSI_TEXTURE_SHADOW1D
:
7291 case TGSI_TEXTURE_1D_ARRAY
:
7292 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
7293 offset_x
= ctx
->literals
[4 * inst
->TexOffsets
[0].Index
+ inst
->TexOffsets
[0].SwizzleX
] << 1;
7298 /* Obtain the sample index for reading a compressed MSAA color texture.
7299 * To read the FMASK, we use the ldfptr instruction, which tells us
7300 * where the samples are stored.
7301 * For uncompressed 8x MSAA surfaces, ldfptr should return 0x76543210,
7302 * which is the identity mapping. Each nibble says which physical sample
7303 * should be fetched to get that sample.
7305 * Assume src.z contains the sample index. It should be modified like this:
7306 * src.z = (ldfptr() >> (src.z * 4)) & 0xF;
7307 * Then fetch the texel with src.
7309 if (read_compressed_msaa
) {
7310 unsigned sample_chan
= 3;
7311 unsigned temp
= r600_get_temp(ctx
);
7314 /* temp.w = ldfptr() */
7315 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7316 tex
.op
= FETCH_OP_LD
;
7317 tex
.inst_mod
= 1; /* to indicate this is ldfptr */
7318 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7319 tex
.sampler_index_mode
= sampler_index_mode
;
7320 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7321 tex
.resource_index_mode
= sampler_index_mode
;
7322 tex
.src_gpr
= src_gpr
;
7324 tex
.dst_sel_x
= 7; /* mask out these components */
7327 tex
.dst_sel_w
= 0; /* store X */
7332 tex
.offset_x
= offset_x
;
7333 tex
.offset_y
= offset_y
;
7334 tex
.offset_z
= offset_z
;
7335 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7339 /* temp.x = sample_index*4 */
7340 if (ctx
->bc
->chip_class
== CAYMAN
) {
7341 for (i
= 0 ; i
< 4; i
++) {
7342 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7343 alu
.op
= ALU_OP2_MULLO_INT
;
7344 alu
.src
[0].sel
= src_gpr
;
7345 alu
.src
[0].chan
= sample_chan
;
7346 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7347 alu
.src
[1].value
= 4;
7350 alu
.dst
.write
= i
== 0;
7353 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7358 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7359 alu
.op
= ALU_OP2_MULLO_INT
;
7360 alu
.src
[0].sel
= src_gpr
;
7361 alu
.src
[0].chan
= sample_chan
;
7362 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7363 alu
.src
[1].value
= 4;
7368 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7373 /* sample_index = temp.w >> temp.x */
7374 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7375 alu
.op
= ALU_OP2_LSHR_INT
;
7376 alu
.src
[0].sel
= temp
;
7377 alu
.src
[0].chan
= 3;
7378 alu
.src
[1].sel
= temp
;
7379 alu
.src
[1].chan
= 0;
7380 alu
.dst
.sel
= src_gpr
;
7381 alu
.dst
.chan
= sample_chan
;
7384 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7388 /* sample_index & 0xF */
7389 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7390 alu
.op
= ALU_OP2_AND_INT
;
7391 alu
.src
[0].sel
= src_gpr
;
7392 alu
.src
[0].chan
= sample_chan
;
7393 alu
.src
[1].sel
= V_SQ_ALU_SRC_LITERAL
;
7394 alu
.src
[1].value
= 0xF;
7395 alu
.dst
.sel
= src_gpr
;
7396 alu
.dst
.chan
= sample_chan
;
7399 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7403 /* visualize the FMASK */
7404 for (i
= 0; i
< 4; i
++) {
7405 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7406 alu
.op
= ALU_OP1_INT_TO_FLT
;
7407 alu
.src
[0].sel
= src_gpr
;
7408 alu
.src
[0].chan
= sample_chan
;
7409 alu
.dst
.sel
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7413 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7421 /* does this shader want a num layers from TXQ for a cube array? */
7422 if (has_txq_cube_array_z
) {
7423 int id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7425 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7426 alu
.op
= ALU_OP1_MOV
;
7428 alu
.src
[0].sel
= R600_SHADER_BUFFER_INFO_SEL
;
7429 if (ctx
->bc
->chip_class
>= EVERGREEN
) {
7430 /* channel 1 or 3 of each word */
7431 alu
.src
[0].sel
+= (id
/ 2);
7432 alu
.src
[0].chan
= ((id
% 2) * 2) + 1;
7434 /* r600 we have them at channel 2 of the second dword */
7435 alu
.src
[0].sel
+= (id
* 2) + 1;
7436 alu
.src
[0].chan
= 2;
7438 alu
.src
[0].kc_bank
= R600_BUFFER_INFO_CONST_BUFFER
;
7439 tgsi_dst(ctx
, &inst
->Dst
[0], 2, &alu
.dst
);
7441 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7444 /* disable writemask from texture instruction */
7445 inst
->Dst
[0].Register
.WriteMask
&= ~4;
7448 opcode
= ctx
->inst_info
->op
;
7449 if (opcode
== FETCH_OP_GATHER4
&&
7450 inst
->TexOffsets
[0].File
!= TGSI_FILE_NULL
&&
7451 inst
->TexOffsets
[0].File
!= TGSI_FILE_IMMEDIATE
) {
7452 opcode
= FETCH_OP_GATHER4_O
;
7454 /* GATHER4_O/GATHER4_C_O use offset values loaded by
7455 SET_TEXTURE_OFFSETS instruction. The immediate offset values
7456 encoded in the instruction are ignored. */
7457 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7458 tex
.op
= FETCH_OP_SET_TEXTURE_OFFSETS
;
7459 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7460 tex
.sampler_index_mode
= sampler_index_mode
;
7461 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7462 tex
.resource_index_mode
= sampler_index_mode
;
7464 tex
.src_gpr
= ctx
->file_offset
[inst
->TexOffsets
[0].File
] + inst
->TexOffsets
[0].Index
;
7465 tex
.src_sel_x
= inst
->TexOffsets
[0].SwizzleX
;
7466 tex
.src_sel_y
= inst
->TexOffsets
[0].SwizzleY
;
7467 tex
.src_sel_z
= inst
->TexOffsets
[0].SwizzleZ
;
7475 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7480 if (inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7481 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7482 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7483 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7484 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
||
7485 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7486 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7488 case FETCH_OP_SAMPLE
:
7489 opcode
= FETCH_OP_SAMPLE_C
;
7491 case FETCH_OP_SAMPLE_L
:
7492 opcode
= FETCH_OP_SAMPLE_C_L
;
7494 case FETCH_OP_SAMPLE_LB
:
7495 opcode
= FETCH_OP_SAMPLE_C_LB
;
7497 case FETCH_OP_SAMPLE_G
:
7498 opcode
= FETCH_OP_SAMPLE_C_G
;
7500 /* Texture gather variants */
7501 case FETCH_OP_GATHER4
:
7502 opcode
= FETCH_OP_GATHER4_C
;
7504 case FETCH_OP_GATHER4_O
:
7505 opcode
= FETCH_OP_GATHER4_C_O
;
7510 memset(&tex
, 0, sizeof(struct r600_bytecode_tex
));
7513 tex
.sampler_id
= tgsi_tex_get_src_gpr(ctx
, sampler_src_reg
);
7514 tex
.sampler_index_mode
= sampler_index_mode
;
7515 tex
.resource_id
= tex
.sampler_id
+ R600_MAX_CONST_BUFFERS
;
7516 tex
.resource_index_mode
= sampler_index_mode
;
7517 tex
.src_gpr
= src_gpr
;
7518 tex
.dst_gpr
= ctx
->file_offset
[inst
->Dst
[0].Register
.File
] + inst
->Dst
[0].Register
.Index
;
7520 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_DDX_FINE
||
7521 inst
->Instruction
.Opcode
== TGSI_OPCODE_DDY_FINE
) {
7522 tex
.inst_mod
= 1; /* per pixel gradient calculation instead of per 2x2 quad */
7525 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
) {
7526 int8_t texture_component_select
= ctx
->literals
[4 * inst
->Src
[1].Register
.Index
+ inst
->Src
[1].Register
.SwizzleX
];
7527 tex
.inst_mod
= texture_component_select
;
7529 if (ctx
->bc
->chip_class
== CAYMAN
) {
7530 /* GATHER4 result order is different from TGSI TG4 */
7531 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 0 : 7;
7532 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 1 : 7;
7533 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 2 : 7;
7534 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7536 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7537 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7538 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7539 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7542 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_LODQ
) {
7543 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7544 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7548 else if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7555 tex
.dst_sel_x
= (inst
->Dst
[0].Register
.WriteMask
& 1) ? 0 : 7;
7556 tex
.dst_sel_y
= (inst
->Dst
[0].Register
.WriteMask
& 2) ? 1 : 7;
7557 tex
.dst_sel_z
= (inst
->Dst
[0].Register
.WriteMask
& 4) ? 2 : 7;
7558 tex
.dst_sel_w
= (inst
->Dst
[0].Register
.WriteMask
& 8) ? 3 : 7;
7562 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQ_LZ
||
7563 inst
->Instruction
.Opcode
== TGSI_OPCODE_TXQS
) {
7568 } else if (src_loaded
) {
7574 tex
.src_sel_x
= ctx
->src
[0].swizzle
[0];
7575 tex
.src_sel_y
= ctx
->src
[0].swizzle
[1];
7576 tex
.src_sel_z
= ctx
->src
[0].swizzle
[2];
7577 tex
.src_sel_w
= ctx
->src
[0].swizzle
[3];
7578 tex
.src_rel
= ctx
->src
[0].rel
;
7581 if (inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE
||
7582 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE
||
7583 inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7584 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) {
7588 tex
.src_sel_w
= 2; /* route Z compare or Lod value into W */
7591 if (inst
->Texture
.Texture
!= TGSI_TEXTURE_RECT
&&
7592 inst
->Texture
.Texture
!= TGSI_TEXTURE_SHADOWRECT
) {
7593 tex
.coord_type_x
= 1;
7594 tex
.coord_type_y
= 1;
7596 tex
.coord_type_z
= 1;
7597 tex
.coord_type_w
= 1;
7599 tex
.offset_x
= offset_x
;
7600 tex
.offset_y
= offset_y
;
7601 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_TG4
&&
7602 (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7603 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
)) {
7607 tex
.offset_z
= offset_z
;
7610 /* Put the depth for comparison in W.
7611 * TGSI_TEXTURE_SHADOW2D_ARRAY already has the depth in W.
7612 * Some instructions expect the depth in Z. */
7613 if ((inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D
||
7614 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D
||
7615 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWRECT
||
7616 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) &&
7617 opcode
!= FETCH_OP_SAMPLE_C_L
&&
7618 opcode
!= FETCH_OP_SAMPLE_C_LB
) {
7619 tex
.src_sel_w
= tex
.src_sel_z
;
7622 if (inst
->Texture
.Texture
== TGSI_TEXTURE_1D_ARRAY
||
7623 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW1D_ARRAY
) {
7624 if (opcode
== FETCH_OP_SAMPLE_C_L
||
7625 opcode
== FETCH_OP_SAMPLE_C_LB
) {
7626 /* the array index is read from Y */
7627 tex
.coord_type_y
= 0;
7629 /* the array index is read from Z */
7630 tex
.coord_type_z
= 0;
7631 tex
.src_sel_z
= tex
.src_sel_y
;
7633 } else if (inst
->Texture
.Texture
== TGSI_TEXTURE_2D_ARRAY
||
7634 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOW2D_ARRAY
||
7635 ((inst
->Texture
.Texture
== TGSI_TEXTURE_CUBE_ARRAY
||
7636 inst
->Texture
.Texture
== TGSI_TEXTURE_SHADOWCUBE_ARRAY
) &&
7637 (ctx
->bc
->chip_class
>= EVERGREEN
)))
7638 /* the array index is read from Z */
7639 tex
.coord_type_z
= 0;
7641 /* mask unused source components */
7642 if (opcode
== FETCH_OP_SAMPLE
|| opcode
== FETCH_OP_GATHER4
) {
7643 switch (inst
->Texture
.Texture
) {
7644 case TGSI_TEXTURE_2D
:
7645 case TGSI_TEXTURE_RECT
:
7649 case TGSI_TEXTURE_1D_ARRAY
:
7653 case TGSI_TEXTURE_1D
:
7661 r
= r600_bytecode_add_tex(ctx
->bc
, &tex
);
7665 /* add shadow ambient support - gallium doesn't do it yet */
7669 static int tgsi_lrp(struct r600_shader_ctx
*ctx
)
7671 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7672 struct r600_bytecode_alu alu
;
7673 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7674 unsigned i
, temp_regs
[2];
7677 /* optimize if it's just an equal balance */
7678 if (ctx
->src
[0].sel
== V_SQ_ALU_SRC_0_5
) {
7679 for (i
= 0; i
< lasti
+ 1; i
++) {
7680 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7683 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7684 alu
.op
= ALU_OP2_ADD
;
7685 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[1], i
);
7686 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7688 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7693 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7701 for (i
= 0; i
< lasti
+ 1; i
++) {
7702 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7705 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7706 alu
.op
= ALU_OP2_ADD
;
7707 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
7708 alu
.src
[0].chan
= 0;
7709 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[0], i
);
7710 r600_bytecode_src_toggle_neg(&alu
.src
[1]);
7711 alu
.dst
.sel
= ctx
->temp_reg
;
7717 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7722 /* (1 - src0) * src2 */
7723 for (i
= 0; i
< lasti
+ 1; i
++) {
7724 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7727 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7728 alu
.op
= ALU_OP2_MUL
;
7729 alu
.src
[0].sel
= ctx
->temp_reg
;
7730 alu
.src
[0].chan
= i
;
7731 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7732 alu
.dst
.sel
= ctx
->temp_reg
;
7738 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7743 /* src0 * src1 + (1 - src0) * src2 */
7744 if (ctx
->src
[0].abs
)
7745 temp_regs
[0] = r600_get_temp(ctx
);
7748 if (ctx
->src
[1].abs
)
7749 temp_regs
[1] = r600_get_temp(ctx
);
7753 for (i
= 0; i
< lasti
+ 1; i
++) {
7754 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7757 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7758 alu
.op
= ALU_OP3_MULADD
;
7760 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
7763 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[1], &ctx
->src
[1]);
7766 alu
.src
[2].sel
= ctx
->temp_reg
;
7767 alu
.src
[2].chan
= i
;
7769 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7774 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7781 static int tgsi_cmp(struct r600_shader_ctx
*ctx
)
7783 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7784 struct r600_bytecode_alu alu
;
7786 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7789 for (j
= 0; j
< inst
->Instruction
.NumSrcRegs
; j
++) {
7791 if (ctx
->src
[j
].abs
)
7792 temp_regs
[j
] = r600_get_temp(ctx
);
7795 for (i
= 0; i
< lasti
+ 1; i
++) {
7796 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7799 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7800 alu
.op
= ALU_OP3_CNDGE
;
7801 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[0], i
, &alu
.src
[0], &ctx
->src
[0]);
7804 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[2], i
, &alu
.src
[1], &ctx
->src
[2]);
7807 r
= tgsi_make_src_for_op3(ctx
, temp_regs
[1], i
, &alu
.src
[2], &ctx
->src
[1]);
7810 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7816 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7823 static int tgsi_ucmp(struct r600_shader_ctx
*ctx
)
7825 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7826 struct r600_bytecode_alu alu
;
7828 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
7830 for (i
= 0; i
< lasti
+ 1; i
++) {
7831 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
7834 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7835 alu
.op
= ALU_OP3_CNDE_INT
;
7836 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
7837 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
7838 r600_bytecode_src(&alu
.src
[2], &ctx
->src
[1], i
);
7839 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7845 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7852 static int tgsi_xpd(struct r600_shader_ctx
*ctx
)
7854 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7855 static const unsigned int src0_swizzle
[] = {2, 0, 1};
7856 static const unsigned int src1_swizzle
[] = {1, 2, 0};
7857 struct r600_bytecode_alu alu
;
7858 uint32_t use_temp
= 0;
7861 if (inst
->Dst
[0].Register
.WriteMask
!= 0xf)
7864 for (i
= 0; i
< 4; i
++) {
7865 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7866 alu
.op
= ALU_OP2_MUL
;
7868 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src0_swizzle
[i
]);
7869 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src1_swizzle
[i
]);
7871 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
7872 alu
.src
[0].chan
= i
;
7873 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7874 alu
.src
[1].chan
= i
;
7877 alu
.dst
.sel
= ctx
->temp_reg
;
7883 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7888 for (i
= 0; i
< 4; i
++) {
7889 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7890 alu
.op
= ALU_OP3_MULADD
;
7893 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], src1_swizzle
[i
]);
7894 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], src0_swizzle
[i
]);
7896 alu
.src
[0].sel
= V_SQ_ALU_SRC_0
;
7897 alu
.src
[0].chan
= i
;
7898 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
7899 alu
.src
[1].chan
= i
;
7902 alu
.src
[2].sel
= ctx
->temp_reg
;
7904 alu
.src
[2].chan
= i
;
7907 alu
.dst
.sel
= ctx
->temp_reg
;
7909 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7915 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7920 return tgsi_helper_copy(ctx
, inst
);
7924 static int tgsi_exp(struct r600_shader_ctx
*ctx
)
7926 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
7927 struct r600_bytecode_alu alu
;
7931 /* result.x = 2^floor(src); */
7932 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
7933 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7935 alu
.op
= ALU_OP1_FLOOR
;
7936 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7938 alu
.dst
.sel
= ctx
->temp_reg
;
7942 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7946 if (ctx
->bc
->chip_class
== CAYMAN
) {
7947 for (i
= 0; i
< 3; i
++) {
7948 alu
.op
= ALU_OP1_EXP_IEEE
;
7949 alu
.src
[0].sel
= ctx
->temp_reg
;
7950 alu
.src
[0].chan
= 0;
7952 alu
.dst
.sel
= ctx
->temp_reg
;
7954 alu
.dst
.write
= i
== 0;
7956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7961 alu
.op
= ALU_OP1_EXP_IEEE
;
7962 alu
.src
[0].sel
= ctx
->temp_reg
;
7963 alu
.src
[0].chan
= 0;
7965 alu
.dst
.sel
= ctx
->temp_reg
;
7969 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7975 /* result.y = tmp - floor(tmp); */
7976 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
7977 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
7979 alu
.op
= ALU_OP1_FRACT
;
7980 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
7982 alu
.dst
.sel
= ctx
->temp_reg
;
7984 r
= tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
7993 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
7998 /* result.z = RoughApprox2ToX(tmp);*/
7999 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 0x1) {
8000 if (ctx
->bc
->chip_class
== CAYMAN
) {
8001 for (i
= 0; i
< 3; i
++) {
8002 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8003 alu
.op
= ALU_OP1_EXP_IEEE
;
8004 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8006 alu
.dst
.sel
= ctx
->temp_reg
;
8013 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8018 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8019 alu
.op
= ALU_OP1_EXP_IEEE
;
8020 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8022 alu
.dst
.sel
= ctx
->temp_reg
;
8028 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8034 /* result.w = 1.0;*/
8035 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 0x1) {
8036 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8038 alu
.op
= ALU_OP1_MOV
;
8039 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8040 alu
.src
[0].chan
= 0;
8042 alu
.dst
.sel
= ctx
->temp_reg
;
8046 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8050 return tgsi_helper_copy(ctx
, inst
);
8053 static int tgsi_log(struct r600_shader_ctx
*ctx
)
8055 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8056 struct r600_bytecode_alu alu
;
8060 /* result.x = floor(log2(|src|)); */
8061 if (inst
->Dst
[0].Register
.WriteMask
& 1) {
8062 if (ctx
->bc
->chip_class
== CAYMAN
) {
8063 for (i
= 0; i
< 3; i
++) {
8064 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8066 alu
.op
= ALU_OP1_LOG_IEEE
;
8067 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8068 r600_bytecode_src_set_abs(&alu
.src
[0]);
8070 alu
.dst
.sel
= ctx
->temp_reg
;
8076 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8082 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8084 alu
.op
= ALU_OP1_LOG_IEEE
;
8085 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8086 r600_bytecode_src_set_abs(&alu
.src
[0]);
8088 alu
.dst
.sel
= ctx
->temp_reg
;
8092 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8097 alu
.op
= ALU_OP1_FLOOR
;
8098 alu
.src
[0].sel
= ctx
->temp_reg
;
8099 alu
.src
[0].chan
= 0;
8101 alu
.dst
.sel
= ctx
->temp_reg
;
8106 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8111 /* result.y = |src.x| / (2 ^ floor(log2(|src.x|))); */
8112 if ((inst
->Dst
[0].Register
.WriteMask
>> 1) & 1) {
8114 if (ctx
->bc
->chip_class
== CAYMAN
) {
8115 for (i
= 0; i
< 3; i
++) {
8116 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8118 alu
.op
= ALU_OP1_LOG_IEEE
;
8119 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8120 r600_bytecode_src_set_abs(&alu
.src
[0]);
8122 alu
.dst
.sel
= ctx
->temp_reg
;
8129 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8134 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8136 alu
.op
= ALU_OP1_LOG_IEEE
;
8137 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8138 r600_bytecode_src_set_abs(&alu
.src
[0]);
8140 alu
.dst
.sel
= ctx
->temp_reg
;
8145 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8150 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8152 alu
.op
= ALU_OP1_FLOOR
;
8153 alu
.src
[0].sel
= ctx
->temp_reg
;
8154 alu
.src
[0].chan
= 1;
8156 alu
.dst
.sel
= ctx
->temp_reg
;
8161 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8165 if (ctx
->bc
->chip_class
== CAYMAN
) {
8166 for (i
= 0; i
< 3; i
++) {
8167 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8168 alu
.op
= ALU_OP1_EXP_IEEE
;
8169 alu
.src
[0].sel
= ctx
->temp_reg
;
8170 alu
.src
[0].chan
= 1;
8172 alu
.dst
.sel
= ctx
->temp_reg
;
8179 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8184 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8185 alu
.op
= ALU_OP1_EXP_IEEE
;
8186 alu
.src
[0].sel
= ctx
->temp_reg
;
8187 alu
.src
[0].chan
= 1;
8189 alu
.dst
.sel
= ctx
->temp_reg
;
8194 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8199 if (ctx
->bc
->chip_class
== CAYMAN
) {
8200 for (i
= 0; i
< 3; i
++) {
8201 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8202 alu
.op
= ALU_OP1_RECIP_IEEE
;
8203 alu
.src
[0].sel
= ctx
->temp_reg
;
8204 alu
.src
[0].chan
= 1;
8206 alu
.dst
.sel
= ctx
->temp_reg
;
8213 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8218 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8219 alu
.op
= ALU_OP1_RECIP_IEEE
;
8220 alu
.src
[0].sel
= ctx
->temp_reg
;
8221 alu
.src
[0].chan
= 1;
8223 alu
.dst
.sel
= ctx
->temp_reg
;
8228 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8233 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8235 alu
.op
= ALU_OP2_MUL
;
8237 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8238 r600_bytecode_src_set_abs(&alu
.src
[0]);
8240 alu
.src
[1].sel
= ctx
->temp_reg
;
8241 alu
.src
[1].chan
= 1;
8243 alu
.dst
.sel
= ctx
->temp_reg
;
8248 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8253 /* result.z = log2(|src|);*/
8254 if ((inst
->Dst
[0].Register
.WriteMask
>> 2) & 1) {
8255 if (ctx
->bc
->chip_class
== CAYMAN
) {
8256 for (i
= 0; i
< 3; i
++) {
8257 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8259 alu
.op
= ALU_OP1_LOG_IEEE
;
8260 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8261 r600_bytecode_src_set_abs(&alu
.src
[0]);
8263 alu
.dst
.sel
= ctx
->temp_reg
;
8270 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8275 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8277 alu
.op
= ALU_OP1_LOG_IEEE
;
8278 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8279 r600_bytecode_src_set_abs(&alu
.src
[0]);
8281 alu
.dst
.sel
= ctx
->temp_reg
;
8286 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8292 /* result.w = 1.0; */
8293 if ((inst
->Dst
[0].Register
.WriteMask
>> 3) & 1) {
8294 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8296 alu
.op
= ALU_OP1_MOV
;
8297 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8298 alu
.src
[0].chan
= 0;
8300 alu
.dst
.sel
= ctx
->temp_reg
;
8305 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8310 return tgsi_helper_copy(ctx
, inst
);
8313 static int tgsi_eg_arl(struct r600_shader_ctx
*ctx
)
8315 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8316 struct r600_bytecode_alu alu
;
8318 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8319 unsigned reg
= get_address_file_reg(ctx
, inst
->Dst
[0].Register
.Index
);
8321 assert(inst
->Dst
[0].Register
.Index
< 3);
8322 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8324 switch (inst
->Instruction
.Opcode
) {
8325 case TGSI_OPCODE_ARL
:
8326 alu
.op
= ALU_OP1_FLT_TO_INT_FLOOR
;
8328 case TGSI_OPCODE_ARR
:
8329 alu
.op
= ALU_OP1_FLT_TO_INT
;
8331 case TGSI_OPCODE_UARL
:
8332 alu
.op
= ALU_OP1_MOV
;
8339 for (i
= 0; i
<= lasti
; ++i
) {
8340 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8342 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8343 alu
.last
= i
== lasti
;
8347 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8352 if (inst
->Dst
[0].Register
.Index
> 0)
8353 ctx
->bc
->index_loaded
[inst
->Dst
[0].Register
.Index
- 1] = 0;
8355 ctx
->bc
->ar_loaded
= 0;
8359 static int tgsi_r600_arl(struct r600_shader_ctx
*ctx
)
8361 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8362 struct r600_bytecode_alu alu
;
8364 int i
, lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8366 switch (inst
->Instruction
.Opcode
) {
8367 case TGSI_OPCODE_ARL
:
8368 memset(&alu
, 0, sizeof(alu
));
8369 alu
.op
= ALU_OP1_FLOOR
;
8370 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8372 for (i
= 0; i
<= lasti
; ++i
) {
8373 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8375 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8376 alu
.last
= i
== lasti
;
8377 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8382 memset(&alu
, 0, sizeof(alu
));
8383 alu
.op
= ALU_OP1_FLT_TO_INT
;
8384 alu
.src
[0].sel
= ctx
->bc
->ar_reg
;
8385 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8387 /* FLT_TO_INT is trans-only on r600/r700 */
8389 for (i
= 0; i
<= lasti
; ++i
) {
8391 alu
.src
[0].chan
= i
;
8392 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8396 case TGSI_OPCODE_ARR
:
8397 memset(&alu
, 0, sizeof(alu
));
8398 alu
.op
= ALU_OP1_FLT_TO_INT
;
8399 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8401 /* FLT_TO_INT is trans-only on r600/r700 */
8403 for (i
= 0; i
<= lasti
; ++i
) {
8404 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8406 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8407 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8412 case TGSI_OPCODE_UARL
:
8413 memset(&alu
, 0, sizeof(alu
));
8414 alu
.op
= ALU_OP1_MOV
;
8415 alu
.dst
.sel
= ctx
->bc
->ar_reg
;
8417 for (i
= 0; i
<= lasti
; ++i
) {
8418 if (inst
->Dst
[0].Register
.WriteMask
& (1 << i
)) {
8420 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8421 alu
.last
= i
== lasti
;
8422 if ((r
= r600_bytecode_add_alu(ctx
->bc
, &alu
)))
8432 ctx
->bc
->ar_loaded
= 0;
8436 static int tgsi_opdst(struct r600_shader_ctx
*ctx
)
8438 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8439 struct r600_bytecode_alu alu
;
8442 for (i
= 0; i
< 4; i
++) {
8443 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8445 alu
.op
= ALU_OP2_MUL
;
8446 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8448 if (i
== 0 || i
== 3) {
8449 alu
.src
[0].sel
= V_SQ_ALU_SRC_1
;
8451 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], i
);
8454 if (i
== 0 || i
== 2) {
8455 alu
.src
[1].sel
= V_SQ_ALU_SRC_1
;
8457 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[1], i
);
8461 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8468 static int emit_logic_pred(struct r600_shader_ctx
*ctx
, int opcode
, int alu_type
)
8470 struct r600_bytecode_alu alu
;
8473 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8475 alu
.execute_mask
= 1;
8476 alu
.update_pred
= 1;
8478 alu
.dst
.sel
= ctx
->temp_reg
;
8482 r600_bytecode_src(&alu
.src
[0], &ctx
->src
[0], 0);
8483 alu
.src
[1].sel
= V_SQ_ALU_SRC_0
;
8484 alu
.src
[1].chan
= 0;
8488 r
= r600_bytecode_add_alu_type(ctx
->bc
, &alu
, alu_type
);
8494 static int pops(struct r600_shader_ctx
*ctx
, int pops
)
8496 unsigned force_pop
= ctx
->bc
->force_add_cf
;
8500 if (ctx
->bc
->cf_last
) {
8501 if (ctx
->bc
->cf_last
->op
== CF_OP_ALU
)
8503 else if (ctx
->bc
->cf_last
->op
== CF_OP_ALU_POP_AFTER
)
8508 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP_AFTER
;
8509 ctx
->bc
->force_add_cf
= 1;
8510 } else if (alu_pop
== 2) {
8511 ctx
->bc
->cf_last
->op
= CF_OP_ALU_POP2_AFTER
;
8512 ctx
->bc
->force_add_cf
= 1;
8519 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_POP
);
8520 ctx
->bc
->cf_last
->pop_count
= pops
;
8521 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8527 static inline void callstack_update_max_depth(struct r600_shader_ctx
*ctx
,
8530 struct r600_stack_info
*stack
= &ctx
->bc
->stack
;
8531 unsigned elements
, entries
;
8533 unsigned entry_size
= stack
->entry_size
;
8535 elements
= (stack
->loop
+ stack
->push_wqm
) * entry_size
;
8536 elements
+= stack
->push
;
8538 switch (ctx
->bc
->chip_class
) {
8541 /* pre-r8xx: if any non-WQM PUSH instruction is invoked, 2 elements on
8542 * the stack must be reserved to hold the current active/continue
8544 if (reason
== FC_PUSH_VPM
) {
8550 /* r9xx: any stack operation on empty stack consumes 2 additional
8555 /* FIXME: do the two elements added above cover the cases for the
8559 /* r8xx+: 2 extra elements are not always required, but one extra
8560 * element must be added for each of the following cases:
8561 * 1. There is an ALU_ELSE_AFTER instruction at the point of greatest
8563 * (Currently we don't use ALU_ELSE_AFTER.)
8564 * 2. There are LOOP/WQM frames on the stack when any flavor of non-WQM
8565 * PUSH instruction executed.
8567 * NOTE: it seems we also need to reserve additional element in some
8568 * other cases, e.g. when we have 4 levels of PUSH_VPM in the shader,
8569 * then STACK_SIZE should be 2 instead of 1 */
8570 if (reason
== FC_PUSH_VPM
) {
8580 /* NOTE: it seems STACK_SIZE is interpreted by hw as if entry_size is 4
8581 * for all chips, so we use 4 in the final formula, not the real entry_size
8585 entries
= (elements
+ (entry_size
- 1)) / entry_size
;
8587 if (entries
> stack
->max_entries
)
8588 stack
->max_entries
= entries
;
8591 static inline void callstack_pop(struct r600_shader_ctx
*ctx
, unsigned reason
)
8595 --ctx
->bc
->stack
.push
;
8596 assert(ctx
->bc
->stack
.push
>= 0);
8599 --ctx
->bc
->stack
.push_wqm
;
8600 assert(ctx
->bc
->stack
.push_wqm
>= 0);
8603 --ctx
->bc
->stack
.loop
;
8604 assert(ctx
->bc
->stack
.loop
>= 0);
8612 static inline void callstack_push(struct r600_shader_ctx
*ctx
, unsigned reason
)
8616 ++ctx
->bc
->stack
.push
;
8619 ++ctx
->bc
->stack
.push_wqm
;
8621 ++ctx
->bc
->stack
.loop
;
8627 callstack_update_max_depth(ctx
, reason
);
8630 static void fc_set_mid(struct r600_shader_ctx
*ctx
, int fc_sp
)
8632 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[fc_sp
];
8634 sp
->mid
= realloc((void *)sp
->mid
,
8635 sizeof(struct r600_bytecode_cf
*) * (sp
->num_mid
+ 1));
8636 sp
->mid
[sp
->num_mid
] = ctx
->bc
->cf_last
;
8640 static void fc_pushlevel(struct r600_shader_ctx
*ctx
, int type
)
8643 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
= type
;
8644 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
= ctx
->bc
->cf_last
;
8647 static void fc_poplevel(struct r600_shader_ctx
*ctx
)
8649 struct r600_cf_stack_entry
*sp
= &ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
];
8659 static int emit_return(struct r600_shader_ctx
*ctx
)
8661 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_RETURN
));
8665 static int emit_jump_to_offset(struct r600_shader_ctx
*ctx
, int pops
, int offset
)
8668 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
));
8669 ctx
->bc
->cf_last
->pop_count
= pops
;
8670 /* XXX work out offset */
8674 static int emit_setret_in_loop_flag(struct r600_shader_ctx
*ctx
, unsigned flag_value
)
8679 static void emit_testflag(struct r600_shader_ctx
*ctx
)
8684 static void emit_return_on_flag(struct r600_shader_ctx
*ctx
, unsigned ifidx
)
8687 emit_jump_to_offset(ctx
, 1, 4);
8688 emit_setret_in_loop_flag(ctx
, V_SQ_ALU_SRC_0
);
8689 pops(ctx
, ifidx
+ 1);
8693 static void break_loop_on_flag(struct r600_shader_ctx
*ctx
, unsigned fc_sp
)
8697 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8698 ctx
->bc
->cf_last
->pop_count
= 1;
8700 fc_set_mid(ctx
, fc_sp
);
8706 static int emit_if(struct r600_shader_ctx
*ctx
, int opcode
)
8708 int alu_type
= CF_OP_ALU_PUSH_BEFORE
;
8710 /* There is a hardware bug on Cayman where a BREAK/CONTINUE followed by
8711 * LOOP_STARTxxx for nested loops may put the branch stack into a state
8712 * such that ALU_PUSH_BEFORE doesn't work as expected. Workaround this
8713 * by replacing the ALU_PUSH_BEFORE with a PUSH + ALU */
8714 if (ctx
->bc
->chip_class
== CAYMAN
&& ctx
->bc
->stack
.loop
> 1) {
8715 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_PUSH
);
8716 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8717 alu_type
= CF_OP_ALU
;
8720 emit_logic_pred(ctx
, opcode
, alu_type
);
8722 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_JUMP
);
8724 fc_pushlevel(ctx
, FC_IF
);
8726 callstack_push(ctx
, FC_PUSH_VPM
);
8730 static int tgsi_if(struct r600_shader_ctx
*ctx
)
8732 return emit_if(ctx
, ALU_OP2_PRED_SETNE
);
8735 static int tgsi_uif(struct r600_shader_ctx
*ctx
)
8737 return emit_if(ctx
, ALU_OP2_PRED_SETNE_INT
);
8740 static int tgsi_else(struct r600_shader_ctx
*ctx
)
8742 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_ELSE
);
8743 ctx
->bc
->cf_last
->pop_count
= 1;
8745 fc_set_mid(ctx
, ctx
->bc
->fc_sp
);
8746 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
;
8750 static int tgsi_endif(struct r600_shader_ctx
*ctx
)
8753 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_IF
) {
8754 R600_ERR("if/endif unbalanced in shader\n");
8758 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
== NULL
) {
8759 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8760 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->pop_count
= 1;
8762 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[0]->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8766 callstack_pop(ctx
, FC_PUSH_VPM
);
8770 static int tgsi_bgnloop(struct r600_shader_ctx
*ctx
)
8772 /* LOOP_START_DX10 ignores the LOOP_CONFIG* registers, so it is not
8773 * limited to 4096 iterations, like the other LOOP_* instructions. */
8774 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_START_DX10
);
8776 fc_pushlevel(ctx
, FC_LOOP
);
8778 /* check stack depth */
8779 callstack_push(ctx
, FC_LOOP
);
8783 static int tgsi_endloop(struct r600_shader_ctx
*ctx
)
8787 r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_END
);
8789 if (ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].type
!= FC_LOOP
) {
8790 R600_ERR("loop/endloop in shader code are not paired.\n");
8794 /* fixup loop pointers - from r600isa
8795 LOOP END points to CF after LOOP START,
8796 LOOP START point to CF after LOOP END
8797 BRK/CONT point to LOOP END CF
8799 ctx
->bc
->cf_last
->cf_addr
= ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->id
+ 2;
8801 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].start
->cf_addr
= ctx
->bc
->cf_last
->id
+ 2;
8803 for (i
= 0; i
< ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].num_mid
; i
++) {
8804 ctx
->bc
->fc_stack
[ctx
->bc
->fc_sp
].mid
[i
]->cf_addr
= ctx
->bc
->cf_last
->id
;
8806 /* XXX add LOOPRET support */
8808 callstack_pop(ctx
, FC_LOOP
);
8812 static int tgsi_loop_breakc(struct r600_shader_ctx
*ctx
)
8817 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
8819 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
8823 R600_ERR("BREAKC not inside loop/endloop pair\n");
8827 if (ctx
->bc
->chip_class
== EVERGREEN
&&
8828 ctx
->bc
->family
!= CHIP_CYPRESS
&&
8829 ctx
->bc
->family
!= CHIP_JUNIPER
) {
8830 /* HW bug: ALU_BREAK does not save the active mask correctly */
8835 r
= r600_bytecode_add_cfinst(ctx
->bc
, CF_OP_LOOP_BREAK
);
8838 fc_set_mid(ctx
, fscp
);
8840 return tgsi_endif(ctx
);
8842 r
= emit_logic_pred(ctx
, ALU_OP2_PRED_SETE_INT
, CF_OP_ALU_BREAK
);
8845 fc_set_mid(ctx
, fscp
);
8851 static int tgsi_loop_brk_cont(struct r600_shader_ctx
*ctx
)
8855 for (fscp
= ctx
->bc
->fc_sp
; fscp
> 0; fscp
--)
8857 if (FC_LOOP
== ctx
->bc
->fc_stack
[fscp
].type
)
8862 R600_ERR("Break not inside loop/endloop pair\n");
8866 r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8868 fc_set_mid(ctx
, fscp
);
8873 static int tgsi_gs_emit(struct r600_shader_ctx
*ctx
)
8875 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8876 int stream
= ctx
->literals
[inst
->Src
[0].Register
.Index
* 4 + inst
->Src
[0].Register
.SwizzleX
];
8879 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
8880 emit_gs_ring_writes(ctx
, ctx
->gs_stream_output_info
, stream
, TRUE
);
8882 r
= r600_bytecode_add_cfinst(ctx
->bc
, ctx
->inst_info
->op
);
8884 ctx
->bc
->cf_last
->count
= stream
; // Count field for CUT/EMIT_VERTEX indicates which stream
8885 if (ctx
->inst_info
->op
== CF_OP_EMIT_VERTEX
)
8886 return emit_inc_ring_offset(ctx
, stream
, TRUE
);
8891 static int tgsi_umad(struct r600_shader_ctx
*ctx
)
8893 struct tgsi_full_instruction
*inst
= &ctx
->parse
.FullToken
.FullInstruction
;
8894 struct r600_bytecode_alu alu
;
8896 int lasti
= tgsi_last_instruction(inst
->Dst
[0].Register
.WriteMask
);
8899 for (i
= 0; i
< lasti
+ 1; i
++) {
8900 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8903 if (ctx
->bc
->chip_class
== CAYMAN
) {
8904 for (j
= 0 ; j
< 4; j
++) {
8905 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8907 alu
.op
= ALU_OP2_MULLO_UINT
;
8908 for (k
= 0; k
< inst
->Instruction
.NumSrcRegs
; k
++) {
8909 r600_bytecode_src(&alu
.src
[k
], &ctx
->src
[k
], i
);
8912 alu
.dst
.sel
= ctx
->temp_reg
;
8913 alu
.dst
.write
= (j
== i
);
8916 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8921 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8924 alu
.dst
.sel
= ctx
->temp_reg
;
8927 alu
.op
= ALU_OP2_MULLO_UINT
;
8928 for (j
= 0; j
< 2; j
++) {
8929 r600_bytecode_src(&alu
.src
[j
], &ctx
->src
[j
], i
);
8933 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8940 for (i
= 0; i
< lasti
+ 1; i
++) {
8941 if (!(inst
->Dst
[0].Register
.WriteMask
& (1 << i
)))
8944 memset(&alu
, 0, sizeof(struct r600_bytecode_alu
));
8945 tgsi_dst(ctx
, &inst
->Dst
[0], i
, &alu
.dst
);
8947 alu
.op
= ALU_OP2_ADD_INT
;
8949 alu
.src
[0].sel
= ctx
->temp_reg
;
8950 alu
.src
[0].chan
= i
;
8952 r600_bytecode_src(&alu
.src
[1], &ctx
->src
[2], i
);
8956 r
= r600_bytecode_add_alu(ctx
->bc
, &alu
);
8963 static const struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction
[] = {
8964 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
8965 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
8966 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
8969 * For state trackers other than OpenGL, we'll want to use
8970 * _RECIP_IEEE instead.
8972 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_CLAMPED
, tgsi_trans_srcx_replicate
},
8974 [TGSI_OPCODE_RSQ
] = { ALU_OP0_NOP
, tgsi_rsq
},
8975 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
8976 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
8977 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
8978 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
8979 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
8980 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
8981 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
8982 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
8983 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
8984 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
8985 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
8986 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
8987 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
8988 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
8989 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8990 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
8991 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8992 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
8993 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
8994 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
8995 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
8996 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
8997 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
8998 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
8999 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9000 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9001 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
9002 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9003 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
9004 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9005 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
9006 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9007 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9008 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9009 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9010 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9011 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9012 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9013 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9014 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9015 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9016 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9017 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9018 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9019 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9020 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9021 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9022 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9023 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9024 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9025 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9026 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9027 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9028 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9029 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9030 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9031 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_r600_arl
},
9032 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9033 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9034 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9035 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9036 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9037 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
9038 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9039 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9040 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9041 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
9042 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9043 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9044 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9045 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9046 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9047 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9048 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9049 [TGSI_OPCODE_DDX_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9050 [TGSI_OPCODE_DDY_FINE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9051 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9052 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9053 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9054 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9055 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9056 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9057 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2_trans
},
9058 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9059 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9060 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9061 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9062 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9063 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9064 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9065 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9066 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9067 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9068 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9069 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9070 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9071 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9072 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9073 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9074 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9075 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
9076 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9077 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9078 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9079 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9080 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9081 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9082 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
9083 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9084 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9085 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_loop_breakc
},
9086 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9087 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9088 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
9089 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2_trans
},
9090 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9091 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9092 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9093 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9094 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9095 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2_trans
},
9096 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9097 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2_trans
},
9098 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9099 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9100 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9101 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9102 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9103 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9104 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9105 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9106 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9107 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9108 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2_trans
},
9109 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9110 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2_swap
},
9111 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9112 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9113 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9114 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9115 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9116 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9117 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9118 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9119 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9120 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9121 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9122 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9123 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9124 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9125 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9126 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9127 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_r600_arl
},
9128 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9129 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9130 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9131 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9132 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9133 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9134 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9135 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9136 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9137 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9138 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9139 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9140 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9141 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9142 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9143 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9144 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9145 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9146 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9147 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9148 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9149 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9150 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9151 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9152 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_unsupported
},
9153 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_unsupported
},
9154 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_unsupported
},
9155 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_unsupported
},
9156 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9157 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_unsupported
},
9158 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_unsupported
},
9159 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_unsupported
},
9160 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_unsupported
},
9161 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_unsupported
},
9162 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9163 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9164 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9165 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9168 static const struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction
[] = {
9169 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9170 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9171 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9172 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, tgsi_trans_srcx_replicate
},
9173 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, tgsi_rsq
},
9174 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9175 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9176 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
9177 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9178 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
9179 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
9180 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9181 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
9182 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
9183 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9184 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9185 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
9186 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
9187 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9188 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9189 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, tgsi_trans_srcx_replicate
},
9190 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9191 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9192 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9193 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9194 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9195 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9196 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9197 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, tgsi_trans_srcx_replicate
},
9198 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, tgsi_trans_srcx_replicate
},
9199 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, tgsi_pow
},
9200 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
9201 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9202 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
9203 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9204 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
9205 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, tgsi_trig
},
9206 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9207 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9208 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9209 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9210 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9211 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9212 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9213 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9214 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9215 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9216 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9217 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, tgsi_trig
},
9218 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9219 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9220 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9221 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9222 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9223 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9224 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9225 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9226 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9227 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9228 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9229 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9230 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9231 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9232 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9233 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9234 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9235 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9236 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
9237 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9238 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9239 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9240 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
9241 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9242 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9243 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9244 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9245 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9246 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9247 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9248 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9249 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9250 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9251 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9252 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9253 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2_trans
},
9254 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9255 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9256 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9257 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9258 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9259 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9260 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9261 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9262 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9263 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9264 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9265 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9266 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9267 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9268 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9269 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9270 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9271 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9272 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9273 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9274 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
9275 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9276 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9277 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9278 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9279 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9280 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9281 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
9282 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9283 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9284 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9285 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9286 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9287 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
9288 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_f2i
},
9289 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9290 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9291 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9292 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9293 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9294 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9295 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9296 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_f2i
},
9297 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2_trans
},
9298 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9299 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9300 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9301 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9302 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9303 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9304 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_UINT
, tgsi_op2_trans
},
9305 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9306 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9307 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9308 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9309 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9310 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9311 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9312 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9313 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9314 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9315 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9316 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9317 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9318 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9319 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9320 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9321 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9322 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9323 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9324 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9325 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9326 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
9327 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9328 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9329 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9330 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9331 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9332 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9333 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9334 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9335 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9336 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9337 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9338 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9339 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9340 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9341 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9342 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9343 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9344 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9345 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9346 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9347 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9348 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9349 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, tgsi_op2_trans
},
9350 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, tgsi_op2_trans
},
9351 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
9352 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
9353 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_op3
},
9354 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_op3
},
9355 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
9356 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
9357 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
9358 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
9359 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
9360 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
9361 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9362 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9363 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9364 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
9365 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
9366 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
9367 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
9368 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
9369 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
9370 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
9371 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
9372 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
9373 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
9374 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
9375 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
9376 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
9377 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
9378 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9379 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
9380 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
9381 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
9382 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
9383 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
9384 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
9385 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
9386 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
9387 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9390 static const struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction
[] = {
9391 [TGSI_OPCODE_ARL
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9392 [TGSI_OPCODE_MOV
] = { ALU_OP1_MOV
, tgsi_op2
},
9393 [TGSI_OPCODE_LIT
] = { ALU_OP0_NOP
, tgsi_lit
},
9394 [TGSI_OPCODE_RCP
] = { ALU_OP1_RECIP_IEEE
, cayman_emit_float_instr
},
9395 [TGSI_OPCODE_RSQ
] = { ALU_OP1_RECIPSQRT_IEEE
, cayman_emit_float_instr
},
9396 [TGSI_OPCODE_EXP
] = { ALU_OP0_NOP
, tgsi_exp
},
9397 [TGSI_OPCODE_LOG
] = { ALU_OP0_NOP
, tgsi_log
},
9398 [TGSI_OPCODE_MUL
] = { ALU_OP2_MUL
, tgsi_op2
},
9399 [TGSI_OPCODE_ADD
] = { ALU_OP2_ADD
, tgsi_op2
},
9400 [TGSI_OPCODE_DP3
] = { ALU_OP2_DOT4
, tgsi_dp
},
9401 [TGSI_OPCODE_DP4
] = { ALU_OP2_DOT4
, tgsi_dp
},
9402 [TGSI_OPCODE_DST
] = { ALU_OP0_NOP
, tgsi_opdst
},
9403 [TGSI_OPCODE_MIN
] = { ALU_OP2_MIN
, tgsi_op2
},
9404 [TGSI_OPCODE_MAX
] = { ALU_OP2_MAX
, tgsi_op2
},
9405 [TGSI_OPCODE_SLT
] = { ALU_OP2_SETGT
, tgsi_op2_swap
},
9406 [TGSI_OPCODE_SGE
] = { ALU_OP2_SETGE
, tgsi_op2
},
9407 [TGSI_OPCODE_MAD
] = { ALU_OP3_MULADD
, tgsi_op3
},
9408 [TGSI_OPCODE_SUB
] = { ALU_OP2_ADD
, tgsi_op2
},
9409 [TGSI_OPCODE_LRP
] = { ALU_OP0_NOP
, tgsi_lrp
},
9410 [TGSI_OPCODE_FMA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9411 [TGSI_OPCODE_SQRT
] = { ALU_OP1_SQRT_IEEE
, cayman_emit_float_instr
},
9412 [TGSI_OPCODE_DP2A
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9413 [22] = { ALU_OP0_NOP
, tgsi_unsupported
},
9414 [23] = { ALU_OP0_NOP
, tgsi_unsupported
},
9415 [TGSI_OPCODE_FRC
] = { ALU_OP1_FRACT
, tgsi_op2
},
9416 [TGSI_OPCODE_CLAMP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9417 [TGSI_OPCODE_FLR
] = { ALU_OP1_FLOOR
, tgsi_op2
},
9418 [TGSI_OPCODE_ROUND
] = { ALU_OP1_RNDNE
, tgsi_op2
},
9419 [TGSI_OPCODE_EX2
] = { ALU_OP1_EXP_IEEE
, cayman_emit_float_instr
},
9420 [TGSI_OPCODE_LG2
] = { ALU_OP1_LOG_IEEE
, cayman_emit_float_instr
},
9421 [TGSI_OPCODE_POW
] = { ALU_OP0_NOP
, cayman_pow
},
9422 [TGSI_OPCODE_XPD
] = { ALU_OP0_NOP
, tgsi_xpd
},
9423 [32] = { ALU_OP0_NOP
, tgsi_unsupported
},
9424 [TGSI_OPCODE_ABS
] = { ALU_OP1_MOV
, tgsi_op2
},
9425 [34] = { ALU_OP0_NOP
, tgsi_unsupported
},
9426 [TGSI_OPCODE_DPH
] = { ALU_OP2_DOT4
, tgsi_dp
},
9427 [TGSI_OPCODE_COS
] = { ALU_OP1_COS
, cayman_trig
},
9428 [TGSI_OPCODE_DDX
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9429 [TGSI_OPCODE_DDY
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9430 [TGSI_OPCODE_KILL
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* unconditional kill */
9431 [TGSI_OPCODE_PK2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9432 [TGSI_OPCODE_PK2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9433 [TGSI_OPCODE_PK4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9434 [TGSI_OPCODE_PK4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9435 [44] = { ALU_OP0_NOP
, tgsi_unsupported
},
9436 [TGSI_OPCODE_SEQ
] = { ALU_OP2_SETE
, tgsi_op2
},
9437 [46] = { ALU_OP0_NOP
, tgsi_unsupported
},
9438 [TGSI_OPCODE_SGT
] = { ALU_OP2_SETGT
, tgsi_op2
},
9439 [TGSI_OPCODE_SIN
] = { ALU_OP1_SIN
, cayman_trig
},
9440 [TGSI_OPCODE_SLE
] = { ALU_OP2_SETGE
, tgsi_op2_swap
},
9441 [TGSI_OPCODE_SNE
] = { ALU_OP2_SETNE
, tgsi_op2
},
9442 [51] = { ALU_OP0_NOP
, tgsi_unsupported
},
9443 [TGSI_OPCODE_TEX
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9444 [TGSI_OPCODE_TXD
] = { FETCH_OP_SAMPLE_G
, tgsi_tex
},
9445 [TGSI_OPCODE_TXP
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9446 [TGSI_OPCODE_UP2H
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9447 [TGSI_OPCODE_UP2US
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9448 [TGSI_OPCODE_UP4B
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9449 [TGSI_OPCODE_UP4UB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9450 [59] = { ALU_OP0_NOP
, tgsi_unsupported
},
9451 [60] = { ALU_OP0_NOP
, tgsi_unsupported
},
9452 [TGSI_OPCODE_ARR
] = { ALU_OP0_NOP
, tgsi_eg_arl
},
9453 [62] = { ALU_OP0_NOP
, tgsi_unsupported
},
9454 [TGSI_OPCODE_CAL
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9455 [TGSI_OPCODE_RET
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9456 [TGSI_OPCODE_SSG
] = { ALU_OP0_NOP
, tgsi_ssg
},
9457 [TGSI_OPCODE_CMP
] = { ALU_OP0_NOP
, tgsi_cmp
},
9458 [TGSI_OPCODE_SCS
] = { ALU_OP0_NOP
, tgsi_scs
},
9459 [TGSI_OPCODE_TXB
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9460 [69] = { ALU_OP0_NOP
, tgsi_unsupported
},
9461 [TGSI_OPCODE_DIV
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9462 [TGSI_OPCODE_DP2
] = { ALU_OP2_DOT4
, tgsi_dp
},
9463 [TGSI_OPCODE_TXL
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9464 [TGSI_OPCODE_BRK
] = { CF_OP_LOOP_BREAK
, tgsi_loop_brk_cont
},
9465 [TGSI_OPCODE_IF
] = { ALU_OP0_NOP
, tgsi_if
},
9466 [TGSI_OPCODE_UIF
] = { ALU_OP0_NOP
, tgsi_uif
},
9467 [76] = { ALU_OP0_NOP
, tgsi_unsupported
},
9468 [TGSI_OPCODE_ELSE
] = { ALU_OP0_NOP
, tgsi_else
},
9469 [TGSI_OPCODE_ENDIF
] = { ALU_OP0_NOP
, tgsi_endif
},
9470 [TGSI_OPCODE_DDX_FINE
] = { FETCH_OP_GET_GRADIENTS_H
, tgsi_tex
},
9471 [TGSI_OPCODE_DDY_FINE
] = { FETCH_OP_GET_GRADIENTS_V
, tgsi_tex
},
9472 [TGSI_OPCODE_PUSHA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9473 [TGSI_OPCODE_POPA
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9474 [TGSI_OPCODE_CEIL
] = { ALU_OP1_CEIL
, tgsi_op2
},
9475 [TGSI_OPCODE_I2F
] = { ALU_OP1_INT_TO_FLT
, tgsi_op2
},
9476 [TGSI_OPCODE_NOT
] = { ALU_OP1_NOT_INT
, tgsi_op2
},
9477 [TGSI_OPCODE_TRUNC
] = { ALU_OP1_TRUNC
, tgsi_op2
},
9478 [TGSI_OPCODE_SHL
] = { ALU_OP2_LSHL_INT
, tgsi_op2
},
9479 [88] = { ALU_OP0_NOP
, tgsi_unsupported
},
9480 [TGSI_OPCODE_AND
] = { ALU_OP2_AND_INT
, tgsi_op2
},
9481 [TGSI_OPCODE_OR
] = { ALU_OP2_OR_INT
, tgsi_op2
},
9482 [TGSI_OPCODE_MOD
] = { ALU_OP0_NOP
, tgsi_imod
},
9483 [TGSI_OPCODE_XOR
] = { ALU_OP2_XOR_INT
, tgsi_op2
},
9484 [TGSI_OPCODE_SAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9485 [TGSI_OPCODE_TXF
] = { FETCH_OP_LD
, tgsi_tex
},
9486 [TGSI_OPCODE_TXQ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9487 [TGSI_OPCODE_CONT
] = { CF_OP_LOOP_CONTINUE
, tgsi_loop_brk_cont
},
9488 [TGSI_OPCODE_EMIT
] = { CF_OP_EMIT_VERTEX
, tgsi_gs_emit
},
9489 [TGSI_OPCODE_ENDPRIM
] = { CF_OP_CUT_VERTEX
, tgsi_gs_emit
},
9490 [TGSI_OPCODE_BGNLOOP
] = { ALU_OP0_NOP
, tgsi_bgnloop
},
9491 [TGSI_OPCODE_BGNSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9492 [TGSI_OPCODE_ENDLOOP
] = { ALU_OP0_NOP
, tgsi_endloop
},
9493 [TGSI_OPCODE_ENDSUB
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9494 [TGSI_OPCODE_TXQ_LZ
] = { FETCH_OP_GET_TEXTURE_RESINFO
, tgsi_tex
},
9495 [TGSI_OPCODE_TXQS
] = { FETCH_OP_GET_NUMBER_OF_SAMPLES
, tgsi_tex
},
9496 [105] = { ALU_OP0_NOP
, tgsi_unsupported
},
9497 [106] = { ALU_OP0_NOP
, tgsi_unsupported
},
9498 [TGSI_OPCODE_NOP
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9499 [TGSI_OPCODE_FSEQ
] = { ALU_OP2_SETE_DX10
, tgsi_op2
},
9500 [TGSI_OPCODE_FSGE
] = { ALU_OP2_SETGE_DX10
, tgsi_op2
},
9501 [TGSI_OPCODE_FSLT
] = { ALU_OP2_SETGT_DX10
, tgsi_op2_swap
},
9502 [TGSI_OPCODE_FSNE
] = { ALU_OP2_SETNE_DX10
, tgsi_op2_swap
},
9503 [112] = { ALU_OP0_NOP
, tgsi_unsupported
},
9504 [TGSI_OPCODE_CALLNZ
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9505 [114] = { ALU_OP0_NOP
, tgsi_unsupported
},
9506 [TGSI_OPCODE_BREAKC
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9507 [TGSI_OPCODE_KILL_IF
] = { ALU_OP2_KILLGT
, tgsi_kill
}, /* conditional kill */
9508 [TGSI_OPCODE_END
] = { ALU_OP0_NOP
, tgsi_end
}, /* aka HALT */
9509 [118] = { ALU_OP0_NOP
, tgsi_unsupported
},
9510 [TGSI_OPCODE_F2I
] = { ALU_OP1_FLT_TO_INT
, tgsi_op2
},
9511 [TGSI_OPCODE_IDIV
] = { ALU_OP0_NOP
, tgsi_idiv
},
9512 [TGSI_OPCODE_IMAX
] = { ALU_OP2_MAX_INT
, tgsi_op2
},
9513 [TGSI_OPCODE_IMIN
] = { ALU_OP2_MIN_INT
, tgsi_op2
},
9514 [TGSI_OPCODE_INEG
] = { ALU_OP2_SUB_INT
, tgsi_ineg
},
9515 [TGSI_OPCODE_ISGE
] = { ALU_OP2_SETGE_INT
, tgsi_op2
},
9516 [TGSI_OPCODE_ISHR
] = { ALU_OP2_ASHR_INT
, tgsi_op2
},
9517 [TGSI_OPCODE_ISLT
] = { ALU_OP2_SETGT_INT
, tgsi_op2_swap
},
9518 [TGSI_OPCODE_F2U
] = { ALU_OP1_FLT_TO_UINT
, tgsi_op2
},
9519 [TGSI_OPCODE_U2F
] = { ALU_OP1_UINT_TO_FLT
, tgsi_op2
},
9520 [TGSI_OPCODE_UADD
] = { ALU_OP2_ADD_INT
, tgsi_op2
},
9521 [TGSI_OPCODE_UDIV
] = { ALU_OP0_NOP
, tgsi_udiv
},
9522 [TGSI_OPCODE_UMAD
] = { ALU_OP0_NOP
, tgsi_umad
},
9523 [TGSI_OPCODE_UMAX
] = { ALU_OP2_MAX_UINT
, tgsi_op2
},
9524 [TGSI_OPCODE_UMIN
] = { ALU_OP2_MIN_UINT
, tgsi_op2
},
9525 [TGSI_OPCODE_UMOD
] = { ALU_OP0_NOP
, tgsi_umod
},
9526 [TGSI_OPCODE_UMUL
] = { ALU_OP2_MULLO_INT
, cayman_mul_int_instr
},
9527 [TGSI_OPCODE_USEQ
] = { ALU_OP2_SETE_INT
, tgsi_op2
},
9528 [TGSI_OPCODE_USGE
] = { ALU_OP2_SETGE_UINT
, tgsi_op2
},
9529 [TGSI_OPCODE_USHR
] = { ALU_OP2_LSHR_INT
, tgsi_op2
},
9530 [TGSI_OPCODE_USLT
] = { ALU_OP2_SETGT_UINT
, tgsi_op2_swap
},
9531 [TGSI_OPCODE_USNE
] = { ALU_OP2_SETNE_INT
, tgsi_op2
},
9532 [TGSI_OPCODE_SWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9533 [TGSI_OPCODE_CASE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9534 [TGSI_OPCODE_DEFAULT
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9535 [TGSI_OPCODE_ENDSWITCH
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9536 [TGSI_OPCODE_SAMPLE
] = { 0, tgsi_unsupported
},
9537 [TGSI_OPCODE_SAMPLE_I
] = { 0, tgsi_unsupported
},
9538 [TGSI_OPCODE_SAMPLE_I_MS
] = { 0, tgsi_unsupported
},
9539 [TGSI_OPCODE_SAMPLE_B
] = { 0, tgsi_unsupported
},
9540 [TGSI_OPCODE_SAMPLE_C
] = { 0, tgsi_unsupported
},
9541 [TGSI_OPCODE_SAMPLE_C_LZ
] = { 0, tgsi_unsupported
},
9542 [TGSI_OPCODE_SAMPLE_D
] = { 0, tgsi_unsupported
},
9543 [TGSI_OPCODE_SAMPLE_L
] = { 0, tgsi_unsupported
},
9544 [TGSI_OPCODE_GATHER4
] = { 0, tgsi_unsupported
},
9545 [TGSI_OPCODE_SVIEWINFO
] = { 0, tgsi_unsupported
},
9546 [TGSI_OPCODE_SAMPLE_POS
] = { 0, tgsi_unsupported
},
9547 [TGSI_OPCODE_SAMPLE_INFO
] = { 0, tgsi_unsupported
},
9548 [TGSI_OPCODE_UARL
] = { ALU_OP1_MOVA_INT
, tgsi_eg_arl
},
9549 [TGSI_OPCODE_UCMP
] = { ALU_OP0_NOP
, tgsi_ucmp
},
9550 [TGSI_OPCODE_IABS
] = { 0, tgsi_iabs
},
9551 [TGSI_OPCODE_ISSG
] = { 0, tgsi_issg
},
9552 [TGSI_OPCODE_LOAD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9553 [TGSI_OPCODE_STORE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9554 [TGSI_OPCODE_MFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9555 [TGSI_OPCODE_LFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9556 [TGSI_OPCODE_SFENCE
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9557 [TGSI_OPCODE_BARRIER
] = { ALU_OP0_GROUP_BARRIER
, tgsi_barrier
},
9558 [TGSI_OPCODE_ATOMUADD
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9559 [TGSI_OPCODE_ATOMXCHG
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9560 [TGSI_OPCODE_ATOMCAS
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9561 [TGSI_OPCODE_ATOMAND
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9562 [TGSI_OPCODE_ATOMOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9563 [TGSI_OPCODE_ATOMXOR
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9564 [TGSI_OPCODE_ATOMUMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9565 [TGSI_OPCODE_ATOMUMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9566 [TGSI_OPCODE_ATOMIMIN
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9567 [TGSI_OPCODE_ATOMIMAX
] = { ALU_OP0_NOP
, tgsi_unsupported
},
9568 [TGSI_OPCODE_TEX2
] = { FETCH_OP_SAMPLE
, tgsi_tex
},
9569 [TGSI_OPCODE_TXB2
] = { FETCH_OP_SAMPLE_LB
, tgsi_tex
},
9570 [TGSI_OPCODE_TXL2
] = { FETCH_OP_SAMPLE_L
, tgsi_tex
},
9571 [TGSI_OPCODE_IMUL_HI
] = { ALU_OP2_MULHI_INT
, cayman_mul_int_instr
},
9572 [TGSI_OPCODE_UMUL_HI
] = { ALU_OP2_MULHI_UINT
, cayman_mul_int_instr
},
9573 [TGSI_OPCODE_TG4
] = { FETCH_OP_GATHER4
, tgsi_tex
},
9574 [TGSI_OPCODE_LODQ
] = { FETCH_OP_GET_LOD
, tgsi_tex
},
9575 [TGSI_OPCODE_IBFE
] = { ALU_OP3_BFE_INT
, tgsi_op3
},
9576 [TGSI_OPCODE_UBFE
] = { ALU_OP3_BFE_UINT
, tgsi_op3
},
9577 [TGSI_OPCODE_BFI
] = { ALU_OP0_NOP
, tgsi_bfi
},
9578 [TGSI_OPCODE_BREV
] = { ALU_OP1_BFREV_INT
, tgsi_op2
},
9579 [TGSI_OPCODE_POPC
] = { ALU_OP1_BCNT_INT
, tgsi_op2
},
9580 [TGSI_OPCODE_LSB
] = { ALU_OP1_FFBL_INT
, tgsi_op2
},
9581 [TGSI_OPCODE_IMSB
] = { ALU_OP1_FFBH_INT
, tgsi_msb
},
9582 [TGSI_OPCODE_UMSB
] = { ALU_OP1_FFBH_UINT
, tgsi_msb
},
9583 [TGSI_OPCODE_INTERP_CENTROID
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9584 [TGSI_OPCODE_INTERP_SAMPLE
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9585 [TGSI_OPCODE_INTERP_OFFSET
] = { ALU_OP0_NOP
, tgsi_interp_egcm
},
9586 [TGSI_OPCODE_F2D
] = { ALU_OP1_FLT32_TO_FLT64
, tgsi_op2_64
},
9587 [TGSI_OPCODE_D2F
] = { ALU_OP1_FLT64_TO_FLT32
, tgsi_op2_64_single_dest
},
9588 [TGSI_OPCODE_DABS
] = { ALU_OP1_MOV
, tgsi_op2_64
},
9589 [TGSI_OPCODE_DNEG
] = { ALU_OP2_ADD_64
, tgsi_dneg
},
9590 [TGSI_OPCODE_DADD
] = { ALU_OP2_ADD_64
, tgsi_op2_64
},
9591 [TGSI_OPCODE_DMUL
] = { ALU_OP2_MUL_64
, cayman_mul_double_instr
},
9592 [TGSI_OPCODE_DMAX
] = { ALU_OP2_MAX_64
, tgsi_op2_64
},
9593 [TGSI_OPCODE_DMIN
] = { ALU_OP2_MIN_64
, tgsi_op2_64
},
9594 [TGSI_OPCODE_DSLT
] = { ALU_OP2_SETGT_64
, tgsi_op2_64_single_dest_s
},
9595 [TGSI_OPCODE_DSGE
] = { ALU_OP2_SETGE_64
, tgsi_op2_64_single_dest
},
9596 [TGSI_OPCODE_DSEQ
] = { ALU_OP2_SETE_64
, tgsi_op2_64_single_dest
},
9597 [TGSI_OPCODE_DSNE
] = { ALU_OP2_SETNE_64
, tgsi_op2_64_single_dest
},
9598 [TGSI_OPCODE_DRCP
] = { ALU_OP2_RECIP_64
, cayman_emit_double_instr
},
9599 [TGSI_OPCODE_DSQRT
] = { ALU_OP2_SQRT_64
, cayman_emit_double_instr
},
9600 [TGSI_OPCODE_DMAD
] = { ALU_OP3_FMA_64
, tgsi_op3_64
},
9601 [TGSI_OPCODE_DFRAC
] = { ALU_OP1_FRACT_64
, tgsi_op2_64
},
9602 [TGSI_OPCODE_DLDEXP
] = { ALU_OP2_LDEXP_64
, tgsi_op2_64
},
9603 [TGSI_OPCODE_DFRACEXP
] = { ALU_OP1_FREXP_64
, tgsi_dfracexp
},
9604 [TGSI_OPCODE_D2I
] = { ALU_OP1_FLT_TO_INT
, egcm_double_to_int
},
9605 [TGSI_OPCODE_I2D
] = { ALU_OP1_INT_TO_FLT
, egcm_int_to_double
},
9606 [TGSI_OPCODE_D2U
] = { ALU_OP1_FLT_TO_UINT
, egcm_double_to_int
},
9607 [TGSI_OPCODE_U2D
] = { ALU_OP1_UINT_TO_FLT
, egcm_int_to_double
},
9608 [TGSI_OPCODE_DRSQ
] = { ALU_OP2_RECIPSQRT_64
, cayman_emit_double_instr
},
9609 [TGSI_OPCODE_LAST
] = { ALU_OP0_NOP
, tgsi_unsupported
},